diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2011-07-11 22:53:56 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-07-11 22:53:56 -0400 |
commit | 78f23926dff9c8587d510fa4d746e77a8ad9410d (patch) | |
tree | c94222fbdb85c9c3dbfd1785f6ca2c360fce4fde /drivers/staging | |
parent | 966b9016a175f0c2a555e937fb918fd845e4b2cc (diff) |
Staging: delete westbridge code
It's been stagnant for a while with out much forward progress for a
variety of different reasons. So remove it for now. It can be reverted
at any time if development picks back up again.
Acked-by: David Cross <odc@cypress.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
67 files changed, 0 insertions, 42055 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 6780df0ba77f..06c9081d596d 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig | |||
@@ -124,8 +124,6 @@ source "drivers/staging/tidspbridge/Kconfig" | |||
124 | 124 | ||
125 | source "drivers/staging/quickstart/Kconfig" | 125 | source "drivers/staging/quickstart/Kconfig" |
126 | 126 | ||
127 | source "drivers/staging/westbridge/Kconfig" | ||
128 | |||
129 | source "drivers/staging/sbe-2t3e3/Kconfig" | 127 | source "drivers/staging/sbe-2t3e3/Kconfig" |
130 | 128 | ||
131 | source "drivers/staging/ath6kl/Kconfig" | 129 | source "drivers/staging/ath6kl/Kconfig" |
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 36a8b84259bd..f3c5e33bb263 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile | |||
@@ -53,7 +53,6 @@ obj-$(CONFIG_EASYCAP) += easycap/ | |||
53 | obj-$(CONFIG_SOLO6X10) += solo6x10/ | 53 | obj-$(CONFIG_SOLO6X10) += solo6x10/ |
54 | obj-$(CONFIG_TIDSPBRIDGE) += tidspbridge/ | 54 | obj-$(CONFIG_TIDSPBRIDGE) += tidspbridge/ |
55 | obj-$(CONFIG_ACPI_QUICKSTART) += quickstart/ | 55 | obj-$(CONFIG_ACPI_QUICKSTART) += quickstart/ |
56 | obj-$(CONFIG_WESTBRIDGE_ASTORIA) += westbridge/astoria/ | ||
57 | obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/ | 56 | obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/ |
58 | obj-$(CONFIG_ATH6K_LEGACY) += ath6kl/ | 57 | obj-$(CONFIG_ATH6K_LEGACY) += ath6kl/ |
59 | obj-$(CONFIG_USB_ENESTORAGE) += keucr/ | 58 | obj-$(CONFIG_USB_ENESTORAGE) += keucr/ |
diff --git a/drivers/staging/westbridge/Kconfig b/drivers/staging/westbridge/Kconfig deleted file mode 100644 index 2b1c2ae557b6..000000000000 --- a/drivers/staging/westbridge/Kconfig +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | # | ||
2 | # West Bridge configuration | ||
3 | # | ||
4 | |||
5 | menuconfig WESTBRIDGE | ||
6 | tristate "West Bridge support" | ||
7 | depends on WESTBRIDGE_HAL_SELECTED | ||
8 | help | ||
9 | This selects West Bridge Peripheral controller support. | ||
10 | |||
11 | If you want West Bridge support, you should say Y here. | ||
12 | |||
13 | menuconfig WESTBRIDGE_ASTORIA | ||
14 | bool "West Bridge Astoria support" | ||
15 | depends on WESTBRIDGE != n && WESTBRIDGE_HAL_SELECTED | ||
16 | help | ||
17 | This option enables support for West Bridge Astoria | ||
18 | |||
19 | if WESTBRIDGE_ASTORIA | ||
20 | source "drivers/staging/westbridge/astoria/Kconfig" | ||
21 | endif #WESTBRIDGE_ASTORIA | ||
22 | |||
23 | config WESTBRIDGE_HAL_SELECTED | ||
24 | boolean | ||
25 | |||
26 | choice | ||
27 | prompt "West Bridge HAL" | ||
28 | help | ||
29 | West Bridge HAL/processor interface to be used | ||
30 | |||
31 | # | ||
32 | # HAL Layers | ||
33 | # | ||
34 | |||
35 | config MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
36 | bool "WESTBRIDGE OMAP3430 Astoria PNAND HAL" | ||
37 | depends on ARCH_OMAP3 | ||
38 | select WESTBRIDGE_HAL_SELECTED | ||
39 | help | ||
40 | Include the OMAP3430 HAL for PNAND interface | ||
41 | |||
42 | config MACH_NO_WESTBRIDGE | ||
43 | bool "no West Bridge HAL selected" | ||
44 | help | ||
45 | Do not include any HAL layer(de-activates West Bridge option) | ||
46 | endchoice | ||
47 | |||
48 | config WESTBRIDGE_DEBUG | ||
49 | bool "West Bridge debugging" | ||
50 | depends on WESTBRIDGE != n | ||
51 | help | ||
52 | This is an option for use by developers; most people should | ||
53 | say N here. This enables WESTBRIDGE core and driver debugging. | ||
diff --git a/drivers/staging/westbridge/TODO b/drivers/staging/westbridge/TODO deleted file mode 100644 index 6ca80581bbe2..000000000000 --- a/drivers/staging/westbridge/TODO +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | TODO: | ||
2 | - checkpatch.pl fixes | ||
3 | - determine where to put the hal and common api code | ||
4 | - modify the driver directory structure in an intuitive way | ||
5 | |||
6 | Please send any patches to Greg Kroah-Hartman <gregkh@suse.de> | ||
7 | and David Cross <david.cross@cypress.com>. | ||
diff --git a/drivers/staging/westbridge/astoria/Kconfig b/drivers/staging/westbridge/astoria/Kconfig deleted file mode 100644 index 1ce388acbfeb..000000000000 --- a/drivers/staging/westbridge/astoria/Kconfig +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # | ||
2 | # West Bridge configuration | ||
3 | # | ||
4 | source "drivers/staging/westbridge/astoria/device/Kconfig" | ||
5 | |||
6 | source "drivers/staging/westbridge/astoria/block/Kconfig" | ||
7 | |||
8 | source "drivers/staging/westbridge/astoria/gadget/Kconfig" | ||
9 | |||
diff --git a/drivers/staging/westbridge/astoria/Makefile b/drivers/staging/westbridge/astoria/Makefile deleted file mode 100644 index 907bdb25804b..000000000000 --- a/drivers/staging/westbridge/astoria/Makefile +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the kernel westbridge device drivers. | ||
3 | # | ||
4 | |||
5 | ifneq ($(CONFIG_WESTBRIDGE_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -WESTBRIDGE_NDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_WESTBRIDGE) += device/ | ||
10 | obj-$(CONFIG_WESTBRIDGE) += block/ | ||
11 | obj-$(CONFIG_WESTBRIDGE) += gadget/ \ No newline at end of file | ||
diff --git a/drivers/staging/westbridge/astoria/api/Makefile b/drivers/staging/westbridge/astoria/api/Makefile deleted file mode 100644 index 1c94bc7bb310..000000000000 --- a/drivers/staging/westbridge/astoria/api/Makefile +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the kernel westbridge core. | ||
3 | # | ||
4 | |||
5 | ifeq ($(CONFIG_WESTBRIDGE_DEBUG),n) | ||
6 | EXTRA_CFLAGS += -NDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_WESTBRIDGE_DEVICE_DRIVER) += cyasapi.o | ||
10 | cyasapi-y := src/cyasdma.o src/cyasintr.o src/cyaslep2pep.o \ | ||
11 | src/cyaslowlevel.o src/cyasmisc.o src/cyasmtp.o \ | ||
12 | src/cyasstorage.o src/cyasusb.o | ||
13 | |||
14 | |||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasdma.c b/drivers/staging/westbridge/astoria/api/src/cyasdma.c deleted file mode 100644 index c461d4f60bfb..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasdma.c +++ /dev/null | |||
@@ -1,1107 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyasdma.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasdma.h" | ||
24 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
25 | #include "../../include/linux/westbridge/cyaserr.h" | ||
26 | #include "../../include/linux/westbridge/cyasregs.h" | ||
27 | |||
28 | /* | ||
29 | * Add the DMA queue entry to the free list to be re-used later | ||
30 | */ | ||
31 | static void | ||
32 | cy_as_dma_add_request_to_free_queue(cy_as_device *dev_p, | ||
33 | cy_as_dma_queue_entry *req_p) | ||
34 | { | ||
35 | uint32_t imask; | ||
36 | imask = cy_as_hal_disable_interrupts(); | ||
37 | |||
38 | req_p->next_p = dev_p->dma_freelist_p; | ||
39 | dev_p->dma_freelist_p = req_p; | ||
40 | |||
41 | cy_as_hal_enable_interrupts(imask); | ||
42 | } | ||
43 | |||
44 | /* | ||
45 | * Get a DMA queue entry from the free list. | ||
46 | */ | ||
47 | static cy_as_dma_queue_entry * | ||
48 | cy_as_dma_get_dma_queue_entry(cy_as_device *dev_p) | ||
49 | { | ||
50 | cy_as_dma_queue_entry *req_p; | ||
51 | uint32_t imask; | ||
52 | |||
53 | cy_as_hal_assert(dev_p->dma_freelist_p != 0); | ||
54 | |||
55 | imask = cy_as_hal_disable_interrupts(); | ||
56 | req_p = dev_p->dma_freelist_p; | ||
57 | dev_p->dma_freelist_p = req_p->next_p; | ||
58 | cy_as_hal_enable_interrupts(imask); | ||
59 | |||
60 | return req_p; | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * Set the maximum size that the West Bridge hardware | ||
65 | * can handle in a single DMA operation. This size | ||
66 | * may change for the P <-> U endpoints as a function | ||
67 | * of the endpoint type and whether we are running | ||
68 | * at full speed or high speed. | ||
69 | */ | ||
70 | cy_as_return_status_t | ||
71 | cy_as_dma_set_max_dma_size(cy_as_device *dev_p, | ||
72 | cy_as_end_point_number_t ep, uint32_t size) | ||
73 | { | ||
74 | /* In MTP mode, EP2 is allowed to have all max sizes. */ | ||
75 | if ((!dev_p->is_mtp_firmware) || (ep != 0x02)) { | ||
76 | if (size < 64 || size > 1024) | ||
77 | return CY_AS_ERROR_INVALID_SIZE; | ||
78 | } | ||
79 | |||
80 | CY_AS_NUM_EP(dev_p, ep)->maxhwdata = (uint16_t)size; | ||
81 | return CY_AS_ERROR_SUCCESS; | ||
82 | } | ||
83 | |||
84 | /* | ||
85 | * The callback for requests sent to West Bridge | ||
86 | * to relay endpoint data. Endpoint data for EP0 | ||
87 | * and EP1 are sent using mailbox requests. This | ||
88 | * is the callback that is called when a response | ||
89 | * to a mailbox request to send data is received. | ||
90 | */ | ||
91 | static void | ||
92 | cy_as_dma_request_callback( | ||
93 | cy_as_device *dev_p, | ||
94 | uint8_t context, | ||
95 | cy_as_ll_request_response *req_p, | ||
96 | cy_as_ll_request_response *resp_p, | ||
97 | cy_as_return_status_t ret) | ||
98 | { | ||
99 | uint16_t v; | ||
100 | uint16_t datacnt; | ||
101 | cy_as_end_point_number_t ep; | ||
102 | |||
103 | (void)context; | ||
104 | |||
105 | cy_as_log_debug_message(5, "cy_as_dma_request_callback called"); | ||
106 | |||
107 | /* | ||
108 | * extract the return code from the firmware | ||
109 | */ | ||
110 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
111 | if (cy_as_ll_request_response__get_code(resp_p) != | ||
112 | CY_RESP_SUCCESS_FAILURE) | ||
113 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
114 | else | ||
115 | ret = cy_as_ll_request_response__get_word(resp_p, 0); | ||
116 | } | ||
117 | |||
118 | /* | ||
119 | * extract the endpoint number and the transferred byte count | ||
120 | * from the request. | ||
121 | */ | ||
122 | v = cy_as_ll_request_response__get_word(req_p, 0); | ||
123 | ep = (cy_as_end_point_number_t)((v >> 13) & 0x01); | ||
124 | |||
125 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
126 | /* | ||
127 | * if the firmware returns success, | ||
128 | * all of the data requested was | ||
129 | * transferred. there are no partial | ||
130 | * transfers. | ||
131 | */ | ||
132 | datacnt = v & 0x3FF; | ||
133 | } else { | ||
134 | /* | ||
135 | * if the firmware returned an error, no data was transferred. | ||
136 | */ | ||
137 | datacnt = 0; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * queue the request and response data structures for use with the | ||
142 | * next EP0 or EP1 request. | ||
143 | */ | ||
144 | if (ep == 0) { | ||
145 | dev_p->usb_ep0_dma_req = req_p; | ||
146 | dev_p->usb_ep0_dma_resp = resp_p; | ||
147 | } else { | ||
148 | dev_p->usb_ep1_dma_req = req_p; | ||
149 | dev_p->usb_ep1_dma_resp = resp_p; | ||
150 | } | ||
151 | |||
152 | /* | ||
153 | * call the DMA complete function so we can | ||
154 | * signal that this portion of the transfer | ||
155 | * has completed. if the low level request | ||
156 | * was canceled, we do not need to signal | ||
157 | * the completed function as the only way a | ||
158 | * cancel can happen is via the DMA cancel | ||
159 | * function. | ||
160 | */ | ||
161 | if (ret != CY_AS_ERROR_CANCELED) | ||
162 | cy_as_dma_completed_callback(dev_p->tag, ep, datacnt, ret); | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | * Set the DRQ mask register for the given endpoint number. If state is | ||
167 | * CyTrue, the DRQ interrupt for the given endpoint is enabled, otherwise | ||
168 | * it is disabled. | ||
169 | */ | ||
170 | static void | ||
171 | cy_as_dma_set_drq(cy_as_device *dev_p, | ||
172 | cy_as_end_point_number_t ep, cy_bool state) | ||
173 | { | ||
174 | uint16_t mask; | ||
175 | uint16_t v; | ||
176 | uint32_t intval; | ||
177 | |||
178 | /* | ||
179 | * there are not DRQ register bits for EP0 and EP1 | ||
180 | */ | ||
181 | if (ep == 0 || ep == 1) | ||
182 | return; | ||
183 | |||
184 | /* | ||
185 | * disable interrupts while we do this to be sure the state of the | ||
186 | * DRQ mask register is always well defined. | ||
187 | */ | ||
188 | intval = cy_as_hal_disable_interrupts(); | ||
189 | |||
190 | /* | ||
191 | * set the DRQ bit to the given state for the ep given | ||
192 | */ | ||
193 | mask = (1 << ep); | ||
194 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_DRQ_MASK); | ||
195 | |||
196 | if (state) | ||
197 | v |= mask; | ||
198 | else | ||
199 | v &= ~mask; | ||
200 | |||
201 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_DRQ_MASK, v); | ||
202 | cy_as_hal_enable_interrupts(intval); | ||
203 | } | ||
204 | |||
205 | /* | ||
206 | * Send the next DMA request for the endpoint given | ||
207 | */ | ||
208 | static void | ||
209 | cy_as_dma_send_next_dma_request(cy_as_device *dev_p, cy_as_dma_end_point *ep_p) | ||
210 | { | ||
211 | uint32_t datacnt; | ||
212 | void *buf_p; | ||
213 | cy_as_dma_queue_entry *dma_p; | ||
214 | |||
215 | cy_as_log_debug_message(6, "cy_as_dma_send_next_dma_request called"); | ||
216 | |||
217 | /* If the queue is empty, nothing to do */ | ||
218 | dma_p = ep_p->queue_p; | ||
219 | if (dma_p == 0) { | ||
220 | /* | ||
221 | * there are no pending DMA requests | ||
222 | * for this endpoint. disable the DRQ | ||
223 | * mask bits to insure no interrupts | ||
224 | * will be triggered by this endpoint | ||
225 | * until someone is interested in the data. | ||
226 | */ | ||
227 | cy_as_dma_set_drq(dev_p, ep_p->ep, cy_false); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | cy_as_dma_end_point_set_running(ep_p); | ||
232 | |||
233 | /* | ||
234 | * get the number of words that still | ||
235 | * need to be xferred in this request. | ||
236 | */ | ||
237 | datacnt = dma_p->size - dma_p->offset; | ||
238 | cy_as_hal_assert(datacnt >= 0); | ||
239 | |||
240 | /* | ||
241 | * the HAL layer should never limit the size | ||
242 | * of the transfer to something less than the | ||
243 | * maxhwdata otherwise, the data will be sent | ||
244 | * in packets that are not correct in size. | ||
245 | */ | ||
246 | cy_as_hal_assert(ep_p->maxhaldata == CY_AS_DMA_MAX_SIZE_HW_SIZE | ||
247 | || ep_p->maxhaldata >= ep_p->maxhwdata); | ||
248 | |||
249 | /* | ||
250 | * update the number of words that need to be xferred yet | ||
251 | * based on the limits of the HAL layer. | ||
252 | */ | ||
253 | if (ep_p->maxhaldata == CY_AS_DMA_MAX_SIZE_HW_SIZE) { | ||
254 | if (datacnt > ep_p->maxhwdata) | ||
255 | datacnt = ep_p->maxhwdata; | ||
256 | } else { | ||
257 | if (datacnt > ep_p->maxhaldata) | ||
258 | datacnt = ep_p->maxhaldata; | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * find a pointer to the data that needs to be transferred | ||
263 | */ | ||
264 | buf_p = (((char *)dma_p->buf_p) + dma_p->offset); | ||
265 | |||
266 | /* | ||
267 | * mark a request in transit | ||
268 | */ | ||
269 | cy_as_dma_end_point_set_in_transit(ep_p); | ||
270 | |||
271 | if (ep_p->ep == 0 || ep_p->ep == 1) { | ||
272 | /* | ||
273 | * if this is a WRITE request on EP0 and EP1 | ||
274 | * we write the data via an EP_DATA request | ||
275 | * to west bridge via the mailbox registers. | ||
276 | * if this is a READ request, we do nothing | ||
277 | * and the data will arrive via an EP_DATA | ||
278 | * request from west bridge. in the request | ||
279 | * handler for the USB context we will pass | ||
280 | * the data back into the DMA module. | ||
281 | */ | ||
282 | if (dma_p->readreq == cy_false) { | ||
283 | uint16_t v; | ||
284 | uint16_t len; | ||
285 | cy_as_ll_request_response *resp_p; | ||
286 | cy_as_ll_request_response *req_p; | ||
287 | cy_as_return_status_t ret; | ||
288 | |||
289 | len = (uint16_t)(datacnt / 2); | ||
290 | if (datacnt % 2) | ||
291 | len++; | ||
292 | |||
293 | len++; | ||
294 | |||
295 | if (ep_p->ep == 0) { | ||
296 | req_p = dev_p->usb_ep0_dma_req; | ||
297 | resp_p = dev_p->usb_ep0_dma_resp; | ||
298 | dev_p->usb_ep0_dma_req = 0; | ||
299 | dev_p->usb_ep0_dma_resp = 0; | ||
300 | } else { | ||
301 | req_p = dev_p->usb_ep1_dma_req; | ||
302 | resp_p = dev_p->usb_ep1_dma_resp; | ||
303 | dev_p->usb_ep1_dma_req = 0; | ||
304 | dev_p->usb_ep1_dma_resp = 0; | ||
305 | } | ||
306 | |||
307 | cy_as_hal_assert(req_p != 0); | ||
308 | cy_as_hal_assert(resp_p != 0); | ||
309 | cy_as_hal_assert(len <= 64); | ||
310 | |||
311 | cy_as_ll_init_request(req_p, CY_RQT_USB_EP_DATA, | ||
312 | CY_RQT_USB_RQT_CONTEXT, len); | ||
313 | |||
314 | v = (uint16_t)(datacnt | (ep_p->ep << 13) | (1 << 14)); | ||
315 | if (dma_p->offset == 0) | ||
316 | v |= (1 << 12);/* Set the first packet bit */ | ||
317 | if (dma_p->offset + datacnt == dma_p->size) | ||
318 | v |= (1 << 11);/* Set the last packet bit */ | ||
319 | |||
320 | cy_as_ll_request_response__set_word(req_p, 0, v); | ||
321 | cy_as_ll_request_response__pack(req_p, | ||
322 | 1, datacnt, buf_p); | ||
323 | |||
324 | cy_as_ll_init_response(resp_p, 1); | ||
325 | |||
326 | ret = cy_as_ll_send_request(dev_p, req_p, resp_p, | ||
327 | cy_false, cy_as_dma_request_callback); | ||
328 | if (ret == CY_AS_ERROR_SUCCESS) | ||
329 | cy_as_log_debug_message(5, | ||
330 | "+++ send EP 0/1 data via mailbox registers"); | ||
331 | else | ||
332 | cy_as_log_debug_message(5, | ||
333 | "+++ error sending EP 0/1 data via mailbox " | ||
334 | "registers - CY_AS_ERROR_TIMEOUT"); | ||
335 | |||
336 | if (ret != CY_AS_ERROR_SUCCESS) | ||
337 | cy_as_dma_completed_callback(dev_p->tag, | ||
338 | ep_p->ep, 0, ret); | ||
339 | } | ||
340 | } else { | ||
341 | /* | ||
342 | * this is a DMA request on an endpoint that is accessible | ||
343 | * via the P port. ask the HAL DMA capabilities to | ||
344 | * perform this. the amount of data sent is limited by the | ||
345 | * HAL max size as well as what we need to send. if the | ||
346 | * ep_p->maxhaldata is set to a value larger than the | ||
347 | * endpoint buffer size, then we will pass more than a | ||
348 | * single buffer worth of data to the HAL layer and expect | ||
349 | * the HAL layer to divide the data into packets. the last | ||
350 | * parameter here (ep_p->maxhwdata) gives the packet size for | ||
351 | * the data so the HAL layer knows what the packet size should | ||
352 | * be. | ||
353 | */ | ||
354 | if (cy_as_dma_end_point_is_direction_in(ep_p)) | ||
355 | cy_as_hal_dma_setup_write(dev_p->tag, | ||
356 | ep_p->ep, buf_p, datacnt, ep_p->maxhwdata); | ||
357 | else | ||
358 | cy_as_hal_dma_setup_read(dev_p->tag, | ||
359 | ep_p->ep, buf_p, datacnt, ep_p->maxhwdata); | ||
360 | |||
361 | /* | ||
362 | * the DRQ interrupt for this endpoint should be enabled | ||
363 | * so that the data transfer progresses at interrupt time. | ||
364 | */ | ||
365 | cy_as_dma_set_drq(dev_p, ep_p->ep, cy_true); | ||
366 | } | ||
367 | } | ||
368 | |||
369 | /* | ||
370 | * This function is called when the HAL layer has | ||
371 | * completed the last requested DMA operation. | ||
372 | * This function sends/receives the next batch of | ||
373 | * data associated with the current DMA request, | ||
374 | * or it is is complete, moves to the next DMA request. | ||
375 | */ | ||
376 | void | ||
377 | cy_as_dma_completed_callback(cy_as_hal_device_tag tag, | ||
378 | cy_as_end_point_number_t ep, uint32_t cnt, cy_as_return_status_t status) | ||
379 | { | ||
380 | uint32_t mask; | ||
381 | cy_as_dma_queue_entry *req_p; | ||
382 | cy_as_dma_end_point *ep_p; | ||
383 | cy_as_device *dev_p = cy_as_device_find_from_tag(tag); | ||
384 | |||
385 | /* Make sure the HAL layer gave us good parameters */ | ||
386 | cy_as_hal_assert(dev_p != 0); | ||
387 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
388 | cy_as_hal_assert(ep < 16); | ||
389 | |||
390 | |||
391 | /* Get the endpoint ptr */ | ||
392 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
393 | cy_as_hal_assert(ep_p->queue_p != 0); | ||
394 | |||
395 | /* Get a pointer to the current entry in the queue */ | ||
396 | mask = cy_as_hal_disable_interrupts(); | ||
397 | req_p = ep_p->queue_p; | ||
398 | |||
399 | /* Update the offset to reflect the data actually received or sent */ | ||
400 | req_p->offset += cnt; | ||
401 | |||
402 | /* | ||
403 | * if we are still sending/receiving the current packet, | ||
404 | * send/receive the next chunk basically we keep going | ||
405 | * if we have not sent/received enough data, and we are | ||
406 | * not doing a packet operation, and the last packet | ||
407 | * sent or received was a full sized packet. in other | ||
408 | * words, when we are NOT doing a packet operation, a | ||
409 | * less than full size packet (a short packet) will | ||
410 | * terminate the operation. | ||
411 | * | ||
412 | * note: if this is EP1 request and the request has | ||
413 | * timed out, it means the buffer is not free. | ||
414 | * we have to resend the data. | ||
415 | * | ||
416 | * note: for the MTP data transfers, the DMA transfer | ||
417 | * for the next packet can only be started asynchronously, | ||
418 | * after a firmware event notifies that the device is ready. | ||
419 | */ | ||
420 | if (((req_p->offset != req_p->size) && (req_p->packet == cy_false) && | ||
421 | ((cnt == ep_p->maxhaldata) || ((cnt == ep_p->maxhwdata) && | ||
422 | ((ep != CY_AS_MTP_READ_ENDPOINT) || | ||
423 | (cnt == dev_p->usb_max_tx_size))))) | ||
424 | || ((ep == 1) && (status == CY_AS_ERROR_TIMEOUT))) { | ||
425 | cy_as_hal_enable_interrupts(mask); | ||
426 | |||
427 | /* | ||
428 | * and send the request again to send the next block of | ||
429 | * data. special handling for MTP transfers on E_ps 2 | ||
430 | * and 6. the send_next_request will be processed based | ||
431 | * on the event sent by the firmware. | ||
432 | */ | ||
433 | if ((ep == CY_AS_MTP_WRITE_ENDPOINT) || ( | ||
434 | (ep == CY_AS_MTP_READ_ENDPOINT) && | ||
435 | (!cy_as_dma_end_point_is_direction_in(ep_p)))) | ||
436 | cy_as_dma_end_point_set_stopped(ep_p); | ||
437 | else | ||
438 | cy_as_dma_send_next_dma_request(dev_p, ep_p); | ||
439 | } else { | ||
440 | /* | ||
441 | * we get here if ... | ||
442 | * we have sent or received all of the data | ||
443 | * or | ||
444 | * we are doing a packet operation | ||
445 | * or | ||
446 | * we receive a short packet | ||
447 | */ | ||
448 | |||
449 | /* | ||
450 | * remove this entry from the DMA queue for this endpoint. | ||
451 | */ | ||
452 | cy_as_dma_end_point_clear_in_transit(ep_p); | ||
453 | ep_p->queue_p = req_p->next_p; | ||
454 | if (ep_p->last_p == req_p) { | ||
455 | /* | ||
456 | * we have removed the last packet from the DMA queue, | ||
457 | * disable the interrupt associated with this interrupt. | ||
458 | */ | ||
459 | ep_p->last_p = 0; | ||
460 | cy_as_hal_enable_interrupts(mask); | ||
461 | cy_as_dma_set_drq(dev_p, ep, cy_false); | ||
462 | } else | ||
463 | cy_as_hal_enable_interrupts(mask); | ||
464 | |||
465 | if (req_p->cb) { | ||
466 | /* | ||
467 | * if the request has a callback associated with it, | ||
468 | * call the callback to tell the interested party that | ||
469 | * this DMA request has completed. | ||
470 | * | ||
471 | * note, we set the in_callback bit to insure that we | ||
472 | * cannot recursively call an API function that is | ||
473 | * synchronous only from a callback. | ||
474 | */ | ||
475 | cy_as_device_set_in_callback(dev_p); | ||
476 | (*req_p->cb)(dev_p, ep, req_p->buf_p, | ||
477 | req_p->offset, status); | ||
478 | cy_as_device_clear_in_callback(dev_p); | ||
479 | } | ||
480 | |||
481 | /* | ||
482 | * we are done with this request, put it on the freelist to be | ||
483 | * reused at a later time. | ||
484 | */ | ||
485 | cy_as_dma_add_request_to_free_queue(dev_p, req_p); | ||
486 | |||
487 | if (ep_p->queue_p == 0) { | ||
488 | /* | ||
489 | * if the endpoint is out of DMA entries, set the | ||
490 | * endpoint as stopped. | ||
491 | */ | ||
492 | cy_as_dma_end_point_set_stopped(ep_p); | ||
493 | |||
494 | /* | ||
495 | * the DMA queue is empty, wake any task waiting on | ||
496 | * the QUEUE to drain. | ||
497 | */ | ||
498 | if (cy_as_dma_end_point_is_sleeping(ep_p)) { | ||
499 | cy_as_dma_end_point_set_wake_state(ep_p); | ||
500 | cy_as_hal_wake(&ep_p->channel); | ||
501 | } | ||
502 | } else { | ||
503 | /* | ||
504 | * if the queued operation is a MTP transfer, | ||
505 | * wait until firmware event before sending | ||
506 | * down the next DMA request. | ||
507 | */ | ||
508 | if ((ep == CY_AS_MTP_WRITE_ENDPOINT) || | ||
509 | ((ep == CY_AS_MTP_READ_ENDPOINT) && | ||
510 | (!cy_as_dma_end_point_is_direction_in(ep_p))) || | ||
511 | ((ep == dev_p->storage_read_endpoint) && | ||
512 | (!cy_as_device_is_p2s_dma_start_recvd(dev_p))) | ||
513 | || ((ep == dev_p->storage_write_endpoint) && | ||
514 | (!cy_as_device_is_p2s_dma_start_recvd(dev_p)))) | ||
515 | cy_as_dma_end_point_set_stopped(ep_p); | ||
516 | else | ||
517 | cy_as_dma_send_next_dma_request(dev_p, ep_p); | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 | /* | ||
523 | * This function is used to kick start DMA on a given | ||
524 | * channel. If DMA is already running on the given | ||
525 | * endpoint, nothing happens. If DMA is not running, | ||
526 | * the first entry is pulled from the DMA queue and | ||
527 | * sent/recevied to/from the West Bridge device. | ||
528 | */ | ||
529 | cy_as_return_status_t | ||
530 | cy_as_dma_kick_start(cy_as_device *dev_p, cy_as_end_point_number_t ep) | ||
531 | { | ||
532 | cy_as_dma_end_point *ep_p; | ||
533 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
534 | |||
535 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
536 | |||
537 | /* We are already running */ | ||
538 | if (cy_as_dma_end_point_is_running(ep_p)) | ||
539 | return CY_AS_ERROR_SUCCESS; | ||
540 | |||
541 | cy_as_dma_send_next_dma_request(dev_p, ep_p); | ||
542 | return CY_AS_ERROR_SUCCESS; | ||
543 | } | ||
544 | |||
545 | /* | ||
546 | * This function stops the given endpoint. Stopping and endpoint cancels | ||
547 | * any pending DMA operations and frees all resources associated with the | ||
548 | * given endpoint. | ||
549 | */ | ||
550 | static cy_as_return_status_t | ||
551 | cy_as_dma_stop_end_point(cy_as_device *dev_p, cy_as_end_point_number_t ep) | ||
552 | { | ||
553 | cy_as_return_status_t ret; | ||
554 | cy_as_dma_end_point *ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
555 | |||
556 | /* | ||
557 | * cancel any pending DMA requests associated with this endpoint. this | ||
558 | * cancels any DMA requests at the HAL layer as well as dequeues any | ||
559 | * request that is currently pending. | ||
560 | */ | ||
561 | ret = cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
562 | if (ret != CY_AS_ERROR_SUCCESS) | ||
563 | return ret; | ||
564 | |||
565 | /* | ||
566 | * destroy the sleep channel | ||
567 | */ | ||
568 | if (!cy_as_hal_destroy_sleep_channel(&ep_p->channel) | ||
569 | && ret == CY_AS_ERROR_SUCCESS) | ||
570 | ret = CY_AS_ERROR_DESTROY_SLEEP_CHANNEL_FAILED; | ||
571 | |||
572 | /* | ||
573 | * free the memory associated with this endpoint | ||
574 | */ | ||
575 | cy_as_hal_free(ep_p); | ||
576 | |||
577 | /* | ||
578 | * set the data structure ptr to something sane since the | ||
579 | * previous pointer is now free. | ||
580 | */ | ||
581 | dev_p->endp[ep] = 0; | ||
582 | |||
583 | return ret; | ||
584 | } | ||
585 | |||
586 | /* | ||
587 | * This method stops the USB stack. This is an internal function that does | ||
588 | * all of the work of destroying the USB stack without the protections that | ||
589 | * we provide to the API (i.e. stopping at stack that is not running). | ||
590 | */ | ||
591 | static cy_as_return_status_t | ||
592 | cy_as_dma_stop_internal(cy_as_device *dev_p) | ||
593 | { | ||
594 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
595 | cy_as_return_status_t lret; | ||
596 | cy_as_end_point_number_t i; | ||
597 | |||
598 | /* | ||
599 | * stop all of the endpoints. this cancels all DMA requests, and | ||
600 | * frees all resources associated with each endpoint. | ||
601 | */ | ||
602 | for (i = 0; i < sizeof(dev_p->endp)/(sizeof(dev_p->endp[0])); i++) { | ||
603 | lret = cy_as_dma_stop_end_point(dev_p, i); | ||
604 | if (lret != CY_AS_ERROR_SUCCESS && ret == CY_AS_ERROR_SUCCESS) | ||
605 | ret = lret; | ||
606 | } | ||
607 | |||
608 | /* | ||
609 | * now, free the list of DMA requests structures that we use to manage | ||
610 | * DMA requests. | ||
611 | */ | ||
612 | while (dev_p->dma_freelist_p) { | ||
613 | cy_as_dma_queue_entry *req_p; | ||
614 | uint32_t imask = cy_as_hal_disable_interrupts(); | ||
615 | |||
616 | req_p = dev_p->dma_freelist_p; | ||
617 | dev_p->dma_freelist_p = req_p->next_p; | ||
618 | |||
619 | cy_as_hal_enable_interrupts(imask); | ||
620 | |||
621 | cy_as_hal_free(req_p); | ||
622 | } | ||
623 | |||
624 | cy_as_ll_destroy_request(dev_p, dev_p->usb_ep0_dma_req); | ||
625 | cy_as_ll_destroy_request(dev_p, dev_p->usb_ep1_dma_req); | ||
626 | cy_as_ll_destroy_response(dev_p, dev_p->usb_ep0_dma_resp); | ||
627 | cy_as_ll_destroy_response(dev_p, dev_p->usb_ep1_dma_resp); | ||
628 | |||
629 | return ret; | ||
630 | } | ||
631 | |||
632 | |||
633 | /* | ||
634 | * CyAsDmaStop() | ||
635 | * | ||
636 | * This function shuts down the DMA module. All resources | ||
637 | * associated with the DMA module will be freed. This | ||
638 | * routine is the API stop function. It insures that we | ||
639 | * are stopping a stack that is actually running and then | ||
640 | * calls the internal function to do the work. | ||
641 | */ | ||
642 | cy_as_return_status_t | ||
643 | cy_as_dma_stop(cy_as_device *dev_p) | ||
644 | { | ||
645 | cy_as_return_status_t ret; | ||
646 | |||
647 | ret = cy_as_dma_stop_internal(dev_p); | ||
648 | cy_as_device_set_dma_stopped(dev_p); | ||
649 | |||
650 | return ret; | ||
651 | } | ||
652 | |||
653 | /* | ||
654 | * CyAsDmaStart() | ||
655 | * | ||
656 | * This function initializes the DMA module to insure it is up and running. | ||
657 | */ | ||
658 | cy_as_return_status_t | ||
659 | cy_as_dma_start(cy_as_device *dev_p) | ||
660 | { | ||
661 | cy_as_end_point_number_t i; | ||
662 | uint16_t cnt; | ||
663 | |||
664 | if (cy_as_device_is_dma_running(dev_p)) | ||
665 | return CY_AS_ERROR_ALREADY_RUNNING; | ||
666 | |||
667 | /* | ||
668 | * pre-allocate DMA queue structures to be used in the interrupt context | ||
669 | */ | ||
670 | for (cnt = 0; cnt < 32; cnt++) { | ||
671 | cy_as_dma_queue_entry *entry_p = (cy_as_dma_queue_entry *) | ||
672 | cy_as_hal_alloc(sizeof(cy_as_dma_queue_entry)); | ||
673 | if (entry_p == 0) { | ||
674 | cy_as_dma_stop_internal(dev_p); | ||
675 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
676 | } | ||
677 | cy_as_dma_add_request_to_free_queue(dev_p, entry_p); | ||
678 | } | ||
679 | |||
680 | /* | ||
681 | * pre-allocate the DMA requests for sending EP0 | ||
682 | * and EP1 data to west bridge | ||
683 | */ | ||
684 | dev_p->usb_ep0_dma_req = cy_as_ll_create_request(dev_p, | ||
685 | CY_RQT_USB_EP_DATA, CY_RQT_USB_RQT_CONTEXT, 64); | ||
686 | dev_p->usb_ep1_dma_req = cy_as_ll_create_request(dev_p, | ||
687 | CY_RQT_USB_EP_DATA, CY_RQT_USB_RQT_CONTEXT, 64); | ||
688 | |||
689 | if (dev_p->usb_ep0_dma_req == 0 || dev_p->usb_ep1_dma_req == 0) { | ||
690 | cy_as_dma_stop_internal(dev_p); | ||
691 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
692 | } | ||
693 | dev_p->usb_ep0_dma_req_save = dev_p->usb_ep0_dma_req; | ||
694 | |||
695 | dev_p->usb_ep0_dma_resp = cy_as_ll_create_response(dev_p, 1); | ||
696 | dev_p->usb_ep1_dma_resp = cy_as_ll_create_response(dev_p, 1); | ||
697 | if (dev_p->usb_ep0_dma_resp == 0 || dev_p->usb_ep1_dma_resp == 0) { | ||
698 | cy_as_dma_stop_internal(dev_p); | ||
699 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
700 | } | ||
701 | dev_p->usb_ep0_dma_resp_save = dev_p->usb_ep0_dma_resp; | ||
702 | |||
703 | /* | ||
704 | * set the dev_p->endp to all zeros to insure cleanup is possible if | ||
705 | * an error occurs during initialization. | ||
706 | */ | ||
707 | cy_as_hal_mem_set(dev_p->endp, 0, sizeof(dev_p->endp)); | ||
708 | |||
709 | /* | ||
710 | * now, iterate through each of the endpoints and initialize each | ||
711 | * one. | ||
712 | */ | ||
713 | for (i = 0; i < sizeof(dev_p->endp)/sizeof(dev_p->endp[0]); i++) { | ||
714 | dev_p->endp[i] = (cy_as_dma_end_point *) | ||
715 | cy_as_hal_alloc(sizeof(cy_as_dma_end_point)); | ||
716 | if (dev_p->endp[i] == 0) { | ||
717 | cy_as_dma_stop_internal(dev_p); | ||
718 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
719 | } | ||
720 | cy_as_hal_mem_set(dev_p->endp[i], 0, | ||
721 | sizeof(cy_as_dma_end_point)); | ||
722 | |||
723 | dev_p->endp[i]->ep = i; | ||
724 | dev_p->endp[i]->queue_p = 0; | ||
725 | dev_p->endp[i]->last_p = 0; | ||
726 | |||
727 | cy_as_dma_set_drq(dev_p, i, cy_false); | ||
728 | |||
729 | if (!cy_as_hal_create_sleep_channel(&dev_p->endp[i]->channel)) | ||
730 | return CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED; | ||
731 | } | ||
732 | |||
733 | /* | ||
734 | * tell the HAL layer who to call when the | ||
735 | * HAL layer completes a DMA request | ||
736 | */ | ||
737 | cy_as_hal_dma_register_callback(dev_p->tag, | ||
738 | cy_as_dma_completed_callback); | ||
739 | |||
740 | /* | ||
741 | * mark DMA as up and running on this device | ||
742 | */ | ||
743 | cy_as_device_set_dma_running(dev_p); | ||
744 | |||
745 | return CY_AS_ERROR_SUCCESS; | ||
746 | } | ||
747 | |||
748 | /* | ||
749 | * Wait for all entries in the DMA queue associated | ||
750 | * the given endpoint to be drained. This function | ||
751 | * will not return until all the DMA data has been | ||
752 | * transferred. | ||
753 | */ | ||
754 | cy_as_return_status_t | ||
755 | cy_as_dma_drain_queue(cy_as_device *dev_p, | ||
756 | cy_as_end_point_number_t ep, cy_bool kickstart) | ||
757 | { | ||
758 | cy_as_dma_end_point *ep_p; | ||
759 | int loopcount = 1000; | ||
760 | uint32_t mask; | ||
761 | |||
762 | /* | ||
763 | * make sure the endpoint is valid | ||
764 | */ | ||
765 | if (ep >= sizeof(dev_p->endp)/sizeof(dev_p->endp[0])) | ||
766 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
767 | |||
768 | /* Get the endpoint pointer based on the endpoint number */ | ||
769 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
770 | |||
771 | /* | ||
772 | * if the endpoint is empty of traffic, we return | ||
773 | * with success immediately | ||
774 | */ | ||
775 | mask = cy_as_hal_disable_interrupts(); | ||
776 | if (ep_p->queue_p == 0) { | ||
777 | cy_as_hal_enable_interrupts(mask); | ||
778 | return CY_AS_ERROR_SUCCESS; | ||
779 | } else { | ||
780 | /* | ||
781 | * add 10 seconds to the time out value for each 64 KB segment | ||
782 | * of data to be transferred. | ||
783 | */ | ||
784 | if (ep_p->queue_p->size > 0x10000) | ||
785 | loopcount += ((ep_p->queue_p->size / 0x10000) * 1000); | ||
786 | } | ||
787 | cy_as_hal_enable_interrupts(mask); | ||
788 | |||
789 | /* If we are already sleeping on this endpoint, it is an error */ | ||
790 | if (cy_as_dma_end_point_is_sleeping(ep_p)) | ||
791 | return CY_AS_ERROR_NESTED_SLEEP; | ||
792 | |||
793 | /* | ||
794 | * we disable the endpoint while the queue drains to | ||
795 | * prevent any additional requests from being queued while we are waiting | ||
796 | */ | ||
797 | cy_as_dma_enable_end_point(dev_p, ep, | ||
798 | cy_false, cy_as_direction_dont_change); | ||
799 | |||
800 | if (kickstart) { | ||
801 | /* | ||
802 | * now, kick start the DMA if necessary | ||
803 | */ | ||
804 | cy_as_dma_kick_start(dev_p, ep); | ||
805 | } | ||
806 | |||
807 | /* | ||
808 | * check one last time before we begin sleeping to see if the | ||
809 | * queue is drained. | ||
810 | */ | ||
811 | if (ep_p->queue_p == 0) { | ||
812 | cy_as_dma_enable_end_point(dev_p, ep, cy_true, | ||
813 | cy_as_direction_dont_change); | ||
814 | return CY_AS_ERROR_SUCCESS; | ||
815 | } | ||
816 | |||
817 | while (loopcount-- > 0) { | ||
818 | /* | ||
819 | * sleep for 10 ms maximum (per loop) while | ||
820 | * waiting for the transfer to complete. | ||
821 | */ | ||
822 | cy_as_dma_end_point_set_sleep_state(ep_p); | ||
823 | cy_as_hal_sleep_on(&ep_p->channel, 10); | ||
824 | |||
825 | /* If we timed out, the sleep bit will still be set */ | ||
826 | cy_as_dma_end_point_set_wake_state(ep_p); | ||
827 | |||
828 | /* Check the queue to see if is drained */ | ||
829 | if (ep_p->queue_p == 0) { | ||
830 | /* | ||
831 | * clear the endpoint running and in transit flags | ||
832 | * for the endpoint, now that its DMA queue is empty. | ||
833 | */ | ||
834 | cy_as_dma_end_point_clear_in_transit(ep_p); | ||
835 | cy_as_dma_end_point_set_stopped(ep_p); | ||
836 | |||
837 | cy_as_dma_enable_end_point(dev_p, ep, | ||
838 | cy_true, cy_as_direction_dont_change); | ||
839 | return CY_AS_ERROR_SUCCESS; | ||
840 | } | ||
841 | } | ||
842 | |||
843 | /* | ||
844 | * the DMA operation that has timed out can be cancelled, so that later | ||
845 | * operations on this queue can proceed. | ||
846 | */ | ||
847 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_TIMEOUT); | ||
848 | cy_as_dma_enable_end_point(dev_p, ep, | ||
849 | cy_true, cy_as_direction_dont_change); | ||
850 | return CY_AS_ERROR_TIMEOUT; | ||
851 | } | ||
852 | |||
853 | /* | ||
854 | * This function queues a write request in the DMA queue | ||
855 | * for a given endpoint. The direction of the | ||
856 | * entry will be inferred from the endpoint direction. | ||
857 | */ | ||
858 | cy_as_return_status_t | ||
859 | cy_as_dma_queue_request(cy_as_device *dev_p, | ||
860 | cy_as_end_point_number_t ep, void *mem_p, | ||
861 | uint32_t size, cy_bool pkt, cy_bool readreq, cy_as_dma_callback cb) | ||
862 | { | ||
863 | uint32_t mask; | ||
864 | cy_as_dma_queue_entry *entry_p; | ||
865 | cy_as_dma_end_point *ep_p; | ||
866 | |||
867 | /* | ||
868 | * make sure the endpoint is valid | ||
869 | */ | ||
870 | if (ep >= sizeof(dev_p->endp)/sizeof(dev_p->endp[0])) | ||
871 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
872 | |||
873 | /* Get the endpoint pointer based on the endpoint number */ | ||
874 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
875 | |||
876 | if (!cy_as_dma_end_point_is_enabled(ep_p)) | ||
877 | return CY_AS_ERROR_ENDPOINT_DISABLED; | ||
878 | |||
879 | entry_p = cy_as_dma_get_dma_queue_entry(dev_p); | ||
880 | |||
881 | entry_p->buf_p = mem_p; | ||
882 | entry_p->cb = cb; | ||
883 | entry_p->size = size; | ||
884 | entry_p->offset = 0; | ||
885 | entry_p->packet = pkt; | ||
886 | entry_p->readreq = readreq; | ||
887 | |||
888 | mask = cy_as_hal_disable_interrupts(); | ||
889 | entry_p->next_p = 0; | ||
890 | if (ep_p->last_p) | ||
891 | ep_p->last_p->next_p = entry_p; | ||
892 | ep_p->last_p = entry_p; | ||
893 | if (ep_p->queue_p == 0) | ||
894 | ep_p->queue_p = entry_p; | ||
895 | cy_as_hal_enable_interrupts(mask); | ||
896 | |||
897 | return CY_AS_ERROR_SUCCESS; | ||
898 | } | ||
899 | |||
900 | /* | ||
901 | * This function enables or disables and endpoint for DMA | ||
902 | * queueing. If an endpoint is disabled, any queue requests | ||
903 | * continue to be processed, but no new requests can be queued. | ||
904 | */ | ||
905 | cy_as_return_status_t | ||
906 | cy_as_dma_enable_end_point(cy_as_device *dev_p, | ||
907 | cy_as_end_point_number_t ep, cy_bool enable, cy_as_dma_direction dir) | ||
908 | { | ||
909 | cy_as_dma_end_point *ep_p; | ||
910 | |||
911 | /* | ||
912 | * make sure the endpoint is valid | ||
913 | */ | ||
914 | if (ep >= sizeof(dev_p->endp)/sizeof(dev_p->endp[0])) | ||
915 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
916 | |||
917 | /* Get the endpoint pointer based on the endpoint number */ | ||
918 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
919 | |||
920 | if (dir == cy_as_direction_out) | ||
921 | cy_as_dma_end_point_set_direction_out(ep_p); | ||
922 | else if (dir == cy_as_direction_in) | ||
923 | cy_as_dma_end_point_set_direction_in(ep_p); | ||
924 | |||
925 | /* | ||
926 | * get the maximum size of data buffer the HAL | ||
927 | * layer can accept. this is used when the DMA | ||
928 | * module is sending DMA requests to the HAL. | ||
929 | * the DMA module will never send down a request | ||
930 | * that is greater than this value. | ||
931 | * | ||
932 | * for EP0 and EP1, we can send no more than 64 | ||
933 | * bytes of data at one time as this is the maximum | ||
934 | * size of a packet that can be sent via these | ||
935 | * endpoints. | ||
936 | */ | ||
937 | if (ep == 0 || ep == 1) | ||
938 | ep_p->maxhaldata = 64; | ||
939 | else | ||
940 | ep_p->maxhaldata = cy_as_hal_dma_max_request_size( | ||
941 | dev_p->tag, ep); | ||
942 | |||
943 | if (enable) | ||
944 | cy_as_dma_end_point_enable(ep_p); | ||
945 | else | ||
946 | cy_as_dma_end_point_disable(ep_p); | ||
947 | |||
948 | return CY_AS_ERROR_SUCCESS; | ||
949 | } | ||
950 | |||
951 | /* | ||
952 | * This function cancels any DMA operations pending with the HAL layer as well | ||
953 | * as any DMA operation queued on the endpoint. | ||
954 | */ | ||
955 | cy_as_return_status_t | ||
956 | cy_as_dma_cancel( | ||
957 | cy_as_device *dev_p, | ||
958 | cy_as_end_point_number_t ep, | ||
959 | cy_as_return_status_t err) | ||
960 | { | ||
961 | uint32_t mask; | ||
962 | cy_as_dma_end_point *ep_p; | ||
963 | cy_as_dma_queue_entry *entry_p; | ||
964 | cy_bool epstate; | ||
965 | |||
966 | /* | ||
967 | * make sure the endpoint is valid | ||
968 | */ | ||
969 | if (ep >= sizeof(dev_p->endp)/sizeof(dev_p->endp[0])) | ||
970 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
971 | |||
972 | /* Get the endpoint pointer based on the endpoint number */ | ||
973 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
974 | |||
975 | if (ep_p) { | ||
976 | /* Remember the state of the endpoint */ | ||
977 | epstate = cy_as_dma_end_point_is_enabled(ep_p); | ||
978 | |||
979 | /* | ||
980 | * disable the endpoint so no more DMA packets can be | ||
981 | * queued. | ||
982 | */ | ||
983 | cy_as_dma_enable_end_point(dev_p, ep, | ||
984 | cy_false, cy_as_direction_dont_change); | ||
985 | |||
986 | /* | ||
987 | * don't allow any interrupts from this endpoint | ||
988 | * while we get the most current request off of | ||
989 | * the queue. | ||
990 | */ | ||
991 | cy_as_dma_set_drq(dev_p, ep, cy_false); | ||
992 | |||
993 | /* | ||
994 | * cancel any pending request queued in the HAL layer | ||
995 | */ | ||
996 | if (cy_as_dma_end_point_in_transit(ep_p)) | ||
997 | cy_as_hal_dma_cancel_request(dev_p->tag, ep_p->ep); | ||
998 | |||
999 | /* | ||
1000 | * shutdown the DMA for this endpoint so no | ||
1001 | * more data is transferred | ||
1002 | */ | ||
1003 | cy_as_dma_end_point_set_stopped(ep_p); | ||
1004 | |||
1005 | /* | ||
1006 | * mark the endpoint as not in transit, because we are | ||
1007 | * going to consume any queued requests | ||
1008 | */ | ||
1009 | cy_as_dma_end_point_clear_in_transit(ep_p); | ||
1010 | |||
1011 | /* | ||
1012 | * now, remove each entry in the queue and call the | ||
1013 | * associated callback stating that the request was | ||
1014 | * canceled. | ||
1015 | */ | ||
1016 | ep_p->last_p = 0; | ||
1017 | while (ep_p->queue_p != 0) { | ||
1018 | /* Disable interrupts to manipulate the queue */ | ||
1019 | mask = cy_as_hal_disable_interrupts(); | ||
1020 | |||
1021 | /* Remove an entry from the queue */ | ||
1022 | entry_p = ep_p->queue_p; | ||
1023 | ep_p->queue_p = entry_p->next_p; | ||
1024 | |||
1025 | /* Ok, the queue has been updated, we can | ||
1026 | * turn interrupts back on */ | ||
1027 | cy_as_hal_enable_interrupts(mask); | ||
1028 | |||
1029 | /* Call the callback indicating we have | ||
1030 | * canceled the DMA */ | ||
1031 | if (entry_p->cb) | ||
1032 | entry_p->cb(dev_p, ep, | ||
1033 | entry_p->buf_p, entry_p->size, err); | ||
1034 | |||
1035 | cy_as_dma_add_request_to_free_queue(dev_p, entry_p); | ||
1036 | } | ||
1037 | |||
1038 | if (ep == 0 || ep == 1) { | ||
1039 | /* | ||
1040 | * if this endpoint is zero or one, we need to | ||
1041 | * clear the queue of any pending CY_RQT_USB_EP_DATA | ||
1042 | * requests as these are pending requests to send | ||
1043 | * data to the west bridge device. | ||
1044 | */ | ||
1045 | cy_as_ll_remove_ep_data_requests(dev_p, ep); | ||
1046 | } | ||
1047 | |||
1048 | if (epstate) { | ||
1049 | /* | ||
1050 | * the endpoint started out enabled, so we | ||
1051 | * re-enable the endpoint here. | ||
1052 | */ | ||
1053 | cy_as_dma_enable_end_point(dev_p, ep, | ||
1054 | cy_true, cy_as_direction_dont_change); | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | return CY_AS_ERROR_SUCCESS; | ||
1059 | } | ||
1060 | |||
1061 | cy_as_return_status_t | ||
1062 | cy_as_dma_received_data(cy_as_device *dev_p, | ||
1063 | cy_as_end_point_number_t ep, uint32_t dsize, void *data) | ||
1064 | { | ||
1065 | cy_as_dma_queue_entry *dma_p; | ||
1066 | uint8_t *src_p, *dest_p; | ||
1067 | cy_as_dma_end_point *ep_p; | ||
1068 | uint32_t xfersize; | ||
1069 | |||
1070 | /* | ||
1071 | * make sure the endpoint is valid | ||
1072 | */ | ||
1073 | if (ep != 0 && ep != 1) | ||
1074 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
1075 | |||
1076 | /* Get the endpoint pointer based on the endpoint number */ | ||
1077 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
1078 | dma_p = ep_p->queue_p; | ||
1079 | if (dma_p == 0) | ||
1080 | return CY_AS_ERROR_SUCCESS; | ||
1081 | |||
1082 | /* | ||
1083 | * if the data received exceeds the size of the DMA buffer, | ||
1084 | * clip the data to the size of the buffer. this can lead | ||
1085 | * to losing some data, but is not different than doing | ||
1086 | * non-packet reads on the other endpoints. | ||
1087 | */ | ||
1088 | if (dsize > dma_p->size - dma_p->offset) | ||
1089 | dsize = dma_p->size - dma_p->offset; | ||
1090 | |||
1091 | /* | ||
1092 | * copy the data from the request packet to the DMA buffer | ||
1093 | * for the endpoint | ||
1094 | */ | ||
1095 | src_p = (uint8_t *)data; | ||
1096 | dest_p = ((uint8_t *)(dma_p->buf_p)) + dma_p->offset; | ||
1097 | xfersize = dsize; | ||
1098 | while (xfersize-- > 0) | ||
1099 | *dest_p++ = *src_p++; | ||
1100 | |||
1101 | /* Signal the DMA module that we have | ||
1102 | * received data for this EP request */ | ||
1103 | cy_as_dma_completed_callback(dev_p->tag, | ||
1104 | ep, dsize, CY_AS_ERROR_SUCCESS); | ||
1105 | |||
1106 | return CY_AS_ERROR_SUCCESS; | ||
1107 | } | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasintr.c b/drivers/staging/westbridge/astoria/api/src/cyasintr.c deleted file mode 100644 index b60f69ce5985..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasintr.c +++ /dev/null | |||
@@ -1,143 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyasintr.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasdevice.h" | ||
24 | #include "../../include/linux/westbridge/cyasregs.h" | ||
25 | #include "../../include/linux/westbridge/cyaserr.h" | ||
26 | |||
27 | extern void cy_as_mail_box_interrupt_handler(cy_as_device *); | ||
28 | |||
29 | void | ||
30 | cy_as_mcu_interrupt_handler(cy_as_device *dev_p) | ||
31 | { | ||
32 | /* Read and clear the interrupt. */ | ||
33 | uint16_t v; | ||
34 | |||
35 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_MCU_STAT); | ||
36 | v = v; | ||
37 | } | ||
38 | |||
39 | void | ||
40 | cy_as_power_management_interrupt_handler(cy_as_device *dev_p) | ||
41 | { | ||
42 | uint16_t v; | ||
43 | |||
44 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PWR_MAGT_STAT); | ||
45 | v = v; | ||
46 | } | ||
47 | |||
48 | void | ||
49 | cy_as_pll_lock_loss_interrupt_handler(cy_as_device *dev_p) | ||
50 | { | ||
51 | uint16_t v; | ||
52 | |||
53 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PLL_LOCK_LOSS_STAT); | ||
54 | v = v; | ||
55 | } | ||
56 | |||
57 | uint32_t cy_as_intr_start(cy_as_device *dev_p, cy_bool dmaintr) | ||
58 | { | ||
59 | uint16_t v; | ||
60 | |||
61 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
62 | |||
63 | if (cy_as_device_is_intr_running(dev_p) != 0) | ||
64 | return CY_AS_ERROR_ALREADY_RUNNING; | ||
65 | |||
66 | v = CY_AS_MEM_P0_INT_MASK_REG_MMCUINT | | ||
67 | CY_AS_MEM_P0_INT_MASK_REG_MMBINT | | ||
68 | CY_AS_MEM_P0_INT_MASK_REG_MPMINT; | ||
69 | |||
70 | if (dmaintr) | ||
71 | v |= CY_AS_MEM_P0_INT_MASK_REG_MDRQINT; | ||
72 | |||
73 | /* Enable the interrupts of interest */ | ||
74 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_INT_MASK_REG, v); | ||
75 | |||
76 | /* Mark the interrupt module as initialized */ | ||
77 | cy_as_device_set_intr_running(dev_p); | ||
78 | |||
79 | return CY_AS_ERROR_SUCCESS; | ||
80 | } | ||
81 | |||
82 | uint32_t cy_as_intr_stop(cy_as_device *dev_p) | ||
83 | { | ||
84 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
85 | |||
86 | if (cy_as_device_is_intr_running(dev_p) == 0) | ||
87 | return CY_AS_ERROR_NOT_RUNNING; | ||
88 | |||
89 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_INT_MASK_REG, 0); | ||
90 | cy_as_device_set_intr_stopped(dev_p); | ||
91 | |||
92 | return CY_AS_ERROR_SUCCESS; | ||
93 | } | ||
94 | |||
95 | void cy_as_intr_service_interrupt(cy_as_hal_device_tag tag) | ||
96 | { | ||
97 | uint16_t v; | ||
98 | cy_as_device *dev_p; | ||
99 | |||
100 | dev_p = cy_as_device_find_from_tag(tag); | ||
101 | |||
102 | /* | ||
103 | * only power management interrupts can occur before the | ||
104 | * antioch API setup is complete. if this is a PM interrupt | ||
105 | * handle it here; otherwise output a warning message. | ||
106 | */ | ||
107 | if (dev_p == 0) { | ||
108 | v = cy_as_hal_read_register(tag, CY_AS_MEM_P0_INTR_REG); | ||
109 | if (v == CY_AS_MEM_P0_INTR_REG_PMINT) { | ||
110 | /* Read the PWR_MAGT_STAT register | ||
111 | * to clear this interrupt. */ | ||
112 | v = cy_as_hal_read_register(tag, | ||
113 | CY_AS_MEM_PWR_MAGT_STAT); | ||
114 | } else | ||
115 | cy_as_hal_print_message("stray antioch " | ||
116 | "interrupt detected" | ||
117 | ", tag not associated " | ||
118 | "with any created device."); | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | /* Make sure we got a valid object from CyAsDeviceFindFromTag */ | ||
123 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
124 | |||
125 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_INTR_REG); | ||
126 | |||
127 | if (v & CY_AS_MEM_P0_INTR_REG_MCUINT) | ||
128 | cy_as_mcu_interrupt_handler(dev_p); | ||
129 | |||
130 | if (v & CY_AS_MEM_P0_INTR_REG_PMINT) | ||
131 | cy_as_power_management_interrupt_handler(dev_p); | ||
132 | |||
133 | if (v & CY_AS_MEM_P0_INTR_REG_PLLLOCKINT) | ||
134 | cy_as_pll_lock_loss_interrupt_handler(dev_p); | ||
135 | |||
136 | /* If the interrupt module is not running, no mailbox | ||
137 | * interrupts are expected from the west bridge. */ | ||
138 | if (cy_as_device_is_intr_running(dev_p) == 0) | ||
139 | return; | ||
140 | |||
141 | if (v & CY_AS_MEM_P0_INTR_REG_MBINT) | ||
142 | cy_as_mail_box_interrupt_handler(dev_p); | ||
143 | } | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyaslep2pep.c b/drivers/staging/westbridge/astoria/api/src/cyaslep2pep.c deleted file mode 100644 index 76821e51b817..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyaslep2pep.c +++ /dev/null | |||
@@ -1,358 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyaslep2pep.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasusb.h" | ||
24 | #include "../../include/linux/westbridge/cyaserr.h" | ||
25 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
26 | #include "../../include/linux/westbridge/cyasdma.h" | ||
27 | |||
28 | typedef enum cy_as_physical_endpoint_state { | ||
29 | cy_as_e_p_free, | ||
30 | cy_as_e_p_in, | ||
31 | cy_as_e_p_out, | ||
32 | cy_as_e_p_iso_in, | ||
33 | cy_as_e_p_iso_out | ||
34 | } cy_as_physical_endpoint_state; | ||
35 | |||
36 | |||
37 | /* | ||
38 | * This map is used to map an index between 1 and 10 | ||
39 | * to a logical endpoint number. This is used to map | ||
40 | * LEP register indexes into actual EP numbers. | ||
41 | */ | ||
42 | static cy_as_end_point_number_t end_point_map[] = { | ||
43 | 3, 5, 7, 9, 10, 11, 12, 13, 14, 15 }; | ||
44 | |||
45 | #define CY_AS_EPCFG_1024 (1 << 3) | ||
46 | #define CY_AS_EPCFG_DBL (0x02) | ||
47 | #define CY_AS_EPCFG_TRIPLE (0x03) | ||
48 | #define CY_AS_EPCFG_QUAD (0x00) | ||
49 | |||
50 | /* | ||
51 | * NB: This table contains the register values for PEP1 | ||
52 | * and PEP3. PEP2 and PEP4 only have a bit to change the | ||
53 | * direction of the PEP and therefre are not represented | ||
54 | * in this table. | ||
55 | */ | ||
56 | static uint8_t pep_register_values[12][4] = { | ||
57 | /* Bit 1:0 buffering, 0 = quad, 2 = double, 3 = triple */ | ||
58 | /* Bit 3 size, 0 = 512, 1 = 1024 */ | ||
59 | { | ||
60 | CY_AS_EPCFG_DBL, | ||
61 | CY_AS_EPCFG_DBL, | ||
62 | },/* Config 1 - PEP1 (2 * 512), PEP2 (2 * 512), | ||
63 | * PEP3 (2 * 512), PEP4 (2 * 512) */ | ||
64 | { | ||
65 | CY_AS_EPCFG_DBL, | ||
66 | CY_AS_EPCFG_QUAD, | ||
67 | }, /* Config 2 - PEP1 (2 * 512), PEP2 (2 * 512), | ||
68 | * PEP3 (4 * 512), PEP4 (N/A) */ | ||
69 | { | ||
70 | CY_AS_EPCFG_DBL, | ||
71 | CY_AS_EPCFG_DBL | CY_AS_EPCFG_1024, | ||
72 | },/* Config 3 - PEP1 (2 * 512), PEP2 (2 * 512), | ||
73 | * PEP3 (2 * 1024), PEP4(N/A) */ | ||
74 | { | ||
75 | CY_AS_EPCFG_QUAD, | ||
76 | CY_AS_EPCFG_DBL, | ||
77 | },/* Config 4 - PEP1 (4 * 512), PEP2 (N/A), | ||
78 | * PEP3 (2 * 512), PEP4 (2 * 512) */ | ||
79 | { | ||
80 | CY_AS_EPCFG_QUAD, | ||
81 | CY_AS_EPCFG_QUAD, | ||
82 | },/* Config 5 - PEP1 (4 * 512), PEP2 (N/A), | ||
83 | * PEP3 (4 * 512), PEP4 (N/A) */ | ||
84 | { | ||
85 | CY_AS_EPCFG_QUAD, | ||
86 | CY_AS_EPCFG_1024 | CY_AS_EPCFG_DBL, | ||
87 | },/* Config 6 - PEP1 (4 * 512), PEP2 (N/A), | ||
88 | * PEP3 (2 * 1024), PEP4 (N/A) */ | ||
89 | { | ||
90 | CY_AS_EPCFG_1024 | CY_AS_EPCFG_DBL, | ||
91 | CY_AS_EPCFG_DBL, | ||
92 | },/* Config 7 - PEP1 (2 * 1024), PEP2 (N/A), | ||
93 | * PEP3 (2 * 512), PEP4 (2 * 512) */ | ||
94 | { | ||
95 | CY_AS_EPCFG_1024 | CY_AS_EPCFG_DBL, | ||
96 | CY_AS_EPCFG_QUAD, | ||
97 | },/* Config 8 - PEP1 (2 * 1024), PEP2 (N/A), | ||
98 | * PEP3 (4 * 512), PEP4 (N/A) */ | ||
99 | { | ||
100 | CY_AS_EPCFG_1024 | CY_AS_EPCFG_DBL, | ||
101 | CY_AS_EPCFG_1024 | CY_AS_EPCFG_DBL, | ||
102 | },/* Config 9 - PEP1 (2 * 1024), PEP2 (N/A), | ||
103 | * PEP3 (2 * 1024), PEP4 (N/A)*/ | ||
104 | { | ||
105 | CY_AS_EPCFG_TRIPLE, | ||
106 | CY_AS_EPCFG_TRIPLE, | ||
107 | },/* Config 10 - PEP1 (3 * 512), PEP2 (N/A), | ||
108 | * PEP3 (3 * 512), PEP4 (2 * 512)*/ | ||
109 | { | ||
110 | CY_AS_EPCFG_TRIPLE | CY_AS_EPCFG_1024, | ||
111 | CY_AS_EPCFG_DBL, | ||
112 | },/* Config 11 - PEP1 (3 * 1024), PEP2 (N/A), | ||
113 | * PEP3 (N/A), PEP4 (2 * 512) */ | ||
114 | { | ||
115 | CY_AS_EPCFG_QUAD | CY_AS_EPCFG_1024, | ||
116 | CY_AS_EPCFG_DBL, | ||
117 | },/* Config 12 - PEP1 (4 * 1024), PEP2 (N/A), | ||
118 | * PEP3 (N/A), PEP4 (N/A) */ | ||
119 | }; | ||
120 | |||
121 | static cy_as_return_status_t | ||
122 | find_endpoint_directions(cy_as_device *dev_p, | ||
123 | cy_as_physical_endpoint_state epstate[4]) | ||
124 | { | ||
125 | int i; | ||
126 | cy_as_physical_endpoint_state desired; | ||
127 | |||
128 | /* | ||
129 | * note, there is no error checking here because | ||
130 | * ISO error checking happens when the API is called. | ||
131 | */ | ||
132 | for (i = 0; i < 10; i++) { | ||
133 | int epno = end_point_map[i]; | ||
134 | if (dev_p->usb_config[epno].enabled) { | ||
135 | int pep = dev_p->usb_config[epno].physical; | ||
136 | if (dev_p->usb_config[epno].type == cy_as_usb_iso) { | ||
137 | /* | ||
138 | * marking this as an ISO endpoint, removes the | ||
139 | * physical EP from consideration when | ||
140 | * mapping the remaining E_ps. | ||
141 | */ | ||
142 | if (dev_p->usb_config[epno].dir == cy_as_usb_in) | ||
143 | desired = cy_as_e_p_iso_in; | ||
144 | else | ||
145 | desired = cy_as_e_p_iso_out; | ||
146 | } else { | ||
147 | if (dev_p->usb_config[epno].dir == cy_as_usb_in) | ||
148 | desired = cy_as_e_p_in; | ||
149 | else | ||
150 | desired = cy_as_e_p_out; | ||
151 | } | ||
152 | |||
153 | /* | ||
154 | * NB: Note the API calls insure that an ISO endpoint | ||
155 | * has a physical and logical EP number that are the | ||
156 | * same, therefore this condition is not enforced here. | ||
157 | */ | ||
158 | if (epstate[pep - 1] != | ||
159 | cy_as_e_p_free && epstate[pep - 1] != desired) | ||
160 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
161 | |||
162 | epstate[pep - 1] = desired; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /* | ||
167 | * create the EP1 config values directly. | ||
168 | * both EP1OUT and EP1IN are invalid by default. | ||
169 | */ | ||
170 | dev_p->usb_ep1cfg[0] = 0; | ||
171 | dev_p->usb_ep1cfg[1] = 0; | ||
172 | if (dev_p->usb_config[1].enabled) { | ||
173 | if ((dev_p->usb_config[1].dir == cy_as_usb_out) || | ||
174 | (dev_p->usb_config[1].dir == cy_as_usb_in_out)) { | ||
175 | /* Set the valid bit and type field. */ | ||
176 | dev_p->usb_ep1cfg[0] = (1 << 7); | ||
177 | if (dev_p->usb_config[1].type == cy_as_usb_bulk) | ||
178 | dev_p->usb_ep1cfg[0] |= (2 << 4); | ||
179 | else | ||
180 | dev_p->usb_ep1cfg[0] |= (3 << 4); | ||
181 | } | ||
182 | |||
183 | if ((dev_p->usb_config[1].dir == cy_as_usb_in) || | ||
184 | (dev_p->usb_config[1].dir == cy_as_usb_in_out)) { | ||
185 | /* Set the valid bit and type field. */ | ||
186 | dev_p->usb_ep1cfg[1] = (1 << 7); | ||
187 | if (dev_p->usb_config[1].type == cy_as_usb_bulk) | ||
188 | dev_p->usb_ep1cfg[1] |= (2 << 4); | ||
189 | else | ||
190 | dev_p->usb_ep1cfg[1] |= (3 << 4); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | return CY_AS_ERROR_SUCCESS; | ||
195 | } | ||
196 | |||
197 | static void | ||
198 | create_register_settings(cy_as_device *dev_p, | ||
199 | cy_as_physical_endpoint_state epstate[4]) | ||
200 | { | ||
201 | int i; | ||
202 | uint8_t v; | ||
203 | |||
204 | for (i = 0; i < 4; i++) { | ||
205 | if (i == 0) { | ||
206 | /* Start with the values that specify size */ | ||
207 | dev_p->usb_pepcfg[i] = | ||
208 | pep_register_values | ||
209 | [dev_p->usb_phy_config - 1][0]; | ||
210 | } else if (i == 2) { | ||
211 | /* Start with the values that specify size */ | ||
212 | dev_p->usb_pepcfg[i] = | ||
213 | pep_register_values | ||
214 | [dev_p->usb_phy_config - 1][1]; | ||
215 | } else | ||
216 | dev_p->usb_pepcfg[i] = 0; | ||
217 | |||
218 | /* Adjust direction if it is in */ | ||
219 | if (epstate[i] == cy_as_e_p_iso_in || | ||
220 | epstate[i] == cy_as_e_p_in) | ||
221 | dev_p->usb_pepcfg[i] |= (1 << 6); | ||
222 | } | ||
223 | |||
224 | /* Configure the logical EP registers */ | ||
225 | for (i = 0; i < 10; i++) { | ||
226 | int val; | ||
227 | int epnum = end_point_map[i]; | ||
228 | |||
229 | v = 0x10; /* PEP 1, Bulk Endpoint, EP not valid */ | ||
230 | if (dev_p->usb_config[epnum].enabled) { | ||
231 | v |= (1 << 7); /* Enabled */ | ||
232 | |||
233 | val = dev_p->usb_config[epnum].physical - 1; | ||
234 | cy_as_hal_assert(val >= 0 && val <= 3); | ||
235 | v |= (val << 5); | ||
236 | |||
237 | switch (dev_p->usb_config[epnum].type) { | ||
238 | case cy_as_usb_bulk: | ||
239 | val = 2; | ||
240 | break; | ||
241 | case cy_as_usb_int: | ||
242 | val = 3; | ||
243 | break; | ||
244 | case cy_as_usb_iso: | ||
245 | val = 1; | ||
246 | break; | ||
247 | default: | ||
248 | cy_as_hal_assert(cy_false); | ||
249 | break; | ||
250 | } | ||
251 | v |= (val << 3); | ||
252 | } | ||
253 | |||
254 | dev_p->usb_lepcfg[i] = v; | ||
255 | } | ||
256 | } | ||
257 | |||
258 | |||
259 | cy_as_return_status_t | ||
260 | cy_as_usb_map_logical2_physical(cy_as_device *dev_p) | ||
261 | { | ||
262 | cy_as_return_status_t ret; | ||
263 | |||
264 | /* Physical EPs 3 5 7 9 respectively in the array */ | ||
265 | cy_as_physical_endpoint_state epstate[4] = { | ||
266 | cy_as_e_p_free, cy_as_e_p_free, | ||
267 | cy_as_e_p_free, cy_as_e_p_free }; | ||
268 | |||
269 | /* Find the direction for the endpoints */ | ||
270 | ret = find_endpoint_directions(dev_p, epstate); | ||
271 | if (ret != CY_AS_ERROR_SUCCESS) | ||
272 | return ret; | ||
273 | |||
274 | /* | ||
275 | * now create the register settings based on the given | ||
276 | * assigned of logical E_ps to physical endpoints. | ||
277 | */ | ||
278 | create_register_settings(dev_p, epstate); | ||
279 | |||
280 | return ret; | ||
281 | } | ||
282 | |||
283 | static uint16_t | ||
284 | get_max_dma_size(cy_as_device *dev_p, cy_as_end_point_number_t ep) | ||
285 | { | ||
286 | uint16_t size = dev_p->usb_config[ep].size; | ||
287 | |||
288 | if (size == 0) { | ||
289 | switch (dev_p->usb_config[ep].type) { | ||
290 | case cy_as_usb_control: | ||
291 | size = 64; | ||
292 | break; | ||
293 | |||
294 | case cy_as_usb_bulk: | ||
295 | size = cy_as_device_is_usb_high_speed(dev_p) ? | ||
296 | 512 : 64; | ||
297 | break; | ||
298 | |||
299 | case cy_as_usb_int: | ||
300 | size = cy_as_device_is_usb_high_speed(dev_p) ? | ||
301 | 1024 : 64; | ||
302 | break; | ||
303 | |||
304 | case cy_as_usb_iso: | ||
305 | size = cy_as_device_is_usb_high_speed(dev_p) ? | ||
306 | 1024 : 1023; | ||
307 | break; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | return size; | ||
312 | } | ||
313 | |||
314 | cy_as_return_status_t | ||
315 | cy_as_usb_set_dma_sizes(cy_as_device *dev_p) | ||
316 | { | ||
317 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
318 | uint32_t i; | ||
319 | |||
320 | for (i = 0; i < 10; i++) { | ||
321 | cy_as_usb_end_point_config *config_p = | ||
322 | &dev_p->usb_config[end_point_map[i]]; | ||
323 | if (config_p->enabled) { | ||
324 | ret = cy_as_dma_set_max_dma_size(dev_p, | ||
325 | end_point_map[i], | ||
326 | get_max_dma_size(dev_p, end_point_map[i])); | ||
327 | if (ret != CY_AS_ERROR_SUCCESS) | ||
328 | break; | ||
329 | } | ||
330 | } | ||
331 | |||
332 | return ret; | ||
333 | } | ||
334 | |||
335 | cy_as_return_status_t | ||
336 | cy_as_usb_setup_dma(cy_as_device *dev_p) | ||
337 | { | ||
338 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
339 | uint32_t i; | ||
340 | |||
341 | for (i = 0; i < 10; i++) { | ||
342 | cy_as_usb_end_point_config *config_p = | ||
343 | &dev_p->usb_config[end_point_map[i]]; | ||
344 | if (config_p->enabled) { | ||
345 | /* Map the endpoint direction to the DMA direction */ | ||
346 | cy_as_dma_direction dir = cy_as_direction_out; | ||
347 | if (config_p->dir == cy_as_usb_in) | ||
348 | dir = cy_as_direction_in; | ||
349 | |||
350 | ret = cy_as_dma_enable_end_point(dev_p, | ||
351 | end_point_map[i], cy_true, dir); | ||
352 | if (ret != CY_AS_ERROR_SUCCESS) | ||
353 | break; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | return ret; | ||
358 | } | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyaslowlevel.c b/drivers/staging/westbridge/astoria/api/src/cyaslowlevel.c deleted file mode 100644 index 96a86d088305..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyaslowlevel.c +++ /dev/null | |||
@@ -1,1264 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyaslowlevel.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyascast.h" | ||
24 | #include "../../include/linux/westbridge/cyasdevice.h" | ||
25 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
26 | #include "../../include/linux/westbridge/cyasintr.h" | ||
27 | #include "../../include/linux/westbridge/cyaserr.h" | ||
28 | #include "../../include/linux/westbridge/cyasregs.h" | ||
29 | |||
30 | static const uint32_t cy_as_low_level_timeout_count = 65536 * 4; | ||
31 | |||
32 | /* Forward declaration */ | ||
33 | static cy_as_return_status_t cy_as_send_one(cy_as_device *dev_p, | ||
34 | cy_as_ll_request_response *req_p); | ||
35 | |||
36 | /* | ||
37 | * This array holds the size of the largest request we will ever recevie from | ||
38 | * the West Bridge device per context. The size is in 16 bit words. Note a | ||
39 | * size of 0xffff indicates that there will be no requests on this context | ||
40 | * from West Bridge. | ||
41 | */ | ||
42 | static uint16_t max_request_length[CY_RQT_CONTEXT_COUNT] = { | ||
43 | 8, /* CY_RQT_GENERAL_RQT_CONTEXT - CY_RQT_INITIALIZATION_COMPLETE */ | ||
44 | 8, /* CY_RQT_RESOURCE_RQT_CONTEXT - none */ | ||
45 | 8, /* CY_RQT_STORAGE_RQT_CONTEXT - CY_RQT_MEDIA_CHANGED */ | ||
46 | 128, /* CY_RQT_USB_RQT_CONTEXT - CY_RQT_USB_EVENT */ | ||
47 | 8 /* CY_RQT_TUR_RQT_CONTEXT - CY_RQT_TURBO_CMD_FROM_HOST */ | ||
48 | }; | ||
49 | |||
50 | /* | ||
51 | * For the given context, this function removes the request node at the head | ||
52 | * of the queue from the context. This is called after all processing has | ||
53 | * occurred on the given request and response and we are ready to remove this | ||
54 | * entry from the queue. | ||
55 | */ | ||
56 | static void | ||
57 | cy_as_ll_remove_request_queue_head(cy_as_device *dev_p, cy_as_context *ctxt_p) | ||
58 | { | ||
59 | uint32_t mask, state; | ||
60 | cy_as_ll_request_list_node *node_p; | ||
61 | |||
62 | (void)dev_p; | ||
63 | cy_as_hal_assert(ctxt_p->request_queue_p != 0); | ||
64 | |||
65 | mask = cy_as_hal_disable_interrupts(); | ||
66 | node_p = ctxt_p->request_queue_p; | ||
67 | ctxt_p->request_queue_p = node_p->next; | ||
68 | cy_as_hal_enable_interrupts(mask); | ||
69 | |||
70 | node_p->callback = 0; | ||
71 | node_p->rqt = 0; | ||
72 | node_p->resp = 0; | ||
73 | |||
74 | /* | ||
75 | * note that the caller allocates and destroys the request and | ||
76 | * response. generally the destroy happens in the callback for | ||
77 | * async requests and after the wait returns for sync. the | ||
78 | * request and response may not actually be destroyed but may be | ||
79 | * managed in other ways as well. it is the responsibilty of | ||
80 | * the caller to deal with these in any case. the caller can do | ||
81 | * this in the request/response callback function. | ||
82 | */ | ||
83 | state = cy_as_hal_disable_interrupts(); | ||
84 | cy_as_hal_c_b_free(node_p); | ||
85 | cy_as_hal_enable_interrupts(state); | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * For the context given, this function sends the next request to | ||
90 | * West Bridge via the mailbox register, if the next request is | ||
91 | * ready to be sent and has not already been sent. | ||
92 | */ | ||
93 | static void | ||
94 | cy_as_ll_send_next_request(cy_as_device *dev_p, cy_as_context *ctxt_p) | ||
95 | { | ||
96 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
97 | |||
98 | /* | ||
99 | * ret == ret is equivalent to while (1) but eliminates compiler | ||
100 | * warnings for some compilers. | ||
101 | */ | ||
102 | while (ret == ret) { | ||
103 | cy_as_ll_request_list_node *node_p = ctxt_p->request_queue_p; | ||
104 | if (node_p == 0) | ||
105 | break; | ||
106 | |||
107 | if (cy_as_request_get_node_state(node_p) != | ||
108 | CY_AS_REQUEST_LIST_STATE_QUEUED) | ||
109 | break; | ||
110 | |||
111 | cy_as_request_set_node_state(node_p, | ||
112 | CY_AS_REQUEST_LIST_STATE_WAITING); | ||
113 | ret = cy_as_send_one(dev_p, node_p->rqt); | ||
114 | if (ret == CY_AS_ERROR_SUCCESS) | ||
115 | break; | ||
116 | |||
117 | /* | ||
118 | * if an error occurs in sending the request, tell the requester | ||
119 | * about the error and remove the request from the queue. | ||
120 | */ | ||
121 | cy_as_request_set_node_state(node_p, | ||
122 | CY_AS_REQUEST_LIST_STATE_RECEIVED); | ||
123 | node_p->callback(dev_p, ctxt_p->number, | ||
124 | node_p->rqt, node_p->resp, ret); | ||
125 | cy_as_ll_remove_request_queue_head(dev_p, ctxt_p); | ||
126 | |||
127 | /* | ||
128 | * this falls through to the while loop to send the next request | ||
129 | * since the previous request did not get sent. | ||
130 | */ | ||
131 | } | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * This method removes an entry from the request queue of a given context. | ||
136 | * The entry is removed only if it is not in transit. | ||
137 | */ | ||
138 | cy_as_remove_request_result_t | ||
139 | cy_as_ll_remove_request(cy_as_device *dev_p, cy_as_context *ctxt_p, | ||
140 | cy_as_ll_request_response *req_p, cy_bool force) | ||
141 | { | ||
142 | uint32_t imask; | ||
143 | cy_as_ll_request_list_node *node_p; | ||
144 | cy_as_ll_request_list_node *tmp_p; | ||
145 | uint32_t state; | ||
146 | |||
147 | imask = cy_as_hal_disable_interrupts(); | ||
148 | if (ctxt_p->request_queue_p != 0 && | ||
149 | ctxt_p->request_queue_p->rqt == req_p) { | ||
150 | node_p = ctxt_p->request_queue_p; | ||
151 | if ((cy_as_request_get_node_state(node_p) == | ||
152 | CY_AS_REQUEST_LIST_STATE_WAITING) && (!force)) { | ||
153 | cy_as_hal_enable_interrupts(imask); | ||
154 | return cy_as_remove_request_in_transit; | ||
155 | } | ||
156 | |||
157 | ctxt_p->request_queue_p = node_p->next; | ||
158 | } else { | ||
159 | tmp_p = ctxt_p->request_queue_p; | ||
160 | while (tmp_p != 0 && tmp_p->next != 0 && | ||
161 | tmp_p->next->rqt != req_p) | ||
162 | tmp_p = tmp_p->next; | ||
163 | |||
164 | if (tmp_p == 0 || tmp_p->next == 0) { | ||
165 | cy_as_hal_enable_interrupts(imask); | ||
166 | return cy_as_remove_request_not_found; | ||
167 | } | ||
168 | |||
169 | node_p = tmp_p->next; | ||
170 | tmp_p->next = node_p->next; | ||
171 | } | ||
172 | |||
173 | if (node_p->callback) | ||
174 | node_p->callback(dev_p, ctxt_p->number, node_p->rqt, | ||
175 | node_p->resp, CY_AS_ERROR_CANCELED); | ||
176 | |||
177 | state = cy_as_hal_disable_interrupts(); | ||
178 | cy_as_hal_c_b_free(node_p); | ||
179 | cy_as_hal_enable_interrupts(state); | ||
180 | |||
181 | cy_as_hal_enable_interrupts(imask); | ||
182 | return cy_as_remove_request_sucessful; | ||
183 | } | ||
184 | |||
185 | void | ||
186 | cy_as_ll_remove_all_requests(cy_as_device *dev_p, cy_as_context *ctxt_p) | ||
187 | { | ||
188 | cy_as_ll_request_list_node *node = ctxt_p->request_queue_p; | ||
189 | |||
190 | while (node) { | ||
191 | if (cy_as_request_get_node_state(ctxt_p->request_queue_p) != | ||
192 | CY_AS_REQUEST_LIST_STATE_RECEIVED) | ||
193 | cy_as_ll_remove_request(dev_p, ctxt_p, | ||
194 | node->rqt, cy_true); | ||
195 | node = node->next; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | static cy_bool | ||
200 | cy_as_ll_is_in_queue(cy_as_context *ctxt_p, cy_as_ll_request_response *req_p) | ||
201 | { | ||
202 | uint32_t mask; | ||
203 | cy_as_ll_request_list_node *node_p; | ||
204 | |||
205 | mask = cy_as_hal_disable_interrupts(); | ||
206 | node_p = ctxt_p->request_queue_p; | ||
207 | while (node_p) { | ||
208 | if (node_p->rqt == req_p) { | ||
209 | cy_as_hal_enable_interrupts(mask); | ||
210 | return cy_true; | ||
211 | } | ||
212 | node_p = node_p->next; | ||
213 | } | ||
214 | cy_as_hal_enable_interrupts(mask); | ||
215 | return cy_false; | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * This is the handler for mailbox data when we are trying to send data | ||
220 | * to the West Bridge firmware. The firmware may be trying to send us | ||
221 | * data and we need to queue this data to allow the firmware to move | ||
222 | * forward and be in a state to receive our request. Here we just queue | ||
223 | * the data and it is processed at a later time by the mailbox interrupt | ||
224 | * handler. | ||
225 | */ | ||
226 | void | ||
227 | cy_as_ll_queue_mailbox_data(cy_as_device *dev_p) | ||
228 | { | ||
229 | cy_as_context *ctxt_p; | ||
230 | uint8_t context; | ||
231 | uint16_t data[4]; | ||
232 | int32_t i; | ||
233 | |||
234 | /* Read the data from mailbox 0 to determine what to do with the data */ | ||
235 | for (i = 3; i >= 0; i--) | ||
236 | data[i] = cy_as_hal_read_register(dev_p->tag, | ||
237 | cy_cast_int2U_int16(CY_AS_MEM_P0_MAILBOX0 + i)); | ||
238 | |||
239 | context = cy_as_mbox_get_context(data[0]); | ||
240 | if (context >= CY_RQT_CONTEXT_COUNT) { | ||
241 | cy_as_hal_print_message("mailbox request/response received " | ||
242 | "with invalid context value (%d)\n", context); | ||
243 | return; | ||
244 | } | ||
245 | |||
246 | ctxt_p = dev_p->context[context]; | ||
247 | |||
248 | /* | ||
249 | * if we have queued too much data, drop future data. | ||
250 | */ | ||
251 | cy_as_hal_assert(ctxt_p->queue_index * sizeof(uint16_t) + | ||
252 | sizeof(data) <= sizeof(ctxt_p->data_queue)); | ||
253 | |||
254 | for (i = 0; i < 4; i++) | ||
255 | ctxt_p->data_queue[ctxt_p->queue_index++] = data[i]; | ||
256 | |||
257 | cy_as_hal_assert((ctxt_p->queue_index % 4) == 0); | ||
258 | dev_p->ll_queued_data = cy_true; | ||
259 | } | ||
260 | |||
261 | void | ||
262 | cy_as_mail_box_process_data(cy_as_device *dev_p, uint16_t *data) | ||
263 | { | ||
264 | cy_as_context *ctxt_p; | ||
265 | uint8_t context; | ||
266 | uint16_t *len_p; | ||
267 | cy_as_ll_request_response *rec_p; | ||
268 | uint8_t st; | ||
269 | uint16_t src, dest; | ||
270 | |||
271 | context = cy_as_mbox_get_context(data[0]); | ||
272 | if (context >= CY_RQT_CONTEXT_COUNT) { | ||
273 | cy_as_hal_print_message("mailbox request/response received " | ||
274 | "with invalid context value (%d)\n", context); | ||
275 | return; | ||
276 | } | ||
277 | |||
278 | ctxt_p = dev_p->context[context]; | ||
279 | |||
280 | if (cy_as_mbox_is_request(data[0])) { | ||
281 | cy_as_hal_assert(ctxt_p->req_p != 0); | ||
282 | rec_p = ctxt_p->req_p; | ||
283 | len_p = &ctxt_p->request_length; | ||
284 | |||
285 | } else { | ||
286 | if (ctxt_p->request_queue_p == 0 || | ||
287 | cy_as_request_get_node_state(ctxt_p->request_queue_p) | ||
288 | != CY_AS_REQUEST_LIST_STATE_WAITING) { | ||
289 | cy_as_hal_print_message("mailbox response received on " | ||
290 | "context that was not expecting a response\n"); | ||
291 | cy_as_hal_print_message(" context: %d\n", context); | ||
292 | cy_as_hal_print_message(" contents: 0x%04x 0x%04x " | ||
293 | "0x%04x 0x%04x\n", | ||
294 | data[0], data[1], data[2], data[3]); | ||
295 | if (ctxt_p->request_queue_p != 0) | ||
296 | cy_as_hal_print_message(" state: 0x%02x\n", | ||
297 | ctxt_p->request_queue_p->state); | ||
298 | return; | ||
299 | } | ||
300 | |||
301 | /* Make sure the request has an associated response */ | ||
302 | cy_as_hal_assert(ctxt_p->request_queue_p->resp != 0); | ||
303 | |||
304 | rec_p = ctxt_p->request_queue_p->resp; | ||
305 | len_p = &ctxt_p->request_queue_p->length; | ||
306 | } | ||
307 | |||
308 | if (rec_p->stored == 0) { | ||
309 | /* | ||
310 | * this is the first cycle of the response | ||
311 | */ | ||
312 | cy_as_ll_request_response__set_code(rec_p, | ||
313 | cy_as_mbox_get_code(data[0])); | ||
314 | cy_as_ll_request_response__set_context(rec_p, context); | ||
315 | |||
316 | if (cy_as_mbox_is_last(data[0])) { | ||
317 | /* This is a single cycle response */ | ||
318 | *len_p = rec_p->length; | ||
319 | st = 1; | ||
320 | } else { | ||
321 | /* Ensure that enough memory has been | ||
322 | * reserved for the response. */ | ||
323 | cy_as_hal_assert(rec_p->length >= data[1]); | ||
324 | *len_p = (data[1] < rec_p->length) ? | ||
325 | data[1] : rec_p->length; | ||
326 | st = 2; | ||
327 | } | ||
328 | } else | ||
329 | st = 1; | ||
330 | |||
331 | /* Trasnfer the data from the mailboxes to the response */ | ||
332 | while (rec_p->stored < *len_p && st < 4) | ||
333 | rec_p->data[rec_p->stored++] = data[st++]; | ||
334 | |||
335 | if (cy_as_mbox_is_last(data[0])) { | ||
336 | /* NB: The call-back that is made below can cause the | ||
337 | * addition of more data in this queue, thus causing | ||
338 | * a recursive overflow of the queue. this is prevented | ||
339 | * by removing the request entry that is currently | ||
340 | * being passed up from the data queue. if this is done, | ||
341 | * the queue only needs to be as long as two request | ||
342 | * entries from west bridge. | ||
343 | */ | ||
344 | if ((ctxt_p->rqt_index > 0) && | ||
345 | (ctxt_p->rqt_index <= ctxt_p->queue_index)) { | ||
346 | dest = 0; | ||
347 | src = ctxt_p->rqt_index; | ||
348 | |||
349 | while (src < ctxt_p->queue_index) | ||
350 | ctxt_p->data_queue[dest++] = | ||
351 | ctxt_p->data_queue[src++]; | ||
352 | |||
353 | ctxt_p->rqt_index = 0; | ||
354 | ctxt_p->queue_index = dest; | ||
355 | cy_as_hal_assert((ctxt_p->queue_index % 4) == 0); | ||
356 | } | ||
357 | |||
358 | if (ctxt_p->request_queue_p != 0 && rec_p == | ||
359 | ctxt_p->request_queue_p->resp) { | ||
360 | /* | ||
361 | * if this is the last cycle of the response, call the | ||
362 | * callback and reset for the next response. | ||
363 | */ | ||
364 | cy_as_ll_request_response *resp_p = | ||
365 | ctxt_p->request_queue_p->resp; | ||
366 | resp_p->length = ctxt_p->request_queue_p->length; | ||
367 | cy_as_request_set_node_state(ctxt_p->request_queue_p, | ||
368 | CY_AS_REQUEST_LIST_STATE_RECEIVED); | ||
369 | |||
370 | cy_as_device_set_in_callback(dev_p); | ||
371 | ctxt_p->request_queue_p->callback(dev_p, context, | ||
372 | ctxt_p->request_queue_p->rqt, | ||
373 | resp_p, CY_AS_ERROR_SUCCESS); | ||
374 | |||
375 | cy_as_device_clear_in_callback(dev_p); | ||
376 | |||
377 | cy_as_ll_remove_request_queue_head(dev_p, ctxt_p); | ||
378 | cy_as_ll_send_next_request(dev_p, ctxt_p); | ||
379 | } else { | ||
380 | /* Send the request to the appropriate | ||
381 | * module to handle */ | ||
382 | cy_as_ll_request_response *request_p = ctxt_p->req_p; | ||
383 | ctxt_p->req_p = 0; | ||
384 | if (ctxt_p->request_callback) { | ||
385 | cy_as_device_set_in_callback(dev_p); | ||
386 | ctxt_p->request_callback(dev_p, context, | ||
387 | request_p, 0, CY_AS_ERROR_SUCCESS); | ||
388 | cy_as_device_clear_in_callback(dev_p); | ||
389 | } | ||
390 | cy_as_ll_init_request(request_p, 0, | ||
391 | context, request_p->length); | ||
392 | ctxt_p->req_p = request_p; | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | |||
397 | /* | ||
398 | * This is the handler for processing queued mailbox data | ||
399 | */ | ||
400 | void | ||
401 | cy_as_mail_box_queued_data_handler(cy_as_device *dev_p) | ||
402 | { | ||
403 | uint16_t i; | ||
404 | |||
405 | /* | ||
406 | * if more data gets queued in between our entering this call | ||
407 | * and the end of the iteration on all contexts; we should | ||
408 | * continue processing the queued data. | ||
409 | */ | ||
410 | while (dev_p->ll_queued_data) { | ||
411 | dev_p->ll_queued_data = cy_false; | ||
412 | for (i = 0; i < CY_RQT_CONTEXT_COUNT; i++) { | ||
413 | uint16_t offset; | ||
414 | cy_as_context *ctxt_p = dev_p->context[i]; | ||
415 | cy_as_hal_assert((ctxt_p->queue_index % 4) == 0); | ||
416 | |||
417 | offset = 0; | ||
418 | while (offset < ctxt_p->queue_index) { | ||
419 | ctxt_p->rqt_index = offset + 4; | ||
420 | cy_as_mail_box_process_data(dev_p, | ||
421 | ctxt_p->data_queue + offset); | ||
422 | offset = ctxt_p->rqt_index; | ||
423 | } | ||
424 | ctxt_p->queue_index = 0; | ||
425 | } | ||
426 | } | ||
427 | } | ||
428 | |||
429 | /* | ||
430 | * This is the handler for the mailbox interrupt. This function reads | ||
431 | * data from the mailbox registers until a complete request or response | ||
432 | * is received. When a complete request is received, the callback | ||
433 | * associated with requests on that context is called. When a complete | ||
434 | * response is recevied, the callback associated with the request that | ||
435 | * generated the response is called. | ||
436 | */ | ||
437 | void | ||
438 | cy_as_mail_box_interrupt_handler(cy_as_device *dev_p) | ||
439 | { | ||
440 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
441 | |||
442 | /* | ||
443 | * queue the mailbox data to preserve | ||
444 | * order for later processing. | ||
445 | */ | ||
446 | cy_as_ll_queue_mailbox_data(dev_p); | ||
447 | |||
448 | /* | ||
449 | * process what was queued and anything that may be pending | ||
450 | */ | ||
451 | cy_as_mail_box_queued_data_handler(dev_p); | ||
452 | } | ||
453 | |||
454 | cy_as_return_status_t | ||
455 | cy_as_ll_start(cy_as_device *dev_p) | ||
456 | { | ||
457 | uint16_t i; | ||
458 | |||
459 | if (cy_as_device_is_low_level_running(dev_p)) | ||
460 | return CY_AS_ERROR_ALREADY_RUNNING; | ||
461 | |||
462 | dev_p->ll_sending_rqt = cy_false; | ||
463 | dev_p->ll_abort_curr_rqt = cy_false; | ||
464 | |||
465 | for (i = 0; i < CY_RQT_CONTEXT_COUNT; i++) { | ||
466 | dev_p->context[i] = (cy_as_context *) | ||
467 | cy_as_hal_alloc(sizeof(cy_as_context)); | ||
468 | if (dev_p->context[i] == 0) | ||
469 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
470 | |||
471 | dev_p->context[i]->number = (uint8_t)i; | ||
472 | dev_p->context[i]->request_callback = 0; | ||
473 | dev_p->context[i]->request_queue_p = 0; | ||
474 | dev_p->context[i]->last_node_p = 0; | ||
475 | dev_p->context[i]->req_p = cy_as_ll_create_request(dev_p, | ||
476 | 0, (uint8_t)i, max_request_length[i]); | ||
477 | dev_p->context[i]->queue_index = 0; | ||
478 | |||
479 | if (!cy_as_hal_create_sleep_channel | ||
480 | (&dev_p->context[i]->channel)) | ||
481 | return CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED; | ||
482 | } | ||
483 | |||
484 | cy_as_device_set_low_level_running(dev_p); | ||
485 | return CY_AS_ERROR_SUCCESS; | ||
486 | } | ||
487 | |||
488 | /* | ||
489 | * Shutdown the low level communications module. This operation will | ||
490 | * also cancel any queued low level requests. | ||
491 | */ | ||
492 | cy_as_return_status_t | ||
493 | cy_as_ll_stop(cy_as_device *dev_p) | ||
494 | { | ||
495 | uint8_t i; | ||
496 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
497 | cy_as_context *ctxt_p; | ||
498 | uint32_t mask; | ||
499 | |||
500 | for (i = 0; i < CY_RQT_CONTEXT_COUNT; i++) { | ||
501 | ctxt_p = dev_p->context[i]; | ||
502 | if (!cy_as_hal_destroy_sleep_channel(&ctxt_p->channel)) | ||
503 | return CY_AS_ERROR_DESTROY_SLEEP_CHANNEL_FAILED; | ||
504 | |||
505 | /* | ||
506 | * now, free any queued requests and assocaited responses | ||
507 | */ | ||
508 | while (ctxt_p->request_queue_p) { | ||
509 | uint32_t state; | ||
510 | cy_as_ll_request_list_node *node_p = | ||
511 | ctxt_p->request_queue_p; | ||
512 | |||
513 | /* Mark this pair as in a cancel operation */ | ||
514 | cy_as_request_set_node_state(node_p, | ||
515 | CY_AS_REQUEST_LIST_STATE_CANCELING); | ||
516 | |||
517 | /* Tell the caller that we are canceling this request */ | ||
518 | /* NB: The callback is responsible for destroying the | ||
519 | * request and the response. we cannot count on the | ||
520 | * contents of these two after calling the callback. | ||
521 | */ | ||
522 | node_p->callback(dev_p, i, node_p->rqt, | ||
523 | node_p->resp, CY_AS_ERROR_CANCELED); | ||
524 | |||
525 | /* Remove the pair from the queue */ | ||
526 | mask = cy_as_hal_disable_interrupts(); | ||
527 | ctxt_p->request_queue_p = node_p->next; | ||
528 | cy_as_hal_enable_interrupts(mask); | ||
529 | |||
530 | /* Free the list node */ | ||
531 | state = cy_as_hal_disable_interrupts(); | ||
532 | cy_as_hal_c_b_free(node_p); | ||
533 | cy_as_hal_enable_interrupts(state); | ||
534 | } | ||
535 | |||
536 | cy_as_ll_destroy_request(dev_p, dev_p->context[i]->req_p); | ||
537 | cy_as_hal_free(dev_p->context[i]); | ||
538 | dev_p->context[i] = 0; | ||
539 | |||
540 | } | ||
541 | cy_as_device_set_low_level_stopped(dev_p); | ||
542 | |||
543 | return ret; | ||
544 | } | ||
545 | |||
546 | void | ||
547 | cy_as_ll_init_request(cy_as_ll_request_response *req_p, | ||
548 | uint16_t code, uint16_t context, uint16_t length) | ||
549 | { | ||
550 | uint16_t totallen = sizeof(cy_as_ll_request_response) + | ||
551 | (length - 1) * sizeof(uint16_t); | ||
552 | |||
553 | cy_as_hal_mem_set(req_p, 0, totallen); | ||
554 | req_p->length = length; | ||
555 | cy_as_ll_request_response__set_code(req_p, code); | ||
556 | cy_as_ll_request_response__set_context(req_p, context); | ||
557 | cy_as_ll_request_response__set_request(req_p); | ||
558 | } | ||
559 | |||
560 | /* | ||
561 | * Create a new request. | ||
562 | */ | ||
563 | cy_as_ll_request_response * | ||
564 | cy_as_ll_create_request(cy_as_device *dev_p, uint16_t code, | ||
565 | uint8_t context, uint16_t length) | ||
566 | { | ||
567 | cy_as_ll_request_response *req_p; | ||
568 | uint32_t state; | ||
569 | uint16_t totallen = sizeof(cy_as_ll_request_response) + | ||
570 | (length - 1) * sizeof(uint16_t); | ||
571 | |||
572 | (void)dev_p; | ||
573 | |||
574 | state = cy_as_hal_disable_interrupts(); | ||
575 | req_p = cy_as_hal_c_b_alloc(totallen); | ||
576 | cy_as_hal_enable_interrupts(state); | ||
577 | if (req_p) | ||
578 | cy_as_ll_init_request(req_p, code, context, length); | ||
579 | |||
580 | return req_p; | ||
581 | } | ||
582 | |||
583 | /* | ||
584 | * Destroy a request. | ||
585 | */ | ||
586 | void | ||
587 | cy_as_ll_destroy_request(cy_as_device *dev_p, cy_as_ll_request_response *req_p) | ||
588 | { | ||
589 | uint32_t state; | ||
590 | (void)dev_p; | ||
591 | (void)req_p; | ||
592 | |||
593 | state = cy_as_hal_disable_interrupts(); | ||
594 | cy_as_hal_c_b_free(req_p); | ||
595 | cy_as_hal_enable_interrupts(state); | ||
596 | |||
597 | } | ||
598 | |||
599 | void | ||
600 | cy_as_ll_init_response(cy_as_ll_request_response *req_p, uint16_t length) | ||
601 | { | ||
602 | uint16_t totallen = sizeof(cy_as_ll_request_response) + | ||
603 | (length - 1) * sizeof(uint16_t); | ||
604 | |||
605 | cy_as_hal_mem_set(req_p, 0, totallen); | ||
606 | req_p->length = length; | ||
607 | cy_as_ll_request_response__set_response(req_p); | ||
608 | } | ||
609 | |||
610 | /* | ||
611 | * Create a new response | ||
612 | */ | ||
613 | cy_as_ll_request_response * | ||
614 | cy_as_ll_create_response(cy_as_device *dev_p, uint16_t length) | ||
615 | { | ||
616 | cy_as_ll_request_response *req_p; | ||
617 | uint32_t state; | ||
618 | uint16_t totallen = sizeof(cy_as_ll_request_response) + | ||
619 | (length - 1) * sizeof(uint16_t); | ||
620 | |||
621 | (void)dev_p; | ||
622 | |||
623 | state = cy_as_hal_disable_interrupts(); | ||
624 | req_p = cy_as_hal_c_b_alloc(totallen); | ||
625 | cy_as_hal_enable_interrupts(state); | ||
626 | if (req_p) | ||
627 | cy_as_ll_init_response(req_p, length); | ||
628 | |||
629 | return req_p; | ||
630 | } | ||
631 | |||
632 | /* | ||
633 | * Destroy the new response | ||
634 | */ | ||
635 | void | ||
636 | cy_as_ll_destroy_response(cy_as_device *dev_p, cy_as_ll_request_response *req_p) | ||
637 | { | ||
638 | uint32_t state; | ||
639 | (void)dev_p; | ||
640 | (void)req_p; | ||
641 | |||
642 | state = cy_as_hal_disable_interrupts(); | ||
643 | cy_as_hal_c_b_free(req_p); | ||
644 | cy_as_hal_enable_interrupts(state); | ||
645 | } | ||
646 | |||
647 | static uint16_t | ||
648 | cy_as_read_intr_status( | ||
649 | cy_as_device *dev_p) | ||
650 | { | ||
651 | uint32_t mask; | ||
652 | cy_bool bloop = cy_true; | ||
653 | uint16_t v = 0, last = 0xffff; | ||
654 | |||
655 | /* | ||
656 | * before determining if the mailboxes are ready for more data, | ||
657 | * we first check the mailbox interrupt to see if we need to | ||
658 | * receive data. this prevents a dead-lock condition that can | ||
659 | * occur when both sides are trying to receive data. | ||
660 | */ | ||
661 | while (last == last) { | ||
662 | /* | ||
663 | * disable interrupts to be sure we don't process the mailbox | ||
664 | * here and have the interrupt routine try to read this data | ||
665 | * as well. | ||
666 | */ | ||
667 | mask = cy_as_hal_disable_interrupts(); | ||
668 | |||
669 | /* | ||
670 | * see if there is data to be read. | ||
671 | */ | ||
672 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_INTR_REG); | ||
673 | if ((v & CY_AS_MEM_P0_INTR_REG_MBINT) == 0) { | ||
674 | cy_as_hal_enable_interrupts(mask); | ||
675 | break; | ||
676 | } | ||
677 | |||
678 | /* | ||
679 | * queue the mailbox data for later processing. | ||
680 | * this allows the firmware to move forward and | ||
681 | * service the requst from the P port. | ||
682 | */ | ||
683 | cy_as_ll_queue_mailbox_data(dev_p); | ||
684 | |||
685 | /* | ||
686 | * enable interrupts again to service mailbox | ||
687 | * interrupts appropriately | ||
688 | */ | ||
689 | cy_as_hal_enable_interrupts(mask); | ||
690 | } | ||
691 | |||
692 | /* | ||
693 | * now, all data is received | ||
694 | */ | ||
695 | last = cy_as_hal_read_register(dev_p->tag, | ||
696 | CY_AS_MEM_MCU_MB_STAT) & CY_AS_MEM_P0_MCU_MBNOTRD; | ||
697 | while (bloop) { | ||
698 | v = cy_as_hal_read_register(dev_p->tag, | ||
699 | CY_AS_MEM_MCU_MB_STAT) & CY_AS_MEM_P0_MCU_MBNOTRD; | ||
700 | if (v == last) | ||
701 | break; | ||
702 | |||
703 | last = v; | ||
704 | } | ||
705 | |||
706 | return v; | ||
707 | } | ||
708 | |||
709 | /* | ||
710 | * Send a single request or response using the mail box register. | ||
711 | * This function does not deal with the internal queues at all, | ||
712 | * but only sends the request or response across to the firmware | ||
713 | */ | ||
714 | static cy_as_return_status_t | ||
715 | cy_as_send_one( | ||
716 | cy_as_device *dev_p, | ||
717 | cy_as_ll_request_response *req_p) | ||
718 | { | ||
719 | int i; | ||
720 | uint16_t mb0, v; | ||
721 | int32_t loopcount; | ||
722 | uint32_t int_stat; | ||
723 | |||
724 | #ifdef _DEBUG | ||
725 | if (cy_as_ll_request_response__is_request(req_p)) { | ||
726 | switch (cy_as_ll_request_response__get_context(req_p)) { | ||
727 | case CY_RQT_GENERAL_RQT_CONTEXT: | ||
728 | cy_as_hal_assert(req_p->length * 2 + 2 < | ||
729 | CY_CTX_GEN_MAX_DATA_SIZE); | ||
730 | break; | ||
731 | |||
732 | case CY_RQT_RESOURCE_RQT_CONTEXT: | ||
733 | cy_as_hal_assert(req_p->length * 2 + 2 < | ||
734 | CY_CTX_RES_MAX_DATA_SIZE); | ||
735 | break; | ||
736 | |||
737 | case CY_RQT_STORAGE_RQT_CONTEXT: | ||
738 | cy_as_hal_assert(req_p->length * 2 + 2 < | ||
739 | CY_CTX_STR_MAX_DATA_SIZE); | ||
740 | break; | ||
741 | |||
742 | case CY_RQT_USB_RQT_CONTEXT: | ||
743 | cy_as_hal_assert(req_p->length * 2 + 2 < | ||
744 | CY_CTX_USB_MAX_DATA_SIZE); | ||
745 | break; | ||
746 | } | ||
747 | } | ||
748 | #endif | ||
749 | |||
750 | /* Write the request to the mail box registers */ | ||
751 | if (req_p->length > 3) { | ||
752 | uint16_t length = req_p->length; | ||
753 | int which = 0; | ||
754 | int st = 1; | ||
755 | |||
756 | dev_p->ll_sending_rqt = cy_true; | ||
757 | while (which < length) { | ||
758 | loopcount = cy_as_low_level_timeout_count; | ||
759 | do { | ||
760 | v = cy_as_read_intr_status(dev_p); | ||
761 | |||
762 | } while (v && loopcount-- > 0); | ||
763 | |||
764 | if (v) { | ||
765 | cy_as_hal_print_message( | ||
766 | ">>>>>> LOW LEVEL TIMEOUT " | ||
767 | "%x %x %x %x\n", | ||
768 | cy_as_hal_read_register(dev_p->tag, | ||
769 | CY_AS_MEM_MCU_MAILBOX0), | ||
770 | cy_as_hal_read_register(dev_p->tag, | ||
771 | CY_AS_MEM_MCU_MAILBOX1), | ||
772 | cy_as_hal_read_register(dev_p->tag, | ||
773 | CY_AS_MEM_MCU_MAILBOX2), | ||
774 | cy_as_hal_read_register(dev_p->tag, | ||
775 | CY_AS_MEM_MCU_MAILBOX3)); | ||
776 | return CY_AS_ERROR_TIMEOUT; | ||
777 | } | ||
778 | |||
779 | if (dev_p->ll_abort_curr_rqt) { | ||
780 | dev_p->ll_sending_rqt = cy_false; | ||
781 | dev_p->ll_abort_curr_rqt = cy_false; | ||
782 | return CY_AS_ERROR_CANCELED; | ||
783 | } | ||
784 | |||
785 | int_stat = cy_as_hal_disable_interrupts(); | ||
786 | |||
787 | /* | ||
788 | * check again whether the mailbox is free. | ||
789 | * it is possible that an ISR came in and | ||
790 | * wrote into the mailboxes since we last | ||
791 | * checked the status. | ||
792 | */ | ||
793 | v = cy_as_hal_read_register(dev_p->tag, | ||
794 | CY_AS_MEM_MCU_MB_STAT) & | ||
795 | CY_AS_MEM_P0_MCU_MBNOTRD; | ||
796 | if (v) { | ||
797 | /* Go back to the original check since | ||
798 | * the mailbox is not free. */ | ||
799 | cy_as_hal_enable_interrupts(int_stat); | ||
800 | continue; | ||
801 | } | ||
802 | |||
803 | if (which == 0) { | ||
804 | cy_as_hal_write_register(dev_p->tag, | ||
805 | CY_AS_MEM_MCU_MAILBOX1, length); | ||
806 | st = 2; | ||
807 | } else { | ||
808 | st = 1; | ||
809 | } | ||
810 | |||
811 | while ((which < length) && (st < 4)) { | ||
812 | cy_as_hal_write_register(dev_p->tag, | ||
813 | cy_cast_int2U_int16 | ||
814 | (CY_AS_MEM_MCU_MAILBOX0 + st), | ||
815 | req_p->data[which++]); | ||
816 | st++; | ||
817 | } | ||
818 | |||
819 | mb0 = req_p->box0; | ||
820 | if (which == length) { | ||
821 | dev_p->ll_sending_rqt = cy_false; | ||
822 | mb0 |= CY_AS_REQUEST_RESPONSE_LAST_MASK; | ||
823 | } | ||
824 | |||
825 | if (dev_p->ll_abort_curr_rqt) { | ||
826 | dev_p->ll_sending_rqt = cy_false; | ||
827 | dev_p->ll_abort_curr_rqt = cy_false; | ||
828 | cy_as_hal_enable_interrupts(int_stat); | ||
829 | return CY_AS_ERROR_CANCELED; | ||
830 | } | ||
831 | |||
832 | cy_as_hal_write_register(dev_p->tag, | ||
833 | CY_AS_MEM_MCU_MAILBOX0, mb0); | ||
834 | |||
835 | /* Wait for the MBOX interrupt to be high */ | ||
836 | cy_as_hal_sleep150(); | ||
837 | cy_as_hal_enable_interrupts(int_stat); | ||
838 | } | ||
839 | } else { | ||
840 | check_mailbox_availability: | ||
841 | /* | ||
842 | * wait for the mailbox registers to become available. this | ||
843 | * should be a very quick wait as the firmware is designed | ||
844 | * to accept requests at interrupt time and queue them for | ||
845 | * future processing. | ||
846 | */ | ||
847 | loopcount = cy_as_low_level_timeout_count; | ||
848 | do { | ||
849 | v = cy_as_read_intr_status(dev_p); | ||
850 | |||
851 | } while (v && loopcount-- > 0); | ||
852 | |||
853 | if (v) { | ||
854 | cy_as_hal_print_message( | ||
855 | ">>>>>> LOW LEVEL TIMEOUT %x %x %x %x\n", | ||
856 | cy_as_hal_read_register(dev_p->tag, | ||
857 | CY_AS_MEM_MCU_MAILBOX0), | ||
858 | cy_as_hal_read_register(dev_p->tag, | ||
859 | CY_AS_MEM_MCU_MAILBOX1), | ||
860 | cy_as_hal_read_register(dev_p->tag, | ||
861 | CY_AS_MEM_MCU_MAILBOX2), | ||
862 | cy_as_hal_read_register(dev_p->tag, | ||
863 | CY_AS_MEM_MCU_MAILBOX3)); | ||
864 | return CY_AS_ERROR_TIMEOUT; | ||
865 | } | ||
866 | |||
867 | int_stat = cy_as_hal_disable_interrupts(); | ||
868 | |||
869 | /* | ||
870 | * check again whether the mailbox is free. it is | ||
871 | * possible that an ISR came in and wrote into the | ||
872 | * mailboxes since we last checked the status. | ||
873 | */ | ||
874 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_MCU_MB_STAT) & | ||
875 | CY_AS_MEM_P0_MCU_MBNOTRD; | ||
876 | if (v) { | ||
877 | /* Go back to the original check | ||
878 | * since the mailbox is not free. */ | ||
879 | cy_as_hal_enable_interrupts(int_stat); | ||
880 | goto check_mailbox_availability; | ||
881 | } | ||
882 | |||
883 | /* Write the data associated with the request | ||
884 | * into the mbox registers 1 - 3 */ | ||
885 | v = 0; | ||
886 | for (i = req_p->length - 1; i >= 0; i--) | ||
887 | cy_as_hal_write_register(dev_p->tag, | ||
888 | cy_cast_int2U_int16(CY_AS_MEM_MCU_MAILBOX1 + i), | ||
889 | req_p->data[i]); | ||
890 | |||
891 | /* Write the mbox register 0 to trigger the interrupt */ | ||
892 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_MCU_MAILBOX0, | ||
893 | req_p->box0 | CY_AS_REQUEST_RESPONSE_LAST_MASK); | ||
894 | |||
895 | cy_as_hal_sleep150(); | ||
896 | cy_as_hal_enable_interrupts(int_stat); | ||
897 | } | ||
898 | |||
899 | return CY_AS_ERROR_SUCCESS; | ||
900 | } | ||
901 | |||
902 | /* | ||
903 | * This function queues a single request to be sent to the firmware. | ||
904 | */ | ||
905 | extern cy_as_return_status_t | ||
906 | cy_as_ll_send_request( | ||
907 | cy_as_device *dev_p, | ||
908 | /* The request to send */ | ||
909 | cy_as_ll_request_response *req, | ||
910 | /* Storage for a reply, must be sure | ||
911 | * it is of sufficient size */ | ||
912 | cy_as_ll_request_response *resp, | ||
913 | /* If true, this is a synchronous request */ | ||
914 | cy_bool sync, | ||
915 | /* Callback to call when reply is received */ | ||
916 | cy_as_response_callback cb | ||
917 | ) | ||
918 | { | ||
919 | cy_as_context *ctxt_p; | ||
920 | uint16_t box0 = req->box0; | ||
921 | uint8_t context; | ||
922 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
923 | cy_as_ll_request_list_node *node_p; | ||
924 | uint32_t mask, state; | ||
925 | |||
926 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
927 | |||
928 | context = cy_as_mbox_get_context(box0); | ||
929 | cy_as_hal_assert(context < CY_RQT_CONTEXT_COUNT); | ||
930 | ctxt_p = dev_p->context[context]; | ||
931 | |||
932 | /* Allocate the list node */ | ||
933 | state = cy_as_hal_disable_interrupts(); | ||
934 | node_p = cy_as_hal_c_b_alloc(sizeof(cy_as_ll_request_list_node)); | ||
935 | cy_as_hal_enable_interrupts(state); | ||
936 | |||
937 | if (node_p == 0) | ||
938 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
939 | |||
940 | /* Initialize the list node */ | ||
941 | node_p->callback = cb; | ||
942 | node_p->length = 0; | ||
943 | node_p->next = 0; | ||
944 | node_p->resp = resp; | ||
945 | node_p->rqt = req; | ||
946 | node_p->state = CY_AS_REQUEST_LIST_STATE_QUEUED; | ||
947 | if (sync) | ||
948 | cy_as_request_node_set_sync(node_p); | ||
949 | |||
950 | /* Put the request into the queue */ | ||
951 | mask = cy_as_hal_disable_interrupts(); | ||
952 | if (ctxt_p->request_queue_p == 0) { | ||
953 | /* Empty queue */ | ||
954 | ctxt_p->request_queue_p = node_p; | ||
955 | ctxt_p->last_node_p = node_p; | ||
956 | } else { | ||
957 | ctxt_p->last_node_p->next = node_p; | ||
958 | ctxt_p->last_node_p = node_p; | ||
959 | } | ||
960 | cy_as_hal_enable_interrupts(mask); | ||
961 | cy_as_ll_send_next_request(dev_p, ctxt_p); | ||
962 | |||
963 | if (!cy_as_device_is_in_callback(dev_p)) { | ||
964 | mask = cy_as_hal_disable_interrupts(); | ||
965 | cy_as_mail_box_queued_data_handler(dev_p); | ||
966 | cy_as_hal_enable_interrupts(mask); | ||
967 | } | ||
968 | |||
969 | return ret; | ||
970 | } | ||
971 | |||
972 | static void | ||
973 | cy_as_ll_send_callback( | ||
974 | cy_as_device *dev_p, | ||
975 | uint8_t context, | ||
976 | cy_as_ll_request_response *rqt, | ||
977 | cy_as_ll_request_response *resp, | ||
978 | cy_as_return_status_t ret) | ||
979 | { | ||
980 | (void)rqt; | ||
981 | (void)resp; | ||
982 | (void)ret; | ||
983 | |||
984 | |||
985 | cy_as_hal_assert(dev_p->sig == CY_AS_DEVICE_HANDLE_SIGNATURE); | ||
986 | |||
987 | /* | ||
988 | * storage the state to return to the caller | ||
989 | */ | ||
990 | dev_p->ll_error = ret; | ||
991 | |||
992 | /* | ||
993 | * now wake the caller | ||
994 | */ | ||
995 | cy_as_hal_wake(&dev_p->context[context]->channel); | ||
996 | } | ||
997 | |||
998 | cy_as_return_status_t | ||
999 | cy_as_ll_send_request_wait_reply( | ||
1000 | cy_as_device *dev_p, | ||
1001 | /* The request to send */ | ||
1002 | cy_as_ll_request_response *req, | ||
1003 | /* Storage for a reply, must be | ||
1004 | * sure it is of sufficient size */ | ||
1005 | cy_as_ll_request_response *resp | ||
1006 | ) | ||
1007 | { | ||
1008 | cy_as_return_status_t ret; | ||
1009 | uint8_t context; | ||
1010 | /* Larger 8 sec time-out to handle the init | ||
1011 | * delay for slower storage devices in USB FS. */ | ||
1012 | uint32_t loopcount = 800; | ||
1013 | cy_as_context *ctxt_p; | ||
1014 | |||
1015 | /* Get the context for the request */ | ||
1016 | context = cy_as_ll_request_response__get_context(req); | ||
1017 | cy_as_hal_assert(context < CY_RQT_CONTEXT_COUNT); | ||
1018 | ctxt_p = dev_p->context[context]; | ||
1019 | |||
1020 | ret = cy_as_ll_send_request(dev_p, req, resp, | ||
1021 | cy_true, cy_as_ll_send_callback); | ||
1022 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1023 | return ret; | ||
1024 | |||
1025 | while (loopcount-- > 0) { | ||
1026 | /* | ||
1027 | * sleep while we wait on the response. receiving the reply will | ||
1028 | * wake this thread. we will wait, at most 2 seconds (10 ms*200 | ||
1029 | * tries) before we timeout. note if the reply arrives, we will | ||
1030 | * not sleep the entire 10 ms, just til the reply arrives. | ||
1031 | */ | ||
1032 | cy_as_hal_sleep_on(&ctxt_p->channel, 10); | ||
1033 | |||
1034 | /* | ||
1035 | * if the request has left the queue, it means the request has | ||
1036 | * been sent and the reply has been received. this means we can | ||
1037 | * return to the caller and be sure the reply has been received. | ||
1038 | */ | ||
1039 | if (!cy_as_ll_is_in_queue(ctxt_p, req)) | ||
1040 | return dev_p->ll_error; | ||
1041 | } | ||
1042 | |||
1043 | /* Remove the QueueListNode for this request. */ | ||
1044 | cy_as_ll_remove_request(dev_p, ctxt_p, req, cy_true); | ||
1045 | |||
1046 | return CY_AS_ERROR_TIMEOUT; | ||
1047 | } | ||
1048 | |||
1049 | cy_as_return_status_t | ||
1050 | cy_as_ll_register_request_callback( | ||
1051 | cy_as_device *dev_p, | ||
1052 | uint8_t context, | ||
1053 | cy_as_response_callback cb) | ||
1054 | { | ||
1055 | cy_as_context *ctxt_p; | ||
1056 | cy_as_hal_assert(context < CY_RQT_CONTEXT_COUNT); | ||
1057 | ctxt_p = dev_p->context[context]; | ||
1058 | |||
1059 | ctxt_p->request_callback = cb; | ||
1060 | return CY_AS_ERROR_SUCCESS; | ||
1061 | } | ||
1062 | |||
1063 | void | ||
1064 | cy_as_ll_request_response__pack( | ||
1065 | cy_as_ll_request_response *req_p, | ||
1066 | uint32_t offset, | ||
1067 | uint32_t length, | ||
1068 | void *data_p) | ||
1069 | { | ||
1070 | uint16_t dt; | ||
1071 | uint8_t *dp = (uint8_t *)data_p; | ||
1072 | |||
1073 | while (length > 1) { | ||
1074 | dt = ((*dp++) << 8); | ||
1075 | dt |= (*dp++); | ||
1076 | cy_as_ll_request_response__set_word(req_p, offset, dt); | ||
1077 | offset++; | ||
1078 | length -= 2; | ||
1079 | } | ||
1080 | |||
1081 | if (length == 1) { | ||
1082 | dt = (*dp << 8); | ||
1083 | cy_as_ll_request_response__set_word(req_p, offset, dt); | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | void | ||
1088 | cy_as_ll_request_response__unpack( | ||
1089 | cy_as_ll_request_response *req_p, | ||
1090 | uint32_t offset, | ||
1091 | uint32_t length, | ||
1092 | void *data_p) | ||
1093 | { | ||
1094 | uint8_t *dp = (uint8_t *)data_p; | ||
1095 | |||
1096 | while (length-- > 0) { | ||
1097 | uint16_t val = cy_as_ll_request_response__get_word | ||
1098 | (req_p, offset++); | ||
1099 | *dp++ = (uint8_t)((val >> 8) & 0xff); | ||
1100 | |||
1101 | if (length) { | ||
1102 | length--; | ||
1103 | *dp++ = (uint8_t)(val & 0xff); | ||
1104 | } | ||
1105 | } | ||
1106 | } | ||
1107 | |||
1108 | extern cy_as_return_status_t | ||
1109 | cy_as_ll_send_status_response( | ||
1110 | cy_as_device *dev_p, | ||
1111 | uint8_t context, | ||
1112 | uint16_t code, | ||
1113 | uint8_t clear_storage) | ||
1114 | { | ||
1115 | cy_as_return_status_t ret; | ||
1116 | cy_as_ll_request_response resp; | ||
1117 | cy_as_ll_request_response *resp_p = &resp; | ||
1118 | |||
1119 | cy_as_hal_mem_set(resp_p, 0, sizeof(resp)); | ||
1120 | resp_p->length = 1; | ||
1121 | cy_as_ll_request_response__set_response(resp_p); | ||
1122 | cy_as_ll_request_response__set_context(resp_p, context); | ||
1123 | |||
1124 | if (clear_storage) | ||
1125 | cy_as_ll_request_response__set_clear_storage_flag(resp_p); | ||
1126 | |||
1127 | cy_as_ll_request_response__set_code(resp_p, CY_RESP_SUCCESS_FAILURE); | ||
1128 | cy_as_ll_request_response__set_word(resp_p, 0, code); | ||
1129 | |||
1130 | ret = cy_as_send_one(dev_p, resp_p); | ||
1131 | |||
1132 | return ret; | ||
1133 | } | ||
1134 | |||
1135 | extern cy_as_return_status_t | ||
1136 | cy_as_ll_send_data_response( | ||
1137 | cy_as_device *dev_p, | ||
1138 | uint8_t context, | ||
1139 | uint16_t code, | ||
1140 | uint16_t length, | ||
1141 | void *data) | ||
1142 | { | ||
1143 | cy_as_ll_request_response *resp_p; | ||
1144 | uint16_t wlen; | ||
1145 | uint8_t respbuf[256]; | ||
1146 | |||
1147 | if (length > 192) | ||
1148 | return CY_AS_ERROR_INVALID_SIZE; | ||
1149 | |||
1150 | /* Word length for bytes */ | ||
1151 | wlen = length / 2; | ||
1152 | |||
1153 | /* If byte length odd, add one more */ | ||
1154 | if (length % 2) | ||
1155 | wlen++; | ||
1156 | |||
1157 | /* One for the length of field */ | ||
1158 | wlen++; | ||
1159 | |||
1160 | resp_p = (cy_as_ll_request_response *)respbuf; | ||
1161 | cy_as_hal_mem_set(resp_p, 0, sizeof(respbuf)); | ||
1162 | resp_p->length = wlen; | ||
1163 | cy_as_ll_request_response__set_context(resp_p, context); | ||
1164 | cy_as_ll_request_response__set_code(resp_p, code); | ||
1165 | |||
1166 | cy_as_ll_request_response__set_word(resp_p, 0, length); | ||
1167 | cy_as_ll_request_response__pack(resp_p, 1, length, data); | ||
1168 | |||
1169 | return cy_as_send_one(dev_p, resp_p); | ||
1170 | } | ||
1171 | |||
1172 | static cy_bool | ||
1173 | cy_as_ll_is_e_p_transfer_related_request(cy_as_ll_request_response *rqt_p, | ||
1174 | cy_as_end_point_number_t ep) | ||
1175 | { | ||
1176 | uint16_t v; | ||
1177 | uint8_t type = cy_as_ll_request_response__get_code(rqt_p); | ||
1178 | |||
1179 | if (cy_as_ll_request_response__get_context(rqt_p) != | ||
1180 | CY_RQT_USB_RQT_CONTEXT) | ||
1181 | return cy_false; | ||
1182 | |||
1183 | /* | ||
1184 | * when cancelling outstanding EP0 data transfers, any pending | ||
1185 | * setup ACK requests also need to be cancelled. | ||
1186 | */ | ||
1187 | if ((ep == 0) && (type == CY_RQT_ACK_SETUP_PACKET)) | ||
1188 | return cy_true; | ||
1189 | |||
1190 | if (type != CY_RQT_USB_EP_DATA) | ||
1191 | return cy_false; | ||
1192 | |||
1193 | v = cy_as_ll_request_response__get_word(rqt_p, 0); | ||
1194 | if ((cy_as_end_point_number_t)((v >> 13) & 1) != ep) | ||
1195 | return cy_false; | ||
1196 | |||
1197 | return cy_true; | ||
1198 | } | ||
1199 | |||
1200 | cy_as_return_status_t | ||
1201 | cy_as_ll_remove_ep_data_requests(cy_as_device *dev_p, | ||
1202 | cy_as_end_point_number_t ep) | ||
1203 | { | ||
1204 | cy_as_context *ctxt_p; | ||
1205 | cy_as_ll_request_list_node *node_p; | ||
1206 | uint32_t imask; | ||
1207 | |||
1208 | /* | ||
1209 | * first, remove any queued requests | ||
1210 | */ | ||
1211 | ctxt_p = dev_p->context[CY_RQT_USB_RQT_CONTEXT]; | ||
1212 | if (ctxt_p) { | ||
1213 | for (node_p = ctxt_p->request_queue_p; node_p; | ||
1214 | node_p = node_p->next) { | ||
1215 | if (cy_as_ll_is_e_p_transfer_related_request | ||
1216 | (node_p->rqt, ep)) { | ||
1217 | cy_as_ll_remove_request(dev_p, ctxt_p, | ||
1218 | node_p->rqt, cy_false); | ||
1219 | break; | ||
1220 | } | ||
1221 | } | ||
1222 | |||
1223 | /* | ||
1224 | * now, deal with any request that may be in transit | ||
1225 | */ | ||
1226 | imask = cy_as_hal_disable_interrupts(); | ||
1227 | |||
1228 | if (ctxt_p->request_queue_p != 0 && | ||
1229 | cy_as_ll_is_e_p_transfer_related_request | ||
1230 | (ctxt_p->request_queue_p->rqt, ep) && | ||
1231 | cy_as_request_get_node_state(ctxt_p->request_queue_p) == | ||
1232 | CY_AS_REQUEST_LIST_STATE_WAITING) { | ||
1233 | cy_as_hal_print_message("need to remove an in-transit " | ||
1234 | "request to antioch\n"); | ||
1235 | |||
1236 | /* | ||
1237 | * if the request has not been fully sent to west bridge | ||
1238 | * yet, abort sending. otherwise, terminate the request | ||
1239 | * with a CANCELED status. firmware will already have | ||
1240 | * terminated this transfer. | ||
1241 | */ | ||
1242 | if (dev_p->ll_sending_rqt) | ||
1243 | dev_p->ll_abort_curr_rqt = cy_true; | ||
1244 | else { | ||
1245 | uint32_t state; | ||
1246 | |||
1247 | node_p = ctxt_p->request_queue_p; | ||
1248 | if (node_p->callback) | ||
1249 | node_p->callback(dev_p, ctxt_p->number, | ||
1250 | node_p->rqt, node_p->resp, | ||
1251 | CY_AS_ERROR_CANCELED); | ||
1252 | |||
1253 | ctxt_p->request_queue_p = node_p->next; | ||
1254 | state = cy_as_hal_disable_interrupts(); | ||
1255 | cy_as_hal_c_b_free(node_p); | ||
1256 | cy_as_hal_enable_interrupts(state); | ||
1257 | } | ||
1258 | } | ||
1259 | |||
1260 | cy_as_hal_enable_interrupts(imask); | ||
1261 | } | ||
1262 | |||
1263 | return CY_AS_ERROR_SUCCESS; | ||
1264 | } | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasmisc.c b/drivers/staging/westbridge/astoria/api/src/cyasmisc.c deleted file mode 100644 index 4564fc11df22..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasmisc.c +++ /dev/null | |||
@@ -1,3488 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyasmisc.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasmisc.h" | ||
24 | #include "../../include/linux/westbridge/cyasdma.h" | ||
25 | #include "../../include/linux/westbridge/cyasintr.h" | ||
26 | #include "../../include/linux/westbridge/cyaserr.h" | ||
27 | #include "../../include/linux/westbridge/cyasregs.h" | ||
28 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
29 | #include "../../include/linux/westbridge/cyasprotocol.h" | ||
30 | |||
31 | /* | ||
32 | * The device list, the only global in the API | ||
33 | */ | ||
34 | static cy_as_device *g_device_list; | ||
35 | |||
36 | /* | ||
37 | * The current debug level | ||
38 | */ | ||
39 | static uint8_t debug_level; | ||
40 | |||
41 | /* | ||
42 | * This function sets the debug level for the API | ||
43 | * | ||
44 | */ | ||
45 | void | ||
46 | cy_as_misc_set_log_level(uint8_t level) | ||
47 | { | ||
48 | debug_level = level; | ||
49 | } | ||
50 | |||
51 | #ifdef CY_AS_LOG_SUPPORT | ||
52 | |||
53 | /* | ||
54 | * This function is a low level logger for the API. | ||
55 | */ | ||
56 | void | ||
57 | cy_as_log_debug_message(int level, const char *str) | ||
58 | { | ||
59 | if (level <= debug_level) | ||
60 | cy_as_hal_print_message("log %d: %s\n", level, str); | ||
61 | } | ||
62 | |||
63 | #endif | ||
64 | |||
65 | #define cy_as_check_device_ready(dev_p) \ | ||
66 | {\ | ||
67 | if (!(dev_p) || ((dev_p)->sig != \ | ||
68 | CY_AS_DEVICE_HANDLE_SIGNATURE)) \ | ||
69 | return CY_AS_ERROR_INVALID_HANDLE; \ | ||
70 | \ | ||
71 | if (!cy_as_device_is_configured(dev_p)) \ | ||
72 | return CY_AS_ERROR_NOT_CONFIGURED; \ | ||
73 | \ | ||
74 | if (!cy_as_device_is_firmware_loaded(dev_p))\ | ||
75 | return CY_AS_ERROR_NO_FIRMWARE; \ | ||
76 | } | ||
77 | |||
78 | /* Find an West Bridge device based on a TAG */ | ||
79 | cy_as_device * | ||
80 | cy_as_device_find_from_tag(cy_as_hal_device_tag tag) | ||
81 | { | ||
82 | cy_as_device *dev_p; | ||
83 | |||
84 | for (dev_p = g_device_list; dev_p != 0; dev_p = dev_p->next_p) { | ||
85 | if (dev_p->tag == tag) | ||
86 | return dev_p; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /* Map a pre-V1.2 media type to the V1.2+ bus number */ | ||
93 | static void | ||
94 | cy_as_bus_from_media_type(cy_as_media_type type, | ||
95 | cy_as_bus_number_t *bus) | ||
96 | { | ||
97 | if (type == cy_as_media_nand) | ||
98 | *bus = 0; | ||
99 | else | ||
100 | *bus = 1; | ||
101 | } | ||
102 | |||
103 | static cy_as_return_status_t | ||
104 | my_handle_response_no_data(cy_as_device *dev_p, | ||
105 | cy_as_ll_request_response *req_p, | ||
106 | cy_as_ll_request_response *reply_p) | ||
107 | { | ||
108 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
109 | |||
110 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
111 | CY_RESP_SUCCESS_FAILURE) | ||
112 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
113 | else | ||
114 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
115 | |||
116 | cy_as_ll_destroy_request(dev_p, req_p); | ||
117 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
118 | |||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Create a new West Bridge device | ||
124 | */ | ||
125 | cy_as_return_status_t | ||
126 | cy_as_misc_create_device(cy_as_device_handle *handle_p, | ||
127 | cy_as_hal_device_tag tag) | ||
128 | { | ||
129 | cy_as_device *dev_p; | ||
130 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
131 | |||
132 | cy_as_log_debug_message(6, "cy_as_misc_create_device called"); | ||
133 | |||
134 | dev_p = (cy_as_device *)cy_as_hal_alloc(sizeof(cy_as_device)); | ||
135 | if (dev_p == 0) | ||
136 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
137 | cy_as_hal_mem_set(dev_p, 0, sizeof(cy_as_device)); | ||
138 | |||
139 | /* | ||
140 | * dynamically allocating this buffer to ensure that it is | ||
141 | * word aligned. | ||
142 | */ | ||
143 | dev_p->usb_ep_data = (uint8_t *)cy_as_hal_alloc(64 * sizeof(uint8_t)); | ||
144 | if (dev_p->usb_ep_data == 0) { | ||
145 | cy_as_hal_free(dev_p); | ||
146 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
147 | } | ||
148 | |||
149 | dev_p->sig = CY_AS_DEVICE_HANDLE_SIGNATURE; | ||
150 | dev_p->tag = tag; | ||
151 | dev_p->usb_max_tx_size = 0x40; | ||
152 | |||
153 | dev_p->storage_write_endpoint = CY_AS_P2S_WRITE_ENDPOINT; | ||
154 | dev_p->storage_read_endpoint = CY_AS_P2S_READ_ENDPOINT; | ||
155 | |||
156 | dev_p->func_cbs_misc = cy_as_create_c_b_queue(CYAS_FUNC_CB); | ||
157 | if (dev_p->func_cbs_misc == 0) | ||
158 | goto destroy; | ||
159 | |||
160 | dev_p->func_cbs_res = cy_as_create_c_b_queue(CYAS_FUNC_CB); | ||
161 | if (dev_p->func_cbs_res == 0) | ||
162 | goto destroy; | ||
163 | |||
164 | dev_p->func_cbs_stor = cy_as_create_c_b_queue(CYAS_FUNC_CB); | ||
165 | if (dev_p->func_cbs_stor == 0) | ||
166 | goto destroy; | ||
167 | |||
168 | dev_p->func_cbs_usb = cy_as_create_c_b_queue(CYAS_FUNC_CB); | ||
169 | if (dev_p->func_cbs_usb == 0) | ||
170 | goto destroy; | ||
171 | |||
172 | dev_p->func_cbs_mtp = cy_as_create_c_b_queue(CYAS_FUNC_CB); | ||
173 | if (dev_p->func_cbs_mtp == 0) | ||
174 | goto destroy; | ||
175 | |||
176 | /* | ||
177 | * allocate memory for the DMA module here. it is then marked idle, and | ||
178 | * will be activated when cy_as_misc_configure_device is called. | ||
179 | */ | ||
180 | ret = cy_as_dma_start(dev_p); | ||
181 | if (ret != CY_AS_ERROR_SUCCESS) | ||
182 | goto destroy; | ||
183 | |||
184 | cy_as_device_set_dma_stopped(dev_p); | ||
185 | |||
186 | /* | ||
187 | * allocate memory for the low level module here. this module is also | ||
188 | * activated only when cy_as_misc_configure_device is called. | ||
189 | */ | ||
190 | ret = cy_as_ll_start(dev_p); | ||
191 | if (ret != CY_AS_ERROR_SUCCESS) | ||
192 | goto destroy; | ||
193 | |||
194 | cy_as_device_set_low_level_stopped(dev_p); | ||
195 | |||
196 | dev_p->next_p = g_device_list; | ||
197 | g_device_list = dev_p; | ||
198 | |||
199 | *handle_p = dev_p; | ||
200 | cy_as_hal_init_dev_registers(tag, cy_false); | ||
201 | return CY_AS_ERROR_SUCCESS; | ||
202 | |||
203 | destroy: | ||
204 | /* Free any queues that were successfully allocated. */ | ||
205 | if (dev_p->func_cbs_misc) | ||
206 | cy_as_destroy_c_b_queue(dev_p->func_cbs_misc); | ||
207 | |||
208 | if (dev_p->func_cbs_res) | ||
209 | cy_as_destroy_c_b_queue(dev_p->func_cbs_res); | ||
210 | |||
211 | if (dev_p->func_cbs_stor) | ||
212 | cy_as_destroy_c_b_queue(dev_p->func_cbs_stor); | ||
213 | |||
214 | if (dev_p->func_cbs_usb) | ||
215 | cy_as_destroy_c_b_queue(dev_p->func_cbs_usb); | ||
216 | |||
217 | if (dev_p->func_cbs_mtp) | ||
218 | cy_as_destroy_c_b_queue(dev_p->func_cbs_mtp); | ||
219 | |||
220 | cy_as_hal_free(dev_p->usb_ep_data); | ||
221 | cy_as_hal_free(dev_p); | ||
222 | |||
223 | if (ret != CY_AS_ERROR_SUCCESS) | ||
224 | return ret; | ||
225 | else | ||
226 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
227 | } | ||
228 | |||
229 | /* | ||
230 | * Destroy an existing West Bridge device | ||
231 | */ | ||
232 | cy_as_return_status_t | ||
233 | cy_as_misc_destroy_device(cy_as_device_handle handle) | ||
234 | { | ||
235 | cy_as_return_status_t ret; | ||
236 | cy_as_device *dev_p; | ||
237 | |||
238 | cy_as_log_debug_message(6, "cy_as_misc_destroy_device called"); | ||
239 | |||
240 | dev_p = (cy_as_device *)handle; | ||
241 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
242 | return CY_AS_ERROR_INVALID_HANDLE; | ||
243 | |||
244 | /* | ||
245 | * if the USB stack is still running, | ||
246 | * it must be stopped first | ||
247 | */ | ||
248 | if (dev_p->usb_count > 0) | ||
249 | return CY_AS_ERROR_STILL_RUNNING; | ||
250 | |||
251 | /* | ||
252 | * if the STORAGE stack is still running, | ||
253 | * it must be stopped first | ||
254 | */ | ||
255 | if (dev_p->storage_count > 0) | ||
256 | return CY_AS_ERROR_STILL_RUNNING; | ||
257 | |||
258 | if (cy_as_device_is_intr_running(dev_p)) | ||
259 | ret = cy_as_intr_stop(dev_p); | ||
260 | |||
261 | ret = cy_as_ll_stop(dev_p); | ||
262 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
263 | cy_as_intr_start(dev_p, dev_p->use_int_drq); | ||
264 | return ret; | ||
265 | } | ||
266 | |||
267 | ret = cy_as_dma_stop(dev_p); | ||
268 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
269 | cy_as_intr_start(dev_p, dev_p->use_int_drq); | ||
270 | return ret; | ||
271 | } | ||
272 | |||
273 | /* Reset the West Bridge device. */ | ||
274 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_RST_CTRL_REG, | ||
275 | CY_AS_MEM_RST_CTRL_REG_HARD); | ||
276 | |||
277 | /* | ||
278 | * remove the device from the device list | ||
279 | */ | ||
280 | if (g_device_list == dev_p) { | ||
281 | g_device_list = dev_p->next_p; | ||
282 | } else { | ||
283 | cy_as_device *tmp_p = g_device_list; | ||
284 | while (tmp_p && tmp_p->next_p != dev_p) | ||
285 | tmp_p = tmp_p->next_p; | ||
286 | |||
287 | cy_as_hal_assert(tmp_p != 0); | ||
288 | tmp_p->next_p = dev_p->next_p; | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | * reset the signature so this will not be detected | ||
293 | * as a valid handle | ||
294 | */ | ||
295 | dev_p->sig = 0; | ||
296 | |||
297 | cy_as_destroy_c_b_queue(dev_p->func_cbs_misc); | ||
298 | cy_as_destroy_c_b_queue(dev_p->func_cbs_res); | ||
299 | cy_as_destroy_c_b_queue(dev_p->func_cbs_stor); | ||
300 | cy_as_destroy_c_b_queue(dev_p->func_cbs_usb); | ||
301 | cy_as_destroy_c_b_queue(dev_p->func_cbs_mtp); | ||
302 | |||
303 | /* | ||
304 | * free the memory associated with the device | ||
305 | */ | ||
306 | cy_as_hal_free(dev_p->usb_ep_data); | ||
307 | cy_as_hal_free(dev_p); | ||
308 | |||
309 | return CY_AS_ERROR_SUCCESS; | ||
310 | } | ||
311 | |||
312 | /* | ||
313 | * Determine the endian mode for the processor we are | ||
314 | * running on, then set the endian mode register | ||
315 | */ | ||
316 | static void | ||
317 | cy_as_setup_endian_mode(cy_as_device *dev_p) | ||
318 | { | ||
319 | /* | ||
320 | * In general, we always set west bridge intothe little | ||
321 | * endian mode. this causes the data on bit 0 internally | ||
322 | * to come out on data line 0 externally and it is generally | ||
323 | * what we want regardless of the endian mode of the | ||
324 | * processor. this capability in west bridge should be | ||
325 | * labeled as a "SWAP" capability and can be used to swap the | ||
326 | * bytes of data in and out of west bridge. this is | ||
327 | * useful if there is DMA hardware that requires this for some | ||
328 | * reason I cannot imagine at this time. basically if the | ||
329 | * wires are connected correctly, we should never need to | ||
330 | * change the endian-ness of west bridge. | ||
331 | */ | ||
332 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_ENDIAN, | ||
333 | CY_AS_LITTLE_ENDIAN); | ||
334 | } | ||
335 | |||
336 | /* | ||
337 | * Query the West Bridge device and determine if we are an standby mode | ||
338 | */ | ||
339 | cy_as_return_status_t | ||
340 | cy_as_misc_in_standby(cy_as_device_handle handle, cy_bool *standby) | ||
341 | { | ||
342 | cy_as_device *dev_p; | ||
343 | |||
344 | cy_as_log_debug_message(6, "cy_as_misc_in_standby called"); | ||
345 | |||
346 | dev_p = (cy_as_device *)handle; | ||
347 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
348 | return CY_AS_ERROR_INVALID_HANDLE; | ||
349 | |||
350 | if (cy_as_device_is_pin_standby(dev_p) || | ||
351 | cy_as_device_is_register_standby(dev_p)) { | ||
352 | *standby = cy_true; | ||
353 | } else | ||
354 | *standby = cy_false; | ||
355 | |||
356 | return CY_AS_ERROR_SUCCESS; | ||
357 | } | ||
358 | |||
359 | static void | ||
360 | cy_as_misc_func_callback(cy_as_device *dev_p, | ||
361 | uint8_t context, | ||
362 | cy_as_ll_request_response *rqt, | ||
363 | cy_as_ll_request_response *resp, | ||
364 | cy_as_return_status_t ret); | ||
365 | |||
366 | |||
367 | static void | ||
368 | my_misc_callback(cy_as_device *dev_p, uint8_t context, | ||
369 | cy_as_ll_request_response *req_p, | ||
370 | cy_as_ll_request_response *resp_p, | ||
371 | cy_as_return_status_t ret) | ||
372 | { | ||
373 | (void)resp_p; | ||
374 | (void)context; | ||
375 | (void)ret; | ||
376 | |||
377 | switch (cy_as_ll_request_response__get_code(req_p)) { | ||
378 | case CY_RQT_INITIALIZATION_COMPLETE: | ||
379 | { | ||
380 | uint16_t v; | ||
381 | |||
382 | cy_as_ll_send_status_response(dev_p, | ||
383 | CY_RQT_GENERAL_RQT_CONTEXT, | ||
384 | CY_AS_ERROR_SUCCESS, 0); | ||
385 | cy_as_device_set_firmware_loaded(dev_p); | ||
386 | |||
387 | if (cy_as_device_is_waking(dev_p)) { | ||
388 | /* | ||
389 | * this is a callback from a | ||
390 | * cy_as_misc_leave_standby() | ||
391 | * request. in this case we call | ||
392 | * the standby callback and clear | ||
393 | * the waking state. | ||
394 | */ | ||
395 | if (dev_p->misc_event_cb) | ||
396 | dev_p->misc_event_cb( | ||
397 | (cy_as_device_handle)dev_p, | ||
398 | cy_as_event_misc_awake, 0); | ||
399 | cy_as_device_clear_waking(dev_p); | ||
400 | } else { | ||
401 | v = cy_as_ll_request_response__get_word | ||
402 | (req_p, 3); | ||
403 | |||
404 | /* | ||
405 | * store the media supported on | ||
406 | * each of the device buses. | ||
407 | */ | ||
408 | dev_p->media_supported[0] = | ||
409 | (uint8_t)(v & 0xFF); | ||
410 | dev_p->media_supported[1] = | ||
411 | (uint8_t)((v >> 8) & 0xFF); | ||
412 | |||
413 | v = cy_as_ll_request_response__get_word | ||
414 | (req_p, 4); | ||
415 | |||
416 | dev_p->is_mtp_firmware = | ||
417 | (cy_bool)((v >> 8) & 0xFF); | ||
418 | |||
419 | if (dev_p->misc_event_cb) | ||
420 | dev_p->misc_event_cb( | ||
421 | (cy_as_device_handle)dev_p, | ||
422 | cy_as_event_misc_initialized, 0); | ||
423 | } | ||
424 | |||
425 | v = cy_as_hal_read_register(dev_p->tag, | ||
426 | CY_AS_MEM_P0_VM_SET); | ||
427 | |||
428 | if (v & CY_AS_MEM_P0_VM_SET_CFGMODE) | ||
429 | cy_as_hal_print_message( | ||
430 | "initialization message " | ||
431 | "received, but config bit " | ||
432 | "still set\n"); | ||
433 | |||
434 | v = cy_as_hal_read_register(dev_p->tag, | ||
435 | CY_AS_MEM_RST_CTRL_REG); | ||
436 | if ((v & CY_AS_MEM_RST_RSTCMPT) == 0) | ||
437 | cy_as_hal_print_message( | ||
438 | "initialization message " | ||
439 | "received, but reset complete " | ||
440 | "bit still not set\n"); | ||
441 | } | ||
442 | break; | ||
443 | |||
444 | case CY_RQT_OUT_OF_SUSPEND: | ||
445 | cy_as_ll_send_status_response(dev_p, CY_RQT_GENERAL_RQT_CONTEXT, | ||
446 | CY_AS_ERROR_SUCCESS, 0); | ||
447 | cy_as_device_clear_suspend_mode(dev_p); | ||
448 | |||
449 | /* | ||
450 | * if the wakeup was caused by an async cy_as_misc_leave_suspend | ||
451 | * call, we have to call the corresponding callback. | ||
452 | */ | ||
453 | if (dev_p->func_cbs_misc->count > 0) { | ||
454 | cy_as_func_c_b_node *node = (cy_as_func_c_b_node *) | ||
455 | dev_p->func_cbs_misc->head_p; | ||
456 | cy_as_hal_assert(node); | ||
457 | |||
458 | if (cy_as_funct_c_b_type_get_type(node->data_type) == | ||
459 | CY_FUNCT_CB_MISC_LEAVESUSPEND) { | ||
460 | cy_as_hal_assert(node->cb_p != 0); | ||
461 | |||
462 | node->cb_p((cy_as_device_handle)dev_p, | ||
463 | CY_AS_ERROR_SUCCESS, node->client_data, | ||
464 | CY_FUNCT_CB_MISC_LEAVESUSPEND, 0); | ||
465 | cy_as_remove_c_b_node(dev_p->func_cbs_misc); | ||
466 | } | ||
467 | } | ||
468 | |||
469 | if (dev_p->misc_event_cb) | ||
470 | dev_p->misc_event_cb((cy_as_device_handle)dev_p, | ||
471 | cy_as_event_misc_wakeup, 0); | ||
472 | break; | ||
473 | |||
474 | case CY_RQT_DEBUG_MESSAGE: | ||
475 | if ((req_p->data[0] == 0) && (req_p->data[1] == 0) && | ||
476 | (req_p->data[2] == 0)) { | ||
477 | if (dev_p->misc_event_cb) | ||
478 | dev_p->misc_event_cb((cy_as_device_handle)dev_p, | ||
479 | cy_as_event_misc_heart_beat, 0); | ||
480 | } else { | ||
481 | cy_as_hal_print_message( | ||
482 | "**** debug message: %02x " | ||
483 | "%02x %02x %02x %02x %02x\n", | ||
484 | req_p->data[0] & 0xff, | ||
485 | (req_p->data[0] >> 8) & 0xff, | ||
486 | req_p->data[1] & 0xff, | ||
487 | (req_p->data[1] >> 8) & 0xff, | ||
488 | req_p->data[2] & 0xff, | ||
489 | (req_p->data[2] >> 8) & 0xff); | ||
490 | } | ||
491 | break; | ||
492 | |||
493 | case CY_RQT_WB_DEVICE_MISMATCH: | ||
494 | { | ||
495 | if (dev_p->misc_event_cb) | ||
496 | dev_p->misc_event_cb((cy_as_device_handle)dev_p, | ||
497 | cy_as_event_misc_device_mismatch, 0); | ||
498 | } | ||
499 | break; | ||
500 | |||
501 | case CY_RQT_BOOTLOAD_NO_FIRMWARE: | ||
502 | { | ||
503 | /* TODO Handle case when firmware is | ||
504 | * not found during bootloading. */ | ||
505 | cy_as_hal_print_message("no firmware image found " | ||
506 | "during bootload. device not started\n"); | ||
507 | } | ||
508 | break; | ||
509 | |||
510 | default: | ||
511 | cy_as_hal_assert(0); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | static cy_bool | ||
516 | is_valid_silicon_id(uint16_t v) | ||
517 | { | ||
518 | cy_bool idok = cy_false; | ||
519 | |||
520 | /* | ||
521 | * remove the revision number from the ID value | ||
522 | */ | ||
523 | v = v & CY_AS_MEM_CM_WB_CFG_ID_HDID_MASK; | ||
524 | |||
525 | /* | ||
526 | * if this is west bridge, then we are OK. | ||
527 | */ | ||
528 | if (v == CY_AS_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE || | ||
529 | v == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE || | ||
530 | v == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE) | ||
531 | idok = cy_true; | ||
532 | |||
533 | return idok; | ||
534 | } | ||
535 | |||
536 | /* | ||
537 | * Configure the West Bridge device hardware | ||
538 | */ | ||
539 | cy_as_return_status_t | ||
540 | cy_as_misc_configure_device(cy_as_device_handle handle, | ||
541 | cy_as_device_config *config_p) | ||
542 | { | ||
543 | cy_as_return_status_t ret; | ||
544 | cy_bool standby; | ||
545 | cy_as_device *dev_p; | ||
546 | uint16_t v; | ||
547 | uint16_t fw_present; | ||
548 | cy_as_log_debug_message(6, "cy_as_misc_configure_device called"); | ||
549 | |||
550 | dev_p = (cy_as_device *)handle; | ||
551 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
552 | return CY_AS_ERROR_INVALID_HANDLE; | ||
553 | |||
554 | /* Setup big endian vs little endian */ | ||
555 | cy_as_setup_endian_mode(dev_p); | ||
556 | |||
557 | /* Now, confirm that we can talk to the West Bridge device */ | ||
558 | dev_p->silicon_id = cy_as_hal_read_register(dev_p->tag, | ||
559 | CY_AS_MEM_CM_WB_CFG_ID); | ||
560 | fw_present = cy_as_hal_read_register(dev_p->tag, | ||
561 | CY_AS_MEM_RST_CTRL_REG); | ||
562 | if (!(fw_present & CY_AS_MEM_RST_RSTCMPT)) { | ||
563 | if (!is_valid_silicon_id(dev_p->silicon_id)) | ||
564 | return CY_AS_ERROR_NO_ANTIOCH; | ||
565 | } | ||
566 | /* Check for standby mode */ | ||
567 | ret = cy_as_misc_in_standby(handle, &standby); | ||
568 | if (ret != CY_AS_ERROR_SUCCESS) | ||
569 | return ret; | ||
570 | if (ret) | ||
571 | return CY_AS_ERROR_IN_STANDBY; | ||
572 | |||
573 | /* Setup P-port interface mode (CRAM / SRAM). */ | ||
574 | if (cy_as_device_is_astoria_dev(dev_p)) { | ||
575 | if (config_p->srammode) | ||
576 | v = CY_AS_MEM_P0_VM_SET_VMTYPE_SRAM; | ||
577 | else | ||
578 | v = CY_AS_MEM_P0_VM_SET_VMTYPE_RAM; | ||
579 | } else | ||
580 | v = CY_AS_MEM_P0_VM_SET_VMTYPE_RAM; | ||
581 | |||
582 | /* Setup synchronous versus asynchronous mode */ | ||
583 | if (config_p->sync) | ||
584 | v |= CY_AS_MEM_P0_VM_SET_IFMODE; | ||
585 | if (config_p->dackmode == cy_as_device_dack_ack) | ||
586 | v |= CY_AS_MEM_P0_VM_SET_DACKEOB; | ||
587 | if (config_p->drqpol) | ||
588 | v |= CY_AS_MEM_P0_VM_SET_DRQPOL; | ||
589 | if (config_p->dackpol) | ||
590 | v |= CY_AS_MEM_P0_VM_SET_DACKPOL; | ||
591 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_P0_VM_SET, v); | ||
592 | |||
593 | if (config_p->crystal) | ||
594 | cy_as_device_set_crystal(dev_p); | ||
595 | else | ||
596 | cy_as_device_set_external_clock(dev_p); | ||
597 | |||
598 | /* Register a callback to handle MISC requests from the firmware */ | ||
599 | cy_as_ll_register_request_callback(dev_p, | ||
600 | CY_RQT_GENERAL_RQT_CONTEXT, my_misc_callback); | ||
601 | |||
602 | /* Now mark the DMA and low level modules as active. */ | ||
603 | cy_as_device_set_dma_running(dev_p); | ||
604 | cy_as_device_set_low_level_running(dev_p); | ||
605 | |||
606 | /* Now, initialize the interrupt module */ | ||
607 | dev_p->use_int_drq = config_p->dmaintr; | ||
608 | ret = cy_as_intr_start(dev_p, config_p->dmaintr); | ||
609 | if (ret != CY_AS_ERROR_SUCCESS) | ||
610 | return ret; | ||
611 | |||
612 | /* Mark the interface as initialized */ | ||
613 | cy_as_device_set_configured(dev_p); | ||
614 | |||
615 | return CY_AS_ERROR_SUCCESS; | ||
616 | } | ||
617 | |||
618 | static void | ||
619 | my_dma_callback(cy_as_device *dev_p, | ||
620 | cy_as_end_point_number_t ep, | ||
621 | void *mem_p, | ||
622 | uint32_t size, | ||
623 | cy_as_return_status_t ret | ||
624 | ) | ||
625 | { | ||
626 | cy_as_dma_end_point *ep_p; | ||
627 | |||
628 | (void)size; | ||
629 | |||
630 | /* Get the endpoint pointer based on the endpoint number */ | ||
631 | ep_p = CY_AS_NUM_EP(dev_p, ep); | ||
632 | |||
633 | /* Check the queue to see if is drained */ | ||
634 | if (ep_p->queue_p == 0) { | ||
635 | cy_as_func_c_b_node *node = | ||
636 | (cy_as_func_c_b_node *)dev_p->func_cbs_misc->head_p; | ||
637 | |||
638 | cy_as_hal_assert(node); | ||
639 | |||
640 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
641 | /* | ||
642 | * disable endpoint 2. the storage module | ||
643 | * will enable this EP if necessary. | ||
644 | */ | ||
645 | cy_as_dma_enable_end_point(dev_p, | ||
646 | CY_AS_FIRMWARE_ENDPOINT, | ||
647 | cy_false, cy_as_direction_in); | ||
648 | |||
649 | /* | ||
650 | * clear the reset register. this releases the | ||
651 | * antioch micro-controller from reset and begins | ||
652 | * running the code at address zero. | ||
653 | */ | ||
654 | cy_as_hal_write_register(dev_p->tag, | ||
655 | CY_AS_MEM_RST_CTRL_REG, 0x00); | ||
656 | } | ||
657 | |||
658 | /* Call the user Callback */ | ||
659 | node->cb_p((cy_as_device_handle)dev_p, ret, node->client_data, | ||
660 | node->data_type, node->data); | ||
661 | cy_as_remove_c_b_node(dev_p->func_cbs_misc); | ||
662 | } else { | ||
663 | /* This is the header data that was allocated in the | ||
664 | * download firmware function, and can be safely freed | ||
665 | * here. */ | ||
666 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
667 | cy_as_hal_c_b_free(mem_p); | ||
668 | cy_as_hal_enable_interrupts(state); | ||
669 | } | ||
670 | } | ||
671 | |||
672 | cy_as_return_status_t | ||
673 | cy_as_misc_download_firmware(cy_as_device_handle handle, | ||
674 | const void *mem_p, | ||
675 | uint16_t size, | ||
676 | cy_as_function_callback cb, | ||
677 | uint32_t client) | ||
678 | { | ||
679 | uint8_t *header; | ||
680 | cy_as_return_status_t ret; | ||
681 | cy_bool standby; | ||
682 | cy_as_device *dev_p; | ||
683 | cy_as_dma_callback dmacb = 0; | ||
684 | uint32_t state; | ||
685 | |||
686 | cy_as_log_debug_message(6, "cy_as_misc_download_firmware called"); | ||
687 | |||
688 | /* Make sure we have a valid device */ | ||
689 | dev_p = (cy_as_device *)handle; | ||
690 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
691 | return CY_AS_ERROR_INVALID_HANDLE; | ||
692 | |||
693 | /* | ||
694 | * if the device has not been initialized, we cannot download firmware | ||
695 | * to the device. | ||
696 | */ | ||
697 | if (!cy_as_device_is_configured(dev_p)) | ||
698 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
699 | |||
700 | /* | ||
701 | * make sure west bridge is not in standby | ||
702 | */ | ||
703 | ret = cy_as_misc_in_standby(dev_p, &standby); | ||
704 | if (ret != CY_AS_ERROR_SUCCESS) | ||
705 | return ret; | ||
706 | |||
707 | if (standby) | ||
708 | return CY_AS_ERROR_IN_STANDBY; | ||
709 | |||
710 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
711 | return CY_AS_ERROR_IN_SUSPEND; | ||
712 | |||
713 | /* | ||
714 | * make sure we are in configuration mode | ||
715 | */ | ||
716 | if ((cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_VM_SET) & | ||
717 | CY_AS_MEM_P0_VM_SET_CFGMODE) == 0) | ||
718 | return CY_AS_ERROR_NOT_IN_CONFIG_MODE; | ||
719 | |||
720 | /* Maximum firmware size is 24k */ | ||
721 | if (size > CY_AS_MAXIMUM_FIRMWARE_SIZE) | ||
722 | return CY_AS_ERROR_INVALID_SIZE; | ||
723 | |||
724 | /* Make sure the size is an even number of bytes as well */ | ||
725 | if (size & 0x01) | ||
726 | return CY_AS_ERROR_ALIGNMENT_ERROR; | ||
727 | |||
728 | /* | ||
729 | * write the two word header that gives the base address and | ||
730 | * size of the firmware image to download | ||
731 | */ | ||
732 | state = cy_as_hal_disable_interrupts(); | ||
733 | header = (uint8_t *)cy_as_hal_c_b_alloc(4); | ||
734 | cy_as_hal_enable_interrupts(state); | ||
735 | if (header == NULL) | ||
736 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
737 | |||
738 | header[0] = 0x00; | ||
739 | header[1] = 0x00; | ||
740 | header[2] = (uint8_t)(size & 0xff); | ||
741 | header[3] = (uint8_t)((size >> 8) & 0xff); | ||
742 | |||
743 | /* Enable the firmware endpoint */ | ||
744 | ret = cy_as_dma_enable_end_point(dev_p, CY_AS_FIRMWARE_ENDPOINT, | ||
745 | cy_true, cy_as_direction_in); | ||
746 | if (ret != CY_AS_ERROR_SUCCESS) | ||
747 | return ret; | ||
748 | |||
749 | /* | ||
750 | * setup DMA for 64 byte packets. this is the requirement for downloading | ||
751 | * firmware to west bridge. | ||
752 | */ | ||
753 | cy_as_dma_set_max_dma_size(dev_p, CY_AS_FIRMWARE_ENDPOINT, 64); | ||
754 | |||
755 | if (cb) | ||
756 | dmacb = my_dma_callback; | ||
757 | |||
758 | ret = cy_as_dma_queue_request(dev_p, CY_AS_FIRMWARE_ENDPOINT, header, | ||
759 | 4, cy_false, cy_false, dmacb); | ||
760 | if (ret != CY_AS_ERROR_SUCCESS) | ||
761 | return ret; | ||
762 | |||
763 | /* | ||
764 | * write the firmware image to the west bridge device | ||
765 | */ | ||
766 | ret = cy_as_dma_queue_request(dev_p, CY_AS_FIRMWARE_ENDPOINT, | ||
767 | (void *)mem_p, size, cy_false, cy_false, dmacb); | ||
768 | if (ret != CY_AS_ERROR_SUCCESS) | ||
769 | return ret; | ||
770 | |||
771 | if (cb) { | ||
772 | cy_as_func_c_b_node *cbnode = cy_as_create_func_c_b_node_data( | ||
773 | cb, client, CY_FUNCT_CB_MISC_DOWNLOADFIRMWARE, 0); | ||
774 | |||
775 | if (cbnode == 0) | ||
776 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
777 | else | ||
778 | cy_as_insert_c_b_node(dev_p->func_cbs_misc, cbnode); | ||
779 | |||
780 | ret = cy_as_dma_kick_start(dev_p, CY_AS_FIRMWARE_ENDPOINT); | ||
781 | if (ret != CY_AS_ERROR_SUCCESS) | ||
782 | return ret; | ||
783 | } else { | ||
784 | ret = cy_as_dma_drain_queue(dev_p, | ||
785 | CY_AS_FIRMWARE_ENDPOINT, cy_true); | ||
786 | |||
787 | /* Free the header memory that was allocated earlier. */ | ||
788 | cy_as_hal_c_b_free(header); | ||
789 | |||
790 | if (ret != CY_AS_ERROR_SUCCESS) | ||
791 | return ret; | ||
792 | |||
793 | /* | ||
794 | * disable EP 2. the storage module will | ||
795 | * enable this EP if necessary. | ||
796 | */ | ||
797 | cy_as_dma_enable_end_point(dev_p, CY_AS_FIRMWARE_ENDPOINT, | ||
798 | cy_false, cy_as_direction_in); | ||
799 | |||
800 | /* | ||
801 | * clear the reset register. this releases the west bridge | ||
802 | * micro-controller from reset and begins running the code at | ||
803 | * address zero. | ||
804 | */ | ||
805 | cy_as_hal_write_register(dev_p->tag, | ||
806 | CY_AS_MEM_RST_CTRL_REG, 0x00); | ||
807 | } | ||
808 | |||
809 | /* | ||
810 | * the firmware is not marked as loaded until the firmware | ||
811 | * initializes west bridge and a request is sent from west bridge | ||
812 | * to the P port processor indicating that west bridge is ready. | ||
813 | */ | ||
814 | return CY_AS_ERROR_SUCCESS; | ||
815 | } | ||
816 | |||
817 | |||
818 | static cy_as_return_status_t | ||
819 | my_handle_response_get_firmware_version(cy_as_device *dev_p, | ||
820 | cy_as_ll_request_response *req_p, | ||
821 | cy_as_ll_request_response *reply_p, | ||
822 | cy_as_get_firmware_version_data *data_p) | ||
823 | { | ||
824 | |||
825 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
826 | uint16_t val; | ||
827 | |||
828 | if (cy_as_ll_request_response__get_code(reply_p) | ||
829 | != CY_RESP_FIRMWARE_VERSION) { | ||
830 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
831 | goto destroy; | ||
832 | } | ||
833 | |||
834 | data_p->major = cy_as_ll_request_response__get_word(reply_p, 0); | ||
835 | data_p->minor = cy_as_ll_request_response__get_word(reply_p, 1); | ||
836 | data_p->build = cy_as_ll_request_response__get_word(reply_p, 2); | ||
837 | val = cy_as_ll_request_response__get_word(reply_p, 3); | ||
838 | data_p->media_type = (uint8_t)(((val >> 8) & 0xFF) | (val & 0xFF)); | ||
839 | val = cy_as_ll_request_response__get_word(reply_p, 4); | ||
840 | data_p->is_debug_mode = (cy_bool)(val & 0xFF); | ||
841 | |||
842 | destroy: | ||
843 | cy_as_ll_destroy_request(dev_p, req_p); | ||
844 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
845 | |||
846 | return ret; | ||
847 | } | ||
848 | |||
849 | cy_as_return_status_t | ||
850 | cy_as_misc_get_firmware_version(cy_as_device_handle handle, | ||
851 | cy_as_get_firmware_version_data *data, | ||
852 | cy_as_function_callback cb, | ||
853 | uint32_t client) | ||
854 | { | ||
855 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
856 | cy_bool standby; | ||
857 | cy_as_ll_request_response *req_p, *reply_p; | ||
858 | |||
859 | cy_as_device *dev_p; | ||
860 | |||
861 | (void)client; | ||
862 | |||
863 | cy_as_log_debug_message(6, "cy_as_misc_get_firmware_version called"); | ||
864 | |||
865 | /* Make sure we have a valid device */ | ||
866 | dev_p = (cy_as_device *)handle; | ||
867 | cy_as_check_device_ready(dev_p); | ||
868 | |||
869 | /* | ||
870 | * make sure antioch is not in standby | ||
871 | */ | ||
872 | ret = cy_as_misc_in_standby(dev_p, &standby); | ||
873 | if (ret != CY_AS_ERROR_SUCCESS) | ||
874 | return ret; | ||
875 | if (standby) | ||
876 | return CY_AS_ERROR_IN_STANDBY; | ||
877 | |||
878 | /* Make sure the Antioch is not in suspend mode. */ | ||
879 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
880 | return CY_AS_ERROR_IN_SUSPEND; | ||
881 | |||
882 | /* Create the request to send to the West Bridge device */ | ||
883 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_GET_FIRMWARE_VERSION, | ||
884 | CY_RQT_GENERAL_RQT_CONTEXT, 0); | ||
885 | if (req_p == 0) | ||
886 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
887 | |||
888 | /* | ||
889 | * Reserve space for the reply, the reply data | ||
890 | * will not exceed three words | ||
891 | */ | ||
892 | reply_p = cy_as_ll_create_response(dev_p, 5); | ||
893 | if (reply_p == 0) { | ||
894 | cy_as_ll_destroy_request(dev_p, req_p); | ||
895 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
896 | } | ||
897 | |||
898 | if (cb == 0) { | ||
899 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
900 | if (ret != CY_AS_ERROR_SUCCESS) | ||
901 | goto destroy; | ||
902 | |||
903 | /* Request and response are freed in | ||
904 | * MyHandleResponseGetFirmwareVersion. */ | ||
905 | ret = my_handle_response_get_firmware_version(dev_p, | ||
906 | req_p, reply_p, data); | ||
907 | return ret; | ||
908 | } else { | ||
909 | |||
910 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
911 | CY_FUNCT_CB_MISC_GETFIRMWAREVERSION, data, | ||
912 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
913 | req_p, reply_p, cy_as_misc_func_callback); | ||
914 | |||
915 | if (ret != CY_AS_ERROR_SUCCESS) | ||
916 | goto destroy; | ||
917 | |||
918 | /* The request and response are freed | ||
919 | * as part of the MiscFuncCallback */ | ||
920 | return ret; | ||
921 | } | ||
922 | |||
923 | destroy: | ||
924 | cy_as_ll_destroy_request(dev_p, req_p); | ||
925 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
926 | |||
927 | return ret; | ||
928 | } | ||
929 | EXPORT_SYMBOL(cy_as_misc_get_firmware_version); | ||
930 | |||
931 | static cy_as_return_status_t | ||
932 | my_handle_response_read_m_c_u_register(cy_as_device *dev_p, | ||
933 | cy_as_ll_request_response *req_p, | ||
934 | cy_as_ll_request_response *reply_p, | ||
935 | uint8_t *data_p) | ||
936 | { | ||
937 | |||
938 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
939 | |||
940 | if (cy_as_ll_request_response__get_code(reply_p) | ||
941 | != CY_RESP_MCU_REGISTER_DATA) { | ||
942 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
943 | goto destroy; | ||
944 | } | ||
945 | |||
946 | *data_p = (uint8_t) | ||
947 | (cy_as_ll_request_response__get_word(reply_p, 0)); | ||
948 | |||
949 | destroy: | ||
950 | cy_as_ll_destroy_request(dev_p, req_p); | ||
951 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
952 | |||
953 | return ret; | ||
954 | } | ||
955 | |||
956 | static cy_as_return_status_t | ||
957 | my_handle_response_get_gpio_value(cy_as_device *dev_p, | ||
958 | cy_as_ll_request_response *req_p, | ||
959 | cy_as_ll_request_response *reply_p, | ||
960 | uint8_t *data_p) | ||
961 | { | ||
962 | |||
963 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
964 | |||
965 | if (cy_as_ll_request_response__get_code(reply_p) | ||
966 | != CY_RESP_GPIO_STATE) { | ||
967 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
968 | } else | ||
969 | *data_p = (uint8_t) | ||
970 | (cy_as_ll_request_response__get_word(reply_p, 0)); | ||
971 | |||
972 | cy_as_ll_destroy_request(dev_p, req_p); | ||
973 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
974 | |||
975 | return ret; | ||
976 | } | ||
977 | |||
978 | |||
979 | cy_as_return_status_t cy_as_misc_set_sd_power_polarity( | ||
980 | cy_as_device_handle handle, | ||
981 | cy_as_misc_signal_polarity polarity, | ||
982 | cy_as_function_callback cb, | ||
983 | uint32_t client) | ||
984 | { | ||
985 | cy_as_ll_request_response *req_p, *reply_p; | ||
986 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
987 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
988 | |||
989 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
990 | return CY_AS_ERROR_INVALID_HANDLE; | ||
991 | |||
992 | if (!cy_as_device_is_configured(dev_p)) | ||
993 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
994 | |||
995 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
996 | return CY_AS_ERROR_NO_FIRMWARE; | ||
997 | |||
998 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
999 | return CY_AS_ERROR_IN_SUSPEND; | ||
1000 | |||
1001 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SDPOLARITY, | ||
1002 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1003 | if (req_p == 0) | ||
1004 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1005 | |||
1006 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1007 | (uint16_t)polarity); | ||
1008 | |||
1009 | /* | ||
1010 | * Reserve space for the reply, the reply data will | ||
1011 | * not exceed one word | ||
1012 | */ | ||
1013 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1014 | if (reply_p == 0) { | ||
1015 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1016 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1017 | } | ||
1018 | |||
1019 | if (cb == 0) { | ||
1020 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1021 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1022 | goto destroy; | ||
1023 | |||
1024 | return (my_handle_response_no_data(dev_p, req_p, reply_p)); | ||
1025 | } else { | ||
1026 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1027 | CY_FUNCT_CB_MISC_SETSDPOLARITY, 0, dev_p->func_cbs_misc, | ||
1028 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1029 | cy_as_misc_func_callback); | ||
1030 | |||
1031 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1032 | goto destroy; | ||
1033 | |||
1034 | /* The request and response are freed | ||
1035 | * as part of the FuncCallback */ | ||
1036 | return ret; | ||
1037 | } | ||
1038 | |||
1039 | destroy: | ||
1040 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1041 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1042 | return ret; | ||
1043 | } | ||
1044 | |||
1045 | |||
1046 | cy_as_return_status_t | ||
1047 | cy_as_misc_read_m_c_u_register(cy_as_device_handle handle, | ||
1048 | uint16_t address, | ||
1049 | uint8_t *value, | ||
1050 | cy_as_function_callback cb, | ||
1051 | uint32_t client) | ||
1052 | { | ||
1053 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1054 | cy_as_ll_request_response *req_p, *reply_p; | ||
1055 | |||
1056 | cy_as_device *dev_p; | ||
1057 | |||
1058 | cy_as_log_debug_message(6, "cy_as_misc_read_m_c_u_register called"); | ||
1059 | |||
1060 | dev_p = (cy_as_device *)handle; | ||
1061 | cy_as_check_device_ready(dev_p); | ||
1062 | |||
1063 | /* Check whether the firmware supports this command. */ | ||
1064 | if (cy_as_device_is_nand_storage_supported(dev_p)) | ||
1065 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
1066 | |||
1067 | /* Make sure the Antioch is not in suspend mode. */ | ||
1068 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1069 | return CY_AS_ERROR_IN_SUSPEND; | ||
1070 | |||
1071 | /* Create the request to send to the West Bridge device */ | ||
1072 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_READ_MCU_REGISTER, | ||
1073 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1074 | if (req_p == 0) | ||
1075 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1076 | |||
1077 | cy_as_ll_request_response__set_word(req_p, 0, (uint16_t)address); | ||
1078 | |||
1079 | /* Reserve space for the reply, the reply | ||
1080 | * data will not exceed one word */ | ||
1081 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1082 | if (reply_p == 0) { | ||
1083 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1084 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1085 | } | ||
1086 | |||
1087 | if (cb == 0) { | ||
1088 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1089 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1090 | goto destroy; | ||
1091 | |||
1092 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1093 | CY_RESP_MCU_REGISTER_DATA) { | ||
1094 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1095 | goto destroy; | ||
1096 | } | ||
1097 | |||
1098 | *value = (uint8_t)(cy_as_ll_request_response__get_word | ||
1099 | (reply_p, 0)); | ||
1100 | } else { | ||
1101 | |||
1102 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1103 | CY_FUNCT_CB_MISC_READMCUREGISTER, value, | ||
1104 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
1105 | req_p, reply_p, cy_as_misc_func_callback); | ||
1106 | |||
1107 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1108 | goto destroy; | ||
1109 | |||
1110 | /* The request and response are freed | ||
1111 | * as part of the MiscFuncCallback */ | ||
1112 | return ret; | ||
1113 | } | ||
1114 | destroy: | ||
1115 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1116 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1117 | |||
1118 | return ret; | ||
1119 | } | ||
1120 | EXPORT_SYMBOL(cy_as_misc_read_m_c_u_register); | ||
1121 | |||
1122 | cy_as_return_status_t | ||
1123 | cy_as_misc_write_m_c_u_register(cy_as_device_handle handle, | ||
1124 | uint16_t address, | ||
1125 | uint8_t mask, | ||
1126 | uint8_t value, | ||
1127 | cy_as_function_callback cb, | ||
1128 | uint32_t client) | ||
1129 | { | ||
1130 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1131 | cy_as_ll_request_response *req_p, *reply_p; | ||
1132 | cy_as_device *dev_p; | ||
1133 | |||
1134 | cy_as_log_debug_message(6, "cy_as_misc_write_m_c_u_register called"); | ||
1135 | |||
1136 | dev_p = (cy_as_device *)handle; | ||
1137 | cy_as_check_device_ready(dev_p); | ||
1138 | |||
1139 | /* Check whether the firmware supports this command. */ | ||
1140 | if (cy_as_device_is_nand_storage_supported(dev_p)) | ||
1141 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
1142 | |||
1143 | /* Make sure the Antioch is not in suspend mode. */ | ||
1144 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1145 | return CY_AS_ERROR_IN_SUSPEND; | ||
1146 | |||
1147 | /* Create the request to send to the West Bridge device */ | ||
1148 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_WRITE_MCU_REGISTER, | ||
1149 | CY_RQT_GENERAL_RQT_CONTEXT, 2); | ||
1150 | if (req_p == 0) | ||
1151 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1152 | |||
1153 | cy_as_ll_request_response__set_word(req_p, 0, (uint16_t)address); | ||
1154 | cy_as_ll_request_response__set_word(req_p, 1, | ||
1155 | (uint16_t)((mask << 8) | value)); | ||
1156 | |||
1157 | /* | ||
1158 | * Reserve space for the reply, the reply data | ||
1159 | * will not exceed one word | ||
1160 | */ | ||
1161 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1162 | if (reply_p == 0) { | ||
1163 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1164 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1165 | } | ||
1166 | |||
1167 | if (cb == 0) { | ||
1168 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1169 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1170 | goto destroy; | ||
1171 | |||
1172 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1173 | CY_RESP_SUCCESS_FAILURE) { | ||
1174 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1175 | goto destroy; | ||
1176 | } | ||
1177 | |||
1178 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1179 | } else { | ||
1180 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1181 | CY_FUNCT_CB_MISC_WRITEMCUREGISTER, 0, | ||
1182 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
1183 | req_p, reply_p, cy_as_misc_func_callback); | ||
1184 | |||
1185 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1186 | goto destroy; | ||
1187 | |||
1188 | /* | ||
1189 | * The request and response are freed as part of the | ||
1190 | * MiscFuncCallback | ||
1191 | */ | ||
1192 | return ret; | ||
1193 | } | ||
1194 | |||
1195 | destroy: | ||
1196 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1197 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1198 | |||
1199 | return ret; | ||
1200 | } | ||
1201 | |||
1202 | cy_as_return_status_t | ||
1203 | my_handle_response_reset(cy_as_device *dev_p, | ||
1204 | cy_as_ll_request_response *req_p, | ||
1205 | cy_as_ll_request_response *reply_p, | ||
1206 | cy_as_reset_type type) | ||
1207 | { | ||
1208 | uint16_t v; | ||
1209 | |||
1210 | (void)req_p; | ||
1211 | (void)reply_p; | ||
1212 | |||
1213 | /* | ||
1214 | * if the device is in suspend mode, it needs to be woken up | ||
1215 | * so that the write to the reset control register succeeds. | ||
1216 | * we need not however wait for the wake up procedure to be | ||
1217 | * complete. | ||
1218 | */ | ||
1219 | if (cy_as_device_is_in_suspend_mode(dev_p)) { | ||
1220 | v = cy_as_hal_read_register(dev_p->tag, | ||
1221 | CY_AS_MEM_CM_WB_CFG_ID); | ||
1222 | cy_as_hal_sleep(1); | ||
1223 | } | ||
1224 | |||
1225 | if (type == cy_as_reset_hard) { | ||
1226 | cy_as_misc_cancel_ex_requests(dev_p); | ||
1227 | cy_as_hal_write_register(dev_p->tag, CY_AS_MEM_RST_CTRL_REG, | ||
1228 | CY_AS_MEM_RST_CTRL_REG_HARD); | ||
1229 | cy_as_device_set_unconfigured(dev_p); | ||
1230 | cy_as_device_set_firmware_not_loaded(dev_p); | ||
1231 | cy_as_device_set_dma_stopped(dev_p); | ||
1232 | cy_as_device_set_low_level_stopped(dev_p); | ||
1233 | cy_as_device_set_intr_stopped(dev_p); | ||
1234 | cy_as_device_clear_suspend_mode(dev_p); | ||
1235 | cy_as_usb_cleanup(dev_p); | ||
1236 | cy_as_storage_cleanup(dev_p); | ||
1237 | |||
1238 | /* | ||
1239 | * wait for a small amount of time to | ||
1240 | * allow reset to be complete. | ||
1241 | */ | ||
1242 | cy_as_hal_sleep(100); | ||
1243 | } | ||
1244 | |||
1245 | cy_as_device_clear_reset_pending(dev_p); | ||
1246 | |||
1247 | return CY_AS_ERROR_SUCCESS; | ||
1248 | } | ||
1249 | |||
1250 | cy_as_return_status_t | ||
1251 | cy_as_misc_reset(cy_as_device_handle handle, | ||
1252 | cy_as_reset_type type, | ||
1253 | cy_bool flush, | ||
1254 | cy_as_function_callback cb, | ||
1255 | uint32_t client) | ||
1256 | { | ||
1257 | cy_as_device *dev_p; | ||
1258 | cy_as_end_point_number_t i; | ||
1259 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1260 | (void)client; | ||
1261 | (void)cb; | ||
1262 | |||
1263 | cy_as_log_debug_message(6, "cy_as_misc_reset_e_x called"); | ||
1264 | |||
1265 | /* Make sure the device is ready for the command. */ | ||
1266 | dev_p = (cy_as_device *)handle; | ||
1267 | cy_as_check_device_ready(dev_p); | ||
1268 | |||
1269 | /* | ||
1270 | * soft reset is not supported until we close on the issues | ||
1271 | * in the firmware with what needs to happen. | ||
1272 | */ | ||
1273 | if (type == cy_as_reset_soft) | ||
1274 | return CY_AS_ERROR_NOT_YET_SUPPORTED; | ||
1275 | |||
1276 | cy_as_device_set_reset_pending(dev_p); | ||
1277 | |||
1278 | if (flush) { | ||
1279 | /* Unable to DrainQueues in polling mode */ | ||
1280 | if ((dev_p->storage_cb || dev_p->storage_cb_ms) && | ||
1281 | cy_as_hal_is_polling()) | ||
1282 | return CY_AS_ERROR_ASYNC_PENDING; | ||
1283 | |||
1284 | /* | ||
1285 | * shutdown the endpoints so no more traffic can be queued | ||
1286 | */ | ||
1287 | for (i = 0; i < 15; i++) | ||
1288 | cy_as_dma_enable_end_point(dev_p, i, cy_false, | ||
1289 | cy_as_direction_dont_change); | ||
1290 | |||
1291 | /* | ||
1292 | * if we are in normal mode, drain all traffic across all | ||
1293 | * endpoints to be sure all traffic is flushed. if the | ||
1294 | * device is suspended, data will not be coming in on any | ||
1295 | * endpoint and all outstanding DMA operations can be | ||
1296 | * cancelled. | ||
1297 | */ | ||
1298 | if (cy_as_device_is_in_suspend_mode(dev_p)) { | ||
1299 | for (i = 0; i < 15; i++) | ||
1300 | cy_as_dma_cancel(dev_p, i, | ||
1301 | CY_AS_ERROR_CANCELED); | ||
1302 | } else { | ||
1303 | for (i = 0; i < 15; i++) { | ||
1304 | if ((i == CY_AS_P2S_WRITE_ENDPOINT) || | ||
1305 | (i == CY_AS_P2S_READ_ENDPOINT)) | ||
1306 | cy_as_dma_drain_queue(dev_p, i, | ||
1307 | cy_false); | ||
1308 | else | ||
1309 | cy_as_dma_drain_queue(dev_p, i, | ||
1310 | cy_true); | ||
1311 | } | ||
1312 | } | ||
1313 | } else { | ||
1314 | /* No flush was requested, so cancel any outstanding DMAs | ||
1315 | * so the user callbacks are called as needed | ||
1316 | */ | ||
1317 | if (cy_as_device_is_storage_async_pending(dev_p)) { | ||
1318 | for (i = 0; i < 15; i++) | ||
1319 | cy_as_dma_cancel(dev_p, i, | ||
1320 | CY_AS_ERROR_CANCELED); | ||
1321 | } | ||
1322 | } | ||
1323 | |||
1324 | ret = my_handle_response_reset(dev_p, 0, 0, type); | ||
1325 | |||
1326 | if (cb) | ||
1327 | /* Even though no mailbox communication was needed, | ||
1328 | * issue the callback so the user does not need to | ||
1329 | * special case their code. */ | ||
1330 | cb((cy_as_device_handle)dev_p, ret, client, | ||
1331 | CY_FUNCT_CB_MISC_RESET, 0); | ||
1332 | |||
1333 | /* | ||
1334 | * initialize any registers that may have been | ||
1335 | * changed when the device was reset. | ||
1336 | */ | ||
1337 | cy_as_hal_init_dev_registers(dev_p->tag, cy_false); | ||
1338 | |||
1339 | return ret; | ||
1340 | } | ||
1341 | EXPORT_SYMBOL(cy_as_misc_reset); | ||
1342 | |||
1343 | static cy_as_return_status_t | ||
1344 | get_unallocated_resource(cy_as_device *dev_p, cy_as_resource_type resource) | ||
1345 | { | ||
1346 | uint8_t shift = 0; | ||
1347 | uint16_t v; | ||
1348 | cy_as_return_status_t ret = CY_AS_ERROR_NOT_ACQUIRED; | ||
1349 | |||
1350 | switch (resource) { | ||
1351 | case cy_as_bus_u_s_b: | ||
1352 | shift = 4; | ||
1353 | break; | ||
1354 | case cy_as_bus_1: | ||
1355 | shift = 0; | ||
1356 | break; | ||
1357 | case cy_as_bus_0: | ||
1358 | shift = 2; | ||
1359 | break; | ||
1360 | default: | ||
1361 | cy_as_hal_assert(cy_false); | ||
1362 | break; | ||
1363 | } | ||
1364 | |||
1365 | /* Get the semaphore value for this resource */ | ||
1366 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_RSE_ALLOCATE); | ||
1367 | v = (v >> shift) & 0x03; | ||
1368 | |||
1369 | if (v == 0x03) { | ||
1370 | ret = CY_AS_ERROR_RESOURCE_ALREADY_OWNED; | ||
1371 | } else if ((v & 0x01) == 0) { | ||
1372 | /* The resource is not owned by anyone, we can try to get it */ | ||
1373 | cy_as_hal_write_register(dev_p->tag, | ||
1374 | CY_AS_MEM_P0_RSE_MASK, (0x03 << shift)); | ||
1375 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_RSE_MASK); | ||
1376 | cy_as_hal_write_register(dev_p->tag, | ||
1377 | CY_AS_MEM_P0_RSE_ALLOCATE, (0x01 << shift)); | ||
1378 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_P0_RSE_MASK); | ||
1379 | |||
1380 | v = cy_as_hal_read_register(dev_p->tag, | ||
1381 | CY_AS_MEM_P0_RSE_ALLOCATE); | ||
1382 | v = (v >> shift) & 0x03; | ||
1383 | if (v == 0x03) | ||
1384 | ret = CY_AS_ERROR_SUCCESS; | ||
1385 | } | ||
1386 | |||
1387 | return ret; | ||
1388 | } | ||
1389 | |||
1390 | static cy_as_return_status_t | ||
1391 | my_handle_response_acquire_resource(cy_as_device *dev_p, | ||
1392 | cy_as_ll_request_response *req_p, | ||
1393 | cy_as_ll_request_response *reply_p, | ||
1394 | cy_as_resource_type *resource) | ||
1395 | { | ||
1396 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1397 | |||
1398 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1399 | CY_RESP_SUCCESS_FAILURE) { | ||
1400 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1401 | goto destroy; | ||
1402 | } | ||
1403 | |||
1404 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
1405 | ret = get_unallocated_resource(dev_p, *resource); | ||
1406 | if (ret != CY_AS_ERROR_NOT_ACQUIRED) | ||
1407 | ret = CY_AS_ERROR_SUCCESS; | ||
1408 | } | ||
1409 | |||
1410 | destroy: | ||
1411 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1412 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1413 | |||
1414 | return ret; | ||
1415 | } | ||
1416 | |||
1417 | cy_as_return_status_t | ||
1418 | cy_as_misc_acquire_resource(cy_as_device_handle handle, | ||
1419 | cy_as_resource_type *resource, | ||
1420 | cy_bool force, | ||
1421 | cy_as_function_callback cb, | ||
1422 | uint32_t client) | ||
1423 | { | ||
1424 | cy_as_ll_request_response *req_p, *reply_p; | ||
1425 | cy_as_return_status_t ret; | ||
1426 | |||
1427 | cy_as_device *dev_p; | ||
1428 | |||
1429 | (void)client; | ||
1430 | |||
1431 | cy_as_log_debug_message(6, "cy_as_misc_acquire_resource called"); | ||
1432 | |||
1433 | if (*resource != cy_as_bus_u_s_b && *resource != | ||
1434 | cy_as_bus_0 && *resource != cy_as_bus_1) | ||
1435 | return CY_AS_ERROR_INVALID_RESOURCE; | ||
1436 | |||
1437 | |||
1438 | /* Make sure the device is ready to accept the command. */ | ||
1439 | dev_p = (cy_as_device *)handle; | ||
1440 | cy_as_check_device_ready(dev_p); | ||
1441 | |||
1442 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1443 | return CY_AS_ERROR_IN_SUSPEND; | ||
1444 | |||
1445 | |||
1446 | ret = get_unallocated_resource(dev_p, *resource); | ||
1447 | |||
1448 | /* | ||
1449 | * make sure that the callback is called if the resource is | ||
1450 | * successfully acquired at this point. | ||
1451 | */ | ||
1452 | if ((ret == CY_AS_ERROR_SUCCESS) && (cb != 0)) | ||
1453 | cb(handle, ret, client, | ||
1454 | CY_FUNCT_CB_MISC_ACQUIRERESOURCE, resource); | ||
1455 | |||
1456 | if (ret != CY_AS_ERROR_NOT_ACQUIRED) | ||
1457 | return ret; | ||
1458 | |||
1459 | if (!force) | ||
1460 | return CY_AS_ERROR_NOT_ACQUIRED; | ||
1461 | |||
1462 | /* Create the request to acquire the resource */ | ||
1463 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_ACQUIRE_RESOURCE, | ||
1464 | CY_RQT_RESOURCE_RQT_CONTEXT, 1); | ||
1465 | if (req_p == 0) | ||
1466 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1467 | |||
1468 | cy_as_ll_request_response__set_word(req_p, 0, (uint16_t)(*resource)); | ||
1469 | |||
1470 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1471 | if (reply_p == 0) { | ||
1472 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1473 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1474 | } | ||
1475 | |||
1476 | if (cb == 0) { | ||
1477 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1478 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1479 | goto destroy; | ||
1480 | |||
1481 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1482 | CY_RESP_SUCCESS_FAILURE) { | ||
1483 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1484 | goto destroy; | ||
1485 | } | ||
1486 | |||
1487 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1488 | } else { | ||
1489 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1490 | CY_FUNCT_CB_MISC_ACQUIRERESOURCE, resource, | ||
1491 | dev_p->func_cbs_res, CY_AS_REQUEST_RESPONSE_EX, | ||
1492 | req_p, reply_p, cy_as_misc_func_callback); | ||
1493 | |||
1494 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1495 | goto destroy; | ||
1496 | |||
1497 | /* The request and response are freed | ||
1498 | * as part of the MiscFuncCallback */ | ||
1499 | return ret; | ||
1500 | } | ||
1501 | |||
1502 | destroy: | ||
1503 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1504 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1505 | |||
1506 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
1507 | ret = get_unallocated_resource(dev_p, *resource); | ||
1508 | if (ret != CY_AS_ERROR_NOT_ACQUIRED) | ||
1509 | ret = CY_AS_ERROR_SUCCESS; | ||
1510 | } | ||
1511 | |||
1512 | return ret; | ||
1513 | } | ||
1514 | EXPORT_SYMBOL(cy_as_misc_acquire_resource); | ||
1515 | |||
1516 | cy_as_return_status_t | ||
1517 | cy_as_misc_release_resource(cy_as_device_handle handle, | ||
1518 | cy_as_resource_type resource) | ||
1519 | { | ||
1520 | uint8_t shift = 0; | ||
1521 | uint16_t v; | ||
1522 | |||
1523 | cy_as_device *dev_p; | ||
1524 | |||
1525 | cy_as_log_debug_message(6, "cy_as_misc_release_resource called"); | ||
1526 | |||
1527 | /* Make sure the device is ready for the command. */ | ||
1528 | dev_p = (cy_as_device *)handle; | ||
1529 | cy_as_check_device_ready(dev_p); | ||
1530 | |||
1531 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1532 | return CY_AS_ERROR_IN_SUSPEND; | ||
1533 | |||
1534 | if (resource != cy_as_bus_u_s_b && resource != | ||
1535 | cy_as_bus_0 && resource != cy_as_bus_1) | ||
1536 | return CY_AS_ERROR_INVALID_RESOURCE; | ||
1537 | |||
1538 | switch (resource) { | ||
1539 | case cy_as_bus_u_s_b: | ||
1540 | shift = 4; | ||
1541 | break; | ||
1542 | case cy_as_bus_1: | ||
1543 | shift = 0; | ||
1544 | break; | ||
1545 | case cy_as_bus_0: | ||
1546 | shift = 2; | ||
1547 | break; | ||
1548 | default: | ||
1549 | cy_as_hal_assert(cy_false); | ||
1550 | break; | ||
1551 | } | ||
1552 | |||
1553 | /* Get the semaphore value for this resource */ | ||
1554 | v = (cy_as_hal_read_register(dev_p->tag, | ||
1555 | CY_AS_MEM_P0_RSE_ALLOCATE) >> shift) & 0x03; | ||
1556 | if (v == 0 || v == 1 || v == 2) | ||
1557 | return CY_AS_ERROR_RESOURCE_NOT_OWNED; | ||
1558 | |||
1559 | cy_as_hal_write_register(dev_p->tag, | ||
1560 | CY_AS_MEM_P0_RSE_MASK, (0x03 << shift)); | ||
1561 | cy_as_hal_write_register(dev_p->tag, | ||
1562 | CY_AS_MEM_P0_RSE_ALLOCATE, (0x02 << shift)); | ||
1563 | cy_as_hal_write_register(dev_p->tag, | ||
1564 | CY_AS_MEM_P0_RSE_MASK, 0); | ||
1565 | |||
1566 | return CY_AS_ERROR_SUCCESS; | ||
1567 | } | ||
1568 | EXPORT_SYMBOL(cy_as_misc_release_resource); | ||
1569 | |||
1570 | cy_as_return_status_t | ||
1571 | cy_as_misc_set_trace_level(cy_as_device_handle handle, | ||
1572 | uint8_t level, | ||
1573 | cy_as_bus_number_t bus, | ||
1574 | uint32_t device, | ||
1575 | uint32_t unit, | ||
1576 | cy_as_function_callback cb, | ||
1577 | uint32_t client) | ||
1578 | { | ||
1579 | cy_as_ll_request_response *req_p, *reply_p; | ||
1580 | cy_as_return_status_t ret; | ||
1581 | cy_as_device *dev_p; | ||
1582 | |||
1583 | cy_as_log_debug_message(6, "cy_as_misc_set_trace_level called"); | ||
1584 | |||
1585 | /* Make sure the device is ready for the command. */ | ||
1586 | dev_p = (cy_as_device *)handle; | ||
1587 | cy_as_check_device_ready(dev_p); | ||
1588 | |||
1589 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1590 | return CY_AS_ERROR_IN_SUSPEND; | ||
1591 | |||
1592 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
1593 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
1594 | |||
1595 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
1596 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
1597 | |||
1598 | if (unit > 255) | ||
1599 | return CY_AS_ERROR_NO_SUCH_UNIT; | ||
1600 | |||
1601 | if (level >= CYAS_FW_TRACE_MAX_LEVEL) | ||
1602 | return CY_AS_ERROR_INVALID_TRACE_LEVEL; | ||
1603 | |||
1604 | /* Create the request to send to the West Bridge device */ | ||
1605 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SET_TRACE_LEVEL, | ||
1606 | CY_RQT_GENERAL_RQT_CONTEXT, 2); | ||
1607 | if (req_p == 0) | ||
1608 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1609 | |||
1610 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1611 | (uint16_t)level); | ||
1612 | cy_as_ll_request_response__set_word(req_p, 1, | ||
1613 | (uint16_t)((bus << 12) | (device << 8) | (unit))); | ||
1614 | |||
1615 | /* | ||
1616 | * Reserve space for the reply, the reply data will not | ||
1617 | * exceed three words | ||
1618 | */ | ||
1619 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
1620 | if (reply_p == 0) { | ||
1621 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1622 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1623 | } | ||
1624 | |||
1625 | if (cb == 0) { | ||
1626 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1627 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1628 | goto destroy; | ||
1629 | |||
1630 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1631 | CY_RESP_SUCCESS_FAILURE) { | ||
1632 | ret = CY_AS_ERROR_NOT_SUPPORTED; | ||
1633 | goto destroy; | ||
1634 | } | ||
1635 | |||
1636 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1637 | } else { | ||
1638 | |||
1639 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1640 | CY_FUNCT_CB_MISC_SETTRACELEVEL, 0, dev_p->func_cbs_misc, | ||
1641 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1642 | cy_as_misc_func_callback); | ||
1643 | |||
1644 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1645 | goto destroy; | ||
1646 | |||
1647 | /* The request and response are freed as part of the | ||
1648 | * MiscFuncCallback */ | ||
1649 | return ret; | ||
1650 | } | ||
1651 | |||
1652 | destroy: | ||
1653 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1654 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1655 | |||
1656 | return ret; | ||
1657 | } | ||
1658 | |||
1659 | cy_as_return_status_t | ||
1660 | cy_as_misc_heart_beat_control(cy_as_device_handle handle, | ||
1661 | cy_bool enable, | ||
1662 | cy_as_function_callback cb, | ||
1663 | uint32_t client) | ||
1664 | { | ||
1665 | cy_as_ll_request_response *req_p, *reply_p; | ||
1666 | cy_as_return_status_t ret; | ||
1667 | cy_as_device *dev_p; | ||
1668 | |||
1669 | cy_as_log_debug_message(6, "cy_as_misc_heart_beat_control called"); | ||
1670 | |||
1671 | /* Make sure the device is ready for the command. */ | ||
1672 | dev_p = (cy_as_device *)handle; | ||
1673 | cy_as_check_device_ready(dev_p); | ||
1674 | |||
1675 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1676 | return CY_AS_ERROR_IN_SUSPEND; | ||
1677 | |||
1678 | /* Create the request to send to the West Bridge device */ | ||
1679 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_CONTROL_ANTIOCH_HEARTBEAT, | ||
1680 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1681 | if (req_p == 0) | ||
1682 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1683 | |||
1684 | cy_as_ll_request_response__set_word(req_p, 0, (uint16_t)enable); | ||
1685 | |||
1686 | /* Reserve space for the reply, the reply | ||
1687 | * data will not exceed one word */ | ||
1688 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1689 | if (reply_p == 0) { | ||
1690 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1691 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1692 | } | ||
1693 | |||
1694 | if (cb == 0) { | ||
1695 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1696 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1697 | goto destroy; | ||
1698 | |||
1699 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1700 | CY_RESP_SUCCESS_FAILURE) { | ||
1701 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1702 | goto destroy; | ||
1703 | } | ||
1704 | |||
1705 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1706 | } else { | ||
1707 | |||
1708 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1709 | CY_FUNCT_CB_MISC_HEARTBEATCONTROL, 0, | ||
1710 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
1711 | req_p, reply_p, cy_as_misc_func_callback); | ||
1712 | |||
1713 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1714 | goto destroy; | ||
1715 | |||
1716 | /* The request and response are freed as part of the | ||
1717 | * MiscFuncCallback */ | ||
1718 | return ret; | ||
1719 | } | ||
1720 | |||
1721 | destroy: | ||
1722 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1723 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1724 | |||
1725 | return ret; | ||
1726 | } | ||
1727 | EXPORT_SYMBOL(cy_as_misc_heart_beat_control); | ||
1728 | |||
1729 | static cy_as_return_status_t | ||
1730 | my_set_sd_clock_freq( | ||
1731 | cy_as_device *dev_p, | ||
1732 | uint8_t card_type, | ||
1733 | uint8_t setting, | ||
1734 | cy_as_function_callback cb, | ||
1735 | uint32_t client) | ||
1736 | { | ||
1737 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1738 | cy_as_ll_request_response *req_p, *reply_p; | ||
1739 | |||
1740 | if (cy_as_device_is_in_callback(dev_p) && (cb == 0)) | ||
1741 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1742 | |||
1743 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SET_SD_CLOCK_FREQ, | ||
1744 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1745 | if (req_p == 0) | ||
1746 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1747 | |||
1748 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1749 | (uint16_t)((card_type << 8) | setting)); | ||
1750 | |||
1751 | /* Reserve space for the reply, which will not exceed one word. */ | ||
1752 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1753 | if (reply_p == 0) { | ||
1754 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1755 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1756 | } | ||
1757 | |||
1758 | if (cb == 0) { | ||
1759 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1760 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1761 | goto destroy; | ||
1762 | |||
1763 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1764 | CY_RESP_SUCCESS_FAILURE) { | ||
1765 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1766 | goto destroy; | ||
1767 | } | ||
1768 | |||
1769 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1770 | } else { | ||
1771 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1772 | CY_FUNCT_CB_MISC_SETSDFREQ, 0, dev_p->func_cbs_misc, | ||
1773 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1774 | cy_as_misc_func_callback); | ||
1775 | |||
1776 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1777 | goto destroy; | ||
1778 | |||
1779 | /* The request and response are freed as part of the | ||
1780 | * MiscFuncCallback */ | ||
1781 | return ret; | ||
1782 | } | ||
1783 | |||
1784 | destroy: | ||
1785 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1786 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1787 | |||
1788 | return ret; | ||
1789 | } | ||
1790 | |||
1791 | cy_as_return_status_t | ||
1792 | cy_as_misc_set_low_speed_sd_freq( | ||
1793 | cy_as_device_handle handle, | ||
1794 | cy_as_low_speed_sd_freq setting, | ||
1795 | cy_as_function_callback cb, | ||
1796 | uint32_t client) | ||
1797 | { | ||
1798 | cy_as_device *dev_p; | ||
1799 | |||
1800 | cy_as_log_debug_message(6, "cy_as_misc_set_low_speed_sd_freq called"); | ||
1801 | |||
1802 | /* Make sure the device is ready for the command. */ | ||
1803 | dev_p = (cy_as_device *)handle; | ||
1804 | cy_as_check_device_ready(dev_p); | ||
1805 | |||
1806 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1807 | return CY_AS_ERROR_IN_SUSPEND; | ||
1808 | |||
1809 | if ((setting != CY_AS_SD_DEFAULT_FREQ) && | ||
1810 | (setting != CY_AS_SD_RATED_FREQ)) | ||
1811 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
1812 | |||
1813 | return my_set_sd_clock_freq(dev_p, 0, (uint8_t)setting, cb, client); | ||
1814 | } | ||
1815 | EXPORT_SYMBOL(cy_as_misc_set_low_speed_sd_freq); | ||
1816 | |||
1817 | cy_as_return_status_t | ||
1818 | cy_as_misc_set_high_speed_sd_freq( | ||
1819 | cy_as_device_handle handle, | ||
1820 | cy_as_high_speed_sd_freq setting, | ||
1821 | cy_as_function_callback cb, | ||
1822 | uint32_t client) | ||
1823 | { | ||
1824 | cy_as_device *dev_p; | ||
1825 | |||
1826 | cy_as_log_debug_message(6, "cy_as_misc_set_high_speed_sd_freq called"); | ||
1827 | |||
1828 | /* Make sure the device is ready for the command. */ | ||
1829 | dev_p = (cy_as_device *)handle; | ||
1830 | cy_as_check_device_ready(dev_p); | ||
1831 | |||
1832 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1833 | return CY_AS_ERROR_IN_SUSPEND; | ||
1834 | |||
1835 | if ((setting != CY_AS_HS_SD_FREQ_24) && | ||
1836 | (setting != CY_AS_HS_SD_FREQ_48)) | ||
1837 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
1838 | |||
1839 | return my_set_sd_clock_freq(dev_p, 1, (uint8_t)setting, cb, client); | ||
1840 | } | ||
1841 | EXPORT_SYMBOL(cy_as_misc_set_high_speed_sd_freq); | ||
1842 | |||
1843 | cy_as_return_status_t | ||
1844 | cy_as_misc_get_gpio_value(cy_as_device_handle handle, | ||
1845 | cy_as_misc_gpio pin, | ||
1846 | uint8_t *value, | ||
1847 | cy_as_function_callback cb, | ||
1848 | uint32_t client) | ||
1849 | { | ||
1850 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1851 | cy_as_ll_request_response *req_p, *reply_p; | ||
1852 | cy_as_device *dev_p; | ||
1853 | uint16_t v; | ||
1854 | |||
1855 | cy_as_log_debug_message(6, "cy_as_misc_get_gpio_value called"); | ||
1856 | |||
1857 | /* Make sure the device is ready for the command. */ | ||
1858 | dev_p = (cy_as_device *)handle; | ||
1859 | cy_as_check_device_ready(dev_p); | ||
1860 | |||
1861 | /* If the pin specified is UVALID, there is no need | ||
1862 | * for firmware to be loaded. */ | ||
1863 | if (pin == cy_as_misc_gpio_U_valid) { | ||
1864 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PMU_UPDATE); | ||
1865 | *value = (uint8_t)(v & CY_AS_MEM_PMU_UPDATE_UVALID); | ||
1866 | |||
1867 | if (cb != 0) | ||
1868 | cb(dev_p, ret, client, | ||
1869 | CY_FUNCT_CB_MISC_GETGPIOVALUE, value); | ||
1870 | |||
1871 | return ret; | ||
1872 | } | ||
1873 | |||
1874 | /* Check whether the firmware supports this command. */ | ||
1875 | if (cy_as_device_is_nand_storage_supported(dev_p)) | ||
1876 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
1877 | |||
1878 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1879 | return CY_AS_ERROR_IN_SUSPEND; | ||
1880 | |||
1881 | /* Make sure the pin selected is valid */ | ||
1882 | if ((pin != cy_as_misc_gpio_1) && (pin != cy_as_misc_gpio_0)) | ||
1883 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
1884 | |||
1885 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_GET_GPIO_STATE, | ||
1886 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1887 | if (req_p == 0) | ||
1888 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1889 | |||
1890 | cy_as_ll_request_response__set_word(req_p, 0, ((uint8_t)pin << 8)); | ||
1891 | |||
1892 | /* Reserve space for the reply, which will not exceed one word. */ | ||
1893 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1894 | if (reply_p == 0) { | ||
1895 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1896 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1897 | } | ||
1898 | |||
1899 | if (cb == 0) { | ||
1900 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1901 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1902 | goto destroy; | ||
1903 | |||
1904 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1905 | CY_RESP_GPIO_STATE) { | ||
1906 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1907 | goto destroy; | ||
1908 | } | ||
1909 | |||
1910 | *value = (uint8_t) | ||
1911 | cy_as_ll_request_response__get_word(reply_p, 0); | ||
1912 | } else { | ||
1913 | |||
1914 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1915 | CY_FUNCT_CB_MISC_GETGPIOVALUE, value, | ||
1916 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
1917 | req_p, reply_p, cy_as_misc_func_callback); | ||
1918 | |||
1919 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1920 | goto destroy; | ||
1921 | |||
1922 | /* The request and response are freed as part of the | ||
1923 | * MiscFuncCallback */ | ||
1924 | return ret; | ||
1925 | } | ||
1926 | |||
1927 | destroy: | ||
1928 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1929 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1930 | |||
1931 | return ret; | ||
1932 | } | ||
1933 | EXPORT_SYMBOL(cy_as_misc_get_gpio_value); | ||
1934 | |||
1935 | cy_as_return_status_t | ||
1936 | cy_as_misc_set_gpio_value(cy_as_device_handle handle, | ||
1937 | cy_as_misc_gpio pin, | ||
1938 | uint8_t value, | ||
1939 | cy_as_function_callback cb, | ||
1940 | uint32_t client) | ||
1941 | { | ||
1942 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1943 | cy_as_ll_request_response *req_p, *reply_p; | ||
1944 | cy_as_device *dev_p; | ||
1945 | uint16_t v; | ||
1946 | |||
1947 | cy_as_log_debug_message(6, "cy_as_misc_set_gpio_value called"); | ||
1948 | |||
1949 | /* Make sure the device is ready for the command. */ | ||
1950 | dev_p = (cy_as_device *)handle; | ||
1951 | cy_as_check_device_ready(dev_p); | ||
1952 | |||
1953 | /* If the pin specified is UVALID, there is | ||
1954 | * no need for firmware to be loaded. */ | ||
1955 | if (pin == cy_as_misc_gpio_U_valid) { | ||
1956 | v = cy_as_hal_read_register(dev_p->tag, CY_AS_MEM_PMU_UPDATE); | ||
1957 | if (value) | ||
1958 | cy_as_hal_write_register(dev_p->tag, | ||
1959 | CY_AS_MEM_PMU_UPDATE, | ||
1960 | (v | CY_AS_MEM_PMU_UPDATE_UVALID)); | ||
1961 | else | ||
1962 | cy_as_hal_write_register(dev_p->tag, | ||
1963 | CY_AS_MEM_PMU_UPDATE, | ||
1964 | (v & ~CY_AS_MEM_PMU_UPDATE_UVALID)); | ||
1965 | |||
1966 | if (cb != 0) | ||
1967 | cb(dev_p, ret, client, | ||
1968 | CY_FUNCT_CB_MISC_SETGPIOVALUE, 0); | ||
1969 | return ret; | ||
1970 | } | ||
1971 | |||
1972 | /* Check whether the firmware supports this command. */ | ||
1973 | if (cy_as_device_is_nand_storage_supported(dev_p)) | ||
1974 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
1975 | |||
1976 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1977 | return CY_AS_ERROR_IN_SUSPEND; | ||
1978 | |||
1979 | /* Make sure the pin selected is valid */ | ||
1980 | if ((pin < cy_as_misc_gpio_0) || (pin > cy_as_misc_gpio_U_valid)) | ||
1981 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
1982 | |||
1983 | /* Create and initialize the low level request to the firmware. */ | ||
1984 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SET_GPIO_STATE, | ||
1985 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
1986 | if (req_p == 0) | ||
1987 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1988 | |||
1989 | v = (uint16_t)(((uint8_t)pin << 8) | (value > 0)); | ||
1990 | cy_as_ll_request_response__set_word(req_p, 0, v); | ||
1991 | |||
1992 | /* Reserve space for the reply, which will not exceed one word. */ | ||
1993 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1994 | if (reply_p == 0) { | ||
1995 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1996 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1997 | } | ||
1998 | |||
1999 | if (cb == 0) { | ||
2000 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2001 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2002 | goto destroy; | ||
2003 | |||
2004 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2005 | CY_RESP_SUCCESS_FAILURE) { | ||
2006 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2007 | goto destroy; | ||
2008 | } | ||
2009 | |||
2010 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2011 | } else { | ||
2012 | |||
2013 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2014 | CY_FUNCT_CB_MISC_SETGPIOVALUE, 0, | ||
2015 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
2016 | req_p, reply_p, cy_as_misc_func_callback); | ||
2017 | |||
2018 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2019 | goto destroy; | ||
2020 | |||
2021 | /* The request and response are freed as part of the | ||
2022 | * MiscFuncCallback */ | ||
2023 | return ret; | ||
2024 | } | ||
2025 | |||
2026 | destroy: | ||
2027 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2028 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2029 | |||
2030 | return ret; | ||
2031 | } | ||
2032 | EXPORT_SYMBOL(cy_as_misc_set_gpio_value); | ||
2033 | |||
2034 | static cy_as_return_status_t | ||
2035 | my_enter_standby(cy_as_device *dev_p, cy_bool pin) | ||
2036 | { | ||
2037 | cy_as_misc_cancel_ex_requests(dev_p); | ||
2038 | |||
2039 | /* Save the current values in the critical P-port | ||
2040 | * registers, where necessary. */ | ||
2041 | cy_as_hal_read_regs_before_standby(dev_p->tag); | ||
2042 | |||
2043 | if (pin) { | ||
2044 | if (cy_as_hal_set_wakeup_pin(dev_p->tag, cy_false)) | ||
2045 | cy_as_device_set_pin_standby(dev_p); | ||
2046 | else | ||
2047 | return CY_AS_ERROR_SETTING_WAKEUP_PIN; | ||
2048 | } else { | ||
2049 | /* | ||
2050 | * put antioch in the standby mode | ||
2051 | */ | ||
2052 | cy_as_hal_write_register(dev_p->tag, | ||
2053 | CY_AS_MEM_PWR_MAGT_STAT, 0x02); | ||
2054 | cy_as_device_set_register_standby(dev_p); | ||
2055 | } | ||
2056 | |||
2057 | /* | ||
2058 | * when the antioch comes out of standby, we have to wait until | ||
2059 | * the firmware initialization completes before sending other | ||
2060 | * requests down. | ||
2061 | */ | ||
2062 | cy_as_device_set_firmware_not_loaded(dev_p); | ||
2063 | |||
2064 | /* | ||
2065 | * keep west bridge interrupt disabled until the device is being woken | ||
2066 | * up from standby. | ||
2067 | */ | ||
2068 | dev_p->stby_int_mask = cy_as_hal_disable_interrupts(); | ||
2069 | |||
2070 | return CY_AS_ERROR_SUCCESS; | ||
2071 | } | ||
2072 | |||
2073 | static cy_as_return_status_t | ||
2074 | my_handle_response_enter_standby(cy_as_device *dev_p, | ||
2075 | cy_as_ll_request_response *req_p, | ||
2076 | cy_as_ll_request_response *reply_p, | ||
2077 | cy_bool pin) | ||
2078 | { | ||
2079 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2080 | |||
2081 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2082 | CY_RESP_SUCCESS_FAILURE) { | ||
2083 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2084 | goto destroy; | ||
2085 | } | ||
2086 | |||
2087 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2088 | |||
2089 | destroy: | ||
2090 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2091 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2092 | |||
2093 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2094 | return ret; | ||
2095 | |||
2096 | ret = my_enter_standby(dev_p, pin); | ||
2097 | |||
2098 | return ret; | ||
2099 | } | ||
2100 | |||
2101 | cy_as_return_status_t | ||
2102 | cy_as_misc_enter_standby(cy_as_device_handle handle, | ||
2103 | cy_bool pin, | ||
2104 | cy_as_function_callback cb, | ||
2105 | uint32_t client) | ||
2106 | { | ||
2107 | cy_as_device *dev_p; | ||
2108 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2109 | cy_as_ll_request_response *req_p, *reply_p; | ||
2110 | cy_bool standby; | ||
2111 | |||
2112 | cy_as_log_debug_message(6, "cy_as_misc_enter_standby called"); | ||
2113 | |||
2114 | /* Make sure we have a valid device */ | ||
2115 | dev_p = (cy_as_device *)handle; | ||
2116 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2117 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2118 | |||
2119 | /* | ||
2120 | * if we already are in standby, do not do it again and let the | ||
2121 | * user know via the error return. | ||
2122 | */ | ||
2123 | ret = cy_as_misc_in_standby(handle, &standby); | ||
2124 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2125 | return ret; | ||
2126 | |||
2127 | if (standby == cy_true) | ||
2128 | return CY_AS_ERROR_ALREADY_STANDBY; | ||
2129 | |||
2130 | /* | ||
2131 | * if the user wants to transition from suspend mode to standby mode, | ||
2132 | * the device needs to be woken up so that it can complete all pending | ||
2133 | * operations. | ||
2134 | */ | ||
2135 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2136 | cy_as_misc_leave_suspend(dev_p, 0, 0); | ||
2137 | |||
2138 | if (dev_p->usb_count) { | ||
2139 | /* | ||
2140 | * we do not allow west bridge to go into standby mode when the | ||
2141 | * USB stack is initialized. you must stop the USB stack in | ||
2142 | * order to enter standby mode. | ||
2143 | */ | ||
2144 | return CY_AS_ERROR_USB_RUNNING; | ||
2145 | } | ||
2146 | |||
2147 | /* | ||
2148 | * if the storage stack is not running, the device can directly be | ||
2149 | * put into sleep mode. otherwise, the firmware needs to be signaled | ||
2150 | * to prepare for going into sleep mode. | ||
2151 | */ | ||
2152 | if (dev_p->storage_count) { | ||
2153 | /* | ||
2154 | * if there are async storage operations pending, | ||
2155 | * make one attempt to complete them. | ||
2156 | */ | ||
2157 | if (cy_as_device_is_storage_async_pending(dev_p)) { | ||
2158 | /* DrainQueue will not work in polling mode */ | ||
2159 | if (cy_as_hal_is_polling()) | ||
2160 | return CY_AS_ERROR_ASYNC_PENDING; | ||
2161 | |||
2162 | cy_as_dma_drain_queue(dev_p, | ||
2163 | CY_AS_P2S_READ_ENDPOINT, cy_false); | ||
2164 | cy_as_dma_drain_queue(dev_p, | ||
2165 | CY_AS_P2S_WRITE_ENDPOINT, cy_false); | ||
2166 | |||
2167 | /* | ||
2168 | * if more storage operations were queued | ||
2169 | * at this stage, return an error. | ||
2170 | */ | ||
2171 | if (cy_as_device_is_storage_async_pending(dev_p)) | ||
2172 | return CY_AS_ERROR_ASYNC_PENDING; | ||
2173 | } | ||
2174 | |||
2175 | req_p = cy_as_ll_create_request(dev_p, | ||
2176 | CY_RQT_PREPARE_FOR_STANDBY, | ||
2177 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
2178 | if (req_p == 0) | ||
2179 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2180 | |||
2181 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2182 | if (reply_p == 0) { | ||
2183 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2184 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2185 | } | ||
2186 | |||
2187 | if (!cb) { | ||
2188 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
2189 | req_p, reply_p); | ||
2190 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2191 | goto destroy; | ||
2192 | |||
2193 | /* The request and response are freed | ||
2194 | * in the HandleResponse */ | ||
2195 | return my_handle_response_enter_standby(dev_p, | ||
2196 | req_p, reply_p, pin); | ||
2197 | |||
2198 | } else { | ||
2199 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2200 | CY_FUNCT_CB_MISC_ENTERSTANDBY, (void *)pin, | ||
2201 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
2202 | req_p, reply_p, cy_as_misc_func_callback); | ||
2203 | |||
2204 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2205 | goto destroy; | ||
2206 | |||
2207 | /* The request and response are freed | ||
2208 | * as part of the MiscFuncCallback */ | ||
2209 | return ret; | ||
2210 | } | ||
2211 | destroy: | ||
2212 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2213 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2214 | } else { | ||
2215 | ret = my_enter_standby(dev_p, pin); | ||
2216 | if (cb) | ||
2217 | /* Even though no mailbox communication was | ||
2218 | * needed, issue the callback so the user | ||
2219 | * does not need to special case their code. */ | ||
2220 | cb((cy_as_device_handle)dev_p, ret, client, | ||
2221 | CY_FUNCT_CB_MISC_ENTERSTANDBY, 0); | ||
2222 | } | ||
2223 | |||
2224 | return ret; | ||
2225 | } | ||
2226 | EXPORT_SYMBOL(cy_as_misc_enter_standby); | ||
2227 | |||
2228 | cy_as_return_status_t | ||
2229 | cy_as_misc_enter_standby_e_x_u(cy_as_device_handle handle, | ||
2230 | cy_bool pin, | ||
2231 | cy_bool uvalid_special, | ||
2232 | cy_as_function_callback cb, | ||
2233 | uint32_t client) | ||
2234 | { | ||
2235 | cy_as_device *dev_p; | ||
2236 | |||
2237 | dev_p = (cy_as_device *)handle; | ||
2238 | if (uvalid_special) | ||
2239 | cy_as_hal_write_register(dev_p->tag, 0xc5, 0x4); | ||
2240 | |||
2241 | return cy_as_misc_enter_standby(handle, pin, cb, client); | ||
2242 | } | ||
2243 | |||
2244 | cy_as_return_status_t | ||
2245 | cy_as_misc_leave_standby(cy_as_device_handle handle, | ||
2246 | cy_as_resource_type resource) | ||
2247 | { | ||
2248 | cy_as_device *dev_p; | ||
2249 | uint16_t v; | ||
2250 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2251 | uint32_t count = 8; | ||
2252 | uint8_t retry = 1; | ||
2253 | |||
2254 | cy_as_log_debug_message(6, "cy_as_misc_leave_standby called"); | ||
2255 | (void)resource; | ||
2256 | |||
2257 | /* Make sure we have a valid device */ | ||
2258 | dev_p = (cy_as_device *)handle; | ||
2259 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2260 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2261 | |||
2262 | if (cy_as_device_is_register_standby(dev_p)) { | ||
2263 | /* | ||
2264 | * set a flag to indicate that the west bridge is waking | ||
2265 | * up from standby. | ||
2266 | */ | ||
2267 | cy_as_device_set_waking(dev_p); | ||
2268 | |||
2269 | /* | ||
2270 | * the initial read will not succeed, but will just wake | ||
2271 | * the west bridge device from standby. successive reads | ||
2272 | * should succeed and in that way we know west bridge is awake. | ||
2273 | */ | ||
2274 | v = cy_as_hal_read_register(dev_p->tag, | ||
2275 | CY_AS_MEM_CM_WB_CFG_ID); | ||
2276 | |||
2277 | do { | ||
2278 | /* | ||
2279 | * we have initiated the operation to leave standby, now | ||
2280 | * we need to wait at least N ms before trying to access | ||
2281 | * the west bridge device to insure the PLLs have locked | ||
2282 | * and we can talk to the device. | ||
2283 | */ | ||
2284 | if (cy_as_device_is_crystal(dev_p)) | ||
2285 | cy_as_hal_sleep( | ||
2286 | CY_AS_LEAVE_STANDBY_DELAY_CRYSTAL); | ||
2287 | else | ||
2288 | cy_as_hal_sleep( | ||
2289 | CY_AS_LEAVE_STANDBY_DELAY_CLOCK); | ||
2290 | v = cy_as_hal_read_register(dev_p->tag, | ||
2291 | CY_AS_MEM_CM_WB_CFG_ID); | ||
2292 | |||
2293 | /* | ||
2294 | * if the P-SPI interface mode is in use, there may be a | ||
2295 | * need to re-synchronise the serial clock used for | ||
2296 | * astoria access. | ||
2297 | */ | ||
2298 | if (!is_valid_silicon_id(v)) { | ||
2299 | if (cy_as_hal_sync_device_clocks(dev_p->tag) != | ||
2300 | cy_true) { | ||
2301 | cy_as_hal_enable_interrupts( | ||
2302 | dev_p->stby_int_mask); | ||
2303 | return CY_AS_ERROR_TIMEOUT; | ||
2304 | } | ||
2305 | } | ||
2306 | } while (!is_valid_silicon_id(v) && count-- > 0); | ||
2307 | |||
2308 | /* | ||
2309 | * if we tried to read the register and could not, | ||
2310 | * return a timeout | ||
2311 | */ | ||
2312 | if (count == 0) { | ||
2313 | cy_as_hal_enable_interrupts( | ||
2314 | dev_p->stby_int_mask); | ||
2315 | return CY_AS_ERROR_TIMEOUT; | ||
2316 | } | ||
2317 | |||
2318 | /* | ||
2319 | * the standby flag is cleared here, after the action to | ||
2320 | * exit standby has been taken. the wait for firmware | ||
2321 | * initialization, is ensured by marking the firmware as | ||
2322 | * not loaded until the init event is received. | ||
2323 | */ | ||
2324 | cy_as_device_clear_register_standby(dev_p); | ||
2325 | |||
2326 | /* | ||
2327 | * initialize any registers that may have been changed | ||
2328 | * while the device was in standby mode. | ||
2329 | */ | ||
2330 | cy_as_hal_init_dev_registers(dev_p->tag, cy_true); | ||
2331 | } else if (cy_as_device_is_pin_standby(dev_p)) { | ||
2332 | /* | ||
2333 | * set a flag to indicate that the west bridge is waking | ||
2334 | * up from standby. | ||
2335 | */ | ||
2336 | cy_as_device_set_waking(dev_p); | ||
2337 | |||
2338 | try_wakeup_again: | ||
2339 | /* | ||
2340 | * try to set the wakeup pin, if this fails in the HAL | ||
2341 | * layer, return this failure to the user. | ||
2342 | */ | ||
2343 | if (!cy_as_hal_set_wakeup_pin(dev_p->tag, cy_true)) { | ||
2344 | cy_as_hal_enable_interrupts(dev_p->stby_int_mask); | ||
2345 | return CY_AS_ERROR_SETTING_WAKEUP_PIN; | ||
2346 | } | ||
2347 | |||
2348 | /* | ||
2349 | * we have initiated the operation to leave standby, now | ||
2350 | * we need to wait at least N ms before trying to access | ||
2351 | * the west bridge device to insure the PL_ls have locked | ||
2352 | * and we can talk to the device. | ||
2353 | */ | ||
2354 | if (cy_as_device_is_crystal(dev_p)) | ||
2355 | cy_as_hal_sleep(CY_AS_LEAVE_STANDBY_DELAY_CRYSTAL); | ||
2356 | else | ||
2357 | cy_as_hal_sleep(CY_AS_LEAVE_STANDBY_DELAY_CLOCK); | ||
2358 | |||
2359 | /* | ||
2360 | * initialize any registers that may have been changed | ||
2361 | * while the device was in standby mode. | ||
2362 | */ | ||
2363 | cy_as_hal_init_dev_registers(dev_p->tag, cy_true); | ||
2364 | |||
2365 | /* | ||
2366 | * the standby flag is cleared here, after the action to | ||
2367 | * exit standby has been taken. the wait for firmware | ||
2368 | * initialization, is ensured by marking the firmware as | ||
2369 | * not loaded until the init event is received. | ||
2370 | */ | ||
2371 | cy_as_device_clear_pin_standby(dev_p); | ||
2372 | } else { | ||
2373 | return CY_AS_ERROR_NOT_IN_STANDBY; | ||
2374 | } | ||
2375 | |||
2376 | /* | ||
2377 | * the west bridge interrupt can be enabled now. | ||
2378 | */ | ||
2379 | cy_as_hal_enable_interrupts(dev_p->stby_int_mask); | ||
2380 | |||
2381 | /* | ||
2382 | * release the west bridge micro-_controller from reset, | ||
2383 | * so that firmware initialization can complete. the attempt | ||
2384 | * to release antioch reset is made up to 8 times. | ||
2385 | */ | ||
2386 | v = 0x03; | ||
2387 | count = 0x08; | ||
2388 | while ((v & 0x03) && (count)) { | ||
2389 | cy_as_hal_write_register(dev_p->tag, | ||
2390 | CY_AS_MEM_RST_CTRL_REG, 0x00); | ||
2391 | v = cy_as_hal_read_register(dev_p->tag, | ||
2392 | CY_AS_MEM_RST_CTRL_REG); | ||
2393 | count--; | ||
2394 | } | ||
2395 | |||
2396 | if (v & 0x03) { | ||
2397 | cy_as_hal_print_message("failed to clear antioch reset\n"); | ||
2398 | return CY_AS_ERROR_TIMEOUT; | ||
2399 | } | ||
2400 | |||
2401 | /* | ||
2402 | * if the wake-up pin is being used, wait here to make | ||
2403 | * sure that the wake-up event is received within a | ||
2404 | * reasonable delay. otherwise, toggle the wake-up pin | ||
2405 | * again in an attempt to start the firmware properly. | ||
2406 | */ | ||
2407 | if (retry) { | ||
2408 | count = 10; | ||
2409 | while (count) { | ||
2410 | /* If the wake-up event has been received, | ||
2411 | * we can return. */ | ||
2412 | if (cy_as_device_is_firmware_loaded(dev_p)) | ||
2413 | break; | ||
2414 | /* If we are in polling mode, the interrupt may | ||
2415 | * not have been serviced as yet. read the | ||
2416 | * interrupt status register. if a pending mailbox | ||
2417 | * interrupt is seen, we can assume that the | ||
2418 | * wake-up event will be received soon. */ | ||
2419 | v = cy_as_hal_read_register(dev_p->tag, | ||
2420 | CY_AS_MEM_P0_INTR_REG); | ||
2421 | if (v & CY_AS_MEM_P0_INTR_REG_MBINT) | ||
2422 | break; | ||
2423 | |||
2424 | cy_as_hal_sleep(10); | ||
2425 | count--; | ||
2426 | } | ||
2427 | |||
2428 | if (!count) { | ||
2429 | retry = 0; | ||
2430 | dev_p->stby_int_mask = cy_as_hal_disable_interrupts(); | ||
2431 | cy_as_hal_set_wakeup_pin(dev_p->tag, cy_false); | ||
2432 | cy_as_hal_sleep(10); | ||
2433 | goto try_wakeup_again; | ||
2434 | } | ||
2435 | } | ||
2436 | |||
2437 | return ret; | ||
2438 | } | ||
2439 | EXPORT_SYMBOL(cy_as_misc_leave_standby); | ||
2440 | |||
2441 | cy_as_return_status_t | ||
2442 | cy_as_misc_register_callback( | ||
2443 | /* Handle to the West Bridge device */ | ||
2444 | cy_as_device_handle handle, | ||
2445 | /* The function to call */ | ||
2446 | cy_as_misc_event_callback callback | ||
2447 | ) | ||
2448 | { | ||
2449 | cy_as_device *dev_p; | ||
2450 | |||
2451 | cy_as_log_debug_message(6, "cy_as_misc_register_callback called"); | ||
2452 | |||
2453 | /* Make sure we have a valid device */ | ||
2454 | dev_p = (cy_as_device *)handle; | ||
2455 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2456 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2457 | |||
2458 | dev_p->misc_event_cb = callback; | ||
2459 | return CY_AS_ERROR_SUCCESS; | ||
2460 | } | ||
2461 | |||
2462 | cy_as_return_status_t | ||
2463 | cy_as_misc_storage_changed(cy_as_device_handle handle, | ||
2464 | cy_as_function_callback cb, | ||
2465 | uint32_t client) | ||
2466 | { | ||
2467 | cy_as_device *dev_p; | ||
2468 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2469 | cy_bool standby; | ||
2470 | cy_as_ll_request_response *req_p, *reply_p; | ||
2471 | |||
2472 | cy_as_log_debug_message(6, "cy_as_misc_storage_changed called"); | ||
2473 | |||
2474 | /* Make sure the device is ready for the command. */ | ||
2475 | dev_p = (cy_as_device *)handle; | ||
2476 | cy_as_check_device_ready(dev_p); | ||
2477 | |||
2478 | /* | ||
2479 | * make sure antioch is not in standby | ||
2480 | */ | ||
2481 | ret = cy_as_misc_in_standby(dev_p, &standby); | ||
2482 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2483 | return ret; | ||
2484 | |||
2485 | if (standby) | ||
2486 | return CY_AS_ERROR_IN_STANDBY; | ||
2487 | |||
2488 | /* | ||
2489 | * make sure westbridge is not in suspend mode. | ||
2490 | */ | ||
2491 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2492 | return CY_AS_ERROR_IN_SUSPEND; | ||
2493 | |||
2494 | /* Create the request to send to the West Bridge device */ | ||
2495 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_STORAGE_MEDIA_CHANGED, | ||
2496 | CY_RQT_GENERAL_RQT_CONTEXT, 0); | ||
2497 | if (req_p == 0) | ||
2498 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2499 | |||
2500 | /* Reserve space for the reply, the reply data will | ||
2501 | * not exceed one word */ | ||
2502 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2503 | if (reply_p == 0) { | ||
2504 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2505 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2506 | } | ||
2507 | |||
2508 | if (cb == 0) { | ||
2509 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2510 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2511 | goto destroy; | ||
2512 | |||
2513 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2514 | CY_RESP_SUCCESS_FAILURE) { | ||
2515 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2516 | goto destroy; | ||
2517 | } | ||
2518 | |||
2519 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2520 | } else { | ||
2521 | |||
2522 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2523 | CY_FUNCT_CB_MISC_STORAGECHANGED, 0, | ||
2524 | dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
2525 | req_p, reply_p, cy_as_misc_func_callback); | ||
2526 | |||
2527 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2528 | goto destroy; | ||
2529 | |||
2530 | /* The request and response are freed as part of the | ||
2531 | * MiscFuncCallback */ | ||
2532 | return ret; | ||
2533 | } | ||
2534 | |||
2535 | destroy: | ||
2536 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2537 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2538 | |||
2539 | return ret; | ||
2540 | } | ||
2541 | EXPORT_SYMBOL(cy_as_misc_storage_changed); | ||
2542 | |||
2543 | cy_as_return_status_t | ||
2544 | cy_as_misc_enter_suspend( | ||
2545 | cy_as_device_handle handle, | ||
2546 | cy_bool usb_wakeup_en, | ||
2547 | cy_bool gpio_wakeup_en, | ||
2548 | cy_as_function_callback cb, | ||
2549 | uint32_t client) | ||
2550 | { | ||
2551 | cy_as_device *dev_p; | ||
2552 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2553 | cy_bool standby; | ||
2554 | cy_as_ll_request_response *req_p, *reply_p; | ||
2555 | uint16_t value; | ||
2556 | uint32_t int_state; | ||
2557 | |||
2558 | cy_as_log_debug_message(6, "cy_as_misc_enter_suspend called"); | ||
2559 | |||
2560 | /* | ||
2561 | * basic sanity checks to ensure that the device is initialised. | ||
2562 | */ | ||
2563 | dev_p = (cy_as_device *)handle; | ||
2564 | cy_as_check_device_ready(dev_p); | ||
2565 | |||
2566 | /* | ||
2567 | * make sure west bridge is not already in standby | ||
2568 | */ | ||
2569 | cy_as_misc_in_standby(dev_p, &standby); | ||
2570 | if (standby) | ||
2571 | return CY_AS_ERROR_IN_STANDBY; | ||
2572 | |||
2573 | /* | ||
2574 | * make sure that the device is not already in suspend mode. | ||
2575 | */ | ||
2576 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2577 | return CY_AS_ERROR_IN_SUSPEND; | ||
2578 | |||
2579 | /* | ||
2580 | * make sure there is no active USB connection. | ||
2581 | */ | ||
2582 | if ((cy_as_device_is_usb_connected(dev_p)) && (dev_p->usb_last_event | ||
2583 | != cy_as_event_usb_suspend)) | ||
2584 | return CY_AS_ERROR_USB_CONNECTED; | ||
2585 | |||
2586 | /* | ||
2587 | * make sure that there are no async requests at this point in time. | ||
2588 | */ | ||
2589 | int_state = cy_as_hal_disable_interrupts(); | ||
2590 | if ((dev_p->func_cbs_misc->count) || (dev_p->func_cbs_res->count) || | ||
2591 | (dev_p->func_cbs_stor->count) || (dev_p->func_cbs_usb->count)) { | ||
2592 | cy_as_hal_enable_interrupts(int_state); | ||
2593 | return CY_AS_ERROR_ASYNC_PENDING; | ||
2594 | } | ||
2595 | cy_as_hal_enable_interrupts(int_state); | ||
2596 | |||
2597 | /* Create the request to send to the Antioch device */ | ||
2598 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_ENTER_SUSPEND_MODE, | ||
2599 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
2600 | if (req_p == 0) | ||
2601 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2602 | |||
2603 | /* Reserve space for the reply, the reply data will not | ||
2604 | * exceed one word */ | ||
2605 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2606 | if (reply_p == 0) { | ||
2607 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2608 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2609 | } | ||
2610 | |||
2611 | /* Wakeup control flags. */ | ||
2612 | value = 0x0001; | ||
2613 | if (usb_wakeup_en) | ||
2614 | value |= 0x04; | ||
2615 | if (gpio_wakeup_en) | ||
2616 | value |= 0x02; | ||
2617 | cy_as_ll_request_response__set_word(req_p, 0, value); | ||
2618 | |||
2619 | if (cb != 0) { | ||
2620 | |||
2621 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2622 | CY_FUNCT_CB_MISC_ENTERSUSPEND, | ||
2623 | 0, dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
2624 | req_p, reply_p, | ||
2625 | cy_as_misc_func_callback); | ||
2626 | |||
2627 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2628 | goto destroy; | ||
2629 | |||
2630 | return CY_AS_ERROR_SUCCESS; | ||
2631 | } else { | ||
2632 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2633 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2634 | CY_RESP_SUCCESS_FAILURE) | ||
2635 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2636 | else | ||
2637 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2638 | } | ||
2639 | |||
2640 | destroy: | ||
2641 | if (ret == CY_AS_ERROR_SUCCESS) | ||
2642 | cy_as_device_set_suspend_mode(dev_p); | ||
2643 | |||
2644 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2645 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2646 | |||
2647 | return ret; | ||
2648 | } | ||
2649 | EXPORT_SYMBOL(cy_as_misc_enter_suspend); | ||
2650 | |||
2651 | cy_as_return_status_t | ||
2652 | cy_as_misc_leave_suspend( | ||
2653 | cy_as_device_handle handle, | ||
2654 | cy_as_function_callback cb, | ||
2655 | uint32_t client) | ||
2656 | { | ||
2657 | cy_as_device *dev_p; | ||
2658 | uint16_t v, count; | ||
2659 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2660 | |||
2661 | cy_as_log_debug_message(6, "cy_as_misc_leave_suspend called"); | ||
2662 | |||
2663 | /* Make sure we have a valid device */ | ||
2664 | dev_p = (cy_as_device *)handle; | ||
2665 | cy_as_check_device_ready(dev_p); | ||
2666 | |||
2667 | /* Make sure we are in suspend mode. */ | ||
2668 | if (cy_as_device_is_in_suspend_mode(dev_p)) { | ||
2669 | if (cb) { | ||
2670 | cy_as_func_c_b_node *cbnode = | ||
2671 | cy_as_create_func_c_b_node_data(cb, client, | ||
2672 | CY_FUNCT_CB_MISC_LEAVESUSPEND, 0); | ||
2673 | if (cbnode == 0) | ||
2674 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2675 | |||
2676 | cy_as_insert_c_b_node(dev_p->func_cbs_misc, cbnode); | ||
2677 | } | ||
2678 | |||
2679 | /* | ||
2680 | * do a read from the ID register so that the CE assertion | ||
2681 | * will wake west bridge. the read is repeated until the | ||
2682 | * read comes back with valid data. | ||
2683 | */ | ||
2684 | count = 8; | ||
2685 | |||
2686 | v = cy_as_hal_read_register(dev_p->tag, | ||
2687 | CY_AS_MEM_CM_WB_CFG_ID); | ||
2688 | |||
2689 | while (!is_valid_silicon_id(v) && count-- > 0) { | ||
2690 | cy_as_hal_sleep(CY_AS_LEAVE_STANDBY_DELAY_CLOCK); | ||
2691 | v = cy_as_hal_read_register(dev_p->tag, | ||
2692 | CY_AS_MEM_CM_WB_CFG_ID); | ||
2693 | } | ||
2694 | |||
2695 | /* | ||
2696 | * if we tried to read the register and could not, | ||
2697 | * return a timeout | ||
2698 | */ | ||
2699 | if (count == 0) | ||
2700 | return CY_AS_ERROR_TIMEOUT; | ||
2701 | } else | ||
2702 | return CY_AS_ERROR_NOT_IN_SUSPEND; | ||
2703 | |||
2704 | if (cb == 0) { | ||
2705 | /* | ||
2706 | * wait until the in suspend mode flag is cleared. | ||
2707 | */ | ||
2708 | count = 20; | ||
2709 | while ((cy_as_device_is_in_suspend_mode(dev_p)) | ||
2710 | && (count--)) { | ||
2711 | cy_as_hal_sleep(CY_AS_LEAVE_STANDBY_DELAY_CLOCK); | ||
2712 | } | ||
2713 | |||
2714 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2715 | ret = CY_AS_ERROR_TIMEOUT; | ||
2716 | } | ||
2717 | |||
2718 | return ret; | ||
2719 | } | ||
2720 | EXPORT_SYMBOL(cy_as_misc_leave_suspend); | ||
2721 | |||
2722 | cy_as_return_status_t | ||
2723 | cy_as_misc_reserve_l_n_a_boot_area(cy_as_device_handle handle, | ||
2724 | uint8_t numzones, | ||
2725 | cy_as_function_callback cb, | ||
2726 | uint32_t client) | ||
2727 | { | ||
2728 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2729 | cy_bool standby; | ||
2730 | cy_as_ll_request_response *req_p, *reply_p; | ||
2731 | |||
2732 | cy_as_device *dev_p; | ||
2733 | |||
2734 | (void)client; | ||
2735 | |||
2736 | cy_as_log_debug_message(6, "cy_as_misc_switch_pnand_mode called"); | ||
2737 | |||
2738 | /* Make sure we have a valid device */ | ||
2739 | dev_p = (cy_as_device *)handle; | ||
2740 | cy_as_check_device_ready(dev_p); | ||
2741 | |||
2742 | /* | ||
2743 | * make sure antioch is not in standby | ||
2744 | */ | ||
2745 | ret = cy_as_misc_in_standby(dev_p, &standby); | ||
2746 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2747 | return ret; | ||
2748 | if (standby) | ||
2749 | return CY_AS_ERROR_IN_STANDBY; | ||
2750 | |||
2751 | /* Make sure the Antioch is not in suspend mode. */ | ||
2752 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2753 | return CY_AS_ERROR_IN_SUSPEND; | ||
2754 | |||
2755 | /* Create the request to send to the West Bridge device */ | ||
2756 | req_p = cy_as_ll_create_request(dev_p, | ||
2757 | CY_RQT_RESERVE_LNA_BOOT_AREA, | ||
2758 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
2759 | if (req_p == 0) | ||
2760 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2761 | cy_as_ll_request_response__set_word(req_p, | ||
2762 | 0, (uint16_t)numzones); | ||
2763 | |||
2764 | /* Reserve space for the reply, the reply data will not | ||
2765 | * exceed one word */ | ||
2766 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2767 | if (reply_p == 0) { | ||
2768 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2769 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2770 | } | ||
2771 | |||
2772 | if (cb == 0) { | ||
2773 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
2774 | req_p, reply_p); | ||
2775 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2776 | goto destroy; | ||
2777 | |||
2778 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2779 | CY_RESP_SUCCESS_FAILURE) { | ||
2780 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2781 | goto destroy; | ||
2782 | } | ||
2783 | |||
2784 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2785 | } else { | ||
2786 | |||
2787 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2788 | CY_FUNCT_CB_MISC_RESERVELNABOOTAREA, | ||
2789 | 0, dev_p->func_cbs_misc, CY_AS_REQUEST_RESPONSE_EX, | ||
2790 | req_p, reply_p, cy_as_misc_func_callback); | ||
2791 | |||
2792 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2793 | goto destroy; | ||
2794 | |||
2795 | /* The request and response are freed as part of the | ||
2796 | * MiscFuncCallback */ | ||
2797 | return ret; | ||
2798 | } | ||
2799 | |||
2800 | destroy: | ||
2801 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2802 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2803 | |||
2804 | return ret; | ||
2805 | } | ||
2806 | |||
2807 | cy_as_func_c_b_node* | ||
2808 | cy_as_create_func_c_b_node_data(cy_as_function_callback cb, | ||
2809 | uint32_t client, | ||
2810 | cy_as_funct_c_b_type type, | ||
2811 | void *data) | ||
2812 | { | ||
2813 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
2814 | cy_as_func_c_b_node *node = cy_as_hal_c_b_alloc( | ||
2815 | sizeof(cy_as_func_c_b_node)); | ||
2816 | cy_as_hal_enable_interrupts(state); | ||
2817 | if (node != 0) { | ||
2818 | node->node_type = CYAS_FUNC_CB; | ||
2819 | node->cb_p = cb; | ||
2820 | node->client_data = client; | ||
2821 | node->data_type = type; | ||
2822 | if (data != 0) | ||
2823 | node->data_type |= CY_FUNCT_CB_DATA; | ||
2824 | else | ||
2825 | node->data_type |= CY_FUNCT_CB_NODATA; | ||
2826 | node->data = data; | ||
2827 | node->next_p = 0; | ||
2828 | } | ||
2829 | return node; | ||
2830 | } | ||
2831 | |||
2832 | cy_as_func_c_b_node* | ||
2833 | cy_as_create_func_c_b_node(cy_as_function_callback cb, | ||
2834 | uint32_t client) | ||
2835 | { | ||
2836 | return cy_as_create_func_c_b_node_data(cb, client, | ||
2837 | CY_FUNCT_CB_NODATA, 0); | ||
2838 | } | ||
2839 | |||
2840 | void | ||
2841 | cy_as_destroy_func_c_b_node(cy_as_func_c_b_node *node) | ||
2842 | { | ||
2843 | uint32_t state; | ||
2844 | |||
2845 | node->node_type = CYAS_INVALID; | ||
2846 | state = cy_as_hal_disable_interrupts(); | ||
2847 | cy_as_hal_c_b_free(node); | ||
2848 | cy_as_hal_enable_interrupts(state); | ||
2849 | } | ||
2850 | |||
2851 | cy_as_usb_func_c_b_node* | ||
2852 | cy_as_create_usb_func_c_b_node( | ||
2853 | cy_as_usb_function_callback cb, uint32_t client) | ||
2854 | { | ||
2855 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
2856 | cy_as_usb_func_c_b_node *node = cy_as_hal_c_b_alloc( | ||
2857 | sizeof(cy_as_usb_func_c_b_node)); | ||
2858 | cy_as_hal_enable_interrupts(state); | ||
2859 | if (node != 0) { | ||
2860 | node->type = CYAS_USB_FUNC_CB; | ||
2861 | node->cb_p = cb; | ||
2862 | node->client_data = client; | ||
2863 | node->next_p = 0; | ||
2864 | } | ||
2865 | return node; | ||
2866 | } | ||
2867 | |||
2868 | void | ||
2869 | cy_as_destroy_usb_func_c_b_node(cy_as_usb_func_c_b_node *node) | ||
2870 | { | ||
2871 | uint32_t state; | ||
2872 | |||
2873 | node->type = CYAS_INVALID; | ||
2874 | state = cy_as_hal_disable_interrupts(); | ||
2875 | cy_as_hal_c_b_free(node); | ||
2876 | cy_as_hal_enable_interrupts(state); | ||
2877 | } | ||
2878 | |||
2879 | cy_as_usb_io_c_b_node* | ||
2880 | cy_as_create_usb_io_c_b_node(cy_as_usb_io_callback cb) | ||
2881 | { | ||
2882 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
2883 | cy_as_usb_io_c_b_node *node = cy_as_hal_c_b_alloc( | ||
2884 | sizeof(cy_as_usb_io_c_b_node)); | ||
2885 | cy_as_hal_enable_interrupts(state); | ||
2886 | if (node != 0) { | ||
2887 | node->type = CYAS_USB_IO_CB; | ||
2888 | node->cb_p = cb; | ||
2889 | node->next_p = 0; | ||
2890 | } | ||
2891 | return node; | ||
2892 | } | ||
2893 | |||
2894 | void | ||
2895 | cy_as_destroy_usb_io_c_b_node(cy_as_usb_io_c_b_node *node) | ||
2896 | { | ||
2897 | uint32_t state; | ||
2898 | |||
2899 | node->type = CYAS_INVALID; | ||
2900 | |||
2901 | state = cy_as_hal_disable_interrupts(); | ||
2902 | cy_as_hal_c_b_free(node); | ||
2903 | cy_as_hal_enable_interrupts(state); | ||
2904 | } | ||
2905 | |||
2906 | cy_as_storage_io_c_b_node* | ||
2907 | cy_as_create_storage_io_c_b_node(cy_as_storage_callback cb, | ||
2908 | cy_as_media_type media, uint32_t device_index, | ||
2909 | uint32_t unit, uint32_t block_addr, cy_as_oper_type oper, | ||
2910 | cy_as_ll_request_response *req_p, | ||
2911 | cy_as_ll_request_response *reply_p) | ||
2912 | { | ||
2913 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
2914 | cy_as_storage_io_c_b_node *node = cy_as_hal_c_b_alloc( | ||
2915 | sizeof(cy_as_storage_io_c_b_node)); | ||
2916 | cy_as_hal_enable_interrupts(state); | ||
2917 | if (node != 0) { | ||
2918 | node->type = CYAS_STORAGE_IO_CB; | ||
2919 | node->cb_p = cb; | ||
2920 | node->media = media; | ||
2921 | node->device_index = device_index; | ||
2922 | node->unit = unit; | ||
2923 | node->block_addr = block_addr; | ||
2924 | node->oper = oper; | ||
2925 | node->req_p = req_p; | ||
2926 | node->reply_p = reply_p; | ||
2927 | node->next_p = 0; | ||
2928 | } | ||
2929 | return node; | ||
2930 | } | ||
2931 | |||
2932 | void | ||
2933 | cy_as_destroy_storage_io_c_b_node(cy_as_storage_io_c_b_node *node) | ||
2934 | { | ||
2935 | uint32_t state; | ||
2936 | node->type = CYAS_INVALID; | ||
2937 | state = cy_as_hal_disable_interrupts(); | ||
2938 | cy_as_hal_c_b_free(node); | ||
2939 | cy_as_hal_enable_interrupts(state); | ||
2940 | } | ||
2941 | |||
2942 | cy_as_c_b_queue * | ||
2943 | cy_as_create_c_b_queue(cy_as_c_b_node_type type) | ||
2944 | { | ||
2945 | uint32_t state = cy_as_hal_disable_interrupts(); | ||
2946 | cy_as_c_b_queue *queue = cy_as_hal_c_b_alloc( | ||
2947 | sizeof(cy_as_c_b_queue)); | ||
2948 | cy_as_hal_enable_interrupts(state); | ||
2949 | if (queue) { | ||
2950 | queue->type = type; | ||
2951 | queue->head_p = 0; | ||
2952 | queue->tail_p = 0; | ||
2953 | queue->count = 0; | ||
2954 | } | ||
2955 | |||
2956 | return queue; | ||
2957 | } | ||
2958 | |||
2959 | void | ||
2960 | cy_as_destroy_c_b_queue(cy_as_c_b_queue *queue) | ||
2961 | { | ||
2962 | uint32_t state; | ||
2963 | queue->type = CYAS_INVALID; | ||
2964 | queue->head_p = 0; | ||
2965 | queue->tail_p = 0; | ||
2966 | queue->count = 0; | ||
2967 | state = cy_as_hal_disable_interrupts(); | ||
2968 | cy_as_hal_c_b_free(queue); | ||
2969 | cy_as_hal_enable_interrupts(state); | ||
2970 | } | ||
2971 | |||
2972 | /* Inserts a CyAsCBNode into the queue, the | ||
2973 | * node type must match the queue type*/ | ||
2974 | void | ||
2975 | cy_as_insert_c_b_node(cy_as_c_b_queue *queue_p, void*cbnode) | ||
2976 | { | ||
2977 | uint32_t int_state; | ||
2978 | |||
2979 | int_state = cy_as_hal_disable_interrupts(); | ||
2980 | |||
2981 | cy_as_hal_assert(queue_p != 0); | ||
2982 | |||
2983 | switch (queue_p->type) { | ||
2984 | case CYAS_USB_FUNC_CB: | ||
2985 | { | ||
2986 | cy_as_usb_func_c_b_node *node = | ||
2987 | (cy_as_usb_func_c_b_node *)cbnode; | ||
2988 | cy_as_usb_func_c_b_node *tail = | ||
2989 | (cy_as_usb_func_c_b_node *)queue_p->tail_p; | ||
2990 | |||
2991 | cy_as_hal_assert(node->type == CYAS_USB_FUNC_CB); | ||
2992 | cy_as_hal_assert(tail == 0 || | ||
2993 | tail->type == CYAS_USB_FUNC_CB); | ||
2994 | if (queue_p->head_p == 0) | ||
2995 | queue_p->head_p = node; | ||
2996 | else | ||
2997 | tail->next_p = node; | ||
2998 | |||
2999 | queue_p->tail_p = node; | ||
3000 | } | ||
3001 | break; | ||
3002 | |||
3003 | case CYAS_USB_IO_CB: | ||
3004 | { | ||
3005 | cy_as_usb_io_c_b_node *node = | ||
3006 | (cy_as_usb_io_c_b_node *)cbnode; | ||
3007 | cy_as_usb_io_c_b_node *tail = | ||
3008 | (cy_as_usb_io_c_b_node *)queue_p->tail_p; | ||
3009 | |||
3010 | cy_as_hal_assert(node->type == CYAS_USB_IO_CB); | ||
3011 | cy_as_hal_assert(tail == 0 || | ||
3012 | tail->type == CYAS_USB_IO_CB); | ||
3013 | if (queue_p->head_p == 0) | ||
3014 | queue_p->head_p = node; | ||
3015 | else | ||
3016 | tail->next_p = node; | ||
3017 | |||
3018 | queue_p->tail_p = node; | ||
3019 | } | ||
3020 | break; | ||
3021 | |||
3022 | case CYAS_STORAGE_IO_CB: | ||
3023 | { | ||
3024 | cy_as_storage_io_c_b_node *node = | ||
3025 | (cy_as_storage_io_c_b_node *)cbnode; | ||
3026 | cy_as_storage_io_c_b_node *tail = | ||
3027 | (cy_as_storage_io_c_b_node *)queue_p->tail_p; | ||
3028 | |||
3029 | cy_as_hal_assert(node->type == CYAS_STORAGE_IO_CB); | ||
3030 | cy_as_hal_assert(tail == 0 || | ||
3031 | tail->type == CYAS_STORAGE_IO_CB); | ||
3032 | if (queue_p->head_p == 0) | ||
3033 | queue_p->head_p = node; | ||
3034 | else | ||
3035 | tail->next_p = node; | ||
3036 | |||
3037 | queue_p->tail_p = node; | ||
3038 | } | ||
3039 | break; | ||
3040 | |||
3041 | case CYAS_FUNC_CB: | ||
3042 | { | ||
3043 | cy_as_func_c_b_node *node = | ||
3044 | (cy_as_func_c_b_node *)cbnode; | ||
3045 | cy_as_func_c_b_node *tail = | ||
3046 | (cy_as_func_c_b_node *)queue_p->tail_p; | ||
3047 | |||
3048 | cy_as_hal_assert(node->node_type == CYAS_FUNC_CB); | ||
3049 | cy_as_hal_assert(tail == 0 || | ||
3050 | tail->node_type == CYAS_FUNC_CB); | ||
3051 | if (queue_p->head_p == 0) | ||
3052 | queue_p->head_p = node; | ||
3053 | else | ||
3054 | tail->next_p = node; | ||
3055 | |||
3056 | queue_p->tail_p = node; | ||
3057 | } | ||
3058 | break; | ||
3059 | |||
3060 | default: | ||
3061 | cy_as_hal_assert(cy_false); | ||
3062 | break; | ||
3063 | } | ||
3064 | |||
3065 | queue_p->count++; | ||
3066 | |||
3067 | cy_as_hal_enable_interrupts(int_state); | ||
3068 | } | ||
3069 | |||
3070 | /* Removes the tail node from the queue and frees it */ | ||
3071 | void | ||
3072 | cy_as_remove_c_b_tail_node(cy_as_c_b_queue *queue_p) | ||
3073 | { | ||
3074 | uint32_t int_state; | ||
3075 | |||
3076 | int_state = cy_as_hal_disable_interrupts(); | ||
3077 | |||
3078 | if (queue_p->count > 0) { | ||
3079 | /* | ||
3080 | * the worst case length of the queue should be | ||
3081 | * under 10 elements, and the average case should | ||
3082 | * be just 1 element. so, we just employ a linear | ||
3083 | * search to find the node to be freed. | ||
3084 | */ | ||
3085 | switch (queue_p->type) { | ||
3086 | case CYAS_FUNC_CB: | ||
3087 | { | ||
3088 | cy_as_func_c_b_node *node = | ||
3089 | (cy_as_func_c_b_node *) | ||
3090 | queue_p->head_p; | ||
3091 | cy_as_func_c_b_node *tail = | ||
3092 | (cy_as_func_c_b_node *) | ||
3093 | queue_p->tail_p; | ||
3094 | if (node != tail) { | ||
3095 | while (node->next_p != tail) | ||
3096 | node = node->next_p; | ||
3097 | node->next_p = 0; | ||
3098 | queue_p->tail_p = node; | ||
3099 | } | ||
3100 | cy_as_destroy_func_c_b_node(tail); | ||
3101 | } | ||
3102 | break; | ||
3103 | |||
3104 | case CYAS_USB_FUNC_CB: | ||
3105 | { | ||
3106 | cy_as_usb_func_c_b_node *node = | ||
3107 | (cy_as_usb_func_c_b_node *) | ||
3108 | queue_p->head_p; | ||
3109 | cy_as_usb_func_c_b_node *tail = | ||
3110 | (cy_as_usb_func_c_b_node *) | ||
3111 | queue_p->tail_p; | ||
3112 | if (node != tail) { | ||
3113 | while (node->next_p != tail) | ||
3114 | node = node->next_p; | ||
3115 | node->next_p = 0; | ||
3116 | queue_p->tail_p = node; | ||
3117 | } | ||
3118 | |||
3119 | cy_as_destroy_usb_func_c_b_node(tail); | ||
3120 | } | ||
3121 | break; | ||
3122 | |||
3123 | case CYAS_USB_IO_CB: | ||
3124 | { | ||
3125 | cy_as_usb_io_c_b_node *node = | ||
3126 | (cy_as_usb_io_c_b_node *) | ||
3127 | queue_p->head_p; | ||
3128 | cy_as_usb_io_c_b_node *tail = | ||
3129 | (cy_as_usb_io_c_b_node *) | ||
3130 | queue_p->tail_p; | ||
3131 | if (node != tail) { | ||
3132 | while (node->next_p != tail) | ||
3133 | node = node->next_p; | ||
3134 | node->next_p = 0; | ||
3135 | queue_p->tail_p = node; | ||
3136 | } | ||
3137 | cy_as_destroy_usb_io_c_b_node(tail); | ||
3138 | } | ||
3139 | break; | ||
3140 | |||
3141 | case CYAS_STORAGE_IO_CB: | ||
3142 | { | ||
3143 | cy_as_storage_io_c_b_node *node = | ||
3144 | (cy_as_storage_io_c_b_node *) | ||
3145 | queue_p->head_p; | ||
3146 | cy_as_storage_io_c_b_node *tail = | ||
3147 | (cy_as_storage_io_c_b_node *) | ||
3148 | queue_p->tail_p; | ||
3149 | if (node != tail) { | ||
3150 | while (node->next_p != tail) | ||
3151 | node = node->next_p; | ||
3152 | node->next_p = 0; | ||
3153 | queue_p->tail_p = node; | ||
3154 | } | ||
3155 | cy_as_destroy_storage_io_c_b_node(tail); | ||
3156 | } | ||
3157 | break; | ||
3158 | |||
3159 | default: | ||
3160 | cy_as_hal_assert(cy_false); | ||
3161 | } | ||
3162 | |||
3163 | queue_p->count--; | ||
3164 | if (queue_p->count == 0) { | ||
3165 | queue_p->head_p = 0; | ||
3166 | queue_p->tail_p = 0; | ||
3167 | } | ||
3168 | } | ||
3169 | |||
3170 | cy_as_hal_enable_interrupts(int_state); | ||
3171 | } | ||
3172 | |||
3173 | /* Removes the first CyAsCBNode from the queue and frees it */ | ||
3174 | void | ||
3175 | cy_as_remove_c_b_node(cy_as_c_b_queue *queue_p) | ||
3176 | { | ||
3177 | uint32_t int_state; | ||
3178 | |||
3179 | int_state = cy_as_hal_disable_interrupts(); | ||
3180 | |||
3181 | cy_as_hal_assert(queue_p->count >= 0); | ||
3182 | if (queue_p->count > 0) { | ||
3183 | if (queue_p->type == CYAS_USB_FUNC_CB) { | ||
3184 | cy_as_usb_func_c_b_node *node = | ||
3185 | (cy_as_usb_func_c_b_node *) | ||
3186 | queue_p->head_p; | ||
3187 | queue_p->head_p = node->next_p; | ||
3188 | cy_as_destroy_usb_func_c_b_node(node); | ||
3189 | } else if (queue_p->type == CYAS_USB_IO_CB) { | ||
3190 | cy_as_usb_io_c_b_node *node = | ||
3191 | (cy_as_usb_io_c_b_node *) | ||
3192 | queue_p->head_p; | ||
3193 | queue_p->head_p = node->next_p; | ||
3194 | cy_as_destroy_usb_io_c_b_node(node); | ||
3195 | } else if (queue_p->type == CYAS_STORAGE_IO_CB) { | ||
3196 | cy_as_storage_io_c_b_node *node = | ||
3197 | (cy_as_storage_io_c_b_node *) | ||
3198 | queue_p->head_p; | ||
3199 | queue_p->head_p = node->next_p; | ||
3200 | cy_as_destroy_storage_io_c_b_node(node); | ||
3201 | } else if (queue_p->type == CYAS_FUNC_CB) { | ||
3202 | cy_as_func_c_b_node *node = | ||
3203 | (cy_as_func_c_b_node *) | ||
3204 | queue_p->head_p; | ||
3205 | queue_p->head_p = node->next_p; | ||
3206 | cy_as_destroy_func_c_b_node(node); | ||
3207 | } else { | ||
3208 | cy_as_hal_assert(cy_false); | ||
3209 | } | ||
3210 | |||
3211 | queue_p->count--; | ||
3212 | if (queue_p->count == 0) { | ||
3213 | queue_p->head_p = 0; | ||
3214 | queue_p->tail_p = 0; | ||
3215 | } | ||
3216 | } | ||
3217 | |||
3218 | cy_as_hal_enable_interrupts(int_state); | ||
3219 | } | ||
3220 | |||
3221 | void my_print_func_c_b_node(cy_as_func_c_b_node *node) | ||
3222 | { | ||
3223 | cy_as_funct_c_b_type type = | ||
3224 | cy_as_funct_c_b_type_get_type(node->data_type); | ||
3225 | cy_as_hal_print_message("[cd:%2u dt:%2u cb:0x%08x " | ||
3226 | "d:0x%08x nt:%1i]", node->client_data, type, | ||
3227 | (uint32_t)node->cb_p, (uint32_t)node->data, | ||
3228 | node->node_type); | ||
3229 | } | ||
3230 | |||
3231 | void my_print_c_b_queue(cy_as_c_b_queue *queue_p) | ||
3232 | { | ||
3233 | uint32_t i = 0; | ||
3234 | |||
3235 | cy_as_hal_print_message("| count: %u type: ", queue_p->count); | ||
3236 | |||
3237 | if (queue_p->type == CYAS_USB_FUNC_CB) { | ||
3238 | cy_as_hal_print_message("USB_FUNC_CB\n"); | ||
3239 | } else if (queue_p->type == CYAS_USB_IO_CB) { | ||
3240 | cy_as_hal_print_message("USB_IO_CB\n"); | ||
3241 | } else if (queue_p->type == CYAS_STORAGE_IO_CB) { | ||
3242 | cy_as_hal_print_message("STORAGE_IO_CB\n"); | ||
3243 | } else if (queue_p->type == CYAS_FUNC_CB) { | ||
3244 | cy_as_func_c_b_node *node = queue_p->head_p; | ||
3245 | cy_as_hal_print_message("FUNC_CB\n"); | ||
3246 | if (queue_p->count > 0) { | ||
3247 | cy_as_hal_print_message("| head->"); | ||
3248 | |||
3249 | for (i = 0; i < queue_p->count; i++) { | ||
3250 | if (node) { | ||
3251 | cy_as_hal_print_message("->"); | ||
3252 | my_print_func_c_b_node(node); | ||
3253 | node = node->next_p; | ||
3254 | } else | ||
3255 | cy_as_hal_print_message("->[NULL]\n"); | ||
3256 | } | ||
3257 | |||
3258 | cy_as_hal_print_message("\n| tail->"); | ||
3259 | my_print_func_c_b_node(queue_p->tail_p); | ||
3260 | cy_as_hal_print_message("\n"); | ||
3261 | } | ||
3262 | } else { | ||
3263 | cy_as_hal_print_message("INVALID\n"); | ||
3264 | } | ||
3265 | |||
3266 | cy_as_hal_print_message("|----------\n"); | ||
3267 | } | ||
3268 | |||
3269 | |||
3270 | /* Removes and frees all pending callbacks */ | ||
3271 | void | ||
3272 | cy_as_clear_c_b_queue(cy_as_c_b_queue *queue_p) | ||
3273 | { | ||
3274 | uint32_t int_state = cy_as_hal_disable_interrupts(); | ||
3275 | |||
3276 | while (queue_p->count != 0) | ||
3277 | cy_as_remove_c_b_node(queue_p); | ||
3278 | |||
3279 | cy_as_hal_enable_interrupts(int_state); | ||
3280 | } | ||
3281 | |||
3282 | cy_as_return_status_t | ||
3283 | cy_as_misc_send_request(cy_as_device *dev_p, | ||
3284 | cy_as_function_callback cb, | ||
3285 | uint32_t client, | ||
3286 | cy_as_funct_c_b_type type, | ||
3287 | void *data, | ||
3288 | cy_as_c_b_queue *queue, | ||
3289 | uint16_t req_type, | ||
3290 | cy_as_ll_request_response *req_p, | ||
3291 | cy_as_ll_request_response *reply_p, | ||
3292 | cy_as_response_callback rcb) | ||
3293 | { | ||
3294 | |||
3295 | cy_as_func_c_b_node *cbnode = cy_as_create_func_c_b_node_data(cb, | ||
3296 | client, type, data); | ||
3297 | cy_as_return_status_t ret; | ||
3298 | |||
3299 | if (cbnode == 0) | ||
3300 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3301 | else | ||
3302 | cy_as_insert_c_b_node(queue, cbnode); | ||
3303 | |||
3304 | req_p->flags |= req_type; | ||
3305 | |||
3306 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, cy_false, rcb); | ||
3307 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3308 | cy_as_remove_c_b_tail_node(queue); | ||
3309 | |||
3310 | return ret; | ||
3311 | } | ||
3312 | |||
3313 | void | ||
3314 | cy_as_misc_cancel_ex_requests(cy_as_device *dev_p) | ||
3315 | { | ||
3316 | int i; | ||
3317 | for (i = 0; i < CY_RQT_CONTEXT_COUNT; i++) | ||
3318 | cy_as_ll_remove_all_requests(dev_p, dev_p->context[i]); | ||
3319 | } | ||
3320 | |||
3321 | |||
3322 | static void | ||
3323 | cy_as_misc_func_callback(cy_as_device *dev_p, | ||
3324 | uint8_t context, | ||
3325 | cy_as_ll_request_response *rqt, | ||
3326 | cy_as_ll_request_response *resp, | ||
3327 | cy_as_return_status_t stat) | ||
3328 | { | ||
3329 | cy_as_func_c_b_node *node = NULL; | ||
3330 | cy_as_return_status_t ret; | ||
3331 | |||
3332 | cy_bool ex_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_EX) | ||
3333 | == CY_AS_REQUEST_RESPONSE_EX; | ||
3334 | cy_bool ms_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_MS) | ||
3335 | == CY_AS_REQUEST_RESPONSE_MS; | ||
3336 | uint8_t code; | ||
3337 | uint32_t type; | ||
3338 | uint8_t cntxt; | ||
3339 | |||
3340 | cy_as_hal_assert(ex_request || ms_request); | ||
3341 | (void) ex_request; | ||
3342 | (void) ms_request; | ||
3343 | (void)context; | ||
3344 | |||
3345 | cntxt = cy_as_ll_request_response__get_context(rqt); | ||
3346 | code = cy_as_ll_request_response__get_code(rqt); | ||
3347 | |||
3348 | switch (cntxt) { | ||
3349 | case CY_RQT_GENERAL_RQT_CONTEXT: | ||
3350 | cy_as_hal_assert(dev_p->func_cbs_misc->count != 0); | ||
3351 | cy_as_hal_assert(dev_p->func_cbs_misc->type == CYAS_FUNC_CB); | ||
3352 | node = (cy_as_func_c_b_node *)dev_p->func_cbs_misc->head_p; | ||
3353 | type = cy_as_funct_c_b_type_get_type(node->data_type); | ||
3354 | |||
3355 | switch (code) { | ||
3356 | case CY_RQT_GET_FIRMWARE_VERSION: | ||
3357 | cy_as_hal_assert(node->data != 0); | ||
3358 | cy_as_hal_assert(type == | ||
3359 | CY_FUNCT_CB_MISC_GETFIRMWAREVERSION); | ||
3360 | ret = my_handle_response_get_firmware_version(dev_p, | ||
3361 | rqt, resp, | ||
3362 | (cy_as_get_firmware_version_data *)node->data); | ||
3363 | break; | ||
3364 | case CY_RQT_READ_MCU_REGISTER: | ||
3365 | cy_as_hal_assert(node->data != 0); | ||
3366 | cy_as_hal_assert(type == | ||
3367 | CY_FUNCT_CB_MISC_READMCUREGISTER); | ||
3368 | ret = my_handle_response_read_m_c_u_register(dev_p, rqt, | ||
3369 | resp, (uint8_t *)node->data); | ||
3370 | break; | ||
3371 | case CY_RQT_GET_GPIO_STATE: | ||
3372 | cy_as_hal_assert(node->data != 0); | ||
3373 | cy_as_hal_assert(type == | ||
3374 | CY_FUNCT_CB_MISC_GETGPIOVALUE); | ||
3375 | ret = my_handle_response_get_gpio_value(dev_p, rqt, | ||
3376 | resp, (uint8_t *)node->data); | ||
3377 | break; | ||
3378 | case CY_RQT_SET_SD_CLOCK_FREQ: | ||
3379 | cy_as_hal_assert(type == CY_FUNCT_CB_MISC_SETSDFREQ); | ||
3380 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3381 | break; | ||
3382 | case CY_RQT_CONTROL_ANTIOCH_HEARTBEAT: | ||
3383 | cy_as_hal_assert(type == | ||
3384 | CY_FUNCT_CB_MISC_HEARTBEATCONTROL); | ||
3385 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3386 | break; | ||
3387 | case CY_RQT_WRITE_MCU_REGISTER: | ||
3388 | cy_as_hal_assert(type == | ||
3389 | CY_FUNCT_CB_MISC_WRITEMCUREGISTER); | ||
3390 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3391 | break; | ||
3392 | case CY_RQT_STORAGE_MEDIA_CHANGED: | ||
3393 | cy_as_hal_assert(type == | ||
3394 | CY_FUNCT_CB_MISC_STORAGECHANGED); | ||
3395 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3396 | break; | ||
3397 | case CY_RQT_SET_GPIO_STATE: | ||
3398 | cy_as_hal_assert(type == | ||
3399 | CY_FUNCT_CB_MISC_SETGPIOVALUE); | ||
3400 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3401 | break; | ||
3402 | case CY_RQT_SET_TRACE_LEVEL: | ||
3403 | cy_as_hal_assert(type == | ||
3404 | CY_FUNCT_CB_MISC_SETTRACELEVEL); | ||
3405 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3406 | if (ret == CY_AS_ERROR_INVALID_RESPONSE) | ||
3407 | ret = CY_AS_ERROR_NOT_SUPPORTED; | ||
3408 | break; | ||
3409 | case CY_RQT_PREPARE_FOR_STANDBY: | ||
3410 | cy_as_hal_assert(type == | ||
3411 | CY_FUNCT_CB_MISC_ENTERSTANDBY); | ||
3412 | ret = my_handle_response_enter_standby(dev_p, rqt, resp, | ||
3413 | (cy_bool)node->data); | ||
3414 | break; | ||
3415 | case CY_RQT_ENTER_SUSPEND_MODE: | ||
3416 | cy_as_hal_assert(type == | ||
3417 | CY_FUNCT_CB_MISC_ENTERSUSPEND); | ||
3418 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3419 | if (ret == CY_AS_ERROR_SUCCESS) | ||
3420 | cy_as_device_set_suspend_mode(dev_p); | ||
3421 | |||
3422 | break; | ||
3423 | case CY_RQT_RESERVE_LNA_BOOT_AREA: | ||
3424 | cy_as_hal_assert(type == | ||
3425 | CY_FUNCT_CB_MISC_RESERVELNABOOTAREA); | ||
3426 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3427 | break; | ||
3428 | case CY_RQT_SDPOLARITY: | ||
3429 | cy_as_hal_assert(type == | ||
3430 | CY_FUNCT_CB_MISC_SETSDPOLARITY); | ||
3431 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3432 | break; | ||
3433 | default: | ||
3434 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3435 | cy_as_hal_assert(cy_false); | ||
3436 | break; | ||
3437 | } | ||
3438 | break; | ||
3439 | |||
3440 | case CY_RQT_RESOURCE_RQT_CONTEXT: | ||
3441 | cy_as_hal_assert(dev_p->func_cbs_res->count != 0); | ||
3442 | cy_as_hal_assert(dev_p->func_cbs_res->type == CYAS_FUNC_CB); | ||
3443 | node = (cy_as_func_c_b_node *)dev_p->func_cbs_res->head_p; | ||
3444 | type = cy_as_funct_c_b_type_get_type(node->data_type); | ||
3445 | |||
3446 | switch (code) { | ||
3447 | case CY_RQT_ACQUIRE_RESOURCE: | ||
3448 | /* The node->data field is actually an enum value | ||
3449 | * which could be 0, thus no assert is done */ | ||
3450 | cy_as_hal_assert(type == | ||
3451 | CY_FUNCT_CB_MISC_ACQUIRERESOURCE); | ||
3452 | ret = my_handle_response_acquire_resource(dev_p, rqt, | ||
3453 | resp, (cy_as_resource_type *)node->data); | ||
3454 | break; | ||
3455 | default: | ||
3456 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3457 | cy_as_hal_assert(cy_false); | ||
3458 | break; | ||
3459 | } | ||
3460 | break; | ||
3461 | |||
3462 | default: | ||
3463 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3464 | cy_as_hal_assert(cy_false); | ||
3465 | break; | ||
3466 | } | ||
3467 | |||
3468 | /* | ||
3469 | * if the low level layer returns a direct error, use the | ||
3470 | * corresponding error code. if not, use the error code | ||
3471 | * based on the response from firmware. | ||
3472 | */ | ||
3473 | if (stat == CY_AS_ERROR_SUCCESS) | ||
3474 | stat = ret; | ||
3475 | |||
3476 | /* Call the user Callback */ | ||
3477 | node->cb_p((cy_as_device_handle)dev_p, stat, node->client_data, | ||
3478 | node->data_type, node->data); | ||
3479 | if (cntxt == CY_RQT_GENERAL_RQT_CONTEXT) | ||
3480 | cy_as_remove_c_b_node(dev_p->func_cbs_misc); | ||
3481 | else | ||
3482 | cy_as_remove_c_b_node(dev_p->func_cbs_res); | ||
3483 | |||
3484 | } | ||
3485 | |||
3486 | |||
3487 | |||
3488 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasmtp.c b/drivers/staging/westbridge/astoria/api/src/cyasmtp.c deleted file mode 100644 index 8598364f7ab7..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasmtp.c +++ /dev/null | |||
@@ -1,1136 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasmtp.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasmtp.h" | ||
24 | #include "../../include/linux/westbridge/cyaserr.h" | ||
25 | #include "../../include/linux/westbridge/cyasdma.h" | ||
26 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
27 | |||
28 | static void | ||
29 | cy_as_mtp_func_callback(cy_as_device *dev_p, | ||
30 | uint8_t context, | ||
31 | cy_as_ll_request_response *rqt, | ||
32 | cy_as_ll_request_response *resp, | ||
33 | cy_as_return_status_t stat); | ||
34 | |||
35 | static cy_as_return_status_t | ||
36 | is_mtp_active(cy_as_device *dev_p) | ||
37 | { | ||
38 | if (!cy_as_device_is_configured(dev_p)) | ||
39 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
40 | |||
41 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
42 | return CY_AS_ERROR_NO_FIRMWARE; | ||
43 | |||
44 | if (dev_p->mtp_count == 0) | ||
45 | return CY_AS_ERROR_NOT_RUNNING; | ||
46 | |||
47 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
48 | return CY_AS_ERROR_IN_SUSPEND; | ||
49 | |||
50 | return CY_AS_ERROR_SUCCESS; | ||
51 | } | ||
52 | |||
53 | static void | ||
54 | my_mtp_request_callback(cy_as_device *dev_p, | ||
55 | uint8_t context, | ||
56 | cy_as_ll_request_response *req_p, | ||
57 | cy_as_ll_request_response *resp_p, | ||
58 | cy_as_return_status_t ret) | ||
59 | { | ||
60 | uint16_t val, ev, status; | ||
61 | uint16_t mtp_datalen = 0; | ||
62 | uint32_t bytecount_l, bytecount_h; | ||
63 | cy_as_mtp_send_object_complete_data send_obj_data; | ||
64 | cy_as_mtp_get_object_complete_data get_obj_data; | ||
65 | cy_as_dma_end_point *ep_p; | ||
66 | |||
67 | uint8_t code = cy_as_ll_request_response__get_code(req_p); | ||
68 | |||
69 | (void)resp_p; | ||
70 | (void)context; | ||
71 | (void)ret; | ||
72 | |||
73 | switch (code) { | ||
74 | case CY_RQT_MTP_EVENT: | ||
75 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
76 | /* MSB indicates status of read/write */ | ||
77 | status = (val >> 8) & 0xFF; | ||
78 | /* event type */ | ||
79 | ev = val & 0xFF; | ||
80 | switch (ev) { | ||
81 | case 0: /* SendObject Complete */ | ||
82 | { | ||
83 | bytecount_l = | ||
84 | cy_as_ll_request_response__get_word | ||
85 | (req_p, 1); | ||
86 | bytecount_h = | ||
87 | cy_as_ll_request_response__get_word | ||
88 | (req_p, 2); | ||
89 | send_obj_data.byte_count = | ||
90 | (bytecount_h << 16) | bytecount_l; | ||
91 | |||
92 | send_obj_data.status = status; | ||
93 | |||
94 | /* use the byte count again */ | ||
95 | bytecount_l = | ||
96 | cy_as_ll_request_response__get_word | ||
97 | (req_p, 3); | ||
98 | bytecount_h = | ||
99 | cy_as_ll_request_response__get_word | ||
100 | (req_p, 4); | ||
101 | send_obj_data.transaction_id = | ||
102 | (bytecount_h << 16) | bytecount_l; | ||
103 | |||
104 | dev_p->mtp_turbo_active = cy_false; | ||
105 | |||
106 | if (dev_p->mtp_event_cb) | ||
107 | dev_p->mtp_event_cb( | ||
108 | (cy_as_device_handle) dev_p, | ||
109 | cy_as_mtp_send_object_complete, | ||
110 | &send_obj_data); | ||
111 | } | ||
112 | break; | ||
113 | |||
114 | case 1: /* GetObject Complete */ | ||
115 | { | ||
116 | bytecount_l = | ||
117 | cy_as_ll_request_response__get_word | ||
118 | (req_p, 1); | ||
119 | bytecount_h = | ||
120 | cy_as_ll_request_response__get_word | ||
121 | (req_p, 2); | ||
122 | |||
123 | get_obj_data.byte_count = | ||
124 | (bytecount_h << 16) | bytecount_l; | ||
125 | |||
126 | get_obj_data.status = status; | ||
127 | |||
128 | dev_p->mtp_turbo_active = cy_false; | ||
129 | |||
130 | if (dev_p->mtp_event_cb) | ||
131 | dev_p->mtp_event_cb( | ||
132 | (cy_as_device_handle) dev_p, | ||
133 | cy_as_mtp_get_object_complete, | ||
134 | &get_obj_data); | ||
135 | } | ||
136 | break; | ||
137 | |||
138 | case 2: /* BlockTable Needed */ | ||
139 | { | ||
140 | if (dev_p->mtp_event_cb) | ||
141 | dev_p->mtp_event_cb( | ||
142 | (cy_as_device_handle) dev_p, | ||
143 | cy_as_mtp_block_table_needed, 0); | ||
144 | } | ||
145 | break; | ||
146 | default: | ||
147 | cy_as_hal_print_message("invalid event type\n"); | ||
148 | cy_as_ll_send_data_response(dev_p, | ||
149 | CY_RQT_TUR_RQT_CONTEXT, | ||
150 | CY_RESP_MTP_INVALID_EVENT, | ||
151 | sizeof(ev), &ev); | ||
152 | break; | ||
153 | } | ||
154 | break; | ||
155 | |||
156 | case CY_RQT_TURBO_CMD_FROM_HOST: | ||
157 | { | ||
158 | mtp_datalen = | ||
159 | cy_as_ll_request_response__get_word(req_p, 1); | ||
160 | |||
161 | /* Get the endpoint pointer based on | ||
162 | * the endpoint number */ | ||
163 | ep_p = CY_AS_NUM_EP(dev_p, CY_AS_MTP_READ_ENDPOINT); | ||
164 | |||
165 | /* The event should arrive only after the DMA operation | ||
166 | * has been queued. */ | ||
167 | cy_as_hal_assert(ep_p->queue_p != 0); | ||
168 | |||
169 | /* Put the len in ep data information in | ||
170 | * dmaqueue and kick start the queue */ | ||
171 | cy_as_hal_assert(ep_p->queue_p->size >= mtp_datalen); | ||
172 | |||
173 | if (mtp_datalen == 0) { | ||
174 | cy_as_dma_completed_callback(dev_p->tag, | ||
175 | CY_AS_MTP_READ_ENDPOINT, 0, | ||
176 | CY_AS_ERROR_SUCCESS); | ||
177 | } else { | ||
178 | ep_p->maxhwdata = mtp_datalen; | ||
179 | |||
180 | /* | ||
181 | * make sure that the DMA status for this | ||
182 | * EP is not running, so that the call to | ||
183 | * cy_as_dma_kick_start gets this transfer | ||
184 | * going. note: in MTP mode, we never leave | ||
185 | * a DMA transfer of greater than one packet | ||
186 | * running. so, it is okay to override the | ||
187 | * status here and start the next packet | ||
188 | * transfer. | ||
189 | */ | ||
190 | cy_as_dma_end_point_set_stopped(ep_p); | ||
191 | |||
192 | /* Kick start the queue if it is not running */ | ||
193 | cy_as_dma_kick_start(dev_p, | ||
194 | CY_AS_MTP_READ_ENDPOINT); | ||
195 | } | ||
196 | } | ||
197 | break; | ||
198 | |||
199 | case CY_RQT_TURBO_START_WRITE_DMA: | ||
200 | { | ||
201 | /* | ||
202 | * now that the firmware is ready to receive the | ||
203 | * next packet of data, start the corresponding | ||
204 | * DMA transfer. first, ensure that a DMA | ||
205 | * operation is still pending in the queue for the | ||
206 | * write endpoint. | ||
207 | */ | ||
208 | cy_as_ll_send_status_response(dev_p, | ||
209 | CY_RQT_TUR_RQT_CONTEXT, | ||
210 | CY_AS_ERROR_SUCCESS, 0); | ||
211 | |||
212 | ep_p = CY_AS_NUM_EP(dev_p, CY_AS_MTP_WRITE_ENDPOINT); | ||
213 | cy_as_hal_assert(ep_p->queue_p != 0); | ||
214 | |||
215 | cy_as_dma_end_point_set_stopped(ep_p); | ||
216 | cy_as_dma_kick_start(dev_p, CY_AS_MTP_WRITE_ENDPOINT); | ||
217 | } | ||
218 | break; | ||
219 | |||
220 | default: | ||
221 | cy_as_hal_print_message("invalid request received " | ||
222 | "on TUR context\n"); | ||
223 | val = req_p->box0; | ||
224 | cy_as_ll_send_data_response(dev_p, CY_RQT_TUR_RQT_CONTEXT, | ||
225 | CY_RESP_INVALID_REQUEST, sizeof(val), &val); | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | static cy_as_return_status_t | ||
231 | my_handle_response_no_data(cy_as_device *dev_p, | ||
232 | cy_as_ll_request_response *req_p, | ||
233 | cy_as_ll_request_response *reply_p) | ||
234 | { | ||
235 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
236 | |||
237 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
238 | CY_RESP_SUCCESS_FAILURE) { | ||
239 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
240 | goto destroy; | ||
241 | } | ||
242 | |||
243 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
244 | |||
245 | destroy: | ||
246 | cy_as_ll_destroy_request(dev_p, req_p); | ||
247 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
248 | |||
249 | return ret; | ||
250 | } | ||
251 | |||
252 | static cy_as_return_status_t | ||
253 | my_handle_response_mtp_start(cy_as_device *dev_p, | ||
254 | cy_as_ll_request_response *req_p, | ||
255 | cy_as_ll_request_response *reply_p, | ||
256 | cy_as_return_status_t ret) | ||
257 | { | ||
258 | if (ret != CY_AS_ERROR_SUCCESS) | ||
259 | goto destroy; | ||
260 | |||
261 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
262 | CY_RESP_SUCCESS_FAILURE) { | ||
263 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
264 | goto destroy; | ||
265 | } | ||
266 | |||
267 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
268 | if (ret != CY_AS_ERROR_SUCCESS) | ||
269 | goto destroy; | ||
270 | |||
271 | dev_p->mtp_count++; | ||
272 | |||
273 | cy_as_dma_enable_end_point(dev_p, CY_AS_MTP_READ_ENDPOINT, | ||
274 | cy_true, cy_as_direction_out); | ||
275 | dev_p->usb_config[CY_AS_MTP_READ_ENDPOINT].enabled = cy_true; | ||
276 | dev_p->usb_config[CY_AS_MTP_READ_ENDPOINT].dir = cy_as_usb_out; | ||
277 | dev_p->usb_config[CY_AS_MTP_READ_ENDPOINT].type = cy_as_usb_bulk; | ||
278 | |||
279 | cy_as_dma_enable_end_point(dev_p, CY_AS_MTP_WRITE_ENDPOINT, | ||
280 | cy_true, cy_as_direction_in); | ||
281 | dev_p->usb_config[CY_AS_MTP_WRITE_ENDPOINT].enabled = cy_true; | ||
282 | dev_p->usb_config[CY_AS_MTP_WRITE_ENDPOINT].dir = cy_as_usb_in; | ||
283 | dev_p->usb_config[CY_AS_MTP_WRITE_ENDPOINT].type = cy_as_usb_bulk; | ||
284 | |||
285 | /* Packet size is 512 bytes */ | ||
286 | cy_as_dma_set_max_dma_size(dev_p, 0x02, 0x0200); | ||
287 | /* Packet size is 64 bytes until a switch to high speed happens.*/ | ||
288 | cy_as_dma_set_max_dma_size(dev_p, 0x06, 0x40); | ||
289 | |||
290 | destroy: | ||
291 | cy_as_ll_destroy_request(dev_p, req_p); | ||
292 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
293 | |||
294 | if (ret != CY_AS_ERROR_SUCCESS) | ||
295 | cy_as_ll_register_request_callback(dev_p, | ||
296 | CY_RQT_TUR_RQT_CONTEXT, 0); | ||
297 | |||
298 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
299 | |||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | |||
304 | cy_as_return_status_t | ||
305 | cy_as_mtp_start(cy_as_device_handle handle, | ||
306 | cy_as_mtp_event_callback event_c_b, | ||
307 | cy_as_function_callback cb, | ||
308 | uint32_t client | ||
309 | ) | ||
310 | { | ||
311 | cy_as_ll_request_response *req_p, *reply_p; | ||
312 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
313 | cy_as_device *dev_p; | ||
314 | |||
315 | dev_p = (cy_as_device *)handle; | ||
316 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
317 | return CY_AS_ERROR_INVALID_HANDLE; | ||
318 | |||
319 | if (!cy_as_device_is_configured(dev_p)) | ||
320 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
321 | |||
322 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
323 | return CY_AS_ERROR_NO_FIRMWARE; | ||
324 | |||
325 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
326 | return CY_AS_ERROR_IN_SUSPEND; | ||
327 | |||
328 | if (cy_as_device_is_in_callback(dev_p)) | ||
329 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
330 | |||
331 | if (cy_as_device_is_m_s_s_pending(dev_p)) | ||
332 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
333 | |||
334 | if (dev_p->storage_count == 0) | ||
335 | return CY_AS_ERROR_NOT_RUNNING; | ||
336 | |||
337 | if (dev_p->usb_count == 0) | ||
338 | return CY_AS_ERROR_NOT_RUNNING; | ||
339 | |||
340 | if (dev_p->is_mtp_firmware == 0) | ||
341 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
342 | |||
343 | cy_as_device_set_m_s_s_pending(dev_p); | ||
344 | |||
345 | if (dev_p->mtp_count == 0) { | ||
346 | |||
347 | dev_p->mtp_event_cb = event_c_b; | ||
348 | /* | ||
349 | * we register here because the start request may cause | ||
350 | * events to occur before the response to the start request. | ||
351 | */ | ||
352 | cy_as_ll_register_request_callback(dev_p, | ||
353 | CY_RQT_TUR_RQT_CONTEXT, my_mtp_request_callback); | ||
354 | |||
355 | /* Create the request to send to the West Bridge device */ | ||
356 | req_p = cy_as_ll_create_request(dev_p, | ||
357 | CY_RQT_START_MTP, CY_RQT_TUR_RQT_CONTEXT, 0); | ||
358 | if (req_p == 0) { | ||
359 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
360 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
361 | } | ||
362 | |||
363 | /* Reserve space for the reply, the reply data will | ||
364 | * not exceed one word */ | ||
365 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
366 | if (reply_p == 0) { | ||
367 | cy_as_ll_destroy_request(dev_p, req_p); | ||
368 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
369 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
370 | } | ||
371 | |||
372 | if (cb == 0) { | ||
373 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
374 | req_p, reply_p); | ||
375 | if (ret != CY_AS_ERROR_SUCCESS) | ||
376 | goto destroy; | ||
377 | |||
378 | return my_handle_response_mtp_start(dev_p, req_p, | ||
379 | reply_p, ret); | ||
380 | } else { | ||
381 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
382 | CY_FUNCT_CB_MTP_START, 0, dev_p->func_cbs_mtp, | ||
383 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
384 | cy_as_mtp_func_callback); | ||
385 | |||
386 | if (ret != CY_AS_ERROR_SUCCESS) | ||
387 | goto destroy; | ||
388 | |||
389 | return ret; | ||
390 | } | ||
391 | |||
392 | destroy: | ||
393 | cy_as_ll_destroy_request(dev_p, req_p); | ||
394 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
395 | } else { | ||
396 | dev_p->mtp_count++; | ||
397 | if (cb) | ||
398 | cb(handle, ret, client, CY_FUNCT_CB_MTP_START, 0); | ||
399 | } | ||
400 | |||
401 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
402 | |||
403 | return ret; | ||
404 | } | ||
405 | EXPORT_SYMBOL(cy_as_mtp_start); | ||
406 | |||
407 | static cy_as_return_status_t | ||
408 | my_handle_response_mtp_stop(cy_as_device *dev_p, | ||
409 | cy_as_ll_request_response *req_p, | ||
410 | cy_as_ll_request_response *reply_p, | ||
411 | cy_as_return_status_t ret) | ||
412 | { | ||
413 | if (ret != CY_AS_ERROR_SUCCESS) | ||
414 | goto destroy; | ||
415 | |||
416 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
417 | CY_RESP_SUCCESS_FAILURE) { | ||
418 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
419 | goto destroy; | ||
420 | } | ||
421 | |||
422 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
423 | if (ret != CY_AS_ERROR_SUCCESS) | ||
424 | goto destroy; | ||
425 | |||
426 | /* | ||
427 | * we successfully shutdown the stack, so decrement | ||
428 | * to make the count zero. | ||
429 | */ | ||
430 | dev_p->mtp_count--; | ||
431 | |||
432 | destroy: | ||
433 | cy_as_ll_destroy_request(dev_p, req_p); | ||
434 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
435 | |||
436 | if (ret != CY_AS_ERROR_SUCCESS) | ||
437 | cy_as_ll_register_request_callback(dev_p, | ||
438 | CY_RQT_TUR_RQT_CONTEXT, 0); | ||
439 | |||
440 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
441 | |||
442 | return ret; | ||
443 | } | ||
444 | |||
445 | cy_as_return_status_t | ||
446 | cy_as_mtp_stop(cy_as_device_handle handle, | ||
447 | cy_as_function_callback cb, | ||
448 | uint32_t client | ||
449 | ) | ||
450 | { | ||
451 | cy_as_ll_request_response *req_p = 0, *reply_p = 0; | ||
452 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
453 | |||
454 | cy_as_device *dev_p; | ||
455 | |||
456 | cy_as_log_debug_message(6, "cy_as_mtp_stop called"); | ||
457 | |||
458 | dev_p = (cy_as_device *)handle; | ||
459 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
460 | return CY_AS_ERROR_INVALID_HANDLE; | ||
461 | |||
462 | ret = is_mtp_active(dev_p); | ||
463 | if (ret != CY_AS_ERROR_SUCCESS) | ||
464 | return ret; | ||
465 | |||
466 | if (cy_as_device_is_in_callback(dev_p)) | ||
467 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
468 | |||
469 | if (cy_as_device_is_m_s_s_pending(dev_p)) | ||
470 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
471 | |||
472 | cy_as_device_set_m_s_s_pending(dev_p); | ||
473 | |||
474 | if (dev_p->mtp_count == 1) { | ||
475 | /* Create the request to send to the West | ||
476 | * Bridge device */ | ||
477 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_STOP_MTP, | ||
478 | CY_RQT_TUR_RQT_CONTEXT, 0); | ||
479 | if (req_p == 0) { | ||
480 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
481 | goto destroy; | ||
482 | } | ||
483 | |||
484 | /* Reserve space for the reply, the reply data will | ||
485 | * not exceed one word */ | ||
486 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
487 | if (reply_p == 0) { | ||
488 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
489 | goto destroy; | ||
490 | } | ||
491 | |||
492 | if (cb == 0) { | ||
493 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
494 | req_p, reply_p); | ||
495 | if (ret != CY_AS_ERROR_SUCCESS) | ||
496 | goto destroy; | ||
497 | |||
498 | return my_handle_response_mtp_stop(dev_p, req_p, | ||
499 | reply_p, ret); | ||
500 | } else { | ||
501 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
502 | CY_FUNCT_CB_MTP_STOP, 0, dev_p->func_cbs_mtp, | ||
503 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
504 | cy_as_mtp_func_callback); | ||
505 | |||
506 | if (ret != CY_AS_ERROR_SUCCESS) | ||
507 | goto destroy; | ||
508 | |||
509 | return ret; | ||
510 | } | ||
511 | |||
512 | destroy: | ||
513 | cy_as_ll_destroy_request(dev_p, req_p); | ||
514 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
515 | } else if (dev_p->mtp_count > 1) { | ||
516 | |||
517 | dev_p->mtp_count--; | ||
518 | |||
519 | if (cb) | ||
520 | cb(handle, ret, client, CY_FUNCT_CB_MTP_STOP, 0); | ||
521 | } | ||
522 | |||
523 | cy_as_device_clear_m_s_s_pending(dev_p); | ||
524 | |||
525 | return ret; | ||
526 | } | ||
527 | |||
528 | static void | ||
529 | mtp_write_callback( | ||
530 | cy_as_device *dev_p, | ||
531 | uint8_t context, | ||
532 | cy_as_ll_request_response *rqt, | ||
533 | cy_as_ll_request_response *resp, | ||
534 | cy_as_return_status_t ret) | ||
535 | { | ||
536 | cy_as_hal_assert(context == CY_RQT_TUR_RQT_CONTEXT); | ||
537 | |||
538 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
539 | if (cy_as_ll_request_response__get_code(resp) != | ||
540 | CY_RESP_SUCCESS_FAILURE) | ||
541 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
542 | else | ||
543 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
544 | } | ||
545 | |||
546 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
547 | /* Firmware failed the request. Cancel the DMA transfer. */ | ||
548 | cy_as_dma_cancel(dev_p, 0x04, CY_AS_ERROR_CANCELED); | ||
549 | cy_as_device_clear_storage_async_pending(dev_p); | ||
550 | } | ||
551 | |||
552 | cy_as_ll_destroy_response(dev_p, resp); | ||
553 | cy_as_ll_destroy_request(dev_p, rqt); | ||
554 | } | ||
555 | |||
556 | static void | ||
557 | async_write_request_callback(cy_as_device *dev_p, | ||
558 | cy_as_end_point_number_t ep, void *buf_p, uint32_t size, | ||
559 | cy_as_return_status_t err) | ||
560 | { | ||
561 | cy_as_device_handle h; | ||
562 | cy_as_function_callback cb; | ||
563 | |||
564 | (void)size; | ||
565 | (void)buf_p; | ||
566 | (void)ep; | ||
567 | |||
568 | |||
569 | cy_as_log_debug_message(6, "async_write_request_callback called"); | ||
570 | |||
571 | h = (cy_as_device_handle)dev_p; | ||
572 | |||
573 | cb = dev_p->mtp_cb; | ||
574 | dev_p->mtp_cb = 0; | ||
575 | |||
576 | cy_as_device_clear_storage_async_pending(dev_p); | ||
577 | |||
578 | if (cb) | ||
579 | cb(h, err, dev_p->mtp_client, dev_p->mtp_op, 0); | ||
580 | |||
581 | } | ||
582 | |||
583 | static void | ||
584 | sync_mtp_callback(cy_as_device *dev_p, cy_as_end_point_number_t ep, | ||
585 | void *buf_p, uint32_t size, cy_as_return_status_t err) | ||
586 | { | ||
587 | (void)ep; | ||
588 | (void)buf_p; | ||
589 | (void)size; | ||
590 | |||
591 | dev_p->mtp_error = err; | ||
592 | } | ||
593 | |||
594 | static cy_as_return_status_t | ||
595 | cy_as_mtp_operation(cy_as_device *dev_p, | ||
596 | cy_as_mtp_block_table *blk_table, | ||
597 | uint32_t num_bytes, | ||
598 | uint32_t transaction_id, | ||
599 | cy_as_function_callback cb, | ||
600 | uint32_t client, | ||
601 | uint8_t rqttype | ||
602 | ) | ||
603 | { | ||
604 | cy_as_ll_request_response *req_p = 0, *reply_p = 0; | ||
605 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
606 | uint32_t mask = 0; | ||
607 | cy_as_funct_c_b_type mtp_cb_op = 0; | ||
608 | uint16_t size = 2; | ||
609 | |||
610 | if (dev_p->mtp_count == 0) | ||
611 | return CY_AS_ERROR_NOT_RUNNING; | ||
612 | |||
613 | if (rqttype == CY_RQT_INIT_SEND_OBJECT) { | ||
614 | mtp_cb_op = CY_FUNCT_CB_MTP_INIT_SEND_OBJECT; | ||
615 | dev_p->mtp_turbo_active = cy_true; | ||
616 | } else if (rqttype == CY_RQT_INIT_GET_OBJECT) { | ||
617 | mtp_cb_op = CY_FUNCT_CB_MTP_INIT_GET_OBJECT; | ||
618 | dev_p->mtp_turbo_active = cy_true; | ||
619 | } else | ||
620 | mtp_cb_op = CY_FUNCT_CB_MTP_SEND_BLOCK_TABLE; | ||
621 | |||
622 | ret = is_mtp_active(dev_p); | ||
623 | if (ret != CY_AS_ERROR_SUCCESS) | ||
624 | return ret; | ||
625 | |||
626 | if (CY_RQT_INIT_GET_OBJECT == rqttype) | ||
627 | size = 4; | ||
628 | |||
629 | /* Create the request to send to the West | ||
630 | * Bridge device */ | ||
631 | req_p = cy_as_ll_create_request(dev_p, rqttype, | ||
632 | CY_RQT_TUR_RQT_CONTEXT, size); | ||
633 | if (req_p == 0) { | ||
634 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
635 | goto destroy; | ||
636 | } | ||
637 | |||
638 | /* Reserve space for the reply, the reply data will | ||
639 | * not exceed one word */ | ||
640 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
641 | if (reply_p == 0) { | ||
642 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
643 | goto destroy; | ||
644 | } | ||
645 | |||
646 | cy_as_ll_request_response__set_word(req_p, 0, | ||
647 | (uint16_t)(num_bytes & 0xFFFF)); | ||
648 | cy_as_ll_request_response__set_word(req_p, 1, | ||
649 | (uint16_t)((num_bytes >> 16) & 0xFFFF)); | ||
650 | |||
651 | /* If it is GET_OBJECT, send transaction id as well*/ | ||
652 | if (CY_RQT_INIT_GET_OBJECT == rqttype) { | ||
653 | cy_as_ll_request_response__set_word(req_p, 2, | ||
654 | (uint16_t)(transaction_id & 0xFFFF)); | ||
655 | cy_as_ll_request_response__set_word(req_p, 3, | ||
656 | (uint16_t)((transaction_id >> 16) & 0xFFFF)); | ||
657 | } | ||
658 | |||
659 | if (cb == 0) { | ||
660 | /* Queue the DMA request for block table write */ | ||
661 | ret = cy_as_dma_queue_request(dev_p, 4, blk_table, | ||
662 | sizeof(cy_as_mtp_block_table), cy_false, | ||
663 | cy_false, sync_mtp_callback); | ||
664 | |||
665 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
666 | req_p, reply_p); | ||
667 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
668 | cy_as_dma_cancel(dev_p, 4, CY_AS_ERROR_CANCELED); | ||
669 | cy_as_device_clear_storage_async_pending(dev_p); | ||
670 | |||
671 | goto destroy; | ||
672 | } | ||
673 | |||
674 | ret = cy_as_dma_drain_queue(dev_p, 4, cy_true); | ||
675 | if (ret != CY_AS_ERROR_SUCCESS) | ||
676 | goto destroy; | ||
677 | |||
678 | ret = dev_p->mtp_error; | ||
679 | goto destroy; | ||
680 | } else { | ||
681 | #if 0 | ||
682 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
683 | CY_FUNCT_CB_MTP_INIT_SEND_OBJECT, | ||
684 | 0, dev_p->func_cbs_mtp, CY_AS_REQUEST_RESPONSE_EX, | ||
685 | req_p, reply_p, cy_as_mtp_func_callback); | ||
686 | |||
687 | if (ret != CY_AS_ERROR_SUCCESS) | ||
688 | goto destroy; | ||
689 | #endif | ||
690 | |||
691 | /* Protection from interrupt driven code */ | ||
692 | /* since we are using storage EP4 check if any | ||
693 | * storage activity is pending */ | ||
694 | mask = cy_as_hal_disable_interrupts(); | ||
695 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
696 | (dev_p->storage_wait)) { | ||
697 | cy_as_hal_enable_interrupts(mask); | ||
698 | return CY_AS_ERROR_ASYNC_PENDING; | ||
699 | } | ||
700 | cy_as_device_set_storage_async_pending(dev_p); | ||
701 | cy_as_hal_enable_interrupts(mask); | ||
702 | |||
703 | dev_p->mtp_cb = cb; | ||
704 | dev_p->mtp_client = client; | ||
705 | dev_p->mtp_op = mtp_cb_op; | ||
706 | |||
707 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
708 | cy_false, mtp_write_callback); | ||
709 | if (ret != CY_AS_ERROR_SUCCESS) | ||
710 | goto destroy; | ||
711 | |||
712 | ret = cy_as_dma_queue_request(dev_p, 4, blk_table, | ||
713 | sizeof(cy_as_mtp_block_table), cy_false, cy_false, | ||
714 | async_write_request_callback); | ||
715 | if (ret != CY_AS_ERROR_SUCCESS) | ||
716 | return ret; | ||
717 | |||
718 | /* Kick start the queue if it is not running */ | ||
719 | cy_as_dma_kick_start(dev_p, 4); | ||
720 | |||
721 | return CY_AS_ERROR_SUCCESS; | ||
722 | } | ||
723 | |||
724 | destroy: | ||
725 | cy_as_ll_destroy_request(dev_p, req_p); | ||
726 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
727 | |||
728 | return ret; | ||
729 | } | ||
730 | |||
731 | cy_as_return_status_t | ||
732 | cy_as_mtp_init_send_object(cy_as_device_handle handle, | ||
733 | cy_as_mtp_block_table *blk_table, | ||
734 | uint32_t num_bytes, | ||
735 | cy_as_function_callback cb, | ||
736 | uint32_t client | ||
737 | ) | ||
738 | { | ||
739 | cy_as_device *dev_p; | ||
740 | dev_p = (cy_as_device *)handle; | ||
741 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
742 | return CY_AS_ERROR_INVALID_HANDLE; | ||
743 | |||
744 | return cy_as_mtp_operation(dev_p, blk_table, num_bytes, 0, cb, | ||
745 | client, CY_RQT_INIT_SEND_OBJECT); | ||
746 | |||
747 | } | ||
748 | EXPORT_SYMBOL(cy_as_mtp_init_send_object); | ||
749 | |||
750 | cy_as_return_status_t | ||
751 | cy_as_mtp_init_get_object(cy_as_device_handle handle, | ||
752 | cy_as_mtp_block_table *blk_table, | ||
753 | uint32_t num_bytes, | ||
754 | uint32_t transaction_id, | ||
755 | cy_as_function_callback cb, | ||
756 | uint32_t client | ||
757 | ) | ||
758 | { | ||
759 | cy_as_device *dev_p; | ||
760 | dev_p = (cy_as_device *)handle; | ||
761 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
762 | return CY_AS_ERROR_INVALID_HANDLE; | ||
763 | |||
764 | return cy_as_mtp_operation(dev_p, blk_table, num_bytes, | ||
765 | transaction_id, cb, client, CY_RQT_INIT_GET_OBJECT); | ||
766 | |||
767 | } | ||
768 | EXPORT_SYMBOL(cy_as_mtp_init_get_object); | ||
769 | |||
770 | static cy_as_return_status_t | ||
771 | my_handle_response_cancel_send_object(cy_as_device *dev_p, | ||
772 | cy_as_ll_request_response *req_p, | ||
773 | cy_as_ll_request_response *reply_p, | ||
774 | cy_as_return_status_t ret) | ||
775 | { | ||
776 | if (ret != CY_AS_ERROR_SUCCESS) | ||
777 | goto destroy; | ||
778 | |||
779 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
780 | CY_RESP_SUCCESS_FAILURE) { | ||
781 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
782 | goto destroy; | ||
783 | } | ||
784 | |||
785 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
786 | if (ret != CY_AS_ERROR_SUCCESS) | ||
787 | goto destroy; | ||
788 | |||
789 | |||
790 | destroy: | ||
791 | cy_as_ll_destroy_request(dev_p, req_p); | ||
792 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
793 | |||
794 | return ret; | ||
795 | } | ||
796 | |||
797 | cy_as_return_status_t | ||
798 | cy_as_mtp_cancel_send_object(cy_as_device_handle handle, | ||
799 | cy_as_function_callback cb, | ||
800 | uint32_t client | ||
801 | ) | ||
802 | { | ||
803 | cy_as_ll_request_response *req_p = 0, *reply_p = 0; | ||
804 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
805 | cy_as_device *dev_p; | ||
806 | |||
807 | dev_p = (cy_as_device *)handle; | ||
808 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
809 | return CY_AS_ERROR_INVALID_HANDLE; | ||
810 | |||
811 | if (dev_p->mtp_count == 0) | ||
812 | return CY_AS_ERROR_NOT_RUNNING; | ||
813 | |||
814 | /* Create the request to send to the West Bridge device */ | ||
815 | req_p = cy_as_ll_create_request(dev_p, | ||
816 | CY_RQT_CANCEL_SEND_OBJECT, CY_RQT_TUR_RQT_CONTEXT, 0); | ||
817 | if (req_p == 0) { | ||
818 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
819 | goto destroy; | ||
820 | } | ||
821 | |||
822 | /* Reserve space for the reply, the reply data will | ||
823 | * not exceed one word */ | ||
824 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
825 | if (reply_p == 0) { | ||
826 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
827 | goto destroy; | ||
828 | } | ||
829 | |||
830 | if (cb == 0) { | ||
831 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
832 | req_p, reply_p); | ||
833 | if (ret != CY_AS_ERROR_SUCCESS) | ||
834 | goto destroy; | ||
835 | |||
836 | return my_handle_response_cancel_send_object(dev_p, | ||
837 | req_p, reply_p, ret); | ||
838 | } else { | ||
839 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
840 | CY_FUNCT_CB_MTP_CANCEL_SEND_OBJECT, 0, | ||
841 | dev_p->func_cbs_mtp, CY_AS_REQUEST_RESPONSE_EX, | ||
842 | req_p, reply_p, cy_as_mtp_func_callback); | ||
843 | |||
844 | if (ret != CY_AS_ERROR_SUCCESS) | ||
845 | goto destroy; | ||
846 | |||
847 | return ret; | ||
848 | } | ||
849 | |||
850 | destroy: | ||
851 | cy_as_ll_destroy_request(dev_p, req_p); | ||
852 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
853 | |||
854 | return ret; | ||
855 | } | ||
856 | EXPORT_SYMBOL(cy_as_mtp_cancel_send_object); | ||
857 | |||
858 | static cy_as_return_status_t | ||
859 | my_handle_response_cancel_get_object(cy_as_device *dev_p, | ||
860 | cy_as_ll_request_response *req_p, | ||
861 | cy_as_ll_request_response *reply_p, | ||
862 | cy_as_return_status_t ret) | ||
863 | { | ||
864 | if (ret != CY_AS_ERROR_SUCCESS) | ||
865 | goto destroy; | ||
866 | |||
867 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
868 | CY_RESP_SUCCESS_FAILURE) { | ||
869 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
870 | goto destroy; | ||
871 | } | ||
872 | |||
873 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
874 | if (ret != CY_AS_ERROR_SUCCESS) | ||
875 | goto destroy; | ||
876 | |||
877 | |||
878 | destroy: | ||
879 | cy_as_ll_destroy_request(dev_p, req_p); | ||
880 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
881 | |||
882 | return ret; | ||
883 | } | ||
884 | |||
885 | cy_as_return_status_t | ||
886 | cy_as_mtp_cancel_get_object(cy_as_device_handle handle, | ||
887 | cy_as_function_callback cb, | ||
888 | uint32_t client | ||
889 | ) | ||
890 | { | ||
891 | cy_as_ll_request_response *req_p = 0, *reply_p = 0; | ||
892 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
893 | cy_as_device *dev_p; | ||
894 | |||
895 | dev_p = (cy_as_device *)handle; | ||
896 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
897 | return CY_AS_ERROR_INVALID_HANDLE; | ||
898 | |||
899 | if (dev_p->mtp_count == 0) | ||
900 | return CY_AS_ERROR_NOT_RUNNING; | ||
901 | |||
902 | /* Create the request to send to the West Bridge device */ | ||
903 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_CANCEL_GET_OBJECT, | ||
904 | CY_RQT_TUR_RQT_CONTEXT, 0); | ||
905 | if (req_p == 0) { | ||
906 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
907 | goto destroy; | ||
908 | } | ||
909 | |||
910 | /* Reserve space for the reply, the reply data will | ||
911 | * not exceed one word */ | ||
912 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
913 | if (reply_p == 0) { | ||
914 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
915 | goto destroy; | ||
916 | } | ||
917 | |||
918 | if (cb == 0) { | ||
919 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
920 | req_p, reply_p); | ||
921 | if (ret != CY_AS_ERROR_SUCCESS) | ||
922 | goto destroy; | ||
923 | |||
924 | return my_handle_response_cancel_get_object(dev_p, | ||
925 | req_p, reply_p, ret); | ||
926 | } else { | ||
927 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
928 | CY_FUNCT_CB_MTP_CANCEL_GET_OBJECT, 0, | ||
929 | dev_p->func_cbs_mtp, CY_AS_REQUEST_RESPONSE_EX, | ||
930 | req_p, reply_p, cy_as_mtp_func_callback); | ||
931 | |||
932 | if (ret != CY_AS_ERROR_SUCCESS) | ||
933 | goto destroy; | ||
934 | |||
935 | return ret; | ||
936 | } | ||
937 | |||
938 | destroy: | ||
939 | cy_as_ll_destroy_request(dev_p, req_p); | ||
940 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
941 | |||
942 | return ret; | ||
943 | } | ||
944 | EXPORT_SYMBOL(cy_as_mtp_cancel_get_object); | ||
945 | |||
946 | cy_as_return_status_t | ||
947 | cy_as_mtp_send_block_table(cy_as_device_handle handle, | ||
948 | cy_as_mtp_block_table *blk_table, | ||
949 | cy_as_function_callback cb, | ||
950 | uint32_t client) | ||
951 | { | ||
952 | cy_as_device *dev_p; | ||
953 | dev_p = (cy_as_device *)handle; | ||
954 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
955 | return CY_AS_ERROR_INVALID_HANDLE; | ||
956 | |||
957 | return cy_as_mtp_operation(dev_p, blk_table, 0, 0, cb, | ||
958 | client, CY_RQT_SEND_BLOCK_TABLE); | ||
959 | } | ||
960 | |||
961 | static void | ||
962 | cy_as_mtp_func_callback(cy_as_device *dev_p, | ||
963 | uint8_t context, | ||
964 | cy_as_ll_request_response *rqt, | ||
965 | cy_as_ll_request_response *resp, | ||
966 | cy_as_return_status_t stat) | ||
967 | { | ||
968 | cy_as_func_c_b_node* node = (cy_as_func_c_b_node *) | ||
969 | dev_p->func_cbs_mtp->head_p; | ||
970 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
971 | uint8_t code; | ||
972 | cy_bool delay_callback = cy_false; | ||
973 | |||
974 | cy_as_hal_assert(dev_p->func_cbs_mtp->count != 0); | ||
975 | cy_as_hal_assert(dev_p->func_cbs_mtp->type == CYAS_FUNC_CB); | ||
976 | |||
977 | (void)context; | ||
978 | |||
979 | /* The Handlers are responsible for Deleting the | ||
980 | * rqt and resp when they are finished | ||
981 | */ | ||
982 | code = cy_as_ll_request_response__get_code(rqt); | ||
983 | switch (code) { | ||
984 | case CY_RQT_START_MTP: | ||
985 | ret = my_handle_response_mtp_start(dev_p, rqt, | ||
986 | resp, stat); | ||
987 | break; | ||
988 | case CY_RQT_STOP_MTP: | ||
989 | ret = my_handle_response_mtp_stop(dev_p, rqt, | ||
990 | resp, stat); | ||
991 | break; | ||
992 | #if 0 | ||
993 | case CY_RQT_INIT_SEND_OBJECT: | ||
994 | ret = my_handle_response_init_send_object(dev_p, | ||
995 | rqt, resp, stat, cy_true); | ||
996 | delay_callback = cy_true; | ||
997 | break; | ||
998 | #endif | ||
999 | case CY_RQT_CANCEL_SEND_OBJECT: | ||
1000 | ret = my_handle_response_cancel_send_object(dev_p, | ||
1001 | rqt, resp, stat); | ||
1002 | break; | ||
1003 | #if 0 | ||
1004 | case CY_RQT_INIT_GET_OBJECT: | ||
1005 | ret = my_handle_response_init_get_object(dev_p, | ||
1006 | rqt, resp, stat, cy_true); | ||
1007 | delay_callback = cy_true; | ||
1008 | break; | ||
1009 | #endif | ||
1010 | case CY_RQT_CANCEL_GET_OBJECT: | ||
1011 | ret = my_handle_response_cancel_get_object(dev_p, | ||
1012 | rqt, resp, stat); | ||
1013 | break; | ||
1014 | #if 0 | ||
1015 | case CY_RQT_SEND_BLOCK_TABLE: | ||
1016 | ret = my_handle_response_send_block_table(dev_p, rqt, | ||
1017 | resp, stat, cy_true); | ||
1018 | delay_callback = cy_true; | ||
1019 | break; | ||
1020 | #endif | ||
1021 | case CY_RQT_ENABLE_USB_PATH: | ||
1022 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
1023 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1024 | dev_p->is_storage_only_mode = cy_false; | ||
1025 | break; | ||
1026 | default: | ||
1027 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1028 | cy_as_hal_assert(cy_false); | ||
1029 | break; | ||
1030 | } | ||
1031 | |||
1032 | /* | ||
1033 | * if the low level layer returns a direct error, use the | ||
1034 | * corresponding error code. if not, use the error code | ||
1035 | * based on the response from firmware. | ||
1036 | */ | ||
1037 | if (stat == CY_AS_ERROR_SUCCESS) | ||
1038 | stat = ret; | ||
1039 | |||
1040 | if (!delay_callback) { | ||
1041 | node->cb_p((cy_as_device_handle)dev_p, stat, node->client_data, | ||
1042 | node->data_type, node->data); | ||
1043 | cy_as_remove_c_b_node(dev_p->func_cbs_mtp); | ||
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | cy_as_return_status_t | ||
1048 | cy_as_mtp_storage_only_start(cy_as_device_handle handle) | ||
1049 | { | ||
1050 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1051 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1052 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1053 | |||
1054 | if (!cy_as_device_is_configured(dev_p)) | ||
1055 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
1056 | |||
1057 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
1058 | return CY_AS_ERROR_NO_FIRMWARE; | ||
1059 | |||
1060 | if (dev_p->storage_count == 0) | ||
1061 | return CY_AS_ERROR_NOT_RUNNING; | ||
1062 | |||
1063 | dev_p->is_storage_only_mode = cy_true; | ||
1064 | return CY_AS_ERROR_SUCCESS; | ||
1065 | } | ||
1066 | EXPORT_SYMBOL(cy_as_mtp_storage_only_start); | ||
1067 | |||
1068 | cy_as_return_status_t | ||
1069 | cy_as_mtp_storage_only_stop(cy_as_device_handle handle, | ||
1070 | cy_as_function_callback cb, | ||
1071 | uint32_t client) | ||
1072 | { | ||
1073 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1074 | cy_as_ll_request_response *req_p, *reply_p; | ||
1075 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1076 | |||
1077 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1078 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1079 | |||
1080 | if (!cy_as_device_is_configured(dev_p)) | ||
1081 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
1082 | |||
1083 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
1084 | return CY_AS_ERROR_NO_FIRMWARE; | ||
1085 | |||
1086 | if (dev_p->storage_count == 0) | ||
1087 | return CY_AS_ERROR_NOT_RUNNING; | ||
1088 | |||
1089 | if (dev_p->is_storage_only_mode == cy_false) | ||
1090 | return CY_AS_ERROR_SUCCESS; | ||
1091 | |||
1092 | if (cy_as_device_is_in_callback(dev_p)) | ||
1093 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1094 | |||
1095 | req_p = cy_as_ll_create_request(dev_p, | ||
1096 | CY_RQT_ENABLE_USB_PATH, CY_RQT_TUR_RQT_CONTEXT, 1); | ||
1097 | if (req_p == 0) | ||
1098 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1099 | |||
1100 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1101 | if (reply_p == 0) { | ||
1102 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1103 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1104 | } | ||
1105 | |||
1106 | if (cb == 0) { | ||
1107 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
1108 | req_p, reply_p); | ||
1109 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1110 | goto destroy; | ||
1111 | |||
1112 | ret = my_handle_response_no_data(dev_p, req_p, | ||
1113 | reply_p); | ||
1114 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1115 | dev_p->is_storage_only_mode = cy_false; | ||
1116 | return ret; | ||
1117 | } else { | ||
1118 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1119 | CY_FUNCT_CB_MTP_STOP_STORAGE_ONLY, 0, | ||
1120 | dev_p->func_cbs_mtp, CY_AS_REQUEST_RESPONSE_EX, | ||
1121 | req_p, reply_p, cy_as_mtp_func_callback); | ||
1122 | |||
1123 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1124 | goto destroy; | ||
1125 | |||
1126 | return ret; | ||
1127 | } | ||
1128 | |||
1129 | destroy: | ||
1130 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1131 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1132 | |||
1133 | return ret; | ||
1134 | } | ||
1135 | EXPORT_SYMBOL(cy_as_mtp_storage_only_stop); | ||
1136 | |||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasstorage.c b/drivers/staging/westbridge/astoria/api/src/cyasstorage.c deleted file mode 100644 index 7abd6a35e828..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasstorage.c +++ /dev/null | |||
@@ -1,4125 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyasstorage.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Storage Design | ||
24 | * | ||
25 | * The storage module is fairly straight forward once the | ||
26 | * DMA and LOWLEVEL modules have been designed. The | ||
27 | * storage module simple takes requests from the user, queues | ||
28 | * the associated DMA requests for action, and then sends | ||
29 | * the low level requests to the West Bridge firmware. | ||
30 | * | ||
31 | */ | ||
32 | |||
33 | #include "../../include/linux/westbridge/cyashal.h" | ||
34 | #include "../../include/linux/westbridge/cyasstorage.h" | ||
35 | #include "../../include/linux/westbridge/cyaserr.h" | ||
36 | #include "../../include/linux/westbridge/cyasdevice.h" | ||
37 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
38 | #include "../../include/linux/westbridge/cyasdma.h" | ||
39 | #include "../../include/linux/westbridge/cyasregs.h" | ||
40 | |||
41 | /* Map a pre-V1.2 media type to the V1.2+ bus number */ | ||
42 | cy_as_return_status_t | ||
43 | cy_an_map_bus_from_media_type(cy_as_device *dev_p, | ||
44 | cy_as_media_type type, cy_as_bus_number_t *bus) | ||
45 | { | ||
46 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
47 | uint8_t code = (uint8_t)(1 << type); | ||
48 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
49 | return CY_AS_ERROR_INVALID_HANDLE; | ||
50 | |||
51 | if (!cy_as_device_is_configured(dev_p)) | ||
52 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
53 | |||
54 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
55 | return CY_AS_ERROR_NO_FIRMWARE; | ||
56 | |||
57 | |||
58 | if (dev_p->media_supported[0] & code) { | ||
59 | if (dev_p->media_supported[1] & code) { | ||
60 | /* | ||
61 | * this media type could be supported on multiple | ||
62 | * buses. so, report an address resolution error. | ||
63 | */ | ||
64 | ret = CY_AS_ERROR_ADDRESS_RESOLUTION_ERROR; | ||
65 | } else | ||
66 | *bus = 0; | ||
67 | } else { | ||
68 | if (dev_p->media_supported[1] & code) | ||
69 | *bus = 1; | ||
70 | else | ||
71 | ret = CY_AS_ERROR_NO_SUCH_MEDIA; | ||
72 | } | ||
73 | |||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | static uint16_t | ||
78 | create_address(cy_as_bus_number_t bus, uint32_t device, uint8_t unit) | ||
79 | { | ||
80 | cy_as_hal_assert(bus >= 0 && bus < CY_AS_MAX_BUSES); | ||
81 | cy_as_hal_assert(device < 16); | ||
82 | |||
83 | return (uint16_t)(((uint8_t)bus << 12) | (device << 8) | unit); | ||
84 | } | ||
85 | |||
86 | cy_as_media_type | ||
87 | cy_as_storage_get_media_from_address(uint16_t v) | ||
88 | { | ||
89 | cy_as_media_type media = cy_as_media_max_media_value; | ||
90 | |||
91 | switch (v & 0xFF) { | ||
92 | case 0x00: | ||
93 | break; | ||
94 | case 0x01: | ||
95 | media = cy_as_media_nand; | ||
96 | break; | ||
97 | case 0x02: | ||
98 | media = cy_as_media_sd_flash; | ||
99 | break; | ||
100 | case 0x04: | ||
101 | media = cy_as_media_mmc_flash; | ||
102 | break; | ||
103 | case 0x08: | ||
104 | media = cy_as_media_ce_ata; | ||
105 | break; | ||
106 | case 0x10: | ||
107 | media = cy_as_media_sdio; | ||
108 | break; | ||
109 | default: | ||
110 | cy_as_hal_assert(0); | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | return media; | ||
115 | } | ||
116 | |||
117 | cy_as_bus_number_t | ||
118 | cy_as_storage_get_bus_from_address(uint16_t v) | ||
119 | { | ||
120 | cy_as_bus_number_t bus = (cy_as_bus_number_t)((v >> 12) & 0x0f); | ||
121 | cy_as_hal_assert(bus >= 0 && bus < CY_AS_MAX_BUSES); | ||
122 | return bus; | ||
123 | } | ||
124 | |||
125 | uint32_t | ||
126 | cy_as_storage_get_device_from_address(uint16_t v) | ||
127 | { | ||
128 | return (uint32_t)((v >> 8) & 0x0f); | ||
129 | } | ||
130 | |||
131 | static uint8_t | ||
132 | get_unit_from_address(uint16_t v) | ||
133 | { | ||
134 | return (uint8_t)(v & 0xff); | ||
135 | } | ||
136 | |||
137 | static cy_as_return_status_t | ||
138 | cy_as_map_bad_addr(uint16_t val) | ||
139 | { | ||
140 | cy_as_return_status_t ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
141 | |||
142 | switch (val) { | ||
143 | case 0: | ||
144 | ret = CY_AS_ERROR_NO_SUCH_BUS; | ||
145 | break; | ||
146 | case 1: | ||
147 | ret = CY_AS_ERROR_NO_SUCH_DEVICE; | ||
148 | break; | ||
149 | case 2: | ||
150 | ret = CY_AS_ERROR_NO_SUCH_UNIT; | ||
151 | break; | ||
152 | case 3: | ||
153 | ret = CY_AS_ERROR_INVALID_BLOCK; | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | my_storage_request_callback(cy_as_device *dev_p, | ||
162 | uint8_t context, | ||
163 | cy_as_ll_request_response *req_p, | ||
164 | cy_as_ll_request_response *resp_p, | ||
165 | cy_as_return_status_t ret) | ||
166 | { | ||
167 | uint16_t val; | ||
168 | uint16_t addr; | ||
169 | cy_as_bus_number_t bus; | ||
170 | uint32_t device; | ||
171 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
172 | cy_as_dma_end_point *ep_p = NULL; | ||
173 | |||
174 | (void)resp_p; | ||
175 | (void)context; | ||
176 | (void)ret; | ||
177 | |||
178 | switch (cy_as_ll_request_response__get_code(req_p)) { | ||
179 | case CY_RQT_MEDIA_CHANGED: | ||
180 | cy_as_ll_send_status_response(dev_p, | ||
181 | CY_RQT_STORAGE_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
182 | |||
183 | /* Media has either been inserted or removed */ | ||
184 | addr = cy_as_ll_request_response__get_word(req_p, 0); | ||
185 | |||
186 | bus = cy_as_storage_get_bus_from_address(addr); | ||
187 | device = cy_as_storage_get_device_from_address(addr); | ||
188 | |||
189 | /* Clear the entry for this device to force re-query later */ | ||
190 | cy_as_hal_mem_set(&(dev_p->storage_device_info[bus][device]), 0, | ||
191 | sizeof(dev_p->storage_device_info[bus][device])); | ||
192 | |||
193 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
194 | if (dev_p->storage_event_cb_ms) { | ||
195 | if (val == 1) | ||
196 | dev_p->storage_event_cb_ms(h, bus, | ||
197 | device, cy_as_storage_removed, 0); | ||
198 | else | ||
199 | dev_p->storage_event_cb_ms(h, bus, | ||
200 | device, cy_as_storage_inserted, 0); | ||
201 | } else if (dev_p->storage_event_cb) { | ||
202 | if (val == 1) | ||
203 | dev_p->storage_event_cb(h, bus, | ||
204 | cy_as_storage_removed, 0); | ||
205 | else | ||
206 | dev_p->storage_event_cb(h, bus, | ||
207 | cy_as_storage_inserted, 0); | ||
208 | } | ||
209 | |||
210 | break; | ||
211 | |||
212 | case CY_RQT_ANTIOCH_CLAIM: | ||
213 | cy_as_ll_send_status_response(dev_p, | ||
214 | CY_RQT_STORAGE_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
215 | if (dev_p->storage_event_cb || dev_p->storage_event_cb_ms) { | ||
216 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
217 | if (dev_p->storage_event_cb_ms) { | ||
218 | if (val & 0x0100) | ||
219 | dev_p->storage_event_cb_ms(h, 0, 0, | ||
220 | cy_as_storage_antioch, 0); | ||
221 | if (val & 0x0200) | ||
222 | dev_p->storage_event_cb_ms(h, 1, 0, | ||
223 | cy_as_storage_antioch, 0); | ||
224 | } else { | ||
225 | if (val & 0x01) | ||
226 | dev_p->storage_event_cb(h, | ||
227 | cy_as_media_nand, | ||
228 | cy_as_storage_antioch, 0); | ||
229 | if (val & 0x02) | ||
230 | dev_p->storage_event_cb(h, | ||
231 | cy_as_media_sd_flash, | ||
232 | cy_as_storage_antioch, 0); | ||
233 | if (val & 0x04) | ||
234 | dev_p->storage_event_cb(h, | ||
235 | cy_as_media_mmc_flash, | ||
236 | cy_as_storage_antioch, 0); | ||
237 | if (val & 0x08) | ||
238 | dev_p->storage_event_cb(h, | ||
239 | cy_as_media_ce_ata, | ||
240 | cy_as_storage_antioch, 0); | ||
241 | } | ||
242 | } | ||
243 | break; | ||
244 | |||
245 | case CY_RQT_ANTIOCH_RELEASE: | ||
246 | cy_as_ll_send_status_response(dev_p, | ||
247 | CY_RQT_STORAGE_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
248 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
249 | if (dev_p->storage_event_cb_ms) { | ||
250 | if (val & 0x0100) | ||
251 | dev_p->storage_event_cb_ms(h, 0, 0, | ||
252 | cy_as_storage_processor, 0); | ||
253 | if (val & 0x0200) | ||
254 | dev_p->storage_event_cb_ms(h, 1, 0, | ||
255 | cy_as_storage_processor, 0); | ||
256 | } else if (dev_p->storage_event_cb) { | ||
257 | if (val & 0x01) | ||
258 | dev_p->storage_event_cb(h, | ||
259 | cy_as_media_nand, | ||
260 | cy_as_storage_processor, 0); | ||
261 | if (val & 0x02) | ||
262 | dev_p->storage_event_cb(h, | ||
263 | cy_as_media_sd_flash, | ||
264 | cy_as_storage_processor, 0); | ||
265 | if (val & 0x04) | ||
266 | dev_p->storage_event_cb(h, | ||
267 | cy_as_media_mmc_flash, | ||
268 | cy_as_storage_processor, 0); | ||
269 | if (val & 0x08) | ||
270 | dev_p->storage_event_cb(h, | ||
271 | cy_as_media_ce_ata, | ||
272 | cy_as_storage_processor, 0); | ||
273 | } | ||
274 | break; | ||
275 | |||
276 | |||
277 | case CY_RQT_SDIO_INTR: | ||
278 | cy_as_ll_send_status_response(dev_p, | ||
279 | CY_RQT_STORAGE_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
280 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
281 | if (dev_p->storage_event_cb_ms) { | ||
282 | if (val & 0x0100) | ||
283 | dev_p->storage_event_cb_ms(h, 1, 0, | ||
284 | cy_as_sdio_interrupt, 0); | ||
285 | else | ||
286 | dev_p->storage_event_cb_ms(h, 0, 0, | ||
287 | cy_as_sdio_interrupt, 0); | ||
288 | |||
289 | } else if (dev_p->storage_event_cb) { | ||
290 | dev_p->storage_event_cb(h, | ||
291 | cy_as_media_sdio, cy_as_sdio_interrupt, 0); | ||
292 | } | ||
293 | break; | ||
294 | |||
295 | case CY_RQT_P2S_DMA_START: | ||
296 | /* Do the DMA setup for the waiting operation. */ | ||
297 | cy_as_ll_send_status_response(dev_p, | ||
298 | CY_RQT_STORAGE_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
299 | cy_as_device_set_p2s_dma_start_recvd(dev_p); | ||
300 | if (dev_p->storage_oper == cy_as_op_read) { | ||
301 | ep_p = CY_AS_NUM_EP(dev_p, CY_AS_P2S_READ_ENDPOINT); | ||
302 | cy_as_dma_end_point_set_stopped(ep_p); | ||
303 | cy_as_dma_kick_start(dev_p, CY_AS_P2S_READ_ENDPOINT); | ||
304 | } else { | ||
305 | ep_p = CY_AS_NUM_EP(dev_p, CY_AS_P2S_WRITE_ENDPOINT); | ||
306 | cy_as_dma_end_point_set_stopped(ep_p); | ||
307 | cy_as_dma_kick_start(dev_p, CY_AS_P2S_WRITE_ENDPOINT); | ||
308 | } | ||
309 | break; | ||
310 | |||
311 | default: | ||
312 | cy_as_hal_print_message("invalid request received " | ||
313 | "on storage context\n"); | ||
314 | val = req_p->box0; | ||
315 | cy_as_ll_send_data_response(dev_p, CY_RQT_STORAGE_RQT_CONTEXT, | ||
316 | CY_RESP_INVALID_REQUEST, sizeof(val), &val); | ||
317 | break; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | static cy_as_return_status_t | ||
322 | is_storage_active(cy_as_device *dev_p) | ||
323 | { | ||
324 | if (!cy_as_device_is_configured(dev_p)) | ||
325 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
326 | |||
327 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
328 | return CY_AS_ERROR_NO_FIRMWARE; | ||
329 | |||
330 | if (dev_p->storage_count == 0) | ||
331 | return CY_AS_ERROR_NOT_RUNNING; | ||
332 | |||
333 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
334 | return CY_AS_ERROR_IN_SUSPEND; | ||
335 | |||
336 | return CY_AS_ERROR_SUCCESS; | ||
337 | } | ||
338 | |||
339 | static void | ||
340 | cy_as_storage_func_callback(cy_as_device *dev_p, | ||
341 | uint8_t context, | ||
342 | cy_as_ll_request_response *rqt, | ||
343 | cy_as_ll_request_response *resp, | ||
344 | cy_as_return_status_t ret); | ||
345 | |||
346 | static cy_as_return_status_t | ||
347 | my_handle_response_no_data(cy_as_device *dev_p, | ||
348 | cy_as_ll_request_response *req_p, | ||
349 | cy_as_ll_request_response *reply_p) | ||
350 | { | ||
351 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
352 | |||
353 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
354 | CY_RESP_SUCCESS_FAILURE) { | ||
355 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
356 | goto destroy; | ||
357 | } | ||
358 | |||
359 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
360 | |||
361 | destroy: | ||
362 | cy_as_ll_destroy_request(dev_p, req_p); | ||
363 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
364 | |||
365 | return ret; | ||
366 | } | ||
367 | |||
368 | static cy_as_return_status_t | ||
369 | my_handle_response_storage_start(cy_as_device *dev_p, | ||
370 | cy_as_ll_request_response *req_p, | ||
371 | cy_as_ll_request_response *reply_p, | ||
372 | cy_as_return_status_t ret) | ||
373 | { | ||
374 | if (ret != CY_AS_ERROR_SUCCESS) | ||
375 | goto destroy; | ||
376 | |||
377 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
378 | CY_RESP_SUCCESS_FAILURE) { | ||
379 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
380 | goto destroy; | ||
381 | } | ||
382 | |||
383 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
384 | if (dev_p->storage_count > 0 && ret == | ||
385 | CY_AS_ERROR_ALREADY_RUNNING) | ||
386 | ret = CY_AS_ERROR_SUCCESS; | ||
387 | |||
388 | ret = cy_as_dma_enable_end_point(dev_p, | ||
389 | CY_AS_P2S_WRITE_ENDPOINT, cy_true, cy_as_direction_in); | ||
390 | if (ret != CY_AS_ERROR_SUCCESS) | ||
391 | goto destroy; | ||
392 | |||
393 | ret = cy_as_dma_set_max_dma_size(dev_p, | ||
394 | CY_AS_P2S_WRITE_ENDPOINT, CY_AS_STORAGE_EP_SIZE); | ||
395 | if (ret != CY_AS_ERROR_SUCCESS) | ||
396 | goto destroy; | ||
397 | |||
398 | ret = cy_as_dma_enable_end_point(dev_p, | ||
399 | CY_AS_P2S_READ_ENDPOINT, cy_true, cy_as_direction_out); | ||
400 | if (ret != CY_AS_ERROR_SUCCESS) | ||
401 | goto destroy; | ||
402 | |||
403 | ret = cy_as_dma_set_max_dma_size(dev_p, | ||
404 | CY_AS_P2S_READ_ENDPOINT, CY_AS_STORAGE_EP_SIZE); | ||
405 | if (ret != CY_AS_ERROR_SUCCESS) | ||
406 | goto destroy; | ||
407 | |||
408 | cy_as_ll_register_request_callback(dev_p, | ||
409 | CY_RQT_STORAGE_RQT_CONTEXT, my_storage_request_callback); | ||
410 | |||
411 | /* Create the request/response used for storage reads and writes. */ | ||
412 | dev_p->storage_rw_req_p = cy_as_ll_create_request(dev_p, | ||
413 | 0, CY_RQT_STORAGE_RQT_CONTEXT, 5); | ||
414 | if (dev_p->storage_rw_req_p == 0) { | ||
415 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
416 | goto destroy; | ||
417 | } | ||
418 | |||
419 | dev_p->storage_rw_resp_p = cy_as_ll_create_response(dev_p, 5); | ||
420 | if (dev_p->storage_rw_resp_p == 0) { | ||
421 | cy_as_ll_destroy_request(dev_p, dev_p->storage_rw_req_p); | ||
422 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
423 | } | ||
424 | |||
425 | destroy: | ||
426 | cy_as_ll_destroy_request(dev_p, req_p); | ||
427 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
428 | |||
429 | /* Increment the storage count only if | ||
430 | * the above functionality succeeds.*/ | ||
431 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
432 | if (dev_p->storage_count == 0) { | ||
433 | cy_as_hal_mem_set(dev_p->storage_device_info, | ||
434 | 0, sizeof(dev_p->storage_device_info)); | ||
435 | dev_p->is_storage_only_mode = cy_false; | ||
436 | } | ||
437 | |||
438 | dev_p->storage_count++; | ||
439 | } | ||
440 | |||
441 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
442 | |||
443 | return ret; | ||
444 | } | ||
445 | |||
446 | cy_as_return_status_t | ||
447 | cy_as_storage_start(cy_as_device_handle handle, | ||
448 | cy_as_function_callback cb, | ||
449 | uint32_t client) | ||
450 | { | ||
451 | cy_as_ll_request_response *req_p, *reply_p; | ||
452 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
453 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
454 | |||
455 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
456 | return CY_AS_ERROR_INVALID_HANDLE; | ||
457 | |||
458 | if (!cy_as_device_is_configured(dev_p)) | ||
459 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
460 | |||
461 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
462 | return CY_AS_ERROR_NO_FIRMWARE; | ||
463 | |||
464 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
465 | return CY_AS_ERROR_IN_SUSPEND; | ||
466 | |||
467 | if (cy_as_device_is_s_s_s_pending(dev_p)) | ||
468 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
469 | |||
470 | cy_as_device_set_s_s_s_pending(dev_p); | ||
471 | |||
472 | if (dev_p->storage_count == 0) { | ||
473 | /* Create the request to send to the West Bridge device */ | ||
474 | req_p = cy_as_ll_create_request(dev_p, | ||
475 | CY_RQT_START_STORAGE, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
476 | if (req_p == 0) { | ||
477 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
478 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
479 | } | ||
480 | |||
481 | /* Reserve space for the reply, the reply data | ||
482 | * will not exceed one word */ | ||
483 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
484 | if (reply_p == 0) { | ||
485 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
486 | cy_as_ll_destroy_request(dev_p, req_p); | ||
487 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
488 | } | ||
489 | |||
490 | if (cb == 0) { | ||
491 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
492 | req_p, reply_p); | ||
493 | if (ret != CY_AS_ERROR_SUCCESS) | ||
494 | goto destroy; | ||
495 | |||
496 | return my_handle_response_storage_start(dev_p, | ||
497 | req_p, reply_p, ret); | ||
498 | } else { | ||
499 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
500 | CY_FUNCT_CB_STOR_START, 0, dev_p->func_cbs_stor, | ||
501 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
502 | cy_as_storage_func_callback); | ||
503 | |||
504 | if (ret != CY_AS_ERROR_SUCCESS) | ||
505 | goto destroy; | ||
506 | |||
507 | /* The request and response are freed as | ||
508 | * part of the FuncCallback */ | ||
509 | return ret; | ||
510 | } | ||
511 | |||
512 | destroy: | ||
513 | cy_as_ll_destroy_request(dev_p, req_p); | ||
514 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
515 | } else { | ||
516 | dev_p->storage_count++; | ||
517 | if (cb) | ||
518 | cb(handle, ret, client, CY_FUNCT_CB_STOR_START, 0); | ||
519 | } | ||
520 | |||
521 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
522 | |||
523 | return ret; | ||
524 | } | ||
525 | EXPORT_SYMBOL(cy_as_storage_start); | ||
526 | |||
527 | static cy_as_return_status_t | ||
528 | my_handle_response_storage_stop(cy_as_device *dev_p, | ||
529 | cy_as_ll_request_response *req_p, | ||
530 | cy_as_ll_request_response *reply_p, | ||
531 | cy_as_return_status_t ret) | ||
532 | { | ||
533 | if (ret != CY_AS_ERROR_SUCCESS) | ||
534 | goto destroy; | ||
535 | |||
536 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
537 | CY_RESP_SUCCESS_FAILURE) { | ||
538 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
539 | goto destroy; | ||
540 | } | ||
541 | |||
542 | destroy: | ||
543 | cy_as_ll_destroy_request(dev_p, req_p); | ||
544 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
545 | |||
546 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
547 | cy_as_ll_destroy_request(dev_p, dev_p->storage_rw_req_p); | ||
548 | cy_as_ll_destroy_response(dev_p, dev_p->storage_rw_resp_p); | ||
549 | dev_p->storage_count--; | ||
550 | } | ||
551 | |||
552 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
553 | |||
554 | return ret; | ||
555 | } | ||
556 | cy_as_return_status_t | ||
557 | cy_as_storage_stop(cy_as_device_handle handle, | ||
558 | cy_as_function_callback cb, | ||
559 | uint32_t client) | ||
560 | { | ||
561 | cy_as_ll_request_response *req_p , *reply_p; | ||
562 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
563 | |||
564 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
565 | |||
566 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
567 | return CY_AS_ERROR_INVALID_HANDLE; | ||
568 | |||
569 | ret = is_storage_active(dev_p); | ||
570 | if (ret != CY_AS_ERROR_SUCCESS) | ||
571 | return ret; | ||
572 | |||
573 | if (cy_as_device_is_storage_async_pending(dev_p)) | ||
574 | return CY_AS_ERROR_ASYNC_PENDING; | ||
575 | |||
576 | if (cy_as_device_is_s_s_s_pending(dev_p)) | ||
577 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
578 | |||
579 | cy_as_device_set_s_s_s_pending(dev_p); | ||
580 | |||
581 | if (dev_p->storage_count == 1) { | ||
582 | |||
583 | /* Create the request to send to the West Bridge device */ | ||
584 | req_p = cy_as_ll_create_request(dev_p, | ||
585 | CY_RQT_STOP_STORAGE, CY_RQT_STORAGE_RQT_CONTEXT, 0); | ||
586 | if (req_p == 0) { | ||
587 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
588 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
589 | } | ||
590 | |||
591 | /* Reserve space for the reply, the reply data | ||
592 | * will not exceed one word */ | ||
593 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
594 | if (reply_p == 0) { | ||
595 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
596 | cy_as_ll_destroy_request(dev_p, req_p); | ||
597 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
598 | } | ||
599 | |||
600 | if (cb == 0) { | ||
601 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
602 | req_p, reply_p); | ||
603 | if (ret != CY_AS_ERROR_SUCCESS) | ||
604 | goto destroy; | ||
605 | |||
606 | return my_handle_response_storage_stop(dev_p, | ||
607 | req_p, reply_p, ret); | ||
608 | } else { | ||
609 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
610 | CY_FUNCT_CB_STOR_STOP, 0, dev_p->func_cbs_stor, | ||
611 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
612 | cy_as_storage_func_callback); | ||
613 | |||
614 | if (ret != CY_AS_ERROR_SUCCESS) | ||
615 | goto destroy; | ||
616 | |||
617 | /* The request and response are freed | ||
618 | * as part of the MiscFuncCallback */ | ||
619 | return ret; | ||
620 | } | ||
621 | |||
622 | destroy: | ||
623 | cy_as_ll_destroy_request(dev_p, req_p); | ||
624 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
625 | } else if (dev_p->storage_count > 1) { | ||
626 | dev_p->storage_count--; | ||
627 | if (cb) | ||
628 | cb(handle, ret, client, CY_FUNCT_CB_STOR_STOP, 0); | ||
629 | } | ||
630 | |||
631 | cy_as_device_clear_s_s_s_pending(dev_p); | ||
632 | |||
633 | return ret; | ||
634 | } | ||
635 | EXPORT_SYMBOL(cy_as_storage_stop); | ||
636 | |||
637 | cy_as_return_status_t | ||
638 | cy_as_storage_register_callback(cy_as_device_handle handle, | ||
639 | cy_as_storage_event_callback callback) | ||
640 | { | ||
641 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
642 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
643 | return CY_AS_ERROR_INVALID_HANDLE; | ||
644 | |||
645 | if (!cy_as_device_is_configured(dev_p)) | ||
646 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
647 | |||
648 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
649 | return CY_AS_ERROR_NO_FIRMWARE; | ||
650 | |||
651 | if (dev_p->storage_count == 0) | ||
652 | return CY_AS_ERROR_NOT_RUNNING; | ||
653 | |||
654 | dev_p->storage_event_cb = NULL; | ||
655 | dev_p->storage_event_cb_ms = callback; | ||
656 | |||
657 | return CY_AS_ERROR_SUCCESS; | ||
658 | } | ||
659 | EXPORT_SYMBOL(cy_as_storage_register_callback); | ||
660 | |||
661 | |||
662 | static cy_as_return_status_t | ||
663 | my_handle_response_storage_claim(cy_as_device *dev_p, | ||
664 | cy_as_ll_request_response *req_p, | ||
665 | cy_as_ll_request_response *reply_p) | ||
666 | { | ||
667 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
668 | |||
669 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
670 | CY_RESP_NO_SUCH_ADDRESS) { | ||
671 | ret = cy_as_map_bad_addr( | ||
672 | cy_as_ll_request_response__get_word(reply_p, 3)); | ||
673 | goto destroy; | ||
674 | } | ||
675 | |||
676 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
677 | CY_RESP_MEDIA_CLAIMED_RELEASED) { | ||
678 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
679 | goto destroy; | ||
680 | } | ||
681 | |||
682 | /* The response must be about the address I am | ||
683 | * trying to claim or the firmware is broken */ | ||
684 | if ((cy_as_storage_get_bus_from_address( | ||
685 | cy_as_ll_request_response__get_word(req_p, 0)) != | ||
686 | cy_as_storage_get_bus_from_address( | ||
687 | cy_as_ll_request_response__get_word(reply_p, 0))) || | ||
688 | (cy_as_storage_get_device_from_address( | ||
689 | cy_as_ll_request_response__get_word(req_p, 0)) != | ||
690 | cy_as_storage_get_device_from_address( | ||
691 | cy_as_ll_request_response__get_word(reply_p, 0)))) { | ||
692 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
693 | goto destroy; | ||
694 | } | ||
695 | |||
696 | if (cy_as_ll_request_response__get_word(reply_p, 1) != 1) | ||
697 | ret = CY_AS_ERROR_NOT_ACQUIRED; | ||
698 | |||
699 | destroy: | ||
700 | cy_as_ll_destroy_request(dev_p, req_p); | ||
701 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
702 | |||
703 | return ret; | ||
704 | } | ||
705 | |||
706 | static cy_as_return_status_t | ||
707 | my_storage_claim(cy_as_device *dev_p, | ||
708 | void *data, | ||
709 | cy_as_bus_number_t bus, | ||
710 | uint32_t device, | ||
711 | uint16_t req_flags, | ||
712 | cy_as_function_callback cb, | ||
713 | uint32_t client) | ||
714 | { | ||
715 | cy_as_ll_request_response *req_p , *reply_p; | ||
716 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
717 | |||
718 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
719 | return CY_AS_ERROR_INVALID_HANDLE; | ||
720 | |||
721 | ret = is_storage_active(dev_p); | ||
722 | if (ret != CY_AS_ERROR_SUCCESS) | ||
723 | return ret; | ||
724 | |||
725 | if (dev_p->mtp_count > 0) | ||
726 | return CY_AS_ERROR_NOT_VALID_IN_MTP; | ||
727 | |||
728 | /* Create the request to send to the West Bridge device */ | ||
729 | req_p = cy_as_ll_create_request(dev_p, | ||
730 | CY_RQT_CLAIM_STORAGE, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
731 | if (req_p == 0) | ||
732 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
733 | |||
734 | cy_as_ll_request_response__set_word(req_p, | ||
735 | 0, create_address(bus, device, 0)); | ||
736 | |||
737 | /* Reserve space for the reply, the reply data will | ||
738 | * not exceed one word */ | ||
739 | reply_p = cy_as_ll_create_response(dev_p, 4); | ||
740 | if (reply_p == 0) { | ||
741 | cy_as_ll_destroy_request(dev_p, req_p); | ||
742 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
743 | } | ||
744 | |||
745 | if (cb == 0) { | ||
746 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
747 | if (ret != CY_AS_ERROR_SUCCESS) | ||
748 | goto destroy; | ||
749 | |||
750 | return my_handle_response_storage_claim(dev_p, req_p, reply_p); | ||
751 | } else { | ||
752 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
753 | CY_FUNCT_CB_STOR_CLAIM, data, dev_p->func_cbs_stor, | ||
754 | req_flags, req_p, reply_p, | ||
755 | cy_as_storage_func_callback); | ||
756 | |||
757 | if (ret != CY_AS_ERROR_SUCCESS) | ||
758 | goto destroy; | ||
759 | |||
760 | /* The request and response are freed as part of | ||
761 | * the MiscFuncCallback */ | ||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | destroy: | ||
766 | cy_as_ll_destroy_request(dev_p, req_p); | ||
767 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
768 | |||
769 | return ret; | ||
770 | } | ||
771 | |||
772 | cy_as_return_status_t | ||
773 | cy_as_storage_claim(cy_as_device_handle handle, | ||
774 | cy_as_bus_number_t bus, | ||
775 | uint32_t device, | ||
776 | cy_as_function_callback cb, | ||
777 | uint32_t client) | ||
778 | { | ||
779 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
780 | |||
781 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
782 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
783 | |||
784 | return my_storage_claim(dev_p, NULL, bus, device, | ||
785 | CY_AS_REQUEST_RESPONSE_MS, cb, client); | ||
786 | } | ||
787 | EXPORT_SYMBOL(cy_as_storage_claim); | ||
788 | |||
789 | static cy_as_return_status_t | ||
790 | my_handle_response_storage_release(cy_as_device *dev_p, | ||
791 | cy_as_ll_request_response *req_p, | ||
792 | cy_as_ll_request_response *reply_p) | ||
793 | { | ||
794 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
795 | |||
796 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
797 | CY_RESP_NO_SUCH_ADDRESS) { | ||
798 | ret = cy_as_map_bad_addr( | ||
799 | cy_as_ll_request_response__get_word(reply_p, 3)); | ||
800 | goto destroy; | ||
801 | } | ||
802 | |||
803 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
804 | CY_RESP_MEDIA_CLAIMED_RELEASED) { | ||
805 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
806 | goto destroy; | ||
807 | } | ||
808 | |||
809 | /* The response must be about the address I am | ||
810 | * trying to release or the firmware is broken */ | ||
811 | if ((cy_as_storage_get_bus_from_address( | ||
812 | cy_as_ll_request_response__get_word(req_p, 0)) != | ||
813 | cy_as_storage_get_bus_from_address( | ||
814 | cy_as_ll_request_response__get_word(reply_p, 0))) || | ||
815 | (cy_as_storage_get_device_from_address( | ||
816 | cy_as_ll_request_response__get_word(req_p, 0)) != | ||
817 | cy_as_storage_get_device_from_address( | ||
818 | cy_as_ll_request_response__get_word(reply_p, 0)))) { | ||
819 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
820 | goto destroy; | ||
821 | } | ||
822 | |||
823 | |||
824 | if (cy_as_ll_request_response__get_word(reply_p, 1) != 0) | ||
825 | ret = CY_AS_ERROR_NOT_RELEASED; | ||
826 | |||
827 | destroy: | ||
828 | cy_as_ll_destroy_request(dev_p, req_p); | ||
829 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
830 | |||
831 | return ret; | ||
832 | } | ||
833 | |||
834 | static cy_as_return_status_t | ||
835 | my_storage_release(cy_as_device *dev_p, | ||
836 | void *data, | ||
837 | cy_as_bus_number_t bus, | ||
838 | uint32_t device, | ||
839 | uint16_t req_flags, | ||
840 | cy_as_function_callback cb, | ||
841 | uint32_t client) | ||
842 | { | ||
843 | cy_as_ll_request_response *req_p , *reply_p; | ||
844 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
845 | |||
846 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
847 | return CY_AS_ERROR_INVALID_HANDLE; | ||
848 | |||
849 | ret = is_storage_active(dev_p); | ||
850 | if (ret != CY_AS_ERROR_SUCCESS) | ||
851 | return ret; | ||
852 | |||
853 | if (dev_p->mtp_count > 0) | ||
854 | return CY_AS_ERROR_NOT_VALID_IN_MTP; | ||
855 | |||
856 | /* Create the request to send to the West Bridge device */ | ||
857 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_RELEASE_STORAGE, | ||
858 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
859 | if (req_p == 0) | ||
860 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
861 | |||
862 | cy_as_ll_request_response__set_word( | ||
863 | req_p, 0, create_address(bus, device, 0)); | ||
864 | |||
865 | /* Reserve space for the reply, the reply | ||
866 | * data will not exceed one word */ | ||
867 | reply_p = cy_as_ll_create_response(dev_p, 4); | ||
868 | if (reply_p == 0) { | ||
869 | cy_as_ll_destroy_request(dev_p, req_p); | ||
870 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
871 | } | ||
872 | |||
873 | if (cb == 0) { | ||
874 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
875 | if (ret != CY_AS_ERROR_SUCCESS) | ||
876 | goto destroy; | ||
877 | |||
878 | return my_handle_response_storage_release( | ||
879 | dev_p, req_p, reply_p); | ||
880 | } else { | ||
881 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
882 | CY_FUNCT_CB_STOR_RELEASE, data, dev_p->func_cbs_stor, | ||
883 | req_flags, req_p, reply_p, | ||
884 | cy_as_storage_func_callback); | ||
885 | |||
886 | if (ret != CY_AS_ERROR_SUCCESS) | ||
887 | goto destroy; | ||
888 | |||
889 | /* The request and response are freed as | ||
890 | * part of the MiscFuncCallback */ | ||
891 | return ret; | ||
892 | } | ||
893 | |||
894 | destroy: | ||
895 | cy_as_ll_destroy_request(dev_p, req_p); | ||
896 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
897 | |||
898 | return ret; | ||
899 | } | ||
900 | |||
901 | cy_as_return_status_t | ||
902 | cy_as_storage_release(cy_as_device_handle handle, | ||
903 | cy_as_bus_number_t bus, | ||
904 | uint32_t device, | ||
905 | cy_as_function_callback cb, | ||
906 | uint32_t client) | ||
907 | { | ||
908 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
909 | |||
910 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
911 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
912 | |||
913 | return my_storage_release(dev_p, NULL, bus, device, | ||
914 | CY_AS_REQUEST_RESPONSE_MS, cb, client); | ||
915 | } | ||
916 | EXPORT_SYMBOL(cy_as_storage_release); | ||
917 | |||
918 | static cy_as_return_status_t | ||
919 | my_handle_response_storage_query_bus(cy_as_device *dev_p, | ||
920 | cy_as_ll_request_response *req_p, | ||
921 | cy_as_ll_request_response *reply_p, | ||
922 | uint32_t *count) | ||
923 | { | ||
924 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
925 | uint8_t code = cy_as_ll_request_response__get_code(reply_p); | ||
926 | uint16_t v; | ||
927 | |||
928 | if (code == CY_RESP_NO_SUCH_ADDRESS) { | ||
929 | ret = CY_AS_ERROR_NO_SUCH_BUS; | ||
930 | goto destroy; | ||
931 | } | ||
932 | |||
933 | if (code != CY_RESP_BUS_DESCRIPTOR) { | ||
934 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
935 | goto destroy; | ||
936 | } | ||
937 | |||
938 | /* | ||
939 | * verify that the response corresponds to the bus that was queried. | ||
940 | */ | ||
941 | if (cy_as_storage_get_bus_from_address( | ||
942 | cy_as_ll_request_response__get_word(req_p, 0)) != | ||
943 | cy_as_storage_get_bus_from_address( | ||
944 | cy_as_ll_request_response__get_word(reply_p, 0))) { | ||
945 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
946 | goto destroy; | ||
947 | } | ||
948 | |||
949 | v = cy_as_ll_request_response__get_word(reply_p, 1); | ||
950 | if (req_p->flags & CY_AS_REQUEST_RESPONSE_MS) { | ||
951 | /* | ||
952 | * this request is only for the count of devices | ||
953 | * on the bus. there is no need to check the media type. | ||
954 | */ | ||
955 | if (v) | ||
956 | *count = 1; | ||
957 | else | ||
958 | *count = 0; | ||
959 | } else { | ||
960 | /* | ||
961 | * this request is for the count of devices of a | ||
962 | * particular type. we need to check whether the media | ||
963 | * type found matches the queried type. | ||
964 | */ | ||
965 | cy_as_media_type queried = (cy_as_media_type) | ||
966 | cy_as_ll_request_response__get_word(req_p, 1); | ||
967 | cy_as_media_type found = | ||
968 | cy_as_storage_get_media_from_address(v); | ||
969 | |||
970 | if (queried == found) | ||
971 | *count = 1; | ||
972 | else | ||
973 | *count = 0; | ||
974 | } | ||
975 | |||
976 | destroy: | ||
977 | cy_as_ll_destroy_request(dev_p, req_p); | ||
978 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
979 | |||
980 | return ret; | ||
981 | } | ||
982 | |||
983 | cy_as_return_status_t | ||
984 | my_storage_query_bus(cy_as_device *dev_p, | ||
985 | cy_as_bus_number_t bus, | ||
986 | cy_as_media_type type, | ||
987 | uint16_t req_flags, | ||
988 | uint32_t *count, | ||
989 | cy_as_function_callback cb, | ||
990 | uint32_t client) | ||
991 | { | ||
992 | cy_as_return_status_t ret; | ||
993 | cy_as_ll_request_response *req_p, *reply_p; | ||
994 | cy_as_funct_c_b_type cb_type = CY_FUNCT_CB_STOR_QUERYBUS; | ||
995 | |||
996 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
997 | return CY_AS_ERROR_INVALID_HANDLE; | ||
998 | |||
999 | ret = is_storage_active(dev_p); | ||
1000 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1001 | return ret; | ||
1002 | |||
1003 | /* Create the request to send to the Antioch device */ | ||
1004 | req_p = cy_as_ll_create_request(dev_p, | ||
1005 | CY_RQT_QUERY_BUS, CY_RQT_STORAGE_RQT_CONTEXT, 2); | ||
1006 | if (req_p == 0) | ||
1007 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1008 | |||
1009 | cy_as_ll_request_response__set_word(req_p, | ||
1010 | 0, create_address(bus, 0, 0)); | ||
1011 | cy_as_ll_request_response__set_word(req_p, 1, (uint16_t)type); | ||
1012 | |||
1013 | /* Reserve space for the reply, the reply data | ||
1014 | * will not exceed two words. */ | ||
1015 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
1016 | if (reply_p == 0) { | ||
1017 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1018 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1019 | } | ||
1020 | |||
1021 | if (cb == 0) { | ||
1022 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
1023 | req_p, reply_p); | ||
1024 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1025 | goto destroy; | ||
1026 | |||
1027 | req_p->flags |= req_flags; | ||
1028 | return my_handle_response_storage_query_bus(dev_p, | ||
1029 | req_p, reply_p, count); | ||
1030 | } else { | ||
1031 | if (req_flags == CY_AS_REQUEST_RESPONSE_EX) | ||
1032 | cb_type = CY_FUNCT_CB_STOR_QUERYMEDIA; | ||
1033 | |||
1034 | ret = cy_as_misc_send_request(dev_p, cb, client, cb_type, | ||
1035 | count, dev_p->func_cbs_stor, req_flags, | ||
1036 | req_p, reply_p, cy_as_storage_func_callback); | ||
1037 | |||
1038 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1039 | goto destroy; | ||
1040 | |||
1041 | /* The request and response are freed as part of | ||
1042 | * the MiscFuncCallback */ | ||
1043 | return ret; | ||
1044 | } | ||
1045 | |||
1046 | destroy: | ||
1047 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1048 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1049 | |||
1050 | return ret; | ||
1051 | } | ||
1052 | |||
1053 | cy_as_return_status_t | ||
1054 | cy_as_storage_query_bus(cy_as_device_handle handle, | ||
1055 | cy_as_bus_number_t bus, | ||
1056 | uint32_t *count, | ||
1057 | cy_as_function_callback cb, | ||
1058 | uint32_t client) | ||
1059 | { | ||
1060 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1061 | |||
1062 | return my_storage_query_bus(dev_p, bus, cy_as_media_max_media_value, | ||
1063 | CY_AS_REQUEST_RESPONSE_MS, count, cb, client); | ||
1064 | } | ||
1065 | EXPORT_SYMBOL(cy_as_storage_query_bus); | ||
1066 | |||
1067 | cy_as_return_status_t | ||
1068 | cy_as_storage_query_media(cy_as_device_handle handle, | ||
1069 | cy_as_media_type type, | ||
1070 | uint32_t *count, | ||
1071 | cy_as_function_callback cb, | ||
1072 | uint32_t client) | ||
1073 | { | ||
1074 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1075 | cy_as_bus_number_t bus; | ||
1076 | |||
1077 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1078 | |||
1079 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1080 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1081 | |||
1082 | ret = is_storage_active(dev_p); | ||
1083 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1084 | return ret; | ||
1085 | |||
1086 | ret = cy_an_map_bus_from_media_type(dev_p, type, &bus); | ||
1087 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1088 | return ret; | ||
1089 | |||
1090 | return my_storage_query_bus(dev_p, bus, type, CY_AS_REQUEST_RESPONSE_EX, | ||
1091 | count, cb, client); | ||
1092 | } | ||
1093 | EXPORT_SYMBOL(cy_as_storage_query_media); | ||
1094 | |||
1095 | static cy_as_return_status_t | ||
1096 | my_handle_response_storage_query_device(cy_as_device *dev_p, | ||
1097 | cy_as_ll_request_response *req_p, | ||
1098 | cy_as_ll_request_response *reply_p, | ||
1099 | void *data_p) | ||
1100 | { | ||
1101 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1102 | uint16_t v; | ||
1103 | cy_as_bus_number_t bus; | ||
1104 | cy_as_media_type type; | ||
1105 | uint32_t device; | ||
1106 | cy_bool removable; | ||
1107 | cy_bool writeable; | ||
1108 | cy_bool locked; | ||
1109 | uint16_t block_size; | ||
1110 | uint32_t number_units; | ||
1111 | uint32_t number_eus; | ||
1112 | |||
1113 | if (cy_as_ll_request_response__get_code(reply_p) | ||
1114 | == CY_RESP_NO_SUCH_ADDRESS) { | ||
1115 | ret = cy_as_map_bad_addr( | ||
1116 | cy_as_ll_request_response__get_word(reply_p, 3)); | ||
1117 | goto destroy; | ||
1118 | } | ||
1119 | |||
1120 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1121 | CY_RESP_DEVICE_DESCRIPTOR) { | ||
1122 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1123 | goto destroy; | ||
1124 | } | ||
1125 | |||
1126 | /* Unpack the response */ | ||
1127 | v = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1128 | type = cy_as_storage_get_media_from_address(v); | ||
1129 | bus = cy_as_storage_get_bus_from_address(v); | ||
1130 | device = cy_as_storage_get_device_from_address(v); | ||
1131 | |||
1132 | block_size = cy_as_ll_request_response__get_word(reply_p, 1); | ||
1133 | |||
1134 | v = cy_as_ll_request_response__get_word(reply_p, 2); | ||
1135 | removable = (v & 0x8000) ? cy_true : cy_false; | ||
1136 | writeable = (v & 0x0100) ? cy_true : cy_false; | ||
1137 | locked = (v & 0x0200) ? cy_true : cy_false; | ||
1138 | number_units = (v & 0xff); | ||
1139 | |||
1140 | number_eus = (cy_as_ll_request_response__get_word(reply_p, 3) << 16) | ||
1141 | | cy_as_ll_request_response__get_word(reply_p, 4); | ||
1142 | |||
1143 | /* Store the results based on the version of originating function */ | ||
1144 | if (req_p->flags & CY_AS_REQUEST_RESPONSE_MS) { | ||
1145 | cy_as_storage_query_device_data *store_p = | ||
1146 | (cy_as_storage_query_device_data *)data_p; | ||
1147 | |||
1148 | /* Make sure the response is about the address we asked | ||
1149 | * about - if not, firmware error */ | ||
1150 | if ((bus != store_p->bus) || (device != store_p->device)) { | ||
1151 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1152 | goto destroy; | ||
1153 | } | ||
1154 | |||
1155 | store_p->desc_p.type = type; | ||
1156 | store_p->desc_p.removable = removable; | ||
1157 | store_p->desc_p.writeable = writeable; | ||
1158 | store_p->desc_p.block_size = block_size; | ||
1159 | store_p->desc_p.number_units = number_units; | ||
1160 | store_p->desc_p.locked = locked; | ||
1161 | store_p->desc_p.erase_unit_size = number_eus; | ||
1162 | dev_p->storage_device_info[bus][device] = store_p->desc_p; | ||
1163 | } else { | ||
1164 | cy_as_storage_query_device_data_dep *store_p = | ||
1165 | (cy_as_storage_query_device_data_dep *)data_p; | ||
1166 | |||
1167 | /* Make sure the response is about the address we asked | ||
1168 | * about - if not, firmware error */ | ||
1169 | if ((type != store_p->type) || (device != store_p->device)) { | ||
1170 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1171 | goto destroy; | ||
1172 | } | ||
1173 | |||
1174 | store_p->desc_p.type = type; | ||
1175 | store_p->desc_p.removable = removable; | ||
1176 | store_p->desc_p.writeable = writeable; | ||
1177 | store_p->desc_p.block_size = block_size; | ||
1178 | store_p->desc_p.number_units = number_units; | ||
1179 | store_p->desc_p.locked = locked; | ||
1180 | store_p->desc_p.erase_unit_size = number_eus; | ||
1181 | dev_p->storage_device_info[bus][device] = store_p->desc_p; | ||
1182 | } | ||
1183 | |||
1184 | destroy: | ||
1185 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1186 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1187 | |||
1188 | return ret; | ||
1189 | } | ||
1190 | |||
1191 | static cy_as_return_status_t | ||
1192 | my_storage_query_device(cy_as_device *dev_p, | ||
1193 | void *data_p, | ||
1194 | uint16_t req_flags, | ||
1195 | cy_as_bus_number_t bus, | ||
1196 | uint32_t device, | ||
1197 | cy_as_function_callback cb, | ||
1198 | uint32_t client) | ||
1199 | { | ||
1200 | cy_as_ll_request_response *req_p , *reply_p; | ||
1201 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1202 | |||
1203 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1204 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1205 | |||
1206 | ret = is_storage_active(dev_p); | ||
1207 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1208 | return ret; | ||
1209 | |||
1210 | /* Create the request to send to the Antioch device */ | ||
1211 | req_p = cy_as_ll_create_request(dev_p, | ||
1212 | CY_RQT_QUERY_DEVICE, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
1213 | if (req_p == 0) | ||
1214 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1215 | |||
1216 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1217 | create_address(bus, device, 0)); | ||
1218 | |||
1219 | /* Reserve space for the reply, the reply data | ||
1220 | * will not exceed five words. */ | ||
1221 | reply_p = cy_as_ll_create_response(dev_p, 5); | ||
1222 | if (reply_p == 0) { | ||
1223 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1224 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1225 | } | ||
1226 | |||
1227 | if (cb == 0) { | ||
1228 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1229 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1230 | goto destroy; | ||
1231 | |||
1232 | req_p->flags |= req_flags; | ||
1233 | return my_handle_response_storage_query_device(dev_p, | ||
1234 | req_p, reply_p, data_p); | ||
1235 | } else { | ||
1236 | |||
1237 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1238 | CY_FUNCT_CB_STOR_QUERYDEVICE, data_p, | ||
1239 | dev_p->func_cbs_stor, req_flags, req_p, | ||
1240 | reply_p, cy_as_storage_func_callback); | ||
1241 | |||
1242 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1243 | goto destroy; | ||
1244 | |||
1245 | /* The request and response are freed as part of the | ||
1246 | * MiscFuncCallback */ | ||
1247 | return ret; | ||
1248 | } | ||
1249 | |||
1250 | destroy: | ||
1251 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1252 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1253 | |||
1254 | return ret; | ||
1255 | } | ||
1256 | |||
1257 | cy_as_return_status_t | ||
1258 | cy_as_storage_query_device(cy_as_device_handle handle, | ||
1259 | cy_as_storage_query_device_data *data_p, | ||
1260 | cy_as_function_callback cb, | ||
1261 | uint32_t client) | ||
1262 | { | ||
1263 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1264 | return my_storage_query_device(dev_p, data_p, | ||
1265 | CY_AS_REQUEST_RESPONSE_MS, data_p->bus, | ||
1266 | data_p->device, cb, client); | ||
1267 | } | ||
1268 | EXPORT_SYMBOL(cy_as_storage_query_device); | ||
1269 | |||
1270 | static cy_as_return_status_t | ||
1271 | my_handle_response_storage_query_unit(cy_as_device *dev_p, | ||
1272 | cy_as_ll_request_response *req_p, | ||
1273 | cy_as_ll_request_response *reply_p, | ||
1274 | void *data_p) | ||
1275 | { | ||
1276 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1277 | cy_as_bus_number_t bus; | ||
1278 | uint32_t device; | ||
1279 | uint32_t unit; | ||
1280 | cy_as_media_type type; | ||
1281 | uint16_t block_size; | ||
1282 | uint32_t start_block; | ||
1283 | uint32_t unit_size; | ||
1284 | uint16_t v; | ||
1285 | |||
1286 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
1287 | CY_RESP_NO_SUCH_ADDRESS) { | ||
1288 | ret = cy_as_map_bad_addr( | ||
1289 | cy_as_ll_request_response__get_word(reply_p, 3)); | ||
1290 | goto destroy; | ||
1291 | } | ||
1292 | |||
1293 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1294 | CY_RESP_UNIT_DESCRIPTOR) { | ||
1295 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1296 | goto destroy; | ||
1297 | } | ||
1298 | |||
1299 | /* Unpack the response */ | ||
1300 | v = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1301 | bus = cy_as_storage_get_bus_from_address(v); | ||
1302 | device = cy_as_storage_get_device_from_address(v); | ||
1303 | unit = get_unit_from_address(v); | ||
1304 | |||
1305 | type = cy_as_storage_get_media_from_address( | ||
1306 | cy_as_ll_request_response__get_word(reply_p, 1)); | ||
1307 | |||
1308 | block_size = cy_as_ll_request_response__get_word(reply_p, 2); | ||
1309 | start_block = cy_as_ll_request_response__get_word(reply_p, 3) | ||
1310 | | (cy_as_ll_request_response__get_word(reply_p, 4) << 16); | ||
1311 | unit_size = cy_as_ll_request_response__get_word(reply_p, 5) | ||
1312 | | (cy_as_ll_request_response__get_word(reply_p, 6) << 16); | ||
1313 | |||
1314 | /* Store the results based on the version of | ||
1315 | * originating function */ | ||
1316 | if (req_p->flags & CY_AS_REQUEST_RESPONSE_MS) { | ||
1317 | cy_as_storage_query_unit_data *store_p = | ||
1318 | (cy_as_storage_query_unit_data *)data_p; | ||
1319 | |||
1320 | /* Make sure the response is about the address we | ||
1321 | * asked about - if not, firmware error */ | ||
1322 | if (bus != store_p->bus || device != store_p->device || | ||
1323 | unit != store_p->unit) { | ||
1324 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1325 | goto destroy; | ||
1326 | } | ||
1327 | |||
1328 | store_p->desc_p.type = type; | ||
1329 | store_p->desc_p.block_size = block_size; | ||
1330 | store_p->desc_p.start_block = start_block; | ||
1331 | store_p->desc_p.unit_size = unit_size; | ||
1332 | } else { | ||
1333 | cy_as_storage_query_unit_data_dep *store_p = | ||
1334 | (cy_as_storage_query_unit_data_dep *)data_p; | ||
1335 | |||
1336 | /* Make sure the response is about the media type we asked | ||
1337 | * about - if not, firmware error */ | ||
1338 | if ((type != store_p->type) || (device != store_p->device) || | ||
1339 | (unit != store_p->unit)) { | ||
1340 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1341 | goto destroy; | ||
1342 | } | ||
1343 | |||
1344 | store_p->desc_p.type = type; | ||
1345 | store_p->desc_p.block_size = block_size; | ||
1346 | store_p->desc_p.start_block = start_block; | ||
1347 | store_p->desc_p.unit_size = unit_size; | ||
1348 | } | ||
1349 | |||
1350 | dev_p->storage_device_info[bus][device].type = type; | ||
1351 | dev_p->storage_device_info[bus][device].block_size = block_size; | ||
1352 | |||
1353 | destroy: | ||
1354 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1355 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1356 | |||
1357 | return ret; | ||
1358 | } | ||
1359 | |||
1360 | static cy_as_return_status_t | ||
1361 | my_storage_query_unit(cy_as_device *dev_p, | ||
1362 | void *data_p, | ||
1363 | uint16_t req_flags, | ||
1364 | cy_as_bus_number_t bus, | ||
1365 | uint32_t device, | ||
1366 | uint32_t unit, | ||
1367 | cy_as_function_callback cb, | ||
1368 | uint32_t client) | ||
1369 | { | ||
1370 | cy_as_ll_request_response *req_p , *reply_p; | ||
1371 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1372 | |||
1373 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1374 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1375 | |||
1376 | ret = is_storage_active(dev_p); | ||
1377 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1378 | return ret; | ||
1379 | |||
1380 | /* Create the request to send to the West Bridge device */ | ||
1381 | req_p = cy_as_ll_create_request(dev_p, | ||
1382 | CY_RQT_QUERY_UNIT, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
1383 | if (req_p == 0) | ||
1384 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1385 | |||
1386 | if (device > 255) | ||
1387 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
1388 | |||
1389 | if (unit > 255) | ||
1390 | return CY_AS_ERROR_NO_SUCH_UNIT; | ||
1391 | |||
1392 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1393 | create_address(bus, device, (uint8_t)unit)); | ||
1394 | |||
1395 | /* Reserve space for the reply, the reply data | ||
1396 | * will be of seven words. */ | ||
1397 | reply_p = cy_as_ll_create_response(dev_p, 7); | ||
1398 | if (reply_p == 0) { | ||
1399 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1400 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1401 | } | ||
1402 | |||
1403 | if (cb == 0) { | ||
1404 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1405 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1406 | goto destroy; | ||
1407 | |||
1408 | req_p->flags |= req_flags; | ||
1409 | return my_handle_response_storage_query_unit(dev_p, | ||
1410 | req_p, reply_p, data_p); | ||
1411 | } else { | ||
1412 | |||
1413 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1414 | CY_FUNCT_CB_STOR_QUERYUNIT, data_p, | ||
1415 | dev_p->func_cbs_stor, req_flags, req_p, reply_p, | ||
1416 | cy_as_storage_func_callback); | ||
1417 | |||
1418 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1419 | goto destroy; | ||
1420 | |||
1421 | /* The request and response are freed | ||
1422 | * as part of the MiscFuncCallback */ | ||
1423 | return ret; | ||
1424 | } | ||
1425 | |||
1426 | destroy: | ||
1427 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1428 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1429 | |||
1430 | return ret; | ||
1431 | } | ||
1432 | |||
1433 | cy_as_return_status_t | ||
1434 | cy_as_storage_query_unit(cy_as_device_handle handle, | ||
1435 | cy_as_storage_query_unit_data *data_p, | ||
1436 | cy_as_function_callback cb, | ||
1437 | uint32_t client) | ||
1438 | { | ||
1439 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1440 | return my_storage_query_unit(dev_p, data_p, CY_AS_REQUEST_RESPONSE_MS, | ||
1441 | data_p->bus, data_p->device, data_p->unit, cb, client); | ||
1442 | } | ||
1443 | EXPORT_SYMBOL(cy_as_storage_query_unit); | ||
1444 | |||
1445 | static cy_as_return_status_t | ||
1446 | cy_as_get_block_size(cy_as_device *dev_p, | ||
1447 | cy_as_bus_number_t bus, | ||
1448 | uint32_t device, | ||
1449 | cy_as_function_callback cb) | ||
1450 | { | ||
1451 | cy_as_ll_request_response *req_p , *reply_p; | ||
1452 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1453 | |||
1454 | /* Create the request to send to the West Bridge device */ | ||
1455 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_QUERY_DEVICE, | ||
1456 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
1457 | if (req_p == 0) | ||
1458 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1459 | |||
1460 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1461 | create_address(bus, device, 0)); | ||
1462 | |||
1463 | reply_p = cy_as_ll_create_response(dev_p, 4); | ||
1464 | if (reply_p == 0) { | ||
1465 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1466 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1467 | } | ||
1468 | |||
1469 | if (cb == 0) { | ||
1470 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1471 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1472 | goto destroy; | ||
1473 | |||
1474 | if (cy_as_ll_request_response__get_code(reply_p) | ||
1475 | == CY_RESP_NO_SUCH_ADDRESS) { | ||
1476 | ret = CY_AS_ERROR_NO_SUCH_BUS; | ||
1477 | goto destroy; | ||
1478 | } | ||
1479 | |||
1480 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1481 | CY_RESP_DEVICE_DESCRIPTOR) { | ||
1482 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1483 | goto destroy; | ||
1484 | } | ||
1485 | |||
1486 | /* Make sure the response is about the media type we asked | ||
1487 | * about - if not, firmware error */ | ||
1488 | if ((cy_as_storage_get_bus_from_address | ||
1489 | (cy_as_ll_request_response__get_word(reply_p, 0)) | ||
1490 | != bus) || (cy_as_storage_get_device_from_address | ||
1491 | (cy_as_ll_request_response__get_word(reply_p, 0)) | ||
1492 | != device)) { | ||
1493 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1494 | goto destroy; | ||
1495 | } | ||
1496 | |||
1497 | |||
1498 | dev_p->storage_device_info[bus][device].block_size = | ||
1499 | cy_as_ll_request_response__get_word(reply_p, 1); | ||
1500 | } else | ||
1501 | ret = CY_AS_ERROR_INVALID_REQUEST; | ||
1502 | |||
1503 | destroy: | ||
1504 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1505 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1506 | |||
1507 | return ret; | ||
1508 | } | ||
1509 | |||
1510 | cy_as_return_status_t | ||
1511 | my_storage_device_control( | ||
1512 | cy_as_device *dev_p, | ||
1513 | cy_as_bus_number_t bus, | ||
1514 | uint32_t device, | ||
1515 | cy_bool card_detect_en, | ||
1516 | cy_bool write_prot_en, | ||
1517 | cy_as_storage_card_detect config_detect, | ||
1518 | cy_as_function_callback cb, | ||
1519 | uint32_t client) | ||
1520 | { | ||
1521 | cy_as_ll_request_response *req_p , *reply_p; | ||
1522 | cy_as_return_status_t ret; | ||
1523 | cy_bool use_gpio = cy_false; | ||
1524 | |||
1525 | (void)device; | ||
1526 | |||
1527 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1528 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1529 | |||
1530 | if (!cy_as_device_is_configured(dev_p)) | ||
1531 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
1532 | |||
1533 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
1534 | return CY_AS_ERROR_NO_FIRMWARE; | ||
1535 | |||
1536 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
1537 | return CY_AS_ERROR_IN_SUSPEND; | ||
1538 | |||
1539 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
1540 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
1541 | |||
1542 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
1543 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
1544 | |||
1545 | /* If SD is not supported on the specified bus, | ||
1546 | * then return ERROR */ | ||
1547 | if ((dev_p->media_supported[bus] == 0) || | ||
1548 | (dev_p->media_supported[bus] & (1<<cy_as_media_nand))) | ||
1549 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
1550 | |||
1551 | if (config_detect == cy_as_storage_detect_GPIO) | ||
1552 | use_gpio = cy_true; | ||
1553 | else if (config_detect == cy_as_storage_detect_SDAT_3) | ||
1554 | use_gpio = cy_false; | ||
1555 | else | ||
1556 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
1557 | |||
1558 | /* Create the request to send to the West Bridge device */ | ||
1559 | req_p = cy_as_ll_create_request(dev_p, | ||
1560 | CY_RQT_SD_INTERFACE_CONTROL, CY_RQT_STORAGE_RQT_CONTEXT, 2); | ||
1561 | if (req_p == 0) | ||
1562 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1563 | |||
1564 | cy_as_ll_request_response__set_word(req_p, | ||
1565 | 0, create_address(bus, device, 0)); | ||
1566 | cy_as_ll_request_response__set_word(req_p, | ||
1567 | 1, (((uint16_t)card_detect_en << 8) | | ||
1568 | ((uint16_t)use_gpio << 1) | (uint16_t)write_prot_en)); | ||
1569 | |||
1570 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1571 | if (reply_p == 0) { | ||
1572 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1573 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1574 | } | ||
1575 | |||
1576 | if (cb == 0) { | ||
1577 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1578 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1579 | goto destroy; | ||
1580 | |||
1581 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1582 | CY_RESP_SUCCESS_FAILURE) { | ||
1583 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1584 | goto destroy; | ||
1585 | } | ||
1586 | |||
1587 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1588 | } else { | ||
1589 | |||
1590 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1591 | CY_FUNCT_CB_STOR_DEVICECONTROL, | ||
1592 | 0, dev_p->func_cbs_stor, CY_AS_REQUEST_RESPONSE_EX, | ||
1593 | req_p, reply_p, cy_as_storage_func_callback); | ||
1594 | |||
1595 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1596 | goto destroy; | ||
1597 | |||
1598 | /* The request and response are freed as part of the | ||
1599 | * MiscFuncCallback */ | ||
1600 | return ret; | ||
1601 | } | ||
1602 | destroy: | ||
1603 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1604 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1605 | |||
1606 | return ret; | ||
1607 | } | ||
1608 | |||
1609 | cy_as_return_status_t | ||
1610 | cy_as_storage_device_control(cy_as_device_handle handle, | ||
1611 | cy_as_bus_number_t bus, | ||
1612 | uint32_t device, | ||
1613 | cy_bool card_detect_en, | ||
1614 | cy_bool write_prot_en, | ||
1615 | cy_as_storage_card_detect config_detect, | ||
1616 | cy_as_function_callback cb, | ||
1617 | uint32_t client) | ||
1618 | { | ||
1619 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1620 | |||
1621 | return my_storage_device_control(dev_p, bus, device, card_detect_en, | ||
1622 | write_prot_en, config_detect, cb, client); | ||
1623 | } | ||
1624 | EXPORT_SYMBOL(cy_as_storage_device_control); | ||
1625 | |||
1626 | static void | ||
1627 | cy_as_async_storage_callback(cy_as_device *dev_p, | ||
1628 | cy_as_end_point_number_t ep, void *buf_p, uint32_t size, | ||
1629 | cy_as_return_status_t ret) | ||
1630 | { | ||
1631 | cy_as_storage_callback_dep cb; | ||
1632 | cy_as_storage_callback cb_ms; | ||
1633 | |||
1634 | (void)size; | ||
1635 | (void)buf_p; | ||
1636 | (void)ep; | ||
1637 | |||
1638 | cy_as_device_clear_storage_async_pending(dev_p); | ||
1639 | |||
1640 | /* | ||
1641 | * if the LL request callback has already been called, | ||
1642 | * the user callback has to be called from here. | ||
1643 | */ | ||
1644 | if (!dev_p->storage_wait) { | ||
1645 | cy_as_hal_assert(dev_p->storage_cb != NULL || | ||
1646 | dev_p->storage_cb_ms != NULL); | ||
1647 | cb = dev_p->storage_cb; | ||
1648 | cb_ms = dev_p->storage_cb_ms; | ||
1649 | |||
1650 | dev_p->storage_cb = 0; | ||
1651 | dev_p->storage_cb_ms = 0; | ||
1652 | |||
1653 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1654 | ret = dev_p->storage_error; | ||
1655 | |||
1656 | if (cb_ms) { | ||
1657 | cb_ms((cy_as_device_handle)dev_p, | ||
1658 | dev_p->storage_bus_index, | ||
1659 | dev_p->storage_device_index, | ||
1660 | dev_p->storage_unit, | ||
1661 | dev_p->storage_block_addr, | ||
1662 | dev_p->storage_oper, ret); | ||
1663 | } else { | ||
1664 | cb((cy_as_device_handle)dev_p, | ||
1665 | dev_p->storage_device_info | ||
1666 | [dev_p->storage_bus_index] | ||
1667 | [dev_p->storage_device_index].type, | ||
1668 | dev_p->storage_device_index, | ||
1669 | dev_p->storage_unit, | ||
1670 | dev_p->storage_block_addr, | ||
1671 | dev_p->storage_oper, ret); | ||
1672 | } | ||
1673 | } else | ||
1674 | dev_p->storage_error = ret; | ||
1675 | } | ||
1676 | |||
1677 | static void | ||
1678 | cy_as_async_storage_reply_callback( | ||
1679 | cy_as_device *dev_p, | ||
1680 | uint8_t context, | ||
1681 | cy_as_ll_request_response *rqt, | ||
1682 | cy_as_ll_request_response *resp, | ||
1683 | cy_as_return_status_t ret) | ||
1684 | { | ||
1685 | cy_as_storage_callback_dep cb; | ||
1686 | cy_as_storage_callback cb_ms; | ||
1687 | uint8_t reqtype; | ||
1688 | (void)rqt; | ||
1689 | (void)context; | ||
1690 | |||
1691 | reqtype = cy_as_ll_request_response__get_code(rqt); | ||
1692 | |||
1693 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
1694 | if (cy_as_ll_request_response__get_code(resp) == | ||
1695 | CY_RESP_ANTIOCH_DEFERRED_ERROR) { | ||
1696 | ret = cy_as_ll_request_response__get_word | ||
1697 | (resp, 0) & 0x00FF; | ||
1698 | } else if (cy_as_ll_request_response__get_code(resp) != | ||
1699 | CY_RESP_SUCCESS_FAILURE) { | ||
1700 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1701 | } | ||
1702 | } | ||
1703 | |||
1704 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1705 | if (reqtype == CY_RQT_READ_BLOCK) | ||
1706 | cy_as_dma_cancel(dev_p, | ||
1707 | dev_p->storage_read_endpoint, ret); | ||
1708 | else | ||
1709 | cy_as_dma_cancel(dev_p, | ||
1710 | dev_p->storage_write_endpoint, ret); | ||
1711 | } | ||
1712 | |||
1713 | dev_p->storage_wait = cy_false; | ||
1714 | |||
1715 | /* | ||
1716 | * if the DMA callback has already been called, the | ||
1717 | * user callback has to be called from here. | ||
1718 | */ | ||
1719 | if (!cy_as_device_is_storage_async_pending(dev_p)) { | ||
1720 | cy_as_hal_assert(dev_p->storage_cb != NULL || | ||
1721 | dev_p->storage_cb_ms != NULL); | ||
1722 | cb = dev_p->storage_cb; | ||
1723 | cb_ms = dev_p->storage_cb_ms; | ||
1724 | |||
1725 | dev_p->storage_cb = 0; | ||
1726 | dev_p->storage_cb_ms = 0; | ||
1727 | |||
1728 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1729 | ret = dev_p->storage_error; | ||
1730 | |||
1731 | if (cb_ms) { | ||
1732 | cb_ms((cy_as_device_handle)dev_p, | ||
1733 | dev_p->storage_bus_index, | ||
1734 | dev_p->storage_device_index, | ||
1735 | dev_p->storage_unit, | ||
1736 | dev_p->storage_block_addr, | ||
1737 | dev_p->storage_oper, ret); | ||
1738 | } else { | ||
1739 | cb((cy_as_device_handle)dev_p, | ||
1740 | dev_p->storage_device_info | ||
1741 | [dev_p->storage_bus_index] | ||
1742 | [dev_p->storage_device_index].type, | ||
1743 | dev_p->storage_device_index, | ||
1744 | dev_p->storage_unit, | ||
1745 | dev_p->storage_block_addr, | ||
1746 | dev_p->storage_oper, ret); | ||
1747 | } | ||
1748 | } else | ||
1749 | dev_p->storage_error = ret; | ||
1750 | } | ||
1751 | |||
1752 | static cy_as_return_status_t | ||
1753 | cy_as_storage_async_oper(cy_as_device *dev_p, cy_as_end_point_number_t ep, | ||
1754 | uint8_t reqtype, uint16_t req_flags, cy_as_bus_number_t bus, | ||
1755 | uint32_t device, uint32_t unit, uint32_t block, void *data_p, | ||
1756 | uint16_t num_blocks, cy_as_storage_callback_dep callback, | ||
1757 | cy_as_storage_callback callback_ms) | ||
1758 | { | ||
1759 | uint32_t mask; | ||
1760 | cy_as_ll_request_response *req_p , *reply_p; | ||
1761 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1762 | |||
1763 | ret = is_storage_active(dev_p); | ||
1764 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1765 | return ret; | ||
1766 | |||
1767 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
1768 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
1769 | |||
1770 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
1771 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
1772 | |||
1773 | if (unit > 255) | ||
1774 | return CY_AS_ERROR_NO_SUCH_UNIT; | ||
1775 | |||
1776 | /* We are supposed to return success if the number of | ||
1777 | * blocks is zero | ||
1778 | */ | ||
1779 | if (num_blocks == 0) { | ||
1780 | if (callback_ms) | ||
1781 | callback_ms((cy_as_device_handle)dev_p, | ||
1782 | bus, device, unit, block, | ||
1783 | ((reqtype == CY_RQT_WRITE_BLOCK) | ||
1784 | ? cy_as_op_write : cy_as_op_read), | ||
1785 | CY_AS_ERROR_SUCCESS); | ||
1786 | else | ||
1787 | callback((cy_as_device_handle)dev_p, | ||
1788 | dev_p->storage_device_info[bus][device].type, | ||
1789 | device, unit, block, | ||
1790 | ((reqtype == CY_RQT_WRITE_BLOCK) ? | ||
1791 | cy_as_op_write : cy_as_op_read), | ||
1792 | CY_AS_ERROR_SUCCESS); | ||
1793 | |||
1794 | return CY_AS_ERROR_SUCCESS; | ||
1795 | } | ||
1796 | |||
1797 | if (dev_p->storage_device_info[bus][device].block_size == 0) | ||
1798 | return CY_AS_ERROR_QUERY_DEVICE_NEEDED; | ||
1799 | |||
1800 | /* | ||
1801 | * since async operations can be triggered by interrupt | ||
1802 | * code, we must insure that we do not get multiple | ||
1803 | * async operations going at one time and protect this | ||
1804 | * test and set operation from interrupts. also need to | ||
1805 | * check for pending async MTP writes | ||
1806 | */ | ||
1807 | mask = cy_as_hal_disable_interrupts(); | ||
1808 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
1809 | (dev_p->storage_wait) || | ||
1810 | (cy_as_device_is_usb_async_pending(dev_p, 6))) { | ||
1811 | cy_as_hal_enable_interrupts(mask); | ||
1812 | return CY_AS_ERROR_ASYNC_PENDING; | ||
1813 | } | ||
1814 | |||
1815 | cy_as_device_set_storage_async_pending(dev_p); | ||
1816 | cy_as_device_clear_p2s_dma_start_recvd(dev_p); | ||
1817 | cy_as_hal_enable_interrupts(mask); | ||
1818 | |||
1819 | /* | ||
1820 | * storage information about the currently outstanding request | ||
1821 | */ | ||
1822 | dev_p->storage_cb = callback; | ||
1823 | dev_p->storage_cb_ms = callback_ms; | ||
1824 | dev_p->storage_bus_index = bus; | ||
1825 | dev_p->storage_device_index = device; | ||
1826 | dev_p->storage_unit = unit; | ||
1827 | dev_p->storage_block_addr = block; | ||
1828 | |||
1829 | /* Initialise the request to send to the West Bridge. */ | ||
1830 | req_p = dev_p->storage_rw_req_p; | ||
1831 | cy_as_ll_init_request(req_p, reqtype, CY_RQT_STORAGE_RQT_CONTEXT, 5); | ||
1832 | |||
1833 | /* Initialise the space for reply from the West Bridge. */ | ||
1834 | reply_p = dev_p->storage_rw_resp_p; | ||
1835 | cy_as_ll_init_response(reply_p, 5); | ||
1836 | |||
1837 | /* Remember which version of the API originated the request */ | ||
1838 | req_p->flags |= req_flags; | ||
1839 | |||
1840 | /* Setup the DMA request and adjust the storage | ||
1841 | * operation if we are reading */ | ||
1842 | if (reqtype == CY_RQT_READ_BLOCK) { | ||
1843 | ret = cy_as_dma_queue_request(dev_p, ep, data_p, | ||
1844 | dev_p->storage_device_info[bus][device].block_size | ||
1845 | * num_blocks, cy_false, cy_true, | ||
1846 | cy_as_async_storage_callback); | ||
1847 | dev_p->storage_oper = cy_as_op_read; | ||
1848 | } else if (reqtype == CY_RQT_WRITE_BLOCK) { | ||
1849 | ret = cy_as_dma_queue_request(dev_p, ep, data_p, | ||
1850 | dev_p->storage_device_info[bus][device].block_size * | ||
1851 | num_blocks, cy_false, cy_false, | ||
1852 | cy_as_async_storage_callback); | ||
1853 | dev_p->storage_oper = cy_as_op_write; | ||
1854 | } | ||
1855 | |||
1856 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1857 | cy_as_device_clear_storage_async_pending(dev_p); | ||
1858 | return ret; | ||
1859 | } | ||
1860 | |||
1861 | cy_as_ll_request_response__set_word(req_p, | ||
1862 | 0, create_address(bus, (uint8_t)device, (uint8_t)unit)); | ||
1863 | cy_as_ll_request_response__set_word(req_p, | ||
1864 | 1, (uint16_t)((block >> 16) & 0xffff)); | ||
1865 | cy_as_ll_request_response__set_word(req_p, | ||
1866 | 2, (uint16_t)(block & 0xffff)); | ||
1867 | cy_as_ll_request_response__set_word(req_p, | ||
1868 | 3, (uint16_t)((num_blocks >> 8) & 0x00ff)); | ||
1869 | cy_as_ll_request_response__set_word(req_p, | ||
1870 | 4, (uint16_t)((num_blocks << 8) & 0xff00)); | ||
1871 | |||
1872 | /* Set the burst mode flag. */ | ||
1873 | if (dev_p->is_storage_only_mode) | ||
1874 | req_p->data[4] |= 0x0001; | ||
1875 | |||
1876 | /* Send the request and wait for completion | ||
1877 | * of storage request */ | ||
1878 | dev_p->storage_wait = cy_true; | ||
1879 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
1880 | cy_true, cy_as_async_storage_reply_callback); | ||
1881 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1882 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
1883 | cy_as_device_clear_storage_async_pending(dev_p); | ||
1884 | } | ||
1885 | |||
1886 | return ret; | ||
1887 | } | ||
1888 | |||
1889 | static void | ||
1890 | cy_as_sync_storage_callback(cy_as_device *dev_p, | ||
1891 | cy_as_end_point_number_t ep, void *buf_p, | ||
1892 | uint32_t size, cy_as_return_status_t err) | ||
1893 | { | ||
1894 | (void)ep; | ||
1895 | (void)buf_p; | ||
1896 | (void)size; | ||
1897 | |||
1898 | dev_p->storage_error = err; | ||
1899 | } | ||
1900 | |||
1901 | static void | ||
1902 | cy_as_sync_storage_reply_callback( | ||
1903 | cy_as_device *dev_p, | ||
1904 | uint8_t context, | ||
1905 | cy_as_ll_request_response *rqt, | ||
1906 | cy_as_ll_request_response *resp, | ||
1907 | cy_as_return_status_t ret) | ||
1908 | { | ||
1909 | uint8_t reqtype; | ||
1910 | (void)rqt; | ||
1911 | |||
1912 | reqtype = cy_as_ll_request_response__get_code(rqt); | ||
1913 | |||
1914 | if (cy_as_ll_request_response__get_code(resp) == | ||
1915 | CY_RESP_ANTIOCH_DEFERRED_ERROR) { | ||
1916 | ret = cy_as_ll_request_response__get_word(resp, 0) & 0x00FF; | ||
1917 | |||
1918 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1919 | if (reqtype == CY_RQT_READ_BLOCK) | ||
1920 | cy_as_dma_cancel(dev_p, | ||
1921 | dev_p->storage_read_endpoint, ret); | ||
1922 | else | ||
1923 | cy_as_dma_cancel(dev_p, | ||
1924 | dev_p->storage_write_endpoint, ret); | ||
1925 | } | ||
1926 | } else if (cy_as_ll_request_response__get_code(resp) != | ||
1927 | CY_RESP_SUCCESS_FAILURE) { | ||
1928 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1929 | } | ||
1930 | |||
1931 | dev_p->storage_wait = cy_false; | ||
1932 | dev_p->storage_error = ret; | ||
1933 | |||
1934 | /* Wake any threads/processes that are waiting on | ||
1935 | * the read/write completion. */ | ||
1936 | cy_as_hal_wake(&dev_p->context[context]->channel); | ||
1937 | } | ||
1938 | |||
1939 | static cy_as_return_status_t | ||
1940 | cy_as_storage_sync_oper(cy_as_device *dev_p, | ||
1941 | cy_as_end_point_number_t ep, uint8_t reqtype, | ||
1942 | cy_as_bus_number_t bus, uint32_t device, | ||
1943 | uint32_t unit, uint32_t block, void *data_p, | ||
1944 | uint16_t num_blocks) | ||
1945 | { | ||
1946 | cy_as_ll_request_response *req_p , *reply_p; | ||
1947 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1948 | cy_as_context *ctxt_p; | ||
1949 | uint32_t loopcount = 200; | ||
1950 | |||
1951 | ret = is_storage_active(dev_p); | ||
1952 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1953 | return ret; | ||
1954 | |||
1955 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
1956 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
1957 | |||
1958 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
1959 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
1960 | |||
1961 | if (unit > 255) | ||
1962 | return CY_AS_ERROR_NO_SUCH_UNIT; | ||
1963 | |||
1964 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
1965 | (dev_p->storage_wait)) | ||
1966 | return CY_AS_ERROR_ASYNC_PENDING; | ||
1967 | |||
1968 | /* Also need to check for pending Async MTP writes */ | ||
1969 | if (cy_as_device_is_usb_async_pending(dev_p, 6)) | ||
1970 | return CY_AS_ERROR_ASYNC_PENDING; | ||
1971 | |||
1972 | /* We are supposed to return success if the number of | ||
1973 | * blocks is zero | ||
1974 | */ | ||
1975 | if (num_blocks == 0) | ||
1976 | return CY_AS_ERROR_SUCCESS; | ||
1977 | |||
1978 | if (dev_p->storage_device_info[bus][device].block_size == 0) { | ||
1979 | /* | ||
1980 | * normally, a given device has been queried via | ||
1981 | * the query device call before a read request is issued. | ||
1982 | * therefore, this normally will not be run. | ||
1983 | */ | ||
1984 | ret = cy_as_get_block_size(dev_p, bus, device, 0); | ||
1985 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1986 | return ret; | ||
1987 | } | ||
1988 | |||
1989 | /* Initialise the request to send to the West Bridge. */ | ||
1990 | req_p = dev_p->storage_rw_req_p; | ||
1991 | cy_as_ll_init_request(req_p, reqtype, | ||
1992 | CY_RQT_STORAGE_RQT_CONTEXT, 5); | ||
1993 | |||
1994 | /* Initialise the space for reply from | ||
1995 | * the West Bridge. */ | ||
1996 | reply_p = dev_p->storage_rw_resp_p; | ||
1997 | cy_as_ll_init_response(reply_p, 5); | ||
1998 | cy_as_device_clear_p2s_dma_start_recvd(dev_p); | ||
1999 | |||
2000 | /* Setup the DMA request */ | ||
2001 | if (reqtype == CY_RQT_READ_BLOCK) { | ||
2002 | ret = cy_as_dma_queue_request(dev_p, ep, data_p, | ||
2003 | dev_p->storage_device_info[bus][device].block_size * | ||
2004 | num_blocks, cy_false, | ||
2005 | cy_true, cy_as_sync_storage_callback); | ||
2006 | dev_p->storage_oper = cy_as_op_read; | ||
2007 | } else if (reqtype == CY_RQT_WRITE_BLOCK) { | ||
2008 | ret = cy_as_dma_queue_request(dev_p, ep, data_p, | ||
2009 | dev_p->storage_device_info[bus][device].block_size * | ||
2010 | num_blocks, cy_false, cy_false, | ||
2011 | cy_as_sync_storage_callback); | ||
2012 | dev_p->storage_oper = cy_as_op_write; | ||
2013 | } | ||
2014 | |||
2015 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2016 | return ret; | ||
2017 | |||
2018 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2019 | create_address(bus, (uint8_t)device, (uint8_t)unit)); | ||
2020 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2021 | (uint16_t)((block >> 16) & 0xffff)); | ||
2022 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2023 | (uint16_t)(block & 0xffff)); | ||
2024 | cy_as_ll_request_response__set_word(req_p, 3, | ||
2025 | (uint16_t)((num_blocks >> 8) & 0x00ff)); | ||
2026 | cy_as_ll_request_response__set_word(req_p, 4, | ||
2027 | (uint16_t)((num_blocks << 8) & 0xff00)); | ||
2028 | |||
2029 | /* Set the burst mode flag. */ | ||
2030 | if (dev_p->is_storage_only_mode) | ||
2031 | req_p->data[4] |= 0x0001; | ||
2032 | |||
2033 | /* Send the request and wait for | ||
2034 | * completion of storage request */ | ||
2035 | dev_p->storage_wait = cy_true; | ||
2036 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, cy_true, | ||
2037 | cy_as_sync_storage_reply_callback); | ||
2038 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2039 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
2040 | } else { | ||
2041 | /* Setup the DMA request */ | ||
2042 | ctxt_p = dev_p->context[CY_RQT_STORAGE_RQT_CONTEXT]; | ||
2043 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_false); | ||
2044 | |||
2045 | while (loopcount-- > 0) { | ||
2046 | if (dev_p->storage_wait == cy_false) | ||
2047 | break; | ||
2048 | cy_as_hal_sleep_on(&ctxt_p->channel, 10); | ||
2049 | } | ||
2050 | |||
2051 | if (dev_p->storage_wait == cy_true) { | ||
2052 | dev_p->storage_wait = cy_false; | ||
2053 | cy_as_ll_remove_request(dev_p, ctxt_p, req_p, cy_true); | ||
2054 | ret = CY_AS_ERROR_TIMEOUT; | ||
2055 | } | ||
2056 | |||
2057 | if (ret == CY_AS_ERROR_SUCCESS) | ||
2058 | ret = dev_p->storage_error; | ||
2059 | } | ||
2060 | |||
2061 | return ret; | ||
2062 | } | ||
2063 | |||
2064 | cy_as_return_status_t | ||
2065 | cy_as_storage_read(cy_as_device_handle handle, | ||
2066 | cy_as_bus_number_t bus, uint32_t device, | ||
2067 | uint32_t unit, uint32_t block, | ||
2068 | void *data_p, uint16_t num_blocks) | ||
2069 | { | ||
2070 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2071 | |||
2072 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2073 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2074 | |||
2075 | return cy_as_storage_sync_oper(dev_p, dev_p->storage_read_endpoint, | ||
2076 | CY_RQT_READ_BLOCK, bus, device, | ||
2077 | unit, block, data_p, num_blocks); | ||
2078 | } | ||
2079 | EXPORT_SYMBOL(cy_as_storage_read); | ||
2080 | |||
2081 | cy_as_return_status_t | ||
2082 | cy_as_storage_write(cy_as_device_handle handle, | ||
2083 | cy_as_bus_number_t bus, uint32_t device, | ||
2084 | uint32_t unit, uint32_t block, void *data_p, | ||
2085 | uint16_t num_blocks) | ||
2086 | { | ||
2087 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2088 | |||
2089 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2090 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2091 | |||
2092 | if (dev_p->mtp_turbo_active) | ||
2093 | return CY_AS_ERROR_NOT_VALID_DURING_MTP; | ||
2094 | |||
2095 | return cy_as_storage_sync_oper(dev_p, | ||
2096 | dev_p->storage_write_endpoint, | ||
2097 | CY_RQT_WRITE_BLOCK, bus, device, | ||
2098 | unit, block, data_p, num_blocks); | ||
2099 | } | ||
2100 | EXPORT_SYMBOL(cy_as_storage_write); | ||
2101 | |||
2102 | cy_as_return_status_t | ||
2103 | cy_as_storage_read_async(cy_as_device_handle handle, | ||
2104 | cy_as_bus_number_t bus, uint32_t device, uint32_t unit, | ||
2105 | uint32_t block, void *data_p, uint16_t num_blocks, | ||
2106 | cy_as_storage_callback callback) | ||
2107 | { | ||
2108 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2109 | |||
2110 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2111 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2112 | |||
2113 | if (callback == 0) | ||
2114 | return CY_AS_ERROR_NULL_CALLBACK; | ||
2115 | |||
2116 | return cy_as_storage_async_oper(dev_p, | ||
2117 | dev_p->storage_read_endpoint, CY_RQT_READ_BLOCK, | ||
2118 | CY_AS_REQUEST_RESPONSE_MS, bus, device, unit, | ||
2119 | block, data_p, num_blocks, NULL, callback); | ||
2120 | } | ||
2121 | EXPORT_SYMBOL(cy_as_storage_read_async); | ||
2122 | |||
2123 | cy_as_return_status_t | ||
2124 | cy_as_storage_write_async(cy_as_device_handle handle, | ||
2125 | cy_as_bus_number_t bus, uint32_t device, uint32_t unit, | ||
2126 | uint32_t block, void *data_p, uint16_t num_blocks, | ||
2127 | cy_as_storage_callback callback) | ||
2128 | { | ||
2129 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2130 | |||
2131 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2132 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2133 | |||
2134 | if (callback == 0) | ||
2135 | return CY_AS_ERROR_NULL_CALLBACK; | ||
2136 | |||
2137 | if (dev_p->mtp_turbo_active) | ||
2138 | return CY_AS_ERROR_NOT_VALID_DURING_MTP; | ||
2139 | |||
2140 | return cy_as_storage_async_oper(dev_p, | ||
2141 | dev_p->storage_write_endpoint, CY_RQT_WRITE_BLOCK, | ||
2142 | CY_AS_REQUEST_RESPONSE_MS, bus, device, unit, block, | ||
2143 | data_p, num_blocks, NULL, callback); | ||
2144 | } | ||
2145 | EXPORT_SYMBOL(cy_as_storage_write_async); | ||
2146 | |||
2147 | static void | ||
2148 | my_storage_cancel_callback( | ||
2149 | cy_as_device *dev_p, | ||
2150 | uint8_t context, | ||
2151 | cy_as_ll_request_response *rqt, | ||
2152 | cy_as_ll_request_response *resp, | ||
2153 | cy_as_return_status_t stat) | ||
2154 | { | ||
2155 | (void)context; | ||
2156 | (void)stat; | ||
2157 | |||
2158 | /* Nothing to do here, except free up the | ||
2159 | * request and response structures. */ | ||
2160 | cy_as_ll_destroy_response(dev_p, resp); | ||
2161 | cy_as_ll_destroy_request(dev_p, rqt); | ||
2162 | } | ||
2163 | |||
2164 | |||
2165 | cy_as_return_status_t | ||
2166 | cy_as_storage_cancel_async(cy_as_device_handle handle) | ||
2167 | { | ||
2168 | cy_as_return_status_t ret; | ||
2169 | cy_as_ll_request_response *req_p , *reply_p; | ||
2170 | |||
2171 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2172 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2173 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2174 | |||
2175 | ret = is_storage_active(dev_p); | ||
2176 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2177 | return ret; | ||
2178 | |||
2179 | if (!cy_as_device_is_storage_async_pending(dev_p)) | ||
2180 | return CY_AS_ERROR_ASYNC_NOT_PENDING; | ||
2181 | |||
2182 | /* | ||
2183 | * create and send a mailbox request to firmware | ||
2184 | * asking it to abort processing of the current | ||
2185 | * P2S operation. the rest of the cancel processing will be | ||
2186 | * driven through the callbacks for the read/write call. | ||
2187 | */ | ||
2188 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_ABORT_P2S_XFER, | ||
2189 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
2190 | if (req_p == 0) | ||
2191 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2192 | |||
2193 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2194 | if (reply_p == 0) { | ||
2195 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2196 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2197 | } | ||
2198 | |||
2199 | ret = cy_as_ll_send_request(dev_p, req_p, | ||
2200 | reply_p, cy_false, my_storage_cancel_callback); | ||
2201 | if (ret) { | ||
2202 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2203 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2204 | } | ||
2205 | |||
2206 | return CY_AS_ERROR_SUCCESS; | ||
2207 | } | ||
2208 | EXPORT_SYMBOL(cy_as_storage_cancel_async); | ||
2209 | |||
2210 | /* | ||
2211 | * This function does all the API side clean-up associated with | ||
2212 | * CyAsStorageStop, without any communication with the firmware. | ||
2213 | */ | ||
2214 | void cy_as_storage_cleanup(cy_as_device *dev_p) | ||
2215 | { | ||
2216 | if (dev_p->storage_count) { | ||
2217 | cy_as_ll_destroy_request(dev_p, dev_p->storage_rw_req_p); | ||
2218 | cy_as_ll_destroy_response(dev_p, dev_p->storage_rw_resp_p); | ||
2219 | dev_p->storage_count = 0; | ||
2220 | cy_as_device_clear_scsi_messages(dev_p); | ||
2221 | cy_as_hal_mem_set(dev_p->storage_device_info, | ||
2222 | 0, sizeof(dev_p->storage_device_info)); | ||
2223 | |||
2224 | cy_as_device_clear_storage_async_pending(dev_p); | ||
2225 | dev_p->storage_cb = 0; | ||
2226 | dev_p->storage_cb_ms = 0; | ||
2227 | dev_p->storage_wait = cy_false; | ||
2228 | } | ||
2229 | } | ||
2230 | |||
2231 | static cy_as_return_status_t | ||
2232 | my_handle_response_sd_reg_read( | ||
2233 | cy_as_device *dev_p, | ||
2234 | cy_as_ll_request_response *req_p, | ||
2235 | cy_as_ll_request_response *reply_p, | ||
2236 | cy_as_storage_sd_reg_read_data *info) | ||
2237 | { | ||
2238 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2239 | uint8_t resp_type, i; | ||
2240 | uint16_t resp_len; | ||
2241 | uint8_t length = info->length; | ||
2242 | uint8_t *data_p = info->buf_p; | ||
2243 | |||
2244 | resp_type = cy_as_ll_request_response__get_code(reply_p); | ||
2245 | if (resp_type == CY_RESP_SD_REGISTER_DATA) { | ||
2246 | uint16_t *resp_p = reply_p->data + 1; | ||
2247 | uint16_t temp; | ||
2248 | |||
2249 | resp_len = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2250 | cy_as_hal_assert(resp_len >= length); | ||
2251 | |||
2252 | /* | ||
2253 | * copy the values into the output buffer after doing the | ||
2254 | * necessary bit shifting. the bit shifting is required because | ||
2255 | * the data comes out of the west bridge with a 6 bit offset. | ||
2256 | */ | ||
2257 | i = 0; | ||
2258 | while (length) { | ||
2259 | temp = ((resp_p[i] << 6) | (resp_p[i + 1] >> 10)); | ||
2260 | i++; | ||
2261 | |||
2262 | *data_p++ = (uint8_t)(temp >> 8); | ||
2263 | length--; | ||
2264 | |||
2265 | if (length) { | ||
2266 | *data_p++ = (uint8_t)(temp & 0xFF); | ||
2267 | length--; | ||
2268 | } | ||
2269 | } | ||
2270 | } else { | ||
2271 | if (resp_type == CY_RESP_SUCCESS_FAILURE) | ||
2272 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2273 | else | ||
2274 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2275 | } | ||
2276 | |||
2277 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2278 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2279 | |||
2280 | return ret; | ||
2281 | } | ||
2282 | |||
2283 | cy_as_return_status_t | ||
2284 | cy_as_storage_sd_register_read( | ||
2285 | cy_as_device_handle handle, | ||
2286 | cy_as_bus_number_t bus, | ||
2287 | uint8_t device, | ||
2288 | cy_as_sd_card_reg_type reg_type, | ||
2289 | cy_as_storage_sd_reg_read_data *data_p, | ||
2290 | cy_as_function_callback cb, | ||
2291 | uint32_t client) | ||
2292 | { | ||
2293 | cy_as_ll_request_response *req_p , *reply_p; | ||
2294 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2295 | uint8_t length; | ||
2296 | |||
2297 | /* | ||
2298 | * sanity checks required before sending the request to the | ||
2299 | * firmware. | ||
2300 | */ | ||
2301 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2302 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2303 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2304 | |||
2305 | ret = is_storage_active(dev_p); | ||
2306 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2307 | return ret; | ||
2308 | |||
2309 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
2310 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
2311 | |||
2312 | if (reg_type > cy_as_sd_reg_CSD) | ||
2313 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
2314 | |||
2315 | /* If SD/MMC media is not supported on the | ||
2316 | * addressed bus, return error. */ | ||
2317 | if ((dev_p->media_supported[bus] & (1 << cy_as_media_sd_flash)) == 0) | ||
2318 | return CY_AS_ERROR_INVALID_PARAMETER; | ||
2319 | |||
2320 | /* | ||
2321 | * find the amount of data to be returned. this will be the minimum of | ||
2322 | * the actual data length, and the length requested. | ||
2323 | */ | ||
2324 | switch (reg_type) { | ||
2325 | case cy_as_sd_reg_OCR: | ||
2326 | length = CY_AS_SD_REG_OCR_LENGTH; | ||
2327 | break; | ||
2328 | case cy_as_sd_reg_CID: | ||
2329 | length = CY_AS_SD_REG_CID_LENGTH; | ||
2330 | break; | ||
2331 | case cy_as_sd_reg_CSD: | ||
2332 | length = CY_AS_SD_REG_CSD_LENGTH; | ||
2333 | break; | ||
2334 | |||
2335 | default: | ||
2336 | length = 0; | ||
2337 | cy_as_hal_assert(0); | ||
2338 | } | ||
2339 | |||
2340 | if (length < data_p->length) | ||
2341 | data_p->length = length; | ||
2342 | length = data_p->length; | ||
2343 | |||
2344 | /* Create the request to send to the West Bridge device */ | ||
2345 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SD_REGISTER_READ, | ||
2346 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
2347 | if (req_p == 0) | ||
2348 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2349 | |||
2350 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2351 | (create_address(bus, device, 0) | (uint16_t)reg_type)); | ||
2352 | |||
2353 | reply_p = cy_as_ll_create_response(dev_p, | ||
2354 | CY_AS_SD_REG_MAX_RESP_LENGTH); | ||
2355 | if (reply_p == 0) { | ||
2356 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2357 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2358 | } | ||
2359 | |||
2360 | if (cb == 0) { | ||
2361 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2362 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2363 | goto destroy; | ||
2364 | |||
2365 | return my_handle_response_sd_reg_read(dev_p, | ||
2366 | req_p, reply_p, data_p); | ||
2367 | } else { | ||
2368 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2369 | CY_FUNCT_CB_STOR_SDREGISTERREAD, data_p, | ||
2370 | dev_p->func_cbs_stor, CY_AS_REQUEST_RESPONSE_EX, | ||
2371 | req_p, reply_p, cy_as_storage_func_callback); | ||
2372 | |||
2373 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2374 | goto destroy; | ||
2375 | |||
2376 | /* The request and response are freed as part of the | ||
2377 | * MiscFuncCallback */ | ||
2378 | return ret; | ||
2379 | } | ||
2380 | |||
2381 | destroy: | ||
2382 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2383 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2384 | |||
2385 | return ret; | ||
2386 | } | ||
2387 | EXPORT_SYMBOL(cy_as_storage_sd_register_read); | ||
2388 | |||
2389 | cy_as_return_status_t | ||
2390 | cy_as_storage_create_p_partition( | ||
2391 | /* Handle to the device of interest */ | ||
2392 | cy_as_device_handle handle, | ||
2393 | cy_as_bus_number_t bus, | ||
2394 | uint32_t device, | ||
2395 | /* of P-port only partition in blocks */ | ||
2396 | uint32_t size, | ||
2397 | cy_as_function_callback cb, | ||
2398 | uint32_t client) | ||
2399 | { | ||
2400 | cy_as_ll_request_response *req_p, *reply_p; | ||
2401 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2402 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2403 | |||
2404 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2405 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2406 | |||
2407 | ret = is_storage_active(dev_p); | ||
2408 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2409 | return ret; | ||
2410 | |||
2411 | /* Partitions cannot be created or deleted while | ||
2412 | * the USB stack is active. */ | ||
2413 | if (dev_p->usb_count) | ||
2414 | return CY_AS_ERROR_USB_RUNNING; | ||
2415 | |||
2416 | /* Create the request to send to the West Bridge device */ | ||
2417 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_PARTITION_STORAGE, | ||
2418 | CY_RQT_STORAGE_RQT_CONTEXT, 3); | ||
2419 | |||
2420 | if (req_p == 0) | ||
2421 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2422 | |||
2423 | /* Reserve space for the reply, the reply | ||
2424 | * data will not exceed one word */ | ||
2425 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2426 | if (reply_p == 0) { | ||
2427 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2428 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2429 | } | ||
2430 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2431 | create_address(bus, (uint8_t)device, 0x00)); | ||
2432 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2433 | (uint16_t)((size >> 16) & 0xffff)); | ||
2434 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2435 | (uint16_t)(size & 0xffff)); | ||
2436 | |||
2437 | if (cb == 0) { | ||
2438 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2439 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2440 | goto destroy; | ||
2441 | |||
2442 | return my_handle_response_no_data(dev_p, req_p, reply_p); | ||
2443 | } else { | ||
2444 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2445 | CY_FUNCT_CB_STOR_PARTITION, 0, dev_p->func_cbs_stor, | ||
2446 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
2447 | cy_as_storage_func_callback); | ||
2448 | |||
2449 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2450 | goto destroy; | ||
2451 | |||
2452 | /* The request and response are freed as part of the | ||
2453 | * FuncCallback */ | ||
2454 | return ret; | ||
2455 | |||
2456 | } | ||
2457 | |||
2458 | destroy: | ||
2459 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2460 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2461 | |||
2462 | return ret; | ||
2463 | } | ||
2464 | EXPORT_SYMBOL(cy_as_storage_create_p_partition); | ||
2465 | |||
2466 | cy_as_return_status_t | ||
2467 | cy_as_storage_remove_p_partition( | ||
2468 | cy_as_device_handle handle, | ||
2469 | cy_as_bus_number_t bus, | ||
2470 | uint32_t device, | ||
2471 | cy_as_function_callback cb, | ||
2472 | uint32_t client) | ||
2473 | { | ||
2474 | cy_as_ll_request_response *req_p, *reply_p; | ||
2475 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2476 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2477 | |||
2478 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2479 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2480 | |||
2481 | ret = is_storage_active(dev_p); | ||
2482 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2483 | return ret; | ||
2484 | |||
2485 | /* Partitions cannot be created or deleted while | ||
2486 | * the USB stack is active. */ | ||
2487 | if (dev_p->usb_count) | ||
2488 | return CY_AS_ERROR_USB_RUNNING; | ||
2489 | |||
2490 | /* Create the request to send to the West Bridge device */ | ||
2491 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_PARTITION_ERASE, | ||
2492 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
2493 | if (req_p == 0) | ||
2494 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2495 | |||
2496 | /* Reserve space for the reply, the reply | ||
2497 | * data will not exceed one word */ | ||
2498 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2499 | if (reply_p == 0) { | ||
2500 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2501 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2502 | } | ||
2503 | |||
2504 | cy_as_ll_request_response__set_word(req_p, | ||
2505 | 0, create_address(bus, (uint8_t)device, 0x00)); | ||
2506 | |||
2507 | if (cb == 0) { | ||
2508 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2509 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2510 | goto destroy; | ||
2511 | |||
2512 | return my_handle_response_no_data(dev_p, req_p, reply_p); | ||
2513 | } else { | ||
2514 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2515 | CY_FUNCT_CB_NODATA, 0, dev_p->func_cbs_stor, | ||
2516 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
2517 | cy_as_storage_func_callback); | ||
2518 | |||
2519 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2520 | goto destroy; | ||
2521 | |||
2522 | /* The request and response are freed | ||
2523 | * as part of the FuncCallback */ | ||
2524 | return ret; | ||
2525 | |||
2526 | } | ||
2527 | |||
2528 | destroy: | ||
2529 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2530 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2531 | |||
2532 | return ret; | ||
2533 | } | ||
2534 | EXPORT_SYMBOL(cy_as_storage_remove_p_partition); | ||
2535 | |||
2536 | static cy_as_return_status_t | ||
2537 | my_handle_response_get_transfer_amount(cy_as_device *dev_p, | ||
2538 | cy_as_ll_request_response *req_p, | ||
2539 | cy_as_ll_request_response *reply_p, | ||
2540 | cy_as_m_s_c_progress_data *data) | ||
2541 | { | ||
2542 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2543 | uint8_t code = cy_as_ll_request_response__get_code(reply_p); | ||
2544 | uint16_t v1, v2; | ||
2545 | |||
2546 | if (code != CY_RESP_TRANSFER_COUNT) { | ||
2547 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2548 | goto destroy; | ||
2549 | } | ||
2550 | |||
2551 | v1 = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2552 | v2 = cy_as_ll_request_response__get_word(reply_p, 1); | ||
2553 | data->wr_count = (uint32_t)((v1 << 16) | v2); | ||
2554 | |||
2555 | v1 = cy_as_ll_request_response__get_word(reply_p, 2); | ||
2556 | v2 = cy_as_ll_request_response__get_word(reply_p, 3); | ||
2557 | data->rd_count = (uint32_t)((v1 << 16) | v2); | ||
2558 | |||
2559 | destroy: | ||
2560 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2561 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2562 | |||
2563 | return ret; | ||
2564 | } | ||
2565 | |||
2566 | cy_as_return_status_t | ||
2567 | cy_as_storage_get_transfer_amount( | ||
2568 | cy_as_device_handle handle, | ||
2569 | cy_as_bus_number_t bus, | ||
2570 | uint32_t device, | ||
2571 | cy_as_m_s_c_progress_data *data_p, | ||
2572 | cy_as_function_callback cb, | ||
2573 | uint32_t client | ||
2574 | ) | ||
2575 | { | ||
2576 | cy_as_ll_request_response *req_p, *reply_p; | ||
2577 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2578 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2579 | |||
2580 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2581 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2582 | |||
2583 | ret = is_storage_active(dev_p); | ||
2584 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2585 | return ret; | ||
2586 | |||
2587 | /* Check if the firmware image supports this feature. */ | ||
2588 | if ((dev_p->media_supported[0]) && (dev_p->media_supported[0] | ||
2589 | == (1 << cy_as_media_nand))) | ||
2590 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
2591 | |||
2592 | /* Create the request to send to the West Bridge device */ | ||
2593 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_GET_TRANSFER_AMOUNT, | ||
2594 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
2595 | if (req_p == 0) | ||
2596 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2597 | |||
2598 | /* Reserve space for the reply, the reply data | ||
2599 | * will not exceed four words. */ | ||
2600 | reply_p = cy_as_ll_create_response(dev_p, 4); | ||
2601 | if (reply_p == 0) { | ||
2602 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2603 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2604 | } | ||
2605 | |||
2606 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2607 | create_address(bus, (uint8_t)device, 0x00)); | ||
2608 | |||
2609 | if (cb == 0) { | ||
2610 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2611 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2612 | goto destroy; | ||
2613 | |||
2614 | return my_handle_response_get_transfer_amount(dev_p, | ||
2615 | req_p, reply_p, data_p); | ||
2616 | } else { | ||
2617 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2618 | CY_FUNCT_CB_STOR_GETTRANSFERAMOUNT, (void *)data_p, | ||
2619 | dev_p->func_cbs_stor, CY_AS_REQUEST_RESPONSE_EX, | ||
2620 | req_p, reply_p, cy_as_storage_func_callback); | ||
2621 | |||
2622 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2623 | goto destroy; | ||
2624 | |||
2625 | /* The request and response are freed as part of the | ||
2626 | * FuncCallback */ | ||
2627 | return ret; | ||
2628 | } | ||
2629 | |||
2630 | destroy: | ||
2631 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2632 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2633 | |||
2634 | return ret; | ||
2635 | |||
2636 | } | ||
2637 | EXPORT_SYMBOL(cy_as_storage_get_transfer_amount); | ||
2638 | |||
2639 | cy_as_return_status_t | ||
2640 | cy_as_storage_erase( | ||
2641 | cy_as_device_handle handle, | ||
2642 | cy_as_bus_number_t bus, | ||
2643 | uint32_t device, | ||
2644 | uint32_t erase_unit, | ||
2645 | uint16_t num_erase_units, | ||
2646 | cy_as_function_callback cb, | ||
2647 | uint32_t client | ||
2648 | ) | ||
2649 | { | ||
2650 | cy_as_ll_request_response *req_p, *reply_p; | ||
2651 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2652 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2653 | |||
2654 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2655 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2656 | |||
2657 | ret = is_storage_active(dev_p); | ||
2658 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2659 | return ret; | ||
2660 | |||
2661 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
2662 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
2663 | |||
2664 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
2665 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
2666 | |||
2667 | if (dev_p->storage_device_info[bus][device].block_size == 0) | ||
2668 | return CY_AS_ERROR_QUERY_DEVICE_NEEDED; | ||
2669 | |||
2670 | /* If SD is not supported on the specified bus, then return ERROR */ | ||
2671 | if (dev_p->storage_device_info[bus][device].type != | ||
2672 | cy_as_media_sd_flash) | ||
2673 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
2674 | |||
2675 | if (num_erase_units == 0) | ||
2676 | return CY_AS_ERROR_SUCCESS; | ||
2677 | |||
2678 | /* Create the request to send to the West Bridge device */ | ||
2679 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_ERASE, | ||
2680 | CY_RQT_STORAGE_RQT_CONTEXT, 5); | ||
2681 | |||
2682 | if (req_p == 0) | ||
2683 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2684 | |||
2685 | /* Reserve space for the reply, the reply | ||
2686 | * data will not exceed four words. */ | ||
2687 | reply_p = cy_as_ll_create_response(dev_p, 4); | ||
2688 | if (reply_p == 0) { | ||
2689 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2690 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2691 | } | ||
2692 | |||
2693 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2694 | create_address(bus, (uint8_t)device, 0x00)); | ||
2695 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2696 | (uint16_t)((erase_unit >> 16) & 0xffff)); | ||
2697 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2698 | (uint16_t)(erase_unit & 0xffff)); | ||
2699 | cy_as_ll_request_response__set_word(req_p, 3, | ||
2700 | (uint16_t)((num_erase_units >> 8) & 0x00ff)); | ||
2701 | cy_as_ll_request_response__set_word(req_p, 4, | ||
2702 | (uint16_t)((num_erase_units << 8) & 0xff00)); | ||
2703 | |||
2704 | if (cb == 0) { | ||
2705 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2706 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2707 | goto destroy; | ||
2708 | |||
2709 | ret = my_handle_response_no_data(dev_p, req_p, reply_p); | ||
2710 | |||
2711 | /* If error = "invalid response", this (very likely) means | ||
2712 | * that we are not using the SD-only firmware module which | ||
2713 | * is the only one supporting storage_erase. in this case | ||
2714 | * force a "non supported" error code */ | ||
2715 | if (ret == CY_AS_ERROR_INVALID_RESPONSE) | ||
2716 | ret = CY_AS_ERROR_NOT_SUPPORTED; | ||
2717 | |||
2718 | return ret; | ||
2719 | } else { | ||
2720 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2721 | CY_FUNCT_CB_STOR_ERASE, 0, dev_p->func_cbs_stor, | ||
2722 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
2723 | cy_as_storage_func_callback); | ||
2724 | |||
2725 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2726 | goto destroy; | ||
2727 | |||
2728 | /* The request and response are freed | ||
2729 | * as part of the FuncCallback */ | ||
2730 | return ret; | ||
2731 | } | ||
2732 | |||
2733 | destroy: | ||
2734 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2735 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2736 | |||
2737 | return ret; | ||
2738 | } | ||
2739 | EXPORT_SYMBOL(cy_as_storage_erase); | ||
2740 | |||
2741 | static void | ||
2742 | cy_as_storage_func_callback(cy_as_device *dev_p, | ||
2743 | uint8_t context, | ||
2744 | cy_as_ll_request_response *rqt, | ||
2745 | cy_as_ll_request_response *resp, | ||
2746 | cy_as_return_status_t stat) | ||
2747 | { | ||
2748 | cy_as_func_c_b_node *node = (cy_as_func_c_b_node *) | ||
2749 | dev_p->func_cbs_stor->head_p; | ||
2750 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2751 | |||
2752 | cy_bool ex_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_EX) | ||
2753 | == CY_AS_REQUEST_RESPONSE_EX; | ||
2754 | cy_bool ms_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_MS) | ||
2755 | == CY_AS_REQUEST_RESPONSE_MS; | ||
2756 | uint8_t code; | ||
2757 | uint8_t cntxt; | ||
2758 | |||
2759 | cy_as_hal_assert(ex_request || ms_request); | ||
2760 | cy_as_hal_assert(dev_p->func_cbs_stor->count != 0); | ||
2761 | cy_as_hal_assert(dev_p->func_cbs_stor->type == CYAS_FUNC_CB); | ||
2762 | (void) ex_request; | ||
2763 | (void) ms_request; | ||
2764 | |||
2765 | (void)context; | ||
2766 | |||
2767 | cntxt = cy_as_ll_request_response__get_context(rqt); | ||
2768 | cy_as_hal_assert(cntxt == CY_RQT_STORAGE_RQT_CONTEXT); | ||
2769 | |||
2770 | code = cy_as_ll_request_response__get_code(rqt); | ||
2771 | switch (code) { | ||
2772 | case CY_RQT_START_STORAGE: | ||
2773 | ret = my_handle_response_storage_start(dev_p, rqt, resp, stat); | ||
2774 | break; | ||
2775 | case CY_RQT_STOP_STORAGE: | ||
2776 | ret = my_handle_response_storage_stop(dev_p, rqt, resp, stat); | ||
2777 | break; | ||
2778 | case CY_RQT_CLAIM_STORAGE: | ||
2779 | ret = my_handle_response_storage_claim(dev_p, rqt, resp); | ||
2780 | break; | ||
2781 | case CY_RQT_RELEASE_STORAGE: | ||
2782 | ret = my_handle_response_storage_release(dev_p, rqt, resp); | ||
2783 | break; | ||
2784 | case CY_RQT_QUERY_MEDIA: | ||
2785 | cy_as_hal_assert(cy_false);/* Not used any more. */ | ||
2786 | break; | ||
2787 | case CY_RQT_QUERY_BUS: | ||
2788 | cy_as_hal_assert(node->data != 0); | ||
2789 | ret = my_handle_response_storage_query_bus(dev_p, | ||
2790 | rqt, resp, (uint32_t *)node->data); | ||
2791 | break; | ||
2792 | case CY_RQT_QUERY_DEVICE: | ||
2793 | cy_as_hal_assert(node->data != 0); | ||
2794 | ret = my_handle_response_storage_query_device(dev_p, | ||
2795 | rqt, resp, node->data); | ||
2796 | break; | ||
2797 | case CY_RQT_QUERY_UNIT: | ||
2798 | cy_as_hal_assert(node->data != 0); | ||
2799 | ret = my_handle_response_storage_query_unit(dev_p, | ||
2800 | rqt, resp, node->data); | ||
2801 | break; | ||
2802 | case CY_RQT_SD_INTERFACE_CONTROL: | ||
2803 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
2804 | break; | ||
2805 | case CY_RQT_SD_REGISTER_READ: | ||
2806 | cy_as_hal_assert(node->data != 0); | ||
2807 | ret = my_handle_response_sd_reg_read(dev_p, rqt, resp, | ||
2808 | (cy_as_storage_sd_reg_read_data *)node->data); | ||
2809 | break; | ||
2810 | case CY_RQT_PARTITION_STORAGE: | ||
2811 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
2812 | break; | ||
2813 | case CY_RQT_PARTITION_ERASE: | ||
2814 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
2815 | break; | ||
2816 | case CY_RQT_GET_TRANSFER_AMOUNT: | ||
2817 | cy_as_hal_assert(node->data != 0); | ||
2818 | ret = my_handle_response_get_transfer_amount(dev_p, | ||
2819 | rqt, resp, (cy_as_m_s_c_progress_data *)node->data); | ||
2820 | break; | ||
2821 | case CY_RQT_ERASE: | ||
2822 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
2823 | |||
2824 | /* If error = "invalid response", this (very likely) | ||
2825 | * means that we are not using the SD-only firmware | ||
2826 | * module which is the only one supporting storage_erase. | ||
2827 | * in this case force a "non supported" error code */ | ||
2828 | if (ret == CY_AS_ERROR_INVALID_RESPONSE) | ||
2829 | ret = CY_AS_ERROR_NOT_SUPPORTED; | ||
2830 | |||
2831 | break; | ||
2832 | |||
2833 | default: | ||
2834 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2835 | cy_as_hal_assert(cy_false); | ||
2836 | break; | ||
2837 | } | ||
2838 | |||
2839 | /* | ||
2840 | * if the low level layer returns a direct error, use the | ||
2841 | * corresponding error code. if not, use the error code | ||
2842 | * based on the response from firmware. | ||
2843 | */ | ||
2844 | if (stat == CY_AS_ERROR_SUCCESS) | ||
2845 | stat = ret; | ||
2846 | |||
2847 | /* Call the user callback, if there is one */ | ||
2848 | if (node->cb_p) | ||
2849 | node->cb_p((cy_as_device_handle)dev_p, stat, | ||
2850 | node->client_data, node->data_type, node->data); | ||
2851 | cy_as_remove_c_b_node(dev_p->func_cbs_stor); | ||
2852 | } | ||
2853 | |||
2854 | |||
2855 | static void | ||
2856 | cy_as_sdio_sync_reply_callback( | ||
2857 | cy_as_device *dev_p, | ||
2858 | uint8_t context, | ||
2859 | cy_as_ll_request_response *rqt, | ||
2860 | cy_as_ll_request_response *resp, | ||
2861 | cy_as_return_status_t ret) | ||
2862 | { | ||
2863 | (void)rqt; | ||
2864 | |||
2865 | if ((cy_as_ll_request_response__get_code(resp) == | ||
2866 | CY_RESP_SDIO_GET_TUPLE) || | ||
2867 | (cy_as_ll_request_response__get_code(resp) == | ||
2868 | CY_RESP_SDIO_EXT)) { | ||
2869 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
2870 | if ((ret & 0x00FF) != CY_AS_ERROR_SUCCESS) { | ||
2871 | if (cy_as_ll_request_response__get_code(rqt) == | ||
2872 | CY_RQT_SDIO_READ_EXTENDED) | ||
2873 | cy_as_dma_cancel(dev_p, | ||
2874 | dev_p->storage_read_endpoint, ret); | ||
2875 | else | ||
2876 | cy_as_dma_cancel(dev_p, | ||
2877 | dev_p->storage_write_endpoint, ret); | ||
2878 | } | ||
2879 | } else { | ||
2880 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2881 | } | ||
2882 | |||
2883 | dev_p->storage_rw_resp_p = resp; | ||
2884 | dev_p->storage_wait = cy_false; | ||
2885 | if (((ret & 0x00FF) == CY_AS_ERROR_IO_ABORTED) || ((ret & 0x00FF) | ||
2886 | == CY_AS_ERROR_IO_SUSPENDED)) | ||
2887 | dev_p->storage_error = (ret & 0x00FF); | ||
2888 | else | ||
2889 | dev_p->storage_error = (ret & 0x00FF) ? | ||
2890 | CY_AS_ERROR_INVALID_RESPONSE : CY_AS_ERROR_SUCCESS; | ||
2891 | |||
2892 | /* Wake any threads/processes that are waiting on | ||
2893 | * the read/write completion. */ | ||
2894 | cy_as_hal_wake(&dev_p->context[context]->channel); | ||
2895 | } | ||
2896 | |||
2897 | cy_as_return_status_t | ||
2898 | cy_as_sdio_device_check( | ||
2899 | cy_as_device *dev_p, | ||
2900 | cy_as_bus_number_t bus, | ||
2901 | uint32_t device) | ||
2902 | { | ||
2903 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2904 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2905 | |||
2906 | if (bus < 0 || bus >= CY_AS_MAX_BUSES) | ||
2907 | return CY_AS_ERROR_NO_SUCH_BUS; | ||
2908 | |||
2909 | if (device >= CY_AS_MAX_STORAGE_DEVICES) | ||
2910 | return CY_AS_ERROR_NO_SUCH_DEVICE; | ||
2911 | |||
2912 | if (!cy_as_device_is_astoria_dev(dev_p)) | ||
2913 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
2914 | |||
2915 | return (is_storage_active(dev_p)); | ||
2916 | } | ||
2917 | |||
2918 | cy_as_return_status_t | ||
2919 | cy_as_sdio_direct_io( | ||
2920 | cy_as_device_handle handle, | ||
2921 | cy_as_bus_number_t bus, | ||
2922 | uint32_t device, | ||
2923 | uint8_t n_function_no, | ||
2924 | uint32_t address, | ||
2925 | uint8_t misc_buf, | ||
2926 | uint16_t argument, | ||
2927 | uint8_t is_write, | ||
2928 | uint8_t *data_p) | ||
2929 | { | ||
2930 | cy_as_ll_request_response *req_p , *reply_p; | ||
2931 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
2932 | uint16_t resp_data; | ||
2933 | |||
2934 | /* | ||
2935 | * sanity checks required before sending the request to the | ||
2936 | * firmware. | ||
2937 | */ | ||
2938 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2939 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
2940 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2941 | return ret; | ||
2942 | |||
2943 | |||
2944 | if (!(cy_as_sdio_check_function_initialized(handle, | ||
2945 | bus, n_function_no))) | ||
2946 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
2947 | if (cy_as_sdio_check_function_suspended(handle, bus, n_function_no)) | ||
2948 | return CY_AS_ERROR_FUNCTION_SUSPENDED; | ||
2949 | |||
2950 | req_p = cy_as_ll_create_request(dev_p, (is_write == cy_true) ? | ||
2951 | CY_RQT_SDIO_WRITE_DIRECT : CY_RQT_SDIO_READ_DIRECT, | ||
2952 | CY_RQT_STORAGE_RQT_CONTEXT, 3); | ||
2953 | if (req_p == 0) | ||
2954 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2955 | |||
2956 | /*Setting up request*/ | ||
2957 | |||
2958 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2959 | create_address(bus, (uint8_t)device, n_function_no)); | ||
2960 | /* D1 */ | ||
2961 | if (is_write == cy_true) { | ||
2962 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2963 | ((argument<<8) | 0x0080 | (n_function_no<<4) | | ||
2964 | ((misc_buf&CY_SDIO_RAW)<<3) | | ||
2965 | ((misc_buf&CY_SDIO_REARM_INT)>>5) | | ||
2966 | (uint16_t)(address>>15))); | ||
2967 | } else { | ||
2968 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2969 | (n_function_no<<4) | ((misc_buf&CY_SDIO_REARM_INT)>>5) | | ||
2970 | (uint16_t)(address>>15)); | ||
2971 | } | ||
2972 | /* D2 */ | ||
2973 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2974 | ((uint16_t)((address&0x00007fff)<<1))); | ||
2975 | |||
2976 | /*Create response*/ | ||
2977 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
2978 | |||
2979 | if (reply_p == 0) { | ||
2980 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2981 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2982 | } | ||
2983 | |||
2984 | /*Sending the request*/ | ||
2985 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2986 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2987 | goto destroy; | ||
2988 | |||
2989 | /*Check reply type*/ | ||
2990 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
2991 | CY_RESP_SDIO_DIRECT) { | ||
2992 | resp_data = cy_as_ll_request_response__get_word(reply_p, 0); | ||
2993 | if (resp_data >> 8) | ||
2994 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2995 | else if (data_p != 0) | ||
2996 | *(uint8_t *)(data_p) = (uint8_t)(resp_data&0x00ff); | ||
2997 | } else { | ||
2998 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2999 | } | ||
3000 | |||
3001 | destroy: | ||
3002 | if (req_p != 0) | ||
3003 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3004 | if (reply_p != 0) | ||
3005 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3006 | return ret; | ||
3007 | } | ||
3008 | |||
3009 | |||
3010 | cy_as_return_status_t | ||
3011 | cy_as_sdio_direct_read( | ||
3012 | cy_as_device_handle handle, | ||
3013 | cy_as_bus_number_t bus, | ||
3014 | uint32_t device, | ||
3015 | uint8_t n_function_no, | ||
3016 | uint32_t address, | ||
3017 | uint8_t misc_buf, | ||
3018 | uint8_t *data_p) | ||
3019 | { | ||
3020 | return cy_as_sdio_direct_io(handle, bus, device, n_function_no, | ||
3021 | address, misc_buf, 0x00, cy_false, data_p); | ||
3022 | } | ||
3023 | EXPORT_SYMBOL(cy_as_sdio_direct_read); | ||
3024 | |||
3025 | cy_as_return_status_t | ||
3026 | cy_as_sdio_direct_write( | ||
3027 | cy_as_device_handle handle, | ||
3028 | cy_as_bus_number_t bus, | ||
3029 | uint32_t device, | ||
3030 | uint8_t n_function_no, | ||
3031 | uint32_t address, | ||
3032 | uint8_t misc_buf, | ||
3033 | uint16_t argument, | ||
3034 | uint8_t *data_p) | ||
3035 | { | ||
3036 | return cy_as_sdio_direct_io(handle, bus, device, n_function_no, | ||
3037 | address, misc_buf, argument, cy_true, data_p); | ||
3038 | } | ||
3039 | EXPORT_SYMBOL(cy_as_sdio_direct_write); | ||
3040 | |||
3041 | /*Cmd53 IO*/ | ||
3042 | cy_as_return_status_t | ||
3043 | cy_as_sdio_extended_i_o( | ||
3044 | cy_as_device_handle handle, | ||
3045 | cy_as_bus_number_t bus, | ||
3046 | uint32_t device, | ||
3047 | uint8_t n_function_no, | ||
3048 | uint32_t address, | ||
3049 | uint8_t misc_buf, | ||
3050 | uint16_t argument, | ||
3051 | uint8_t is_write, | ||
3052 | uint8_t *data_p , | ||
3053 | uint8_t is_resume) | ||
3054 | { | ||
3055 | cy_as_ll_request_response *req_p , *reply_p; | ||
3056 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3057 | uint8_t resp_type; | ||
3058 | uint8_t reqtype; | ||
3059 | uint16_t resp_data; | ||
3060 | cy_as_context *ctxt_p; | ||
3061 | uint32_t dmasize, loopcount = 200; | ||
3062 | cy_as_end_point_number_t ep; | ||
3063 | |||
3064 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3065 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3066 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3067 | return ret; | ||
3068 | |||
3069 | if (!(cy_as_sdio_check_function_initialized(handle, | ||
3070 | bus, n_function_no))) | ||
3071 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3072 | if (cy_as_sdio_check_function_suspended(handle, bus, n_function_no)) | ||
3073 | return CY_AS_ERROR_FUNCTION_SUSPENDED; | ||
3074 | |||
3075 | |||
3076 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
3077 | (dev_p->storage_wait)) | ||
3078 | return CY_AS_ERROR_ASYNC_PENDING; | ||
3079 | |||
3080 | /* Request for 0 bytes of blocks is returned as a success*/ | ||
3081 | if (argument == 0) | ||
3082 | return CY_AS_ERROR_SUCCESS; | ||
3083 | |||
3084 | /* Initialise the request to send to the West Bridge device. */ | ||
3085 | if (is_write == cy_true) { | ||
3086 | reqtype = CY_RQT_SDIO_WRITE_EXTENDED; | ||
3087 | ep = dev_p->storage_write_endpoint; | ||
3088 | } else { | ||
3089 | reqtype = CY_RQT_SDIO_READ_EXTENDED; | ||
3090 | ep = dev_p->storage_read_endpoint; | ||
3091 | } | ||
3092 | |||
3093 | req_p = dev_p->storage_rw_req_p; | ||
3094 | cy_as_ll_init_request(req_p, reqtype, CY_RQT_STORAGE_RQT_CONTEXT, 3); | ||
3095 | |||
3096 | /* Initialise the space for reply from the Antioch. */ | ||
3097 | reply_p = dev_p->storage_rw_resp_p; | ||
3098 | cy_as_ll_init_response(reply_p, 2); | ||
3099 | |||
3100 | /* Setup the DMA request */ | ||
3101 | if (!(misc_buf&CY_SDIO_BLOCKMODE)) { | ||
3102 | if (argument > | ||
3103 | dev_p->sdiocard[bus]. | ||
3104 | function[n_function_no-1].blocksize) | ||
3105 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
3106 | |||
3107 | } else { | ||
3108 | if (argument > 511) | ||
3109 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
3110 | } | ||
3111 | |||
3112 | if (argument == 512) | ||
3113 | argument = 0; | ||
3114 | |||
3115 | dmasize = ((misc_buf&CY_SDIO_BLOCKMODE) != 0) ? | ||
3116 | dev_p->sdiocard[bus].function[n_function_no-1].blocksize | ||
3117 | * argument : argument; | ||
3118 | |||
3119 | ret = cy_as_dma_queue_request(dev_p, ep, (void *)(data_p), | ||
3120 | dmasize, cy_false, (is_write & cy_true) ? cy_false : | ||
3121 | cy_true, cy_as_sync_storage_callback); | ||
3122 | |||
3123 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3124 | return ret; | ||
3125 | |||
3126 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3127 | create_address(bus, (uint8_t)device, | ||
3128 | n_function_no | ((is_resume) ? 0x80 : 0x00))); | ||
3129 | cy_as_ll_request_response__set_word(req_p, 1, | ||
3130 | ((uint16_t)n_function_no)<<12| | ||
3131 | ((uint16_t)(misc_buf & (CY_SDIO_BLOCKMODE|CY_SDIO_OP_INCR))) | ||
3132 | << 9 | (uint16_t)(address >> 7) | | ||
3133 | ((is_write == cy_true) ? 0x8000 : 0x0000)); | ||
3134 | cy_as_ll_request_response__set_word(req_p, 2, | ||
3135 | ((uint16_t)(address&0x0000ffff) << 9) | argument); | ||
3136 | |||
3137 | |||
3138 | /* Send the request and wait for completion of storage request */ | ||
3139 | dev_p->storage_wait = cy_true; | ||
3140 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
3141 | cy_true, cy_as_sdio_sync_reply_callback); | ||
3142 | |||
3143 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3144 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
3145 | } else { | ||
3146 | /* Setup the DMA request */ | ||
3147 | ctxt_p = dev_p->context[CY_RQT_STORAGE_RQT_CONTEXT]; | ||
3148 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_true); | ||
3149 | |||
3150 | while (loopcount-- > 0) { | ||
3151 | if (dev_p->storage_wait == cy_false) | ||
3152 | break; | ||
3153 | cy_as_hal_sleep_on(&ctxt_p->channel, 10); | ||
3154 | } | ||
3155 | if (dev_p->storage_wait == cy_true) { | ||
3156 | dev_p->storage_wait = cy_false; | ||
3157 | cy_as_ll_remove_request(dev_p, ctxt_p, req_p, cy_true); | ||
3158 | dev_p->storage_error = CY_AS_ERROR_TIMEOUT; | ||
3159 | } | ||
3160 | |||
3161 | ret = dev_p->storage_error; | ||
3162 | |||
3163 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3164 | return ret; | ||
3165 | |||
3166 | resp_type = cy_as_ll_request_response__get_code( | ||
3167 | dev_p->storage_rw_resp_p); | ||
3168 | if (resp_type == CY_RESP_SDIO_EXT) { | ||
3169 | resp_data = cy_as_ll_request_response__get_word | ||
3170 | (reply_p, 0)&0x00ff; | ||
3171 | if (resp_data) | ||
3172 | ret = CY_AS_ERROR_INVALID_REQUEST; | ||
3173 | |||
3174 | } else { | ||
3175 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3176 | } | ||
3177 | } | ||
3178 | return ret; | ||
3179 | |||
3180 | } | ||
3181 | |||
3182 | static void | ||
3183 | cy_as_sdio_async_reply_callback( | ||
3184 | cy_as_device *dev_p, | ||
3185 | uint8_t context, | ||
3186 | cy_as_ll_request_response *rqt, | ||
3187 | cy_as_ll_request_response *resp, | ||
3188 | cy_as_return_status_t ret) | ||
3189 | { | ||
3190 | cy_as_storage_callback cb_ms; | ||
3191 | uint8_t reqtype; | ||
3192 | uint32_t pendingblocks; | ||
3193 | (void)rqt; | ||
3194 | (void)context; | ||
3195 | |||
3196 | pendingblocks = 0; | ||
3197 | reqtype = cy_as_ll_request_response__get_code(rqt); | ||
3198 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
3199 | if ((cy_as_ll_request_response__get_code(resp) == | ||
3200 | CY_RESP_SUCCESS_FAILURE) || | ||
3201 | (cy_as_ll_request_response__get_code(resp) == | ||
3202 | CY_RESP_SDIO_EXT)) { | ||
3203 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
3204 | ret &= 0x00FF; | ||
3205 | } else { | ||
3206 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3207 | } | ||
3208 | } | ||
3209 | |||
3210 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3211 | if (reqtype == CY_RQT_SDIO_READ_EXTENDED) | ||
3212 | cy_as_dma_cancel(dev_p, | ||
3213 | dev_p->storage_read_endpoint, ret); | ||
3214 | else | ||
3215 | cy_as_dma_cancel(dev_p, | ||
3216 | dev_p->storage_write_endpoint, ret); | ||
3217 | |||
3218 | dev_p->storage_error = ret; | ||
3219 | } | ||
3220 | |||
3221 | dev_p->storage_wait = cy_false; | ||
3222 | |||
3223 | /* | ||
3224 | * if the DMA callback has already been called, | ||
3225 | * the user callback has to be called from here. | ||
3226 | */ | ||
3227 | if (!cy_as_device_is_storage_async_pending(dev_p)) { | ||
3228 | cy_as_hal_assert(dev_p->storage_cb_ms != NULL); | ||
3229 | cb_ms = dev_p->storage_cb_ms; | ||
3230 | |||
3231 | dev_p->storage_cb = 0; | ||
3232 | dev_p->storage_cb_ms = 0; | ||
3233 | |||
3234 | if ((ret == CY_AS_ERROR_SUCCESS) || | ||
3235 | (ret == CY_AS_ERROR_IO_ABORTED) || | ||
3236 | (ret == CY_AS_ERROR_IO_SUSPENDED)) { | ||
3237 | ret = dev_p->storage_error; | ||
3238 | pendingblocks = ((uint32_t) | ||
3239 | cy_as_ll_request_response__get_word | ||
3240 | (resp, 1)) << 16; | ||
3241 | } else | ||
3242 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3243 | |||
3244 | cb_ms((cy_as_device_handle)dev_p, dev_p->storage_bus_index, | ||
3245 | dev_p->storage_device_index, | ||
3246 | (dev_p->storage_unit | pendingblocks), | ||
3247 | dev_p->storage_block_addr, dev_p->storage_oper, ret); | ||
3248 | } else | ||
3249 | dev_p->storage_error = ret; | ||
3250 | } | ||
3251 | |||
3252 | |||
3253 | cy_as_return_status_t | ||
3254 | cy_as_sdio_extended_i_o_async( | ||
3255 | cy_as_device_handle handle, | ||
3256 | cy_as_bus_number_t bus, | ||
3257 | uint32_t device, | ||
3258 | uint8_t n_function_no, | ||
3259 | uint32_t address, | ||
3260 | uint8_t misc_buf, | ||
3261 | uint16_t argument, | ||
3262 | uint8_t is_write, | ||
3263 | uint8_t *data_p, | ||
3264 | cy_as_storage_callback callback) | ||
3265 | { | ||
3266 | |||
3267 | uint32_t mask; | ||
3268 | uint32_t dmasize; | ||
3269 | cy_as_ll_request_response *req_p , *reply_p; | ||
3270 | uint8_t reqtype; | ||
3271 | cy_as_end_point_number_t ep; | ||
3272 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3273 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3274 | |||
3275 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3276 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3277 | return ret; | ||
3278 | |||
3279 | if (!(cy_as_sdio_check_function_initialized(handle, | ||
3280 | bus, n_function_no))) | ||
3281 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3282 | if (cy_as_sdio_check_function_suspended(handle, bus, n_function_no)) | ||
3283 | return CY_AS_ERROR_FUNCTION_SUSPENDED; | ||
3284 | |||
3285 | if (callback == 0) | ||
3286 | return CY_AS_ERROR_NULL_CALLBACK; | ||
3287 | |||
3288 | /* We are supposed to return success if the number of | ||
3289 | * blocks is zero | ||
3290 | */ | ||
3291 | if (((misc_buf&CY_SDIO_BLOCKMODE) != 0) && (argument == 0)) { | ||
3292 | callback(handle, bus, device, n_function_no, address, | ||
3293 | ((is_write) ? cy_as_op_write : cy_as_op_read), | ||
3294 | CY_AS_ERROR_SUCCESS); | ||
3295 | return CY_AS_ERROR_SUCCESS; | ||
3296 | } | ||
3297 | |||
3298 | |||
3299 | /* | ||
3300 | * since async operations can be triggered by interrupt | ||
3301 | * code, we must insure that we do not get multiple async | ||
3302 | * operations going at one time and protect this test and | ||
3303 | * set operation from interrupts. | ||
3304 | */ | ||
3305 | mask = cy_as_hal_disable_interrupts(); | ||
3306 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
3307 | (dev_p->storage_wait)) { | ||
3308 | cy_as_hal_enable_interrupts(mask); | ||
3309 | return CY_AS_ERROR_ASYNC_PENDING; | ||
3310 | } | ||
3311 | cy_as_device_set_storage_async_pending(dev_p); | ||
3312 | cy_as_hal_enable_interrupts(mask); | ||
3313 | |||
3314 | |||
3315 | /* | ||
3316 | * storage information about the currently | ||
3317 | * outstanding request | ||
3318 | */ | ||
3319 | dev_p->storage_cb_ms = callback; | ||
3320 | dev_p->storage_bus_index = bus; | ||
3321 | dev_p->storage_device_index = device; | ||
3322 | dev_p->storage_unit = n_function_no; | ||
3323 | dev_p->storage_block_addr = address; | ||
3324 | |||
3325 | if (is_write == cy_true) { | ||
3326 | reqtype = CY_RQT_SDIO_WRITE_EXTENDED; | ||
3327 | ep = dev_p->storage_write_endpoint; | ||
3328 | } else { | ||
3329 | reqtype = CY_RQT_SDIO_READ_EXTENDED; | ||
3330 | ep = dev_p->storage_read_endpoint; | ||
3331 | } | ||
3332 | |||
3333 | /* Initialise the request to send to the West Bridge. */ | ||
3334 | req_p = dev_p->storage_rw_req_p; | ||
3335 | cy_as_ll_init_request(req_p, reqtype, | ||
3336 | CY_RQT_STORAGE_RQT_CONTEXT, 3); | ||
3337 | |||
3338 | /* Initialise the space for reply from the West Bridge. */ | ||
3339 | reply_p = dev_p->storage_rw_resp_p; | ||
3340 | cy_as_ll_init_response(reply_p, 2); | ||
3341 | |||
3342 | if (!(misc_buf&CY_SDIO_BLOCKMODE)) { | ||
3343 | if (argument > | ||
3344 | dev_p->sdiocard[bus].function[n_function_no-1].blocksize) | ||
3345 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
3346 | |||
3347 | } else { | ||
3348 | if (argument > 511) | ||
3349 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
3350 | } | ||
3351 | |||
3352 | if (argument == 512) | ||
3353 | argument = 0; | ||
3354 | dmasize = ((misc_buf&CY_SDIO_BLOCKMODE) != 0) ? | ||
3355 | dev_p->sdiocard[bus].function[n_function_no-1].blocksize * | ||
3356 | argument : argument; | ||
3357 | |||
3358 | /* Setup the DMA request and adjust the storage | ||
3359 | * operation if we are reading */ | ||
3360 | if (reqtype == CY_RQT_SDIO_READ_EXTENDED) { | ||
3361 | ret = cy_as_dma_queue_request(dev_p, ep, | ||
3362 | (void *)data_p, dmasize , cy_false, cy_true, | ||
3363 | cy_as_async_storage_callback); | ||
3364 | dev_p->storage_oper = cy_as_op_read; | ||
3365 | } else if (reqtype == CY_RQT_SDIO_WRITE_EXTENDED) { | ||
3366 | ret = cy_as_dma_queue_request(dev_p, ep, (void *)data_p, | ||
3367 | dmasize, cy_false, cy_false, cy_as_async_storage_callback); | ||
3368 | dev_p->storage_oper = cy_as_op_write; | ||
3369 | } | ||
3370 | |||
3371 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3372 | cy_as_device_clear_storage_async_pending(dev_p); | ||
3373 | return ret; | ||
3374 | } | ||
3375 | |||
3376 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3377 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3378 | cy_as_ll_request_response__set_word(req_p, 1, | ||
3379 | ((uint16_t)n_function_no) << 12 | | ||
3380 | ((uint16_t)(misc_buf & (CY_SDIO_BLOCKMODE | CY_SDIO_OP_INCR))) | ||
3381 | << 9 | (uint16_t)(address>>7) | | ||
3382 | ((is_write == cy_true) ? 0x8000 : 0x0000)); | ||
3383 | cy_as_ll_request_response__set_word(req_p, 2, | ||
3384 | ((uint16_t)(address&0x0000ffff) << 9) | argument); | ||
3385 | |||
3386 | |||
3387 | /* Send the request and wait for completion of storage request */ | ||
3388 | dev_p->storage_wait = cy_true; | ||
3389 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, cy_true, | ||
3390 | cy_as_sdio_async_reply_callback); | ||
3391 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3392 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
3393 | cy_as_device_clear_storage_async_pending(dev_p); | ||
3394 | } else { | ||
3395 | cy_as_dma_kick_start(dev_p, ep); | ||
3396 | } | ||
3397 | |||
3398 | return ret; | ||
3399 | } | ||
3400 | |||
3401 | /* CMD53 Extended Read*/ | ||
3402 | cy_as_return_status_t | ||
3403 | cy_as_sdio_extended_read( | ||
3404 | cy_as_device_handle handle, | ||
3405 | cy_as_bus_number_t bus, | ||
3406 | uint32_t device, | ||
3407 | uint8_t n_function_no, | ||
3408 | uint32_t address, | ||
3409 | uint8_t misc_buf, | ||
3410 | uint16_t argument, | ||
3411 | uint8_t *data_p, | ||
3412 | cy_as_sdio_callback callback) | ||
3413 | { | ||
3414 | if (callback == 0) | ||
3415 | return cy_as_sdio_extended_i_o(handle, bus, device, | ||
3416 | n_function_no, address, misc_buf, argument, | ||
3417 | cy_false, data_p, 0); | ||
3418 | |||
3419 | return cy_as_sdio_extended_i_o_async(handle, bus, device, | ||
3420 | n_function_no, address, misc_buf, argument, cy_false, | ||
3421 | data_p, callback); | ||
3422 | } | ||
3423 | EXPORT_SYMBOL(cy_as_sdio_extended_read); | ||
3424 | |||
3425 | /* CMD53 Extended Write*/ | ||
3426 | cy_as_return_status_t | ||
3427 | cy_as_sdio_extended_write( | ||
3428 | cy_as_device_handle handle, | ||
3429 | cy_as_bus_number_t bus, | ||
3430 | uint32_t device, | ||
3431 | uint8_t n_function_no, | ||
3432 | uint32_t address, | ||
3433 | uint8_t misc_buf, | ||
3434 | uint16_t argument, | ||
3435 | uint8_t *data_p, | ||
3436 | cy_as_sdio_callback callback) | ||
3437 | { | ||
3438 | if (callback == 0) | ||
3439 | return cy_as_sdio_extended_i_o(handle, bus, device, | ||
3440 | n_function_no, address, misc_buf, argument, cy_true, | ||
3441 | data_p, 0); | ||
3442 | |||
3443 | return cy_as_sdio_extended_i_o_async(handle, bus, device, | ||
3444 | n_function_no, address, misc_buf, argument, cy_true, | ||
3445 | data_p, callback); | ||
3446 | } | ||
3447 | EXPORT_SYMBOL(cy_as_sdio_extended_write); | ||
3448 | |||
3449 | /* Read the CIS info tuples for the given function and Tuple ID*/ | ||
3450 | cy_as_return_status_t | ||
3451 | cy_as_sdio_get_c_i_s_info( | ||
3452 | cy_as_device_handle handle, | ||
3453 | cy_as_bus_number_t bus, | ||
3454 | uint32_t device, | ||
3455 | uint8_t n_function_no, | ||
3456 | uint16_t tuple_id, | ||
3457 | uint8_t *data_p) | ||
3458 | { | ||
3459 | |||
3460 | cy_as_ll_request_response *req_p , *reply_p; | ||
3461 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3462 | uint16_t resp_data; | ||
3463 | cy_as_context *ctxt_p; | ||
3464 | uint32_t loopcount = 200; | ||
3465 | |||
3466 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3467 | |||
3468 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3469 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3470 | return ret; | ||
3471 | |||
3472 | if (!(cy_as_sdio_check_function_initialized(handle, bus, 0))) | ||
3473 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3474 | |||
3475 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
3476 | (dev_p->storage_wait)) | ||
3477 | return CY_AS_ERROR_ASYNC_PENDING; | ||
3478 | |||
3479 | |||
3480 | /* Initialise the request to send to the Antioch. */ | ||
3481 | req_p = dev_p->storage_rw_req_p; | ||
3482 | cy_as_ll_init_request(req_p, CY_RQT_SDIO_GET_TUPLE, | ||
3483 | CY_RQT_STORAGE_RQT_CONTEXT, 2); | ||
3484 | |||
3485 | /* Initialise the space for reply from the Antioch. */ | ||
3486 | reply_p = dev_p->storage_rw_resp_p; | ||
3487 | cy_as_ll_init_response(reply_p, 3); | ||
3488 | |||
3489 | /* Setup the DMA request */ | ||
3490 | ret = cy_as_dma_queue_request(dev_p, dev_p->storage_read_endpoint, | ||
3491 | data_p+1, 255, cy_false, cy_true, cy_as_sync_storage_callback); | ||
3492 | |||
3493 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3494 | return ret; | ||
3495 | |||
3496 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3497 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3498 | |||
3499 | /* Set tuple id to fetch. */ | ||
3500 | cy_as_ll_request_response__set_word(req_p, 1, tuple_id<<8); | ||
3501 | |||
3502 | /* Send the request and wait for completion of storage request */ | ||
3503 | dev_p->storage_wait = cy_true; | ||
3504 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, cy_true, | ||
3505 | cy_as_sdio_sync_reply_callback); | ||
3506 | |||
3507 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3508 | cy_as_dma_cancel(dev_p, | ||
3509 | dev_p->storage_read_endpoint, CY_AS_ERROR_CANCELED); | ||
3510 | } else { | ||
3511 | /* Setup the DMA request */ | ||
3512 | ctxt_p = dev_p->context[CY_RQT_STORAGE_RQT_CONTEXT]; | ||
3513 | ret = cy_as_dma_drain_queue(dev_p, | ||
3514 | dev_p->storage_read_endpoint, cy_true); | ||
3515 | |||
3516 | while (loopcount-- > 0) { | ||
3517 | if (dev_p->storage_wait == cy_false) | ||
3518 | break; | ||
3519 | cy_as_hal_sleep_on(&ctxt_p->channel, 10); | ||
3520 | } | ||
3521 | |||
3522 | if (dev_p->storage_wait == cy_true) { | ||
3523 | dev_p->storage_wait = cy_false; | ||
3524 | cy_as_ll_remove_request(dev_p, ctxt_p, req_p, cy_true); | ||
3525 | return CY_AS_ERROR_TIMEOUT; | ||
3526 | } | ||
3527 | ret = dev_p->storage_error; | ||
3528 | |||
3529 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3530 | return ret; | ||
3531 | |||
3532 | if (cy_as_ll_request_response__get_code | ||
3533 | (dev_p->storage_rw_resp_p) == CY_RESP_SDIO_GET_TUPLE) { | ||
3534 | resp_data = cy_as_ll_request_response__get_word | ||
3535 | (reply_p, 0); | ||
3536 | if (resp_data) { | ||
3537 | ret = CY_AS_ERROR_INVALID_REQUEST; | ||
3538 | } else if (data_p != 0) | ||
3539 | *(uint8_t *)data_p = (uint8_t) | ||
3540 | (cy_as_ll_request_response__get_word | ||
3541 | (reply_p, 0)&0x00ff); | ||
3542 | } else { | ||
3543 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3544 | } | ||
3545 | } | ||
3546 | return ret; | ||
3547 | } | ||
3548 | |||
3549 | /*Query Device*/ | ||
3550 | cy_as_return_status_t | ||
3551 | cy_as_sdio_query_card( | ||
3552 | cy_as_device_handle handle, | ||
3553 | cy_as_bus_number_t bus, | ||
3554 | uint32_t device, | ||
3555 | cy_as_sdio_card *data_p) | ||
3556 | { | ||
3557 | cy_as_ll_request_response *req_p , *reply_p; | ||
3558 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3559 | |||
3560 | uint8_t resp_type; | ||
3561 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3562 | |||
3563 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3564 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3565 | return ret; | ||
3566 | |||
3567 | /* Allocating memory to the SDIO device structure in dev_p */ | ||
3568 | |||
3569 | cy_as_hal_mem_set(&dev_p->sdiocard[bus], 0, sizeof(cy_as_sdio_device)); | ||
3570 | |||
3571 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SDIO_QUERY_CARD, | ||
3572 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
3573 | if (req_p == 0) | ||
3574 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3575 | |||
3576 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3577 | create_address(bus, (uint8_t)device, 0)); | ||
3578 | |||
3579 | reply_p = cy_as_ll_create_response(dev_p, 5); | ||
3580 | if (reply_p == 0) { | ||
3581 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3582 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3583 | } | ||
3584 | |||
3585 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
3586 | req_p, reply_p); | ||
3587 | |||
3588 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3589 | goto destroy; | ||
3590 | |||
3591 | resp_type = cy_as_ll_request_response__get_code(reply_p); | ||
3592 | if (resp_type == CY_RESP_SDIO_QUERY_CARD) { | ||
3593 | dev_p->sdiocard[bus].card.num_functions = | ||
3594 | (uint8_t)((reply_p->data[0]&0xff00)>>8); | ||
3595 | dev_p->sdiocard[bus].card.memory_present = | ||
3596 | (uint8_t)reply_p->data[0]&0x0001; | ||
3597 | dev_p->sdiocard[bus].card.manufacturer__id = | ||
3598 | reply_p->data[1]; | ||
3599 | dev_p->sdiocard[bus].card.manufacturer_info = | ||
3600 | reply_p->data[2]; | ||
3601 | dev_p->sdiocard[bus].card.blocksize = | ||
3602 | reply_p->data[3]; | ||
3603 | dev_p->sdiocard[bus].card.maxblocksize = | ||
3604 | reply_p->data[3]; | ||
3605 | dev_p->sdiocard[bus].card.card_capability = | ||
3606 | (uint8_t)((reply_p->data[4]&0xff00)>>8); | ||
3607 | dev_p->sdiocard[bus].card.sdio_version = | ||
3608 | (uint8_t)(reply_p->data[4]&0x00ff); | ||
3609 | dev_p->sdiocard[bus].function_init_map = 0x01; | ||
3610 | data_p->num_functions = | ||
3611 | dev_p->sdiocard[bus].card.num_functions; | ||
3612 | data_p->memory_present = | ||
3613 | dev_p->sdiocard[bus].card.memory_present; | ||
3614 | data_p->manufacturer__id = | ||
3615 | dev_p->sdiocard[bus].card.manufacturer__id; | ||
3616 | data_p->manufacturer_info = | ||
3617 | dev_p->sdiocard[bus].card.manufacturer_info; | ||
3618 | data_p->blocksize = dev_p->sdiocard[bus].card.blocksize; | ||
3619 | data_p->maxblocksize = | ||
3620 | dev_p->sdiocard[bus].card.maxblocksize; | ||
3621 | data_p->card_capability = | ||
3622 | dev_p->sdiocard[bus].card.card_capability; | ||
3623 | data_p->sdio_version = | ||
3624 | dev_p->sdiocard[bus].card.sdio_version; | ||
3625 | } else { | ||
3626 | if (resp_type == CY_RESP_SUCCESS_FAILURE) | ||
3627 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3628 | else | ||
3629 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3630 | } | ||
3631 | destroy: | ||
3632 | if (req_p != 0) | ||
3633 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3634 | if (reply_p != 0) | ||
3635 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3636 | return ret; | ||
3637 | } | ||
3638 | EXPORT_SYMBOL(cy_as_sdio_query_card); | ||
3639 | |||
3640 | /*Reset SDIO card. */ | ||
3641 | cy_as_return_status_t | ||
3642 | cy_as_sdio_reset_card( | ||
3643 | cy_as_device_handle handle, | ||
3644 | cy_as_bus_number_t bus, | ||
3645 | uint32_t device) | ||
3646 | { | ||
3647 | |||
3648 | cy_as_ll_request_response *req_p , *reply_p; | ||
3649 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3650 | uint8_t resp_type; | ||
3651 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3652 | |||
3653 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3654 | |||
3655 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3656 | return ret; | ||
3657 | |||
3658 | if (dev_p->sdiocard != 0) { | ||
3659 | dev_p->sdiocard[bus].function_init_map = 0; | ||
3660 | dev_p->sdiocard[bus].function_suspended_map = 0; | ||
3661 | } | ||
3662 | |||
3663 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SDIO_RESET_DEV, | ||
3664 | CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
3665 | |||
3666 | if (req_p == 0) | ||
3667 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3668 | |||
3669 | /*Setup mailbox */ | ||
3670 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3671 | create_address(bus, (uint8_t)device, 0)); | ||
3672 | |||
3673 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
3674 | if (reply_p == 0) { | ||
3675 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3676 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3677 | } | ||
3678 | |||
3679 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
3680 | req_p, reply_p); | ||
3681 | |||
3682 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3683 | goto destroy; | ||
3684 | |||
3685 | resp_type = cy_as_ll_request_response__get_code(reply_p); | ||
3686 | |||
3687 | if (resp_type == CY_RESP_SUCCESS_FAILURE) { | ||
3688 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3689 | if (ret == CY_AS_ERROR_SUCCESS) | ||
3690 | ret = cy_as_sdio_query_card(handle, bus, device, 0); | ||
3691 | } else | ||
3692 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3693 | |||
3694 | destroy: | ||
3695 | if (req_p != 0) | ||
3696 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3697 | if (reply_p != 0) | ||
3698 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3699 | return ret; | ||
3700 | } | ||
3701 | |||
3702 | /* Initialise an IO function*/ | ||
3703 | cy_as_return_status_t | ||
3704 | cy_as_sdio_init_function( | ||
3705 | cy_as_device_handle handle, | ||
3706 | cy_as_bus_number_t bus, | ||
3707 | uint32_t device, | ||
3708 | uint8_t n_function_no, | ||
3709 | uint8_t misc_buf) | ||
3710 | { | ||
3711 | cy_as_ll_request_response *req_p , *reply_p; | ||
3712 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3713 | uint8_t resp_type; | ||
3714 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3715 | |||
3716 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3717 | |||
3718 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3719 | return ret; | ||
3720 | |||
3721 | if (!(cy_as_sdio_check_function_initialized | ||
3722 | (handle, bus, 0))) | ||
3723 | return CY_AS_ERROR_NOT_RUNNING; | ||
3724 | |||
3725 | if ((cy_as_sdio_check_function_initialized | ||
3726 | (handle, bus, n_function_no))) { | ||
3727 | if (misc_buf&CY_SDIO_FORCE_INIT) | ||
3728 | dev_p->sdiocard[bus].function_init_map &= | ||
3729 | (~(1 << n_function_no)); | ||
3730 | else | ||
3731 | return CY_AS_ERROR_ALREADY_RUNNING; | ||
3732 | } | ||
3733 | |||
3734 | req_p = cy_as_ll_create_request(dev_p, | ||
3735 | CY_RQT_SDIO_INIT_FUNCTION, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
3736 | if (req_p == 0) | ||
3737 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3738 | |||
3739 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3740 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3741 | |||
3742 | reply_p = cy_as_ll_create_response(dev_p, 5); | ||
3743 | if (reply_p == 0) { | ||
3744 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3745 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3746 | } | ||
3747 | |||
3748 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3749 | |||
3750 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3751 | goto destroy; | ||
3752 | |||
3753 | resp_type = cy_as_ll_request_response__get_code(reply_p); | ||
3754 | |||
3755 | if (resp_type == CY_RESP_SDIO_INIT_FUNCTION) { | ||
3756 | dev_p->sdiocard[bus].function[n_function_no-1].function_code = | ||
3757 | (uint8_t)((reply_p->data[0]&0xff00)>>8); | ||
3758 | dev_p->sdiocard[bus].function[n_function_no-1]. | ||
3759 | extended_func_code = (uint8_t)reply_p->data[0]&0x00ff; | ||
3760 | dev_p->sdiocard[bus].function[n_function_no-1].blocksize = | ||
3761 | reply_p->data[1]; | ||
3762 | dev_p->sdiocard[bus].function[n_function_no-1]. | ||
3763 | maxblocksize = reply_p->data[1]; | ||
3764 | dev_p->sdiocard[bus].function[n_function_no-1].card_psn = | ||
3765 | (uint32_t)(reply_p->data[2])<<16; | ||
3766 | dev_p->sdiocard[bus].function[n_function_no-1].card_psn |= | ||
3767 | (uint32_t)(reply_p->data[3]); | ||
3768 | dev_p->sdiocard[bus].function[n_function_no-1].csa_bits = | ||
3769 | (uint8_t)((reply_p->data[4]&0xff00)>>8); | ||
3770 | dev_p->sdiocard[bus].function[n_function_no-1].wakeup_support = | ||
3771 | (uint8_t)(reply_p->data[4]&0x0001); | ||
3772 | dev_p->sdiocard[bus].function_init_map |= (1 << n_function_no); | ||
3773 | cy_as_sdio_clear_function_suspended(handle, bus, n_function_no); | ||
3774 | |||
3775 | } else { | ||
3776 | if (resp_type == CY_RESP_SUCCESS_FAILURE) | ||
3777 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3778 | else | ||
3779 | ret = CY_AS_ERROR_INVALID_FUNCTION; | ||
3780 | } | ||
3781 | |||
3782 | destroy: | ||
3783 | if (req_p != 0) | ||
3784 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3785 | if (reply_p != 0) | ||
3786 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3787 | return ret; | ||
3788 | } | ||
3789 | EXPORT_SYMBOL(cy_as_sdio_init_function); | ||
3790 | |||
3791 | /*Query individual functions. */ | ||
3792 | cy_as_return_status_t | ||
3793 | cy_as_sdio_query_function( | ||
3794 | cy_as_device_handle handle, | ||
3795 | cy_as_bus_number_t bus, | ||
3796 | uint32_t device, | ||
3797 | uint8_t n_function_no, | ||
3798 | cy_as_sdio_func *data_p) | ||
3799 | { | ||
3800 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3801 | cy_as_return_status_t ret; | ||
3802 | |||
3803 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3804 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3805 | return ret; | ||
3806 | |||
3807 | if (!(cy_as_sdio_check_function_initialized(handle, | ||
3808 | bus, n_function_no))) | ||
3809 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3810 | |||
3811 | data_p->blocksize = | ||
3812 | dev_p->sdiocard[bus].function[n_function_no-1].blocksize; | ||
3813 | data_p->card_psn = | ||
3814 | dev_p->sdiocard[bus].function[n_function_no-1].card_psn; | ||
3815 | data_p->csa_bits = | ||
3816 | dev_p->sdiocard[bus].function[n_function_no-1].csa_bits; | ||
3817 | data_p->extended_func_code = | ||
3818 | dev_p->sdiocard[bus].function[n_function_no-1]. | ||
3819 | extended_func_code; | ||
3820 | data_p->function_code = | ||
3821 | dev_p->sdiocard[bus].function[n_function_no-1].function_code; | ||
3822 | data_p->maxblocksize = | ||
3823 | dev_p->sdiocard[bus].function[n_function_no-1].maxblocksize; | ||
3824 | data_p->wakeup_support = | ||
3825 | dev_p->sdiocard[bus].function[n_function_no-1].wakeup_support; | ||
3826 | |||
3827 | return CY_AS_ERROR_SUCCESS; | ||
3828 | } | ||
3829 | |||
3830 | /* Abort the Current Extended IO Operation*/ | ||
3831 | cy_as_return_status_t | ||
3832 | cy_as_sdio_abort_function( | ||
3833 | cy_as_device_handle handle, | ||
3834 | cy_as_bus_number_t bus, | ||
3835 | uint32_t device, | ||
3836 | uint8_t n_function_no) | ||
3837 | { | ||
3838 | cy_as_ll_request_response *req_p , *reply_p; | ||
3839 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3840 | uint8_t resp_type; | ||
3841 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3842 | |||
3843 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3844 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3845 | return ret; | ||
3846 | |||
3847 | if (!(cy_as_sdio_check_function_initialized(handle, | ||
3848 | bus, n_function_no))) | ||
3849 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3850 | |||
3851 | if ((cy_as_device_is_storage_async_pending(dev_p)) || | ||
3852 | (dev_p->storage_wait)) { | ||
3853 | if (!(cy_as_sdio_get_card_capability(handle, bus) & | ||
3854 | CY_SDIO_SDC)) | ||
3855 | return CY_AS_ERROR_INVALID_COMMAND; | ||
3856 | } | ||
3857 | |||
3858 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SDIO_ABORT_IO, | ||
3859 | CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
3860 | |||
3861 | if (req_p == 0) | ||
3862 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3863 | |||
3864 | /*Setup mailbox */ | ||
3865 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3866 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3867 | |||
3868 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
3869 | if (reply_p == 0) { | ||
3870 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3871 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3872 | } | ||
3873 | |||
3874 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3875 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3876 | goto destroy; | ||
3877 | |||
3878 | resp_type = cy_as_ll_request_response__get_code(reply_p); | ||
3879 | |||
3880 | if (resp_type == CY_RESP_SUCCESS_FAILURE) | ||
3881 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3882 | else | ||
3883 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3884 | |||
3885 | |||
3886 | destroy: | ||
3887 | if (req_p != 0) | ||
3888 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3889 | if (reply_p != 0) | ||
3890 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3891 | return ret; | ||
3892 | } | ||
3893 | |||
3894 | /* Suspend IO to current function*/ | ||
3895 | cy_as_return_status_t | ||
3896 | cy_as_sdio_suspend( | ||
3897 | cy_as_device_handle handle, | ||
3898 | cy_as_bus_number_t bus, | ||
3899 | uint32_t device, | ||
3900 | uint8_t n_function_no) | ||
3901 | { | ||
3902 | cy_as_ll_request_response *req_p , *reply_p; | ||
3903 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3904 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3905 | |||
3906 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3907 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3908 | return ret; | ||
3909 | |||
3910 | if (!(cy_as_sdio_check_function_initialized(handle, bus, | ||
3911 | n_function_no))) | ||
3912 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3913 | if (!(cy_as_sdio_check_support_bus_suspend(handle, bus))) | ||
3914 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3915 | if (!(cy_as_sdio_get_card_capability(handle, bus) & CY_SDIO_SDC)) | ||
3916 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3917 | if (cy_as_sdio_check_function_suspended(handle, bus, n_function_no)) | ||
3918 | return CY_AS_ERROR_FUNCTION_SUSPENDED; | ||
3919 | |||
3920 | req_p = cy_as_ll_create_request(dev_p, | ||
3921 | CY_RQT_SDIO_SUSPEND, CY_RQT_GENERAL_RQT_CONTEXT, 1); | ||
3922 | if (req_p == 0) | ||
3923 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3924 | |||
3925 | /*Setup mailbox */ | ||
3926 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3927 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3928 | |||
3929 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
3930 | if (reply_p == 0) { | ||
3931 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3932 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3933 | } | ||
3934 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3935 | |||
3936 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
3937 | ret = cy_as_ll_request_response__get_code(reply_p); | ||
3938 | cy_as_sdio_set_function_suspended(handle, bus, n_function_no); | ||
3939 | } | ||
3940 | |||
3941 | if (req_p != 0) | ||
3942 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3943 | if (reply_p != 0) | ||
3944 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3945 | |||
3946 | return ret; | ||
3947 | } | ||
3948 | |||
3949 | /*Resume suspended function*/ | ||
3950 | cy_as_return_status_t | ||
3951 | cy_as_sdio_resume( | ||
3952 | cy_as_device_handle handle, | ||
3953 | cy_as_bus_number_t bus, | ||
3954 | uint32_t device, | ||
3955 | uint8_t n_function_no, | ||
3956 | cy_as_oper_type op, | ||
3957 | uint8_t misc_buf, | ||
3958 | uint16_t pendingblockcount, | ||
3959 | uint8_t *data_p | ||
3960 | ) | ||
3961 | { | ||
3962 | cy_as_ll_request_response *req_p , *reply_p; | ||
3963 | cy_as_return_status_t resp_data, ret = CY_AS_ERROR_SUCCESS; | ||
3964 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3965 | |||
3966 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
3967 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3968 | return ret; | ||
3969 | |||
3970 | if (!(cy_as_sdio_check_function_initialized | ||
3971 | (handle, bus, n_function_no))) | ||
3972 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3973 | |||
3974 | /* If suspend resume is not supported return */ | ||
3975 | if (!(cy_as_sdio_check_support_bus_suspend(handle, bus))) | ||
3976 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3977 | |||
3978 | /* if the function is not suspended return. */ | ||
3979 | if (!(cy_as_sdio_check_function_suspended | ||
3980 | (handle, bus, n_function_no))) | ||
3981 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
3982 | |||
3983 | req_p = cy_as_ll_create_request(dev_p, | ||
3984 | CY_RQT_SDIO_RESUME, CY_RQT_STORAGE_RQT_CONTEXT, 1); | ||
3985 | if (req_p == 0) | ||
3986 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3987 | |||
3988 | /*Setup mailbox */ | ||
3989 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3990 | create_address(bus, (uint8_t)device, n_function_no)); | ||
3991 | |||
3992 | reply_p = cy_as_ll_create_response(dev_p, 2); | ||
3993 | if (reply_p == 0) { | ||
3994 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3995 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3996 | } | ||
3997 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3998 | |||
3999 | if (ret != CY_AS_ERROR_SUCCESS) | ||
4000 | goto destroy; | ||
4001 | |||
4002 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
4003 | CY_RESP_SDIO_RESUME) { | ||
4004 | resp_data = cy_as_ll_request_response__get_word(reply_p, 0); | ||
4005 | if (resp_data & 0x00ff) { | ||
4006 | /* Send extended read request to resume the read. */ | ||
4007 | if (op == cy_as_op_read) { | ||
4008 | ret = cy_as_sdio_extended_i_o(handle, bus, | ||
4009 | device, n_function_no, 0, misc_buf, | ||
4010 | pendingblockcount, cy_false, data_p, 1); | ||
4011 | } else { | ||
4012 | ret = cy_as_sdio_extended_i_o(handle, bus, | ||
4013 | device, n_function_no, 0, misc_buf, | ||
4014 | pendingblockcount, cy_true, data_p, 1); | ||
4015 | } | ||
4016 | } else { | ||
4017 | ret = CY_AS_ERROR_SUCCESS; | ||
4018 | } | ||
4019 | } else { | ||
4020 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
4021 | } | ||
4022 | |||
4023 | destroy: | ||
4024 | cy_as_sdio_clear_function_suspended(handle, bus, n_function_no); | ||
4025 | if (req_p != 0) | ||
4026 | cy_as_ll_destroy_request(dev_p, req_p); | ||
4027 | if (reply_p != 0) | ||
4028 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
4029 | return ret; | ||
4030 | |||
4031 | } | ||
4032 | |||
4033 | /*Set function blocksize. Size cannot exceed max | ||
4034 | * block size for the function*/ | ||
4035 | cy_as_return_status_t | ||
4036 | cy_as_sdio_set_blocksize( | ||
4037 | cy_as_device_handle handle, | ||
4038 | cy_as_bus_number_t bus, | ||
4039 | uint32_t device, | ||
4040 | uint8_t n_function_no, | ||
4041 | uint16_t blocksize) | ||
4042 | { | ||
4043 | cy_as_return_status_t ret; | ||
4044 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
4045 | ret = cy_as_sdio_device_check(dev_p, bus, device); | ||
4046 | if (ret != CY_AS_ERROR_SUCCESS) | ||
4047 | return ret; | ||
4048 | |||
4049 | if (!(cy_as_sdio_check_function_initialized | ||
4050 | (handle, bus, n_function_no))) | ||
4051 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
4052 | if (n_function_no == 0) { | ||
4053 | if (blocksize > cy_as_sdio_get_card_max_blocksize(handle, bus)) | ||
4054 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
4055 | else if (blocksize == cy_as_sdio_get_card_blocksize | ||
4056 | (handle, bus)) | ||
4057 | return CY_AS_ERROR_SUCCESS; | ||
4058 | } else { | ||
4059 | if (blocksize > | ||
4060 | cy_as_sdio_get_function_max_blocksize(handle, | ||
4061 | bus, n_function_no)) | ||
4062 | return CY_AS_ERROR_INVALID_BLOCKSIZE; | ||
4063 | else if (blocksize == | ||
4064 | cy_as_sdio_get_function_blocksize(handle, | ||
4065 | bus, n_function_no)) | ||
4066 | return CY_AS_ERROR_SUCCESS; | ||
4067 | } | ||
4068 | |||
4069 | ret = cy_as_sdio_direct_write(handle, bus, device, 0, | ||
4070 | (uint16_t)(n_function_no << 8) | | ||
4071 | 0x10, 0, blocksize & 0x00ff, 0); | ||
4072 | if (ret != CY_AS_ERROR_SUCCESS) | ||
4073 | return ret; | ||
4074 | |||
4075 | ret = cy_as_sdio_direct_write(handle, bus, device, 0, | ||
4076 | (uint16_t)(n_function_no << 8) | | ||
4077 | 0x11, 0, (blocksize & 0xff00) >> 8, 0); | ||
4078 | |||
4079 | if (ret != CY_AS_ERROR_SUCCESS) | ||
4080 | return ret; | ||
4081 | |||
4082 | if (n_function_no == 0) | ||
4083 | cy_as_sdio_set_card_block_size(handle, bus, blocksize); | ||
4084 | else | ||
4085 | cy_as_sdio_set_function_block_size(handle, | ||
4086 | bus, n_function_no, blocksize); | ||
4087 | return ret; | ||
4088 | } | ||
4089 | EXPORT_SYMBOL(cy_as_sdio_set_blocksize); | ||
4090 | |||
4091 | /* Deinitialize an SDIO function*/ | ||
4092 | cy_as_return_status_t | ||
4093 | cy_as_sdio_de_init_function( | ||
4094 | cy_as_device_handle handle, | ||
4095 | cy_as_bus_number_t bus, | ||
4096 | uint32_t device, | ||
4097 | uint8_t n_function_no) | ||
4098 | { | ||
4099 | cy_as_return_status_t ret; | ||
4100 | uint8_t temp; | ||
4101 | |||
4102 | if (n_function_no == 0) | ||
4103 | return CY_AS_ERROR_INVALID_FUNCTION; | ||
4104 | |||
4105 | ret = cy_as_sdio_device_check((cy_as_device *)handle, bus, device); | ||
4106 | if (ret != CY_AS_ERROR_SUCCESS) | ||
4107 | return ret; | ||
4108 | |||
4109 | if (!(cy_as_sdio_check_function_initialized | ||
4110 | (handle, bus, n_function_no))) | ||
4111 | return CY_AS_ERROR_SUCCESS; | ||
4112 | |||
4113 | temp = (uint8_t)(((cy_as_device *)handle)->sdiocard[bus]. | ||
4114 | function_init_map & (~(1 << n_function_no))); | ||
4115 | |||
4116 | cy_as_sdio_direct_write(handle, bus, device, 0, 0x02, 0, temp, 0); | ||
4117 | |||
4118 | ((cy_as_device *)handle)->sdiocard[bus].function_init_map &= | ||
4119 | (~(1 << n_function_no)); | ||
4120 | |||
4121 | return CY_AS_ERROR_SUCCESS; | ||
4122 | } | ||
4123 | |||
4124 | |||
4125 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/api/src/cyasusb.c b/drivers/staging/westbridge/astoria/api/src/cyasusb.c deleted file mode 100644 index 1b55e611191e..000000000000 --- a/drivers/staging/westbridge/astoria/api/src/cyasusb.c +++ /dev/null | |||
@@ -1,3740 +0,0 @@ | |||
1 | /* Cypress West Bridge API source file (cyasusb.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #include "../../include/linux/westbridge/cyashal.h" | ||
23 | #include "../../include/linux/westbridge/cyasusb.h" | ||
24 | #include "../../include/linux/westbridge/cyaserr.h" | ||
25 | #include "../../include/linux/westbridge/cyasdma.h" | ||
26 | #include "../../include/linux/westbridge/cyaslowlevel.h" | ||
27 | #include "../../include/linux/westbridge/cyaslep2pep.h" | ||
28 | #include "../../include/linux/westbridge/cyasregs.h" | ||
29 | #include "../../include/linux/westbridge/cyasstorage.h" | ||
30 | |||
31 | static cy_as_return_status_t | ||
32 | cy_as_usb_ack_setup_packet( | ||
33 | /* Handle to the West Bridge device */ | ||
34 | cy_as_device_handle handle, | ||
35 | /* The callback if async call */ | ||
36 | cy_as_function_callback cb, | ||
37 | /* Client supplied data */ | ||
38 | uint32_t client | ||
39 | ); | ||
40 | |||
41 | static void | ||
42 | cy_as_usb_func_callback( | ||
43 | cy_as_device *dev_p, | ||
44 | uint8_t context, | ||
45 | cy_as_ll_request_response *rqt, | ||
46 | cy_as_ll_request_response *resp, | ||
47 | cy_as_return_status_t ret); | ||
48 | /* | ||
49 | * Reset the USB EP0 state | ||
50 | */ | ||
51 | static void | ||
52 | cy_as_usb_reset_e_p0_state(cy_as_device *dev_p) | ||
53 | { | ||
54 | cy_as_log_debug_message(6, "cy_as_usb_reset_e_p0_state called"); | ||
55 | |||
56 | cy_as_device_clear_ack_delayed(dev_p); | ||
57 | cy_as_device_clear_setup_packet(dev_p); | ||
58 | if (cy_as_device_is_usb_async_pending(dev_p, 0)) | ||
59 | cy_as_usb_cancel_async((cy_as_device_handle)dev_p, 0); | ||
60 | |||
61 | dev_p->usb_pending_buffer = 0; | ||
62 | } | ||
63 | |||
64 | /* | ||
65 | * External function to map logical endpoints to physical endpoints | ||
66 | */ | ||
67 | static cy_as_return_status_t | ||
68 | is_usb_active(cy_as_device *dev_p) | ||
69 | { | ||
70 | if (!cy_as_device_is_configured(dev_p)) | ||
71 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
72 | |||
73 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
74 | return CY_AS_ERROR_NO_FIRMWARE; | ||
75 | |||
76 | if (dev_p->usb_count == 0) | ||
77 | return CY_AS_ERROR_NOT_RUNNING; | ||
78 | |||
79 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
80 | return CY_AS_ERROR_IN_SUSPEND; | ||
81 | |||
82 | return CY_AS_ERROR_SUCCESS; | ||
83 | } | ||
84 | |||
85 | static void | ||
86 | usb_ack_callback(cy_as_device_handle h, | ||
87 | cy_as_return_status_t status, | ||
88 | uint32_t client, | ||
89 | cy_as_funct_c_b_type type, | ||
90 | void *data) | ||
91 | { | ||
92 | cy_as_device *dev_p = (cy_as_device *)h; | ||
93 | |||
94 | (void)client; | ||
95 | (void)status; | ||
96 | (void)data; | ||
97 | |||
98 | cy_as_hal_assert(type == CY_FUNCT_CB_NODATA); | ||
99 | |||
100 | if (dev_p->usb_pending_buffer) { | ||
101 | cy_as_usb_io_callback cb; | ||
102 | |||
103 | cb = dev_p->usb_cb[0]; | ||
104 | dev_p->usb_cb[0] = 0; | ||
105 | cy_as_device_clear_usb_async_pending(dev_p, 0); | ||
106 | if (cb) | ||
107 | cb(h, 0, dev_p->usb_pending_size, | ||
108 | dev_p->usb_pending_buffer, dev_p->usb_error); | ||
109 | |||
110 | dev_p->usb_pending_buffer = 0; | ||
111 | } | ||
112 | |||
113 | cy_as_device_clear_setup_packet(dev_p); | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | my_usb_request_callback_usb_event(cy_as_device *dev_p, | ||
118 | cy_as_ll_request_response *req_p) | ||
119 | { | ||
120 | uint16_t ev; | ||
121 | uint16_t val; | ||
122 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
123 | |||
124 | ev = cy_as_ll_request_response__get_word(req_p, 0); | ||
125 | switch (ev) { | ||
126 | case 0: /* Reserved */ | ||
127 | cy_as_ll_send_status_response(dev_p, CY_RQT_USB_RQT_CONTEXT, | ||
128 | CY_AS_ERROR_INVALID_REQUEST, 0); | ||
129 | break; | ||
130 | |||
131 | case 1: /* Reserved */ | ||
132 | cy_as_ll_send_status_response(dev_p, CY_RQT_USB_RQT_CONTEXT, | ||
133 | CY_AS_ERROR_INVALID_REQUEST, 0); | ||
134 | break; | ||
135 | |||
136 | case 2: /* USB Suspend */ | ||
137 | dev_p->usb_last_event = cy_as_event_usb_suspend; | ||
138 | if (dev_p->usb_event_cb_ms) | ||
139 | dev_p->usb_event_cb_ms(h, cy_as_event_usb_suspend, 0); | ||
140 | else if (dev_p->usb_event_cb) | ||
141 | dev_p->usb_event_cb(h, cy_as_event_usb_suspend, 0); | ||
142 | cy_as_ll_send_status_response(dev_p, | ||
143 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
144 | break; | ||
145 | |||
146 | case 3: /* USB Resume */ | ||
147 | dev_p->usb_last_event = cy_as_event_usb_resume; | ||
148 | if (dev_p->usb_event_cb_ms) | ||
149 | dev_p->usb_event_cb_ms(h, cy_as_event_usb_resume, 0); | ||
150 | else if (dev_p->usb_event_cb) | ||
151 | dev_p->usb_event_cb(h, cy_as_event_usb_resume, 0); | ||
152 | cy_as_ll_send_status_response(dev_p, | ||
153 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
154 | break; | ||
155 | |||
156 | case 4: /* USB Reset */ | ||
157 | /* | ||
158 | * if we get a USB reset, the USB host did not understand | ||
159 | * our response or we timed out for some reason. reset | ||
160 | * our internal state to be ready for another set of | ||
161 | * enumeration based requests. | ||
162 | */ | ||
163 | if (cy_as_device_is_ack_delayed(dev_p)) | ||
164 | cy_as_usb_reset_e_p0_state(dev_p); | ||
165 | |||
166 | dev_p->usb_last_event = cy_as_event_usb_reset; | ||
167 | if (dev_p->usb_event_cb_ms) | ||
168 | dev_p->usb_event_cb_ms(h, cy_as_event_usb_reset, 0); | ||
169 | else if (dev_p->usb_event_cb) | ||
170 | dev_p->usb_event_cb(h, cy_as_event_usb_reset, 0); | ||
171 | |||
172 | cy_as_ll_send_status_response(dev_p, | ||
173 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
174 | cy_as_device_clear_usb_high_speed(dev_p); | ||
175 | cy_as_usb_set_dma_sizes(dev_p); | ||
176 | dev_p->usb_max_tx_size = 0x40; | ||
177 | cy_as_dma_set_max_dma_size(dev_p, 0x06, 0x40); | ||
178 | break; | ||
179 | |||
180 | case 5: /* USB Set Configuration */ | ||
181 | /* The configuration to set */ | ||
182 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
183 | dev_p->usb_last_event = cy_as_event_usb_set_config; | ||
184 | if (dev_p->usb_event_cb_ms) | ||
185 | dev_p->usb_event_cb_ms(h, | ||
186 | cy_as_event_usb_set_config, &val); | ||
187 | else if (dev_p->usb_event_cb) | ||
188 | dev_p->usb_event_cb(h, | ||
189 | cy_as_event_usb_set_config, &val); | ||
190 | |||
191 | cy_as_ll_send_status_response(dev_p, | ||
192 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
193 | break; | ||
194 | |||
195 | case 6: /* USB Speed change */ | ||
196 | /* Connect speed */ | ||
197 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
198 | dev_p->usb_last_event = cy_as_event_usb_speed_change; | ||
199 | if (dev_p->usb_event_cb_ms) | ||
200 | dev_p->usb_event_cb_ms(h, | ||
201 | cy_as_event_usb_speed_change, &val); | ||
202 | else if (dev_p->usb_event_cb) | ||
203 | dev_p->usb_event_cb(h, | ||
204 | cy_as_event_usb_speed_change, &val); | ||
205 | |||
206 | cy_as_ll_send_status_response(dev_p, | ||
207 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
208 | cy_as_device_set_usb_high_speed(dev_p); | ||
209 | cy_as_usb_set_dma_sizes(dev_p); | ||
210 | dev_p->usb_max_tx_size = 0x200; | ||
211 | cy_as_dma_set_max_dma_size(dev_p, 0x06, 0x200); | ||
212 | break; | ||
213 | |||
214 | case 7: /* USB Clear Feature */ | ||
215 | /* EP Number */ | ||
216 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
217 | if (dev_p->usb_event_cb_ms) | ||
218 | dev_p->usb_event_cb_ms(h, | ||
219 | cy_as_event_usb_clear_feature, &val); | ||
220 | if (dev_p->usb_event_cb) | ||
221 | dev_p->usb_event_cb(h, | ||
222 | cy_as_event_usb_clear_feature, &val); | ||
223 | |||
224 | cy_as_ll_send_status_response(dev_p, | ||
225 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
226 | break; | ||
227 | |||
228 | default: | ||
229 | cy_as_hal_print_message("invalid event type\n"); | ||
230 | cy_as_ll_send_data_response(dev_p, CY_RQT_USB_RQT_CONTEXT, | ||
231 | CY_RESP_USB_INVALID_EVENT, sizeof(ev), &ev); | ||
232 | break; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | static void | ||
237 | my_usb_request_callback_usb_data(cy_as_device *dev_p, | ||
238 | cy_as_ll_request_response *req_p) | ||
239 | { | ||
240 | cy_as_end_point_number_t ep; | ||
241 | uint8_t type; | ||
242 | uint16_t len; | ||
243 | uint16_t val; | ||
244 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
245 | |||
246 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
247 | ep = (cy_as_end_point_number_t)((val >> 13) & 0x01); | ||
248 | len = (val & 0x1ff); | ||
249 | |||
250 | cy_as_hal_assert(len <= 64); | ||
251 | cy_as_ll_request_response__unpack(req_p, | ||
252 | 1, len, dev_p->usb_ep_data); | ||
253 | |||
254 | type = (uint8_t)((val >> 14) & 0x03); | ||
255 | if (type == 0) { | ||
256 | if (cy_as_device_is_ack_delayed(dev_p)) { | ||
257 | /* | ||
258 | * A setup packet has arrived while we are | ||
259 | * processing a previous setup packet. reset | ||
260 | * our state with respect to EP0 to be ready | ||
261 | * to process the new packet. | ||
262 | */ | ||
263 | cy_as_usb_reset_e_p0_state(dev_p); | ||
264 | } | ||
265 | |||
266 | if (len != 8) | ||
267 | cy_as_ll_send_status_response(dev_p, | ||
268 | CY_RQT_USB_RQT_CONTEXT, | ||
269 | CY_AS_ERROR_INVALID_REQUEST, 0); | ||
270 | else { | ||
271 | cy_as_device_clear_ep0_stalled(dev_p); | ||
272 | cy_as_device_set_setup_packet(dev_p); | ||
273 | cy_as_ll_send_status_response(dev_p, | ||
274 | CY_RQT_USB_RQT_CONTEXT, | ||
275 | CY_AS_ERROR_SUCCESS, 0); | ||
276 | |||
277 | if (dev_p->usb_event_cb_ms) | ||
278 | dev_p->usb_event_cb_ms(h, | ||
279 | cy_as_event_usb_setup_packet, | ||
280 | dev_p->usb_ep_data); | ||
281 | else | ||
282 | dev_p->usb_event_cb(h, | ||
283 | cy_as_event_usb_setup_packet, | ||
284 | dev_p->usb_ep_data); | ||
285 | |||
286 | if ((!cy_as_device_is_ack_delayed(dev_p)) && | ||
287 | (!cy_as_device_is_ep0_stalled(dev_p))) | ||
288 | cy_as_usb_ack_setup_packet(h, | ||
289 | usb_ack_callback, 0); | ||
290 | } | ||
291 | } else if (type == 2) { | ||
292 | if (len != 0) | ||
293 | cy_as_ll_send_status_response(dev_p, | ||
294 | CY_RQT_USB_RQT_CONTEXT, | ||
295 | CY_AS_ERROR_INVALID_REQUEST, 0); | ||
296 | else { | ||
297 | if (dev_p->usb_event_cb_ms) | ||
298 | dev_p->usb_event_cb_ms(h, | ||
299 | cy_as_event_usb_status_packet, 0); | ||
300 | else | ||
301 | dev_p->usb_event_cb(h, | ||
302 | cy_as_event_usb_status_packet, 0); | ||
303 | |||
304 | cy_as_ll_send_status_response(dev_p, | ||
305 | CY_RQT_USB_RQT_CONTEXT, | ||
306 | CY_AS_ERROR_SUCCESS, 0); | ||
307 | } | ||
308 | } else if (type == 1) { | ||
309 | /* | ||
310 | * we need to hand the data associated with these | ||
311 | * endpoints to the DMA module. | ||
312 | */ | ||
313 | cy_as_dma_received_data(dev_p, ep, len, dev_p->usb_ep_data); | ||
314 | cy_as_ll_send_status_response(dev_p, | ||
315 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | static void | ||
320 | my_usb_request_callback_inquiry(cy_as_device *dev_p, | ||
321 | cy_as_ll_request_response *req_p) | ||
322 | { | ||
323 | cy_as_usb_inquiry_data_dep cbdata; | ||
324 | cy_as_usb_inquiry_data cbdata_ms; | ||
325 | void *data; | ||
326 | uint16_t val; | ||
327 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
328 | uint8_t def_inq_data[64]; | ||
329 | uint8_t evpd; | ||
330 | uint8_t codepage; | ||
331 | cy_bool updated; | ||
332 | uint16_t length; | ||
333 | |||
334 | cy_as_bus_number_t bus; | ||
335 | uint32_t device; | ||
336 | cy_as_media_type media; | ||
337 | |||
338 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
339 | bus = cy_as_storage_get_bus_from_address(val); | ||
340 | device = cy_as_storage_get_device_from_address(val); | ||
341 | media = cy_as_storage_get_media_from_address(val); | ||
342 | |||
343 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
344 | evpd = (uint8_t)((val >> 8) & 0x01); | ||
345 | codepage = (uint8_t)(val & 0xff); | ||
346 | |||
347 | length = cy_as_ll_request_response__get_word(req_p, 2); | ||
348 | data = (void *)def_inq_data; | ||
349 | |||
350 | updated = cy_false; | ||
351 | |||
352 | if (dev_p->usb_event_cb_ms) { | ||
353 | cbdata_ms.bus = bus; | ||
354 | cbdata_ms.device = device; | ||
355 | cbdata_ms.updated = updated; | ||
356 | cbdata_ms.evpd = evpd; | ||
357 | cbdata_ms.codepage = codepage; | ||
358 | cbdata_ms.length = length; | ||
359 | cbdata_ms.data = data; | ||
360 | |||
361 | cy_as_hal_assert(cbdata_ms.length <= sizeof(def_inq_data)); | ||
362 | cy_as_ll_request_response__unpack(req_p, | ||
363 | 3, cbdata_ms.length, cbdata_ms.data); | ||
364 | |||
365 | dev_p->usb_event_cb_ms(h, | ||
366 | cy_as_event_usb_inquiry_before, &cbdata_ms); | ||
367 | |||
368 | updated = cbdata_ms.updated; | ||
369 | data = cbdata_ms.data; | ||
370 | length = cbdata_ms.length; | ||
371 | } else if (dev_p->usb_event_cb) { | ||
372 | cbdata.media = media; | ||
373 | cbdata.updated = updated; | ||
374 | cbdata.evpd = evpd; | ||
375 | cbdata.codepage = codepage; | ||
376 | cbdata.length = length; | ||
377 | cbdata.data = data; | ||
378 | |||
379 | cy_as_hal_assert(cbdata.length <= | ||
380 | sizeof(def_inq_data)); | ||
381 | cy_as_ll_request_response__unpack(req_p, 3, | ||
382 | cbdata.length, cbdata.data); | ||
383 | |||
384 | dev_p->usb_event_cb(h, | ||
385 | cy_as_event_usb_inquiry_before, &cbdata); | ||
386 | |||
387 | updated = cbdata.updated; | ||
388 | data = cbdata.data; | ||
389 | length = cbdata.length; | ||
390 | } | ||
391 | |||
392 | if (updated && length > 192) | ||
393 | cy_as_hal_print_message("an inquiry result from a " | ||
394 | "cy_as_event_usb_inquiry_before event " | ||
395 | "was greater than 192 bytes."); | ||
396 | |||
397 | /* Now send the reply with the data back | ||
398 | * to the West Bridge device */ | ||
399 | if (updated && length <= 192) { | ||
400 | /* | ||
401 | * the callback function modified the inquiry | ||
402 | * data, ship the data back to the west bridge firmware. | ||
403 | */ | ||
404 | cy_as_ll_send_data_response(dev_p, | ||
405 | CY_RQT_USB_RQT_CONTEXT, | ||
406 | CY_RESP_INQUIRY_DATA, length, data); | ||
407 | } else { | ||
408 | /* | ||
409 | * the callback did not modify the data, just acknowledge | ||
410 | * that we processed the request | ||
411 | */ | ||
412 | cy_as_ll_send_status_response(dev_p, | ||
413 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 1); | ||
414 | } | ||
415 | |||
416 | if (dev_p->usb_event_cb_ms) | ||
417 | dev_p->usb_event_cb_ms(h, | ||
418 | cy_as_event_usb_inquiry_after, &cbdata_ms); | ||
419 | else if (dev_p->usb_event_cb) | ||
420 | dev_p->usb_event_cb(h, | ||
421 | cy_as_event_usb_inquiry_after, &cbdata); | ||
422 | } | ||
423 | |||
424 | static void | ||
425 | my_usb_request_callback_start_stop(cy_as_device *dev_p, | ||
426 | cy_as_ll_request_response *req_p) | ||
427 | { | ||
428 | cy_as_bus_number_t bus; | ||
429 | cy_as_media_type media; | ||
430 | uint32_t device; | ||
431 | uint16_t val; | ||
432 | |||
433 | if (dev_p->usb_event_cb_ms || dev_p->usb_event_cb) { | ||
434 | cy_bool loej; | ||
435 | cy_bool start; | ||
436 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
437 | |||
438 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
439 | bus = cy_as_storage_get_bus_from_address(val); | ||
440 | device = cy_as_storage_get_device_from_address(val); | ||
441 | media = cy_as_storage_get_media_from_address(val); | ||
442 | |||
443 | val = cy_as_ll_request_response__get_word(req_p, 1); | ||
444 | loej = (val & 0x02) ? cy_true : cy_false; | ||
445 | start = (val & 0x01) ? cy_true : cy_false; | ||
446 | |||
447 | if (dev_p->usb_event_cb_ms) { | ||
448 | cy_as_usb_start_stop_data cbdata_ms; | ||
449 | |||
450 | cbdata_ms.bus = bus; | ||
451 | cbdata_ms.device = device; | ||
452 | cbdata_ms.loej = loej; | ||
453 | cbdata_ms.start = start; | ||
454 | dev_p->usb_event_cb_ms(h, | ||
455 | cy_as_event_usb_start_stop, &cbdata_ms); | ||
456 | |||
457 | } else if (dev_p->usb_event_cb) { | ||
458 | cy_as_usb_start_stop_data_dep cbdata; | ||
459 | |||
460 | cbdata.media = media; | ||
461 | cbdata.loej = loej; | ||
462 | cbdata.start = start; | ||
463 | dev_p->usb_event_cb(h, | ||
464 | cy_as_event_usb_start_stop, &cbdata); | ||
465 | } | ||
466 | } | ||
467 | cy_as_ll_send_status_response(dev_p, | ||
468 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 1); | ||
469 | } | ||
470 | |||
471 | static void | ||
472 | my_usb_request_callback_uknown_c_b_w(cy_as_device *dev_p, | ||
473 | cy_as_ll_request_response *req_p) | ||
474 | { | ||
475 | uint16_t val; | ||
476 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
477 | uint8_t buf[16]; | ||
478 | |||
479 | uint8_t response[4]; | ||
480 | uint16_t reqlen; | ||
481 | void *request; | ||
482 | uint8_t status; | ||
483 | uint8_t key; | ||
484 | uint8_t asc; | ||
485 | uint8_t ascq; | ||
486 | |||
487 | val = cy_as_ll_request_response__get_word(req_p, 0); | ||
488 | /* Failed by default */ | ||
489 | status = 1; | ||
490 | /* Invalid command */ | ||
491 | key = 0x05; | ||
492 | /* Invalid command */ | ||
493 | asc = 0x20; | ||
494 | /* Invalid command */ | ||
495 | ascq = 0x00; | ||
496 | reqlen = cy_as_ll_request_response__get_word(req_p, 1); | ||
497 | request = buf; | ||
498 | |||
499 | cy_as_hal_assert(reqlen <= sizeof(buf)); | ||
500 | cy_as_ll_request_response__unpack(req_p, 2, reqlen, request); | ||
501 | |||
502 | if (dev_p->usb_event_cb_ms) { | ||
503 | cy_as_usb_unknown_command_data cbdata_ms; | ||
504 | cbdata_ms.bus = cy_as_storage_get_bus_from_address(val); | ||
505 | cbdata_ms.device = | ||
506 | cy_as_storage_get_device_from_address(val); | ||
507 | cbdata_ms.reqlen = reqlen; | ||
508 | cbdata_ms.request = request; | ||
509 | cbdata_ms.status = status; | ||
510 | cbdata_ms.key = key; | ||
511 | cbdata_ms.asc = asc; | ||
512 | cbdata_ms.ascq = ascq; | ||
513 | |||
514 | dev_p->usb_event_cb_ms(h, | ||
515 | cy_as_event_usb_unknown_storage, &cbdata_ms); | ||
516 | status = cbdata_ms.status; | ||
517 | key = cbdata_ms.key; | ||
518 | asc = cbdata_ms.asc; | ||
519 | ascq = cbdata_ms.ascq; | ||
520 | } else if (dev_p->usb_event_cb) { | ||
521 | cy_as_usb_unknown_command_data_dep cbdata; | ||
522 | cbdata.media = | ||
523 | cy_as_storage_get_media_from_address(val); | ||
524 | cbdata.reqlen = reqlen; | ||
525 | cbdata.request = request; | ||
526 | cbdata.status = status; | ||
527 | cbdata.key = key; | ||
528 | cbdata.asc = asc; | ||
529 | cbdata.ascq = ascq; | ||
530 | |||
531 | dev_p->usb_event_cb(h, | ||
532 | cy_as_event_usb_unknown_storage, &cbdata); | ||
533 | status = cbdata.status; | ||
534 | key = cbdata.key; | ||
535 | asc = cbdata.asc; | ||
536 | ascq = cbdata.ascq; | ||
537 | } | ||
538 | |||
539 | response[0] = status; | ||
540 | response[1] = key; | ||
541 | response[2] = asc; | ||
542 | response[3] = ascq; | ||
543 | cy_as_ll_send_data_response(dev_p, CY_RQT_USB_RQT_CONTEXT, | ||
544 | CY_RESP_UNKNOWN_SCSI_COMMAND, sizeof(response), response); | ||
545 | } | ||
546 | |||
547 | static void | ||
548 | my_usb_request_callback_m_s_c_progress(cy_as_device *dev_p, | ||
549 | cy_as_ll_request_response *req_p) | ||
550 | { | ||
551 | uint16_t val1, val2; | ||
552 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
553 | |||
554 | if ((dev_p->usb_event_cb) || (dev_p->usb_event_cb_ms)) { | ||
555 | cy_as_m_s_c_progress_data cbdata; | ||
556 | |||
557 | val1 = cy_as_ll_request_response__get_word(req_p, 0); | ||
558 | val2 = cy_as_ll_request_response__get_word(req_p, 1); | ||
559 | cbdata.wr_count = (uint32_t)((val1 << 16) | val2); | ||
560 | |||
561 | val1 = cy_as_ll_request_response__get_word(req_p, 2); | ||
562 | val2 = cy_as_ll_request_response__get_word(req_p, 3); | ||
563 | cbdata.rd_count = (uint32_t)((val1 << 16) | val2); | ||
564 | |||
565 | if (dev_p->usb_event_cb) | ||
566 | dev_p->usb_event_cb(h, | ||
567 | cy_as_event_usb_m_s_c_progress, &cbdata); | ||
568 | else | ||
569 | dev_p->usb_event_cb_ms(h, | ||
570 | cy_as_event_usb_m_s_c_progress, &cbdata); | ||
571 | } | ||
572 | |||
573 | cy_as_ll_send_status_response(dev_p, | ||
574 | CY_RQT_USB_RQT_CONTEXT, CY_AS_ERROR_SUCCESS, 0); | ||
575 | } | ||
576 | |||
577 | /* | ||
578 | * This function processes the requests delivered from the | ||
579 | * firmware within the West Bridge device that are delivered | ||
580 | * in the USB context. These requests generally are EP0 and | ||
581 | * EP1 related requests or USB events. | ||
582 | */ | ||
583 | static void | ||
584 | my_usb_request_callback(cy_as_device *dev_p, uint8_t context, | ||
585 | cy_as_ll_request_response *req_p, | ||
586 | cy_as_ll_request_response *resp_p, | ||
587 | cy_as_return_status_t ret) | ||
588 | { | ||
589 | uint16_t val; | ||
590 | uint8_t code = cy_as_ll_request_response__get_code(req_p); | ||
591 | |||
592 | (void)resp_p; | ||
593 | (void)context; | ||
594 | (void)ret; | ||
595 | |||
596 | switch (code) { | ||
597 | case CY_RQT_USB_EVENT: | ||
598 | my_usb_request_callback_usb_event(dev_p, req_p); | ||
599 | break; | ||
600 | |||
601 | case CY_RQT_USB_EP_DATA: | ||
602 | dev_p->usb_last_event = cy_as_event_usb_setup_packet; | ||
603 | my_usb_request_callback_usb_data(dev_p, req_p); | ||
604 | break; | ||
605 | |||
606 | case CY_RQT_SCSI_INQUIRY_COMMAND: | ||
607 | dev_p->usb_last_event = cy_as_event_usb_inquiry_after; | ||
608 | my_usb_request_callback_inquiry(dev_p, req_p); | ||
609 | break; | ||
610 | |||
611 | case CY_RQT_SCSI_START_STOP_COMMAND: | ||
612 | dev_p->usb_last_event = cy_as_event_usb_start_stop; | ||
613 | my_usb_request_callback_start_stop(dev_p, req_p); | ||
614 | break; | ||
615 | |||
616 | case CY_RQT_SCSI_UNKNOWN_COMMAND: | ||
617 | dev_p->usb_last_event = cy_as_event_usb_unknown_storage; | ||
618 | my_usb_request_callback_uknown_c_b_w(dev_p, req_p); | ||
619 | break; | ||
620 | |||
621 | case CY_RQT_USB_ACTIVITY_UPDATE: | ||
622 | dev_p->usb_last_event = cy_as_event_usb_m_s_c_progress; | ||
623 | my_usb_request_callback_m_s_c_progress(dev_p, req_p); | ||
624 | break; | ||
625 | |||
626 | default: | ||
627 | cy_as_hal_print_message("invalid request " | ||
628 | "received on USB context\n"); | ||
629 | val = req_p->box0; | ||
630 | cy_as_ll_send_data_response(dev_p, CY_RQT_USB_RQT_CONTEXT, | ||
631 | CY_RESP_INVALID_REQUEST, sizeof(val), &val); | ||
632 | break; | ||
633 | } | ||
634 | } | ||
635 | |||
636 | static cy_as_return_status_t | ||
637 | my_handle_response_usb_start(cy_as_device *dev_p, | ||
638 | cy_as_ll_request_response *req_p, | ||
639 | cy_as_ll_request_response *reply_p, | ||
640 | cy_as_return_status_t ret) | ||
641 | { | ||
642 | if (ret != CY_AS_ERROR_SUCCESS) | ||
643 | goto destroy; | ||
644 | |||
645 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
646 | CY_RESP_SUCCESS_FAILURE) { | ||
647 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
648 | goto destroy; | ||
649 | } | ||
650 | |||
651 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
652 | if (ret != CY_AS_ERROR_SUCCESS) | ||
653 | goto destroy; | ||
654 | |||
655 | /* | ||
656 | * mark EP 0 and EP1 as 64 byte endpoints | ||
657 | */ | ||
658 | cy_as_dma_set_max_dma_size(dev_p, 0, 64); | ||
659 | cy_as_dma_set_max_dma_size(dev_p, 1, 64); | ||
660 | |||
661 | dev_p->usb_count++; | ||
662 | |||
663 | destroy: | ||
664 | cy_as_ll_destroy_request(dev_p, req_p); | ||
665 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
666 | |||
667 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
668 | cy_as_destroy_c_b_queue(dev_p->usb_func_cbs); | ||
669 | cy_as_ll_register_request_callback(dev_p, | ||
670 | CY_RQT_USB_RQT_CONTEXT, 0); | ||
671 | } | ||
672 | |||
673 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
674 | |||
675 | return ret; | ||
676 | |||
677 | } | ||
678 | |||
679 | /* | ||
680 | * This function starts the USB stack. The stack is reference | ||
681 | * counted so if the stack is already started, this function | ||
682 | * just increments the count. If the stack has not been started, | ||
683 | * a start request is sent to the West Bridge device. | ||
684 | * | ||
685 | * Note: Starting the USB stack does not cause the USB signals | ||
686 | * to be connected to the USB pins. To do this and therefore | ||
687 | * initiate enumeration, CyAsUsbConnect() must be called. | ||
688 | */ | ||
689 | cy_as_return_status_t | ||
690 | cy_as_usb_start(cy_as_device_handle handle, | ||
691 | cy_as_function_callback cb, | ||
692 | uint32_t client) | ||
693 | { | ||
694 | cy_as_ll_request_response *req_p, *reply_p; | ||
695 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
696 | |||
697 | cy_as_device *dev_p; | ||
698 | |||
699 | cy_as_log_debug_message(6, "cy_as_usb_start called"); | ||
700 | |||
701 | dev_p = (cy_as_device *)handle; | ||
702 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
703 | return CY_AS_ERROR_INVALID_HANDLE; | ||
704 | |||
705 | if (!cy_as_device_is_configured(dev_p)) | ||
706 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
707 | |||
708 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
709 | return CY_AS_ERROR_NO_FIRMWARE; | ||
710 | |||
711 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
712 | return CY_AS_ERROR_IN_SUSPEND; | ||
713 | |||
714 | if (cy_as_device_is_in_callback(dev_p)) | ||
715 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
716 | |||
717 | if (cy_as_device_is_u_s_s_pending(dev_p)) | ||
718 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
719 | |||
720 | cy_as_device_set_u_s_s_pending(dev_p); | ||
721 | |||
722 | if (dev_p->usb_count == 0) { | ||
723 | /* | ||
724 | * since we are just starting the stack, | ||
725 | * mark USB as not connected to the remote host | ||
726 | */ | ||
727 | cy_as_device_clear_usb_connected(dev_p); | ||
728 | dev_p->usb_phy_config = 0; | ||
729 | |||
730 | /* Queue for 1.0 Async Requests, kept for | ||
731 | * backwards compatibility */ | ||
732 | dev_p->usb_func_cbs = cy_as_create_c_b_queue(CYAS_USB_FUNC_CB); | ||
733 | if (dev_p->usb_func_cbs == 0) { | ||
734 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
735 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
736 | } | ||
737 | |||
738 | /* Reset the EP0 state */ | ||
739 | cy_as_usb_reset_e_p0_state(dev_p); | ||
740 | |||
741 | /* | ||
742 | * we register here because the start request may cause | ||
743 | * events to occur before the response to the start request. | ||
744 | */ | ||
745 | cy_as_ll_register_request_callback(dev_p, | ||
746 | CY_RQT_USB_RQT_CONTEXT, my_usb_request_callback); | ||
747 | |||
748 | /* Create the request to send to the West Bridge device */ | ||
749 | req_p = cy_as_ll_create_request(dev_p, | ||
750 | CY_RQT_START_USB, CY_RQT_USB_RQT_CONTEXT, 0); | ||
751 | if (req_p == 0) { | ||
752 | cy_as_destroy_c_b_queue(dev_p->usb_func_cbs); | ||
753 | dev_p->usb_func_cbs = 0; | ||
754 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
755 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
756 | } | ||
757 | |||
758 | /* Reserve space for the reply, the reply data | ||
759 | * will not exceed one word */ | ||
760 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
761 | if (reply_p == 0) { | ||
762 | cy_as_destroy_c_b_queue(dev_p->usb_func_cbs); | ||
763 | dev_p->usb_func_cbs = 0; | ||
764 | cy_as_ll_destroy_request(dev_p, req_p); | ||
765 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
766 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
767 | } | ||
768 | |||
769 | if (cb == 0) { | ||
770 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
771 | req_p, reply_p); | ||
772 | if (ret != CY_AS_ERROR_SUCCESS) | ||
773 | goto destroy; | ||
774 | |||
775 | return my_handle_response_usb_start(dev_p, | ||
776 | req_p, reply_p, ret); | ||
777 | } else { | ||
778 | ret = cy_as_misc_send_request(dev_p, cb, | ||
779 | client, CY_FUNCT_CB_USB_START, 0, | ||
780 | dev_p->func_cbs_usb, | ||
781 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
782 | cy_as_usb_func_callback); | ||
783 | |||
784 | if (ret != CY_AS_ERROR_SUCCESS) | ||
785 | goto destroy; | ||
786 | |||
787 | return ret; | ||
788 | } | ||
789 | |||
790 | destroy: | ||
791 | cy_as_ll_destroy_request(dev_p, req_p); | ||
792 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
793 | } else { | ||
794 | dev_p->usb_count++; | ||
795 | if (cb) | ||
796 | cb(handle, ret, client, CY_FUNCT_CB_USB_START, 0); | ||
797 | } | ||
798 | |||
799 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
800 | |||
801 | return ret; | ||
802 | } | ||
803 | EXPORT_SYMBOL(cy_as_usb_start); | ||
804 | |||
805 | void | ||
806 | cy_as_usb_reset(cy_as_device *dev_p) | ||
807 | { | ||
808 | int i; | ||
809 | |||
810 | cy_as_device_clear_usb_connected(dev_p); | ||
811 | |||
812 | for (i = 0; i < sizeof(dev_p->usb_config) / | ||
813 | sizeof(dev_p->usb_config[0]); i++) { | ||
814 | /* | ||
815 | * cancel all pending USB read/write operations, as it is | ||
816 | * possible that the USB stack comes up in a different | ||
817 | * configuration with a different set of endpoints. | ||
818 | */ | ||
819 | if (cy_as_device_is_usb_async_pending(dev_p, i)) | ||
820 | cy_as_usb_cancel_async(dev_p, | ||
821 | (cy_as_end_point_number_t)i); | ||
822 | |||
823 | dev_p->usb_cb[i] = 0; | ||
824 | dev_p->usb_config[i].enabled = cy_false; | ||
825 | } | ||
826 | |||
827 | dev_p->usb_phy_config = 0; | ||
828 | } | ||
829 | |||
830 | /* | ||
831 | * This function does all the API side clean-up associated | ||
832 | * with CyAsUsbStop, without any communication with firmware. | ||
833 | * This needs to be done when the device is being reset while | ||
834 | * the USB stack is active. | ||
835 | */ | ||
836 | void | ||
837 | cy_as_usb_cleanup(cy_as_device *dev_p) | ||
838 | { | ||
839 | if (dev_p->usb_count) { | ||
840 | cy_as_usb_reset_e_p0_state(dev_p); | ||
841 | cy_as_usb_reset(dev_p); | ||
842 | cy_as_hal_mem_set(dev_p->usb_config, 0, | ||
843 | sizeof(dev_p->usb_config)); | ||
844 | cy_as_destroy_c_b_queue(dev_p->usb_func_cbs); | ||
845 | |||
846 | dev_p->usb_count = 0; | ||
847 | } | ||
848 | } | ||
849 | |||
850 | static cy_as_return_status_t | ||
851 | my_handle_response_usb_stop(cy_as_device *dev_p, | ||
852 | cy_as_ll_request_response *req_p, | ||
853 | cy_as_ll_request_response *reply_p, | ||
854 | cy_as_return_status_t ret) | ||
855 | { | ||
856 | if (ret != CY_AS_ERROR_SUCCESS) | ||
857 | goto destroy; | ||
858 | |||
859 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
860 | CY_RESP_SUCCESS_FAILURE) { | ||
861 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
862 | goto destroy; | ||
863 | } | ||
864 | |||
865 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
866 | if (ret != CY_AS_ERROR_SUCCESS) | ||
867 | goto destroy; | ||
868 | |||
869 | /* | ||
870 | * we successfully shutdown the stack, so | ||
871 | * decrement to make the count zero. | ||
872 | */ | ||
873 | cy_as_usb_cleanup(dev_p); | ||
874 | |||
875 | destroy: | ||
876 | cy_as_ll_destroy_request(dev_p, req_p); | ||
877 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
878 | |||
879 | if (ret != CY_AS_ERROR_SUCCESS) | ||
880 | cy_as_ll_register_request_callback(dev_p, | ||
881 | CY_RQT_USB_RQT_CONTEXT, 0); | ||
882 | |||
883 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
884 | |||
885 | return ret; | ||
886 | } | ||
887 | |||
888 | /* | ||
889 | * This function stops the USB stack. The USB stack is reference | ||
890 | * counted so first is reference count is decremented. If the | ||
891 | * reference count is then zero, a request is sent to the West | ||
892 | * Bridge device to stop the USB stack on the West Bridge device. | ||
893 | */ | ||
894 | cy_as_return_status_t | ||
895 | cy_as_usb_stop(cy_as_device_handle handle, | ||
896 | cy_as_function_callback cb, | ||
897 | uint32_t client) | ||
898 | { | ||
899 | cy_as_ll_request_response *req_p = 0, *reply_p = 0; | ||
900 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
901 | |||
902 | cy_as_device *dev_p; | ||
903 | |||
904 | cy_as_log_debug_message(6, "cy_as_usb_stop called"); | ||
905 | |||
906 | dev_p = (cy_as_device *)handle; | ||
907 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
908 | return CY_AS_ERROR_INVALID_HANDLE; | ||
909 | |||
910 | ret = is_usb_active(dev_p); | ||
911 | if (ret != CY_AS_ERROR_SUCCESS) | ||
912 | return ret; | ||
913 | |||
914 | if (cy_as_device_is_usb_connected(dev_p)) | ||
915 | return CY_AS_ERROR_USB_CONNECTED; | ||
916 | |||
917 | if (cy_as_device_is_in_callback(dev_p)) | ||
918 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
919 | |||
920 | if (cy_as_device_is_u_s_s_pending(dev_p)) | ||
921 | return CY_AS_ERROR_STARTSTOP_PENDING; | ||
922 | |||
923 | cy_as_device_set_u_s_s_pending(dev_p); | ||
924 | |||
925 | if (dev_p->usb_count == 1) { | ||
926 | /* Create the request to send to the West Bridge device */ | ||
927 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_STOP_USB, | ||
928 | CY_RQT_USB_RQT_CONTEXT, 0); | ||
929 | if (req_p == 0) { | ||
930 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
931 | goto destroy; | ||
932 | } | ||
933 | |||
934 | /* Reserve space for the reply, the reply data will not | ||
935 | * exceed one word */ | ||
936 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
937 | if (reply_p == 0) { | ||
938 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
939 | goto destroy; | ||
940 | } | ||
941 | |||
942 | if (cb == 0) { | ||
943 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
944 | req_p, reply_p); | ||
945 | if (ret != CY_AS_ERROR_SUCCESS) | ||
946 | goto destroy; | ||
947 | |||
948 | return my_handle_response_usb_stop(dev_p, | ||
949 | req_p, reply_p, ret); | ||
950 | } else { | ||
951 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
952 | CY_FUNCT_CB_USB_STOP, 0, dev_p->func_cbs_usb, | ||
953 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
954 | cy_as_usb_func_callback); | ||
955 | |||
956 | if (ret != CY_AS_ERROR_SUCCESS) | ||
957 | goto destroy; | ||
958 | |||
959 | return ret; | ||
960 | } | ||
961 | |||
962 | destroy: | ||
963 | cy_as_ll_destroy_request(dev_p, req_p); | ||
964 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
965 | } else if (dev_p->usb_count > 1) { | ||
966 | /* | ||
967 | * reset all LE_ps to inactive state, after cleaning | ||
968 | * up any pending async read/write calls. | ||
969 | */ | ||
970 | cy_as_usb_reset(dev_p); | ||
971 | dev_p->usb_count--; | ||
972 | |||
973 | if (cb) | ||
974 | cb(handle, ret, client, CY_FUNCT_CB_USB_STOP, 0); | ||
975 | } | ||
976 | |||
977 | cy_as_device_clear_u_s_s_pending(dev_p); | ||
978 | |||
979 | return ret; | ||
980 | } | ||
981 | EXPORT_SYMBOL(cy_as_usb_stop); | ||
982 | |||
983 | /* | ||
984 | * This function registers a callback to be called when | ||
985 | * USB events are processed | ||
986 | */ | ||
987 | cy_as_return_status_t | ||
988 | cy_as_usb_register_callback(cy_as_device_handle handle, | ||
989 | cy_as_usb_event_callback callback) | ||
990 | { | ||
991 | cy_as_device *dev_p; | ||
992 | |||
993 | cy_as_log_debug_message(6, "cy_as_usb_register_callback called"); | ||
994 | |||
995 | dev_p = (cy_as_device *)handle; | ||
996 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
997 | return CY_AS_ERROR_INVALID_HANDLE; | ||
998 | |||
999 | if (!cy_as_device_is_configured(dev_p)) | ||
1000 | return CY_AS_ERROR_NOT_CONFIGURED; | ||
1001 | |||
1002 | if (!cy_as_device_is_firmware_loaded(dev_p)) | ||
1003 | return CY_AS_ERROR_NO_FIRMWARE; | ||
1004 | |||
1005 | dev_p->usb_event_cb = NULL; | ||
1006 | dev_p->usb_event_cb_ms = callback; | ||
1007 | return CY_AS_ERROR_SUCCESS; | ||
1008 | } | ||
1009 | EXPORT_SYMBOL(cy_as_usb_register_callback); | ||
1010 | |||
1011 | static cy_as_return_status_t | ||
1012 | my_handle_response_no_data(cy_as_device *dev_p, | ||
1013 | cy_as_ll_request_response *req_p, | ||
1014 | cy_as_ll_request_response *reply_p) | ||
1015 | { | ||
1016 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1017 | |||
1018 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1019 | CY_RESP_SUCCESS_FAILURE) | ||
1020 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1021 | else | ||
1022 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1023 | |||
1024 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1025 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1026 | |||
1027 | return ret; | ||
1028 | } | ||
1029 | |||
1030 | static cy_as_return_status_t | ||
1031 | my_handle_response_connect(cy_as_device *dev_p, | ||
1032 | cy_as_ll_request_response *req_p, | ||
1033 | cy_as_ll_request_response *reply_p, | ||
1034 | cy_as_return_status_t ret) | ||
1035 | { | ||
1036 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1037 | goto destroy; | ||
1038 | |||
1039 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1040 | CY_RESP_SUCCESS_FAILURE) { | ||
1041 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1042 | goto destroy; | ||
1043 | } | ||
1044 | |||
1045 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1046 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1047 | cy_as_device_set_usb_connected(dev_p); | ||
1048 | |||
1049 | destroy: | ||
1050 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1051 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1052 | |||
1053 | return ret; | ||
1054 | } | ||
1055 | |||
1056 | |||
1057 | /* | ||
1058 | * This method asks the West Bridge device to connect the | ||
1059 | * internal USB D+ and D- signals to the USB pins, thus | ||
1060 | * starting the enumeration processes if the external pins | ||
1061 | * are connected to a USB host. If the external pins are | ||
1062 | * not connected to a USB host, enumeration will begin as soon | ||
1063 | * as the USB pins are connected to a host. | ||
1064 | */ | ||
1065 | cy_as_return_status_t | ||
1066 | cy_as_usb_connect(cy_as_device_handle handle, | ||
1067 | cy_as_function_callback cb, | ||
1068 | uint32_t client) | ||
1069 | { | ||
1070 | cy_as_ll_request_response *req_p , *reply_p; | ||
1071 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1072 | |||
1073 | cy_as_device *dev_p; | ||
1074 | |||
1075 | cy_as_log_debug_message(6, "cy_as_usb_connect called"); | ||
1076 | |||
1077 | dev_p = (cy_as_device *)handle; | ||
1078 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1079 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1080 | |||
1081 | ret = is_usb_active(dev_p); | ||
1082 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1083 | return ret; | ||
1084 | |||
1085 | if (cy_as_device_is_in_callback(dev_p)) | ||
1086 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1087 | |||
1088 | /* Create the request to send to the West Bridge device */ | ||
1089 | req_p = cy_as_ll_create_request(dev_p, | ||
1090 | CY_RQT_SET_CONNECT_STATE, CY_RQT_USB_RQT_CONTEXT, 1); | ||
1091 | if (req_p == 0) | ||
1092 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1093 | |||
1094 | /* 1 = Connect request */ | ||
1095 | cy_as_ll_request_response__set_word(req_p, 0, 1); | ||
1096 | |||
1097 | /* Reserve space for the reply, the reply | ||
1098 | * data will not exceed one word */ | ||
1099 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1100 | if (reply_p == 0) { | ||
1101 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1102 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1103 | } | ||
1104 | |||
1105 | if (cb == 0) { | ||
1106 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1107 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1108 | goto destroy; | ||
1109 | |||
1110 | return my_handle_response_connect(dev_p, req_p, reply_p, ret); | ||
1111 | } else { | ||
1112 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1113 | CY_FUNCT_CB_USB_CONNECT, 0, dev_p->func_cbs_usb, | ||
1114 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1115 | cy_as_usb_func_callback); | ||
1116 | |||
1117 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1118 | goto destroy; | ||
1119 | |||
1120 | return ret; | ||
1121 | } | ||
1122 | |||
1123 | destroy: | ||
1124 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1125 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1126 | |||
1127 | return ret; | ||
1128 | } | ||
1129 | EXPORT_SYMBOL(cy_as_usb_connect); | ||
1130 | |||
1131 | static cy_as_return_status_t | ||
1132 | my_handle_response_disconnect(cy_as_device *dev_p, | ||
1133 | cy_as_ll_request_response *req_p, | ||
1134 | cy_as_ll_request_response *reply_p, | ||
1135 | cy_as_return_status_t ret) | ||
1136 | { | ||
1137 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1138 | goto destroy; | ||
1139 | |||
1140 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1141 | CY_RESP_SUCCESS_FAILURE) { | ||
1142 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1143 | goto destroy; | ||
1144 | } | ||
1145 | |||
1146 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1147 | if (ret == CY_AS_ERROR_SUCCESS) | ||
1148 | cy_as_device_clear_usb_connected(dev_p); | ||
1149 | |||
1150 | destroy: | ||
1151 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1152 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1153 | |||
1154 | return ret; | ||
1155 | } | ||
1156 | /* | ||
1157 | * This method forces a disconnect of the D+ and D- pins | ||
1158 | * external to the West Bridge device from the D+ and D- | ||
1159 | * signals internally, effectively disconnecting the West | ||
1160 | * Bridge device from any connected USB host. | ||
1161 | */ | ||
1162 | cy_as_return_status_t | ||
1163 | cy_as_usb_disconnect(cy_as_device_handle handle, | ||
1164 | cy_as_function_callback cb, | ||
1165 | uint32_t client) | ||
1166 | { | ||
1167 | cy_as_ll_request_response *req_p , *reply_p; | ||
1168 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1169 | |||
1170 | cy_as_device *dev_p; | ||
1171 | |||
1172 | cy_as_log_debug_message(6, "cy_as_usb_disconnect called"); | ||
1173 | |||
1174 | dev_p = (cy_as_device *)handle; | ||
1175 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1176 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1177 | |||
1178 | ret = is_usb_active(dev_p); | ||
1179 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1180 | return ret; | ||
1181 | |||
1182 | if (cy_as_device_is_in_callback(dev_p)) | ||
1183 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1184 | |||
1185 | if (!cy_as_device_is_usb_connected(dev_p)) | ||
1186 | return CY_AS_ERROR_USB_NOT_CONNECTED; | ||
1187 | |||
1188 | /* Create the request to send to the West Bridge device */ | ||
1189 | req_p = cy_as_ll_create_request(dev_p, | ||
1190 | CY_RQT_SET_CONNECT_STATE, CY_RQT_USB_RQT_CONTEXT, 1); | ||
1191 | if (req_p == 0) | ||
1192 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1193 | |||
1194 | cy_as_ll_request_response__set_word(req_p, 0, 0); | ||
1195 | |||
1196 | /* Reserve space for the reply, the reply | ||
1197 | * data will not exceed two bytes */ | ||
1198 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1199 | if (reply_p == 0) { | ||
1200 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1201 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1202 | } | ||
1203 | |||
1204 | if (cb == 0) { | ||
1205 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1206 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1207 | goto destroy; | ||
1208 | |||
1209 | return my_handle_response_disconnect(dev_p, | ||
1210 | req_p, reply_p, ret); | ||
1211 | } else { | ||
1212 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1213 | CY_FUNCT_CB_USB_DISCONNECT, 0, dev_p->func_cbs_usb, | ||
1214 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1215 | cy_as_usb_func_callback); | ||
1216 | |||
1217 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1218 | goto destroy; | ||
1219 | |||
1220 | return ret; | ||
1221 | } | ||
1222 | destroy: | ||
1223 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1224 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1225 | |||
1226 | return ret; | ||
1227 | } | ||
1228 | EXPORT_SYMBOL(cy_as_usb_disconnect); | ||
1229 | |||
1230 | static cy_as_return_status_t | ||
1231 | my_handle_response_set_enum_config(cy_as_device *dev_p, | ||
1232 | cy_as_ll_request_response *req_p, | ||
1233 | cy_as_ll_request_response *reply_p) | ||
1234 | { | ||
1235 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1236 | |||
1237 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1238 | CY_RESP_SUCCESS_FAILURE) { | ||
1239 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1240 | goto destroy; | ||
1241 | } | ||
1242 | |||
1243 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1244 | |||
1245 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
1246 | /* | ||
1247 | * we configured the west bridge device and | ||
1248 | * enumeration is going to happen on the P port | ||
1249 | * processor. now we must enable endpoint zero | ||
1250 | */ | ||
1251 | cy_as_usb_end_point_config config; | ||
1252 | |||
1253 | config.dir = cy_as_usb_in_out; | ||
1254 | config.type = cy_as_usb_control; | ||
1255 | config.enabled = cy_true; | ||
1256 | |||
1257 | ret = cy_as_usb_set_end_point_config((cy_as_device_handle *) | ||
1258 | dev_p, 0, &config); | ||
1259 | } | ||
1260 | |||
1261 | destroy: | ||
1262 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1263 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1264 | |||
1265 | return ret; | ||
1266 | } | ||
1267 | |||
1268 | /* | ||
1269 | * This method sets how the USB is enumerated and should | ||
1270 | * be called before the CyAsUsbConnect() is called. | ||
1271 | */ | ||
1272 | static cy_as_return_status_t | ||
1273 | my_usb_set_enum_config(cy_as_device *dev_p, | ||
1274 | uint8_t bus_mask, | ||
1275 | uint8_t media_mask, | ||
1276 | cy_bool use_antioch_enumeration, | ||
1277 | uint8_t mass_storage_interface, | ||
1278 | uint8_t mtp_interface, | ||
1279 | cy_bool mass_storage_callbacks, | ||
1280 | cy_as_function_callback cb, | ||
1281 | uint32_t client) | ||
1282 | { | ||
1283 | cy_as_ll_request_response *req_p , *reply_p; | ||
1284 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1285 | |||
1286 | cy_as_log_debug_message(6, "cy_as_usb_set_enum_config called"); | ||
1287 | |||
1288 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1289 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1290 | |||
1291 | ret = is_usb_active(dev_p); | ||
1292 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1293 | return ret; | ||
1294 | |||
1295 | if (cy_as_device_is_usb_connected(dev_p)) | ||
1296 | return CY_AS_ERROR_USB_CONNECTED; | ||
1297 | |||
1298 | if (cy_as_device_is_in_callback(dev_p)) | ||
1299 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1300 | |||
1301 | /* if we are using MTP firmware: */ | ||
1302 | if (dev_p->is_mtp_firmware == 1) { | ||
1303 | /* we cannot enumerate MSC */ | ||
1304 | if (mass_storage_interface != 0) | ||
1305 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1306 | |||
1307 | if (bus_mask == 0) { | ||
1308 | if (mtp_interface != 0) | ||
1309 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1310 | } else if (bus_mask == 2) { | ||
1311 | /* enable EP 1 as it will be used */ | ||
1312 | cy_as_dma_enable_end_point(dev_p, 1, cy_true, | ||
1313 | cy_as_direction_in); | ||
1314 | dev_p->usb_config[1].enabled = cy_true; | ||
1315 | dev_p->usb_config[1].dir = cy_as_usb_in; | ||
1316 | dev_p->usb_config[1].type = cy_as_usb_int; | ||
1317 | } else { | ||
1318 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1319 | } | ||
1320 | /* if we are not using MTP firmware, we cannot enumerate MTP */ | ||
1321 | } else if (mtp_interface != 0) | ||
1322 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1323 | |||
1324 | /* | ||
1325 | * if we are not enumerating mass storage, we should | ||
1326 | * not be providing an interface number. | ||
1327 | */ | ||
1328 | if (bus_mask == 0 && mass_storage_interface != 0) | ||
1329 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1330 | |||
1331 | /* | ||
1332 | * if we are going to use mtp_interface, bus mask must be 2. | ||
1333 | */ | ||
1334 | if (mtp_interface != 0 && bus_mask != 2) | ||
1335 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1336 | |||
1337 | |||
1338 | /* Create the request to send to the West Bridge device */ | ||
1339 | req_p = cy_as_ll_create_request(dev_p, | ||
1340 | CY_RQT_SET_USB_CONFIG, CY_RQT_USB_RQT_CONTEXT, 4); | ||
1341 | if (req_p == 0) | ||
1342 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1343 | |||
1344 | /* Marshal the structure */ | ||
1345 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1346 | (uint16_t)((media_mask << 8) | bus_mask)); | ||
1347 | cy_as_ll_request_response__set_word(req_p, 1, | ||
1348 | (uint16_t)use_antioch_enumeration); | ||
1349 | cy_as_ll_request_response__set_word(req_p, 2, | ||
1350 | dev_p->is_mtp_firmware ? mtp_interface : | ||
1351 | mass_storage_interface); | ||
1352 | cy_as_ll_request_response__set_word(req_p, 3, | ||
1353 | (uint16_t)mass_storage_callbacks); | ||
1354 | |||
1355 | /* Reserve space for the reply, the reply | ||
1356 | * data will not exceed one word */ | ||
1357 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1358 | if (reply_p == 0) { | ||
1359 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1360 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1361 | } | ||
1362 | |||
1363 | if (cb == 0) { | ||
1364 | |||
1365 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1366 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1367 | goto destroy; | ||
1368 | |||
1369 | return my_handle_response_set_enum_config(dev_p, | ||
1370 | req_p, reply_p); | ||
1371 | } else { | ||
1372 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1373 | CY_FUNCT_CB_USB_SETENUMCONFIG, 0, dev_p->func_cbs_usb, | ||
1374 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1375 | cy_as_usb_func_callback); | ||
1376 | |||
1377 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1378 | goto destroy; | ||
1379 | |||
1380 | return ret; | ||
1381 | } | ||
1382 | |||
1383 | destroy: | ||
1384 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1385 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1386 | |||
1387 | return ret; | ||
1388 | } | ||
1389 | |||
1390 | /* | ||
1391 | * This method sets how the USB is enumerated and should | ||
1392 | * be called before the CyAsUsbConnect() is called. | ||
1393 | */ | ||
1394 | cy_as_return_status_t | ||
1395 | cy_as_usb_set_enum_config(cy_as_device_handle handle, | ||
1396 | cy_as_usb_enum_control *config_p, | ||
1397 | cy_as_function_callback cb, | ||
1398 | uint32_t client) | ||
1399 | { | ||
1400 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
1401 | uint8_t bus_mask, media_mask; | ||
1402 | uint32_t bus, device; | ||
1403 | cy_as_return_status_t ret; | ||
1404 | |||
1405 | dev_p = (cy_as_device *)handle; | ||
1406 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1407 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1408 | |||
1409 | ret = is_usb_active(dev_p); | ||
1410 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1411 | return ret; | ||
1412 | |||
1413 | if ((cy_as_device_is_in_callback(dev_p)) && (cb != 0)) | ||
1414 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1415 | |||
1416 | /* Since we are mapping the media types to bus with NAND to 0 | ||
1417 | * and the rest to 1, and we are only allowing for enumerating | ||
1418 | * all the devices on a bus we just scan the array for any | ||
1419 | * positions where there a device is enabled and mark the bus | ||
1420 | * to be enumerated. | ||
1421 | */ | ||
1422 | bus_mask = 0; | ||
1423 | media_mask = 0; | ||
1424 | for (bus = 0; bus < CY_AS_MAX_BUSES; bus++) { | ||
1425 | for (device = 0; device < CY_AS_MAX_STORAGE_DEVICES; device++) { | ||
1426 | if (config_p->devices_to_enumerate[bus][device] == | ||
1427 | cy_true) { | ||
1428 | bus_mask |= (0x01 << bus); | ||
1429 | media_mask |= dev_p->media_supported[bus]; | ||
1430 | media_mask |= dev_p->media_supported[bus]; | ||
1431 | } | ||
1432 | } | ||
1433 | } | ||
1434 | |||
1435 | return my_usb_set_enum_config(dev_p, bus_mask, media_mask, | ||
1436 | config_p->antioch_enumeration, | ||
1437 | config_p->mass_storage_interface, | ||
1438 | config_p->mtp_interface, | ||
1439 | config_p->mass_storage_callbacks, | ||
1440 | cb, | ||
1441 | client | ||
1442 | ); | ||
1443 | } | ||
1444 | EXPORT_SYMBOL(cy_as_usb_set_enum_config); | ||
1445 | |||
1446 | static cy_as_return_status_t | ||
1447 | my_handle_response_get_enum_config(cy_as_device *dev_p, | ||
1448 | cy_as_ll_request_response *req_p, | ||
1449 | cy_as_ll_request_response *reply_p, | ||
1450 | void *config_p) | ||
1451 | { | ||
1452 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1453 | uint16_t val; | ||
1454 | uint8_t bus_mask; | ||
1455 | uint32_t bus; | ||
1456 | |||
1457 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
1458 | CY_RESP_USB_CONFIG) { | ||
1459 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1460 | goto destroy; | ||
1461 | } | ||
1462 | |||
1463 | /* Marshal the reply */ | ||
1464 | if (req_p->flags & CY_AS_REQUEST_RESPONSE_MS) { | ||
1465 | uint32_t device; | ||
1466 | cy_bool state; | ||
1467 | cy_as_usb_enum_control *ms_config_p = | ||
1468 | (cy_as_usb_enum_control *)config_p; | ||
1469 | |||
1470 | bus_mask = (uint8_t) | ||
1471 | (cy_as_ll_request_response__get_word | ||
1472 | (reply_p, 0) & 0xFF); | ||
1473 | for (bus = 0; bus < CY_AS_MAX_BUSES; bus++) { | ||
1474 | if (bus_mask & (1 << bus)) | ||
1475 | state = cy_true; | ||
1476 | else | ||
1477 | state = cy_false; | ||
1478 | |||
1479 | for (device = 0; device < CY_AS_MAX_STORAGE_DEVICES; | ||
1480 | device++) | ||
1481 | ms_config_p->devices_to_enumerate[bus][device] | ||
1482 | = state; | ||
1483 | } | ||
1484 | |||
1485 | ms_config_p->antioch_enumeration = | ||
1486 | (cy_bool)cy_as_ll_request_response__get_word | ||
1487 | (reply_p, 1); | ||
1488 | |||
1489 | val = cy_as_ll_request_response__get_word(reply_p, 2); | ||
1490 | if (dev_p->is_mtp_firmware) { | ||
1491 | ms_config_p->mass_storage_interface = 0; | ||
1492 | ms_config_p->mtp_interface = (uint8_t)(val & 0xFF); | ||
1493 | } else { | ||
1494 | ms_config_p->mass_storage_interface = | ||
1495 | (uint8_t)(val & 0xFF); | ||
1496 | ms_config_p->mtp_interface = 0; | ||
1497 | } | ||
1498 | ms_config_p->mass_storage_callbacks = (cy_bool)(val >> 8); | ||
1499 | |||
1500 | /* | ||
1501 | * firmware returns an invalid interface number for mass storage, | ||
1502 | * if mass storage is not enabled. this needs to be converted to | ||
1503 | * zero to match the input configuration. | ||
1504 | */ | ||
1505 | if (bus_mask == 0) { | ||
1506 | if (dev_p->is_mtp_firmware) | ||
1507 | ms_config_p->mtp_interface = 0; | ||
1508 | else | ||
1509 | ms_config_p->mass_storage_interface = 0; | ||
1510 | } | ||
1511 | } else { | ||
1512 | cy_as_usb_enum_control_dep *ex_config_p = | ||
1513 | (cy_as_usb_enum_control_dep *)config_p; | ||
1514 | |||
1515 | ex_config_p->enum_mass_storage = (uint8_t) | ||
1516 | ((cy_as_ll_request_response__get_word | ||
1517 | (reply_p, 0) >> 8) & 0xFF); | ||
1518 | ex_config_p->antioch_enumeration = (cy_bool) | ||
1519 | cy_as_ll_request_response__get_word(reply_p, 1); | ||
1520 | |||
1521 | val = cy_as_ll_request_response__get_word(reply_p, 2); | ||
1522 | ex_config_p->mass_storage_interface = (uint8_t)(val & 0xFF); | ||
1523 | ex_config_p->mass_storage_callbacks = (cy_bool)(val >> 8); | ||
1524 | |||
1525 | /* | ||
1526 | * firmware returns an invalid interface number for mass | ||
1527 | * storage, if mass storage is not enabled. this needs to | ||
1528 | * be converted to zero to match the input configuration. | ||
1529 | */ | ||
1530 | if (ex_config_p->enum_mass_storage == 0) | ||
1531 | ex_config_p->mass_storage_interface = 0; | ||
1532 | } | ||
1533 | |||
1534 | destroy: | ||
1535 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1536 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1537 | |||
1538 | return ret; | ||
1539 | } | ||
1540 | |||
1541 | /* | ||
1542 | * This sets up the request for the enumerateion configuration | ||
1543 | * information, based on if the request is from the old pre-1.2 | ||
1544 | * functions. | ||
1545 | */ | ||
1546 | static cy_as_return_status_t | ||
1547 | my_usb_get_enum_config(cy_as_device_handle handle, | ||
1548 | uint16_t req_flags, | ||
1549 | void *config_p, | ||
1550 | cy_as_function_callback cb, | ||
1551 | uint32_t client) | ||
1552 | { | ||
1553 | cy_as_ll_request_response *req_p , *reply_p; | ||
1554 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1555 | |||
1556 | cy_as_device *dev_p; | ||
1557 | |||
1558 | cy_as_log_debug_message(6, "cy_as_usb_get_enum_config called"); | ||
1559 | |||
1560 | dev_p = (cy_as_device *)handle; | ||
1561 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1562 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1563 | |||
1564 | ret = is_usb_active(dev_p); | ||
1565 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1566 | return ret; | ||
1567 | |||
1568 | if (cy_as_device_is_in_callback(dev_p)) | ||
1569 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1570 | |||
1571 | /* Create the request to send to the West Bridge device */ | ||
1572 | req_p = cy_as_ll_create_request(dev_p, | ||
1573 | CY_RQT_GET_USB_CONFIG, CY_RQT_USB_RQT_CONTEXT, 0); | ||
1574 | if (req_p == 0) | ||
1575 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1576 | |||
1577 | /* Reserve space for the reply, the reply data | ||
1578 | * will not exceed two bytes */ | ||
1579 | reply_p = cy_as_ll_create_response(dev_p, 3); | ||
1580 | if (reply_p == 0) { | ||
1581 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1582 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1583 | } | ||
1584 | |||
1585 | if (cb == 0) { | ||
1586 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1587 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1588 | goto destroy; | ||
1589 | |||
1590 | /* we need to know the type of request to | ||
1591 | * know how to manage the data */ | ||
1592 | req_p->flags |= req_flags; | ||
1593 | return my_handle_response_get_enum_config(dev_p, | ||
1594 | req_p, reply_p, config_p); | ||
1595 | } else { | ||
1596 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1597 | CY_FUNCT_CB_USB_GETENUMCONFIG, config_p, | ||
1598 | dev_p->func_cbs_usb, req_flags, req_p, reply_p, | ||
1599 | cy_as_usb_func_callback); | ||
1600 | |||
1601 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1602 | goto destroy; | ||
1603 | |||
1604 | return ret; | ||
1605 | } | ||
1606 | |||
1607 | destroy: | ||
1608 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1609 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1610 | |||
1611 | return ret; | ||
1612 | } | ||
1613 | |||
1614 | /* | ||
1615 | * This method returns the enumerateion configuration information | ||
1616 | * from the West Bridge device. Generally this is not used by | ||
1617 | * client software but is provided mostly for debug information. | ||
1618 | * We want a method to read all state information from the device. | ||
1619 | */ | ||
1620 | cy_as_return_status_t | ||
1621 | cy_as_usb_get_enum_config(cy_as_device_handle handle, | ||
1622 | cy_as_usb_enum_control *config_p, | ||
1623 | cy_as_function_callback cb, | ||
1624 | uint32_t client) | ||
1625 | { | ||
1626 | return my_usb_get_enum_config(handle, | ||
1627 | CY_AS_REQUEST_RESPONSE_MS, config_p, cb, client); | ||
1628 | } | ||
1629 | EXPORT_SYMBOL(cy_as_usb_get_enum_config); | ||
1630 | |||
1631 | /* | ||
1632 | * This method sets the USB descriptor for a given entity. | ||
1633 | */ | ||
1634 | cy_as_return_status_t | ||
1635 | cy_as_usb_set_descriptor(cy_as_device_handle handle, | ||
1636 | cy_as_usb_desc_type type, | ||
1637 | uint8_t index, | ||
1638 | void *desc_p, | ||
1639 | uint16_t length, | ||
1640 | cy_as_function_callback cb, | ||
1641 | uint32_t client) | ||
1642 | { | ||
1643 | cy_as_ll_request_response *req_p , *reply_p; | ||
1644 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1645 | uint16_t pktlen; | ||
1646 | |||
1647 | cy_as_device *dev_p; | ||
1648 | |||
1649 | cy_as_log_debug_message(6, "cy_as_usb_set_descriptor called"); | ||
1650 | |||
1651 | dev_p = (cy_as_device *)handle; | ||
1652 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1653 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1654 | |||
1655 | ret = is_usb_active(dev_p); | ||
1656 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1657 | return ret; | ||
1658 | |||
1659 | if (cy_as_device_is_in_callback(dev_p)) | ||
1660 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1661 | |||
1662 | if (length > CY_AS_MAX_USB_DESCRIPTOR_SIZE) | ||
1663 | return CY_AS_ERROR_INVALID_DESCRIPTOR; | ||
1664 | |||
1665 | pktlen = (uint16_t)length / 2; | ||
1666 | if (length % 2) | ||
1667 | pktlen++; | ||
1668 | pktlen += 2; /* 1 for type, 1 for length */ | ||
1669 | |||
1670 | /* Create the request to send to the West Bridge device */ | ||
1671 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_SET_DESCRIPTOR, | ||
1672 | CY_RQT_USB_RQT_CONTEXT, (uint16_t)pktlen); | ||
1673 | if (req_p == 0) | ||
1674 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1675 | |||
1676 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1677 | (uint16_t)((uint8_t)type | (index << 8))); | ||
1678 | cy_as_ll_request_response__set_word(req_p, 1, | ||
1679 | (uint16_t)length); | ||
1680 | cy_as_ll_request_response__pack(req_p, 2, length, desc_p); | ||
1681 | |||
1682 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1683 | if (reply_p == 0) { | ||
1684 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1685 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1686 | } | ||
1687 | |||
1688 | if (cb == 0) { | ||
1689 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1690 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1691 | goto destroy; | ||
1692 | |||
1693 | return my_handle_response_no_data(dev_p, req_p, reply_p); | ||
1694 | } else { | ||
1695 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1696 | CY_FUNCT_CB_USB_SETDESCRIPTOR, 0, dev_p->func_cbs_usb, | ||
1697 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1698 | cy_as_usb_func_callback); | ||
1699 | |||
1700 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1701 | goto destroy; | ||
1702 | |||
1703 | return ret; | ||
1704 | } | ||
1705 | |||
1706 | destroy: | ||
1707 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1708 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1709 | |||
1710 | return ret; | ||
1711 | } | ||
1712 | EXPORT_SYMBOL(cy_as_usb_set_descriptor); | ||
1713 | |||
1714 | /* | ||
1715 | * This method clears all descriptors that were previously | ||
1716 | * stored on the West Bridge through CyAsUsbSetDescriptor calls. | ||
1717 | */ | ||
1718 | cy_as_return_status_t | ||
1719 | cy_as_usb_clear_descriptors(cy_as_device_handle handle, | ||
1720 | cy_as_function_callback cb, | ||
1721 | uint32_t client) | ||
1722 | { | ||
1723 | cy_as_ll_request_response *req_p , *reply_p; | ||
1724 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1725 | |||
1726 | cy_as_device *dev_p; | ||
1727 | |||
1728 | cy_as_log_debug_message(6, "cy_as_usb_clear_descriptors called"); | ||
1729 | |||
1730 | dev_p = (cy_as_device *)handle; | ||
1731 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1732 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1733 | |||
1734 | ret = is_usb_active(dev_p); | ||
1735 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1736 | return ret; | ||
1737 | |||
1738 | if ((cy_as_device_is_in_callback(dev_p)) && (cb == 0)) | ||
1739 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1740 | |||
1741 | /* Create the request to send to the West Bridge device */ | ||
1742 | req_p = cy_as_ll_create_request(dev_p, | ||
1743 | CY_RQT_CLEAR_DESCRIPTORS, CY_RQT_USB_RQT_CONTEXT, 1); | ||
1744 | if (req_p == 0) | ||
1745 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1746 | |||
1747 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
1748 | if (reply_p == 0) { | ||
1749 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1750 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1751 | } | ||
1752 | |||
1753 | if (cb == 0) { | ||
1754 | |||
1755 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
1756 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1757 | goto destroy; | ||
1758 | |||
1759 | return my_handle_response_no_data(dev_p, req_p, reply_p); | ||
1760 | } else { | ||
1761 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1762 | CY_FUNCT_CB_USB_CLEARDESCRIPTORS, 0, | ||
1763 | dev_p->func_cbs_usb, | ||
1764 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
1765 | cy_as_usb_func_callback); | ||
1766 | |||
1767 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1768 | goto destroy; | ||
1769 | |||
1770 | return ret; | ||
1771 | } | ||
1772 | |||
1773 | destroy: | ||
1774 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1775 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1776 | |||
1777 | return ret; | ||
1778 | } | ||
1779 | EXPORT_SYMBOL(cy_as_usb_clear_descriptors); | ||
1780 | |||
1781 | static cy_as_return_status_t | ||
1782 | my_handle_response_get_descriptor(cy_as_device *dev_p, | ||
1783 | cy_as_ll_request_response *req_p, | ||
1784 | cy_as_ll_request_response *reply_p, | ||
1785 | cy_as_get_descriptor_data *data) | ||
1786 | { | ||
1787 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
1788 | uint32_t retlen; | ||
1789 | |||
1790 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
1791 | CY_RESP_SUCCESS_FAILURE) { | ||
1792 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1793 | goto destroy; | ||
1794 | } else if (cy_as_ll_request_response__get_code(reply_p) != | ||
1795 | CY_RESP_USB_DESCRIPTOR) { | ||
1796 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
1797 | goto destroy; | ||
1798 | } | ||
1799 | |||
1800 | retlen = cy_as_ll_request_response__get_word(reply_p, 0); | ||
1801 | if (retlen > data->length) { | ||
1802 | ret = CY_AS_ERROR_INVALID_SIZE; | ||
1803 | goto destroy; | ||
1804 | } | ||
1805 | |||
1806 | ret = CY_AS_ERROR_SUCCESS; | ||
1807 | cy_as_ll_request_response__unpack(reply_p, 1, | ||
1808 | retlen, data->desc_p); | ||
1809 | |||
1810 | destroy: | ||
1811 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1812 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1813 | |||
1814 | return ret; | ||
1815 | } | ||
1816 | |||
1817 | /* | ||
1818 | * This method retreives the USB descriptor for a given type. | ||
1819 | */ | ||
1820 | cy_as_return_status_t | ||
1821 | cy_as_usb_get_descriptor(cy_as_device_handle handle, | ||
1822 | cy_as_usb_desc_type type, | ||
1823 | uint8_t index, | ||
1824 | cy_as_get_descriptor_data *data, | ||
1825 | cy_as_function_callback cb, | ||
1826 | uint32_t client) | ||
1827 | { | ||
1828 | cy_as_return_status_t ret; | ||
1829 | cy_as_ll_request_response *req_p , *reply_p; | ||
1830 | |||
1831 | cy_as_device *dev_p; | ||
1832 | |||
1833 | cy_as_log_debug_message(6, "cy_as_usb_get_descriptor called"); | ||
1834 | |||
1835 | dev_p = (cy_as_device *)handle; | ||
1836 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1837 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1838 | |||
1839 | ret = is_usb_active(dev_p); | ||
1840 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1841 | return ret; | ||
1842 | |||
1843 | if (cy_as_device_is_in_callback(dev_p)) | ||
1844 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
1845 | |||
1846 | /* Create the request to send to the West Bridge device */ | ||
1847 | req_p = cy_as_ll_create_request(dev_p, | ||
1848 | CY_RQT_GET_DESCRIPTOR, CY_RQT_USB_RQT_CONTEXT, 1); | ||
1849 | if (req_p == 0) | ||
1850 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1851 | |||
1852 | cy_as_ll_request_response__set_word(req_p, 0, | ||
1853 | (uint16_t)((uint8_t)type | (index << 8))); | ||
1854 | |||
1855 | /* Add one for the length field */ | ||
1856 | reply_p = cy_as_ll_create_response(dev_p, | ||
1857 | CY_AS_MAX_USB_DESCRIPTOR_SIZE + 1); | ||
1858 | if (reply_p == 0) { | ||
1859 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1860 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
1861 | } | ||
1862 | |||
1863 | if (cb == 0) { | ||
1864 | ret = cy_as_ll_send_request_wait_reply( | ||
1865 | dev_p, req_p, reply_p); | ||
1866 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1867 | goto destroy; | ||
1868 | |||
1869 | return my_handle_response_get_descriptor(dev_p, | ||
1870 | req_p, reply_p, data); | ||
1871 | } else { | ||
1872 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
1873 | CY_FUNCT_CB_USB_GETDESCRIPTOR, data, | ||
1874 | dev_p->func_cbs_usb, | ||
1875 | CY_AS_REQUEST_RESPONSE_EX, req_p, | ||
1876 | reply_p, cy_as_usb_func_callback); | ||
1877 | |||
1878 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1879 | goto destroy; | ||
1880 | |||
1881 | return ret; | ||
1882 | } | ||
1883 | |||
1884 | destroy: | ||
1885 | cy_as_ll_destroy_request(dev_p, req_p); | ||
1886 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
1887 | |||
1888 | return ret; | ||
1889 | } | ||
1890 | EXPORT_SYMBOL(cy_as_usb_get_descriptor); | ||
1891 | |||
1892 | cy_as_return_status_t | ||
1893 | cy_as_usb_set_physical_configuration(cy_as_device_handle handle, | ||
1894 | uint8_t config) | ||
1895 | { | ||
1896 | cy_as_return_status_t ret; | ||
1897 | cy_as_device *dev_p; | ||
1898 | |||
1899 | cy_as_log_debug_message(6, | ||
1900 | "cy_as_usb_set_physical_configuration called"); | ||
1901 | |||
1902 | dev_p = (cy_as_device *)handle; | ||
1903 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1904 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1905 | |||
1906 | ret = is_usb_active(dev_p); | ||
1907 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1908 | return ret; | ||
1909 | |||
1910 | if (cy_as_device_is_usb_connected(dev_p)) | ||
1911 | return CY_AS_ERROR_USB_CONNECTED; | ||
1912 | |||
1913 | if (config < 1 || config > 12) | ||
1914 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1915 | |||
1916 | dev_p->usb_phy_config = config; | ||
1917 | |||
1918 | return CY_AS_ERROR_SUCCESS; | ||
1919 | } | ||
1920 | EXPORT_SYMBOL(cy_as_usb_set_physical_configuration); | ||
1921 | |||
1922 | static cy_bool | ||
1923 | is_physical_valid(uint8_t config, cy_as_end_point_number_t ep) | ||
1924 | { | ||
1925 | static uint8_t validmask[12] = { | ||
1926 | 0x0f, /* Config 1 - 1, 2, 3, 4 */ | ||
1927 | 0x07, /* Config 2 - 1, 2, 3 */ | ||
1928 | 0x07, /* Config 3 - 1, 2, 3 */ | ||
1929 | 0x0d, /* Config 4 - 1, 3, 4 */ | ||
1930 | 0x05, /* Config 5 - 1, 3 */ | ||
1931 | 0x05, /* Config 6 - 1, 3 */ | ||
1932 | 0x0d, /* Config 7 - 1, 3, 4 */ | ||
1933 | 0x05, /* Config 8 - 1, 3 */ | ||
1934 | 0x05, /* Config 9 - 1, 3 */ | ||
1935 | 0x0d, /* Config 10 - 1, 3, 4 */ | ||
1936 | 0x09, /* Config 11 - 1, 4 */ | ||
1937 | 0x01 /* Config 12 - 1 */ | ||
1938 | }; | ||
1939 | |||
1940 | return (validmask[config - 1] & (1 << (ep - 1))) ? cy_true : cy_false; | ||
1941 | } | ||
1942 | |||
1943 | /* | ||
1944 | * This method sets the configuration for an endpoint | ||
1945 | */ | ||
1946 | cy_as_return_status_t | ||
1947 | cy_as_usb_set_end_point_config(cy_as_device_handle handle, | ||
1948 | cy_as_end_point_number_t ep, cy_as_usb_end_point_config *config_p) | ||
1949 | { | ||
1950 | cy_as_return_status_t ret; | ||
1951 | cy_as_device *dev_p; | ||
1952 | |||
1953 | cy_as_log_debug_message(6, "cy_as_usb_set_end_point_config called"); | ||
1954 | |||
1955 | dev_p = (cy_as_device *)handle; | ||
1956 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
1957 | return CY_AS_ERROR_INVALID_HANDLE; | ||
1958 | |||
1959 | ret = is_usb_active(dev_p); | ||
1960 | if (ret != CY_AS_ERROR_SUCCESS) | ||
1961 | return ret; | ||
1962 | |||
1963 | if (cy_as_device_is_usb_connected(dev_p)) | ||
1964 | return CY_AS_ERROR_USB_CONNECTED; | ||
1965 | |||
1966 | if (ep >= 16 || ep == 2 || ep == 4 || ep == 6 || ep == 8) | ||
1967 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
1968 | |||
1969 | if (ep == 0) { | ||
1970 | /* Endpoint 0 must be 64 byte, dir IN/OUT, | ||
1971 | * and control type */ | ||
1972 | if (config_p->dir != cy_as_usb_in_out || | ||
1973 | config_p->type != cy_as_usb_control) | ||
1974 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1975 | } else if (ep == 1) { | ||
1976 | if ((dev_p->is_mtp_firmware == 1) && | ||
1977 | (dev_p->usb_config[1].enabled == cy_true)) { | ||
1978 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
1979 | } | ||
1980 | |||
1981 | /* | ||
1982 | * EP1 can only be used either as an OUT ep, or as an IN ep. | ||
1983 | */ | ||
1984 | if ((config_p->type == cy_as_usb_control) || | ||
1985 | (config_p->type == cy_as_usb_iso) || | ||
1986 | (config_p->dir == cy_as_usb_in_out)) | ||
1987 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1988 | } else { | ||
1989 | if (config_p->dir == cy_as_usb_in_out || | ||
1990 | config_p->type == cy_as_usb_control) | ||
1991 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
1992 | |||
1993 | if (!is_physical_valid(dev_p->usb_phy_config, | ||
1994 | config_p->physical)) | ||
1995 | return CY_AS_ERROR_INVALID_PHYSICAL_ENDPOINT; | ||
1996 | |||
1997 | /* | ||
1998 | * ISO endpoints must be on E_ps 3, 5, 7 or 9 as | ||
1999 | * they need to align directly with the underlying | ||
2000 | * physical endpoint. | ||
2001 | */ | ||
2002 | if (config_p->type == cy_as_usb_iso) { | ||
2003 | if (ep != 3 && ep != 5 && ep != 7 && ep != 9) | ||
2004 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
2005 | |||
2006 | if (ep == 3 && config_p->physical != 1) | ||
2007 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
2008 | |||
2009 | if (ep == 5 && config_p->physical != 2) | ||
2010 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
2011 | |||
2012 | if (ep == 7 && config_p->physical != 3) | ||
2013 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
2014 | |||
2015 | if (ep == 9 && config_p->physical != 4) | ||
2016 | return CY_AS_ERROR_INVALID_CONFIGURATION; | ||
2017 | } | ||
2018 | } | ||
2019 | |||
2020 | /* Store the configuration information until a | ||
2021 | * CyAsUsbCommitConfig is done */ | ||
2022 | dev_p->usb_config[ep] = *config_p; | ||
2023 | |||
2024 | /* If the endpoint is enabled, enable DMA associated | ||
2025 | * with the endpoint */ | ||
2026 | /* | ||
2027 | * we make some assumptions that we check here. we assume | ||
2028 | * that the direction fields for the DMA module are the same | ||
2029 | * values as the direction values for the USB module. | ||
2030 | */ | ||
2031 | cy_as_hal_assert((int)cy_as_usb_in == (int)cy_as_direction_in); | ||
2032 | cy_as_hal_assert((int)cy_as_usb_out == (int)cy_as_direction_out); | ||
2033 | cy_as_hal_assert((int)cy_as_usb_in_out == (int)cy_as_direction_in_out); | ||
2034 | |||
2035 | return cy_as_dma_enable_end_point(dev_p, ep, | ||
2036 | config_p->enabled, (cy_as_dma_direction)config_p->dir); | ||
2037 | } | ||
2038 | EXPORT_SYMBOL(cy_as_usb_set_end_point_config); | ||
2039 | |||
2040 | cy_as_return_status_t | ||
2041 | cy_as_usb_get_end_point_config(cy_as_device_handle handle, | ||
2042 | cy_as_end_point_number_t ep, cy_as_usb_end_point_config *config_p) | ||
2043 | { | ||
2044 | cy_as_return_status_t ret; | ||
2045 | |||
2046 | cy_as_device *dev_p; | ||
2047 | |||
2048 | cy_as_log_debug_message(6, "cy_as_usb_get_end_point_config called"); | ||
2049 | |||
2050 | dev_p = (cy_as_device *)handle; | ||
2051 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2052 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2053 | |||
2054 | ret = is_usb_active(dev_p); | ||
2055 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2056 | return ret; | ||
2057 | |||
2058 | if (ep >= 16 || ep == 2 || ep == 4 || ep == 6 || ep == 8) | ||
2059 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2060 | |||
2061 | *config_p = dev_p->usb_config[ep]; | ||
2062 | |||
2063 | return CY_AS_ERROR_SUCCESS; | ||
2064 | } | ||
2065 | EXPORT_SYMBOL(cy_as_usb_get_end_point_config); | ||
2066 | |||
2067 | /* | ||
2068 | * Commit the configuration of the various endpoints to the hardware. | ||
2069 | */ | ||
2070 | cy_as_return_status_t | ||
2071 | cy_as_usb_commit_config(cy_as_device_handle handle, | ||
2072 | cy_as_function_callback cb, | ||
2073 | uint32_t client) | ||
2074 | { | ||
2075 | uint32_t i; | ||
2076 | cy_as_return_status_t ret; | ||
2077 | cy_as_ll_request_response *req_p , *reply_p; | ||
2078 | cy_as_device *dev_p; | ||
2079 | uint16_t data; | ||
2080 | |||
2081 | cy_as_log_debug_message(6, "cy_as_usb_commit_config called"); | ||
2082 | |||
2083 | dev_p = (cy_as_device *)handle; | ||
2084 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2085 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2086 | |||
2087 | ret = is_usb_active(dev_p); | ||
2088 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2089 | return ret; | ||
2090 | |||
2091 | if (cy_as_device_is_usb_connected(dev_p)) | ||
2092 | return CY_AS_ERROR_USB_CONNECTED; | ||
2093 | |||
2094 | if (cy_as_device_is_in_callback(dev_p)) | ||
2095 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
2096 | |||
2097 | /* | ||
2098 | * this performs the mapping based on informatation that was | ||
2099 | * previously stored on the device about the various endpoints | ||
2100 | * and how they are configured. the output of this mapping is | ||
2101 | * setting the the 14 register values contained in usb_lepcfg | ||
2102 | * and usb_pepcfg | ||
2103 | */ | ||
2104 | ret = cy_as_usb_map_logical2_physical(dev_p); | ||
2105 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2106 | return ret; | ||
2107 | |||
2108 | /* | ||
2109 | * now, package the information about the various logical and | ||
2110 | * physical endpoint configuration registers and send it | ||
2111 | * across to the west bridge device. | ||
2112 | */ | ||
2113 | req_p = cy_as_ll_create_request(dev_p, | ||
2114 | CY_RQT_SET_USB_CONFIG_REGISTERS, CY_RQT_USB_RQT_CONTEXT, 8); | ||
2115 | if (req_p == 0) | ||
2116 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2117 | |||
2118 | cy_as_hal_print_message("USB configuration: %d\n", | ||
2119 | dev_p->usb_phy_config); | ||
2120 | cy_as_hal_print_message("EP1OUT: 0x%02x EP1IN: 0x%02x\n", | ||
2121 | dev_p->usb_ep1cfg[0], dev_p->usb_ep1cfg[1]); | ||
2122 | cy_as_hal_print_message("PEP registers: 0x%02x 0x%02x 0x%02x 0x%02x\n", | ||
2123 | dev_p->usb_pepcfg[0], dev_p->usb_pepcfg[1], | ||
2124 | dev_p->usb_pepcfg[2], dev_p->usb_pepcfg[3]); | ||
2125 | |||
2126 | cy_as_hal_print_message("LEP registers: 0x%02x 0x%02x 0x%02x " | ||
2127 | "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", | ||
2128 | dev_p->usb_lepcfg[0], dev_p->usb_lepcfg[1], | ||
2129 | dev_p->usb_lepcfg[2], dev_p->usb_lepcfg[3], | ||
2130 | dev_p->usb_lepcfg[4], dev_p->usb_lepcfg[5], | ||
2131 | dev_p->usb_lepcfg[6], dev_p->usb_lepcfg[7], | ||
2132 | dev_p->usb_lepcfg[8], dev_p->usb_lepcfg[9]); | ||
2133 | |||
2134 | /* Write the EP1OUTCFG and EP1INCFG data in the first word. */ | ||
2135 | data = (uint16_t)((dev_p->usb_ep1cfg[0] << 8) | | ||
2136 | dev_p->usb_ep1cfg[1]); | ||
2137 | cy_as_ll_request_response__set_word(req_p, 0, data); | ||
2138 | |||
2139 | /* Write the PEP CFG data in the next 2 words */ | ||
2140 | for (i = 0; i < 4; i += 2) { | ||
2141 | data = (uint16_t)((dev_p->usb_pepcfg[i] << 8) | | ||
2142 | dev_p->usb_pepcfg[i + 1]); | ||
2143 | cy_as_ll_request_response__set_word(req_p, | ||
2144 | 1 + i / 2, data); | ||
2145 | } | ||
2146 | |||
2147 | /* Write the LEP CFG data in the next 5 words */ | ||
2148 | for (i = 0; i < 10; i += 2) { | ||
2149 | data = (uint16_t)((dev_p->usb_lepcfg[i] << 8) | | ||
2150 | dev_p->usb_lepcfg[i + 1]); | ||
2151 | cy_as_ll_request_response__set_word(req_p, | ||
2152 | 3 + i / 2, data); | ||
2153 | } | ||
2154 | |||
2155 | /* A single status word response type */ | ||
2156 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2157 | if (reply_p == 0) { | ||
2158 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2159 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2160 | } | ||
2161 | |||
2162 | if (cb == 0) { | ||
2163 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
2164 | req_p, reply_p); | ||
2165 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2166 | goto destroy; | ||
2167 | |||
2168 | ret = my_handle_response_no_data(dev_p, | ||
2169 | req_p, reply_p); | ||
2170 | |||
2171 | if (ret == CY_AS_ERROR_SUCCESS) | ||
2172 | ret = cy_as_usb_setup_dma(dev_p); | ||
2173 | |||
2174 | return ret; | ||
2175 | } else { | ||
2176 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
2177 | CY_FUNCT_CB_USB_COMMITCONFIG, 0, dev_p->func_cbs_usb, | ||
2178 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
2179 | cy_as_usb_func_callback); | ||
2180 | |||
2181 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2182 | goto destroy; | ||
2183 | |||
2184 | return ret; | ||
2185 | } | ||
2186 | |||
2187 | destroy: | ||
2188 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2189 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2190 | |||
2191 | return ret; | ||
2192 | } | ||
2193 | EXPORT_SYMBOL(cy_as_usb_commit_config); | ||
2194 | |||
2195 | static void | ||
2196 | sync_request_callback(cy_as_device *dev_p, | ||
2197 | cy_as_end_point_number_t ep, void *buf_p, | ||
2198 | uint32_t size, cy_as_return_status_t err) | ||
2199 | { | ||
2200 | (void)ep; | ||
2201 | (void)buf_p; | ||
2202 | |||
2203 | dev_p->usb_error = err; | ||
2204 | dev_p->usb_actual_cnt = size; | ||
2205 | } | ||
2206 | |||
2207 | static void | ||
2208 | async_read_request_callback(cy_as_device *dev_p, | ||
2209 | cy_as_end_point_number_t ep, void *buf_p, | ||
2210 | uint32_t size, cy_as_return_status_t err) | ||
2211 | { | ||
2212 | cy_as_device_handle h; | ||
2213 | |||
2214 | cy_as_log_debug_message(6, | ||
2215 | "async_read_request_callback called"); | ||
2216 | |||
2217 | h = (cy_as_device_handle)dev_p; | ||
2218 | |||
2219 | if (ep == 0 && cy_as_device_is_ack_delayed(dev_p)) { | ||
2220 | dev_p->usb_pending_buffer = buf_p; | ||
2221 | dev_p->usb_pending_size = size; | ||
2222 | dev_p->usb_error = err; | ||
2223 | cy_as_usb_ack_setup_packet(h, usb_ack_callback, 0); | ||
2224 | } else { | ||
2225 | cy_as_usb_io_callback cb; | ||
2226 | |||
2227 | cb = dev_p->usb_cb[ep]; | ||
2228 | dev_p->usb_cb[ep] = 0; | ||
2229 | cy_as_device_clear_usb_async_pending(dev_p, ep); | ||
2230 | if (cb) | ||
2231 | cb(h, ep, size, buf_p, err); | ||
2232 | } | ||
2233 | } | ||
2234 | |||
2235 | static void | ||
2236 | async_write_request_callback(cy_as_device *dev_p, | ||
2237 | cy_as_end_point_number_t ep, void *buf_p, | ||
2238 | uint32_t size, cy_as_return_status_t err) | ||
2239 | { | ||
2240 | cy_as_device_handle h; | ||
2241 | |||
2242 | cy_as_log_debug_message(6, | ||
2243 | "async_write_request_callback called"); | ||
2244 | |||
2245 | h = (cy_as_device_handle)dev_p; | ||
2246 | |||
2247 | if (ep == 0 && cy_as_device_is_ack_delayed(dev_p)) { | ||
2248 | dev_p->usb_pending_buffer = buf_p; | ||
2249 | dev_p->usb_pending_size = size; | ||
2250 | dev_p->usb_error = err; | ||
2251 | |||
2252 | /* The west bridge protocol generates ZLPs as required. */ | ||
2253 | cy_as_usb_ack_setup_packet(h, usb_ack_callback, 0); | ||
2254 | } else { | ||
2255 | cy_as_usb_io_callback cb; | ||
2256 | |||
2257 | cb = dev_p->usb_cb[ep]; | ||
2258 | dev_p->usb_cb[ep] = 0; | ||
2259 | |||
2260 | cy_as_device_clear_usb_async_pending(dev_p, ep); | ||
2261 | if (cb) | ||
2262 | cb(h, ep, size, buf_p, err); | ||
2263 | } | ||
2264 | } | ||
2265 | |||
2266 | static void | ||
2267 | my_turbo_rqt_callback(cy_as_device *dev_p, | ||
2268 | uint8_t context, | ||
2269 | cy_as_ll_request_response *rqt, | ||
2270 | cy_as_ll_request_response *resp, | ||
2271 | cy_as_return_status_t stat) | ||
2272 | { | ||
2273 | uint8_t code; | ||
2274 | |||
2275 | (void)context; | ||
2276 | (void)stat; | ||
2277 | |||
2278 | /* The Handlers are responsible for Deleting the rqt and resp when | ||
2279 | * they are finished | ||
2280 | */ | ||
2281 | code = cy_as_ll_request_response__get_code(rqt); | ||
2282 | switch (code) { | ||
2283 | case CY_RQT_TURBO_SWITCH_ENDPOINT: | ||
2284 | cy_as_hal_assert(stat == CY_AS_ERROR_SUCCESS); | ||
2285 | cy_as_ll_destroy_request(dev_p, rqt); | ||
2286 | cy_as_ll_destroy_response(dev_p, resp); | ||
2287 | break; | ||
2288 | default: | ||
2289 | cy_as_hal_assert(cy_false); | ||
2290 | break; | ||
2291 | } | ||
2292 | } | ||
2293 | |||
2294 | /* Send a mailbox request to prepare the endpoint for switching */ | ||
2295 | static cy_as_return_status_t | ||
2296 | my_send_turbo_switch(cy_as_device *dev_p, uint32_t size, cy_bool pktread) | ||
2297 | { | ||
2298 | cy_as_return_status_t ret; | ||
2299 | cy_as_ll_request_response *req_p , *reply_p; | ||
2300 | |||
2301 | /* Create the request to send to the West Bridge device */ | ||
2302 | req_p = cy_as_ll_create_request(dev_p, | ||
2303 | CY_RQT_TURBO_SWITCH_ENDPOINT, CY_RQT_TUR_RQT_CONTEXT, 3); | ||
2304 | if (req_p == 0) | ||
2305 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2306 | |||
2307 | /* Reserve space for the reply, the reply data will | ||
2308 | * not exceed one word */ | ||
2309 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2310 | if (reply_p == 0) { | ||
2311 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2312 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2313 | } | ||
2314 | |||
2315 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2316 | (uint16_t)pktread); | ||
2317 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2318 | (uint16_t)((size >> 16) & 0xFFFF)); | ||
2319 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2320 | (uint16_t)(size & 0xFFFF)); | ||
2321 | |||
2322 | ret = cy_as_ll_send_request(dev_p, req_p, | ||
2323 | reply_p, cy_false, my_turbo_rqt_callback); | ||
2324 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2325 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2326 | cy_as_ll_destroy_request(dev_p, reply_p); | ||
2327 | return ret; | ||
2328 | } | ||
2329 | |||
2330 | return CY_AS_ERROR_SUCCESS; | ||
2331 | } | ||
2332 | |||
2333 | cy_as_return_status_t | ||
2334 | cy_as_usb_read_data(cy_as_device_handle handle, | ||
2335 | cy_as_end_point_number_t ep, cy_bool pktread, | ||
2336 | uint32_t dsize, uint32_t *dataread, void *data) | ||
2337 | { | ||
2338 | cy_as_return_status_t ret; | ||
2339 | cy_as_device *dev_p; | ||
2340 | |||
2341 | cy_as_log_debug_message(6, "cy_as_usb_read_data called"); | ||
2342 | |||
2343 | dev_p = (cy_as_device *)handle; | ||
2344 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2345 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2346 | |||
2347 | ret = is_usb_active(dev_p); | ||
2348 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2349 | return ret; | ||
2350 | |||
2351 | if (cy_as_device_is_in_callback(dev_p)) | ||
2352 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
2353 | |||
2354 | if (ep >= 16 || ep == 4 || ep == 6 || ep == 8) | ||
2355 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2356 | |||
2357 | /* EP2 is available for reading when MTP is active */ | ||
2358 | if (dev_p->mtp_count == 0 && ep == CY_AS_MTP_READ_ENDPOINT) | ||
2359 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2360 | |||
2361 | /* If the endpoint is disabled, we cannot | ||
2362 | * write data to the endpoint */ | ||
2363 | if (!dev_p->usb_config[ep].enabled) | ||
2364 | return CY_AS_ERROR_ENDPOINT_DISABLED; | ||
2365 | |||
2366 | if (dev_p->usb_config[ep].dir != cy_as_usb_out) | ||
2367 | return CY_AS_ERROR_USB_BAD_DIRECTION; | ||
2368 | |||
2369 | ret = cy_as_dma_queue_request(dev_p, ep, data, dsize, | ||
2370 | pktread, cy_true, sync_request_callback); | ||
2371 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2372 | return ret; | ||
2373 | |||
2374 | if (ep == CY_AS_MTP_READ_ENDPOINT) { | ||
2375 | ret = my_send_turbo_switch(dev_p, dsize, pktread); | ||
2376 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2377 | cy_as_dma_cancel(dev_p, ep, ret); | ||
2378 | return ret; | ||
2379 | } | ||
2380 | |||
2381 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_false); | ||
2382 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2383 | return ret; | ||
2384 | } else { | ||
2385 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_true); | ||
2386 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2387 | return ret; | ||
2388 | } | ||
2389 | |||
2390 | ret = dev_p->usb_error; | ||
2391 | *dataread = dev_p->usb_actual_cnt; | ||
2392 | |||
2393 | return ret; | ||
2394 | } | ||
2395 | EXPORT_SYMBOL(cy_as_usb_read_data); | ||
2396 | |||
2397 | cy_as_return_status_t | ||
2398 | cy_as_usb_read_data_async(cy_as_device_handle handle, | ||
2399 | cy_as_end_point_number_t ep, cy_bool pktread, | ||
2400 | uint32_t dsize, void *data, cy_as_usb_io_callback cb) | ||
2401 | { | ||
2402 | cy_as_return_status_t ret; | ||
2403 | uint32_t mask; | ||
2404 | cy_as_device *dev_p; | ||
2405 | |||
2406 | cy_as_log_debug_message(6, "cy_as_usb_read_data_async called"); | ||
2407 | |||
2408 | dev_p = (cy_as_device *)handle; | ||
2409 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2410 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2411 | |||
2412 | ret = is_usb_active(dev_p); | ||
2413 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2414 | return ret; | ||
2415 | |||
2416 | if (ep >= 16 || ep == 4 || ep == 6 || ep == 8) | ||
2417 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2418 | |||
2419 | /* EP2 is available for reading when MTP is active */ | ||
2420 | if (dev_p->mtp_count == 0 && ep == CY_AS_MTP_READ_ENDPOINT) | ||
2421 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2422 | |||
2423 | /* If the endpoint is disabled, we cannot | ||
2424 | * write data to the endpoint */ | ||
2425 | if (!dev_p->usb_config[ep].enabled) | ||
2426 | return CY_AS_ERROR_ENDPOINT_DISABLED; | ||
2427 | |||
2428 | if (dev_p->usb_config[ep].dir != cy_as_usb_out && | ||
2429 | dev_p->usb_config[ep].dir != cy_as_usb_in_out) | ||
2430 | return CY_AS_ERROR_USB_BAD_DIRECTION; | ||
2431 | |||
2432 | /* | ||
2433 | * since async operations can be triggered by interrupt | ||
2434 | * code, we must insure that we do not get multiple async | ||
2435 | * operations going at one time and protect this test and | ||
2436 | * set operation from interrupts. | ||
2437 | */ | ||
2438 | mask = cy_as_hal_disable_interrupts(); | ||
2439 | if (cy_as_device_is_usb_async_pending(dev_p, ep)) { | ||
2440 | cy_as_hal_enable_interrupts(mask); | ||
2441 | return CY_AS_ERROR_ASYNC_PENDING; | ||
2442 | } | ||
2443 | cy_as_device_set_usb_async_pending(dev_p, ep); | ||
2444 | |||
2445 | /* | ||
2446 | * if this is for EP0, we set this bit to delay the | ||
2447 | * ACK response until after this read has completed. | ||
2448 | */ | ||
2449 | if (ep == 0) | ||
2450 | cy_as_device_set_ack_delayed(dev_p); | ||
2451 | |||
2452 | cy_as_hal_enable_interrupts(mask); | ||
2453 | |||
2454 | cy_as_hal_assert(dev_p->usb_cb[ep] == 0); | ||
2455 | dev_p->usb_cb[ep] = cb; | ||
2456 | |||
2457 | ret = cy_as_dma_queue_request(dev_p, ep, data, dsize, | ||
2458 | pktread, cy_true, async_read_request_callback); | ||
2459 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2460 | return ret; | ||
2461 | |||
2462 | if (ep == CY_AS_MTP_READ_ENDPOINT) { | ||
2463 | ret = my_send_turbo_switch(dev_p, dsize, pktread); | ||
2464 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2465 | cy_as_dma_cancel(dev_p, ep, ret); | ||
2466 | return ret; | ||
2467 | } | ||
2468 | } else { | ||
2469 | /* Kick start the queue if it is not running */ | ||
2470 | cy_as_dma_kick_start(dev_p, ep); | ||
2471 | } | ||
2472 | return ret; | ||
2473 | } | ||
2474 | EXPORT_SYMBOL(cy_as_usb_read_data_async); | ||
2475 | |||
2476 | cy_as_return_status_t | ||
2477 | cy_as_usb_write_data(cy_as_device_handle handle, | ||
2478 | cy_as_end_point_number_t ep, uint32_t dsize, void *data) | ||
2479 | { | ||
2480 | cy_as_return_status_t ret; | ||
2481 | cy_as_device *dev_p; | ||
2482 | |||
2483 | cy_as_log_debug_message(6, "cy_as_usb_write_data called"); | ||
2484 | |||
2485 | dev_p = (cy_as_device *)handle; | ||
2486 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2487 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2488 | |||
2489 | ret = is_usb_active(dev_p); | ||
2490 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2491 | return ret; | ||
2492 | |||
2493 | if (cy_as_device_is_in_callback(dev_p)) | ||
2494 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
2495 | |||
2496 | if (ep >= 16 || ep == 2 || ep == 4 || ep == 8) | ||
2497 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2498 | |||
2499 | /* EP6 is available for writing when MTP is active */ | ||
2500 | if (dev_p->mtp_count == 0 && ep == CY_AS_MTP_WRITE_ENDPOINT) | ||
2501 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2502 | |||
2503 | /* If the endpoint is disabled, we cannot | ||
2504 | * write data to the endpoint */ | ||
2505 | if (!dev_p->usb_config[ep].enabled) | ||
2506 | return CY_AS_ERROR_ENDPOINT_DISABLED; | ||
2507 | |||
2508 | if (dev_p->usb_config[ep].dir != cy_as_usb_in && | ||
2509 | dev_p->usb_config[ep].dir != cy_as_usb_in_out) | ||
2510 | return CY_AS_ERROR_USB_BAD_DIRECTION; | ||
2511 | |||
2512 | /* Write on Turbo endpoint */ | ||
2513 | if (ep == CY_AS_MTP_WRITE_ENDPOINT) { | ||
2514 | cy_as_ll_request_response *req_p, *reply_p; | ||
2515 | |||
2516 | req_p = cy_as_ll_create_request(dev_p, | ||
2517 | CY_RQT_TURBO_SEND_RESP_DATA_TO_HOST, | ||
2518 | CY_RQT_TUR_RQT_CONTEXT, 3); | ||
2519 | if (req_p == 0) | ||
2520 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2521 | |||
2522 | cy_as_ll_request_response__set_word(req_p, | ||
2523 | 0, 0x0006); /* EP number to use. */ | ||
2524 | cy_as_ll_request_response__set_word(req_p, | ||
2525 | 1, (uint16_t)((dsize >> 16) & 0xFFFF)); | ||
2526 | cy_as_ll_request_response__set_word(req_p, | ||
2527 | 2, (uint16_t)(dsize & 0xFFFF)); | ||
2528 | |||
2529 | /* Reserve space for the reply, the reply data | ||
2530 | * will not exceed one word */ | ||
2531 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2532 | if (reply_p == 0) { | ||
2533 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2534 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2535 | } | ||
2536 | |||
2537 | if (dsize) { | ||
2538 | ret = cy_as_dma_queue_request(dev_p, | ||
2539 | ep, data, dsize, cy_false, | ||
2540 | cy_false, sync_request_callback); | ||
2541 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2542 | return ret; | ||
2543 | } | ||
2544 | |||
2545 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
2546 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
2547 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
2548 | CY_RESP_SUCCESS_FAILURE) | ||
2549 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2550 | else | ||
2551 | ret = cy_as_ll_request_response__get_word | ||
2552 | (reply_p, 0); | ||
2553 | } | ||
2554 | |||
2555 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2556 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2557 | |||
2558 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2559 | if (dsize) | ||
2560 | cy_as_dma_cancel(dev_p, ep, ret); | ||
2561 | return ret; | ||
2562 | } | ||
2563 | |||
2564 | /* If this is a zero-byte write, firmware will | ||
2565 | * handle it. there is no need to do any work here. | ||
2566 | */ | ||
2567 | if (!dsize) | ||
2568 | return CY_AS_ERROR_SUCCESS; | ||
2569 | } else { | ||
2570 | ret = cy_as_dma_queue_request(dev_p, ep, data, dsize, | ||
2571 | cy_false, cy_false, sync_request_callback); | ||
2572 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2573 | return ret; | ||
2574 | } | ||
2575 | |||
2576 | if (ep != CY_AS_MTP_WRITE_ENDPOINT) | ||
2577 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_true); | ||
2578 | else | ||
2579 | ret = cy_as_dma_drain_queue(dev_p, ep, cy_false); | ||
2580 | |||
2581 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2582 | return ret; | ||
2583 | |||
2584 | ret = dev_p->usb_error; | ||
2585 | return ret; | ||
2586 | } | ||
2587 | EXPORT_SYMBOL(cy_as_usb_write_data); | ||
2588 | |||
2589 | static void | ||
2590 | mtp_write_callback( | ||
2591 | cy_as_device *dev_p, | ||
2592 | uint8_t context, | ||
2593 | cy_as_ll_request_response *rqt, | ||
2594 | cy_as_ll_request_response *resp, | ||
2595 | cy_as_return_status_t ret) | ||
2596 | { | ||
2597 | cy_as_usb_io_callback cb; | ||
2598 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
2599 | |||
2600 | cy_as_hal_assert(context == CY_RQT_TUR_RQT_CONTEXT); | ||
2601 | |||
2602 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
2603 | if (cy_as_ll_request_response__get_code(resp) != | ||
2604 | CY_RESP_SUCCESS_FAILURE) | ||
2605 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2606 | else | ||
2607 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
2608 | } | ||
2609 | |||
2610 | /* If this was a zero byte transfer request, we can | ||
2611 | * call the callback from here. */ | ||
2612 | if ((cy_as_ll_request_response__get_word(rqt, 1) == 0) && | ||
2613 | (cy_as_ll_request_response__get_word(rqt, 2) == 0)) { | ||
2614 | cb = dev_p->usb_cb[CY_AS_MTP_WRITE_ENDPOINT]; | ||
2615 | dev_p->usb_cb[CY_AS_MTP_WRITE_ENDPOINT] = 0; | ||
2616 | cy_as_device_clear_usb_async_pending(dev_p, | ||
2617 | CY_AS_MTP_WRITE_ENDPOINT); | ||
2618 | if (cb) | ||
2619 | cb(h, CY_AS_MTP_WRITE_ENDPOINT, 0, 0, ret); | ||
2620 | |||
2621 | goto destroy; | ||
2622 | } | ||
2623 | |||
2624 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2625 | /* Firmware failed the request. Cancel the DMA transfer. */ | ||
2626 | cy_as_dma_cancel(dev_p, 0x06, CY_AS_ERROR_CANCELED); | ||
2627 | dev_p->usb_cb[0x06] = 0; | ||
2628 | cy_as_device_clear_usb_async_pending(dev_p, 0x06); | ||
2629 | } | ||
2630 | |||
2631 | destroy: | ||
2632 | cy_as_ll_destroy_response(dev_p, resp); | ||
2633 | cy_as_ll_destroy_request(dev_p, rqt); | ||
2634 | } | ||
2635 | |||
2636 | cy_as_return_status_t | ||
2637 | cy_as_usb_write_data_async(cy_as_device_handle handle, | ||
2638 | cy_as_end_point_number_t ep, uint32_t dsize, void *data, | ||
2639 | cy_bool spacket, cy_as_usb_io_callback cb) | ||
2640 | { | ||
2641 | uint32_t mask; | ||
2642 | cy_as_return_status_t ret; | ||
2643 | cy_as_device *dev_p; | ||
2644 | |||
2645 | cy_as_log_debug_message(6, "cy_as_usb_write_data_async called"); | ||
2646 | |||
2647 | dev_p = (cy_as_device *)handle; | ||
2648 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2649 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2650 | |||
2651 | ret = is_usb_active(dev_p); | ||
2652 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2653 | return ret; | ||
2654 | |||
2655 | if (ep >= 16 || ep == 2 || ep == 4 || ep == 8) | ||
2656 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2657 | |||
2658 | /* EP6 is available for writing when MTP is active */ | ||
2659 | if (dev_p->mtp_count == 0 && ep == CY_AS_MTP_WRITE_ENDPOINT) | ||
2660 | return CY_AS_ERROR_INVALID_ENDPOINT; | ||
2661 | |||
2662 | /* If the endpoint is disabled, we cannot | ||
2663 | * write data to the endpoint */ | ||
2664 | if (!dev_p->usb_config[ep].enabled) | ||
2665 | return CY_AS_ERROR_ENDPOINT_DISABLED; | ||
2666 | |||
2667 | if (dev_p->usb_config[ep].dir != cy_as_usb_in && | ||
2668 | dev_p->usb_config[ep].dir != cy_as_usb_in_out) | ||
2669 | return CY_AS_ERROR_USB_BAD_DIRECTION; | ||
2670 | |||
2671 | /* | ||
2672 | * since async operations can be triggered by interrupt | ||
2673 | * code, we must insure that we do not get multiple | ||
2674 | * async operations going at one time and | ||
2675 | * protect this test and set operation from interrupts. | ||
2676 | */ | ||
2677 | mask = cy_as_hal_disable_interrupts(); | ||
2678 | if (cy_as_device_is_usb_async_pending(dev_p, ep)) { | ||
2679 | cy_as_hal_enable_interrupts(mask); | ||
2680 | return CY_AS_ERROR_ASYNC_PENDING; | ||
2681 | } | ||
2682 | |||
2683 | cy_as_device_set_usb_async_pending(dev_p, ep); | ||
2684 | |||
2685 | if (ep == 0) | ||
2686 | cy_as_device_set_ack_delayed(dev_p); | ||
2687 | |||
2688 | cy_as_hal_enable_interrupts(mask); | ||
2689 | |||
2690 | cy_as_hal_assert(dev_p->usb_cb[ep] == 0); | ||
2691 | dev_p->usb_cb[ep] = cb; | ||
2692 | dev_p->usb_spacket[ep] = spacket; | ||
2693 | |||
2694 | /* Write on Turbo endpoint */ | ||
2695 | if (ep == CY_AS_MTP_WRITE_ENDPOINT) { | ||
2696 | cy_as_ll_request_response *req_p, *reply_p; | ||
2697 | |||
2698 | req_p = cy_as_ll_create_request(dev_p, | ||
2699 | CY_RQT_TURBO_SEND_RESP_DATA_TO_HOST, | ||
2700 | CY_RQT_TUR_RQT_CONTEXT, 3); | ||
2701 | |||
2702 | if (req_p == 0) | ||
2703 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2704 | |||
2705 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2706 | 0x0006); /* EP number to use. */ | ||
2707 | cy_as_ll_request_response__set_word(req_p, 1, | ||
2708 | (uint16_t)((dsize >> 16) & 0xFFFF)); | ||
2709 | cy_as_ll_request_response__set_word(req_p, 2, | ||
2710 | (uint16_t)(dsize & 0xFFFF)); | ||
2711 | |||
2712 | /* Reserve space for the reply, the reply data | ||
2713 | * will not exceed one word */ | ||
2714 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2715 | if (reply_p == 0) { | ||
2716 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2717 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2718 | } | ||
2719 | |||
2720 | if (dsize) { | ||
2721 | ret = cy_as_dma_queue_request(dev_p, ep, data, | ||
2722 | dsize, cy_false, cy_false, | ||
2723 | async_write_request_callback); | ||
2724 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2725 | return ret; | ||
2726 | } | ||
2727 | |||
2728 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
2729 | cy_false, mtp_write_callback); | ||
2730 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2731 | if (dsize) | ||
2732 | cy_as_dma_cancel(dev_p, ep, ret); | ||
2733 | return ret; | ||
2734 | } | ||
2735 | |||
2736 | /* Firmware will handle a zero byte transfer | ||
2737 | * without any DMA transfers. */ | ||
2738 | if (!dsize) | ||
2739 | return CY_AS_ERROR_SUCCESS; | ||
2740 | } else { | ||
2741 | ret = cy_as_dma_queue_request(dev_p, ep, data, dsize, | ||
2742 | cy_false, cy_false, async_write_request_callback); | ||
2743 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2744 | return ret; | ||
2745 | } | ||
2746 | |||
2747 | /* Kick start the queue if it is not running */ | ||
2748 | if (ep != CY_AS_MTP_WRITE_ENDPOINT) | ||
2749 | cy_as_dma_kick_start(dev_p, ep); | ||
2750 | |||
2751 | return CY_AS_ERROR_SUCCESS; | ||
2752 | } | ||
2753 | EXPORT_SYMBOL(cy_as_usb_write_data_async); | ||
2754 | |||
2755 | static void | ||
2756 | my_usb_cancel_async_callback( | ||
2757 | cy_as_device *dev_p, | ||
2758 | uint8_t context, | ||
2759 | cy_as_ll_request_response *rqt, | ||
2760 | cy_as_ll_request_response *resp, | ||
2761 | cy_as_return_status_t ret) | ||
2762 | { | ||
2763 | uint8_t ep; | ||
2764 | (void)context; | ||
2765 | |||
2766 | ep = (uint8_t)cy_as_ll_request_response__get_word(rqt, 0); | ||
2767 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
2768 | if (cy_as_ll_request_response__get_code(resp) != | ||
2769 | CY_RESP_SUCCESS_FAILURE) | ||
2770 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2771 | else | ||
2772 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
2773 | } | ||
2774 | |||
2775 | cy_as_ll_destroy_request(dev_p, rqt); | ||
2776 | cy_as_ll_destroy_response(dev_p, resp); | ||
2777 | |||
2778 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
2779 | cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
2780 | dev_p->usb_cb[ep] = 0; | ||
2781 | cy_as_device_clear_usb_async_pending(dev_p, ep); | ||
2782 | } | ||
2783 | } | ||
2784 | |||
2785 | cy_as_return_status_t | ||
2786 | cy_as_usb_cancel_async(cy_as_device_handle handle, | ||
2787 | cy_as_end_point_number_t ep) | ||
2788 | { | ||
2789 | cy_as_return_status_t ret; | ||
2790 | cy_as_ll_request_response *req_p, *reply_p; | ||
2791 | |||
2792 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2793 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2794 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2795 | |||
2796 | ep &= 0x7F; /* Remove the direction bit. */ | ||
2797 | if (!cy_as_device_is_usb_async_pending(dev_p, ep)) | ||
2798 | return CY_AS_ERROR_ASYNC_NOT_PENDING; | ||
2799 | |||
2800 | ret = is_usb_active(dev_p); | ||
2801 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2802 | return ret; | ||
2803 | |||
2804 | if (cy_as_device_is_in_suspend_mode(dev_p)) | ||
2805 | return CY_AS_ERROR_IN_SUSPEND; | ||
2806 | |||
2807 | if ((ep == CY_AS_MTP_WRITE_ENDPOINT) || | ||
2808 | (ep == CY_AS_MTP_READ_ENDPOINT)) { | ||
2809 | /* Need firmware support for the cancel operation. */ | ||
2810 | req_p = cy_as_ll_create_request(dev_p, | ||
2811 | CY_RQT_CANCEL_ASYNC_TRANSFER, | ||
2812 | CY_RQT_TUR_RQT_CONTEXT, 1); | ||
2813 | |||
2814 | if (req_p == 0) | ||
2815 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2816 | |||
2817 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2818 | if (reply_p == 0) { | ||
2819 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2820 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2821 | } | ||
2822 | |||
2823 | cy_as_ll_request_response__set_word(req_p, 0, | ||
2824 | (uint16_t)ep); | ||
2825 | |||
2826 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
2827 | cy_false, my_usb_cancel_async_callback); | ||
2828 | |||
2829 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
2830 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2831 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
2832 | return ret; | ||
2833 | } | ||
2834 | } else { | ||
2835 | ret = cy_as_dma_cancel(dev_p, ep, CY_AS_ERROR_CANCELED); | ||
2836 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2837 | return ret; | ||
2838 | |||
2839 | dev_p->usb_cb[ep] = 0; | ||
2840 | cy_as_device_clear_usb_async_pending(dev_p, ep); | ||
2841 | } | ||
2842 | |||
2843 | return CY_AS_ERROR_SUCCESS; | ||
2844 | } | ||
2845 | EXPORT_SYMBOL(cy_as_usb_cancel_async); | ||
2846 | |||
2847 | static void | ||
2848 | cy_as_usb_ack_callback( | ||
2849 | cy_as_device *dev_p, | ||
2850 | uint8_t context, | ||
2851 | cy_as_ll_request_response *rqt, | ||
2852 | cy_as_ll_request_response *resp, | ||
2853 | cy_as_return_status_t ret) | ||
2854 | { | ||
2855 | cy_as_func_c_b_node *node = (cy_as_func_c_b_node *) | ||
2856 | dev_p->func_cbs_usb->head_p; | ||
2857 | |||
2858 | (void)context; | ||
2859 | |||
2860 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
2861 | if (cy_as_ll_request_response__get_code(resp) != | ||
2862 | CY_RESP_SUCCESS_FAILURE) | ||
2863 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
2864 | else | ||
2865 | ret = cy_as_ll_request_response__get_word(resp, 0); | ||
2866 | } | ||
2867 | |||
2868 | node->cb_p((cy_as_device_handle)dev_p, ret, | ||
2869 | node->client_data, node->data_type, node->data); | ||
2870 | cy_as_remove_c_b_node(dev_p->func_cbs_usb); | ||
2871 | |||
2872 | cy_as_ll_destroy_request(dev_p, rqt); | ||
2873 | cy_as_ll_destroy_response(dev_p, resp); | ||
2874 | cy_as_device_clear_ack_delayed(dev_p); | ||
2875 | } | ||
2876 | |||
2877 | static cy_as_return_status_t | ||
2878 | cy_as_usb_ack_setup_packet(cy_as_device_handle handle, | ||
2879 | cy_as_function_callback cb, | ||
2880 | uint32_t client) | ||
2881 | { | ||
2882 | cy_as_return_status_t ret; | ||
2883 | cy_as_ll_request_response *req_p; | ||
2884 | cy_as_ll_request_response *reply_p; | ||
2885 | cy_as_func_c_b_node *cbnode; | ||
2886 | |||
2887 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2888 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2889 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2890 | |||
2891 | ret = is_usb_active(dev_p); | ||
2892 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2893 | return ret; | ||
2894 | |||
2895 | if (cy_as_device_is_in_callback(dev_p) && cb == 0) | ||
2896 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
2897 | |||
2898 | cy_as_hal_assert(cb != 0); | ||
2899 | |||
2900 | cbnode = cy_as_create_func_c_b_node(cb, client); | ||
2901 | if (cbnode == 0) | ||
2902 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2903 | |||
2904 | req_p = cy_as_ll_create_request(dev_p, 0, | ||
2905 | CY_RQT_USB_RQT_CONTEXT, 2); | ||
2906 | if (req_p == 0) | ||
2907 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2908 | |||
2909 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2910 | if (reply_p == 0) { | ||
2911 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2912 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2913 | } | ||
2914 | |||
2915 | cy_as_ll_init_request(req_p, CY_RQT_ACK_SETUP_PACKET, | ||
2916 | CY_RQT_USB_RQT_CONTEXT, 1); | ||
2917 | cy_as_ll_init_response(reply_p, 1); | ||
2918 | |||
2919 | req_p->flags |= CY_AS_REQUEST_RESPONSE_EX; | ||
2920 | |||
2921 | cy_as_insert_c_b_node(dev_p->func_cbs_usb, cbnode); | ||
2922 | |||
2923 | ret = cy_as_ll_send_request(dev_p, req_p, reply_p, | ||
2924 | cy_false, cy_as_usb_ack_callback); | ||
2925 | |||
2926 | return ret; | ||
2927 | } | ||
2928 | |||
2929 | /* | ||
2930 | * Flush all data in logical EP that is being NAK-ed or | ||
2931 | * Stall-ed, so that this does not continue to block data | ||
2932 | * on other LEPs that use the same physical EP. | ||
2933 | */ | ||
2934 | static void | ||
2935 | cy_as_usb_flush_logical_e_p( | ||
2936 | cy_as_device *dev_p, | ||
2937 | uint16_t ep) | ||
2938 | { | ||
2939 | uint16_t addr, val, count; | ||
2940 | |||
2941 | addr = CY_AS_MEM_P0_EP2_DMA_REG + ep - 2; | ||
2942 | val = cy_as_hal_read_register(dev_p->tag, addr); | ||
2943 | |||
2944 | while (val) { | ||
2945 | count = ((val & 0xFFF) + 1) / 2; | ||
2946 | while (count--) | ||
2947 | val = cy_as_hal_read_register(dev_p->tag, ep); | ||
2948 | |||
2949 | cy_as_hal_write_register(dev_p->tag, addr, 0); | ||
2950 | val = cy_as_hal_read_register(dev_p->tag, addr); | ||
2951 | } | ||
2952 | } | ||
2953 | |||
2954 | static cy_as_return_status_t | ||
2955 | cy_as_usb_nak_stall_request(cy_as_device_handle handle, | ||
2956 | cy_as_end_point_number_t ep, | ||
2957 | uint16_t request, | ||
2958 | cy_bool state, | ||
2959 | cy_as_usb_function_callback cb, | ||
2960 | cy_as_function_callback fcb, | ||
2961 | uint32_t client) | ||
2962 | { | ||
2963 | cy_as_return_status_t ret; | ||
2964 | cy_as_ll_request_response *req_p , *reply_p; | ||
2965 | uint16_t data; | ||
2966 | |||
2967 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
2968 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
2969 | return CY_AS_ERROR_INVALID_HANDLE; | ||
2970 | |||
2971 | if (cb) | ||
2972 | cy_as_hal_assert(fcb == 0); | ||
2973 | if (fcb) | ||
2974 | cy_as_hal_assert(cb == 0); | ||
2975 | |||
2976 | ret = is_usb_active(dev_p); | ||
2977 | if (ret != CY_AS_ERROR_SUCCESS) | ||
2978 | return ret; | ||
2979 | |||
2980 | if (cy_as_device_is_in_callback(dev_p) && cb == 0 && fcb == 0) | ||
2981 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
2982 | |||
2983 | req_p = cy_as_ll_create_request(dev_p, | ||
2984 | request, CY_RQT_USB_RQT_CONTEXT, 2); | ||
2985 | if (req_p == 0) | ||
2986 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2987 | |||
2988 | /* A single status word response type */ | ||
2989 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
2990 | if (reply_p == 0) { | ||
2991 | cy_as_ll_destroy_request(dev_p, req_p); | ||
2992 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
2993 | } | ||
2994 | |||
2995 | /* Set the endpoint */ | ||
2996 | data = (uint8_t)ep; | ||
2997 | cy_as_ll_request_response__set_word(req_p, 0, data); | ||
2998 | |||
2999 | /* Set stall state to stalled */ | ||
3000 | cy_as_ll_request_response__set_word(req_p, 1, (uint8_t)state); | ||
3001 | |||
3002 | if (cb || fcb) { | ||
3003 | void *cbnode; | ||
3004 | cy_as_c_b_queue *queue; | ||
3005 | if (cb) { | ||
3006 | cbnode = cy_as_create_usb_func_c_b_node(cb, client); | ||
3007 | queue = dev_p->usb_func_cbs; | ||
3008 | } else { | ||
3009 | cbnode = cy_as_create_func_c_b_node(fcb, client); | ||
3010 | queue = dev_p->func_cbs_usb; | ||
3011 | req_p->flags |= CY_AS_REQUEST_RESPONSE_EX; | ||
3012 | } | ||
3013 | |||
3014 | if (cbnode == 0) { | ||
3015 | ret = CY_AS_ERROR_OUT_OF_MEMORY; | ||
3016 | goto destroy; | ||
3017 | } else | ||
3018 | cy_as_insert_c_b_node(queue, cbnode); | ||
3019 | |||
3020 | |||
3021 | if (cy_as_device_is_setup_packet(dev_p)) { | ||
3022 | /* No Ack is needed on a stall request on EP0 */ | ||
3023 | if ((state == cy_true) && (ep == 0)) { | ||
3024 | cy_as_device_set_ep0_stalled(dev_p); | ||
3025 | } else { | ||
3026 | cy_as_device_set_ack_delayed(dev_p); | ||
3027 | req_p->flags |= | ||
3028 | CY_AS_REQUEST_RESPONSE_DELAY_ACK; | ||
3029 | } | ||
3030 | } | ||
3031 | |||
3032 | ret = cy_as_ll_send_request(dev_p, req_p, | ||
3033 | reply_p, cy_false, cy_as_usb_func_callback); | ||
3034 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
3035 | if (req_p->flags & CY_AS_REQUEST_RESPONSE_DELAY_ACK) | ||
3036 | cy_as_device_rem_ack_delayed(dev_p); | ||
3037 | cy_as_remove_c_b_tail_node(queue); | ||
3038 | |||
3039 | goto destroy; | ||
3040 | } | ||
3041 | } else { | ||
3042 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
3043 | req_p, reply_p); | ||
3044 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3045 | goto destroy; | ||
3046 | |||
3047 | if (cy_as_ll_request_response__get_code(reply_p) != | ||
3048 | CY_RESP_SUCCESS_FAILURE) { | ||
3049 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3050 | goto destroy; | ||
3051 | } | ||
3052 | |||
3053 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3054 | |||
3055 | if ((ret == CY_AS_ERROR_SUCCESS) && | ||
3056 | (request == CY_RQT_STALL_ENDPOINT)) { | ||
3057 | if ((ep > 1) && (state != 0) && | ||
3058 | (dev_p->usb_config[ep].dir == cy_as_usb_out)) | ||
3059 | cy_as_usb_flush_logical_e_p(dev_p, ep); | ||
3060 | } | ||
3061 | |||
3062 | destroy: | ||
3063 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3064 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3065 | } | ||
3066 | |||
3067 | return ret; | ||
3068 | } | ||
3069 | |||
3070 | static cy_as_return_status_t | ||
3071 | my_handle_response_get_stall(cy_as_device *dev_p, | ||
3072 | cy_as_ll_request_response *req_p, | ||
3073 | cy_as_ll_request_response *reply_p, | ||
3074 | cy_bool *state_p) | ||
3075 | { | ||
3076 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3077 | uint8_t code = cy_as_ll_request_response__get_code(reply_p); | ||
3078 | |||
3079 | if (code == CY_RESP_SUCCESS_FAILURE) { | ||
3080 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3081 | goto destroy; | ||
3082 | } else if (code != CY_RESP_ENDPOINT_STALL) { | ||
3083 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3084 | goto destroy; | ||
3085 | } | ||
3086 | |||
3087 | *state_p = (cy_bool)cy_as_ll_request_response__get_word(reply_p, 0); | ||
3088 | ret = CY_AS_ERROR_SUCCESS; | ||
3089 | |||
3090 | |||
3091 | destroy: | ||
3092 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3093 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3094 | |||
3095 | return ret; | ||
3096 | } | ||
3097 | |||
3098 | static cy_as_return_status_t | ||
3099 | my_handle_response_get_nak(cy_as_device *dev_p, | ||
3100 | cy_as_ll_request_response *req_p, | ||
3101 | cy_as_ll_request_response *reply_p, | ||
3102 | cy_bool *state_p) | ||
3103 | { | ||
3104 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3105 | uint8_t code = cy_as_ll_request_response__get_code(reply_p); | ||
3106 | |||
3107 | if (code == CY_RESP_SUCCESS_FAILURE) { | ||
3108 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3109 | goto destroy; | ||
3110 | } else if (code != CY_RESP_ENDPOINT_NAK) { | ||
3111 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3112 | goto destroy; | ||
3113 | } | ||
3114 | |||
3115 | *state_p = (cy_bool)cy_as_ll_request_response__get_word(reply_p, 0); | ||
3116 | ret = CY_AS_ERROR_SUCCESS; | ||
3117 | |||
3118 | |||
3119 | destroy: | ||
3120 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3121 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3122 | |||
3123 | return ret; | ||
3124 | } | ||
3125 | |||
3126 | static cy_as_return_status_t | ||
3127 | cy_as_usb_get_nak_stall(cy_as_device_handle handle, | ||
3128 | cy_as_end_point_number_t ep, | ||
3129 | uint16_t request, | ||
3130 | uint16_t response, | ||
3131 | cy_bool *state_p, | ||
3132 | cy_as_function_callback cb, | ||
3133 | uint32_t client) | ||
3134 | { | ||
3135 | cy_as_return_status_t ret; | ||
3136 | cy_as_ll_request_response *req_p , *reply_p; | ||
3137 | uint16_t data; | ||
3138 | |||
3139 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3140 | |||
3141 | (void)response; | ||
3142 | |||
3143 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3144 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3145 | |||
3146 | ret = is_usb_active(dev_p); | ||
3147 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3148 | return ret; | ||
3149 | |||
3150 | if (cy_as_device_is_in_callback(dev_p) && !cb) | ||
3151 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
3152 | |||
3153 | req_p = cy_as_ll_create_request(dev_p, request, | ||
3154 | CY_RQT_USB_RQT_CONTEXT, 1); | ||
3155 | if (req_p == 0) | ||
3156 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3157 | |||
3158 | /* Set the endpoint */ | ||
3159 | data = (uint8_t)ep; | ||
3160 | cy_as_ll_request_response__set_word(req_p, 0, (uint16_t)ep); | ||
3161 | |||
3162 | /* A single status word response type */ | ||
3163 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
3164 | if (reply_p == 0) { | ||
3165 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3166 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3167 | } | ||
3168 | |||
3169 | if (cb == 0) { | ||
3170 | ret = cy_as_ll_send_request_wait_reply(dev_p, | ||
3171 | req_p, reply_p); | ||
3172 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3173 | goto destroy; | ||
3174 | |||
3175 | if (request == CY_RQT_GET_STALL) | ||
3176 | return my_handle_response_get_stall(dev_p, | ||
3177 | req_p, reply_p, state_p); | ||
3178 | else | ||
3179 | return my_handle_response_get_nak(dev_p, | ||
3180 | req_p, reply_p, state_p); | ||
3181 | |||
3182 | } else { | ||
3183 | cy_as_funct_c_b_type type; | ||
3184 | |||
3185 | if (request == CY_RQT_GET_STALL) | ||
3186 | type = CY_FUNCT_CB_USB_GETSTALL; | ||
3187 | else | ||
3188 | type = CY_FUNCT_CB_USB_GETNAK; | ||
3189 | |||
3190 | ret = cy_as_misc_send_request(dev_p, cb, client, type, | ||
3191 | state_p, dev_p->func_cbs_usb, CY_AS_REQUEST_RESPONSE_EX, | ||
3192 | req_p, reply_p, cy_as_usb_func_callback); | ||
3193 | |||
3194 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3195 | goto destroy; | ||
3196 | |||
3197 | return ret; | ||
3198 | } | ||
3199 | |||
3200 | destroy: | ||
3201 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3202 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3203 | |||
3204 | return ret; | ||
3205 | } | ||
3206 | |||
3207 | cy_as_return_status_t | ||
3208 | cy_as_usb_set_nak(cy_as_device_handle handle, | ||
3209 | cy_as_end_point_number_t ep, | ||
3210 | cy_as_function_callback cb, | ||
3211 | uint32_t client) | ||
3212 | { | ||
3213 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3214 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3215 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3216 | |||
3217 | /* | ||
3218 | * we send the firmware the EP# with the appropriate direction | ||
3219 | * bit, regardless of what the user gave us. | ||
3220 | */ | ||
3221 | ep &= 0x0f; | ||
3222 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3223 | ep |= 0x80; | ||
3224 | |||
3225 | if (dev_p->mtp_count > 0) | ||
3226 | return CY_AS_ERROR_NOT_VALID_IN_MTP; | ||
3227 | |||
3228 | return cy_as_usb_nak_stall_request(handle, ep, | ||
3229 | CY_RQT_ENDPOINT_SET_NAK, cy_true, 0, cb, client); | ||
3230 | } | ||
3231 | EXPORT_SYMBOL(cy_as_usb_set_nak); | ||
3232 | |||
3233 | cy_as_return_status_t | ||
3234 | cy_as_usb_clear_nak(cy_as_device_handle handle, | ||
3235 | cy_as_end_point_number_t ep, | ||
3236 | cy_as_function_callback cb, | ||
3237 | uint32_t client) | ||
3238 | { | ||
3239 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3240 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3241 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3242 | |||
3243 | /* | ||
3244 | * we send the firmware the EP# with the appropriate | ||
3245 | * direction bit, regardless of what the user gave us. | ||
3246 | */ | ||
3247 | ep &= 0x0f; | ||
3248 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3249 | ep |= 0x80; | ||
3250 | |||
3251 | if (dev_p->mtp_count > 0) | ||
3252 | return CY_AS_ERROR_NOT_VALID_IN_MTP; | ||
3253 | |||
3254 | return cy_as_usb_nak_stall_request(handle, ep, | ||
3255 | CY_RQT_ENDPOINT_SET_NAK, cy_false, 0, cb, client); | ||
3256 | } | ||
3257 | EXPORT_SYMBOL(cy_as_usb_clear_nak); | ||
3258 | |||
3259 | cy_as_return_status_t | ||
3260 | cy_as_usb_get_nak(cy_as_device_handle handle, | ||
3261 | cy_as_end_point_number_t ep, | ||
3262 | cy_bool *nak_p, | ||
3263 | cy_as_function_callback cb, | ||
3264 | uint32_t client) | ||
3265 | { | ||
3266 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3267 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3268 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3269 | |||
3270 | /* | ||
3271 | * we send the firmware the EP# with the appropriate | ||
3272 | * direction bit, regardless of what the user gave us. | ||
3273 | */ | ||
3274 | ep &= 0x0f; | ||
3275 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3276 | ep |= 0x80; | ||
3277 | |||
3278 | if (dev_p->mtp_count > 0) | ||
3279 | return CY_AS_ERROR_NOT_VALID_IN_MTP; | ||
3280 | |||
3281 | return cy_as_usb_get_nak_stall(handle, ep, | ||
3282 | CY_RQT_GET_ENDPOINT_NAK, CY_RESP_ENDPOINT_NAK, | ||
3283 | nak_p, cb, client); | ||
3284 | } | ||
3285 | EXPORT_SYMBOL(cy_as_usb_get_nak); | ||
3286 | |||
3287 | cy_as_return_status_t | ||
3288 | cy_as_usb_set_stall(cy_as_device_handle handle, | ||
3289 | cy_as_end_point_number_t ep, | ||
3290 | cy_as_function_callback cb, | ||
3291 | uint32_t client) | ||
3292 | { | ||
3293 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3294 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3295 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3296 | |||
3297 | /* | ||
3298 | * we send the firmware the EP# with the appropriate | ||
3299 | * direction bit, regardless of what the user gave us. | ||
3300 | */ | ||
3301 | ep &= 0x0f; | ||
3302 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3303 | ep |= 0x80; | ||
3304 | |||
3305 | if (dev_p->mtp_turbo_active) | ||
3306 | return CY_AS_ERROR_NOT_VALID_DURING_MTP; | ||
3307 | |||
3308 | return cy_as_usb_nak_stall_request(handle, ep, | ||
3309 | CY_RQT_STALL_ENDPOINT, cy_true, 0, cb, client); | ||
3310 | } | ||
3311 | EXPORT_SYMBOL(cy_as_usb_set_stall); | ||
3312 | |||
3313 | cy_as_return_status_t | ||
3314 | cy_as_usb_clear_stall(cy_as_device_handle handle, | ||
3315 | cy_as_end_point_number_t ep, | ||
3316 | cy_as_function_callback cb, | ||
3317 | uint32_t client) | ||
3318 | { | ||
3319 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3320 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3321 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3322 | |||
3323 | /* | ||
3324 | * we send the firmware the EP# with the appropriate | ||
3325 | * direction bit, regardless of what the user gave us. | ||
3326 | */ | ||
3327 | ep &= 0x0f; | ||
3328 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3329 | ep |= 0x80; | ||
3330 | |||
3331 | if (dev_p->mtp_turbo_active) | ||
3332 | return CY_AS_ERROR_NOT_VALID_DURING_MTP; | ||
3333 | |||
3334 | return cy_as_usb_nak_stall_request(handle, ep, | ||
3335 | CY_RQT_STALL_ENDPOINT, cy_false, 0, cb, client); | ||
3336 | } | ||
3337 | EXPORT_SYMBOL(cy_as_usb_clear_stall); | ||
3338 | |||
3339 | cy_as_return_status_t | ||
3340 | cy_as_usb_get_stall(cy_as_device_handle handle, | ||
3341 | cy_as_end_point_number_t ep, | ||
3342 | cy_bool *stall_p, | ||
3343 | cy_as_function_callback cb, | ||
3344 | uint32_t client) | ||
3345 | { | ||
3346 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3347 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3348 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3349 | |||
3350 | /* | ||
3351 | * we send the firmware the EP# with the appropriate | ||
3352 | * direction bit, regardless of what the user gave us. | ||
3353 | */ | ||
3354 | ep &= 0x0f; | ||
3355 | if (dev_p->usb_config[ep].dir == cy_as_usb_in) | ||
3356 | ep |= 0x80; | ||
3357 | |||
3358 | if (dev_p->mtp_turbo_active) | ||
3359 | return CY_AS_ERROR_NOT_VALID_DURING_MTP; | ||
3360 | |||
3361 | return cy_as_usb_get_nak_stall(handle, ep, | ||
3362 | CY_RQT_GET_STALL, CY_RESP_ENDPOINT_STALL, stall_p, cb, client); | ||
3363 | } | ||
3364 | EXPORT_SYMBOL(cy_as_usb_get_stall); | ||
3365 | |||
3366 | cy_as_return_status_t | ||
3367 | cy_as_usb_signal_remote_wakeup(cy_as_device_handle handle, | ||
3368 | cy_as_function_callback cb, | ||
3369 | uint32_t client) | ||
3370 | { | ||
3371 | cy_as_return_status_t ret; | ||
3372 | cy_as_ll_request_response *req_p , *reply_p; | ||
3373 | |||
3374 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3375 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3376 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3377 | |||
3378 | ret = is_usb_active(dev_p); | ||
3379 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3380 | return ret; | ||
3381 | |||
3382 | if (cy_as_device_is_in_callback(dev_p)) | ||
3383 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
3384 | |||
3385 | if (dev_p->usb_last_event != cy_as_event_usb_suspend) | ||
3386 | return CY_AS_ERROR_NOT_IN_SUSPEND; | ||
3387 | |||
3388 | req_p = cy_as_ll_create_request(dev_p, | ||
3389 | CY_RQT_USB_REMOTE_WAKEUP, CY_RQT_USB_RQT_CONTEXT, 0); | ||
3390 | if (req_p == 0) | ||
3391 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3392 | |||
3393 | /* A single status word response type */ | ||
3394 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
3395 | if (reply_p == 0) { | ||
3396 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3397 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3398 | } | ||
3399 | |||
3400 | if (cb == 0) { | ||
3401 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3402 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3403 | goto destroy; | ||
3404 | |||
3405 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
3406 | CY_RESP_SUCCESS_FAILURE) | ||
3407 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3408 | else | ||
3409 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3410 | } else { | ||
3411 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
3412 | CY_FUNCT_CB_USB_SIGNALREMOTEWAKEUP, 0, | ||
3413 | dev_p->func_cbs_usb, | ||
3414 | CY_AS_REQUEST_RESPONSE_EX, req_p, | ||
3415 | reply_p, cy_as_usb_func_callback); | ||
3416 | |||
3417 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3418 | goto destroy; | ||
3419 | return ret; | ||
3420 | } | ||
3421 | |||
3422 | destroy: | ||
3423 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3424 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3425 | |||
3426 | return ret; | ||
3427 | } | ||
3428 | EXPORT_SYMBOL(cy_as_usb_signal_remote_wakeup); | ||
3429 | |||
3430 | cy_as_return_status_t | ||
3431 | cy_as_usb_set_m_s_report_threshold(cy_as_device_handle handle, | ||
3432 | uint32_t wr_sectors, | ||
3433 | uint32_t rd_sectors, | ||
3434 | cy_as_function_callback cb, | ||
3435 | uint32_t client) | ||
3436 | { | ||
3437 | cy_as_return_status_t ret; | ||
3438 | cy_as_ll_request_response *req_p , *reply_p; | ||
3439 | |||
3440 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3441 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3442 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3443 | |||
3444 | ret = is_usb_active(dev_p); | ||
3445 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3446 | return ret; | ||
3447 | |||
3448 | if ((cb == 0) && (cy_as_device_is_in_callback(dev_p))) | ||
3449 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
3450 | |||
3451 | /* Check if the firmware version supports this feature. */ | ||
3452 | if ((dev_p->media_supported[0]) && (dev_p->media_supported[0] == | ||
3453 | (1 << cy_as_media_nand))) | ||
3454 | return CY_AS_ERROR_NOT_SUPPORTED; | ||
3455 | |||
3456 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_USB_STORAGE_MONITOR, | ||
3457 | CY_RQT_USB_RQT_CONTEXT, 4); | ||
3458 | if (req_p == 0) | ||
3459 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3460 | |||
3461 | /* A single status word response type */ | ||
3462 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
3463 | if (reply_p == 0) { | ||
3464 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3465 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3466 | } | ||
3467 | |||
3468 | /* Set the read and write count parameters into | ||
3469 | * the request structure. */ | ||
3470 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3471 | (uint16_t)((wr_sectors >> 16) & 0xFFFF)); | ||
3472 | cy_as_ll_request_response__set_word(req_p, 1, | ||
3473 | (uint16_t)(wr_sectors & 0xFFFF)); | ||
3474 | cy_as_ll_request_response__set_word(req_p, 2, | ||
3475 | (uint16_t)((rd_sectors >> 16) & 0xFFFF)); | ||
3476 | cy_as_ll_request_response__set_word(req_p, 3, | ||
3477 | (uint16_t)(rd_sectors & 0xFFFF)); | ||
3478 | |||
3479 | if (cb == 0) { | ||
3480 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3481 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3482 | goto destroy; | ||
3483 | |||
3484 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
3485 | CY_RESP_SUCCESS_FAILURE) | ||
3486 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3487 | else | ||
3488 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3489 | } else { | ||
3490 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
3491 | CY_FUNCT_CB_USB_SET_MSREPORT_THRESHOLD, 0, | ||
3492 | dev_p->func_cbs_usb, CY_AS_REQUEST_RESPONSE_EX, | ||
3493 | req_p, reply_p, cy_as_usb_func_callback); | ||
3494 | |||
3495 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3496 | goto destroy; | ||
3497 | return ret; | ||
3498 | } | ||
3499 | |||
3500 | destroy: | ||
3501 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3502 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3503 | |||
3504 | return ret; | ||
3505 | } | ||
3506 | EXPORT_SYMBOL(cy_as_usb_set_m_s_report_threshold); | ||
3507 | |||
3508 | cy_as_return_status_t | ||
3509 | cy_as_usb_select_m_s_partitions( | ||
3510 | cy_as_device_handle handle, | ||
3511 | cy_as_bus_number_t bus, | ||
3512 | uint32_t device, | ||
3513 | cy_as_usb_m_s_type_t type, | ||
3514 | cy_as_function_callback cb, | ||
3515 | uint32_t client) | ||
3516 | { | ||
3517 | cy_as_return_status_t ret; | ||
3518 | cy_as_ll_request_response *req_p , *reply_p; | ||
3519 | uint16_t val; | ||
3520 | |||
3521 | cy_as_device *dev_p = (cy_as_device *)handle; | ||
3522 | if (!dev_p || (dev_p->sig != CY_AS_DEVICE_HANDLE_SIGNATURE)) | ||
3523 | return CY_AS_ERROR_INVALID_HANDLE; | ||
3524 | |||
3525 | ret = is_usb_active(dev_p); | ||
3526 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3527 | return ret; | ||
3528 | |||
3529 | /* This API has to be made before SetEnumConfig is called. */ | ||
3530 | if (dev_p->usb_config[0].enabled) | ||
3531 | return CY_AS_ERROR_INVALID_CALL_SEQUENCE; | ||
3532 | |||
3533 | if ((cb == 0) && (cy_as_device_is_in_callback(dev_p))) | ||
3534 | return CY_AS_ERROR_INVALID_IN_CALLBACK; | ||
3535 | |||
3536 | req_p = cy_as_ll_create_request(dev_p, CY_RQT_MS_PARTITION_SELECT, | ||
3537 | CY_RQT_USB_RQT_CONTEXT, 2); | ||
3538 | if (req_p == 0) | ||
3539 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3540 | |||
3541 | /* A single status word response type */ | ||
3542 | reply_p = cy_as_ll_create_response(dev_p, 1); | ||
3543 | if (reply_p == 0) { | ||
3544 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3545 | return CY_AS_ERROR_OUT_OF_MEMORY; | ||
3546 | } | ||
3547 | |||
3548 | /* Set the read and write count parameters into | ||
3549 | * the request structure. */ | ||
3550 | cy_as_ll_request_response__set_word(req_p, 0, | ||
3551 | (uint16_t)((bus << 8) | device)); | ||
3552 | |||
3553 | val = 0; | ||
3554 | if ((type == cy_as_usb_m_s_unit0) || (type == cy_as_usb_m_s_both)) | ||
3555 | val |= 1; | ||
3556 | if ((type == cy_as_usb_m_s_unit1) || (type == cy_as_usb_m_s_both)) | ||
3557 | val |= (1 << 8); | ||
3558 | |||
3559 | cy_as_ll_request_response__set_word(req_p, 1, val); | ||
3560 | |||
3561 | if (cb == 0) { | ||
3562 | ret = cy_as_ll_send_request_wait_reply(dev_p, req_p, reply_p); | ||
3563 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3564 | goto destroy; | ||
3565 | |||
3566 | if (cy_as_ll_request_response__get_code(reply_p) == | ||
3567 | CY_RESP_SUCCESS_FAILURE) | ||
3568 | ret = cy_as_ll_request_response__get_word(reply_p, 0); | ||
3569 | else | ||
3570 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3571 | } else { | ||
3572 | ret = cy_as_misc_send_request(dev_p, cb, client, | ||
3573 | CY_FUNCT_CB_NODATA, 0, dev_p->func_cbs_usb, | ||
3574 | CY_AS_REQUEST_RESPONSE_EX, req_p, reply_p, | ||
3575 | cy_as_usb_func_callback); | ||
3576 | |||
3577 | if (ret != CY_AS_ERROR_SUCCESS) | ||
3578 | goto destroy; | ||
3579 | return ret; | ||
3580 | } | ||
3581 | |||
3582 | destroy: | ||
3583 | cy_as_ll_destroy_request(dev_p, req_p); | ||
3584 | cy_as_ll_destroy_response(dev_p, reply_p); | ||
3585 | |||
3586 | return ret; | ||
3587 | } | ||
3588 | EXPORT_SYMBOL(cy_as_usb_select_m_s_partitions); | ||
3589 | |||
3590 | static void | ||
3591 | cy_as_usb_func_callback( | ||
3592 | cy_as_device *dev_p, | ||
3593 | uint8_t context, | ||
3594 | cy_as_ll_request_response *rqt, | ||
3595 | cy_as_ll_request_response *resp, | ||
3596 | cy_as_return_status_t stat) | ||
3597 | { | ||
3598 | cy_as_usb_func_c_b_node* node = (cy_as_usb_func_c_b_node *) | ||
3599 | dev_p->usb_func_cbs->head_p; | ||
3600 | cy_as_func_c_b_node* fnode = (cy_as_func_c_b_node *) | ||
3601 | dev_p->func_cbs_usb->head_p; | ||
3602 | cy_as_return_status_t ret = CY_AS_ERROR_SUCCESS; | ||
3603 | |||
3604 | cy_as_device_handle h = (cy_as_device_handle)dev_p; | ||
3605 | cy_bool delayed_ack = (rqt->flags & CY_AS_REQUEST_RESPONSE_DELAY_ACK) | ||
3606 | == CY_AS_REQUEST_RESPONSE_DELAY_ACK; | ||
3607 | cy_bool ex_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_EX) | ||
3608 | == CY_AS_REQUEST_RESPONSE_EX; | ||
3609 | cy_bool ms_request = (rqt->flags & CY_AS_REQUEST_RESPONSE_MS) | ||
3610 | == CY_AS_REQUEST_RESPONSE_MS; | ||
3611 | uint8_t code; | ||
3612 | uint8_t ep, state; | ||
3613 | |||
3614 | if (!ex_request && !ms_request) { | ||
3615 | cy_as_hal_assert(dev_p->usb_func_cbs->count != 0); | ||
3616 | cy_as_hal_assert(dev_p->usb_func_cbs->type == | ||
3617 | CYAS_USB_FUNC_CB); | ||
3618 | } else { | ||
3619 | cy_as_hal_assert(dev_p->func_cbs_usb->count != 0); | ||
3620 | cy_as_hal_assert(dev_p->func_cbs_usb->type == CYAS_FUNC_CB); | ||
3621 | } | ||
3622 | |||
3623 | (void)context; | ||
3624 | |||
3625 | /* The Handlers are responsible for Deleting the rqt and resp when | ||
3626 | * they are finished | ||
3627 | */ | ||
3628 | code = cy_as_ll_request_response__get_code(rqt); | ||
3629 | switch (code) { | ||
3630 | case CY_RQT_START_USB: | ||
3631 | ret = my_handle_response_usb_start(dev_p, rqt, resp, stat); | ||
3632 | break; | ||
3633 | case CY_RQT_STOP_USB: | ||
3634 | ret = my_handle_response_usb_stop(dev_p, rqt, resp, stat); | ||
3635 | break; | ||
3636 | case CY_RQT_SET_CONNECT_STATE: | ||
3637 | if (!cy_as_ll_request_response__get_word(rqt, 0)) | ||
3638 | ret = my_handle_response_disconnect( | ||
3639 | dev_p, rqt, resp, stat); | ||
3640 | else | ||
3641 | ret = my_handle_response_connect( | ||
3642 | dev_p, rqt, resp, stat); | ||
3643 | break; | ||
3644 | case CY_RQT_GET_CONNECT_STATE: | ||
3645 | break; | ||
3646 | case CY_RQT_SET_USB_CONFIG: | ||
3647 | ret = my_handle_response_set_enum_config(dev_p, rqt, resp); | ||
3648 | break; | ||
3649 | case CY_RQT_GET_USB_CONFIG: | ||
3650 | cy_as_hal_assert(fnode->data != 0); | ||
3651 | ret = my_handle_response_get_enum_config(dev_p, | ||
3652 | rqt, resp, fnode->data); | ||
3653 | break; | ||
3654 | case CY_RQT_STALL_ENDPOINT: | ||
3655 | ep = (uint8_t)cy_as_ll_request_response__get_word(rqt, 0); | ||
3656 | state = (uint8_t)cy_as_ll_request_response__get_word(rqt, 1); | ||
3657 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3658 | if ((ret == CY_AS_ERROR_SUCCESS) && (ep > 1) && (state != 0) | ||
3659 | && (dev_p->usb_config[ep].dir == cy_as_usb_out)) | ||
3660 | cy_as_usb_flush_logical_e_p(dev_p, ep); | ||
3661 | break; | ||
3662 | case CY_RQT_GET_STALL: | ||
3663 | cy_as_hal_assert(fnode->data != 0); | ||
3664 | ret = my_handle_response_get_stall(dev_p, | ||
3665 | rqt, resp, (cy_bool *)fnode->data); | ||
3666 | break; | ||
3667 | case CY_RQT_SET_DESCRIPTOR: | ||
3668 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3669 | break; | ||
3670 | case CY_RQT_GET_DESCRIPTOR: | ||
3671 | cy_as_hal_assert(fnode->data != 0); | ||
3672 | ret = my_handle_response_get_descriptor(dev_p, | ||
3673 | rqt, resp, (cy_as_get_descriptor_data *)fnode->data); | ||
3674 | break; | ||
3675 | case CY_RQT_SET_USB_CONFIG_REGISTERS: | ||
3676 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3677 | if (ret == CY_AS_ERROR_SUCCESS) | ||
3678 | ret = cy_as_usb_setup_dma(dev_p); | ||
3679 | break; | ||
3680 | case CY_RQT_ENDPOINT_SET_NAK: | ||
3681 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3682 | break; | ||
3683 | case CY_RQT_GET_ENDPOINT_NAK: | ||
3684 | cy_as_hal_assert(fnode->data != 0); | ||
3685 | ret = my_handle_response_get_nak(dev_p, | ||
3686 | rqt, resp, (cy_bool *)fnode->data); | ||
3687 | break; | ||
3688 | case CY_RQT_ACK_SETUP_PACKET: | ||
3689 | break; | ||
3690 | case CY_RQT_USB_REMOTE_WAKEUP: | ||
3691 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3692 | break; | ||
3693 | case CY_RQT_CLEAR_DESCRIPTORS: | ||
3694 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3695 | break; | ||
3696 | case CY_RQT_USB_STORAGE_MONITOR: | ||
3697 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3698 | break; | ||
3699 | case CY_RQT_MS_PARTITION_SELECT: | ||
3700 | ret = my_handle_response_no_data(dev_p, rqt, resp); | ||
3701 | break; | ||
3702 | default: | ||
3703 | ret = CY_AS_ERROR_INVALID_RESPONSE; | ||
3704 | cy_as_hal_assert(cy_false); | ||
3705 | break; | ||
3706 | } | ||
3707 | |||
3708 | /* | ||
3709 | * if the low level layer returns a direct error, use | ||
3710 | * the corresponding error code. if not, use the error | ||
3711 | * code based on the response from firmware. | ||
3712 | */ | ||
3713 | if (stat == CY_AS_ERROR_SUCCESS) | ||
3714 | stat = ret; | ||
3715 | |||
3716 | if (ex_request || ms_request) { | ||
3717 | fnode->cb_p((cy_as_device_handle)dev_p, stat, | ||
3718 | fnode->client_data, fnode->data_type, fnode->data); | ||
3719 | cy_as_remove_c_b_node(dev_p->func_cbs_usb); | ||
3720 | } else { | ||
3721 | node->cb_p((cy_as_device_handle)dev_p, stat, | ||
3722 | node->client_data); | ||
3723 | cy_as_remove_c_b_node(dev_p->usb_func_cbs); | ||
3724 | } | ||
3725 | |||
3726 | if (delayed_ack) { | ||
3727 | cy_as_hal_assert(cy_as_device_is_ack_delayed(dev_p)); | ||
3728 | cy_as_device_rem_ack_delayed(dev_p); | ||
3729 | |||
3730 | /* | ||
3731 | * send the ACK if required. | ||
3732 | */ | ||
3733 | if (!cy_as_device_is_ack_delayed(dev_p)) | ||
3734 | cy_as_usb_ack_setup_packet(h, | ||
3735 | usb_ack_callback, 0); | ||
3736 | } | ||
3737 | } | ||
3738 | |||
3739 | |||
3740 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c b/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c deleted file mode 100644 index dd4cd412aeb5..000000000000 --- a/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c +++ /dev/null | |||
@@ -1,2441 +0,0 @@ | |||
1 | /* Cypress WestBridge OMAP3430 Kernel Hal source file (cyashalomap_kernel.c) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
23 | |||
24 | #include <linux/fs.h> | ||
25 | #include <linux/ioport.h> | ||
26 | #include <linux/timer.h> | ||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/scatterlist.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/irq.h> | ||
33 | #include <linux/slab.h> | ||
34 | #include <linux/sched.h> | ||
35 | /* include seems broken moving for patch submission | ||
36 | * #include <mach/mux.h> | ||
37 | * #include <mach/gpmc.h> | ||
38 | * #include <mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h> | ||
39 | * #include <mach/westbridge/westbridge-omap3-pnand-hal/cyasomapdev_kernel.h> | ||
40 | * #include <mach/westbridge/westbridge-omap3-pnand-hal/cyasmemmap.h> | ||
41 | * #include <linux/westbridge/cyaserr.h> | ||
42 | * #include <linux/westbridge/cyasregs.h> | ||
43 | * #include <linux/westbridge/cyasdma.h> | ||
44 | * #include <linux/westbridge/cyasintr.h> | ||
45 | */ | ||
46 | #include <linux/../../arch/arm/plat-omap/include/plat/mux.h> | ||
47 | #include <linux/../../arch/arm/plat-omap/include/plat/gpmc.h> | ||
48 | #include "../plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h" | ||
49 | #include "../plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasomapdev_kernel.h" | ||
50 | #include "../plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasmemmap.h" | ||
51 | #include "../../../include/linux/westbridge/cyaserr.h" | ||
52 | #include "../../../include/linux/westbridge/cyasregs.h" | ||
53 | #include "../../../include/linux/westbridge/cyasdma.h" | ||
54 | #include "../../../include/linux/westbridge/cyasintr.h" | ||
55 | |||
56 | #define HAL_REV "1.1.0" | ||
57 | |||
58 | /* | ||
59 | * uncomment to enable 16bit pnand interface | ||
60 | */ | ||
61 | #define PNAND_16BIT_MODE | ||
62 | |||
63 | /* | ||
64 | * selects one of 3 versions of pnand_lbd_read() | ||
65 | * PNAND_LBD_READ_NO_PFE - original 8/16 bit code | ||
66 | * reads through the gpmc CONTROLLER REGISTERS | ||
67 | * ENABLE_GPMC_PF_ENGINE - USES GPMC PFE FIFO reads, in 8 bit mode, | ||
68 | * same speed as the above | ||
69 | * PFE_LBD_READ_V2 - slightly diffrenet, performance same as above | ||
70 | */ | ||
71 | #define PNAND_LBD_READ_NO_PFE | ||
72 | /* #define ENABLE_GPMC_PF_ENGINE */ | ||
73 | /* #define PFE_LBD_READ_V2 */ | ||
74 | |||
75 | /* | ||
76 | * westbrige astoria ISR options to limit number of | ||
77 | * back to back DMA transfers per ISR interrupt | ||
78 | */ | ||
79 | #define MAX_DRQ_LOOPS_IN_ISR 4 | ||
80 | |||
81 | /* | ||
82 | * debug prints enabling | ||
83 | *#define DBGPRN_ENABLED | ||
84 | *#define DBGPRN_DMA_SETUP_RD | ||
85 | *#define DBGPRN_DMA_SETUP_WR | ||
86 | */ | ||
87 | |||
88 | |||
89 | /* | ||
90 | * For performance reasons, we handle storage endpoint transfers up to 4 KB | ||
91 | * within the HAL itself. | ||
92 | */ | ||
93 | #define CYASSTORAGE_WRITE_EP_NUM (4) | ||
94 | #define CYASSTORAGE_READ_EP_NUM (8) | ||
95 | |||
96 | /* | ||
97 | * size of DMA packet HAL can accept from Storage API | ||
98 | * HAL will fragment it into smaller chunks that the P port can accept | ||
99 | */ | ||
100 | #define CYASSTORAGE_MAX_XFER_SIZE (2*32768) | ||
101 | |||
102 | /* | ||
103 | * P port MAX DMA packet size according to interface/ep configurartion | ||
104 | */ | ||
105 | #define HAL_DMA_PKT_SZ 512 | ||
106 | |||
107 | #define is_storage_e_p(ep) (((ep) == 2) || ((ep) == 4) || \ | ||
108 | ((ep) == 6) || ((ep) == 8)) | ||
109 | |||
110 | /* | ||
111 | * persistent, stores current GPMC interface cfg mode | ||
112 | */ | ||
113 | static uint8_t pnand_16bit; | ||
114 | |||
115 | /* | ||
116 | * keep processing new WB DRQ in ISR until all handled (performance feature) | ||
117 | */ | ||
118 | #define PROCESS_MULTIPLE_DRQ_IN_ISR (1) | ||
119 | |||
120 | |||
121 | /* | ||
122 | * ASTORIA PNAND IF COMMANDS, CASDO - READ, CASDI - WRITE | ||
123 | */ | ||
124 | #define CASDO 0x05 | ||
125 | #define CASDI 0x85 | ||
126 | #define RDPAGE_B1 0x00 | ||
127 | #define RDPAGE_B2 0x30 | ||
128 | #define PGMPAGE_B1 0x80 | ||
129 | #define PGMPAGE_B2 0x10 | ||
130 | |||
131 | /* | ||
132 | * The type of DMA operation, per endpoint | ||
133 | */ | ||
134 | typedef enum cy_as_hal_dma_type { | ||
135 | cy_as_hal_read, | ||
136 | cy_as_hal_write, | ||
137 | cy_as_hal_none | ||
138 | } cy_as_hal_dma_type; | ||
139 | |||
140 | |||
141 | /* | ||
142 | * SG list halpers defined in scaterlist.h | ||
143 | #define sg_is_chain(sg) ((sg)->page_link & 0x01) | ||
144 | #define sg_is_last(sg) ((sg)->page_link & 0x02) | ||
145 | #define sg_chain_ptr(sg) \ | ||
146 | ((struct scatterlist *) ((sg)->page_link & ~0x03)) | ||
147 | */ | ||
148 | typedef struct cy_as_hal_endpoint_dma { | ||
149 | cy_bool buffer_valid; | ||
150 | uint8_t *data_p; | ||
151 | uint32_t size; | ||
152 | /* | ||
153 | * sg_list_enabled - if true use, r/w DMA transfers use sg list, | ||
154 | * FALSE use pointer to a buffer | ||
155 | * sg_p - pointer to the owner's sg list, of there is such | ||
156 | * (like blockdriver) | ||
157 | * dma_xfer_sz - size of the next dma xfer on P port | ||
158 | * seg_xfer_cnt - counts xfered bytes for in current sg_list | ||
159 | * memory segment | ||
160 | * req_xfer_cnt - total number of bytes transferred so far in | ||
161 | * current request | ||
162 | * req_length - total request length | ||
163 | */ | ||
164 | bool sg_list_enabled; | ||
165 | struct scatterlist *sg_p; | ||
166 | uint16_t dma_xfer_sz; | ||
167 | uint32_t seg_xfer_cnt; | ||
168 | uint16_t req_xfer_cnt; | ||
169 | uint16_t req_length; | ||
170 | cy_as_hal_dma_type type; | ||
171 | cy_bool pending; | ||
172 | } cy_as_hal_endpoint_dma; | ||
173 | |||
174 | /* | ||
175 | * The list of OMAP devices (should be one) | ||
176 | */ | ||
177 | static cy_as_omap_dev_kernel *m_omap_list_p; | ||
178 | |||
179 | /* | ||
180 | * The callback to call after DMA operations are complete | ||
181 | */ | ||
182 | static cy_as_hal_dma_complete_callback callback; | ||
183 | |||
184 | /* | ||
185 | * Pending data size for the endpoints | ||
186 | */ | ||
187 | static cy_as_hal_endpoint_dma end_points[16]; | ||
188 | |||
189 | /* | ||
190 | * Forward declaration | ||
191 | */ | ||
192 | static void cy_handle_d_r_q_interrupt(cy_as_omap_dev_kernel *dev_p); | ||
193 | |||
194 | static uint16_t intr_sequence_num; | ||
195 | static uint8_t intr__enable; | ||
196 | spinlock_t int_lock; | ||
197 | |||
198 | static u32 iomux_vma; | ||
199 | static u32 csa_phy; | ||
200 | |||
201 | /* | ||
202 | * gpmc I/O registers VMA | ||
203 | */ | ||
204 | static u32 gpmc_base; | ||
205 | |||
206 | /* | ||
207 | * gpmc data VMA associated with CS4 (ASTORIA CS on GPMC) | ||
208 | */ | ||
209 | static u32 gpmc_data_vma; | ||
210 | static u32 ndata_reg_vma; | ||
211 | static u32 ncmd_reg_vma; | ||
212 | static u32 naddr_reg_vma; | ||
213 | |||
214 | /* | ||
215 | * fwd declarations | ||
216 | */ | ||
217 | static void p_nand_lbd_read(u16 col_addr, u32 row_addr, u16 count, void *buff); | ||
218 | static void p_nand_lbd_write(u16 col_addr, u32 row_addr, u16 count, void *buff); | ||
219 | static inline u16 __attribute__((always_inline)) | ||
220 | ast_p_nand_casdo_read(u8 reg_addr8); | ||
221 | static inline void __attribute__((always_inline)) | ||
222 | ast_p_nand_casdi_write(u8 reg_addr8, u16 data); | ||
223 | |||
224 | /* | ||
225 | * prints given number of omap registers | ||
226 | */ | ||
227 | static void cy_as_hal_print_omap_regs(char *name_prefix, | ||
228 | u8 name_base, u32 virt_base, u16 count) | ||
229 | { | ||
230 | u32 reg_val, reg_addr; | ||
231 | u16 i; | ||
232 | cy_as_hal_print_message(KERN_INFO "\n"); | ||
233 | for (i = 0; i < count; i++) { | ||
234 | |||
235 | reg_addr = virt_base + (i*4); | ||
236 | /* use virtual addresses here*/ | ||
237 | reg_val = __raw_readl(reg_addr); | ||
238 | cy_as_hal_print_message(KERN_INFO "%s_%d[%8.8x]=%8.8x\n", | ||
239 | name_prefix, name_base+i, | ||
240 | reg_addr, reg_val); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /* | ||
245 | * setMUX function for a pad + additional pad flags | ||
246 | */ | ||
247 | static u16 omap_cfg_reg_L(u32 pad_func_index) | ||
248 | { | ||
249 | static u8 sanity_check = 1; | ||
250 | |||
251 | u32 reg_vma; | ||
252 | u16 cur_val, wr_val, rdback_val; | ||
253 | |||
254 | /* | ||
255 | * do sanity check on the omap_mux_pin_cfg[] table | ||
256 | */ | ||
257 | cy_as_hal_print_message(KERN_INFO" OMAP pins user_pad cfg "); | ||
258 | if (sanity_check) { | ||
259 | if ((omap_mux_pin_cfg[END_OF_TABLE].name[0] == 'E') && | ||
260 | (omap_mux_pin_cfg[END_OF_TABLE].name[1] == 'N') && | ||
261 | (omap_mux_pin_cfg[END_OF_TABLE].name[2] == 'D')) { | ||
262 | |||
263 | cy_as_hal_print_message(KERN_INFO | ||
264 | "table is good.\n"); | ||
265 | } else { | ||
266 | cy_as_hal_print_message(KERN_WARNING | ||
267 | "table is bad, fix it"); | ||
268 | } | ||
269 | /* | ||
270 | * do it only once | ||
271 | */ | ||
272 | sanity_check = 0; | ||
273 | } | ||
274 | |||
275 | /* | ||
276 | * get virtual address to the PADCNF_REG | ||
277 | */ | ||
278 | reg_vma = (u32)iomux_vma + omap_mux_pin_cfg[pad_func_index].offset; | ||
279 | |||
280 | /* | ||
281 | * add additional USER PU/PD/EN flags | ||
282 | */ | ||
283 | wr_val = omap_mux_pin_cfg[pad_func_index].mux_val; | ||
284 | cur_val = IORD16(reg_vma); | ||
285 | |||
286 | /* | ||
287 | * PADCFG regs 16 bit long, packed into 32 bit regs, | ||
288 | * can also be accessed as u16 | ||
289 | */ | ||
290 | IOWR16(reg_vma, wr_val); | ||
291 | rdback_val = IORD16(reg_vma); | ||
292 | |||
293 | /* | ||
294 | * in case if the caller wants to save the old value | ||
295 | */ | ||
296 | return wr_val; | ||
297 | } | ||
298 | |||
299 | #define BLKSZ_4K 0x1000 | ||
300 | |||
301 | /* | ||
302 | * switch GPMC DATA bus mode | ||
303 | */ | ||
304 | void cy_as_hal_gpmc_enable_16bit_bus(bool dbus16_enabled) | ||
305 | { | ||
306 | uint32_t tmp32; | ||
307 | |||
308 | /* | ||
309 | * disable gpmc CS4 operation 1st | ||
310 | */ | ||
311 | tmp32 = gpmc_cs_read_reg(AST_GPMC_CS, | ||
312 | GPMC_CS_CONFIG7) & ~GPMC_CONFIG7_CSVALID; | ||
313 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG7, tmp32); | ||
314 | |||
315 | /* | ||
316 | * GPMC NAND data bus can be 8 or 16 bit wide | ||
317 | */ | ||
318 | if (dbus16_enabled) { | ||
319 | DBGPRN("enabling 16 bit bus\n"); | ||
320 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG1, | ||
321 | (GPMC_CONFIG1_DEVICETYPE(2) | | ||
322 | GPMC_CONFIG1_WAIT_PIN_SEL(2) | | ||
323 | GPMC_CONFIG1_DEVICESIZE_16) | ||
324 | ); | ||
325 | } else { | ||
326 | DBGPRN(KERN_INFO "enabling 8 bit bus\n"); | ||
327 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG1, | ||
328 | (GPMC_CONFIG1_DEVICETYPE(2) | | ||
329 | GPMC_CONFIG1_WAIT_PIN_SEL(2)) | ||
330 | ); | ||
331 | } | ||
332 | |||
333 | /* | ||
334 | * re-enable astoria CS operation on GPMC | ||
335 | */ | ||
336 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG7, | ||
337 | (tmp32 | GPMC_CONFIG7_CSVALID)); | ||
338 | |||
339 | /* | ||
340 | *remember the state | ||
341 | */ | ||
342 | pnand_16bit = dbus16_enabled; | ||
343 | } | ||
344 | |||
345 | static int cy_as_hal_gpmc_init(void) | ||
346 | { | ||
347 | u32 tmp32; | ||
348 | int err; | ||
349 | struct gpmc_timings timings; | ||
350 | |||
351 | gpmc_base = (u32)ioremap_nocache(OMAP34XX_GPMC_BASE, BLKSZ_4K); | ||
352 | DBGPRN(KERN_INFO "kernel has gpmc_base=%x , val@ the base=%x", | ||
353 | gpmc_base, __raw_readl(gpmc_base) | ||
354 | ); | ||
355 | |||
356 | /* | ||
357 | * these are globals are full VMAs of the gpmc_base above | ||
358 | */ | ||
359 | ncmd_reg_vma = GPMC_VMA(AST_GPMC_NAND_CMD); | ||
360 | naddr_reg_vma = GPMC_VMA(AST_GPMC_NAND_ADDR); | ||
361 | ndata_reg_vma = GPMC_VMA(AST_GPMC_NAND_DATA); | ||
362 | |||
363 | /* | ||
364 | * request GPMC CS for ASTORIA request | ||
365 | */ | ||
366 | if (gpmc_cs_request(AST_GPMC_CS, SZ_16M, (void *)&csa_phy) < 0) { | ||
367 | cy_as_hal_print_message(KERN_ERR "error failed to request" | ||
368 | "ncs4 for ASTORIA\n"); | ||
369 | return -1; | ||
370 | } else { | ||
371 | DBGPRN(KERN_INFO "got phy_addr:%x for " | ||
372 | "GPMC CS%d GPMC_CFGREG7[CS4]\n", | ||
373 | csa_phy, AST_GPMC_CS); | ||
374 | } | ||
375 | |||
376 | /* | ||
377 | * request VM region for 4K addr space for chip select 4 phy address | ||
378 | * technically we don't need it for NAND devices, but do it anyway | ||
379 | * so that data read/write bus cycle can be triggered by reading | ||
380 | * or writing this mem region | ||
381 | */ | ||
382 | if (!request_mem_region(csa_phy, BLKSZ_4K, "AST_OMAP_HAL")) { | ||
383 | err = -EBUSY; | ||
384 | cy_as_hal_print_message(KERN_ERR "error MEM region " | ||
385 | "request for phy_addr:%x failed\n", | ||
386 | csa_phy); | ||
387 | goto out_free_cs; | ||
388 | } | ||
389 | |||
390 | /* | ||
391 | * REMAP mem region associated with our CS | ||
392 | */ | ||
393 | gpmc_data_vma = (u32)ioremap_nocache(csa_phy, BLKSZ_4K); | ||
394 | if (!gpmc_data_vma) { | ||
395 | err = -ENOMEM; | ||
396 | cy_as_hal_print_message(KERN_ERR "error- ioremap()" | ||
397 | "for phy_addr:%x failed", csa_phy); | ||
398 | |||
399 | goto out_release_mem_region; | ||
400 | } | ||
401 | cy_as_hal_print_message(KERN_INFO "ioremap(%x) returned vma=%x\n", | ||
402 | csa_phy, gpmc_data_vma); | ||
403 | |||
404 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG1, | ||
405 | (GPMC_CONFIG1_DEVICETYPE(2) | | ||
406 | GPMC_CONFIG1_WAIT_PIN_SEL(2))); | ||
407 | |||
408 | memset(&timings, 0, sizeof(timings)); | ||
409 | |||
410 | /* cs timing */ | ||
411 | timings.cs_on = WB_GPMC_CS_t_o_n; | ||
412 | timings.cs_wr_off = WB_GPMC_BUSCYC_t; | ||
413 | timings.cs_rd_off = WB_GPMC_BUSCYC_t; | ||
414 | |||
415 | /* adv timing */ | ||
416 | timings.adv_on = WB_GPMC_ADV_t_o_n; | ||
417 | timings.adv_rd_off = WB_GPMC_BUSCYC_t; | ||
418 | timings.adv_wr_off = WB_GPMC_BUSCYC_t; | ||
419 | |||
420 | /* oe timing */ | ||
421 | timings.oe_on = WB_GPMC_OE_t_o_n; | ||
422 | timings.oe_off = WB_GPMC_OE_t_o_f_f; | ||
423 | timings.access = WB_GPMC_RD_t_a_c_c; | ||
424 | timings.rd_cycle = WB_GPMC_BUSCYC_t; | ||
425 | |||
426 | /* we timing */ | ||
427 | timings.we_on = WB_GPMC_WE_t_o_n; | ||
428 | timings.we_off = WB_GPMC_WE_t_o_f_f; | ||
429 | timings.wr_access = WB_GPMC_WR_t_a_c_c; | ||
430 | timings.wr_cycle = WB_GPMC_BUSCYC_t; | ||
431 | |||
432 | timings.page_burst_access = WB_GPMC_BUSCYC_t; | ||
433 | timings.wr_data_mux_bus = WB_GPMC_BUSCYC_t; | ||
434 | gpmc_cs_set_timings(AST_GPMC_CS, &timings); | ||
435 | |||
436 | cy_as_hal_print_omap_regs("GPMC_CONFIG", 1, | ||
437 | GPMC_VMA(GPMC_CFG_REG(1, AST_GPMC_CS)), 7); | ||
438 | |||
439 | /* | ||
440 | * DISABLE cs4, NOTE GPMC REG7 is already configured | ||
441 | * at this point by gpmc_cs_request | ||
442 | */ | ||
443 | tmp32 = gpmc_cs_read_reg(AST_GPMC_CS, GPMC_CS_CONFIG7) & | ||
444 | ~GPMC_CONFIG7_CSVALID; | ||
445 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG7, tmp32); | ||
446 | |||
447 | /* | ||
448 | * PROGRAM chip select Region, (see OMAP3430 TRM PAGE 1088) | ||
449 | */ | ||
450 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG7, | ||
451 | (AS_CS_MASK | AS_CS_BADDR)); | ||
452 | |||
453 | /* | ||
454 | * by default configure GPMC into 8 bit mode | ||
455 | * (to match astoria default mode) | ||
456 | */ | ||
457 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG1, | ||
458 | (GPMC_CONFIG1_DEVICETYPE(2) | | ||
459 | GPMC_CONFIG1_WAIT_PIN_SEL(2))); | ||
460 | |||
461 | /* | ||
462 | * ENABLE astoria cs operation on GPMC | ||
463 | */ | ||
464 | gpmc_cs_write_reg(AST_GPMC_CS, GPMC_CS_CONFIG7, | ||
465 | (tmp32 | GPMC_CONFIG7_CSVALID)); | ||
466 | |||
467 | /* | ||
468 | * No method currently exists to write this register through GPMC APIs | ||
469 | * need to change WAIT2 polarity | ||
470 | */ | ||
471 | tmp32 = IORD32(GPMC_VMA(GPMC_CONFIG_REG)); | ||
472 | tmp32 = tmp32 | NAND_FORCE_POSTED_WRITE_B | 0x40; | ||
473 | IOWR32(GPMC_VMA(GPMC_CONFIG_REG), tmp32); | ||
474 | |||
475 | tmp32 = IORD32(GPMC_VMA(GPMC_CONFIG_REG)); | ||
476 | cy_as_hal_print_message("GPMC_CONFIG_REG=0x%x\n", tmp32); | ||
477 | |||
478 | return 0; | ||
479 | |||
480 | out_release_mem_region: | ||
481 | release_mem_region(csa_phy, BLKSZ_4K); | ||
482 | |||
483 | out_free_cs: | ||
484 | gpmc_cs_free(AST_GPMC_CS); | ||
485 | |||
486 | return err; | ||
487 | } | ||
488 | |||
489 | /* | ||
490 | * west bridge astoria ISR (Interrupt handler) | ||
491 | */ | ||
492 | static irqreturn_t cy_astoria_int_handler(int irq, | ||
493 | void *dev_id, struct pt_regs *regs) | ||
494 | { | ||
495 | cy_as_omap_dev_kernel *dev_p; | ||
496 | uint16_t read_val = 0; | ||
497 | uint16_t mask_val = 0; | ||
498 | |||
499 | /* | ||
500 | * debug stuff, counts number of loops per one intr trigger | ||
501 | */ | ||
502 | uint16_t drq_loop_cnt = 0; | ||
503 | uint8_t irq_pin; | ||
504 | /* | ||
505 | * flags to watch | ||
506 | */ | ||
507 | const uint16_t sentinel = (CY_AS_MEM_P0_INTR_REG_MCUINT | | ||
508 | CY_AS_MEM_P0_INTR_REG_MBINT | | ||
509 | CY_AS_MEM_P0_INTR_REG_PMINT | | ||
510 | CY_AS_MEM_P0_INTR_REG_PLLLOCKINT); | ||
511 | |||
512 | /* | ||
513 | * sample IRQ pin level (just for statistics) | ||
514 | */ | ||
515 | irq_pin = __gpio_get_value(AST_INT); | ||
516 | |||
517 | /* | ||
518 | * this one just for debugging | ||
519 | */ | ||
520 | intr_sequence_num++; | ||
521 | |||
522 | /* | ||
523 | * astoria device handle | ||
524 | */ | ||
525 | dev_p = dev_id; | ||
526 | |||
527 | /* | ||
528 | * read Astoria intr register | ||
529 | */ | ||
530 | read_val = cy_as_hal_read_register((cy_as_hal_device_tag)dev_p, | ||
531 | CY_AS_MEM_P0_INTR_REG); | ||
532 | |||
533 | /* | ||
534 | * save current mask value | ||
535 | */ | ||
536 | mask_val = cy_as_hal_read_register((cy_as_hal_device_tag)dev_p, | ||
537 | CY_AS_MEM_P0_INT_MASK_REG); | ||
538 | |||
539 | DBGPRN("<1>HAL__intr__enter:_seq:%d, P0_INTR_REG:%x\n", | ||
540 | intr_sequence_num, read_val); | ||
541 | |||
542 | /* | ||
543 | * Disable WB interrupt signal generation while we are in ISR | ||
544 | */ | ||
545 | cy_as_hal_write_register((cy_as_hal_device_tag)dev_p, | ||
546 | CY_AS_MEM_P0_INT_MASK_REG, 0x0000); | ||
547 | |||
548 | /* | ||
549 | * this is a DRQ Interrupt | ||
550 | */ | ||
551 | if (read_val & CY_AS_MEM_P0_INTR_REG_DRQINT) { | ||
552 | |||
553 | do { | ||
554 | /* | ||
555 | * handle DRQ interrupt | ||
556 | */ | ||
557 | drq_loop_cnt++; | ||
558 | |||
559 | cy_handle_d_r_q_interrupt(dev_p); | ||
560 | |||
561 | /* | ||
562 | * spending to much time in ISR may impact | ||
563 | * average system performance | ||
564 | */ | ||
565 | if (drq_loop_cnt >= MAX_DRQ_LOOPS_IN_ISR) | ||
566 | break; | ||
567 | |||
568 | /* | ||
569 | * Keep processing if there is another DRQ int flag | ||
570 | */ | ||
571 | } while (cy_as_hal_read_register((cy_as_hal_device_tag)dev_p, | ||
572 | CY_AS_MEM_P0_INTR_REG) & | ||
573 | CY_AS_MEM_P0_INTR_REG_DRQINT); | ||
574 | } | ||
575 | |||
576 | if (read_val & sentinel) | ||
577 | cy_as_intr_service_interrupt((cy_as_hal_device_tag)dev_p); | ||
578 | |||
579 | DBGPRN("<1>_hal:_intr__exit seq:%d, mask=%4.4x," | ||
580 | "int_pin:%d DRQ_jobs:%d\n", | ||
581 | intr_sequence_num, | ||
582 | mask_val, | ||
583 | irq_pin, | ||
584 | drq_loop_cnt); | ||
585 | |||
586 | /* | ||
587 | * re-enable WB hw interrupts | ||
588 | */ | ||
589 | cy_as_hal_write_register((cy_as_hal_device_tag)dev_p, | ||
590 | CY_AS_MEM_P0_INT_MASK_REG, mask_val); | ||
591 | |||
592 | return IRQ_HANDLED; | ||
593 | } | ||
594 | |||
595 | static int cy_as_hal_configure_interrupts(void *dev_p) | ||
596 | { | ||
597 | int result; | ||
598 | int irq_pin = AST_INT; | ||
599 | |||
600 | irq_set_irq_type(OMAP_GPIO_IRQ(irq_pin), IRQ_TYPE_LEVEL_LOW); | ||
601 | |||
602 | /* | ||
603 | * for shared IRQS must provide non NULL device ptr | ||
604 | * othervise the int won't register | ||
605 | * */ | ||
606 | result = request_irq(OMAP_GPIO_IRQ(irq_pin), | ||
607 | (irq_handler_t)cy_astoria_int_handler, | ||
608 | IRQF_SHARED, "AST_INT#", dev_p); | ||
609 | |||
610 | if (result == 0) { | ||
611 | /* | ||
612 | * OMAP_GPIO_IRQ(irq_pin) - omap logical IRQ number | ||
613 | * assigned to this interrupt | ||
614 | * OMAP_GPIO_BIT(AST_INT, GPIO_IRQENABLE1) - print status | ||
615 | * of AST_INT GPIO IRQ_ENABLE FLAG | ||
616 | */ | ||
617 | cy_as_hal_print_message(KERN_INFO"AST_INT omap_pin:" | ||
618 | "%d assigned IRQ #%d IRQEN1=%d\n", | ||
619 | irq_pin, | ||
620 | OMAP_GPIO_IRQ(irq_pin), | ||
621 | OMAP_GPIO_BIT(AST_INT, GPIO_IRQENABLE1) | ||
622 | ); | ||
623 | } else { | ||
624 | cy_as_hal_print_message("cyasomaphal: interrupt " | ||
625 | "failed to register\n"); | ||
626 | gpio_free(irq_pin); | ||
627 | cy_as_hal_print_message(KERN_WARNING | ||
628 | "ASTORIA: can't get assigned IRQ" | ||
629 | "%i for INT#\n", OMAP_GPIO_IRQ(irq_pin)); | ||
630 | } | ||
631 | |||
632 | return result; | ||
633 | } | ||
634 | |||
635 | /* | ||
636 | * initialize OMAP pads/pins to user defined functions | ||
637 | */ | ||
638 | static void cy_as_hal_init_user_pads(user_pad_cfg_t *pad_cfg_tab) | ||
639 | { | ||
640 | /* | ||
641 | * browse through the table an dinitiaze the pins | ||
642 | */ | ||
643 | u32 in_level = 0; | ||
644 | u16 tmp16, mux_val; | ||
645 | |||
646 | while (pad_cfg_tab->name != NULL) { | ||
647 | |||
648 | if (gpio_request(pad_cfg_tab->pin_num, NULL) == 0) { | ||
649 | |||
650 | pad_cfg_tab->valid = 1; | ||
651 | mux_val = omap_cfg_reg_L(pad_cfg_tab->mux_func); | ||
652 | |||
653 | /* | ||
654 | * always set drv level before changing out direction | ||
655 | */ | ||
656 | __gpio_set_value(pad_cfg_tab->pin_num, | ||
657 | pad_cfg_tab->drv); | ||
658 | |||
659 | /* | ||
660 | * "0" - OUT, "1", input omap_set_gpio_direction | ||
661 | * (pad_cfg_tab->pin_num, pad_cfg_tab->dir); | ||
662 | */ | ||
663 | if (pad_cfg_tab->dir) | ||
664 | gpio_direction_input(pad_cfg_tab->pin_num); | ||
665 | else | ||
666 | gpio_direction_output(pad_cfg_tab->pin_num, | ||
667 | pad_cfg_tab->drv); | ||
668 | |||
669 | /* sample the pin */ | ||
670 | in_level = __gpio_get_value(pad_cfg_tab->pin_num); | ||
671 | |||
672 | cy_as_hal_print_message(KERN_INFO "configured %s to " | ||
673 | "OMAP pad_%d, DIR=%d " | ||
674 | "DOUT=%d, DIN=%d\n", | ||
675 | pad_cfg_tab->name, | ||
676 | pad_cfg_tab->pin_num, | ||
677 | pad_cfg_tab->dir, | ||
678 | pad_cfg_tab->drv, | ||
679 | in_level | ||
680 | ); | ||
681 | } else { | ||
682 | /* | ||
683 | * get the pad_mux value to check on the pin_function | ||
684 | */ | ||
685 | cy_as_hal_print_message(KERN_INFO "couldn't cfg pin %d" | ||
686 | "for signal %s, its already taken\n", | ||
687 | pad_cfg_tab->pin_num, | ||
688 | pad_cfg_tab->name); | ||
689 | } | ||
690 | |||
691 | tmp16 = *(u16 *)PADCFG_VMA | ||
692 | (omap_mux_pin_cfg[pad_cfg_tab->mux_func].offset); | ||
693 | |||
694 | cy_as_hal_print_message(KERN_INFO "GPIO_%d(PAD_CFG=%x,OE=%d" | ||
695 | "DOUT=%d, DIN=%d IRQEN=%d)\n\n", | ||
696 | pad_cfg_tab->pin_num, tmp16, | ||
697 | OMAP_GPIO_BIT(pad_cfg_tab->pin_num, GPIO_OE), | ||
698 | OMAP_GPIO_BIT(pad_cfg_tab->pin_num, GPIO_DATA_OUT), | ||
699 | OMAP_GPIO_BIT(pad_cfg_tab->pin_num, GPIO_DATA_IN), | ||
700 | OMAP_GPIO_BIT(pad_cfg_tab->pin_num, GPIO_IRQENABLE1) | ||
701 | ); | ||
702 | |||
703 | /* | ||
704 | * next pad_cfg deriptor | ||
705 | */ | ||
706 | pad_cfg_tab++; | ||
707 | } | ||
708 | |||
709 | cy_as_hal_print_message(KERN_INFO"pads configured\n"); | ||
710 | } | ||
711 | |||
712 | |||
713 | /* | ||
714 | * release gpios taken by the module | ||
715 | */ | ||
716 | static void cy_as_hal_release_user_pads(user_pad_cfg_t *pad_cfg_tab) | ||
717 | { | ||
718 | while (pad_cfg_tab->name != NULL) { | ||
719 | |||
720 | if (pad_cfg_tab->valid) { | ||
721 | gpio_free(pad_cfg_tab->pin_num); | ||
722 | pad_cfg_tab->valid = 0; | ||
723 | cy_as_hal_print_message(KERN_INFO "GPIO_%d " | ||
724 | "released from %s\n", | ||
725 | pad_cfg_tab->pin_num, | ||
726 | pad_cfg_tab->name); | ||
727 | } else { | ||
728 | cy_as_hal_print_message(KERN_INFO "no release " | ||
729 | "for %s, GPIO_%d, wasn't acquired\n", | ||
730 | pad_cfg_tab->name, | ||
731 | pad_cfg_tab->pin_num); | ||
732 | } | ||
733 | pad_cfg_tab++; | ||
734 | } | ||
735 | } | ||
736 | |||
737 | void cy_as_hal_config_c_s_mux(void) | ||
738 | { | ||
739 | /* | ||
740 | * FORCE the GPMC CS4 pin (it is in use by the zoom system) | ||
741 | */ | ||
742 | omap_cfg_reg_L(T8_OMAP3430_GPMC_n_c_s4); | ||
743 | } | ||
744 | EXPORT_SYMBOL(cy_as_hal_config_c_s_mux); | ||
745 | |||
746 | /* | ||
747 | * inits all omap h/w | ||
748 | */ | ||
749 | uint32_t cy_as_hal_processor_hw_init(void) | ||
750 | { | ||
751 | int i, err; | ||
752 | |||
753 | cy_as_hal_print_message(KERN_INFO "init OMAP3430 hw...\n"); | ||
754 | |||
755 | iomux_vma = (u32)ioremap_nocache( | ||
756 | (u32)CTLPADCONF_BASE_ADDR, CTLPADCONF_SIZE); | ||
757 | cy_as_hal_print_message(KERN_INFO "PADCONF_VMA=%x val=%x\n", | ||
758 | iomux_vma, IORD32(iomux_vma)); | ||
759 | |||
760 | /* | ||
761 | * remap gpio banks | ||
762 | */ | ||
763 | for (i = 0; i < 6; i++) { | ||
764 | gpio_vma_tab[i].virt_addr = (u32)ioremap_nocache( | ||
765 | gpio_vma_tab[i].phy_addr, | ||
766 | gpio_vma_tab[i].size); | ||
767 | |||
768 | cy_as_hal_print_message(KERN_INFO "%s virt_addr=%x\n", | ||
769 | gpio_vma_tab[i].name, | ||
770 | (u32)gpio_vma_tab[i].virt_addr); | ||
771 | } | ||
772 | |||
773 | /* | ||
774 | * force OMAP_GPIO_126 to rleased state, | ||
775 | * will be configured to drive reset | ||
776 | */ | ||
777 | gpio_free(AST_RESET); | ||
778 | |||
779 | /* | ||
780 | *same thing with AStoria CS pin | ||
781 | */ | ||
782 | gpio_free(AST_CS); | ||
783 | |||
784 | /* | ||
785 | * initialize all the OMAP pads connected to astoria | ||
786 | */ | ||
787 | cy_as_hal_init_user_pads(user_pad_cfg); | ||
788 | |||
789 | err = cy_as_hal_gpmc_init(); | ||
790 | if (err < 0) | ||
791 | cy_as_hal_print_message(KERN_INFO"gpmc init failed:%d", err); | ||
792 | |||
793 | cy_as_hal_config_c_s_mux(); | ||
794 | |||
795 | return gpmc_data_vma; | ||
796 | } | ||
797 | EXPORT_SYMBOL(cy_as_hal_processor_hw_init); | ||
798 | |||
799 | void cy_as_hal_omap_hardware_deinit(cy_as_omap_dev_kernel *dev_p) | ||
800 | { | ||
801 | /* | ||
802 | * free omap hw resources | ||
803 | */ | ||
804 | if (gpmc_data_vma != 0) | ||
805 | iounmap((void *)gpmc_data_vma); | ||
806 | |||
807 | if (csa_phy != 0) | ||
808 | release_mem_region(csa_phy, BLKSZ_4K); | ||
809 | |||
810 | gpmc_cs_free(AST_GPMC_CS); | ||
811 | |||
812 | free_irq(OMAP_GPIO_IRQ(AST_INT), dev_p); | ||
813 | |||
814 | cy_as_hal_release_user_pads(user_pad_cfg); | ||
815 | } | ||
816 | |||
817 | /* | ||
818 | * These are the functions that are not part of the | ||
819 | * HAL layer, but are required to be called for this HAL | ||
820 | */ | ||
821 | |||
822 | /* | ||
823 | * Called On AstDevice LKM exit | ||
824 | */ | ||
825 | int stop_o_m_a_p_kernel(const char *pgm, cy_as_hal_device_tag tag) | ||
826 | { | ||
827 | cy_as_omap_dev_kernel *dev_p = (cy_as_omap_dev_kernel *)tag; | ||
828 | |||
829 | /* | ||
830 | * TODO: Need to disable WB interrupt handlere 1st | ||
831 | */ | ||
832 | if (0 == dev_p) | ||
833 | return 1; | ||
834 | |||
835 | cy_as_hal_print_message("<1>_stopping OMAP34xx HAL layer object\n"); | ||
836 | if (dev_p->m_sig != CY_AS_OMAP_KERNEL_HAL_SIG) { | ||
837 | cy_as_hal_print_message("<1>%s: %s: bad HAL tag\n", | ||
838 | pgm, __func__); | ||
839 | return 1; | ||
840 | } | ||
841 | |||
842 | /* | ||
843 | * disable interrupt | ||
844 | */ | ||
845 | cy_as_hal_write_register((cy_as_hal_device_tag)dev_p, | ||
846 | CY_AS_MEM_P0_INT_MASK_REG, 0x0000); | ||
847 | |||
848 | #if 0 | ||
849 | if (dev_p->thread_flag == 0) { | ||
850 | dev_p->thread_flag = 1; | ||
851 | wait_for_completion(&dev_p->thread_complete); | ||
852 | cy_as_hal_print_message("cyasomaphal:" | ||
853 | "done cleaning thread\n"); | ||
854 | cy_as_hal_destroy_sleep_channel(&dev_p->thread_sc); | ||
855 | } | ||
856 | #endif | ||
857 | |||
858 | cy_as_hal_omap_hardware_deinit(dev_p); | ||
859 | |||
860 | /* | ||
861 | * Rearrange the list | ||
862 | */ | ||
863 | if (m_omap_list_p == dev_p) | ||
864 | m_omap_list_p = dev_p->m_next_p; | ||
865 | |||
866 | cy_as_hal_free(dev_p); | ||
867 | |||
868 | cy_as_hal_print_message(KERN_INFO"OMAP_kernel_hal stopped\n"); | ||
869 | return 0; | ||
870 | } | ||
871 | |||
872 | int omap_start_intr(cy_as_hal_device_tag tag) | ||
873 | { | ||
874 | cy_as_omap_dev_kernel *dev_p = (cy_as_omap_dev_kernel *)tag; | ||
875 | int ret = 0; | ||
876 | const uint16_t mask = CY_AS_MEM_P0_INTR_REG_DRQINT | | ||
877 | CY_AS_MEM_P0_INTR_REG_MBINT; | ||
878 | |||
879 | /* | ||
880 | * register for interrupts | ||
881 | */ | ||
882 | ret = cy_as_hal_configure_interrupts(dev_p); | ||
883 | |||
884 | /* | ||
885 | * enable only MBox & DRQ interrupts for now | ||
886 | */ | ||
887 | cy_as_hal_write_register((cy_as_hal_device_tag)dev_p, | ||
888 | CY_AS_MEM_P0_INT_MASK_REG, mask); | ||
889 | |||
890 | return 1; | ||
891 | } | ||
892 | |||
893 | /* | ||
894 | * Below are the functions that communicate with the WestBridge device. | ||
895 | * These are system dependent and must be defined by the HAL layer | ||
896 | * for a given system. | ||
897 | */ | ||
898 | |||
899 | /* | ||
900 | * GPMC NAND command+addr write phase | ||
901 | */ | ||
902 | static inline void nand_cmd_n_addr(u8 cmdb1, u16 col_addr, u32 row_addr) | ||
903 | { | ||
904 | /* | ||
905 | * byte order on the bus <cmd> <CA0,CA1,RA0,RA1, RA2> | ||
906 | */ | ||
907 | u32 tmpa32 = ((row_addr << 16) | col_addr); | ||
908 | u8 RA2 = (u8)(row_addr >> 16); | ||
909 | |||
910 | if (!pnand_16bit) { | ||
911 | /* | ||
912 | * GPMC PNAND 8bit BUS | ||
913 | */ | ||
914 | /* | ||
915 | * CMD1 | ||
916 | */ | ||
917 | IOWR8(ncmd_reg_vma, cmdb1); | ||
918 | |||
919 | /* | ||
920 | *pnand bus: <CA0,CA1,RA0,RA1> | ||
921 | */ | ||
922 | IOWR32(naddr_reg_vma, tmpa32); | ||
923 | |||
924 | /* | ||
925 | * <RA2> , always zero | ||
926 | */ | ||
927 | IOWR8(naddr_reg_vma, RA2); | ||
928 | |||
929 | } else { | ||
930 | /* | ||
931 | * GPMC PNAND 16bit BUS , in 16 bit mode CMD | ||
932 | * and ADDR sent on [d7..d0] | ||
933 | */ | ||
934 | uint8_t CA0, CA1, RA0, RA1; | ||
935 | CA0 = tmpa32 & 0x000000ff; | ||
936 | CA1 = (tmpa32 >> 8) & 0x000000ff; | ||
937 | RA0 = (tmpa32 >> 16) & 0x000000ff; | ||
938 | RA1 = (tmpa32 >> 24) & 0x000000ff; | ||
939 | |||
940 | /* | ||
941 | * can't use 32 bit writes here omap will not serialize | ||
942 | * them to lower half in16 bit mode | ||
943 | */ | ||
944 | |||
945 | /* | ||
946 | *pnand bus: <CMD1, CA0,CA1,RA0,RA1, RA2 (always zero)> | ||
947 | */ | ||
948 | IOWR8(ncmd_reg_vma, cmdb1); | ||
949 | IOWR8(naddr_reg_vma, CA0); | ||
950 | IOWR8(naddr_reg_vma, CA1); | ||
951 | IOWR8(naddr_reg_vma, RA0); | ||
952 | IOWR8(naddr_reg_vma, RA1); | ||
953 | IOWR8(naddr_reg_vma, RA2); | ||
954 | } | ||
955 | } | ||
956 | |||
957 | /* | ||
958 | * spin until r/b goes high | ||
959 | */ | ||
960 | inline int wait_rn_b_high(void) | ||
961 | { | ||
962 | u32 w_spins = 0; | ||
963 | |||
964 | /* | ||
965 | * TODO: note R/b may go low here, need to spin until high | ||
966 | * while (omap_get_gpio_datain(AST_RnB) == 0) { | ||
967 | * w_spins++; | ||
968 | * } | ||
969 | * if (OMAP_GPIO_BIT(AST_RnB, GPIO_DATA_IN) == 0) { | ||
970 | * | ||
971 | * while (OMAP_GPIO_BIT(AST_RnB, GPIO_DATA_IN) == 0) { | ||
972 | * w_spins++; | ||
973 | * } | ||
974 | * printk("<1>RnB=0!:%d\n",w_spins); | ||
975 | * } | ||
976 | */ | ||
977 | return w_spins; | ||
978 | } | ||
979 | |||
980 | #ifdef ENABLE_GPMC_PF_ENGINE | ||
981 | /* #define PFE_READ_DEBUG | ||
982 | * PNAND block read with OMAP PFE enabled | ||
983 | * status: Not tested, NW, broken , etc | ||
984 | */ | ||
985 | static void p_nand_lbd_read(u16 col_addr, u32 row_addr, u16 count, void *buff) | ||
986 | { | ||
987 | uint16_t w32cnt; | ||
988 | uint32_t *ptr32; | ||
989 | uint8_t *ptr8; | ||
990 | uint8_t bytes_in_fifo; | ||
991 | |||
992 | /* debug vars*/ | ||
993 | #ifdef PFE_READ_DEBUG | ||
994 | uint32_t loop_limit; | ||
995 | uint16_t bytes_read = 0; | ||
996 | #endif | ||
997 | |||
998 | /* | ||
999 | * configure the prefetch engine | ||
1000 | */ | ||
1001 | uint32_t tmp32; | ||
1002 | uint32_t pfe_status; | ||
1003 | |||
1004 | /* | ||
1005 | * DISABLE GPMC CS4 operation 1st, this is | ||
1006 | * in case engine is be already disabled | ||
1007 | */ | ||
1008 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONTROL), 0x0); | ||
1009 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONFIG1), GPMC_PREFETCH_CONFIG1_VAL); | ||
1010 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONFIG2), count); | ||
1011 | |||
1012 | #ifdef PFE_READ_DEBUG | ||
1013 | tmp32 = IORD32(GPMC_VMA(GPMC_PREFETCH_CONFIG1)); | ||
1014 | if (tmp32 != GPMC_PREFETCH_CONFIG1_VAL) { | ||
1015 | printk(KERN_INFO "<1> prefetch is CONFIG1 read val:%8.8x, != VAL written:%8.8x\n", | ||
1016 | tmp32, GPMC_PREFETCH_CONFIG1_VAL); | ||
1017 | tmp32 = IORD32(GPMC_VMA(GPMC_PREFETCH_STATUS)); | ||
1018 | printk(KERN_INFO "<1> GPMC_PREFETCH_STATUS : %8.8x\n", tmp32); | ||
1019 | } | ||
1020 | |||
1021 | /* | ||
1022 | *sanity check 2 | ||
1023 | */ | ||
1024 | tmp32 = IORD32(GPMC_VMA(GPMC_PREFETCH_CONFIG2)); | ||
1025 | if (tmp32 != (count)) | ||
1026 | printk(KERN_INFO "<1> GPMC_PREFETCH_CONFIG2 read val:%d, " | ||
1027 | "!= VAL written:%d\n", tmp32, count); | ||
1028 | #endif | ||
1029 | |||
1030 | /* | ||
1031 | * ISSUE PNAND CMD+ADDR, note gpmc puts 32b words | ||
1032 | * on the bus least sig. byte 1st | ||
1033 | */ | ||
1034 | nand_cmd_n_addr(RDPAGE_B1, col_addr, row_addr); | ||
1035 | |||
1036 | IOWR8(ncmd_reg_vma, RDPAGE_B2); | ||
1037 | |||
1038 | /* | ||
1039 | * start the prefetch engine | ||
1040 | */ | ||
1041 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONTROL), 0x1); | ||
1042 | |||
1043 | ptr32 = buff; | ||
1044 | |||
1045 | while (1) { | ||
1046 | /* | ||
1047 | * GPMC PFE service loop | ||
1048 | */ | ||
1049 | do { | ||
1050 | /* | ||
1051 | * spin until PFE fetched some | ||
1052 | * PNAND bus words in the FIFO | ||
1053 | */ | ||
1054 | pfe_status = IORD32(GPMC_VMA(GPMC_PREFETCH_STATUS)); | ||
1055 | bytes_in_fifo = (pfe_status >> 24) & 0x7f; | ||
1056 | } while (bytes_in_fifo == 0); | ||
1057 | |||
1058 | /* whole 32 bit words in fifo */ | ||
1059 | w32cnt = bytes_in_fifo >> 2; | ||
1060 | |||
1061 | #if 0 | ||
1062 | /* | ||
1063 | *NOTE: FIFO_PTR indicates number of NAND bus words bytes | ||
1064 | * already received in the FIFO and available to be read | ||
1065 | * by DMA or MPU whether COUNTVAL indicates number of BUS | ||
1066 | * words yet to be read from PNAND bus words | ||
1067 | */ | ||
1068 | printk(KERN_ERR "<1> got PF_STATUS:%8.8x FIFO_PTR:%d, COUNTVAL:%d, w32cnt:%d\n", | ||
1069 | pfe_status, bytes_in_fifo, | ||
1070 | (pfe_status & 0x3fff), w32cnt); | ||
1071 | #endif | ||
1072 | |||
1073 | while (w32cnt--) | ||
1074 | *ptr32++ = IORD32(gpmc_data_vma); | ||
1075 | |||
1076 | if ((pfe_status & 0x3fff) == 0) { | ||
1077 | /* | ||
1078 | * PFE acc angine done, there still may be data leftover | ||
1079 | * in the FIFO re-read FIFO BYTE counter (check for | ||
1080 | * leftovers from 32 bit read accesses above) | ||
1081 | */ | ||
1082 | bytes_in_fifo = (IORD32( | ||
1083 | GPMC_VMA(GPMC_PREFETCH_STATUS)) >> 24) & 0x7f; | ||
1084 | |||
1085 | /* | ||
1086 | * NOTE we may still have one word left in the fifo | ||
1087 | * read it out | ||
1088 | */ | ||
1089 | ptr8 = ptr32; | ||
1090 | switch (bytes_in_fifo) { | ||
1091 | |||
1092 | case 0: | ||
1093 | /* | ||
1094 | * nothing to do we already read the | ||
1095 | * FIFO out with 32 bit accesses | ||
1096 | */ | ||
1097 | break; | ||
1098 | case 1: | ||
1099 | /* | ||
1100 | * this only possible | ||
1101 | * for 8 bit pNAND only | ||
1102 | */ | ||
1103 | *ptr8 = IORD8(gpmc_data_vma); | ||
1104 | break; | ||
1105 | |||
1106 | case 2: | ||
1107 | /* | ||
1108 | * this one can occur in either modes | ||
1109 | */ | ||
1110 | *(uint16_t *)ptr8 = IORD16(gpmc_data_vma); | ||
1111 | break; | ||
1112 | |||
1113 | case 3: | ||
1114 | /* | ||
1115 | * this only possible for 8 bit pNAND only | ||
1116 | */ | ||
1117 | *(uint16_t *)ptr8 = IORD16(gpmc_data_vma); | ||
1118 | ptr8 += 2; | ||
1119 | *ptr8 = IORD8(gpmc_data_vma); | ||
1120 | break; | ||
1121 | |||
1122 | case 4: | ||
1123 | /* | ||
1124 | * shouldn't happen, but has been seen | ||
1125 | * in 8 bit mode | ||
1126 | */ | ||
1127 | *ptr32 = IORD32(gpmc_data_vma); | ||
1128 | break; | ||
1129 | |||
1130 | default: | ||
1131 | printk(KERN_ERR"<1>_error: PFE FIFO bytes leftover is not read:%d\n", | ||
1132 | bytes_in_fifo); | ||
1133 | break; | ||
1134 | } | ||
1135 | /* | ||
1136 | * read is completed, get out of the while(1) loop | ||
1137 | */ | ||
1138 | break; | ||
1139 | } | ||
1140 | } | ||
1141 | } | ||
1142 | #endif | ||
1143 | |||
1144 | #ifdef PFE_LBD_READ_V2 | ||
1145 | /* | ||
1146 | * PFE engine assisted reads with the 64 byte blocks | ||
1147 | */ | ||
1148 | static void p_nand_lbd_read(u16 col_addr, u32 row_addr, u16 count, void *buff) | ||
1149 | { | ||
1150 | uint8_t rd_cnt; | ||
1151 | uint32_t *ptr32; | ||
1152 | uint8_t *ptr8; | ||
1153 | uint16_t reminder; | ||
1154 | uint32_t pfe_status; | ||
1155 | |||
1156 | /* | ||
1157 | * ISSUE PNAND CMD+ADDR | ||
1158 | * note gpmc puts 32b words on the bus least sig. byte 1st | ||
1159 | */ | ||
1160 | nand_cmd_n_addr(RDPAGE_B1, col_addr, row_addr); | ||
1161 | IOWR8(ncmd_reg_vma, RDPAGE_B2); | ||
1162 | |||
1163 | /* | ||
1164 | * setup PFE block | ||
1165 | * count - OMAP number of bytes to access on pnand bus | ||
1166 | */ | ||
1167 | |||
1168 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONFIG1), GPMC_PREFETCH_CONFIG1_VAL); | ||
1169 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONFIG2), count); | ||
1170 | IOWR32(GPMC_VMA(GPMC_PREFETCH_CONTROL), 0x1); | ||
1171 | |||
1172 | ptr32 = buff; | ||
1173 | |||
1174 | do { | ||
1175 | pfe_status = IORD32(GPMC_VMA(GPMC_PREFETCH_STATUS)); | ||
1176 | rd_cnt = pfe_status >> (24+2); | ||
1177 | |||
1178 | while (rd_cnt--) | ||
1179 | *ptr32++ = IORD32(gpmc_data_vma); | ||
1180 | |||
1181 | } while (pfe_status & 0x3fff); | ||
1182 | |||
1183 | /* | ||
1184 | * read out the leftover | ||
1185 | */ | ||
1186 | ptr8 = ptr32; | ||
1187 | rd_cnt = (IORD32(GPMC_VMA(GPMC_PREFETCH_STATUS)) >> 24) & 0x7f; | ||
1188 | |||
1189 | while (rd_cnt--) | ||
1190 | *ptr8++ = IORD8(gpmc_data_vma); | ||
1191 | } | ||
1192 | #endif | ||
1193 | |||
1194 | #ifdef PNAND_LBD_READ_NO_PFE | ||
1195 | /* | ||
1196 | * Endpoint buffer read w/o OMAP GPMC Prefetch Engine | ||
1197 | * the original working code, works at max speed for 8 bit xfers | ||
1198 | * for 16 bit the bus diagram has gaps | ||
1199 | */ | ||
1200 | static void p_nand_lbd_read(u16 col_addr, u32 row_addr, u16 count, void *buff) | ||
1201 | { | ||
1202 | uint16_t w32cnt; | ||
1203 | uint32_t *ptr32; | ||
1204 | uint16_t *ptr16; | ||
1205 | uint16_t remainder; | ||
1206 | |||
1207 | DBGPRN("<1> %s(): NO_PFE\n", __func__); | ||
1208 | |||
1209 | ptr32 = buff; | ||
1210 | /* number of whole 32 bit words in the transfer */ | ||
1211 | w32cnt = count >> 2; | ||
1212 | |||
1213 | /* remainder, in bytes(0..3) */ | ||
1214 | remainder = count & 03; | ||
1215 | |||
1216 | /* | ||
1217 | * note gpmc puts 32b words on the bus least sig. byte 1st | ||
1218 | */ | ||
1219 | nand_cmd_n_addr(RDPAGE_B1, col_addr, row_addr); | ||
1220 | IOWR8(ncmd_reg_vma, RDPAGE_B2); | ||
1221 | |||
1222 | /* | ||
1223 | * read data by 32 bit chunks | ||
1224 | */ | ||
1225 | while (w32cnt--) | ||
1226 | *ptr32++ = IORD32(ndata_reg_vma); | ||
1227 | |||
1228 | /* | ||
1229 | * now do the remainder(it can be 0, 1, 2 or 3) | ||
1230 | * same code for both 8 & 16 bit bus | ||
1231 | * do 1 or 2 MORE words | ||
1232 | */ | ||
1233 | ptr16 = (uint16_t *)ptr32; | ||
1234 | |||
1235 | switch (remainder) { | ||
1236 | case 1: | ||
1237 | /* read one 16 bit word | ||
1238 | * IN 8 BIT WE NEED TO READ even number of bytes | ||
1239 | */ | ||
1240 | case 2: | ||
1241 | *ptr16 = IORD16(ndata_reg_vma); | ||
1242 | break; | ||
1243 | case 3: | ||
1244 | /* | ||
1245 | * for 3 bytes read 2 16 bit words | ||
1246 | */ | ||
1247 | *ptr16++ = IORD16(ndata_reg_vma); | ||
1248 | *ptr16 = IORD16(ndata_reg_vma); | ||
1249 | break; | ||
1250 | default: | ||
1251 | /* | ||
1252 | * remainder is 0 | ||
1253 | */ | ||
1254 | break; | ||
1255 | } | ||
1256 | } | ||
1257 | #endif | ||
1258 | |||
1259 | /* | ||
1260 | * uses LBD mode to write N bytes into astoria | ||
1261 | * Status: Working, however there are 150ns idle | ||
1262 | * timeafter every 2 (16 bit or 4(8 bit) bus cycles | ||
1263 | */ | ||
1264 | static void p_nand_lbd_write(u16 col_addr, u32 row_addr, u16 count, void *buff) | ||
1265 | { | ||
1266 | uint16_t w32cnt; | ||
1267 | uint16_t remainder; | ||
1268 | uint8_t *ptr8; | ||
1269 | uint16_t *ptr16; | ||
1270 | uint32_t *ptr32; | ||
1271 | |||
1272 | remainder = count & 03; | ||
1273 | w32cnt = count >> 2; | ||
1274 | ptr32 = buff; | ||
1275 | ptr8 = buff; | ||
1276 | |||
1277 | /* | ||
1278 | * send: CMDB1, CA0,CA1,RA0,RA1,RA2 | ||
1279 | */ | ||
1280 | nand_cmd_n_addr(PGMPAGE_B1, col_addr, row_addr); | ||
1281 | |||
1282 | /* | ||
1283 | * blast the data out in 32bit chunks | ||
1284 | */ | ||
1285 | while (w32cnt--) | ||
1286 | IOWR32(ndata_reg_vma, *ptr32++); | ||
1287 | |||
1288 | /* | ||
1289 | * do the reminder if there is one | ||
1290 | * same handling for both 8 & 16 bit pnand: mode | ||
1291 | */ | ||
1292 | ptr16 = (uint16_t *)ptr32; /* do 1 or 2 words */ | ||
1293 | |||
1294 | switch (remainder) { | ||
1295 | case 1: | ||
1296 | /* | ||
1297 | * read one 16 bit word | ||
1298 | */ | ||
1299 | case 2: | ||
1300 | IOWR16(ndata_reg_vma, *ptr16); | ||
1301 | break; | ||
1302 | |||
1303 | case 3: | ||
1304 | /* | ||
1305 | * for 3 bytes read 2 16 bit words | ||
1306 | */ | ||
1307 | IOWR16(ndata_reg_vma, *ptr16++); | ||
1308 | IOWR16(ndata_reg_vma, *ptr16); | ||
1309 | break; | ||
1310 | default: | ||
1311 | /* | ||
1312 | * reminder is 0 | ||
1313 | */ | ||
1314 | break; | ||
1315 | } | ||
1316 | /* | ||
1317 | * finally issue a PGM cmd | ||
1318 | */ | ||
1319 | IOWR8(ncmd_reg_vma, PGMPAGE_B2); | ||
1320 | } | ||
1321 | |||
1322 | /* | ||
1323 | * write Astoria register | ||
1324 | */ | ||
1325 | static inline void ast_p_nand_casdi_write(u8 reg_addr8, u16 data) | ||
1326 | { | ||
1327 | unsigned long flags; | ||
1328 | u16 addr16; | ||
1329 | /* | ||
1330 | * throw an error if called from multiple threads | ||
1331 | */ | ||
1332 | static atomic_t rdreg_usage_cnt = { 0 }; | ||
1333 | |||
1334 | /* | ||
1335 | * disable interrupts | ||
1336 | */ | ||
1337 | local_irq_save(flags); | ||
1338 | |||
1339 | if (atomic_read(&rdreg_usage_cnt) != 0) { | ||
1340 | cy_as_hal_print_message(KERN_ERR "cy_as_omap_hal:" | ||
1341 | "* cy_as_hal_write_register usage:%d\n", | ||
1342 | atomic_read(&rdreg_usage_cnt)); | ||
1343 | } | ||
1344 | |||
1345 | atomic_inc(&rdreg_usage_cnt); | ||
1346 | |||
1347 | /* | ||
1348 | * 2 flavors of GPMC -> PNAND access | ||
1349 | */ | ||
1350 | if (pnand_16bit) { | ||
1351 | /* | ||
1352 | * 16 BIT gpmc NAND mode | ||
1353 | */ | ||
1354 | |||
1355 | /* | ||
1356 | * CMD1, CA1, CA2, | ||
1357 | */ | ||
1358 | IOWR8(ncmd_reg_vma, 0x85); | ||
1359 | IOWR8(naddr_reg_vma, reg_addr8); | ||
1360 | IOWR8(naddr_reg_vma, 0x0c); | ||
1361 | |||
1362 | /* | ||
1363 | * this should be sent on the 16 bit bus | ||
1364 | */ | ||
1365 | IOWR16(ndata_reg_vma, data); | ||
1366 | } else { | ||
1367 | /* | ||
1368 | * 8 bit nand mode GPMC will automatically | ||
1369 | * seriallize 16bit or 32 bit writes into | ||
1370 | * 8 bit onesto the lower 8 bit in LE order | ||
1371 | */ | ||
1372 | addr16 = 0x0c00 | reg_addr8; | ||
1373 | |||
1374 | /* | ||
1375 | * CMD1, CA1, CA2, | ||
1376 | */ | ||
1377 | IOWR8(ncmd_reg_vma, 0x85); | ||
1378 | IOWR16(naddr_reg_vma, addr16); | ||
1379 | IOWR16(ndata_reg_vma, data); | ||
1380 | } | ||
1381 | |||
1382 | /* | ||
1383 | * re-enable interrupts | ||
1384 | */ | ||
1385 | atomic_dec(&rdreg_usage_cnt); | ||
1386 | local_irq_restore(flags); | ||
1387 | } | ||
1388 | |||
1389 | |||
1390 | /* | ||
1391 | * read astoria register via pNAND interface | ||
1392 | */ | ||
1393 | static inline u16 ast_p_nand_casdo_read(u8 reg_addr8) | ||
1394 | { | ||
1395 | u16 data; | ||
1396 | u16 addr16; | ||
1397 | unsigned long flags; | ||
1398 | /* | ||
1399 | * throw an error if called from multiple threads | ||
1400 | */ | ||
1401 | static atomic_t wrreg_usage_cnt = { 0 }; | ||
1402 | |||
1403 | /* | ||
1404 | * disable interrupts | ||
1405 | */ | ||
1406 | local_irq_save(flags); | ||
1407 | |||
1408 | if (atomic_read(&wrreg_usage_cnt) != 0) { | ||
1409 | /* | ||
1410 | * if it gets here ( from other threads), this function needs | ||
1411 | * need spin_lock_irq save() protection | ||
1412 | */ | ||
1413 | cy_as_hal_print_message(KERN_ERR"cy_as_omap_hal: " | ||
1414 | "cy_as_hal_write_register usage:%d\n", | ||
1415 | atomic_read(&wrreg_usage_cnt)); | ||
1416 | } | ||
1417 | atomic_inc(&wrreg_usage_cnt); | ||
1418 | |||
1419 | /* | ||
1420 | * 2 flavors of GPMC -> PNAND access | ||
1421 | */ | ||
1422 | if (pnand_16bit) { | ||
1423 | /* | ||
1424 | * 16 BIT gpmc NAND mode | ||
1425 | * CMD1, CA1, CA2, | ||
1426 | */ | ||
1427 | |||
1428 | IOWR8(ncmd_reg_vma, 0x05); | ||
1429 | IOWR8(naddr_reg_vma, reg_addr8); | ||
1430 | IOWR8(naddr_reg_vma, 0x0c); | ||
1431 | IOWR8(ncmd_reg_vma, 0x00E0); | ||
1432 | |||
1433 | udelay(1); | ||
1434 | |||
1435 | /* | ||
1436 | * much faster through the gPMC Register space | ||
1437 | */ | ||
1438 | data = IORD16(ndata_reg_vma); | ||
1439 | } else { | ||
1440 | /* | ||
1441 | * 8 BIT gpmc NAND mode | ||
1442 | * CMD1, CA1, CA2, CMD2 | ||
1443 | */ | ||
1444 | addr16 = 0x0c00 | reg_addr8; | ||
1445 | IOWR8(ncmd_reg_vma, 0x05); | ||
1446 | IOWR16(naddr_reg_vma, addr16); | ||
1447 | IOWR8(ncmd_reg_vma, 0xE0); | ||
1448 | udelay(1); | ||
1449 | data = IORD16(ndata_reg_vma); | ||
1450 | } | ||
1451 | |||
1452 | /* | ||
1453 | * re-enable interrupts | ||
1454 | */ | ||
1455 | atomic_dec(&wrreg_usage_cnt); | ||
1456 | local_irq_restore(flags); | ||
1457 | |||
1458 | return data; | ||
1459 | } | ||
1460 | |||
1461 | |||
1462 | /* | ||
1463 | * This function must be defined to write a register within the WestBridge | ||
1464 | * device. The addr value is the address of the register to write with | ||
1465 | * respect to the base address of the WestBridge device. | ||
1466 | */ | ||
1467 | void cy_as_hal_write_register( | ||
1468 | cy_as_hal_device_tag tag, | ||
1469 | uint16_t addr, uint16_t data) | ||
1470 | { | ||
1471 | ast_p_nand_casdi_write((u8)addr, data); | ||
1472 | } | ||
1473 | |||
1474 | /* | ||
1475 | * This function must be defined to read a register from the WestBridge | ||
1476 | * device. The addr value is the address of the register to read with | ||
1477 | * respect to the base address of the WestBridge device. | ||
1478 | */ | ||
1479 | uint16_t cy_as_hal_read_register(cy_as_hal_device_tag tag, uint16_t addr) | ||
1480 | { | ||
1481 | uint16_t data = 0; | ||
1482 | |||
1483 | /* | ||
1484 | * READ ASTORIA REGISTER USING CASDO | ||
1485 | */ | ||
1486 | data = ast_p_nand_casdo_read((u8)addr); | ||
1487 | |||
1488 | return data; | ||
1489 | } | ||
1490 | |||
1491 | /* | ||
1492 | * preps Ep pointers & data counters for next packet | ||
1493 | * (fragment of the request) xfer returns true if | ||
1494 | * there is a next transfer, and false if all bytes in | ||
1495 | * current request have been xfered | ||
1496 | */ | ||
1497 | static inline bool prep_for_next_xfer(cy_as_hal_device_tag tag, uint8_t ep) | ||
1498 | { | ||
1499 | |||
1500 | if (!end_points[ep].sg_list_enabled) { | ||
1501 | /* | ||
1502 | * no further transfers for non storage EPs | ||
1503 | * (like EP2 during firmware download, done | ||
1504 | * in 64 byte chunks) | ||
1505 | */ | ||
1506 | if (end_points[ep].req_xfer_cnt >= end_points[ep].req_length) { | ||
1507 | DBGPRN("<1> %s():RQ sz:%d non-_sg EP:%d completed\n", | ||
1508 | __func__, end_points[ep].req_length, ep); | ||
1509 | |||
1510 | /* | ||
1511 | * no more transfers, we are done with the request | ||
1512 | */ | ||
1513 | return false; | ||
1514 | } | ||
1515 | |||
1516 | /* | ||
1517 | * calculate size of the next DMA xfer, corner | ||
1518 | * case for non-storage EPs where transfer size | ||
1519 | * is not egual N * HAL_DMA_PKT_SZ xfers | ||
1520 | */ | ||
1521 | if ((end_points[ep].req_length - end_points[ep].req_xfer_cnt) | ||
1522 | >= HAL_DMA_PKT_SZ) { | ||
1523 | end_points[ep].dma_xfer_sz = HAL_DMA_PKT_SZ; | ||
1524 | } else { | ||
1525 | /* | ||
1526 | * that would be the last chunk less | ||
1527 | * than P-port max size | ||
1528 | */ | ||
1529 | end_points[ep].dma_xfer_sz = end_points[ep].req_length - | ||
1530 | end_points[ep].req_xfer_cnt; | ||
1531 | } | ||
1532 | |||
1533 | return true; | ||
1534 | } | ||
1535 | |||
1536 | /* | ||
1537 | * for SG_list assisted dma xfers | ||
1538 | * are we done with current SG ? | ||
1539 | */ | ||
1540 | if (end_points[ep].seg_xfer_cnt == end_points[ep].sg_p->length) { | ||
1541 | /* | ||
1542 | * was it the Last SG segment on the list ? | ||
1543 | */ | ||
1544 | if (sg_is_last(end_points[ep].sg_p)) { | ||
1545 | DBGPRN("<1> %s: EP:%d completed," | ||
1546 | "%d bytes xfered\n", | ||
1547 | __func__, | ||
1548 | ep, | ||
1549 | end_points[ep].req_xfer_cnt | ||
1550 | ); | ||
1551 | |||
1552 | return false; | ||
1553 | } else { | ||
1554 | /* | ||
1555 | * There are more SG segments in current | ||
1556 | * request's sg list setup new segment | ||
1557 | */ | ||
1558 | |||
1559 | end_points[ep].seg_xfer_cnt = 0; | ||
1560 | end_points[ep].sg_p = sg_next(end_points[ep].sg_p); | ||
1561 | /* set data pointer for next DMA sg transfer*/ | ||
1562 | end_points[ep].data_p = sg_virt(end_points[ep].sg_p); | ||
1563 | DBGPRN("<1> %s new SG:_va:%p\n\n", | ||
1564 | __func__, end_points[ep].data_p); | ||
1565 | } | ||
1566 | |||
1567 | } | ||
1568 | |||
1569 | /* | ||
1570 | * for sg list xfers it will always be 512 or 1024 | ||
1571 | */ | ||
1572 | end_points[ep].dma_xfer_sz = HAL_DMA_PKT_SZ; | ||
1573 | |||
1574 | /* | ||
1575 | * next transfer is required | ||
1576 | */ | ||
1577 | |||
1578 | return true; | ||
1579 | } | ||
1580 | |||
1581 | /* | ||
1582 | * Astoria DMA read request, APP_CPU reads from WB ep buffer | ||
1583 | */ | ||
1584 | static void cy_service_e_p_dma_read_request( | ||
1585 | cy_as_omap_dev_kernel *dev_p, uint8_t ep) | ||
1586 | { | ||
1587 | cy_as_hal_device_tag tag = (cy_as_hal_device_tag)dev_p; | ||
1588 | uint16_t v, size; | ||
1589 | void *dptr; | ||
1590 | uint16_t col_addr = 0x0000; | ||
1591 | uint32_t row_addr = CYAS_DEV_CALC_EP_ADDR(ep); | ||
1592 | uint16_t ep_dma_reg = CY_AS_MEM_P0_EP2_DMA_REG + ep - 2; | ||
1593 | |||
1594 | /* | ||
1595 | * get the XFER size frtom WB eP DMA REGISTER | ||
1596 | */ | ||
1597 | v = cy_as_hal_read_register(tag, ep_dma_reg); | ||
1598 | |||
1599 | /* | ||
1600 | * amount of data in EP buff in bytes | ||
1601 | */ | ||
1602 | size = v & CY_AS_MEM_P0_E_pn_DMA_REG_COUNT_MASK; | ||
1603 | |||
1604 | /* | ||
1605 | * memory pointer for this DMA packet xfer (sub_segment) | ||
1606 | */ | ||
1607 | dptr = end_points[ep].data_p; | ||
1608 | |||
1609 | DBGPRN("<1>HAL:_svc_dma_read on EP_%d sz:%d, intr_seq:%d, dptr:%p\n", | ||
1610 | ep, | ||
1611 | size, | ||
1612 | intr_sequence_num, | ||
1613 | dptr | ||
1614 | ); | ||
1615 | |||
1616 | cy_as_hal_assert(size != 0); | ||
1617 | |||
1618 | if (size) { | ||
1619 | /* | ||
1620 | * the actual WB-->OMAP memory "soft" DMA xfer | ||
1621 | */ | ||
1622 | p_nand_lbd_read(col_addr, row_addr, size, dptr); | ||
1623 | } | ||
1624 | |||
1625 | /* | ||
1626 | * clear DMAVALID bit indicating that the data has been read | ||
1627 | */ | ||
1628 | cy_as_hal_write_register(tag, ep_dma_reg, 0); | ||
1629 | |||
1630 | end_points[ep].seg_xfer_cnt += size; | ||
1631 | end_points[ep].req_xfer_cnt += size; | ||
1632 | |||
1633 | /* | ||
1634 | * pre-advance data pointer (if it's outside sg | ||
1635 | * list it will be reset anyway | ||
1636 | */ | ||
1637 | end_points[ep].data_p += size; | ||
1638 | |||
1639 | if (prep_for_next_xfer(tag, ep)) { | ||
1640 | /* | ||
1641 | * we have more data to read in this request, | ||
1642 | * setup next dma packet due tell WB how much | ||
1643 | * data we are going to xfer next | ||
1644 | */ | ||
1645 | v = end_points[ep].dma_xfer_sz/*HAL_DMA_PKT_SZ*/ | | ||
1646 | CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL; | ||
1647 | cy_as_hal_write_register(tag, ep_dma_reg, v); | ||
1648 | } else { | ||
1649 | end_points[ep].pending = cy_false; | ||
1650 | end_points[ep].type = cy_as_hal_none; | ||
1651 | end_points[ep].buffer_valid = cy_false; | ||
1652 | |||
1653 | /* | ||
1654 | * notify the API that we are done with rq on this EP | ||
1655 | */ | ||
1656 | if (callback) { | ||
1657 | DBGPRN("<1>trigg rd_dma completion cb: xfer_sz:%d\n", | ||
1658 | end_points[ep].req_xfer_cnt); | ||
1659 | callback(tag, ep, | ||
1660 | end_points[ep].req_xfer_cnt, | ||
1661 | CY_AS_ERROR_SUCCESS); | ||
1662 | } | ||
1663 | } | ||
1664 | } | ||
1665 | |||
1666 | /* | ||
1667 | * omap_cpu needs to transfer data to ASTORIA EP buffer | ||
1668 | */ | ||
1669 | static void cy_service_e_p_dma_write_request( | ||
1670 | cy_as_omap_dev_kernel *dev_p, uint8_t ep) | ||
1671 | { | ||
1672 | uint16_t addr; | ||
1673 | uint16_t v = 0; | ||
1674 | uint32_t size; | ||
1675 | uint16_t col_addr = 0x0000; | ||
1676 | uint32_t row_addr = CYAS_DEV_CALC_EP_ADDR(ep); | ||
1677 | void *dptr; | ||
1678 | |||
1679 | cy_as_hal_device_tag tag = (cy_as_hal_device_tag)dev_p; | ||
1680 | /* | ||
1681 | * note: size here its the size of the dma transfer could be | ||
1682 | * anything > 0 && < P_PORT packet size | ||
1683 | */ | ||
1684 | size = end_points[ep].dma_xfer_sz; | ||
1685 | dptr = end_points[ep].data_p; | ||
1686 | |||
1687 | /* | ||
1688 | * perform the soft DMA transfer, soft in this case | ||
1689 | */ | ||
1690 | if (size) | ||
1691 | p_nand_lbd_write(col_addr, row_addr, size, dptr); | ||
1692 | |||
1693 | end_points[ep].seg_xfer_cnt += size; | ||
1694 | end_points[ep].req_xfer_cnt += size; | ||
1695 | /* | ||
1696 | * pre-advance data pointer | ||
1697 | * (if it's outside sg list it will be reset anyway) | ||
1698 | */ | ||
1699 | end_points[ep].data_p += size; | ||
1700 | |||
1701 | /* | ||
1702 | * now clear DMAVAL bit to indicate we are done | ||
1703 | * transferring data and that the data can now be | ||
1704 | * sent via USB to the USB host, sent to storage, | ||
1705 | * or used internally. | ||
1706 | */ | ||
1707 | |||
1708 | addr = CY_AS_MEM_P0_EP2_DMA_REG + ep - 2; | ||
1709 | cy_as_hal_write_register(tag, addr, size); | ||
1710 | |||
1711 | /* | ||
1712 | * finally, tell the USB subsystem that the | ||
1713 | * data is gone and we can accept the | ||
1714 | * next request if one exists. | ||
1715 | */ | ||
1716 | if (prep_for_next_xfer(tag, ep)) { | ||
1717 | /* | ||
1718 | * There is more data to go. Re-init the WestBridge DMA side | ||
1719 | */ | ||
1720 | v = end_points[ep].dma_xfer_sz | | ||
1721 | CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL; | ||
1722 | cy_as_hal_write_register(tag, addr, v); | ||
1723 | } else { | ||
1724 | |||
1725 | end_points[ep].pending = cy_false; | ||
1726 | end_points[ep].type = cy_as_hal_none; | ||
1727 | end_points[ep].buffer_valid = cy_false; | ||
1728 | |||
1729 | /* | ||
1730 | * notify the API that we are done with rq on this EP | ||
1731 | */ | ||
1732 | if (callback) { | ||
1733 | /* | ||
1734 | * this callback will wake up the process that might be | ||
1735 | * sleeping on the EP which data is being transferred | ||
1736 | */ | ||
1737 | callback(tag, ep, | ||
1738 | end_points[ep].req_xfer_cnt, | ||
1739 | CY_AS_ERROR_SUCCESS); | ||
1740 | } | ||
1741 | } | ||
1742 | } | ||
1743 | |||
1744 | /* | ||
1745 | * HANDLE DRQINT from Astoria (called in AS_Intr context | ||
1746 | */ | ||
1747 | static void cy_handle_d_r_q_interrupt(cy_as_omap_dev_kernel *dev_p) | ||
1748 | { | ||
1749 | uint16_t v; | ||
1750 | static uint8_t service_ep = 2; | ||
1751 | |||
1752 | /* | ||
1753 | * We've got DRQ INT, read DRQ STATUS Register */ | ||
1754 | v = cy_as_hal_read_register((cy_as_hal_device_tag)dev_p, | ||
1755 | CY_AS_MEM_P0_DRQ); | ||
1756 | |||
1757 | if (v == 0) { | ||
1758 | #ifndef WESTBRIDGE_NDEBUG | ||
1759 | cy_as_hal_print_message("stray DRQ interrupt detected\n"); | ||
1760 | #endif | ||
1761 | return; | ||
1762 | } | ||
1763 | |||
1764 | /* | ||
1765 | * Now, pick a given DMA request to handle, for now, we just | ||
1766 | * go round robin. Each bit position in the service_mask | ||
1767 | * represents an endpoint from EP2 to EP15. We rotate through | ||
1768 | * each of the endpoints to find one that needs to be serviced. | ||
1769 | */ | ||
1770 | while ((v & (1 << service_ep)) == 0) { | ||
1771 | |||
1772 | if (service_ep == 15) | ||
1773 | service_ep = 2; | ||
1774 | else | ||
1775 | service_ep++; | ||
1776 | } | ||
1777 | |||
1778 | if (end_points[service_ep].type == cy_as_hal_write) { | ||
1779 | /* | ||
1780 | * handle DMA WRITE REQUEST: app_cpu will | ||
1781 | * write data into astoria EP buffer | ||
1782 | */ | ||
1783 | cy_service_e_p_dma_write_request(dev_p, service_ep); | ||
1784 | } else if (end_points[service_ep].type == cy_as_hal_read) { | ||
1785 | /* | ||
1786 | * handle DMA READ REQUEST: cpu will | ||
1787 | * read EP buffer from Astoria | ||
1788 | */ | ||
1789 | cy_service_e_p_dma_read_request(dev_p, service_ep); | ||
1790 | } | ||
1791 | #ifndef WESTBRIDGE_NDEBUG | ||
1792 | else | ||
1793 | cy_as_hal_print_message("cyashalomap:interrupt," | ||
1794 | " w/o pending DMA job," | ||
1795 | "-check DRQ_MASK logic\n"); | ||
1796 | #endif | ||
1797 | |||
1798 | /* | ||
1799 | * Now bump the EP ahead, so other endpoints get | ||
1800 | * a shot before the one we just serviced | ||
1801 | */ | ||
1802 | if (end_points[service_ep].type == cy_as_hal_none) { | ||
1803 | if (service_ep == 15) | ||
1804 | service_ep = 2; | ||
1805 | else | ||
1806 | service_ep++; | ||
1807 | } | ||
1808 | |||
1809 | } | ||
1810 | |||
1811 | void cy_as_hal_dma_cancel_request(cy_as_hal_device_tag tag, uint8_t ep) | ||
1812 | { | ||
1813 | DBGPRN("cy_as_hal_dma_cancel_request on ep:%d", ep); | ||
1814 | if (end_points[ep].pending) | ||
1815 | cy_as_hal_write_register(tag, | ||
1816 | CY_AS_MEM_P0_EP2_DMA_REG + ep - 2, 0); | ||
1817 | |||
1818 | end_points[ep].buffer_valid = cy_false; | ||
1819 | end_points[ep].type = cy_as_hal_none; | ||
1820 | } | ||
1821 | |||
1822 | /* | ||
1823 | * enables/disables SG list assisted DMA xfers for the given EP | ||
1824 | * sg_list assisted XFERS can use physical addresses of mem pages in case if the | ||
1825 | * xfer is performed by a h/w DMA controller rather then the CPU on P port | ||
1826 | */ | ||
1827 | void cy_as_hal_set_ep_dma_mode(uint8_t ep, bool sg_xfer_enabled) | ||
1828 | { | ||
1829 | end_points[ep].sg_list_enabled = sg_xfer_enabled; | ||
1830 | DBGPRN("<1> EP:%d sg_list assisted DMA mode set to = %d\n", | ||
1831 | ep, end_points[ep].sg_list_enabled); | ||
1832 | } | ||
1833 | EXPORT_SYMBOL(cy_as_hal_set_ep_dma_mode); | ||
1834 | |||
1835 | /* | ||
1836 | * This function must be defined to transfer a block of data to | ||
1837 | * the WestBridge device. This function can use the burst write | ||
1838 | * (DMA) capabilities of WestBridge to do this, or it can just copy | ||
1839 | * the data using writes. | ||
1840 | */ | ||
1841 | void cy_as_hal_dma_setup_write(cy_as_hal_device_tag tag, | ||
1842 | uint8_t ep, void *buf, | ||
1843 | uint32_t size, uint16_t maxsize) | ||
1844 | { | ||
1845 | uint32_t addr = 0; | ||
1846 | uint16_t v = 0; | ||
1847 | |||
1848 | /* | ||
1849 | * Note: "size" is the actual request size | ||
1850 | * "maxsize" - is the P port fragment size | ||
1851 | * No EP0 or EP1 traffic should get here | ||
1852 | */ | ||
1853 | cy_as_hal_assert(ep != 0 && ep != 1); | ||
1854 | |||
1855 | /* | ||
1856 | * If this asserts, we have an ordering problem. Another DMA request | ||
1857 | * is coming down before the previous one has completed. | ||
1858 | */ | ||
1859 | cy_as_hal_assert(end_points[ep].buffer_valid == cy_false); | ||
1860 | end_points[ep].buffer_valid = cy_true; | ||
1861 | end_points[ep].type = cy_as_hal_write; | ||
1862 | end_points[ep].pending = cy_true; | ||
1863 | |||
1864 | /* | ||
1865 | * total length of the request | ||
1866 | */ | ||
1867 | end_points[ep].req_length = size; | ||
1868 | |||
1869 | if (size >= maxsize) { | ||
1870 | /* | ||
1871 | * set xfer size for very 1st DMA xfer operation | ||
1872 | * port max packet size ( typically 512 or 1024) | ||
1873 | */ | ||
1874 | end_points[ep].dma_xfer_sz = maxsize; | ||
1875 | } else { | ||
1876 | /* | ||
1877 | * smaller xfers for non-storage EPs | ||
1878 | */ | ||
1879 | end_points[ep].dma_xfer_sz = size; | ||
1880 | } | ||
1881 | |||
1882 | /* | ||
1883 | * check the EP transfer mode uses sg_list rather then a memory buffer | ||
1884 | * block devices pass it to the HAL, so the hAL could get to the real | ||
1885 | * physical address for each segment and set up a DMA controller | ||
1886 | * hardware ( if there is one) | ||
1887 | */ | ||
1888 | if (end_points[ep].sg_list_enabled) { | ||
1889 | /* | ||
1890 | * buf - pointer to the SG list | ||
1891 | * data_p - data pointer to the 1st DMA segment | ||
1892 | * seg_xfer_cnt - keeps track of N of bytes sent in current | ||
1893 | * sg_list segment | ||
1894 | * req_xfer_cnt - keeps track of the total N of bytes | ||
1895 | * transferred for the request | ||
1896 | */ | ||
1897 | end_points[ep].sg_p = buf; | ||
1898 | end_points[ep].data_p = sg_virt(end_points[ep].sg_p); | ||
1899 | end_points[ep].seg_xfer_cnt = 0; | ||
1900 | end_points[ep].req_xfer_cnt = 0; | ||
1901 | |||
1902 | #ifdef DBGPRN_DMA_SETUP_WR | ||
1903 | DBGPRN("cyasomaphal:%s: EP:%d, buf:%p, buf_va:%p," | ||
1904 | "req_sz:%d, maxsz:%d\n", | ||
1905 | __func__, | ||
1906 | ep, | ||
1907 | buf, | ||
1908 | end_points[ep].data_p, | ||
1909 | size, | ||
1910 | maxsize); | ||
1911 | #endif | ||
1912 | |||
1913 | } else { | ||
1914 | /* | ||
1915 | * setup XFER for non sg_list assisted EPs | ||
1916 | */ | ||
1917 | |||
1918 | #ifdef DBGPRN_DMA_SETUP_WR | ||
1919 | DBGPRN("<1>%s non storage or sz < 512:" | ||
1920 | "EP:%d, sz:%d\n", __func__, ep, size); | ||
1921 | #endif | ||
1922 | |||
1923 | end_points[ep].sg_p = NULL; | ||
1924 | |||
1925 | /* | ||
1926 | * must be a VMA of a membuf in kernel space | ||
1927 | */ | ||
1928 | end_points[ep].data_p = buf; | ||
1929 | |||
1930 | /* | ||
1931 | * will keep track No of bytes xferred for the request | ||
1932 | */ | ||
1933 | end_points[ep].req_xfer_cnt = 0; | ||
1934 | } | ||
1935 | |||
1936 | /* | ||
1937 | * Tell WB we are ready to send data on the given endpoint | ||
1938 | */ | ||
1939 | v = (end_points[ep].dma_xfer_sz & CY_AS_MEM_P0_E_pn_DMA_REG_COUNT_MASK) | ||
1940 | | CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL; | ||
1941 | |||
1942 | addr = CY_AS_MEM_P0_EP2_DMA_REG + ep - 2; | ||
1943 | |||
1944 | cy_as_hal_write_register(tag, addr, v); | ||
1945 | } | ||
1946 | |||
1947 | /* | ||
1948 | * This function must be defined to transfer a block of data from | ||
1949 | * the WestBridge device. This function can use the burst read | ||
1950 | * (DMA) capabilities of WestBridge to do this, or it can just | ||
1951 | * copy the data using reads. | ||
1952 | */ | ||
1953 | void cy_as_hal_dma_setup_read(cy_as_hal_device_tag tag, | ||
1954 | uint8_t ep, void *buf, | ||
1955 | uint32_t size, uint16_t maxsize) | ||
1956 | { | ||
1957 | uint32_t addr; | ||
1958 | uint16_t v; | ||
1959 | |||
1960 | /* | ||
1961 | * Note: "size" is the actual request size | ||
1962 | * "maxsize" - is the P port fragment size | ||
1963 | * No EP0 or EP1 traffic should get here | ||
1964 | */ | ||
1965 | cy_as_hal_assert(ep != 0 && ep != 1); | ||
1966 | |||
1967 | /* | ||
1968 | * If this asserts, we have an ordering problem. | ||
1969 | * Another DMA request is coming down before the | ||
1970 | * previous one has completed. we should not get | ||
1971 | * new requests if current is still in process | ||
1972 | */ | ||
1973 | |||
1974 | cy_as_hal_assert(end_points[ep].buffer_valid == cy_false); | ||
1975 | |||
1976 | end_points[ep].buffer_valid = cy_true; | ||
1977 | end_points[ep].type = cy_as_hal_read; | ||
1978 | end_points[ep].pending = cy_true; | ||
1979 | end_points[ep].req_xfer_cnt = 0; | ||
1980 | end_points[ep].req_length = size; | ||
1981 | |||
1982 | if (size >= maxsize) { | ||
1983 | /* | ||
1984 | * set xfer size for very 1st DMA xfer operation | ||
1985 | * port max packet size ( typically 512 or 1024) | ||
1986 | */ | ||
1987 | end_points[ep].dma_xfer_sz = maxsize; | ||
1988 | } else { | ||
1989 | /* | ||
1990 | * so that we could handle small xfers on in case | ||
1991 | * of non-storage EPs | ||
1992 | */ | ||
1993 | end_points[ep].dma_xfer_sz = size; | ||
1994 | } | ||
1995 | |||
1996 | addr = CY_AS_MEM_P0_EP2_DMA_REG + ep - 2; | ||
1997 | |||
1998 | if (end_points[ep].sg_list_enabled) { | ||
1999 | /* | ||
2000 | * Handle sg-list assisted EPs | ||
2001 | * seg_xfer_cnt - keeps track of N of sent packets | ||
2002 | * buf - pointer to the SG list | ||
2003 | * data_p - data pointer for the 1st DMA segment | ||
2004 | */ | ||
2005 | end_points[ep].seg_xfer_cnt = 0; | ||
2006 | end_points[ep].sg_p = buf; | ||
2007 | end_points[ep].data_p = sg_virt(end_points[ep].sg_p); | ||
2008 | |||
2009 | #ifdef DBGPRN_DMA_SETUP_RD | ||
2010 | DBGPRN("cyasomaphal:DMA_setup_read sg_list EP:%d, " | ||
2011 | "buf:%p, buf_va:%p, req_sz:%d, maxsz:%d\n", | ||
2012 | ep, | ||
2013 | buf, | ||
2014 | end_points[ep].data_p, | ||
2015 | size, | ||
2016 | maxsize); | ||
2017 | #endif | ||
2018 | v = (end_points[ep].dma_xfer_sz & | ||
2019 | CY_AS_MEM_P0_E_pn_DMA_REG_COUNT_MASK) | | ||
2020 | CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL; | ||
2021 | cy_as_hal_write_register(tag, addr, v); | ||
2022 | } else { | ||
2023 | /* | ||
2024 | * Non sg list EP passed void *buf rather then scatterlist *sg | ||
2025 | */ | ||
2026 | #ifdef DBGPRN_DMA_SETUP_RD | ||
2027 | DBGPRN("%s:non-sg_list EP:%d," | ||
2028 | "RQ_sz:%d, maxsz:%d\n", | ||
2029 | __func__, ep, size, maxsize); | ||
2030 | #endif | ||
2031 | |||
2032 | end_points[ep].sg_p = NULL; | ||
2033 | |||
2034 | /* | ||
2035 | * must be a VMA of a membuf in kernel space | ||
2036 | */ | ||
2037 | end_points[ep].data_p = buf; | ||
2038 | |||
2039 | /* | ||
2040 | * Program the EP DMA register for Storage endpoints only. | ||
2041 | */ | ||
2042 | if (is_storage_e_p(ep)) { | ||
2043 | v = (end_points[ep].dma_xfer_sz & | ||
2044 | CY_AS_MEM_P0_E_pn_DMA_REG_COUNT_MASK) | | ||
2045 | CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL; | ||
2046 | cy_as_hal_write_register(tag, addr, v); | ||
2047 | } | ||
2048 | } | ||
2049 | } | ||
2050 | |||
2051 | /* | ||
2052 | * This function must be defined to allow the WB API to | ||
2053 | * register a callback function that is called when a | ||
2054 | * DMA transfer is complete. | ||
2055 | */ | ||
2056 | void cy_as_hal_dma_register_callback(cy_as_hal_device_tag tag, | ||
2057 | cy_as_hal_dma_complete_callback cb) | ||
2058 | { | ||
2059 | DBGPRN("<1>\n%s: WB API has registered a dma_complete callback:%x\n", | ||
2060 | __func__, (uint32_t)cb); | ||
2061 | callback = cb; | ||
2062 | } | ||
2063 | |||
2064 | /* | ||
2065 | * This function must be defined to return the maximum size of | ||
2066 | * DMA request that can be handled on the given endpoint. The | ||
2067 | * return value should be the maximum size in bytes that the DMA | ||
2068 | * module can handle. | ||
2069 | */ | ||
2070 | uint32_t cy_as_hal_dma_max_request_size(cy_as_hal_device_tag tag, | ||
2071 | cy_as_end_point_number_t ep) | ||
2072 | { | ||
2073 | /* | ||
2074 | * Storage reads and writes are always done in 512 byte blocks. | ||
2075 | * So, we do the count handling within the HAL, and save on | ||
2076 | * some of the data transfer delay. | ||
2077 | */ | ||
2078 | if ((ep == CYASSTORAGE_READ_EP_NUM) || | ||
2079 | (ep == CYASSTORAGE_WRITE_EP_NUM)) { | ||
2080 | /* max DMA request size HAL can handle by itself */ | ||
2081 | return CYASSTORAGE_MAX_XFER_SIZE; | ||
2082 | } else { | ||
2083 | /* | ||
2084 | * For the USB - Processor endpoints, the maximum transfer | ||
2085 | * size depends on the speed of USB operation. So, we use | ||
2086 | * the following constant to indicate to the API that | ||
2087 | * splitting of the data into chunks less that or equal to | ||
2088 | * the max transfer size should be handled internally. | ||
2089 | */ | ||
2090 | |||
2091 | /* DEFINED AS 0xffffffff in cyasdma.h */ | ||
2092 | return CY_AS_DMA_MAX_SIZE_HW_SIZE; | ||
2093 | } | ||
2094 | } | ||
2095 | |||
2096 | /* | ||
2097 | * This function must be defined to set the state of the WAKEUP pin | ||
2098 | * on the WestBridge device. Generally this is done via a GPIO of | ||
2099 | * some type. | ||
2100 | */ | ||
2101 | cy_bool cy_as_hal_set_wakeup_pin(cy_as_hal_device_tag tag, cy_bool state) | ||
2102 | { | ||
2103 | /* | ||
2104 | * Not supported as of now. | ||
2105 | */ | ||
2106 | return cy_false; | ||
2107 | } | ||
2108 | |||
2109 | void cy_as_hal_pll_lock_loss_handler(cy_as_hal_device_tag tag) | ||
2110 | { | ||
2111 | cy_as_hal_print_message("error: astoria PLL lock is lost\n"); | ||
2112 | cy_as_hal_print_message("please check the input voltage levels"); | ||
2113 | cy_as_hal_print_message("and clock, and restart the system\n"); | ||
2114 | } | ||
2115 | |||
2116 | /* | ||
2117 | * Below are the functions that must be defined to provide the basic | ||
2118 | * operating system services required by the API. | ||
2119 | */ | ||
2120 | |||
2121 | /* | ||
2122 | * This function is required by the API to allocate memory. | ||
2123 | * This function is expected to work exactly like malloc(). | ||
2124 | */ | ||
2125 | void *cy_as_hal_alloc(uint32_t cnt) | ||
2126 | { | ||
2127 | return kmalloc(cnt, GFP_ATOMIC); | ||
2128 | } | ||
2129 | |||
2130 | /* | ||
2131 | * This function is required by the API to free memory allocated | ||
2132 | * with CyAsHalAlloc(). This function is'expected to work exacly | ||
2133 | * like free(). | ||
2134 | */ | ||
2135 | void cy_as_hal_free(void *mem_p) | ||
2136 | { | ||
2137 | kfree(mem_p); | ||
2138 | } | ||
2139 | |||
2140 | /* | ||
2141 | * Allocator that can be used in interrupt context. | ||
2142 | * We have to ensure that the kmalloc call does not | ||
2143 | * sleep in this case. | ||
2144 | */ | ||
2145 | void *cy_as_hal_c_b_alloc(uint32_t cnt) | ||
2146 | { | ||
2147 | return kmalloc(cnt, GFP_ATOMIC); | ||
2148 | } | ||
2149 | |||
2150 | /* | ||
2151 | * This function is required to set a block of memory to a | ||
2152 | * specific value. This function is expected to work exactly | ||
2153 | * like memset() | ||
2154 | */ | ||
2155 | void cy_as_hal_mem_set(void *ptr, uint8_t value, uint32_t cnt) | ||
2156 | { | ||
2157 | memset(ptr, value, cnt); | ||
2158 | } | ||
2159 | |||
2160 | /* | ||
2161 | * This function is expected to create a sleep channel. | ||
2162 | * The data structure that represents the sleep channel object | ||
2163 | * sleep channel (which is Linux "wait_queue_head_t wq" for this particular HAL) | ||
2164 | * passed as a pointer, and allpocated by the caller | ||
2165 | * (typically as a local var on the stack) "Create" word should read as | ||
2166 | * "SleepOn", this func doesn't actually create anything | ||
2167 | */ | ||
2168 | cy_bool cy_as_hal_create_sleep_channel(cy_as_hal_sleep_channel *channel) | ||
2169 | { | ||
2170 | init_waitqueue_head(&channel->wq); | ||
2171 | return cy_true; | ||
2172 | } | ||
2173 | |||
2174 | /* | ||
2175 | * for this particular HAL it doesn't actually destroy anything | ||
2176 | * since no actual sleep object is created in CreateSleepChannel() | ||
2177 | * sleep channel is given by the pointer in the argument. | ||
2178 | */ | ||
2179 | cy_bool cy_as_hal_destroy_sleep_channel(cy_as_hal_sleep_channel *channel) | ||
2180 | { | ||
2181 | return cy_true; | ||
2182 | } | ||
2183 | |||
2184 | /* | ||
2185 | * platform specific wakeable Sleep implementation | ||
2186 | */ | ||
2187 | cy_bool cy_as_hal_sleep_on(cy_as_hal_sleep_channel *channel, uint32_t ms) | ||
2188 | { | ||
2189 | wait_event_interruptible_timeout(channel->wq, 0, ((ms * HZ)/1000)); | ||
2190 | return cy_true; | ||
2191 | } | ||
2192 | |||
2193 | /* | ||
2194 | * wakes up the process waiting on the CHANNEL | ||
2195 | */ | ||
2196 | cy_bool cy_as_hal_wake(cy_as_hal_sleep_channel *channel) | ||
2197 | { | ||
2198 | wake_up_interruptible_all(&channel->wq); | ||
2199 | return cy_true; | ||
2200 | } | ||
2201 | |||
2202 | uint32_t cy_as_hal_disable_interrupts() | ||
2203 | { | ||
2204 | if (0 == intr__enable) | ||
2205 | ; | ||
2206 | |||
2207 | intr__enable++; | ||
2208 | return 0; | ||
2209 | } | ||
2210 | |||
2211 | void cy_as_hal_enable_interrupts(uint32_t val) | ||
2212 | { | ||
2213 | intr__enable--; | ||
2214 | if (0 == intr__enable) | ||
2215 | ; | ||
2216 | } | ||
2217 | |||
2218 | /* | ||
2219 | * Sleep atleast 150ns, cpu dependent | ||
2220 | */ | ||
2221 | void cy_as_hal_sleep150(void) | ||
2222 | { | ||
2223 | uint32_t i, j; | ||
2224 | |||
2225 | j = 0; | ||
2226 | for (i = 0; i < 1000; i++) | ||
2227 | j += (~i); | ||
2228 | } | ||
2229 | |||
2230 | void cy_as_hal_sleep(uint32_t ms) | ||
2231 | { | ||
2232 | cy_as_hal_sleep_channel channel; | ||
2233 | |||
2234 | cy_as_hal_create_sleep_channel(&channel); | ||
2235 | cy_as_hal_sleep_on(&channel, ms); | ||
2236 | cy_as_hal_destroy_sleep_channel(&channel); | ||
2237 | } | ||
2238 | |||
2239 | cy_bool cy_as_hal_is_polling() | ||
2240 | { | ||
2241 | return cy_false; | ||
2242 | } | ||
2243 | |||
2244 | void cy_as_hal_c_b_free(void *ptr) | ||
2245 | { | ||
2246 | cy_as_hal_free(ptr); | ||
2247 | } | ||
2248 | |||
2249 | /* | ||
2250 | * suppose to reinstate the astoria registers | ||
2251 | * that may be clobbered in sleep mode | ||
2252 | */ | ||
2253 | void cy_as_hal_init_dev_registers(cy_as_hal_device_tag tag, | ||
2254 | cy_bool is_standby_wakeup) | ||
2255 | { | ||
2256 | /* specific to SPI, no implementation required */ | ||
2257 | (void) tag; | ||
2258 | (void) is_standby_wakeup; | ||
2259 | } | ||
2260 | |||
2261 | void cy_as_hal_read_regs_before_standby(cy_as_hal_device_tag tag) | ||
2262 | { | ||
2263 | /* specific to SPI, no implementation required */ | ||
2264 | (void) tag; | ||
2265 | } | ||
2266 | |||
2267 | cy_bool cy_as_hal_sync_device_clocks(cy_as_hal_device_tag tag) | ||
2268 | { | ||
2269 | /* | ||
2270 | * we are in asynchronous mode. so no need to handle this | ||
2271 | */ | ||
2272 | return true; | ||
2273 | } | ||
2274 | |||
2275 | /* | ||
2276 | * init OMAP h/w resources | ||
2277 | */ | ||
2278 | int start_o_m_a_p_kernel(const char *pgm, | ||
2279 | cy_as_hal_device_tag *tag, cy_bool debug) | ||
2280 | { | ||
2281 | cy_as_omap_dev_kernel *dev_p; | ||
2282 | int i; | ||
2283 | u16 data16[4]; | ||
2284 | u8 pncfg_reg; | ||
2285 | |||
2286 | /* | ||
2287 | * No debug mode support through argument as of now | ||
2288 | */ | ||
2289 | (void)debug; | ||
2290 | |||
2291 | DBGPRN(KERN_INFO"starting OMAP34xx HAL...\n"); | ||
2292 | |||
2293 | /* | ||
2294 | * Initialize the HAL level endpoint DMA data. | ||
2295 | */ | ||
2296 | for (i = 0; i < sizeof(end_points)/sizeof(end_points[0]); i++) { | ||
2297 | end_points[i].data_p = 0; | ||
2298 | end_points[i].pending = cy_false; | ||
2299 | end_points[i].size = 0; | ||
2300 | end_points[i].type = cy_as_hal_none; | ||
2301 | end_points[i].sg_list_enabled = cy_false; | ||
2302 | |||
2303 | /* | ||
2304 | * by default the DMA transfers to/from the E_ps don't | ||
2305 | * use sg_list that implies that the upper devices like | ||
2306 | * blockdevice have to enable it for the E_ps in their | ||
2307 | * initialization code | ||
2308 | */ | ||
2309 | } | ||
2310 | |||
2311 | /* | ||
2312 | * allocate memory for OMAP HAL | ||
2313 | */ | ||
2314 | dev_p = (cy_as_omap_dev_kernel *)cy_as_hal_alloc( | ||
2315 | sizeof(cy_as_omap_dev_kernel)); | ||
2316 | if (dev_p == 0) { | ||
2317 | cy_as_hal_print_message("out of memory allocating OMAP" | ||
2318 | "device structure\n"); | ||
2319 | return 0; | ||
2320 | } | ||
2321 | |||
2322 | dev_p->m_sig = CY_AS_OMAP_KERNEL_HAL_SIG; | ||
2323 | |||
2324 | /* | ||
2325 | * initialize OMAP hardware and StartOMAPKernelall gpio pins | ||
2326 | */ | ||
2327 | dev_p->m_addr_base = (void *)cy_as_hal_processor_hw_init(); | ||
2328 | |||
2329 | /* | ||
2330 | * Now perform a hard reset of the device to have | ||
2331 | * the new settings take effect | ||
2332 | */ | ||
2333 | __gpio_set_value(AST_WAKEUP, 1); | ||
2334 | |||
2335 | /* | ||
2336 | * do Astoria h/w reset | ||
2337 | */ | ||
2338 | DBGPRN(KERN_INFO"-_-_pulse -> westbridge RST pin\n"); | ||
2339 | |||
2340 | /* | ||
2341 | * NEGATIVE PULSE on RST pin | ||
2342 | */ | ||
2343 | __gpio_set_value(AST_RESET, 0); | ||
2344 | mdelay(1); | ||
2345 | __gpio_set_value(AST_RESET, 1); | ||
2346 | mdelay(50); | ||
2347 | |||
2348 | /* | ||
2349 | * note AFTER reset PNAND interface is 8 bit mode | ||
2350 | * so if gpmc Is configured in 8 bit mode upper half will be FF | ||
2351 | */ | ||
2352 | pncfg_reg = ast_p_nand_casdo_read(CY_AS_MEM_PNAND_CFG); | ||
2353 | |||
2354 | #ifdef PNAND_16BIT_MODE | ||
2355 | |||
2356 | /* | ||
2357 | * switch to 16 bit mode, force NON-LNA LBD mode, 3 RA addr bytes | ||
2358 | */ | ||
2359 | ast_p_nand_casdi_write(CY_AS_MEM_PNAND_CFG, 0x0001); | ||
2360 | |||
2361 | /* | ||
2362 | * now in order to continue to talk to astoria | ||
2363 | * sw OMAP GPMC into 16 bit mode as well | ||
2364 | */ | ||
2365 | cy_as_hal_gpmc_enable_16bit_bus(cy_true); | ||
2366 | #else | ||
2367 | /* Astoria and GPMC are already in 8 bit mode, just initialize PNAND_CFG */ | ||
2368 | ast_p_nand_casdi_write(CY_AS_MEM_PNAND_CFG, 0x0000); | ||
2369 | #endif | ||
2370 | |||
2371 | /* | ||
2372 | * NOTE: if you want to capture bus activity on the LA, | ||
2373 | * don't use printks in between the activities you want to capture. | ||
2374 | * prinks may take milliseconds, and the data of interest | ||
2375 | * will fall outside the LA capture window/buffer | ||
2376 | */ | ||
2377 | data16[0] = ast_p_nand_casdo_read(CY_AS_MEM_CM_WB_CFG_ID); | ||
2378 | data16[1] = ast_p_nand_casdo_read(CY_AS_MEM_PNAND_CFG); | ||
2379 | |||
2380 | if (data16[0] != 0xA200) { | ||
2381 | /* | ||
2382 | * astoria device is not found | ||
2383 | */ | ||
2384 | printk(KERN_ERR "ERROR: astoria device is not found, CY_AS_MEM_CM_WB_CFG_ID "); | ||
2385 | printk(KERN_ERR "read returned:%4.4X: CY_AS_MEM_PNAND_CFG:%4.4x !\n", | ||
2386 | data16[0], data16[0]); | ||
2387 | goto bus_acc_error; | ||
2388 | } | ||
2389 | |||
2390 | cy_as_hal_print_message(KERN_INFO" register access CASDO test:" | ||
2391 | "\n CY_AS_MEM_CM_WB_CFG_ID:%4.4x\n" | ||
2392 | "PNAND_CFG after RST:%4.4x\n " | ||
2393 | "CY_AS_MEM_PNAND_CFG" | ||
2394 | "after cfg_wr:%4.4x\n\n", | ||
2395 | data16[0], pncfg_reg, data16[1]); | ||
2396 | |||
2397 | dev_p->thread_flag = 1; | ||
2398 | spin_lock_init(&int_lock); | ||
2399 | dev_p->m_next_p = m_omap_list_p; | ||
2400 | |||
2401 | m_omap_list_p = dev_p; | ||
2402 | *tag = dev_p; | ||
2403 | |||
2404 | cy_as_hal_configure_interrupts((void *)dev_p); | ||
2405 | |||
2406 | cy_as_hal_print_message(KERN_INFO"OMAP3430__hal started tag:%p" | ||
2407 | ", kernel HZ:%d\n", dev_p, HZ); | ||
2408 | |||
2409 | /* | ||
2410 | *make processor to storage endpoints SG assisted by default | ||
2411 | */ | ||
2412 | cy_as_hal_set_ep_dma_mode(4, true); | ||
2413 | cy_as_hal_set_ep_dma_mode(8, true); | ||
2414 | |||
2415 | return 1; | ||
2416 | |||
2417 | /* | ||
2418 | * there's been a NAND bus access error or | ||
2419 | * astoria device is not connected | ||
2420 | */ | ||
2421 | bus_acc_error: | ||
2422 | /* | ||
2423 | * at this point hal tag hasn't been set yet | ||
2424 | * so the device will not call omap_stop | ||
2425 | */ | ||
2426 | cy_as_hal_omap_hardware_deinit(dev_p); | ||
2427 | cy_as_hal_free(dev_p); | ||
2428 | return 0; | ||
2429 | } | ||
2430 | |||
2431 | #else | ||
2432 | /* | ||
2433 | * Some compilers do not like empty C files, so if the OMAP hal is not being | ||
2434 | * compiled, we compile this single function. We do this so that for a | ||
2435 | * given target HAL there are not multiple sources for the HAL functions. | ||
2436 | */ | ||
2437 | void my_o_m_a_p_kernel_hal_dummy_function(void) | ||
2438 | { | ||
2439 | } | ||
2440 | |||
2441 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/cyashaldef.h b/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/cyashaldef.h deleted file mode 100644 index c05e6d6cb702..000000000000 --- a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/cyashaldef.h +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyashaldef.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASHALDEF_H_ | ||
23 | #define _INCLUDED_CYASHALDEF_H_ | ||
24 | |||
25 | /* Summary | ||
26 | * If set to TRUE, the basic numeric types are defined by the | ||
27 | * West Bridge API code | ||
28 | * | ||
29 | * Description | ||
30 | * The West Bridge API relies on some basic integral types to be | ||
31 | * defined. These types include uint8_t, int8_t, uint16_t, | ||
32 | * int16_t, uint32_t, and int32_t. If this macro is defined the | ||
33 | * West Bridge API will define these types based on some basic | ||
34 | * assumptions. If this value is set and the West Bridge API is | ||
35 | * used to set these types, the definition of these types must be | ||
36 | * examined to insure that they are appropriate for the given | ||
37 | * target architecture and compiler. | ||
38 | * | ||
39 | * Notes | ||
40 | * It is preferred that if the basic platform development | ||
41 | * environment defines these types that the CY_DEFINE_BASIC_TYPES | ||
42 | * macro be undefined and the appropriate target system header file | ||
43 | * be added to the file cyashaldef.h. | ||
44 | */ | ||
45 | |||
46 | #include <linux/types.h> | ||
47 | |||
48 | |||
49 | #if !defined(__doxygen__) | ||
50 | typedef int cy_bool; | ||
51 | #define cy_true (1) | ||
52 | #define cy_false (0) | ||
53 | #endif | ||
54 | |||
55 | #endif /* _INCLUDED_CYASHALDEF_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h b/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h deleted file mode 100644 index 6426ea61f3d4..000000000000 --- a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h +++ /dev/null | |||
@@ -1,319 +0,0 @@ | |||
1 | /* Cypress Antioch HAL for OMAP KERNEL header file (cyashalomapkernel.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * This file contains the definition of the hardware abstraction | ||
24 | * layer on OMAP3430 talking to the West Bridge Astoria device | ||
25 | */ | ||
26 | |||
27 | |||
28 | #ifndef _INCLUDED_CYASHALOMAP_KERNEL_H_ | ||
29 | #define _INCLUDED_CYASHALOMAP_KERNEL_H_ | ||
30 | |||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/wait.h> | ||
34 | #include <linux/string.h> | ||
35 | /* include does not seem to work | ||
36 | * moving for patch submission | ||
37 | #include <mach/gpmc.h> | ||
38 | */ | ||
39 | #include <linux/../../arch/arm/plat-omap/include/plat/gpmc.h> | ||
40 | typedef struct cy_as_hal_sleep_channel_t { | ||
41 | wait_queue_head_t wq; | ||
42 | } cy_as_hal_sleep_channel; | ||
43 | |||
44 | /* moved to staging location, eventual location | ||
45 | * considered is here | ||
46 | #include <mach/westbridge/cyashaldef.h> | ||
47 | #include <linux/westbridge/cyastypes.h> | ||
48 | #include <linux/westbridge/cyas_cplus_start.h> | ||
49 | */ | ||
50 | #include "../cyashaldef.h" | ||
51 | #include "../../../../../../../include/linux/westbridge/cyastypes.h" | ||
52 | #include "../../../../../../../include/linux/westbridge/cyas_cplus_start.h" | ||
53 | #include "cyasomapdev_kernel.h" | ||
54 | |||
55 | /* | ||
56 | * Below are the data structures that must be defined by the HAL layer | ||
57 | */ | ||
58 | |||
59 | /* | ||
60 | * The HAL layer must define a TAG for identifying a specific Astoria | ||
61 | * device in the system. In this case the tag is a void * which is | ||
62 | * really an OMAP device pointer | ||
63 | */ | ||
64 | typedef void *cy_as_hal_device_tag; | ||
65 | |||
66 | |||
67 | /* This must be included after the CyAsHalDeviceTag type is defined */ | ||
68 | |||
69 | /* moved to staging location, eventual location | ||
70 | * considered is here | ||
71 | * #include <linux/westbridge/cyashalcb.h> | ||
72 | */ | ||
73 | #include "../../../../../../../include/linux/westbridge/cyashalcb.h" | ||
74 | /* | ||
75 | * Below are the functions that communicate with the West Bridge | ||
76 | * device. These are system dependent and must be defined by | ||
77 | * the HAL layer for a given system. | ||
78 | */ | ||
79 | |||
80 | /* | ||
81 | * This function must be defined to write a register within the Antioch | ||
82 | * device. The addr value is the address of the register to write with | ||
83 | * respect to the base address of the Antioch device. | ||
84 | */ | ||
85 | void | ||
86 | cy_as_hal_write_register(cy_as_hal_device_tag tag, | ||
87 | uint16_t addr, uint16_t data); | ||
88 | |||
89 | /* | ||
90 | * This function must be defined to read a register from | ||
91 | * the west bridge device. The addr value is the address of | ||
92 | * the register to read with respect to the base address | ||
93 | * of the west bridge device. | ||
94 | */ | ||
95 | uint16_t | ||
96 | cy_as_hal_read_register(cy_as_hal_device_tag tag, uint16_t addr); | ||
97 | |||
98 | /* | ||
99 | * This function must be defined to transfer a block of data | ||
100 | * to the west bridge device. This function can use the burst write | ||
101 | * (DMA) capabilities of Antioch to do this, or it can just copy | ||
102 | * the data using writes. | ||
103 | */ | ||
104 | void | ||
105 | cy_as_hal_dma_setup_write(cy_as_hal_device_tag tag, | ||
106 | uint8_t ep, void *buf, uint32_t size, uint16_t maxsize); | ||
107 | |||
108 | /* | ||
109 | * This function must be defined to transfer a block of data | ||
110 | * from the Antioch device. This function can use the burst | ||
111 | * read (DMA) capabilities of Antioch to do this, or it can | ||
112 | * just copy the data using reads. | ||
113 | */ | ||
114 | void | ||
115 | cy_as_hal_dma_setup_read(cy_as_hal_device_tag tag, uint8_t ep, | ||
116 | void *buf, uint32_t size, uint16_t maxsize); | ||
117 | |||
118 | /* | ||
119 | * This function must be defined to cancel any pending DMA request. | ||
120 | */ | ||
121 | void | ||
122 | cy_as_hal_dma_cancel_request(cy_as_hal_device_tag tag, uint8_t ep); | ||
123 | |||
124 | /* | ||
125 | * This function must be defined to allow the Antioch API to | ||
126 | * register a callback function that is called when a DMA transfer | ||
127 | * is complete. | ||
128 | */ | ||
129 | void | ||
130 | cy_as_hal_dma_register_callback(cy_as_hal_device_tag tag, | ||
131 | cy_as_hal_dma_complete_callback cb); | ||
132 | |||
133 | /* | ||
134 | * This function must be defined to return the maximum size of DMA | ||
135 | * request that can be handled on the given endpoint. The return | ||
136 | * value should be the maximum size in bytes that the DMA module can | ||
137 | * handle. | ||
138 | */ | ||
139 | uint32_t | ||
140 | cy_as_hal_dma_max_request_size(cy_as_hal_device_tag tag, | ||
141 | cy_as_end_point_number_t ep); | ||
142 | |||
143 | /* | ||
144 | * This function must be defined to set the state of the WAKEUP pin | ||
145 | * on the Antioch device. Generally this is done via a GPIO of some | ||
146 | * type. | ||
147 | */ | ||
148 | cy_bool | ||
149 | cy_as_hal_set_wakeup_pin(cy_as_hal_device_tag tag, cy_bool state); | ||
150 | |||
151 | /* | ||
152 | * This function is called when the Antioch PLL loses lock, because | ||
153 | * of a problem in the supply voltage or the input clock. | ||
154 | */ | ||
155 | void | ||
156 | cy_as_hal_pll_lock_loss_handler(cy_as_hal_device_tag tag); | ||
157 | |||
158 | |||
159 | /********************************************************************** | ||
160 | * | ||
161 | * Below are the functions that must be defined to provide the basic | ||
162 | * operating system services required by the API. | ||
163 | * | ||
164 | ***********************************************************************/ | ||
165 | |||
166 | /* | ||
167 | * This function is required by the API to allocate memory. This function | ||
168 | * is expected to work exactly like malloc(). | ||
169 | */ | ||
170 | void * | ||
171 | cy_as_hal_alloc(uint32_t cnt); | ||
172 | |||
173 | /* | ||
174 | * This function is required by the API to free memory allocated with | ||
175 | * CyAsHalAlloc(). This function is expected to work exacly like free(). | ||
176 | */ | ||
177 | void | ||
178 | cy_as_hal_free(void *mem_p); | ||
179 | |||
180 | /* | ||
181 | * This function is required by the API to allocate memory during a | ||
182 | * callback. This function must be able to provide storage at inturupt | ||
183 | * time. | ||
184 | */ | ||
185 | void * | ||
186 | cy_as_hal_c_b_alloc(uint32_t cnt); | ||
187 | |||
188 | /* | ||
189 | * This function is required by the API to free memory allocated with | ||
190 | * CyAsCBHalAlloc(). | ||
191 | */ | ||
192 | void | ||
193 | cy_as_hal_c_b_free(void *ptr); | ||
194 | |||
195 | /* | ||
196 | * This function is required to set a block of memory to a specific | ||
197 | * value. This function is expected to work exactly like memset() | ||
198 | */ | ||
199 | void | ||
200 | cy_as_hal_mem_set(void *ptr, uint8_t value, uint32_t cnt); | ||
201 | |||
202 | /* | ||
203 | * This function is expected to create a sleep channel. The data | ||
204 | * structure that represents the sleep channel is given by the | ||
205 | * pointer in the argument. | ||
206 | */ | ||
207 | cy_bool | ||
208 | cy_as_hal_create_sleep_channel(cy_as_hal_sleep_channel *channel); | ||
209 | |||
210 | /* | ||
211 | * This function is expected to destroy a sleep channel. The data | ||
212 | * structure that represents the sleep channel is given by | ||
213 | * the pointer in the argument. | ||
214 | */ | ||
215 | |||
216 | |||
217 | cy_bool | ||
218 | cy_as_hal_destroy_sleep_channel(cy_as_hal_sleep_channel *channel); | ||
219 | |||
220 | cy_bool | ||
221 | cy_as_hal_sleep_on(cy_as_hal_sleep_channel *channel, uint32_t ms); | ||
222 | |||
223 | cy_bool | ||
224 | cy_as_hal_wake(cy_as_hal_sleep_channel *channel); | ||
225 | |||
226 | uint32_t | ||
227 | cy_as_hal_disable_interrupts(void); | ||
228 | |||
229 | void | ||
230 | cy_as_hal_enable_interrupts(uint32_t); | ||
231 | |||
232 | void | ||
233 | cy_as_hal_sleep150(void); | ||
234 | |||
235 | void | ||
236 | cy_as_hal_sleep(uint32_t ms); | ||
237 | |||
238 | cy_bool | ||
239 | cy_as_hal_is_polling(void); | ||
240 | |||
241 | void cy_as_hal_init_dev_registers(cy_as_hal_device_tag tag, | ||
242 | cy_bool is_standby_wakeup); | ||
243 | |||
244 | /* | ||
245 | * required only in spi mode | ||
246 | */ | ||
247 | cy_bool cy_as_hal_sync_device_clocks(cy_as_hal_device_tag tag); | ||
248 | |||
249 | void cy_as_hal_read_regs_before_standby(cy_as_hal_device_tag tag); | ||
250 | |||
251 | |||
252 | #ifndef NDEBUG | ||
253 | #define cy_as_hal_assert(cond) if (!(cond))\ | ||
254 | printk(KERN_WARNING"assertion failed at %s:%d\n", __FILE__, __LINE__); | ||
255 | #else | ||
256 | #define cy_as_hal_assert(cond) | ||
257 | #endif | ||
258 | |||
259 | #define cy_as_hal_print_message printk | ||
260 | |||
261 | /* removable debug printks */ | ||
262 | #ifndef WESTBRIDGE_NDEBUG | ||
263 | #define DBG_PRINT_ENABLED | ||
264 | #endif | ||
265 | |||
266 | /*#define MBOX_ACCESS_DBG_PRINT_ENABLED*/ | ||
267 | |||
268 | |||
269 | #ifdef DBG_PRINT_ENABLED | ||
270 | /* Debug printing enabled */ | ||
271 | |||
272 | #define DBGPRN(...) printk(__VA_ARGS__) | ||
273 | #define DBGPRN_FUNC_NAME printk("<1> %x:_func: %s\n", \ | ||
274 | current->pid, __func__) | ||
275 | |||
276 | #else | ||
277 | /** NO DEBUG PRINTING **/ | ||
278 | #define DBGPRN(...) | ||
279 | #define DBGPRN_FUNC_NAME | ||
280 | |||
281 | #endif | ||
282 | |||
283 | /* | ||
284 | CyAsMiscSetLogLevel(uint8_t level) | ||
285 | { | ||
286 | debug_level = level; | ||
287 | } | ||
288 | |||
289 | #ifdef CY_AS_LOG_SUPPORT | ||
290 | |||
291 | void | ||
292 | cy_as_log_debug_message(int level, const char *str) | ||
293 | { | ||
294 | if (level <= debug_level) | ||
295 | cy_as_hal_print_message("log %d: %s\n", level, str); | ||
296 | } | ||
297 | */ | ||
298 | |||
299 | |||
300 | /* | ||
301 | * print buffer helper | ||
302 | */ | ||
303 | void cyashal_prn_buf(void *buf, uint16_t offset, int len); | ||
304 | |||
305 | /* | ||
306 | * These are the functions that are not part of the HAL layer, | ||
307 | * but are required to be called for this HAL. | ||
308 | */ | ||
309 | int start_o_m_a_p_kernel(const char *pgm, | ||
310 | cy_as_hal_device_tag *tag, cy_bool debug); | ||
311 | int stop_o_m_a_p_kernel(const char *pgm, cy_as_hal_device_tag tag); | ||
312 | int omap_start_intr(cy_as_hal_device_tag tag); | ||
313 | void cy_as_hal_set_ep_dma_mode(uint8_t ep, bool sg_xfer_enabled); | ||
314 | |||
315 | /* moved to staging location | ||
316 | #include <linux/westbridge/cyas_cplus_end.h> | ||
317 | */ | ||
318 | #include "../../../../../../../include/linux/westbridge/cyas_cplus_start.h" | ||
319 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasmemmap.h b/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasmemmap.h deleted file mode 100644 index 46f06ee29357..000000000000 --- a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasmemmap.h +++ /dev/null | |||
@@ -1,558 +0,0 @@ | |||
1 | /* | ||
2 | OMAP3430 ZOOM MDK astoria interface defs(cyasmemmap.h) | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
19 | ## Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | /* include does not seem to work | ||
23 | * moving for patch submission | ||
24 | #include <mach/gpmc.h> | ||
25 | #include <mach/mux.h> | ||
26 | */ | ||
27 | #include <linux/../../arch/arm/plat-omap/include/plat/gpmc.h> | ||
28 | #include <linux/../../arch/arm/plat-omap/include/plat/mux.h> | ||
29 | |||
30 | #ifndef _INCLUDED_CYASMEMMAP_H_ | ||
31 | #define _INCLUDED_CYASMEMMAP_H_ | ||
32 | |||
33 | /* defines copied from OMAP kernel branch */ | ||
34 | |||
35 | #define OMAP2_PULL_UP (1 << 4) | ||
36 | #define OMAP2_PULL_ENA (1 << 3) | ||
37 | #define OMAP34XX_MUX_MODE0 0 | ||
38 | #define OMAP34XX_MUX_MODE4 4 | ||
39 | #define OMAP3_INPUT_EN (1 << 8) | ||
40 | #define OMAP34XX_PIN_INPUT_PULLUP (OMAP2_PULL_ENA | OMAP3_INPUT_EN \ | ||
41 | | OMAP2_PULL_UP) | ||
42 | |||
43 | /* | ||
44 | * for OMAP3430 <-> astoria : ADmux mode, 8 bit data path | ||
45 | * WB Signal- OMAP3430 signal COMMENTS | ||
46 | * --------------------------- -------------------- | ||
47 | * CS_L -GPMC_nCS4_GPIO_53 ZOOM I SOM board | ||
48 | * signal: up_nCS_A_EXT | ||
49 | * AD[7:0]-upD[7:0] buffered on the | ||
50 | * transposer board | ||
51 | * GPMC_ADDR | ||
52 | * [A8:A1]->upD[7:0] | ||
53 | * INT# -GPMC_nWP_GPIO_62 | ||
54 | * DACK -N/C not connected | ||
55 | * WAKEUP-GPIO_167 | ||
56 | * RESET-GPIO_126 | ||
57 | * R/B -GPMC_WAIT2_GPIO_64 | ||
58 | * ------------------------------------------- | ||
59 | * The address range for nCS1B is 0x06000000 - 0x07FF FFFF. | ||
60 | */ | ||
61 | |||
62 | /* | ||
63 | *OMAP_ZOOM LEDS | ||
64 | */ | ||
65 | #define LED_0 156 | ||
66 | #define LED_1 128 | ||
67 | #define LED_2 64 | ||
68 | #define LED_3 60 | ||
69 | |||
70 | #define HIGH 1 | ||
71 | #define LOW 1 | ||
72 | |||
73 | /* | ||
74 | *omap GPIO number | ||
75 | */ | ||
76 | #define AST_WAKEUP 167 | ||
77 | #define AST_RESET 126 | ||
78 | #define AST__rn_b 64 | ||
79 | |||
80 | /* | ||
81 | * NOTE THIS PIN IS USED AS WP for OMAP NAND | ||
82 | */ | ||
83 | #define AST_INT 62 | ||
84 | |||
85 | /* | ||
86 | * as an I/O, it is actually controlled by GPMC | ||
87 | */ | ||
88 | #define AST_CS 55 | ||
89 | |||
90 | |||
91 | /* | ||
92 | *GPMC prefetch engine | ||
93 | */ | ||
94 | |||
95 | /* register and its bit fields */ | ||
96 | #define GPMC_PREFETCH_CONFIG1 0x01E0 | ||
97 | |||
98 | /*32 bytes for 16 bit pnand mode*/ | ||
99 | #define PFE_THRESHOLD 31 | ||
100 | |||
101 | /* | ||
102 | * bit fields | ||
103 | * PF_ACCESSMODE - 0 - read mode, 1 - write mode | ||
104 | * PF_DMAMODE - 0 - default only intr line signal will be generated | ||
105 | * PF_SYNCHROMODE - default 0 - engin will start access as soon as | ||
106 | * ctrl re STARTENGINE is set | ||
107 | * PF_WAITPINSEL - FOR synchro mode selects WAIT pin whch edge | ||
108 | * will be monitored | ||
109 | * PF_EN_ENGINE - 1- ENABLES ENGINE, but it needs to be started after | ||
110 | * that C ctrl reg bit 0 | ||
111 | * PF_FIFO_THRESHOLD - FIFO threshold in number of BUS(8 or 16) words | ||
112 | * PF_WEIGHTED_PRIO - NUM of cycles granted to PFE if RND_ROBIN | ||
113 | * prioritization is enabled | ||
114 | * PF_ROUND_ROBIN - if enabled, gives priority to other CS, but | ||
115 | * reserves NUM of cycles for PFE's turn | ||
116 | * PF_ENGIN_CS_SEL - GPMC CS assotiated with PFE function | ||
117 | */ | ||
118 | #define PF_ACCESSMODE (0 << 0) | ||
119 | #define PF_DMAMODE (0 << 2) | ||
120 | #define PF_SYNCHROMODE (0 << 3) | ||
121 | #define PF_WAITPINSEL (0x0 << 4) | ||
122 | #define PF_EN_ENGINE (1 << 7) | ||
123 | #define PF_FIFO_THRESHOLD (PFE_THRESHOLD << 8) | ||
124 | #define PF_WEIGHTED_PRIO (0x0 << 16) | ||
125 | #define PF_ROUND_ROBIN (0 << 23) | ||
126 | #define PF_ENGIN_CS_SEL (AST_GPMC_CS << 24) | ||
127 | #define PF_EN_OPTIM_ACC (0 << 27) | ||
128 | #define PF_CYCLEOPTIM (0x0 << 28) | ||
129 | |||
130 | #define GPMC_PREFETCH_CONFIG1_VAL (PF_ACCESSMODE | \ | ||
131 | PF_DMAMODE | PF_SYNCHROMODE | \ | ||
132 | PF_WAITPINSEL | PF_EN_ENGINE | \ | ||
133 | PF_FIFO_THRESHOLD | PF_FIFO_THRESHOLD | \ | ||
134 | PF_WEIGHTED_PRIO | PF_ROUND_ROBIN | \ | ||
135 | PF_ENGIN_CS_SEL | PF_EN_OPTIM_ACC | \ | ||
136 | PF_CYCLEOPTIM) | ||
137 | |||
138 | /* register and its bit fields */ | ||
139 | #define GPMC_PREFETCH_CONFIG2 0x01E4 | ||
140 | /* | ||
141 | * bit fields | ||
142 | * 14 bit field NOTE this counts is also | ||
143 | * is in number of BUS(8 or 16) words | ||
144 | */ | ||
145 | #define PF_TRANSFERCOUNT (0x000) | ||
146 | |||
147 | |||
148 | /* register and its bit fields */ | ||
149 | #define GPMC_PREFETCH_CONTROL 0x01EC | ||
150 | /* | ||
151 | * bit fields , ONLY BIT 0 is implemented | ||
152 | * PFWE engin must be programmed with this bit = 0 | ||
153 | */ | ||
154 | #define PFPW_STARTENGINE (1 << 0) | ||
155 | |||
156 | /* register and its bit fields */ | ||
157 | #define GPMC_PREFETCH_STATUS 0x01F0 | ||
158 | |||
159 | /* */ | ||
160 | #define PFE_FIFO_THRESHOLD (1 << 16) | ||
161 | |||
162 | /* | ||
163 | * GPMC posted write/prefetch engine end | ||
164 | */ | ||
165 | |||
166 | |||
167 | /* | ||
168 | * chip select number on GPMC ( 0..7 ) | ||
169 | */ | ||
170 | #define AST_GPMC_CS 4 | ||
171 | |||
172 | /* | ||
173 | * not connected | ||
174 | */ | ||
175 | #define AST_DACK 00 | ||
176 | |||
177 | |||
178 | /* | ||
179 | * Physical address above the NAND flash | ||
180 | * we use CS For mapping in OMAP3430 RAM space use 0x0600 0000 | ||
181 | */ | ||
182 | #define CYAS_DEV_BASE_ADDR (0x20000000) | ||
183 | |||
184 | #define CYAS_DEV_MAX_ADDR (0xFF) | ||
185 | #define CYAS_DEV_ADDR_RANGE (CYAS_DEV_MAX_ADDR << 1) | ||
186 | |||
187 | #ifdef p_s_r_a_m_INTERFACE | ||
188 | /* in CRAM or PSRAM mode OMAP A1..An wires-> Astoria, there is no A0 line */ | ||
189 | #define CYAS_DEV_CALC_ADDR(cyas_addr) (cyas_addr << 1) | ||
190 | #define CYAS_DEV_CALC_EP_ADDR(ep) (ep << 1) | ||
191 | #else | ||
192 | /* | ||
193 | * For pNAND interface it depends on NAND emulation mode | ||
194 | * SBD/LBD etc we use NON-LNA_LBD mode, so it goes like this: | ||
195 | * forlbd <CMD><CA0,CA1,RA0,RA1,RA2> <CMD>, | ||
196 | * where CA1 address must have bits 2,3 = "11" | ||
197 | * ep is mapped into RA1 bits {4:0} | ||
198 | */ | ||
199 | #define CYAS_DEV_CALC_ADDR(cyas_addr) (cyas_addr | 0x0c00) | ||
200 | #define CYAS_DEV_CALC_EP_ADDR(ep) ep | ||
201 | #endif | ||
202 | |||
203 | /* | ||
204 | *OMAP3430 i/o access macros | ||
205 | */ | ||
206 | #define IORD32(addr) (*(volatile u32 *)(addr)) | ||
207 | #define IOWR32(addr, val) (*(volatile u32 *)(addr) = val) | ||
208 | |||
209 | #define IORD16(addr) (*(volatile u16 *)(addr)) | ||
210 | #define IOWR16(addr, val) (*(volatile u16 *)(addr) = val) | ||
211 | |||
212 | #define IORD8(addr) (*(volatile u8 *)(addr)) | ||
213 | #define IOWR8(addr, val) (*(volatile u8 *)(addr) = val) | ||
214 | |||
215 | /* | ||
216 | * local defines for accessing to OMAP GPIO *** | ||
217 | */ | ||
218 | #define CTLPADCONF_BASE_ADDR 0x48002000 | ||
219 | #define CTLPADCONF_SIZE 0x1000 | ||
220 | |||
221 | #define GPIO1_BASE_ADDR 0x48310000 | ||
222 | #define GPIO2_BASE_ADDR 0x49050000 | ||
223 | #define GPIO3_BASE_ADDR 0x49052000 | ||
224 | #define GPIO4_BASE_ADDR 0x49054000 | ||
225 | #define GPIO5_BASE_ADDR 0x49056000 | ||
226 | #define GPIO6_BASE_ADDR 0x49058000 | ||
227 | #define GPIO_SPACE_SIZE 0x1000 | ||
228 | |||
229 | |||
230 | /* | ||
231 | * OMAP3430 GPMC timing for pNAND interface | ||
232 | */ | ||
233 | #define GPMC_BASE 0x6E000000 | ||
234 | #define GPMC_REGION_SIZE 0x1000 | ||
235 | #define GPMC_CONFIG_REG (0x50) | ||
236 | |||
237 | /* | ||
238 | * bit 0 in the GPMC_CONFIG_REG | ||
239 | */ | ||
240 | #define NAND_FORCE_POSTED_WRITE_B 1 | ||
241 | |||
242 | /* | ||
243 | * WAIT2STATUS, must be (1 << 10) | ||
244 | */ | ||
245 | #define AS_WAIT_PIN_MASK (1 << 10) | ||
246 | |||
247 | |||
248 | /* | ||
249 | * GPMC_CONFIG(reg number [1..7] [for chip sel CS[0..7]) | ||
250 | */ | ||
251 | #define GPMC_CFG_REG(N, CS) ((0x60 + (4*(N-1))) + (0x30*CS)) | ||
252 | |||
253 | /* | ||
254 | *gpmc nand registers for CS4 | ||
255 | */ | ||
256 | #define AST_GPMC_NAND_CMD (0x7c + (0x30*AST_GPMC_CS)) | ||
257 | #define AST_GPMC_NAND_ADDR (0x80 + (0x30*AST_GPMC_CS)) | ||
258 | #define AST_GPMC_NAND_DATA (0x84 + (0x30*AST_GPMC_CS)) | ||
259 | |||
260 | #define GPMC_STAT_REG (0x54) | ||
261 | #define GPMC_ERR_TYPE (0x48) | ||
262 | |||
263 | /* | ||
264 | * we get "gpmc_base" from kernel | ||
265 | */ | ||
266 | #define GPMC_VMA(offset) (gpmc_base + offset) | ||
267 | |||
268 | /* | ||
269 | * GPMC CS space VMA start address | ||
270 | */ | ||
271 | #define GPMC_CS_VMA(offset) (gpmc_data_vma + offset) | ||
272 | |||
273 | /* | ||
274 | * PAD_CFG mux space VMA | ||
275 | */ | ||
276 | #define PADCFG_VMA(offset) (iomux_vma + offset) | ||
277 | |||
278 | /* | ||
279 | * CONFIG1: by default, sngle access, async r/w RD_MULTIPLE[30] | ||
280 | * WR_MULTIPLE[28]; GPMC_FCL_DIV[1:0] | ||
281 | */ | ||
282 | #define GPMC_FCLK_DIV ((0) << 0) | ||
283 | |||
284 | /* | ||
285 | * ADDITIONAL DIVIDER FOR ALL TIMING PARAMS | ||
286 | */ | ||
287 | #define TIME_GRAN_SCALE ((0) << 4) | ||
288 | |||
289 | /* | ||
290 | * for use by gpmc_set_timings api, measured in ns, not clocks | ||
291 | */ | ||
292 | #define WB_GPMC_BUSCYC_t (7 * 6) | ||
293 | #define WB_GPMC_CS_t_o_n (0) | ||
294 | #define WB_GPMC_ADV_t_o_n (0) | ||
295 | #define WB_GPMC_OE_t_o_n (0) | ||
296 | #define WB_GPMC_OE_t_o_f_f (5 * 6) | ||
297 | #define WB_GPMC_WE_t_o_n (1 * 6) | ||
298 | #define WB_GPMC_WE_t_o_f_f (5 * 6) | ||
299 | #define WB_GPMC_RDS_ADJ (2 * 6) | ||
300 | #define WB_GPMC_RD_t_a_c_c (WB_GPMC_OE_t_o_f_f + WB_GPMC_RDS_ADJ) | ||
301 | #define WB_GPMC_WR_t_a_c_c (WB_GPMC_BUSCYC_t) | ||
302 | |||
303 | #define DIR_OUT 0 | ||
304 | #define DIR_INP 1 | ||
305 | #define DRV_HI 1 | ||
306 | #define DRV_LO 0 | ||
307 | |||
308 | /* | ||
309 | * GPMC_CONFIG7[cs] register bit fields | ||
310 | * AS_CS_MASK - 3 bit mask for A26,A25,A24, | ||
311 | * AS_CS_BADDR - 6 BIT VALUE A29 ...A24 | ||
312 | * CSVALID_B - CSVALID bit on GPMC_CONFIG7[cs] register | ||
313 | */ | ||
314 | #define AS_CS_MASK (0X7 << 8) | ||
315 | #define AS_CS_BADDR 0x02 | ||
316 | #define CSVALID_B (1 << 6) | ||
317 | |||
318 | /* | ||
319 | * DEFINE OMAP34XX GPIO OFFSETS (should have been defined in kernel /arch | ||
320 | * these are offsets from the BASE_ADDRESS of the GPIO BLOCK | ||
321 | */ | ||
322 | #define GPIO_REVISION 0x000 | ||
323 | #define GPIO_SYSCONFIG 0x010 | ||
324 | #define GPIO_SYSSTATUS1 0x014 | ||
325 | #define GPIO_IRQSTATUS1 0x018 | ||
326 | #define GPIO_IRQENABLE1 0x01C | ||
327 | #define GPIO_IRQSTATUS2 0x028 | ||
328 | #define GPIO_CTRL 0x030 | ||
329 | #define GPIO_OE 0x034 | ||
330 | #define GPIO_DATA_IN 0x038 | ||
331 | #define GPIO_DATA_OUT 0x03C | ||
332 | #define GPIO_LEVELDETECT0 0x040 | ||
333 | #define GPIO_LEVELDETECT1 0x044 | ||
334 | #define GPIO_RISINGDETECT 0x048 | ||
335 | #define GPIO_FALLINGDETECT 0x04c | ||
336 | #define GPIO_CLEAR_DATAOUT 0x090 | ||
337 | #define GPIO_SET_DATAOUT 0x094 | ||
338 | |||
339 | typedef struct { | ||
340 | char *name; | ||
341 | u32 phy_addr; | ||
342 | u32 virt_addr; | ||
343 | u32 size; | ||
344 | } io2vma_tab_t; | ||
345 | |||
346 | /* | ||
347 | * GPIO phy to translation VMA table | ||
348 | */ | ||
349 | static io2vma_tab_t gpio_vma_tab[6] = { | ||
350 | {"GPIO1_BASE_ADDR", GPIO1_BASE_ADDR , 0 , GPIO_SPACE_SIZE}, | ||
351 | {"GPIO2_BASE_ADDR", GPIO2_BASE_ADDR , 0 , GPIO_SPACE_SIZE}, | ||
352 | {"GPIO3_BASE_ADDR", GPIO3_BASE_ADDR , 0 , GPIO_SPACE_SIZE}, | ||
353 | {"GPIO4_BASE_ADDR", GPIO4_BASE_ADDR , 0 , GPIO_SPACE_SIZE}, | ||
354 | {"GPIO5_BASE_ADDR", GPIO5_BASE_ADDR , 0 , GPIO_SPACE_SIZE}, | ||
355 | {"GPIO6_BASE_ADDR", GPIO6_BASE_ADDR , 0 , GPIO_SPACE_SIZE} | ||
356 | }; | ||
357 | /* | ||
358 | * name - USER signal name assigned to the pin ( for printks) | ||
359 | * mux_func - enum index NAME for the pad_cfg function | ||
360 | * pin_num - pin_number if mux_func is GPIO, if not a GPIO it is -1 | ||
361 | * mux_ptr - pointer to the corresponding pad_cfg_reg | ||
362 | * (used for pad release ) | ||
363 | * mux_save - preserve here original PAD_CNF value for this | ||
364 | * pin (used for pad release) | ||
365 | * dir - if GPIO: 0 - OUT , 1 - IN | ||
366 | * dir_save - save original pin direction | ||
367 | * drv - initial drive level "0" or "1" | ||
368 | * drv_save - save original pin drive level | ||
369 | * valid - 1 if successfuly configured | ||
370 | */ | ||
371 | typedef struct { | ||
372 | char *name; | ||
373 | u32 mux_func; | ||
374 | int pin_num; | ||
375 | u16 *mux_ptr; | ||
376 | u16 mux_save; | ||
377 | u8 dir; | ||
378 | u8 dir_save; | ||
379 | u8 drv; | ||
380 | u8 drv_save; | ||
381 | u8 valid; | ||
382 | } user_pad_cfg_t; | ||
383 | |||
384 | /* | ||
385 | * need to ensure that enums are in sync with the | ||
386 | * omap_mux_pin_cfg table, these enums designate | ||
387 | * functions that OMAP pads can be configured to | ||
388 | */ | ||
389 | enum { | ||
390 | B23_OMAP3430_GPIO_167, | ||
391 | D23_OMAP3430_GPIO_126, | ||
392 | H1_OMAP3430_GPIO_62, | ||
393 | H1_OMAP3430_GPMC_n_w_p, | ||
394 | T8_OMAP3430_GPMC_n_c_s4, | ||
395 | T8_OMAP3430_GPIO_55, | ||
396 | R25_OMAP3430_GPIO_156, | ||
397 | R27_OMAP3430_GPIO_128, | ||
398 | K8_OMAP3430_GPIO_64, | ||
399 | K8_GPMC_WAIT2, | ||
400 | G3_OMAP3430_GPIO_60, | ||
401 | G3_OMAP3430_n_b_e0_CLE, | ||
402 | C6_GPMC_WAIT3, | ||
403 | J1_OMAP3430_GPIO_61, | ||
404 | C6_OMAP3430_GPIO_65, | ||
405 | |||
406 | END_OF_TABLE | ||
407 | }; | ||
408 | |||
409 | /* | ||
410 | * number of GPIOS we plan to grab | ||
411 | */ | ||
412 | #define GPIO_SLOTS 8 | ||
413 | |||
414 | /* | ||
415 | * user_pads_init() reads(and saves) from/to this table | ||
416 | * used in conjunction with omap_3430_mux_t table in .h file | ||
417 | * because the way it's done in the kernel code | ||
418 | * TODO: implement restore of the the original cfg and i/o regs | ||
419 | */ | ||
420 | |||
421 | static user_pad_cfg_t user_pad_cfg[] = { | ||
422 | /* | ||
423 | * name,pad_func,pin_num, mux_ptr, mux_sav, dir, | ||
424 | * dir_sav, drv, drv_save, valid | ||
425 | */ | ||
426 | {"AST_WAKEUP", B23_OMAP3430_GPIO_167, 167, NULL, 0, | ||
427 | DIR_OUT, 0, DRV_HI, 0, 0}, | ||
428 | {"AST_RESET", D23_OMAP3430_GPIO_126, 126, NULL, 0, | ||
429 | DIR_OUT, 0, DRV_HI, 0, 0}, | ||
430 | {"AST__rn_b", K8_GPMC_WAIT2, 64, NULL, 0, | ||
431 | DIR_INP, 0, 0, 0, 0}, | ||
432 | {"AST_INTR", H1_OMAP3430_GPIO_62, 62, NULL, 0, | ||
433 | DIR_INP, 0, DRV_HI, 0, 0}, | ||
434 | {"AST_CS", T8_OMAP3430_GPMC_n_c_s4, 55, NULL, 0, | ||
435 | DIR_OUT, 0, DRV_HI, 0, 0}, | ||
436 | {"LED_0", R25_OMAP3430_GPIO_156, 156, NULL, 0, | ||
437 | DIR_OUT, 0, DRV_LO, 0, 0}, | ||
438 | {"LED_1", R27_OMAP3430_GPIO_128, 128, NULL, 0, | ||
439 | DIR_OUT, 0, DRV_LO, 0, 0}, | ||
440 | {"AST_CLE", G3_OMAP3430_n_b_e0_CLE , 60, NULL, 0, | ||
441 | DIR_OUT, 0, DRV_LO, 0, 0}, | ||
442 | /* | ||
443 | * Z terminator, must always be present | ||
444 | * for sanity check, don't remove | ||
445 | */ | ||
446 | {NULL} | ||
447 | }; | ||
448 | |||
449 | #define GPIO_BANK(pin) (pin >> 5) | ||
450 | #define REG_WIDTH 32 | ||
451 | #define GPIO_REG_VMA(pin_num, offset) \ | ||
452 | (gpio_vma_tab[GPIO_BANK(pin_num)].virt_addr + offset) | ||
453 | |||
454 | /* | ||
455 | * OMAP GPIO_REG 32 BIT MASK for a bit or | ||
456 | * flag in gpio_No[0..191] apply it to a 32 bit | ||
457 | * location to set clear or check on a corresponding | ||
458 | * gpio bit or flag | ||
459 | */ | ||
460 | #define GPIO_REG_MASK(pin_num) (1 << \ | ||
461 | (pin_num - (GPIO_BANK(pin_num) * REG_WIDTH))) | ||
462 | |||
463 | /* | ||
464 | * OMAP GPIO registers bitwise access macros | ||
465 | */ | ||
466 | |||
467 | #define OMAP_GPIO_BIT(pin_num, reg) \ | ||
468 | ((*((u32 *)GPIO_REG_VMA(pin_num, reg)) \ | ||
469 | & GPIO_REG_MASK(pin_num)) ? 1 : 0) | ||
470 | |||
471 | #define RD_OMAP_GPIO_BIT(pin_num, v) OMAP_GPIO_BIT(pin_num, reg) | ||
472 | |||
473 | /* | ||
474 | *these are superfast set/clr bitbang macro, 48ns cyc tyme | ||
475 | */ | ||
476 | #define OMAP_SET_GPIO(pin_num) \ | ||
477 | (*(u32 *)GPIO_REG_VMA(pin_num, GPIO_SET_DATAOUT) \ | ||
478 | = GPIO_REG_MASK(pin_num)) | ||
479 | #define OMAP_CLR_GPIO(pin_num) \ | ||
480 | (*(u32 *)GPIO_REG_VMA(pin_num, GPIO_CLEAR_DATAOUT) \ | ||
481 | = GPIO_REG_MASK(pin_num)) | ||
482 | |||
483 | #define WR_OMAP_GPIO_BIT(pin_num, v) \ | ||
484 | (v ? (*(u32 *)GPIO_REG_VMA(pin_num, \ | ||
485 | GPIO_SET_DATAOUT) = GPIO_REG_MASK(pin_num)) \ | ||
486 | : (*(u32 *)GPIO_REG_VMA(pin_num, \ | ||
487 | GPIO_CLEAR_DATAOUT) = GPIO_REG_MASK(pin_num))) | ||
488 | |||
489 | /* | ||
490 | * Note this pin cfg mimicks similar implementation | ||
491 | * in linux kernel, which unfortunately doesn't allow | ||
492 | * us to dynamically insert new custom GPIO mux | ||
493 | * configurations all REG definitions used in this | ||
494 | * applications. to add a new pad_cfg function, insert | ||
495 | * a new ENUM and new pin_cfg entry in omap_mux_pin_cfg[] | ||
496 | * table below | ||
497 | * | ||
498 | * offset - note this is a word offset since the | ||
499 | * SCM regs are 16 bit packed in one 32 bit word | ||
500 | * mux_val - just enough to describe pins used | ||
501 | */ | ||
502 | typedef struct { | ||
503 | char *name; | ||
504 | u16 offset; | ||
505 | u16 mux_val; | ||
506 | } omap_3430_mux_t; | ||
507 | |||
508 | /* | ||
509 | * "OUTIN" is configuration when DATA reg drives the | ||
510 | * pin but the level at the pin can be sensed | ||
511 | */ | ||
512 | #define PAD_AS_OUTIN (OMAP34XX_MUX_MODE4 | \ | ||
513 | OMAP34XX_PIN_OUTPUT | OMAP34XX_PIN_INPUT) | ||
514 | |||
515 | omap_3430_mux_t omap_mux_pin_cfg[] = { | ||
516 | /* | ||
517 | * B23_OMAP3430_GPIO_167 - GPIO func to PAD 167 WB wakeup | ||
518 | * D23_OMAP3430_GPIO_126 - drive GPIO_126 ( AST RESET) | ||
519 | * H1_OMAP3430_GPIO_62 - need a pullup on this pin | ||
520 | * H1_OMAP3430_GPMC_n_w_p - GPMC NAND CTRL n_w_p out | ||
521 | * T8_OMAP3430_GPMC_n_c_s4" - T8 is controlled b_y GPMC NAND ctrl | ||
522 | * R25_OMAP3430_GPIO_156 - OMAPZOOM drive LED_0 | ||
523 | * R27_OMAP3430_GPIO_128 - OMAPZOOM drive LED_1 | ||
524 | * K8_OMAP3430_GPIO_64 - OMAPZOOM drive LED_2 | ||
525 | * K8_GPMC_WAIT2 - GPMC WAIT2 function on PAD K8 | ||
526 | * G3_OMAP3430_GPIO_60 - OMAPZOOM drive LED_3 | ||
527 | * G3_OMAP3430_n_b_e0_CLE -GPMC NAND ctrl CLE signal | ||
528 | */ | ||
529 | |||
530 | {"B23_OMAP3430_GPIO_167", 0x0130, (OMAP34XX_MUX_MODE4)}, | ||
531 | {"D23_OMAP3430_GPIO_126", 0x0132, (OMAP34XX_MUX_MODE4)}, | ||
532 | {"H1_OMAP3430_GPIO_62", 0x00CA, (OMAP34XX_MUX_MODE4 | | ||
533 | OMAP3_INPUT_EN | OMAP34XX_PIN_INPUT_PULLUP) }, | ||
534 | {"H1_OMAP3430_GPMC_n_w_p", 0x00CA, (OMAP34XX_MUX_MODE0)}, | ||
535 | {"T8_OMAP3430_GPMC_n_c_s4", 0x00B6, (OMAP34XX_MUX_MODE0) }, | ||
536 | {"T8_OMAP3430_GPIO_55", 0x00B6, (OMAP34XX_MUX_MODE4) }, | ||
537 | {"R25_OMAP3430_GPIO_156", 0x018C, (OMAP34XX_MUX_MODE4) }, | ||
538 | {"R27_OMAP3430_GPIO_128", 0x0154, (OMAP34XX_MUX_MODE4) }, | ||
539 | {"K8_OMAP3430_GPIO_64", 0x00d0, (OMAP34XX_MUX_MODE4) }, | ||
540 | {"K8_GPMC_WAIT2", 0x00d0, (OMAP34XX_MUX_MODE0) }, | ||
541 | {"G3_OMAP3430_GPIO_60", 0x00C6, (OMAP34XX_MUX_MODE4 | | ||
542 | OMAP3_INPUT_EN)}, | ||
543 | {"G3_OMAP3430_n_b_e0_CLE", 0x00C6, (OMAP34XX_MUX_MODE0)}, | ||
544 | {"C6_GPMC_WAIT3", 0x00d2, (OMAP34XX_MUX_MODE0)}, | ||
545 | {"C6_OMAP3430_GPIO_65", 0x00d2, (OMAP34XX_MUX_MODE4 | | ||
546 | OMAP3_INPUT_EN)}, | ||
547 | {"J1_OMAP3430_GPIO_61", 0x00C8, (OMAP34XX_MUX_MODE4 | | ||
548 | OMAP3_INPUT_EN | OMAP34XX_PIN_INPUT_PULLUP)}, | ||
549 | /* | ||
550 | * don't remove, used for sanity check. | ||
551 | */ | ||
552 | {"END_OF_TABLE"} | ||
553 | }; | ||
554 | |||
555 | |||
556 | #endif /* _INCLUDED_CYASMEMMAP_H_ */ | ||
557 | |||
558 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasomapdev_kernel.h b/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasomapdev_kernel.h deleted file mode 100644 index 5a64bb6bb053..000000000000 --- a/drivers/staging/westbridge/astoria/arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyasomapdev_kernel.h +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* Cypress Antioch OMAP KERNEL file (cyanomapdev_kernel.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef __CY_AS_OMAP_DEV_KERNEL_H__ | ||
23 | #define __CY_AS_OMAP_DEV_KERNEL_H__ | ||
24 | |||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/completion.h> | ||
29 | |||
30 | /* include does not seem to work | ||
31 | * moving for patch submission | ||
32 | #include <mach/gpmc.h> | ||
33 | */ | ||
34 | #include <linux/../../arch/arm/plat-omap/include/plat/gpmc.h> | ||
35 | |||
36 | /* | ||
37 | * Constants | ||
38 | */ | ||
39 | #define CY_AS_OMAP_KERNEL_HAL_SIG (0x1441) | ||
40 | |||
41 | |||
42 | /* | ||
43 | * Data structures | ||
44 | */ | ||
45 | typedef struct cy_as_omap_dev_kernel { | ||
46 | /* This is the signature for this data structure */ | ||
47 | unsigned int m_sig; | ||
48 | |||
49 | /* Address base of Antioch Device */ | ||
50 | void *m_addr_base; | ||
51 | |||
52 | /* This is a pointer to the next Antioch device in the system */ | ||
53 | struct cy_as_omap_dev_kernel *m_next_p; | ||
54 | |||
55 | /* This is for thread sync */ | ||
56 | struct completion thread_complete; | ||
57 | |||
58 | /* This is for thread to wait for interrupts */ | ||
59 | cy_as_hal_sleep_channel thread_sc; | ||
60 | |||
61 | /* This is for thread to exit upon StopOmapKernel */ | ||
62 | int thread_flag; /* set 1 to exit */ | ||
63 | |||
64 | int dma_ch; | ||
65 | |||
66 | /* This is for dma sync */ | ||
67 | struct completion dma_complete; | ||
68 | } cy_as_omap_dev_kernel; | ||
69 | |||
70 | #endif | ||
71 | |||
72 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/block/Kconfig b/drivers/staging/westbridge/astoria/block/Kconfig deleted file mode 100644 index 851bf96a7b87..000000000000 --- a/drivers/staging/westbridge/astoria/block/Kconfig +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # | ||
2 | # West Bridge block driver configuration | ||
3 | # | ||
4 | |||
5 | config WESTBRIDGE_BLOCK_DRIVER | ||
6 | tristate "West Bridge Block Driver" | ||
7 | help | ||
8 | Include the West Bridge based block driver | ||
9 | |||
diff --git a/drivers/staging/westbridge/astoria/block/Makefile b/drivers/staging/westbridge/astoria/block/Makefile deleted file mode 100644 index 4a45dd0861e7..000000000000 --- a/drivers/staging/westbridge/astoria/block/Makefile +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the kernel westbridge block driver | ||
3 | # | ||
4 | |||
5 | ifneq ($(CONFIG_WESTBRIDGE_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DWESTBRIDGE_NDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_WESTBRIDGE_BLOCK_DRIVER) += cyasblkdev.o | ||
10 | cyasblkdev-y := cyasblkdev_block.o cyasblkdev_queue.o | ||
11 | |||
diff --git a/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c b/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c deleted file mode 100644 index 87452bde7c93..000000000000 --- a/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c +++ /dev/null | |||
@@ -1,1631 +0,0 @@ | |||
1 | /* cyanblkdev_block.c - West Bridge Linux Block Driver source file | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Linux block driver implementation for Cypress West Bridge. | ||
24 | * Based on the mmc block driver implementation by Andrew Christian | ||
25 | * for the linux 2.6.26 kernel. | ||
26 | * mmc_block.c, 5/28/2002 | ||
27 | */ | ||
28 | |||
29 | /* | ||
30 | * Block driver for media (i.e., flash cards) | ||
31 | * | ||
32 | * Copyright 2002 Hewlett-Packard Company | ||
33 | * | ||
34 | * Use consistent with the GNU GPL is permitted, | ||
35 | * provided that this copyright notice is | ||
36 | * preserved in its entirety in all copies and derived works. | ||
37 | * | ||
38 | * HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED, | ||
39 | * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS | ||
40 | * FITNESS FOR ANY PARTICULAR PURPOSE. | ||
41 | * | ||
42 | * Many thanks to Alessandro Rubini and Jonathan Corbet! | ||
43 | * | ||
44 | * Author: Andrew Christian | ||
45 | * 28 May 2002 | ||
46 | */ | ||
47 | |||
48 | #include <linux/moduleparam.h> | ||
49 | #include <linux/module.h> | ||
50 | #include <linux/init.h> | ||
51 | #include <linux/slab.h> | ||
52 | #include <linux/sched.h> | ||
53 | #include <linux/kernel.h> | ||
54 | #include <linux/fs.h> | ||
55 | #include <linux/errno.h> | ||
56 | #include <linux/hdreg.h> | ||
57 | #include <linux/kdev_t.h> | ||
58 | #include <linux/blkdev.h> | ||
59 | |||
60 | #include <asm/system.h> | ||
61 | #include <linux/uaccess.h> | ||
62 | |||
63 | #include <linux/scatterlist.h> | ||
64 | #include <linux/time.h> | ||
65 | #include <linux/signal.h> | ||
66 | #include <linux/delay.h> | ||
67 | |||
68 | #include "cyasblkdev_queue.h" | ||
69 | |||
70 | #define CYASBLKDEV_SHIFT 0 /* Only a single partition. */ | ||
71 | #define CYASBLKDEV_MAX_REQ_LEN (256) | ||
72 | #define CYASBLKDEV_NUM_MINORS (256 >> CYASBLKDEV_SHIFT) | ||
73 | #define CY_AS_TEST_NUM_BLOCKS (64) | ||
74 | #define CYASBLKDEV_MINOR_0 1 | ||
75 | #define CYASBLKDEV_MINOR_1 2 | ||
76 | #define CYASBLKDEV_MINOR_2 3 | ||
77 | |||
78 | static int major; | ||
79 | module_param(major, int, 0444); | ||
80 | MODULE_PARM_DESC(major, | ||
81 | "specify the major device number for cyasblkdev block driver"); | ||
82 | |||
83 | /* parameters passed from the user space */ | ||
84 | static int vfat_search; | ||
85 | module_param(vfat_search, bool, S_IRUGO | S_IWUSR); | ||
86 | MODULE_PARM_DESC(vfat_search, | ||
87 | "dynamically find the location of the first sector"); | ||
88 | |||
89 | static int private_partition_bus = -1; | ||
90 | module_param(private_partition_bus, int, S_IRUGO | S_IWUSR); | ||
91 | MODULE_PARM_DESC(private_partition_bus, | ||
92 | "bus number for private partition"); | ||
93 | |||
94 | static int private_partition_size = -1; | ||
95 | module_param(private_partition_size, int, S_IRUGO | S_IWUSR); | ||
96 | MODULE_PARM_DESC(private_partition_size, | ||
97 | "size of the private partition"); | ||
98 | |||
99 | /* | ||
100 | * There is one cyasblkdev_blk_data per slot. | ||
101 | */ | ||
102 | struct cyasblkdev_blk_data { | ||
103 | spinlock_t lock; | ||
104 | int media_count[2]; | ||
105 | const struct block_device_operations *blkops; | ||
106 | unsigned int usage; | ||
107 | unsigned int suspended; | ||
108 | |||
109 | /* handle to the west bridge device this handle, typdefed as *void */ | ||
110 | cy_as_device_handle dev_handle; | ||
111 | |||
112 | /* our custom structure, in addition to request queue, | ||
113 | * adds lock & semaphore items*/ | ||
114 | struct cyasblkdev_queue queue; | ||
115 | |||
116 | /* 16 entries is enough given max request size | ||
117 | * 16 * 4K (64 K per request)*/ | ||
118 | struct scatterlist sg[16]; | ||
119 | |||
120 | /* non-zero enables printk of executed reqests */ | ||
121 | unsigned int dbgprn_flags; | ||
122 | |||
123 | /*gen_disk for private, system disk */ | ||
124 | struct gendisk *system_disk; | ||
125 | cy_as_media_type system_disk_type; | ||
126 | cy_bool system_disk_read_only; | ||
127 | cy_bool system_disk_bus_num; | ||
128 | |||
129 | /* sector size for the medium */ | ||
130 | unsigned int system_disk_blk_size; | ||
131 | unsigned int system_disk_first_sector; | ||
132 | unsigned int system_disk_unit_no; | ||
133 | |||
134 | /*gen_disk for bus 0 */ | ||
135 | struct gendisk *user_disk_0; | ||
136 | cy_as_media_type user_disk_0_type; | ||
137 | cy_bool user_disk_0_read_only; | ||
138 | cy_bool user_disk_0_bus_num; | ||
139 | |||
140 | /* sector size for the medium */ | ||
141 | unsigned int user_disk_0_blk_size; | ||
142 | unsigned int user_disk_0_first_sector; | ||
143 | unsigned int user_disk_0_unit_no; | ||
144 | |||
145 | /*gen_disk for bus 1 */ | ||
146 | struct gendisk *user_disk_1; | ||
147 | cy_as_media_type user_disk_1_type; | ||
148 | cy_bool user_disk_1_read_only; | ||
149 | cy_bool user_disk_1_bus_num; | ||
150 | |||
151 | /* sector size for the medium */ | ||
152 | unsigned int user_disk_1_blk_size; | ||
153 | unsigned int user_disk_1_first_sector; | ||
154 | unsigned int user_disk_1_unit_no; | ||
155 | }; | ||
156 | |||
157 | /* pointer to west bridge block data device superstructure */ | ||
158 | static struct cyasblkdev_blk_data *gl_bd; | ||
159 | |||
160 | static DEFINE_SEMAPHORE(open_lock); | ||
161 | |||
162 | /* local forwardd declarationss */ | ||
163 | static cy_as_device_handle *cyas_dev_handle; | ||
164 | static void cyasblkdev_blk_deinit(struct cyasblkdev_blk_data *bd); | ||
165 | |||
166 | /*change debug print options */ | ||
167 | #define DBGPRN_RD_RQ (1 < 0) | ||
168 | #define DBGPRN_WR_RQ (1 < 1) | ||
169 | #define DBGPRN_RQ_END (1 < 2) | ||
170 | |||
171 | int blkdev_ctl_dbgprn( | ||
172 | int prn_flags | ||
173 | ) | ||
174 | { | ||
175 | int cur_options = gl_bd->dbgprn_flags; | ||
176 | |||
177 | DBGPRN_FUNC_NAME; | ||
178 | |||
179 | /* set new debug print options */ | ||
180 | gl_bd->dbgprn_flags = prn_flags; | ||
181 | |||
182 | /* return previous */ | ||
183 | return cur_options; | ||
184 | } | ||
185 | EXPORT_SYMBOL(blkdev_ctl_dbgprn); | ||
186 | |||
187 | static struct cyasblkdev_blk_data *cyasblkdev_blk_get( | ||
188 | struct gendisk *disk | ||
189 | ) | ||
190 | { | ||
191 | struct cyasblkdev_blk_data *bd; | ||
192 | |||
193 | DBGPRN_FUNC_NAME; | ||
194 | |||
195 | down(&open_lock); | ||
196 | |||
197 | bd = disk->private_data; | ||
198 | |||
199 | if (bd && (bd->usage == 0)) | ||
200 | bd = NULL; | ||
201 | |||
202 | if (bd) { | ||
203 | bd->usage++; | ||
204 | #ifndef NBDEBUG | ||
205 | cy_as_hal_print_message( | ||
206 | "cyasblkdev_blk_get: usage = %d\n", bd->usage); | ||
207 | #endif | ||
208 | } | ||
209 | up(&open_lock); | ||
210 | |||
211 | return bd; | ||
212 | } | ||
213 | |||
214 | static void cyasblkdev_blk_put( | ||
215 | struct cyasblkdev_blk_data *bd | ||
216 | ) | ||
217 | { | ||
218 | DBGPRN_FUNC_NAME; | ||
219 | |||
220 | down(&open_lock); | ||
221 | |||
222 | if (bd) { | ||
223 | bd->usage--; | ||
224 | #ifndef WESTBRIDGE_NDEBUG | ||
225 | cy_as_hal_print_message( | ||
226 | " cyasblkdev_blk_put , bd->usage= %d\n", bd->usage); | ||
227 | #endif | ||
228 | } else { | ||
229 | #ifndef WESTBRIDGE_NDEBUG | ||
230 | cy_as_hal_print_message( | ||
231 | "cyasblkdev: blk_put(bd) on bd = NULL!: usage = %d\n", | ||
232 | bd->usage); | ||
233 | #endif | ||
234 | up(&open_lock); | ||
235 | return; | ||
236 | } | ||
237 | |||
238 | if (bd->usage == 0) { | ||
239 | put_disk(bd->user_disk_0); | ||
240 | put_disk(bd->user_disk_1); | ||
241 | put_disk(bd->system_disk); | ||
242 | cyasblkdev_cleanup_queue(&bd->queue); | ||
243 | |||
244 | if (CY_AS_ERROR_SUCCESS != | ||
245 | cy_as_storage_release(bd->dev_handle, 0, 0, 0, 0)) { | ||
246 | #ifndef WESTBRIDGE_NDEBUG | ||
247 | cy_as_hal_print_message( | ||
248 | "cyasblkdev: cannot release bus 0\n"); | ||
249 | #endif | ||
250 | } | ||
251 | |||
252 | if (CY_AS_ERROR_SUCCESS != | ||
253 | cy_as_storage_release(bd->dev_handle, 1, 0, 0, 0)) { | ||
254 | #ifndef WESTBRIDGE_NDEBUG | ||
255 | cy_as_hal_print_message( | ||
256 | "cyasblkdev: cannot release bus 1\n"); | ||
257 | #endif | ||
258 | } | ||
259 | |||
260 | if (CY_AS_ERROR_SUCCESS != | ||
261 | cy_as_storage_stop(bd->dev_handle, 0, 0)) { | ||
262 | #ifndef WESTBRIDGE_NDEBUG | ||
263 | cy_as_hal_print_message( | ||
264 | "cyasblkdev: cannot stop storage stack\n"); | ||
265 | #endif | ||
266 | } | ||
267 | |||
268 | #ifdef __CY_ASTORIA_SCM_KERNEL_HAL__ | ||
269 | /* If the SCM Kernel HAL is being used, disable the use | ||
270 | * of scatter/gather lists at the end of block driver usage. | ||
271 | */ | ||
272 | cy_as_hal_disable_scatter_list(cyasdevice_gethaltag()); | ||
273 | #endif | ||
274 | |||
275 | /*ptr to global struct cyasblkdev_blk_data */ | ||
276 | gl_bd = NULL; | ||
277 | kfree(bd); | ||
278 | } | ||
279 | |||
280 | #ifndef WESTBRIDGE_NDEBUG | ||
281 | cy_as_hal_print_message( | ||
282 | "cyasblkdev (blk_put): usage = %d\n", | ||
283 | bd->usage); | ||
284 | #endif | ||
285 | up(&open_lock); | ||
286 | } | ||
287 | |||
288 | static int cyasblkdev_blk_open( | ||
289 | struct block_device *bdev, | ||
290 | fmode_t mode | ||
291 | ) | ||
292 | { | ||
293 | struct cyasblkdev_blk_data *bd = cyasblkdev_blk_get(bdev->bd_disk); | ||
294 | int ret = -ENXIO; | ||
295 | |||
296 | DBGPRN_FUNC_NAME; | ||
297 | |||
298 | if (bd) { | ||
299 | if (bd->usage == 2) | ||
300 | check_disk_change(bdev); | ||
301 | |||
302 | ret = 0; | ||
303 | |||
304 | if (bdev->bd_disk == bd->user_disk_0) { | ||
305 | if ((mode & FMODE_WRITE) && bd->user_disk_0_read_only) { | ||
306 | #ifndef WESTBRIDGE_NDEBUG | ||
307 | cy_as_hal_print_message( | ||
308 | "device marked as readonly " | ||
309 | "and write requested\n"); | ||
310 | #endif | ||
311 | |||
312 | cyasblkdev_blk_put(bd); | ||
313 | ret = -EROFS; | ||
314 | } | ||
315 | } else if (bdev->bd_disk == bd->user_disk_1) { | ||
316 | if ((mode & FMODE_WRITE) && bd->user_disk_1_read_only) { | ||
317 | #ifndef WESTBRIDGE_NDEBUG | ||
318 | cy_as_hal_print_message( | ||
319 | "device marked as readonly " | ||
320 | "and write requested\n"); | ||
321 | #endif | ||
322 | |||
323 | cyasblkdev_blk_put(bd); | ||
324 | ret = -EROFS; | ||
325 | } | ||
326 | } else if (bdev->bd_disk == bd->system_disk) { | ||
327 | if ((mode & FMODE_WRITE) && bd->system_disk_read_only) { | ||
328 | #ifndef WESTBRIDGE_NDEBUG | ||
329 | cy_as_hal_print_message( | ||
330 | "device marked as readonly " | ||
331 | "and write requested\n"); | ||
332 | #endif | ||
333 | |||
334 | cyasblkdev_blk_put(bd); | ||
335 | ret = -EROFS; | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | |||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | static int cyasblkdev_blk_release( | ||
344 | struct gendisk *disk, | ||
345 | fmode_t mode | ||
346 | ) | ||
347 | { | ||
348 | struct cyasblkdev_blk_data *bd = disk->private_data; | ||
349 | |||
350 | DBGPRN_FUNC_NAME; | ||
351 | |||
352 | cyasblkdev_blk_put(bd); | ||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | static int cyasblkdev_blk_ioctl( | ||
357 | struct block_device *bdev, | ||
358 | fmode_t mode, | ||
359 | unsigned int cmd, | ||
360 | unsigned long arg | ||
361 | ) | ||
362 | { | ||
363 | DBGPRN_FUNC_NAME; | ||
364 | |||
365 | if (cmd == HDIO_GETGEO) { | ||
366 | /*for now we only process geometry IOCTL*/ | ||
367 | struct hd_geometry geo; | ||
368 | |||
369 | memset(&geo, 0, sizeof(struct hd_geometry)); | ||
370 | |||
371 | geo.cylinders = get_capacity(bdev->bd_disk) / (4 * 16); | ||
372 | geo.heads = 4; | ||
373 | geo.sectors = 16; | ||
374 | geo.start = get_start_sect(bdev); | ||
375 | |||
376 | /* copy to user space */ | ||
377 | return copy_to_user((void __user *)arg, &geo, sizeof(geo)) | ||
378 | ? -EFAULT : 0; | ||
379 | } | ||
380 | |||
381 | return -ENOTTY; | ||
382 | } | ||
383 | |||
384 | /* check_events block_device opp | ||
385 | * this one is called by kernel to confirm if the media really changed | ||
386 | * as we indicated by issuing check_disk_change() call */ | ||
387 | unsigned int cyasblkdev_check_events(struct gendisk *gd, unsigned int clearing) | ||
388 | { | ||
389 | struct cyasblkdev_blk_data *bd; | ||
390 | |||
391 | #ifndef WESTBRIDGE_NDEBUG | ||
392 | cy_as_hal_print_message("cyasblkdev_media_changed() is called\n"); | ||
393 | #endif | ||
394 | |||
395 | if (gd) | ||
396 | bd = gd->private_data; | ||
397 | else { | ||
398 | #ifndef WESTBRIDGE_NDEBUG | ||
399 | cy_as_hal_print_message( | ||
400 | "cyasblkdev_media_changed() is called, " | ||
401 | "but gd is null\n"); | ||
402 | #endif | ||
403 | } | ||
404 | |||
405 | /* return media change state - DISK_EVENT_MEDIA_CHANGE yes, 0 no */ | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | /* this one called by kernel to give us a chence | ||
410 | * to prep the new media before it starts to rescaning | ||
411 | * of the newlly inserted SD media */ | ||
412 | int cyasblkdev_revalidate_disk(struct gendisk *gd) | ||
413 | { | ||
414 | /*int (*revalidate_disk) (struct gendisk *); */ | ||
415 | |||
416 | #ifndef WESTBRIDGE_NDEBUG | ||
417 | if (gd) | ||
418 | cy_as_hal_print_message( | ||
419 | "cyasblkdev_revalidate_disk() is called, " | ||
420 | "(gl_bd->usage:%d)\n", gl_bd->usage); | ||
421 | #endif | ||
422 | |||
423 | /* 0 means ok, kern can go ahead with partition rescan */ | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | |||
428 | /*standard block device driver interface */ | ||
429 | static struct block_device_operations cyasblkdev_bdops = { | ||
430 | .open = cyasblkdev_blk_open, | ||
431 | .release = cyasblkdev_blk_release, | ||
432 | .ioctl = cyasblkdev_blk_ioctl, | ||
433 | /* .getgeo = cyasblkdev_blk_getgeo, */ | ||
434 | /* added to support media removal( real and simulated) media */ | ||
435 | .check_events = cyasblkdev_check_events, | ||
436 | /* added to support media removal( real and simulated) media */ | ||
437 | .revalidate_disk = cyasblkdev_revalidate_disk, | ||
438 | .owner = THIS_MODULE, | ||
439 | }; | ||
440 | |||
441 | /* west bridge block device prep request function */ | ||
442 | static int cyasblkdev_blk_prep_rq( | ||
443 | struct cyasblkdev_queue *bq, | ||
444 | struct request *req | ||
445 | ) | ||
446 | { | ||
447 | struct cyasblkdev_blk_data *bd = bq->data; | ||
448 | int stat = BLKPREP_OK; | ||
449 | |||
450 | DBGPRN_FUNC_NAME; | ||
451 | |||
452 | /* If we have no device, we haven't finished initialising. */ | ||
453 | if (!bd || !bd->dev_handle) { | ||
454 | #ifndef WESTBRIDGE_NDEBUG | ||
455 | cy_as_hal_print_message(KERN_ERR | ||
456 | "cyasblkdev %s: killing request - no device/host\n", | ||
457 | req->rq_disk->disk_name); | ||
458 | #endif | ||
459 | stat = BLKPREP_KILL; | ||
460 | } | ||
461 | |||
462 | if (bd->suspended) { | ||
463 | blk_plug_device(bd->queue.queue); | ||
464 | stat = BLKPREP_DEFER; | ||
465 | } | ||
466 | |||
467 | /* Check for excessive requests.*/ | ||
468 | if (blk_rq_pos(req) + blk_rq_sectors(req) > get_capacity(req->rq_disk)) { | ||
469 | cy_as_hal_print_message("cyasblkdev: bad request address\n"); | ||
470 | stat = BLKPREP_KILL; | ||
471 | } | ||
472 | |||
473 | return stat; | ||
474 | } | ||
475 | |||
476 | /*west bridge storage async api on_completed callback */ | ||
477 | static void cyasblkdev_issuecallback( | ||
478 | /* Handle to the device completing the storage operation */ | ||
479 | cy_as_device_handle handle, | ||
480 | /* The media type completing the operation */ | ||
481 | cy_as_media_type type, | ||
482 | /* The device completing the operation */ | ||
483 | uint32_t device, | ||
484 | /* The unit completing the operation */ | ||
485 | uint32_t unit, | ||
486 | /* The block number of the completed operation */ | ||
487 | uint32_t block_number, | ||
488 | /* The type of operation */ | ||
489 | cy_as_oper_type op, | ||
490 | /* The error status */ | ||
491 | cy_as_return_status_t status | ||
492 | ) | ||
493 | { | ||
494 | int retry_cnt = 0; | ||
495 | DBGPRN_FUNC_NAME; | ||
496 | |||
497 | if (status != CY_AS_ERROR_SUCCESS) { | ||
498 | #ifndef WESTBRIDGE_NDEBUG | ||
499 | cy_as_hal_print_message( | ||
500 | "%s: async r/w: op:%d failed with error %d at address %d\n", | ||
501 | __func__, op, status, block_number); | ||
502 | #endif | ||
503 | } | ||
504 | |||
505 | #ifndef WESTBRIDGE_NDEBUG | ||
506 | cy_as_hal_print_message( | ||
507 | "%s calling blk_end_request from issue_callback " | ||
508 | "req=0x%x, status=0x%x, nr_sectors=0x%x\n", | ||
509 | __func__, (unsigned int) gl_bd->queue.req, status, | ||
510 | (unsigned int) blk_rq_sectors(gl_bd->queue.req)); | ||
511 | #endif | ||
512 | |||
513 | /* note: blk_end_request w/o __ prefix should | ||
514 | * not require spinlocks on the queue*/ | ||
515 | while (blk_end_request(gl_bd->queue.req, | ||
516 | status, blk_rq_sectors(gl_bd->queue.req)*512)) { | ||
517 | retry_cnt++; | ||
518 | } | ||
519 | |||
520 | #ifndef WESTBRIDGE_NDEBUG | ||
521 | cy_as_hal_print_message( | ||
522 | "%s blkdev_callback: ended rq on %d sectors, " | ||
523 | "with err:%d, n:%d times\n", __func__, | ||
524 | (int)blk_rq_sectors(gl_bd->queue.req), status, | ||
525 | retry_cnt | ||
526 | ); | ||
527 | #endif | ||
528 | |||
529 | spin_lock_irq(&gl_bd->lock); | ||
530 | |||
531 | /*elevate next request, if there is one*/ | ||
532 | if (!blk_queue_plugged(gl_bd->queue.queue)) { | ||
533 | /* queue is not plugged */ | ||
534 | gl_bd->queue.req = blk_fetch_request(gl_bd->queue.queue); | ||
535 | #ifndef WESTBRIDGE_NDEBUG | ||
536 | cy_as_hal_print_message("%s blkdev_callback: " | ||
537 | "blk_fetch_request():%p\n", | ||
538 | __func__, gl_bd->queue.req); | ||
539 | #endif | ||
540 | } | ||
541 | |||
542 | if (gl_bd->queue.req) { | ||
543 | spin_unlock_irq(&gl_bd->lock); | ||
544 | |||
545 | #ifndef WESTBRIDGE_NDEBUG | ||
546 | cy_as_hal_print_message("%s blkdev_callback: about to " | ||
547 | "call issue_fn:%p\n", __func__, gl_bd->queue.req); | ||
548 | #endif | ||
549 | |||
550 | gl_bd->queue.issue_fn(&gl_bd->queue, gl_bd->queue.req); | ||
551 | } else { | ||
552 | spin_unlock_irq(&gl_bd->lock); | ||
553 | } | ||
554 | } | ||
555 | |||
556 | /* issue astoria blkdev request (issue_fn) */ | ||
557 | static int cyasblkdev_blk_issue_rq( | ||
558 | struct cyasblkdev_queue *bq, | ||
559 | struct request *req | ||
560 | ) | ||
561 | { | ||
562 | struct cyasblkdev_blk_data *bd = bq->data; | ||
563 | int index = 0; | ||
564 | int ret = CY_AS_ERROR_SUCCESS; | ||
565 | uint32_t req_sector = 0; | ||
566 | uint32_t req_nr_sectors = 0; | ||
567 | int bus_num = 0; | ||
568 | int lcl_unit_no = 0; | ||
569 | |||
570 | DBGPRN_FUNC_NAME; | ||
571 | |||
572 | /* | ||
573 | * will construct a scatterlist for the given request; | ||
574 | * the return value is the number of actually used | ||
575 | * entries in the resulting list. Then, this scatterlist | ||
576 | * can be used for the actual DMA prep operation. | ||
577 | */ | ||
578 | spin_lock_irq(&bd->lock); | ||
579 | index = blk_rq_map_sg(bq->queue, req, bd->sg); | ||
580 | |||
581 | if (req->rq_disk == bd->user_disk_0) { | ||
582 | bus_num = bd->user_disk_0_bus_num; | ||
583 | req_sector = blk_rq_pos(req) + gl_bd->user_disk_0_first_sector; | ||
584 | req_nr_sectors = blk_rq_sectors(req); | ||
585 | lcl_unit_no = gl_bd->user_disk_0_unit_no; | ||
586 | |||
587 | #ifndef WESTBRIDGE_NDEBUG | ||
588 | cy_as_hal_print_message("%s: request made to disk 0 " | ||
589 | "for sector=%d, num_sectors=%d, unit_no=%d\n", | ||
590 | __func__, req_sector, (int) blk_rq_sectors(req), | ||
591 | lcl_unit_no); | ||
592 | #endif | ||
593 | } else if (req->rq_disk == bd->user_disk_1) { | ||
594 | bus_num = bd->user_disk_1_bus_num; | ||
595 | req_sector = blk_rq_pos(req) + gl_bd->user_disk_1_first_sector; | ||
596 | /*SECT_NUM_TRANSLATE(blk_rq_sectors(req));*/ | ||
597 | req_nr_sectors = blk_rq_sectors(req); | ||
598 | lcl_unit_no = gl_bd->user_disk_1_unit_no; | ||
599 | |||
600 | #ifndef WESTBRIDGE_NDEBUG | ||
601 | cy_as_hal_print_message("%s: request made to disk 1 for " | ||
602 | "sector=%d, num_sectors=%d, unit_no=%d\n", __func__, | ||
603 | req_sector, (int) blk_rq_sectors(req), lcl_unit_no); | ||
604 | #endif | ||
605 | } else if (req->rq_disk == bd->system_disk) { | ||
606 | bus_num = bd->system_disk_bus_num; | ||
607 | req_sector = blk_rq_pos(req) + gl_bd->system_disk_first_sector; | ||
608 | req_nr_sectors = blk_rq_sectors(req); | ||
609 | lcl_unit_no = gl_bd->system_disk_unit_no; | ||
610 | |||
611 | #ifndef WESTBRIDGE_NDEBUG | ||
612 | cy_as_hal_print_message("%s: request made to system disk " | ||
613 | "for sector=%d, num_sectors=%d, unit_no=%d\n", __func__, | ||
614 | req_sector, (int) blk_rq_sectors(req), lcl_unit_no); | ||
615 | #endif | ||
616 | } | ||
617 | #ifndef WESTBRIDGE_NDEBUG | ||
618 | else { | ||
619 | cy_as_hal_print_message( | ||
620 | "%s: invalid disk used for request\n", __func__); | ||
621 | } | ||
622 | #endif | ||
623 | |||
624 | spin_unlock_irq(&bd->lock); | ||
625 | |||
626 | if (rq_data_dir(req) == READ) { | ||
627 | #ifndef WESTBRIDGE_NDEBUG | ||
628 | cy_as_hal_print_message("%s: calling readasync() " | ||
629 | "req_sector=0x%x, req_nr_sectors=0x%x, bd->sg:%x\n\n", | ||
630 | __func__, req_sector, req_nr_sectors, (uint32_t)bd->sg); | ||
631 | #endif | ||
632 | |||
633 | ret = cy_as_storage_read_async(bd->dev_handle, bus_num, 0, | ||
634 | lcl_unit_no, req_sector, bd->sg, req_nr_sectors, | ||
635 | (cy_as_storage_callback)cyasblkdev_issuecallback); | ||
636 | |||
637 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
638 | #ifndef WESTBRIDGE_NDEBUG | ||
639 | cy_as_hal_print_message("%s:readasync() error %d at " | ||
640 | "address %ld, unit no %d\n", __func__, ret, | ||
641 | blk_rq_pos(req), lcl_unit_no); | ||
642 | cy_as_hal_print_message("%s:ending i/o request " | ||
643 | "on reg:%x\n", __func__, (uint32_t)req); | ||
644 | #endif | ||
645 | |||
646 | while (blk_end_request(req, | ||
647 | (ret == CY_AS_ERROR_SUCCESS), | ||
648 | req_nr_sectors*512)) | ||
649 | ; | ||
650 | |||
651 | bq->req = NULL; | ||
652 | } | ||
653 | } else { | ||
654 | ret = cy_as_storage_write_async(bd->dev_handle, bus_num, 0, | ||
655 | lcl_unit_no, req_sector, bd->sg, req_nr_sectors, | ||
656 | (cy_as_storage_callback)cyasblkdev_issuecallback); | ||
657 | |||
658 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
659 | #ifndef WESTBRIDGE_NDEBUG | ||
660 | cy_as_hal_print_message("%s: write failed with " | ||
661 | "error %d at address %ld, unit no %d\n", | ||
662 | __func__, ret, blk_rq_pos(req), lcl_unit_no); | ||
663 | #endif | ||
664 | |||
665 | /*end IO op on this request(does both | ||
666 | * end_that_request_... _first & _last) */ | ||
667 | while (blk_end_request(req, | ||
668 | (ret == CY_AS_ERROR_SUCCESS), | ||
669 | req_nr_sectors*512)) | ||
670 | ; | ||
671 | |||
672 | bq->req = NULL; | ||
673 | } | ||
674 | } | ||
675 | |||
676 | return ret; | ||
677 | } | ||
678 | |||
679 | static unsigned long | ||
680 | dev_use[CYASBLKDEV_NUM_MINORS / (8 * sizeof(unsigned long))]; | ||
681 | |||
682 | |||
683 | /* storage event callback (note: called in astoria isr context) */ | ||
684 | static void cyasblkdev_storage_callback( | ||
685 | cy_as_device_handle dev_h, | ||
686 | cy_as_bus_number_t bus, | ||
687 | uint32_t device, | ||
688 | cy_as_storage_event evtype, | ||
689 | void *evdata | ||
690 | ) | ||
691 | { | ||
692 | #ifndef WESTBRIDGE_NDEBUG | ||
693 | cy_as_hal_print_message("%s: bus:%d, device:%d, evtype:%d, " | ||
694 | "evdata:%p\n ", __func__, bus, device, evtype, evdata); | ||
695 | #endif | ||
696 | |||
697 | switch (evtype) { | ||
698 | case cy_as_storage_processor: | ||
699 | break; | ||
700 | |||
701 | case cy_as_storage_removed: | ||
702 | break; | ||
703 | |||
704 | case cy_as_storage_inserted: | ||
705 | break; | ||
706 | |||
707 | default: | ||
708 | break; | ||
709 | } | ||
710 | } | ||
711 | |||
712 | #define SECTORS_TO_SCAN 4096 | ||
713 | |||
714 | uint32_t cyasblkdev_get_vfat_offset(int bus_num, int unit_no) | ||
715 | { | ||
716 | /* | ||
717 | * for sd media, vfat partition boot record is not always | ||
718 | * located at sector it greatly depends on the system and | ||
719 | * software that was used to format the sd however, linux | ||
720 | * fs layer always expects it at sector 0, this function | ||
721 | * finds the offset and then uses it in all media r/w | ||
722 | * operations | ||
723 | */ | ||
724 | int sect_no, stat; | ||
725 | uint8_t *sect_buf; | ||
726 | bool br_found = false; | ||
727 | |||
728 | DBGPRN_FUNC_NAME; | ||
729 | |||
730 | sect_buf = kmalloc(1024, GFP_KERNEL); | ||
731 | |||
732 | /* since HAL layer always uses sg lists instead of the | ||
733 | * buffer (for hw dmas) we need to initialize the sg list | ||
734 | * for local buffer*/ | ||
735 | sg_init_one(gl_bd->sg, sect_buf, 512); | ||
736 | |||
737 | /* | ||
738 | * Check MPR partition table 1st, then try to scan through | ||
739 | * 1st 384 sectors until BR signature(intel JMP istruction | ||
740 | * code and ,0x55AA) is found | ||
741 | */ | ||
742 | #ifndef WESTBRIDGE_NDEBUG | ||
743 | cy_as_hal_print_message( | ||
744 | "%s scanning media for vfat partition...\n", __func__); | ||
745 | #endif | ||
746 | |||
747 | for (sect_no = 0; sect_no < SECTORS_TO_SCAN; sect_no++) { | ||
748 | #ifndef WESTBRIDGE_NDEBUG | ||
749 | cy_as_hal_print_message("%s before cyasstorageread " | ||
750 | "gl_bd->sg addr=0x%x\n", __func__, | ||
751 | (unsigned int) gl_bd->sg); | ||
752 | #endif | ||
753 | |||
754 | stat = cy_as_storage_read( | ||
755 | /* Handle to the device of interest */ | ||
756 | gl_bd->dev_handle, | ||
757 | /* The bus to access */ | ||
758 | bus_num, | ||
759 | /* The device to access */ | ||
760 | 0, | ||
761 | /* The unit to access */ | ||
762 | unit_no, | ||
763 | /* absolute sector number */ | ||
764 | sect_no, | ||
765 | /* sg structure */ | ||
766 | gl_bd->sg, | ||
767 | /* The number of blocks to be read */ | ||
768 | 1 | ||
769 | ); | ||
770 | |||
771 | /* try only sectors with boot signature */ | ||
772 | if ((sect_buf[510] == 0x55) && (sect_buf[511] == 0xaa)) { | ||
773 | /* vfat boot record may also be located at | ||
774 | * sector 0, check it first */ | ||
775 | if (sect_buf[0] == 0xEB) { | ||
776 | #ifndef WESTBRIDGE_NDEBUG | ||
777 | cy_as_hal_print_message( | ||
778 | "%s vfat partition found " | ||
779 | "at sector:%d\n", | ||
780 | __func__, sect_no); | ||
781 | #endif | ||
782 | |||
783 | br_found = true; | ||
784 | break; | ||
785 | } | ||
786 | } | ||
787 | |||
788 | if (stat != 0) { | ||
789 | #ifndef WESTBRIDGE_NDEBUG | ||
790 | cy_as_hal_print_message("%s sector scan error\n", | ||
791 | __func__); | ||
792 | #endif | ||
793 | break; | ||
794 | } | ||
795 | } | ||
796 | |||
797 | kfree(sect_buf); | ||
798 | |||
799 | if (br_found) { | ||
800 | return sect_no; | ||
801 | } else { | ||
802 | #ifndef WESTBRIDGE_NDEBUG | ||
803 | cy_as_hal_print_message( | ||
804 | "%s vfat partition is not found, using 0 offset\n", | ||
805 | __func__); | ||
806 | #endif | ||
807 | return 0; | ||
808 | } | ||
809 | } | ||
810 | |||
811 | cy_as_storage_query_device_data dev_data = {0}; | ||
812 | |||
813 | static int cyasblkdev_add_disks(int bus_num, | ||
814 | struct cyasblkdev_blk_data *bd, | ||
815 | int total_media_count, | ||
816 | int devidx) | ||
817 | { | ||
818 | int ret = 0; | ||
819 | uint64_t disk_cap; | ||
820 | int lcl_unit_no; | ||
821 | cy_as_storage_query_unit_data unit_data = {0}; | ||
822 | |||
823 | #ifndef WESTBRIDGE_NDEBUG | ||
824 | cy_as_hal_print_message("%s:query device: " | ||
825 | "type:%d, removable:%d, writable:%d, " | ||
826 | "blksize %d, units:%d, locked:%d, " | ||
827 | "erase_sz:%d\n", | ||
828 | __func__, | ||
829 | dev_data.desc_p.type, | ||
830 | dev_data.desc_p.removable, | ||
831 | dev_data.desc_p.writeable, | ||
832 | dev_data.desc_p.block_size, | ||
833 | dev_data.desc_p.number_units, | ||
834 | dev_data.desc_p.locked, | ||
835 | dev_data.desc_p.erase_unit_size | ||
836 | ); | ||
837 | #endif | ||
838 | |||
839 | /* make sure that device is not locked */ | ||
840 | if (dev_data.desc_p.locked) { | ||
841 | #ifndef WESTBRIDGE_NDEBUG | ||
842 | cy_as_hal_print_message( | ||
843 | "%s: device is locked\n", __func__); | ||
844 | #endif | ||
845 | ret = cy_as_storage_release( | ||
846 | bd->dev_handle, bus_num, 0, 0, 0); | ||
847 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
848 | #ifndef WESTBRIDGE_NDEBUG | ||
849 | cy_as_hal_print_message("%s cannot release" | ||
850 | " storage\n", __func__); | ||
851 | #endif | ||
852 | goto out; | ||
853 | } | ||
854 | goto out; | ||
855 | } | ||
856 | |||
857 | unit_data.device = 0; | ||
858 | unit_data.unit = 0; | ||
859 | unit_data.bus = bus_num; | ||
860 | ret = cy_as_storage_query_unit(bd->dev_handle, | ||
861 | &unit_data, 0, 0); | ||
862 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
863 | #ifndef WESTBRIDGE_NDEBUG | ||
864 | cy_as_hal_print_message("%s: cannot query " | ||
865 | "%d device unit - reason code %d\n", | ||
866 | __func__, bus_num, ret); | ||
867 | #endif | ||
868 | goto out; | ||
869 | } | ||
870 | |||
871 | if (private_partition_bus == bus_num) { | ||
872 | if (private_partition_size > 0) { | ||
873 | ret = cy_as_storage_create_p_partition( | ||
874 | bd->dev_handle, bus_num, 0, | ||
875 | private_partition_size, 0, 0); | ||
876 | if ((ret != CY_AS_ERROR_SUCCESS) && | ||
877 | (ret != CY_AS_ERROR_ALREADY_PARTITIONED)) { | ||
878 | #ifndef WESTBRIDGE_NDEBUG | ||
879 | cy_as_hal_print_message("%s: cy_as_storage_" | ||
880 | "create_p_partition after size > 0 check " | ||
881 | "failed with error code %d\n", | ||
882 | __func__, ret); | ||
883 | #endif | ||
884 | |||
885 | disk_cap = (uint64_t) | ||
886 | (unit_data.desc_p.unit_size); | ||
887 | lcl_unit_no = 0; | ||
888 | |||
889 | } else if (ret == CY_AS_ERROR_ALREADY_PARTITIONED) { | ||
890 | #ifndef WESTBRIDGE_NDEBUG | ||
891 | cy_as_hal_print_message( | ||
892 | "%s: cy_as_storage_create_p_partition " | ||
893 | "indicates memory already partitioned\n", | ||
894 | __func__); | ||
895 | #endif | ||
896 | |||
897 | /*check to see that partition | ||
898 | * matches size */ | ||
899 | if (unit_data.desc_p.unit_size != | ||
900 | private_partition_size) { | ||
901 | ret = cy_as_storage_remove_p_partition( | ||
902 | bd->dev_handle, | ||
903 | bus_num, 0, 0, 0); | ||
904 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
905 | ret = cy_as_storage_create_p_partition( | ||
906 | bd->dev_handle, bus_num, 0, | ||
907 | private_partition_size, 0, 0); | ||
908 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
909 | unit_data.bus = bus_num; | ||
910 | unit_data.device = 0; | ||
911 | unit_data.unit = 1; | ||
912 | } else { | ||
913 | #ifndef WESTBRIDGE_NDEBUG | ||
914 | cy_as_hal_print_message( | ||
915 | "%s: cy_as_storage_create_p_partition " | ||
916 | "after removal unexpectedly failed " | ||
917 | "with error %d\n", __func__, ret); | ||
918 | #endif | ||
919 | |||
920 | /* need to requery bus | ||
921 | * seeing as delete | ||
922 | * successful and create | ||
923 | * failed we have changed | ||
924 | * the disk properties */ | ||
925 | unit_data.bus = bus_num; | ||
926 | unit_data.device = 0; | ||
927 | unit_data.unit = 0; | ||
928 | } | ||
929 | |||
930 | ret = cy_as_storage_query_unit( | ||
931 | bd->dev_handle, | ||
932 | &unit_data, 0, 0); | ||
933 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
934 | #ifndef WESTBRIDGE_NDEBUG | ||
935 | cy_as_hal_print_message( | ||
936 | "%s: cannot query %d " | ||
937 | "device unit - reason code %d\n", | ||
938 | __func__, bus_num, ret); | ||
939 | #endif | ||
940 | goto out; | ||
941 | } else { | ||
942 | disk_cap = (uint64_t) | ||
943 | (unit_data.desc_p.unit_size); | ||
944 | lcl_unit_no = | ||
945 | unit_data.unit; | ||
946 | } | ||
947 | } else { | ||
948 | #ifndef WESTBRIDGE_NDEBUG | ||
949 | cy_as_hal_print_message( | ||
950 | "%s: cy_as_storage_remove_p_partition " | ||
951 | "failed with error %d\n", | ||
952 | __func__, ret); | ||
953 | #endif | ||
954 | |||
955 | unit_data.bus = bus_num; | ||
956 | unit_data.device = 0; | ||
957 | unit_data.unit = 1; | ||
958 | |||
959 | ret = cy_as_storage_query_unit( | ||
960 | bd->dev_handle, &unit_data, 0, 0); | ||
961 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
962 | #ifndef WESTBRIDGE_NDEBUG | ||
963 | cy_as_hal_print_message( | ||
964 | "%s: cannot query %d " | ||
965 | "device unit - reason " | ||
966 | "code %d\n", __func__, | ||
967 | bus_num, ret); | ||
968 | #endif | ||
969 | goto out; | ||
970 | } | ||
971 | |||
972 | disk_cap = (uint64_t) | ||
973 | (unit_data.desc_p.unit_size); | ||
974 | lcl_unit_no = | ||
975 | unit_data.unit; | ||
976 | } | ||
977 | } else { | ||
978 | #ifndef WESTBRIDGE_NDEBUG | ||
979 | cy_as_hal_print_message("%s: partition " | ||
980 | "exists and sizes equal\n", | ||
981 | __func__); | ||
982 | #endif | ||
983 | |||
984 | /*partition already existed, | ||
985 | * need to query second unit*/ | ||
986 | unit_data.bus = bus_num; | ||
987 | unit_data.device = 0; | ||
988 | unit_data.unit = 1; | ||
989 | |||
990 | ret = cy_as_storage_query_unit( | ||
991 | bd->dev_handle, &unit_data, 0, 0); | ||
992 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
993 | #ifndef WESTBRIDGE_NDEBUG | ||
994 | cy_as_hal_print_message( | ||
995 | "%s: cannot query %d " | ||
996 | "device unit " | ||
997 | "- reason code %d\n", | ||
998 | __func__, bus_num, ret); | ||
999 | #endif | ||
1000 | goto out; | ||
1001 | } else { | ||
1002 | disk_cap = (uint64_t) | ||
1003 | (unit_data.desc_p.unit_size); | ||
1004 | lcl_unit_no = unit_data.unit; | ||
1005 | } | ||
1006 | } | ||
1007 | } else { | ||
1008 | #ifndef WESTBRIDGE_NDEBUG | ||
1009 | cy_as_hal_print_message( | ||
1010 | "%s: cy_as_storage_create_p_partition " | ||
1011 | "created successfully\n", __func__); | ||
1012 | #endif | ||
1013 | |||
1014 | disk_cap = (uint64_t) | ||
1015 | (unit_data.desc_p.unit_size - | ||
1016 | private_partition_size); | ||
1017 | |||
1018 | lcl_unit_no = 1; | ||
1019 | } | ||
1020 | } | ||
1021 | #ifndef WESTBRIDGE_NDEBUG | ||
1022 | else { | ||
1023 | cy_as_hal_print_message( | ||
1024 | "%s: invalid partition_size%d\n", __func__, | ||
1025 | private_partition_size); | ||
1026 | |||
1027 | disk_cap = (uint64_t) | ||
1028 | (unit_data.desc_p.unit_size); | ||
1029 | lcl_unit_no = 0; | ||
1030 | } | ||
1031 | #endif | ||
1032 | } else { | ||
1033 | disk_cap = (uint64_t) | ||
1034 | (unit_data.desc_p.unit_size); | ||
1035 | lcl_unit_no = 0; | ||
1036 | } | ||
1037 | |||
1038 | if ((bus_num == 0) || | ||
1039 | (total_media_count == 1)) { | ||
1040 | sprintf(bd->user_disk_0->disk_name, | ||
1041 | "cyasblkdevblk%d", devidx); | ||
1042 | |||
1043 | #ifndef WESTBRIDGE_NDEBUG | ||
1044 | cy_as_hal_print_message( | ||
1045 | "%s: disk unit_sz:%lu blk_sz:%d, " | ||
1046 | "start_blk:%lu, capacity:%llu\n", | ||
1047 | __func__, (unsigned long) | ||
1048 | unit_data.desc_p.unit_size, | ||
1049 | unit_data.desc_p.block_size, | ||
1050 | (unsigned long) | ||
1051 | unit_data.desc_p.start_block, | ||
1052 | (uint64_t)disk_cap | ||
1053 | ); | ||
1054 | #endif | ||
1055 | |||
1056 | #ifndef WESTBRIDGE_NDEBUG | ||
1057 | cy_as_hal_print_message("%s: setting gendisk disk " | ||
1058 | "capacity to %d\n", __func__, (int) disk_cap); | ||
1059 | #endif | ||
1060 | |||
1061 | /* initializing bd->queue */ | ||
1062 | #ifndef WESTBRIDGE_NDEBUG | ||
1063 | cy_as_hal_print_message("%s: init bd->queue\n", | ||
1064 | __func__); | ||
1065 | #endif | ||
1066 | |||
1067 | /* this will create a | ||
1068 | * queue kernel thread */ | ||
1069 | cyasblkdev_init_queue( | ||
1070 | &bd->queue, &bd->lock); | ||
1071 | |||
1072 | bd->queue.prep_fn = cyasblkdev_blk_prep_rq; | ||
1073 | bd->queue.issue_fn = cyasblkdev_blk_issue_rq; | ||
1074 | bd->queue.data = bd; | ||
1075 | |||
1076 | /*blk_size should always | ||
1077 | * be a multiple of 512, | ||
1078 | * set to the max to ensure | ||
1079 | * that all accesses aligned | ||
1080 | * to the greatest multiple, | ||
1081 | * can adjust request to | ||
1082 | * smaller block sizes | ||
1083 | * dynamically*/ | ||
1084 | |||
1085 | bd->user_disk_0_read_only = !dev_data.desc_p.writeable; | ||
1086 | bd->user_disk_0_blk_size = dev_data.desc_p.block_size; | ||
1087 | bd->user_disk_0_type = dev_data.desc_p.type; | ||
1088 | bd->user_disk_0_bus_num = bus_num; | ||
1089 | bd->user_disk_0->major = major; | ||
1090 | bd->user_disk_0->first_minor = devidx << CYASBLKDEV_SHIFT; | ||
1091 | bd->user_disk_0->minors = 8; | ||
1092 | bd->user_disk_0->fops = &cyasblkdev_bdops; | ||
1093 | bd->user_disk_0->events = DISK_EVENT_MEDIA_CHANGE; | ||
1094 | bd->user_disk_0->private_data = bd; | ||
1095 | bd->user_disk_0->queue = bd->queue.queue; | ||
1096 | bd->dbgprn_flags = DBGPRN_RD_RQ; | ||
1097 | bd->user_disk_0_unit_no = lcl_unit_no; | ||
1098 | |||
1099 | blk_queue_logical_block_size(bd->queue.queue, | ||
1100 | bd->user_disk_0_blk_size); | ||
1101 | |||
1102 | set_capacity(bd->user_disk_0, | ||
1103 | disk_cap); | ||
1104 | |||
1105 | #ifndef WESTBRIDGE_NDEBUG | ||
1106 | cy_as_hal_print_message( | ||
1107 | "%s: returned from set_capacity %d\n", | ||
1108 | __func__, (int) disk_cap); | ||
1109 | #endif | ||
1110 | |||
1111 | /* need to start search from | ||
1112 | * public partition beginning */ | ||
1113 | if (vfat_search) { | ||
1114 | bd->user_disk_0_first_sector = | ||
1115 | cyasblkdev_get_vfat_offset( | ||
1116 | bd->user_disk_0_bus_num, | ||
1117 | bd->user_disk_0_unit_no); | ||
1118 | } else { | ||
1119 | bd->user_disk_0_first_sector = 0; | ||
1120 | } | ||
1121 | |||
1122 | #ifndef WESTBRIDGE_NDEBUG | ||
1123 | cy_as_hal_print_message( | ||
1124 | "%s: set user_disk_0_first " | ||
1125 | "sector to %d\n", __func__, | ||
1126 | bd->user_disk_0_first_sector); | ||
1127 | cy_as_hal_print_message( | ||
1128 | "%s: add_disk: disk->major=0x%x\n", | ||
1129 | __func__, | ||
1130 | bd->user_disk_0->major); | ||
1131 | cy_as_hal_print_message( | ||
1132 | "%s: add_disk: " | ||
1133 | "disk->first_minor=0x%x\n", __func__, | ||
1134 | bd->user_disk_0->first_minor); | ||
1135 | cy_as_hal_print_message( | ||
1136 | "%s: add_disk: " | ||
1137 | "disk->minors=0x%x\n", __func__, | ||
1138 | bd->user_disk_0->minors); | ||
1139 | cy_as_hal_print_message( | ||
1140 | "%s: add_disk: " | ||
1141 | "disk->disk_name=%s\n", | ||
1142 | __func__, | ||
1143 | bd->user_disk_0->disk_name); | ||
1144 | cy_as_hal_print_message( | ||
1145 | "%s: add_disk: " | ||
1146 | "disk->part_tbl=0x%x\n", __func__, | ||
1147 | (unsigned int) | ||
1148 | bd->user_disk_0->part_tbl); | ||
1149 | cy_as_hal_print_message( | ||
1150 | "%s: add_disk: " | ||
1151 | "disk->queue=0x%x\n", __func__, | ||
1152 | (unsigned int) | ||
1153 | bd->user_disk_0->queue); | ||
1154 | cy_as_hal_print_message( | ||
1155 | "%s: add_disk: " | ||
1156 | "disk->flags=0x%x\n", | ||
1157 | __func__, (unsigned int) | ||
1158 | bd->user_disk_0->flags); | ||
1159 | cy_as_hal_print_message( | ||
1160 | "%s: add_disk: " | ||
1161 | "disk->driverfs_dev=0x%x\n", | ||
1162 | __func__, (unsigned int) | ||
1163 | bd->user_disk_0->driverfs_dev); | ||
1164 | cy_as_hal_print_message( | ||
1165 | "%s: add_disk: " | ||
1166 | "disk->slave_dir=0x%x\n", | ||
1167 | __func__, (unsigned int) | ||
1168 | bd->user_disk_0->slave_dir); | ||
1169 | cy_as_hal_print_message( | ||
1170 | "%s: add_disk: " | ||
1171 | "disk->random=0x%x\n", | ||
1172 | __func__, (unsigned int) | ||
1173 | bd->user_disk_0->random); | ||
1174 | cy_as_hal_print_message( | ||
1175 | "%s: add_disk: " | ||
1176 | "disk->node_id=0x%x\n", | ||
1177 | __func__, (unsigned int) | ||
1178 | bd->user_disk_0->node_id); | ||
1179 | |||
1180 | #endif | ||
1181 | |||
1182 | add_disk(bd->user_disk_0); | ||
1183 | |||
1184 | } else if ((bus_num == 1) && | ||
1185 | (total_media_count == 2)) { | ||
1186 | bd->user_disk_1_read_only = !dev_data.desc_p.writeable; | ||
1187 | bd->user_disk_1_blk_size = dev_data.desc_p.block_size; | ||
1188 | bd->user_disk_1_type = dev_data.desc_p.type; | ||
1189 | bd->user_disk_1_bus_num = bus_num; | ||
1190 | bd->user_disk_1->major = major; | ||
1191 | bd->user_disk_1->first_minor = (devidx + 1) << CYASBLKDEV_SHIFT; | ||
1192 | bd->user_disk_1->minors = 8; | ||
1193 | bd->user_disk_1->fops = &cyasblkdev_bdops; | ||
1194 | bd->user_disk_1->events = DISK_EVENT_MEDIA_CHANGE; | ||
1195 | bd->user_disk_1->private_data = bd; | ||
1196 | bd->user_disk_1->queue = bd->queue.queue; | ||
1197 | bd->dbgprn_flags = DBGPRN_RD_RQ; | ||
1198 | bd->user_disk_1_unit_no = lcl_unit_no; | ||
1199 | |||
1200 | sprintf(bd->user_disk_1->disk_name, | ||
1201 | "cyasblkdevblk%d", (devidx + 1)); | ||
1202 | |||
1203 | #ifndef WESTBRIDGE_NDEBUG | ||
1204 | cy_as_hal_print_message( | ||
1205 | "%s: disk unit_sz:%lu " | ||
1206 | "blk_sz:%d, " | ||
1207 | "start_blk:%lu, " | ||
1208 | "capacity:%llu\n", | ||
1209 | __func__, | ||
1210 | (unsigned long) | ||
1211 | unit_data.desc_p.unit_size, | ||
1212 | unit_data.desc_p.block_size, | ||
1213 | (unsigned long) | ||
1214 | unit_data.desc_p.start_block, | ||
1215 | (uint64_t)disk_cap | ||
1216 | ); | ||
1217 | #endif | ||
1218 | |||
1219 | /*blk_size should always be a | ||
1220 | * multiple of 512, set to the max | ||
1221 | * to ensure that all accesses | ||
1222 | * aligned to the greatest multiple, | ||
1223 | * can adjust request to smaller | ||
1224 | * block sizes dynamically*/ | ||
1225 | if (bd->user_disk_0_blk_size > | ||
1226 | bd->user_disk_1_blk_size) { | ||
1227 | blk_queue_logical_block_size(bd->queue.queue, | ||
1228 | bd->user_disk_0_blk_size); | ||
1229 | #ifndef WESTBRIDGE_NDEBUG | ||
1230 | cy_as_hal_print_message( | ||
1231 | "%s: set hard sect_sz:%d\n", | ||
1232 | __func__, | ||
1233 | bd->user_disk_0_blk_size); | ||
1234 | #endif | ||
1235 | } else { | ||
1236 | blk_queue_logical_block_size(bd->queue.queue, | ||
1237 | bd->user_disk_1_blk_size); | ||
1238 | #ifndef WESTBRIDGE_NDEBUG | ||
1239 | cy_as_hal_print_message( | ||
1240 | "%s: set hard sect_sz:%d\n", | ||
1241 | __func__, | ||
1242 | bd->user_disk_1_blk_size); | ||
1243 | #endif | ||
1244 | } | ||
1245 | |||
1246 | set_capacity(bd->user_disk_1, disk_cap); | ||
1247 | if (vfat_search) { | ||
1248 | bd->user_disk_1_first_sector = | ||
1249 | cyasblkdev_get_vfat_offset( | ||
1250 | bd->user_disk_1_bus_num, | ||
1251 | bd->user_disk_1_unit_no); | ||
1252 | } else { | ||
1253 | bd->user_disk_1_first_sector | ||
1254 | = 0; | ||
1255 | } | ||
1256 | |||
1257 | add_disk(bd->user_disk_1); | ||
1258 | } | ||
1259 | |||
1260 | if (lcl_unit_no > 0) { | ||
1261 | if (bd->system_disk == NULL) { | ||
1262 | bd->system_disk = | ||
1263 | alloc_disk(8); | ||
1264 | |||
1265 | if (bd->system_disk == NULL) { | ||
1266 | kfree(bd); | ||
1267 | bd = ERR_PTR(-ENOMEM); | ||
1268 | return bd; | ||
1269 | } | ||
1270 | disk_cap = (uint64_t) | ||
1271 | (private_partition_size); | ||
1272 | |||
1273 | /* set properties of | ||
1274 | * system disk */ | ||
1275 | bd->system_disk_read_only = !dev_data.desc_p.writeable; | ||
1276 | bd->system_disk_blk_size = dev_data.desc_p.block_size; | ||
1277 | bd->system_disk_bus_num = bus_num; | ||
1278 | bd->system_disk->major = major; | ||
1279 | bd->system_disk->first_minor = | ||
1280 | (devidx + 2) << CYASBLKDEV_SHIFT; | ||
1281 | bd->system_disk->minors = 8; | ||
1282 | bd->system_disk->fops = &cyasblkdev_bdops; | ||
1283 | bd->system_disk->events = DISK_EVENT_MEDIA_CHANGE; | ||
1284 | bd->system_disk->private_data = bd; | ||
1285 | bd->system_disk->queue = bd->queue.queue; | ||
1286 | /* don't search for vfat | ||
1287 | * with system disk */ | ||
1288 | bd->system_disk_first_sector = 0; | ||
1289 | sprintf( | ||
1290 | bd->system_disk->disk_name, | ||
1291 | "cyasblkdevblk%d", (devidx + 2)); | ||
1292 | |||
1293 | set_capacity(bd->system_disk, | ||
1294 | disk_cap); | ||
1295 | |||
1296 | add_disk(bd->system_disk); | ||
1297 | } | ||
1298 | #ifndef WESTBRIDGE_NDEBUG | ||
1299 | else { | ||
1300 | cy_as_hal_print_message( | ||
1301 | "%s: system disk already allocated %d\n", | ||
1302 | __func__, bus_num); | ||
1303 | } | ||
1304 | #endif | ||
1305 | } | ||
1306 | out: | ||
1307 | return ret; | ||
1308 | } | ||
1309 | |||
1310 | static struct cyasblkdev_blk_data *cyasblkdev_blk_alloc(void) | ||
1311 | { | ||
1312 | struct cyasblkdev_blk_data *bd; | ||
1313 | int ret = 0; | ||
1314 | cy_as_return_status_t stat = -1; | ||
1315 | int bus_num = 0; | ||
1316 | int total_media_count = 0; | ||
1317 | int devidx = 0; | ||
1318 | DBGPRN_FUNC_NAME; | ||
1319 | |||
1320 | total_media_count = 0; | ||
1321 | devidx = find_first_zero_bit(dev_use, CYASBLKDEV_NUM_MINORS); | ||
1322 | if (devidx >= CYASBLKDEV_NUM_MINORS) | ||
1323 | return ERR_PTR(-ENOSPC); | ||
1324 | |||
1325 | __set_bit(devidx, dev_use); | ||
1326 | __set_bit(devidx + 1, dev_use); | ||
1327 | |||
1328 | bd = kzalloc(sizeof(struct cyasblkdev_blk_data), GFP_KERNEL); | ||
1329 | if (bd) { | ||
1330 | gl_bd = bd; | ||
1331 | |||
1332 | spin_lock_init(&bd->lock); | ||
1333 | bd->usage = 1; | ||
1334 | |||
1335 | /* setup the block_dev_ops pointer*/ | ||
1336 | bd->blkops = &cyasblkdev_bdops; | ||
1337 | |||
1338 | /* Get the device handle */ | ||
1339 | bd->dev_handle = cyasdevice_getdevhandle(); | ||
1340 | if (0 == bd->dev_handle) { | ||
1341 | #ifndef WESTBRIDGE_NDEBUG | ||
1342 | cy_as_hal_print_message( | ||
1343 | "%s: get device failed\n", __func__); | ||
1344 | #endif | ||
1345 | ret = ENODEV; | ||
1346 | goto out; | ||
1347 | } | ||
1348 | |||
1349 | #ifndef WESTBRIDGE_NDEBUG | ||
1350 | cy_as_hal_print_message("%s west bridge device handle:%x\n", | ||
1351 | __func__, (uint32_t)bd->dev_handle); | ||
1352 | #endif | ||
1353 | |||
1354 | /* start the storage api and get a handle to the | ||
1355 | * device we are interested in. */ | ||
1356 | |||
1357 | /* Error code to use if the conditions are not satisfied. */ | ||
1358 | ret = ENOMEDIUM; | ||
1359 | |||
1360 | stat = cy_as_misc_release_resource(bd->dev_handle, cy_as_bus_0); | ||
1361 | if ((stat != CY_AS_ERROR_SUCCESS) && | ||
1362 | (stat != CY_AS_ERROR_RESOURCE_NOT_OWNED)) { | ||
1363 | #ifndef WESTBRIDGE_NDEBUG | ||
1364 | cy_as_hal_print_message("%s: cannot release " | ||
1365 | "resource bus 0 - reason code %d\n", | ||
1366 | __func__, stat); | ||
1367 | #endif | ||
1368 | } | ||
1369 | |||
1370 | stat = cy_as_misc_release_resource(bd->dev_handle, cy_as_bus_1); | ||
1371 | if ((stat != CY_AS_ERROR_SUCCESS) && | ||
1372 | (stat != CY_AS_ERROR_RESOURCE_NOT_OWNED)) { | ||
1373 | #ifndef WESTBRIDGE_NDEBUG | ||
1374 | cy_as_hal_print_message("%s: cannot release " | ||
1375 | "resource bus 0 - reason code %d\n", | ||
1376 | __func__, stat); | ||
1377 | #endif | ||
1378 | } | ||
1379 | |||
1380 | /* start storage stack*/ | ||
1381 | stat = cy_as_storage_start(bd->dev_handle, 0, 0x101); | ||
1382 | if (stat != CY_AS_ERROR_SUCCESS) { | ||
1383 | #ifndef WESTBRIDGE_NDEBUG | ||
1384 | cy_as_hal_print_message("%s: cannot start storage " | ||
1385 | "stack - reason code %d\n", __func__, stat); | ||
1386 | #endif | ||
1387 | goto out; | ||
1388 | } | ||
1389 | |||
1390 | #ifndef WESTBRIDGE_NDEBUG | ||
1391 | cy_as_hal_print_message("%s: storage started:%d ok\n", | ||
1392 | __func__, stat); | ||
1393 | #endif | ||
1394 | |||
1395 | stat = cy_as_storage_register_callback(bd->dev_handle, | ||
1396 | cyasblkdev_storage_callback); | ||
1397 | if (stat != CY_AS_ERROR_SUCCESS) { | ||
1398 | #ifndef WESTBRIDGE_NDEBUG | ||
1399 | cy_as_hal_print_message("%s: cannot register callback " | ||
1400 | "- reason code %d\n", __func__, stat); | ||
1401 | #endif | ||
1402 | goto out; | ||
1403 | } | ||
1404 | |||
1405 | for (bus_num = 0; bus_num < 2; bus_num++) { | ||
1406 | stat = cy_as_storage_query_bus(bd->dev_handle, | ||
1407 | bus_num, &bd->media_count[bus_num], 0, 0); | ||
1408 | if (stat == CY_AS_ERROR_SUCCESS) { | ||
1409 | total_media_count = total_media_count + | ||
1410 | bd->media_count[bus_num]; | ||
1411 | } else { | ||
1412 | #ifndef WESTBRIDGE_NDEBUG | ||
1413 | cy_as_hal_print_message("%s: cannot query %d, " | ||
1414 | "reason code: %d\n", | ||
1415 | __func__, bus_num, stat); | ||
1416 | #endif | ||
1417 | goto out; | ||
1418 | } | ||
1419 | } | ||
1420 | |||
1421 | if (total_media_count == 0) { | ||
1422 | #ifndef WESTBRIDGE_NDEBUG | ||
1423 | cy_as_hal_print_message( | ||
1424 | "%s: no storage media was found\n", __func__); | ||
1425 | #endif | ||
1426 | goto out; | ||
1427 | } else if (total_media_count >= 1) { | ||
1428 | if (bd->user_disk_0 == NULL) { | ||
1429 | |||
1430 | bd->user_disk_0 = | ||
1431 | alloc_disk(8); | ||
1432 | if (bd->user_disk_0 == NULL) { | ||
1433 | kfree(bd); | ||
1434 | bd = ERR_PTR(-ENOMEM); | ||
1435 | return bd; | ||
1436 | } | ||
1437 | } | ||
1438 | #ifndef WESTBRIDGE_NDEBUG | ||
1439 | else { | ||
1440 | cy_as_hal_print_message("%s: no available " | ||
1441 | "gen_disk for disk 0, " | ||
1442 | "physically inconsistent\n", __func__); | ||
1443 | } | ||
1444 | #endif | ||
1445 | } | ||
1446 | |||
1447 | if (total_media_count == 2) { | ||
1448 | if (bd->user_disk_1 == NULL) { | ||
1449 | bd->user_disk_1 = | ||
1450 | alloc_disk(8); | ||
1451 | if (bd->user_disk_1 == NULL) { | ||
1452 | kfree(bd); | ||
1453 | bd = ERR_PTR(-ENOMEM); | ||
1454 | return bd; | ||
1455 | } | ||
1456 | } | ||
1457 | #ifndef WESTBRIDGE_NDEBUG | ||
1458 | else { | ||
1459 | cy_as_hal_print_message("%s: no available " | ||
1460 | "gen_disk for media, " | ||
1461 | "physically inconsistent\n", __func__); | ||
1462 | } | ||
1463 | #endif | ||
1464 | } | ||
1465 | #ifndef WESTBRIDGE_NDEBUG | ||
1466 | else if (total_media_count > 2) { | ||
1467 | cy_as_hal_print_message("%s: count corrupted = 0x%d\n", | ||
1468 | __func__, total_media_count); | ||
1469 | } | ||
1470 | #endif | ||
1471 | |||
1472 | #ifndef WESTBRIDGE_NDEBUG | ||
1473 | cy_as_hal_print_message("%s: %d device(s) found\n", | ||
1474 | __func__, total_media_count); | ||
1475 | #endif | ||
1476 | |||
1477 | for (bus_num = 0; bus_num <= 1; bus_num++) { | ||
1478 | /*claim storage for cpu */ | ||
1479 | stat = cy_as_storage_claim(bd->dev_handle, | ||
1480 | bus_num, 0, 0, 0); | ||
1481 | if (stat != CY_AS_ERROR_SUCCESS) { | ||
1482 | cy_as_hal_print_message("%s: cannot claim " | ||
1483 | "%d bus - reason code %d\n", | ||
1484 | __func__, bus_num, stat); | ||
1485 | goto out; | ||
1486 | } | ||
1487 | |||
1488 | dev_data.bus = bus_num; | ||
1489 | dev_data.device = 0; | ||
1490 | |||
1491 | stat = cy_as_storage_query_device(bd->dev_handle, | ||
1492 | &dev_data, 0, 0); | ||
1493 | if (stat == CY_AS_ERROR_SUCCESS) { | ||
1494 | cyasblkdev_add_disks(bus_num, bd, | ||
1495 | total_media_count, devidx); | ||
1496 | } else if (stat == CY_AS_ERROR_NO_SUCH_DEVICE) { | ||
1497 | #ifndef WESTBRIDGE_NDEBUG | ||
1498 | cy_as_hal_print_message( | ||
1499 | "%s: no device on bus %d\n", | ||
1500 | __func__, bus_num); | ||
1501 | #endif | ||
1502 | } else { | ||
1503 | #ifndef WESTBRIDGE_NDEBUG | ||
1504 | cy_as_hal_print_message( | ||
1505 | "%s: cannot query %d device " | ||
1506 | "- reason code %d\n", | ||
1507 | __func__, bus_num, stat); | ||
1508 | #endif | ||
1509 | goto out; | ||
1510 | } | ||
1511 | } /* end for (bus_num = 0; bus_num <= 1; bus_num++)*/ | ||
1512 | |||
1513 | return bd; | ||
1514 | } | ||
1515 | out: | ||
1516 | #ifndef WESTBRIDGE_NDEBUG | ||
1517 | cy_as_hal_print_message( | ||
1518 | "%s: bd failed to initialize\n", __func__); | ||
1519 | #endif | ||
1520 | |||
1521 | kfree(bd); | ||
1522 | bd = ERR_PTR(-ret); | ||
1523 | return bd; | ||
1524 | } | ||
1525 | |||
1526 | |||
1527 | /*init west bridge block device */ | ||
1528 | static int cyasblkdev_blk_initialize(void) | ||
1529 | { | ||
1530 | struct cyasblkdev_blk_data *bd; | ||
1531 | int res; | ||
1532 | |||
1533 | DBGPRN_FUNC_NAME; | ||
1534 | |||
1535 | res = register_blkdev(major, "cyasblkdev"); | ||
1536 | |||
1537 | if (res < 0) { | ||
1538 | #ifndef WESTBRIDGE_NDEBUG | ||
1539 | cy_as_hal_print_message(KERN_WARNING | ||
1540 | "%s unable to get major %d for cyasblkdev media: %d\n", | ||
1541 | __func__, major, res); | ||
1542 | #endif | ||
1543 | return res; | ||
1544 | } | ||
1545 | |||
1546 | if (major == 0) | ||
1547 | major = res; | ||
1548 | |||
1549 | #ifndef WESTBRIDGE_NDEBUG | ||
1550 | cy_as_hal_print_message( | ||
1551 | "%s cyasblkdev registered with major number: %d\n", | ||
1552 | __func__, major); | ||
1553 | #endif | ||
1554 | |||
1555 | bd = cyasblkdev_blk_alloc(); | ||
1556 | if (IS_ERR(bd)) | ||
1557 | return PTR_ERR(bd); | ||
1558 | |||
1559 | return 0; | ||
1560 | } | ||
1561 | |||
1562 | /* start block device */ | ||
1563 | static int __init cyasblkdev_blk_init(void) | ||
1564 | { | ||
1565 | int res = -ENOMEM; | ||
1566 | |||
1567 | DBGPRN_FUNC_NAME; | ||
1568 | |||
1569 | /* get the cyasdev handle for future use*/ | ||
1570 | cyas_dev_handle = cyasdevice_getdevhandle(); | ||
1571 | |||
1572 | if (cyasblkdev_blk_initialize() == 0) | ||
1573 | return 0; | ||
1574 | |||
1575 | #ifndef WESTBRIDGE_NDEBUG | ||
1576 | cy_as_hal_print_message("cyasblkdev init error:%d\n", res); | ||
1577 | #endif | ||
1578 | return res; | ||
1579 | } | ||
1580 | |||
1581 | |||
1582 | static void cyasblkdev_blk_deinit(struct cyasblkdev_blk_data *bd) | ||
1583 | { | ||
1584 | DBGPRN_FUNC_NAME; | ||
1585 | |||
1586 | if (bd) { | ||
1587 | int devidx; | ||
1588 | |||
1589 | if (bd->user_disk_0 != NULL) { | ||
1590 | del_gendisk(bd->user_disk_0); | ||
1591 | devidx = bd->user_disk_0->first_minor | ||
1592 | >> CYASBLKDEV_SHIFT; | ||
1593 | __clear_bit(devidx, dev_use); | ||
1594 | } | ||
1595 | |||
1596 | if (bd->user_disk_1 != NULL) { | ||
1597 | del_gendisk(bd->user_disk_1); | ||
1598 | devidx = bd->user_disk_1->first_minor | ||
1599 | >> CYASBLKDEV_SHIFT; | ||
1600 | __clear_bit(devidx, dev_use); | ||
1601 | } | ||
1602 | |||
1603 | if (bd->system_disk != NULL) { | ||
1604 | del_gendisk(bd->system_disk); | ||
1605 | devidx = bd->system_disk->first_minor | ||
1606 | >> CYASBLKDEV_SHIFT; | ||
1607 | __clear_bit(devidx, dev_use); | ||
1608 | } | ||
1609 | |||
1610 | cyasblkdev_blk_put(bd); | ||
1611 | } | ||
1612 | } | ||
1613 | |||
1614 | /* block device exit */ | ||
1615 | static void __exit cyasblkdev_blk_exit(void) | ||
1616 | { | ||
1617 | DBGPRN_FUNC_NAME; | ||
1618 | |||
1619 | cyasblkdev_blk_deinit(gl_bd); | ||
1620 | unregister_blkdev(major, "cyasblkdev"); | ||
1621 | |||
1622 | } | ||
1623 | |||
1624 | module_init(cyasblkdev_blk_init); | ||
1625 | module_exit(cyasblkdev_blk_exit); | ||
1626 | |||
1627 | MODULE_LICENSE("GPL"); | ||
1628 | MODULE_DESCRIPTION("antioch (cyasblkdev) block device driver"); | ||
1629 | MODULE_AUTHOR("cypress semiconductor"); | ||
1630 | |||
1631 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c b/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c deleted file mode 100644 index d1996a27515e..000000000000 --- a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.c +++ /dev/null | |||
@@ -1,417 +0,0 @@ | |||
1 | /* cyanblkdev_queue.h - Antioch Linux Block Driver queue source file | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Request queue handling for Antioch block device driver. | ||
24 | * Based on the mmc queue handling code by Russell King in the | ||
25 | * linux 2.6.10 kernel. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * linux/drivers/mmc/mmc_queue.c | ||
30 | * | ||
31 | * Copyright (C) 2003 Russell King, All Rights Reserved. | ||
32 | * | ||
33 | * This program is free software; you can redistribute it and/or modify | ||
34 | * it under the terms of the GNU General Public License version 2 as | ||
35 | * published by the Free Software Foundation. | ||
36 | * | ||
37 | */ | ||
38 | |||
39 | #include <linux/module.h> | ||
40 | #include <linux/blkdev.h> | ||
41 | |||
42 | #include "cyasblkdev_queue.h" | ||
43 | |||
44 | #define CYASBLKDEV_QUEUE_EXIT (1 << 0) | ||
45 | #define CYASBLKDEV_QUEUE_SUSPENDED (1 << 1) | ||
46 | #define CY_AS_USE_ASYNC_API | ||
47 | |||
48 | |||
49 | |||
50 | /* print flags by name */ | ||
51 | const char *rq_flag_bit_names[] = { | ||
52 | "REQ_RW", /* not set, read. set, write */ | ||
53 | "REQ_FAILFAST", /* no low level driver retries */ | ||
54 | "REQ_SORTED", /* elevator knows about this request */ | ||
55 | "REQ_SOFTBARRIER", /* may not be passed by ioscheduler */ | ||
56 | "REQ_HARDBARRIER", /* may not be passed by drive either */ | ||
57 | "REQ_FUA", /* forced unit access */ | ||
58 | "REQ_NOMERGE", /* don't touch this for merging */ | ||
59 | "REQ_STARTED", /* drive already may have started this one */ | ||
60 | "REQ_DONTPREP", /* don't call prep for this one */ | ||
61 | "REQ_QUEUED", /* uses queueing */ | ||
62 | "REQ_ELVPRIV", /* elevator private data attached */ | ||
63 | "REQ_FAILED", /* set if the request failed */ | ||
64 | "REQ_QUIET", /* don't worry about errors */ | ||
65 | "REQ_PREEMPT", /* set for "ide_preempt" requests */ | ||
66 | "REQ_ORDERED_COLOR",/* is before or after barrier */ | ||
67 | "REQ_RW_SYNC", /* request is sync (O_DIRECT) */ | ||
68 | "REQ_ALLOCED", /* request came from our alloc pool */ | ||
69 | "REQ_RW_META", /* metadata io request */ | ||
70 | "REQ_COPY_USER", /* contains copies of user pages */ | ||
71 | "REQ_NR_BITS", /* stops here */ | ||
72 | }; | ||
73 | |||
74 | void verbose_rq_flags(int flags) | ||
75 | { | ||
76 | int i; | ||
77 | uint32_t j; | ||
78 | j = 1; | ||
79 | for (i = 0; i < 32; i++) { | ||
80 | if (flags & j) | ||
81 | DBGPRN("<1>%s", rq_flag_bit_names[i]); | ||
82 | j = j << 1; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | |||
87 | /* | ||
88 | * Prepare a -BLK_DEV request. Essentially, this means passing the | ||
89 | * preparation off to the media driver. The media driver will | ||
90 | * create request to CyAsDev. | ||
91 | */ | ||
92 | static int cyasblkdev_prep_request( | ||
93 | struct request_queue *q, struct request *req) | ||
94 | { | ||
95 | DBGPRN_FUNC_NAME; | ||
96 | |||
97 | /* we only like normal block requests.*/ | ||
98 | if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) { | ||
99 | #ifndef WESTBRIDGE_NDEBUG | ||
100 | cy_as_hal_print_message("%s:%x bad request received\n", | ||
101 | __func__, current->pid); | ||
102 | #endif | ||
103 | |||
104 | blk_dump_rq_flags(req, "cyasblkdev bad request"); | ||
105 | return BLKPREP_KILL; | ||
106 | } | ||
107 | |||
108 | req->cmd_flags |= REQ_DONTPREP; | ||
109 | |||
110 | return BLKPREP_OK; | ||
111 | } | ||
112 | |||
113 | /* queue worker thread */ | ||
114 | static int cyasblkdev_queue_thread(void *d) | ||
115 | { | ||
116 | DECLARE_WAITQUEUE(wait, current); | ||
117 | struct cyasblkdev_queue *bq = d; | ||
118 | struct request_queue *q = bq->queue; | ||
119 | u32 qth_pid; | ||
120 | |||
121 | DBGPRN_FUNC_NAME; | ||
122 | |||
123 | /* | ||
124 | * set iothread to ensure that we aren't put to sleep by | ||
125 | * the process freezing. we handle suspension ourselves. | ||
126 | */ | ||
127 | daemonize("cyasblkdev_queue_thread"); | ||
128 | |||
129 | /* signal to queue_init() so it could contnue */ | ||
130 | complete(&bq->thread_complete); | ||
131 | |||
132 | down(&bq->thread_sem); | ||
133 | add_wait_queue(&bq->thread_wq, &wait); | ||
134 | |||
135 | qth_pid = current->pid; | ||
136 | |||
137 | #ifndef WESTBRIDGE_NDEBUG | ||
138 | cy_as_hal_print_message( | ||
139 | "%s:%x started, bq:%p, q:%p\n", __func__, qth_pid, bq, q); | ||
140 | #endif | ||
141 | |||
142 | do { | ||
143 | struct request *req = NULL; | ||
144 | |||
145 | /* the thread wants to be woken up by signals as well */ | ||
146 | set_current_state(TASK_INTERRUPTIBLE); | ||
147 | |||
148 | spin_lock_irq(q->queue_lock); | ||
149 | |||
150 | #ifndef WESTBRIDGE_NDEBUG | ||
151 | cy_as_hal_print_message( | ||
152 | "%s: for bq->queue is null\n", __func__); | ||
153 | #endif | ||
154 | |||
155 | if (!bq->req) { | ||
156 | /* chk if queue is plugged */ | ||
157 | if (!blk_queue_plugged(q)) { | ||
158 | bq->req = req = blk_fetch_request(q); | ||
159 | #ifndef WESTBRIDGE_NDEBUG | ||
160 | cy_as_hal_print_message( | ||
161 | "%s: blk_fetch_request:%x\n", | ||
162 | __func__, (uint32_t)req); | ||
163 | #endif | ||
164 | } else { | ||
165 | #ifndef WESTBRIDGE_NDEBUG | ||
166 | cy_as_hal_print_message( | ||
167 | "%s: queue plugged, " | ||
168 | "skip blk_fetch()\n", __func__); | ||
169 | #endif | ||
170 | } | ||
171 | } | ||
172 | spin_unlock_irq(q->queue_lock); | ||
173 | |||
174 | #ifndef WESTBRIDGE_NDEBUG | ||
175 | cy_as_hal_print_message( | ||
176 | "%s: checking if request queue is null\n", __func__); | ||
177 | #endif | ||
178 | |||
179 | if (!req) { | ||
180 | if (bq->flags & CYASBLKDEV_QUEUE_EXIT) { | ||
181 | #ifndef WESTBRIDGE_NDEBUG | ||
182 | cy_as_hal_print_message( | ||
183 | "%s:got QUEUE_EXIT flag\n", __func__); | ||
184 | #endif | ||
185 | |||
186 | break; | ||
187 | } | ||
188 | |||
189 | #ifndef WESTBRIDGE_NDEBUG | ||
190 | cy_as_hal_print_message( | ||
191 | "%s: request queue is null, goto sleep, " | ||
192 | "thread_sem->count=%d\n", | ||
193 | __func__, bq->thread_sem.count); | ||
194 | if (spin_is_locked(q->queue_lock)) { | ||
195 | cy_as_hal_print_message("%s: queue_lock " | ||
196 | "is locked, need to release\n", __func__); | ||
197 | spin_unlock(q->queue_lock); | ||
198 | |||
199 | if (spin_is_locked(q->queue_lock)) | ||
200 | cy_as_hal_print_message( | ||
201 | "%s: unlock did not work\n", | ||
202 | __func__); | ||
203 | } else { | ||
204 | cy_as_hal_print_message( | ||
205 | "%s: checked lock, is not locked\n", | ||
206 | __func__); | ||
207 | } | ||
208 | #endif | ||
209 | |||
210 | up(&bq->thread_sem); | ||
211 | |||
212 | /* yields to the next rdytorun proc, | ||
213 | * then goes back to sleep*/ | ||
214 | schedule(); | ||
215 | down(&bq->thread_sem); | ||
216 | |||
217 | #ifndef WESTBRIDGE_NDEBUG | ||
218 | cy_as_hal_print_message( | ||
219 | "%s: wake_up,continue\n", | ||
220 | __func__); | ||
221 | #endif | ||
222 | continue; | ||
223 | } | ||
224 | |||
225 | /* new req received, issue it to the driver */ | ||
226 | set_current_state(TASK_RUNNING); | ||
227 | |||
228 | #ifndef WESTBRIDGE_NDEBUG | ||
229 | cy_as_hal_print_message( | ||
230 | "%s: issued a RQ:%x\n", | ||
231 | __func__, (uint32_t)req); | ||
232 | #endif | ||
233 | |||
234 | bq->issue_fn(bq, req); | ||
235 | |||
236 | #ifndef WESTBRIDGE_NDEBUG | ||
237 | cy_as_hal_print_message( | ||
238 | "%s: bq->issue_fn() returned\n", | ||
239 | __func__); | ||
240 | #endif | ||
241 | |||
242 | |||
243 | } while (1); | ||
244 | |||
245 | set_current_state(TASK_RUNNING); | ||
246 | remove_wait_queue(&bq->thread_wq, &wait); | ||
247 | up(&bq->thread_sem); | ||
248 | |||
249 | complete_and_exit(&bq->thread_complete, 0); | ||
250 | |||
251 | #ifndef WESTBRIDGE_NDEBUG | ||
252 | cy_as_hal_print_message("%s: is finished\n", __func__); | ||
253 | #endif | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | /* | ||
259 | * Generic request handler. it is called for any queue on a | ||
260 | * particular host. When the host is not busy, we look for a request | ||
261 | * on any queue on this host, and attempt to issue it. This may | ||
262 | * not be the queue we were asked to process. | ||
263 | */ | ||
264 | static void cyasblkdev_request(struct request_queue *q) | ||
265 | { | ||
266 | struct cyasblkdev_queue *bq = q->queuedata; | ||
267 | DBGPRN_FUNC_NAME; | ||
268 | |||
269 | #ifndef WESTBRIDGE_NDEBUG | ||
270 | cy_as_hal_print_message( | ||
271 | "%s new request on cyasblkdev_queue_t bq:=%x\n", | ||
272 | __func__, (uint32_t)bq); | ||
273 | #endif | ||
274 | |||
275 | if (!bq->req) { | ||
276 | #ifndef WESTBRIDGE_NDEBUG | ||
277 | cy_as_hal_print_message("%s wake_up(&bq->thread_wq)\n", | ||
278 | __func__); | ||
279 | #endif | ||
280 | |||
281 | /* wake up cyasblkdev_queue worker thread*/ | ||
282 | wake_up(&bq->thread_wq); | ||
283 | } else { | ||
284 | #ifndef WESTBRIDGE_NDEBUG | ||
285 | cy_as_hal_print_message("%s: don't wake Q_thr, bq->req:%x\n", | ||
286 | __func__, (uint32_t)bq->req); | ||
287 | #endif | ||
288 | } | ||
289 | } | ||
290 | |||
291 | /* | ||
292 | * cyasblkdev_init_queue - initialise a queue structure. | ||
293 | * @bq: cyasblkdev queue | ||
294 | * @dev: CyAsDeviceHandle to attach this queue | ||
295 | * @lock: queue lock | ||
296 | * | ||
297 | * Initialise a cyasblkdev_request queue. | ||
298 | */ | ||
299 | |||
300 | /* MAX NUMBER OF SECTORS PER REQUEST **/ | ||
301 | #define Q_MAX_SECTORS 128 | ||
302 | |||
303 | /* MAX NUMBER OF PHYS SEGMENTS (entries in the SG list)*/ | ||
304 | #define Q_MAX_SGS 16 | ||
305 | |||
306 | int cyasblkdev_init_queue(struct cyasblkdev_queue *bq, spinlock_t *lock) | ||
307 | { | ||
308 | int ret; | ||
309 | |||
310 | DBGPRN_FUNC_NAME; | ||
311 | |||
312 | /* 1st param is a function that wakes up the queue thread */ | ||
313 | bq->queue = blk_init_queue(cyasblkdev_request, lock); | ||
314 | if (!bq->queue) | ||
315 | return -ENOMEM; | ||
316 | |||
317 | blk_queue_prep_rq(bq->queue, cyasblkdev_prep_request); | ||
318 | |||
319 | blk_queue_bounce_limit(bq->queue, BLK_BOUNCE_ANY); | ||
320 | blk_queue_max_hw_sectors(bq->queue, Q_MAX_SECTORS); | ||
321 | |||
322 | /* As of now, we have the HAL/driver support to | ||
323 | * merge scattered segments and handle them simultaneously. | ||
324 | * so, setting the max_phys_segments to 8. */ | ||
325 | /*blk_queue_max_phys_segments(bq->queue, Q_MAX_SGS); | ||
326 | blk_queue_max_hw_segments(bq->queue, Q_MAX_SGS);*/ | ||
327 | blk_queue_max_segments(bq->queue, Q_MAX_SGS); | ||
328 | |||
329 | /* should be < then HAL can handle */ | ||
330 | blk_queue_max_segment_size(bq->queue, 512*Q_MAX_SECTORS); | ||
331 | |||
332 | bq->queue->queuedata = bq; | ||
333 | bq->req = NULL; | ||
334 | |||
335 | init_completion(&bq->thread_complete); | ||
336 | init_waitqueue_head(&bq->thread_wq); | ||
337 | sema_init(&bq->thread_sem, 1); | ||
338 | |||
339 | ret = kernel_thread(cyasblkdev_queue_thread, bq, CLONE_KERNEL); | ||
340 | if (ret >= 0) { | ||
341 | /* wait until the thread is spawned */ | ||
342 | wait_for_completion(&bq->thread_complete); | ||
343 | |||
344 | /* reinitialize the completion */ | ||
345 | init_completion(&bq->thread_complete); | ||
346 | ret = 0; | ||
347 | goto out; | ||
348 | } | ||
349 | |||
350 | out: | ||
351 | return ret; | ||
352 | } | ||
353 | EXPORT_SYMBOL(cyasblkdev_init_queue); | ||
354 | |||
355 | /*called from blk_put() */ | ||
356 | void cyasblkdev_cleanup_queue(struct cyasblkdev_queue *bq) | ||
357 | { | ||
358 | DBGPRN_FUNC_NAME; | ||
359 | |||
360 | bq->flags |= CYASBLKDEV_QUEUE_EXIT; | ||
361 | wake_up(&bq->thread_wq); | ||
362 | wait_for_completion(&bq->thread_complete); | ||
363 | |||
364 | blk_cleanup_queue(bq->queue); | ||
365 | } | ||
366 | EXPORT_SYMBOL(cyasblkdev_cleanup_queue); | ||
367 | |||
368 | |||
369 | /** | ||
370 | * cyasblkdev_queue_suspend - suspend a CyAsBlkDev request queue | ||
371 | * @bq: CyAsBlkDev queue to suspend | ||
372 | * | ||
373 | * Stop the block request queue, and wait for our thread to | ||
374 | * complete any outstanding requests. This ensures that we | ||
375 | * won't suspend while a request is being processed. | ||
376 | */ | ||
377 | void cyasblkdev_queue_suspend(struct cyasblkdev_queue *bq) | ||
378 | { | ||
379 | struct request_queue *q = bq->queue; | ||
380 | unsigned long flags; | ||
381 | |||
382 | DBGPRN_FUNC_NAME; | ||
383 | |||
384 | if (!(bq->flags & CYASBLKDEV_QUEUE_SUSPENDED)) { | ||
385 | bq->flags |= CYASBLKDEV_QUEUE_SUSPENDED; | ||
386 | |||
387 | spin_lock_irqsave(q->queue_lock, flags); | ||
388 | blk_stop_queue(q); | ||
389 | spin_unlock_irqrestore(q->queue_lock, flags); | ||
390 | |||
391 | down(&bq->thread_sem); | ||
392 | } | ||
393 | } | ||
394 | EXPORT_SYMBOL(cyasblkdev_queue_suspend); | ||
395 | |||
396 | /*cyasblkdev_queue_resume - resume a previously suspended | ||
397 | * CyAsBlkDev request queue @bq: CyAsBlkDev queue to resume */ | ||
398 | void cyasblkdev_queue_resume(struct cyasblkdev_queue *bq) | ||
399 | { | ||
400 | struct request_queue *q = bq->queue; | ||
401 | unsigned long flags; | ||
402 | |||
403 | DBGPRN_FUNC_NAME; | ||
404 | |||
405 | if (bq->flags & CYASBLKDEV_QUEUE_SUSPENDED) { | ||
406 | bq->flags &= ~CYASBLKDEV_QUEUE_SUSPENDED; | ||
407 | |||
408 | up(&bq->thread_sem); | ||
409 | |||
410 | spin_lock_irqsave(q->queue_lock, flags); | ||
411 | blk_start_queue(q); | ||
412 | spin_unlock_irqrestore(q->queue_lock, flags); | ||
413 | } | ||
414 | } | ||
415 | EXPORT_SYMBOL(cyasblkdev_queue_resume); | ||
416 | |||
417 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.h b/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.h deleted file mode 100644 index 51cba6ae6718..000000000000 --- a/drivers/staging/westbridge/astoria/block/cyasblkdev_queue.h +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* cyanblkdev_queue.h - Antioch Linux Block Driver queue header file | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYANBLKDEV_QUEUE_H_ | ||
23 | #define _INCLUDED_CYANBLKDEV_QUEUE_H_ | ||
24 | |||
25 | /* | ||
26 | * may contain various useful MACRO and debug printks | ||
27 | */ | ||
28 | |||
29 | /* moved to staging location, eventual implementation | ||
30 | * considered is here | ||
31 | * #include <linux/westbridge/cyashal.h> | ||
32 | * #include <linux/westbridge/cyastoria.h> | ||
33 | * */ | ||
34 | |||
35 | #include "../include/linux/westbridge/cyashal.h" | ||
36 | #include "../include/linux/westbridge/cyastoria.h" | ||
37 | |||
38 | struct request; | ||
39 | struct task_struct; | ||
40 | |||
41 | struct cyasblkdev_queue { | ||
42 | struct completion thread_complete; | ||
43 | wait_queue_head_t thread_wq; | ||
44 | struct semaphore thread_sem; | ||
45 | unsigned int flags; | ||
46 | struct request *req; | ||
47 | int (*prep_fn)(struct cyasblkdev_queue *, struct request *); | ||
48 | int (*issue_fn)(struct cyasblkdev_queue *, struct request *); | ||
49 | void *data; | ||
50 | struct request_queue *queue; | ||
51 | }; | ||
52 | |||
53 | extern int cyasblkdev_init_queue(struct cyasblkdev_queue *, spinlock_t *); | ||
54 | extern void cyasblkdev_cleanup_queue(struct cyasblkdev_queue *); | ||
55 | extern void cyasblkdev_queue_suspend(struct cyasblkdev_queue *); | ||
56 | extern void cyasblkdev_queue_resume(struct cyasblkdev_queue *); | ||
57 | |||
58 | extern cy_as_device_handle cyasdevice_getdevhandle(void); | ||
59 | #define MOD_LOGS 1 | ||
60 | void verbose_rq_flags(int flags); | ||
61 | |||
62 | #endif /* _INCLUDED_CYANBLKDEV_QUEUE_H_ */ | ||
63 | |||
64 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/device/Kconfig b/drivers/staging/westbridge/astoria/device/Kconfig deleted file mode 100644 index cc99658cf3a4..000000000000 --- a/drivers/staging/westbridge/astoria/device/Kconfig +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # | ||
2 | # West Bridge block driver configuration | ||
3 | # | ||
4 | |||
5 | config WESTBRIDGE_DEVICE_DRIVER | ||
6 | tristate "West Bridge Device Driver" | ||
7 | help | ||
8 | Include the West Bridge based device driver | ||
9 | |||
diff --git a/drivers/staging/westbridge/astoria/device/Makefile b/drivers/staging/westbridge/astoria/device/Makefile deleted file mode 100644 index 7af8b5b0a8f5..000000000000 --- a/drivers/staging/westbridge/astoria/device/Makefile +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the kernel westbridge device driver | ||
3 | # | ||
4 | |||
5 | ifneq ($(CONFIG_WESTBRIDGE_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DWESTBRIDGE_NDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_WESTBRIDGE_DEVICE_DRIVER) += cyasdev.o | ||
10 | |||
11 | |||
12 | ifeq ($(CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL),y) | ||
13 | #moved for staging compatbility | ||
14 | #cyasdev-y := ../../../arch/arm/mach-omap2/cyashalomap_kernel.o cyasdevice.o | ||
15 | cyasdev-y := ../arch/arm/mach-omap2/cyashalomap_kernel.o cyasdevice.o \ | ||
16 | ../api/src/cyasdma.o ../api/src/cyasintr.o ../api/src/cyaslep2pep.o \ | ||
17 | ../api/src/cyaslowlevel.o ../api/src/cyasmisc.o ../api/src/cyasmtp.o \ | ||
18 | ../api/src/cyasstorage.o ../api/src/cyasusb.o | ||
19 | |||
20 | else | ||
21 | # should not get here, need to be built with some hal | ||
22 | cyasdev-y := cyasdevice.o | ||
23 | endif | ||
diff --git a/drivers/staging/westbridge/astoria/device/cyasdevice.c b/drivers/staging/westbridge/astoria/device/cyasdevice.c deleted file mode 100644 index 7de35ccffd32..000000000000 --- a/drivers/staging/westbridge/astoria/device/cyasdevice.c +++ /dev/null | |||
@@ -1,409 +0,0 @@ | |||
1 | /* | ||
2 | ## cyandevice.c - Linux Antioch device driver file | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
19 | ## Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #include <linux/delay.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/scatterlist.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/firmware.h> | ||
29 | #include <linux/platform_device.h> | ||
30 | #include <linux/slab.h> | ||
31 | |||
32 | /* moved for staging location | ||
33 | * update/patch submission | ||
34 | #include <linux/westbridge/cyastoria.h> | ||
35 | #include <linux/westbridge/cyashal.h> | ||
36 | #include <linux/westbridge/cyasregs.h> | ||
37 | */ | ||
38 | |||
39 | #include "../include/linux/westbridge/cyastoria.h" | ||
40 | #include "../include/linux/westbridge/cyashal.h" | ||
41 | #include "../include/linux/westbridge/cyasregs.h" | ||
42 | |||
43 | typedef struct cyasdevice { | ||
44 | /* Handle to the Antioch device */ | ||
45 | cy_as_device_handle dev_handle; | ||
46 | /* Handle to the HAL */ | ||
47 | cy_as_hal_device_tag hal_tag; | ||
48 | spinlock_t common_lock; | ||
49 | unsigned long flags; | ||
50 | } cyasdevice; | ||
51 | |||
52 | /* global ptr to astoria device */ | ||
53 | static cyasdevice *cy_as_device_controller; | ||
54 | int cy_as_device_init_done; | ||
55 | const char *dev_handle_name = "cy_astoria_dev_handle"; | ||
56 | |||
57 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
58 | extern void cy_as_hal_config_c_s_mux(void); | ||
59 | #endif | ||
60 | |||
61 | static void cyasdevice_deinit(cyasdevice *cy_as_dev) | ||
62 | { | ||
63 | cy_as_hal_print_message("<1>_cy_as_device deinitialize called\n"); | ||
64 | if (!cy_as_dev) { | ||
65 | cy_as_hal_print_message("<1>_cy_as_device_deinit: " | ||
66 | "device handle %x is invalid\n", (uint32_t)cy_as_dev); | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | /* stop west_brige */ | ||
71 | if (cy_as_dev->dev_handle) { | ||
72 | cy_as_hal_print_message("<1>_cy_as_device: " | ||
73 | "cy_as_misc_destroy_device called\n"); | ||
74 | if (cy_as_misc_destroy_device(cy_as_dev->dev_handle) != | ||
75 | CY_AS_ERROR_SUCCESS) { | ||
76 | cy_as_hal_print_message( | ||
77 | "<1>_cy_as_device: destroying failed\n"); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | if (cy_as_dev->hal_tag) { | ||
82 | |||
83 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
84 | if (stop_o_m_a_p_kernel(dev_handle_name, | ||
85 | cy_as_dev->hal_tag) != 0) | ||
86 | cy_as_hal_print_message("<1>_cy_as_device: stopping " | ||
87 | "OMAP kernel HAL failed\n"); | ||
88 | |||
89 | #endif | ||
90 | } | ||
91 | cy_as_hal_print_message("<1>_cy_as_device:HAL layer stopped\n"); | ||
92 | |||
93 | kfree(cy_as_dev); | ||
94 | cy_as_device_controller = NULL; | ||
95 | cy_as_hal_print_message("<1>_cy_as_device: deinitialized\n"); | ||
96 | } | ||
97 | |||
98 | /*called from src/cyasmisc.c:MyMiscCallback() as a func | ||
99 | * pointer [dev_p->misc_event_cb] which was previously | ||
100 | * registered by CyAsLLRegisterRequestCallback(..., | ||
101 | * MyMiscCallback); called from CyAsMiscConfigureDevice() | ||
102 | * which is in turn called from cyasdevice_initialize() in | ||
103 | * this src | ||
104 | */ | ||
105 | static void cy_misc_callback(cy_as_device_handle h, | ||
106 | cy_as_misc_event_type evtype, void *evdata) | ||
107 | { | ||
108 | (void)h; | ||
109 | (void)evdata; | ||
110 | |||
111 | switch (evtype) { | ||
112 | case cy_as_event_misc_initialized: | ||
113 | cy_as_hal_print_message("<1>_cy_as_device: " | ||
114 | "initialization done callback triggered\n"); | ||
115 | cy_as_device_init_done = 1; | ||
116 | break; | ||
117 | |||
118 | case cy_as_event_misc_awake: | ||
119 | cy_as_hal_print_message("<1>_cy_as_device: " | ||
120 | "cy_as_event_misc_awake event callback triggered\n"); | ||
121 | cy_as_device_init_done = 1; | ||
122 | break; | ||
123 | default: | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | void cy_as_acquire_common_lock() | ||
129 | { | ||
130 | spin_lock_irqsave(&cy_as_device_controller->common_lock, | ||
131 | cy_as_device_controller->flags); | ||
132 | } | ||
133 | EXPORT_SYMBOL(cy_as_acquire_common_lock); | ||
134 | |||
135 | void cy_as_release_common_lock() | ||
136 | { | ||
137 | spin_unlock_irqrestore(&cy_as_device_controller->common_lock, | ||
138 | cy_as_device_controller->flags); | ||
139 | } | ||
140 | EXPORT_SYMBOL(cy_as_release_common_lock); | ||
141 | |||
142 | /* reset astoria and reinit all regs */ | ||
143 | #define PNAND_REG_CFG_INIT_VAL 0x0000 | ||
144 | void hal_reset(cy_as_hal_device_tag tag) | ||
145 | { | ||
146 | cy_as_hal_print_message("<1> send soft hard rst: " | ||
147 | "MEM_RST_CTRL_REG_HARD...\n"); | ||
148 | cy_as_hal_write_register(tag, CY_AS_MEM_RST_CTRL_REG, | ||
149 | CY_AS_MEM_RST_CTRL_REG_HARD); | ||
150 | mdelay(60); | ||
151 | |||
152 | cy_as_hal_print_message("<1> after RST: si_rev_REG:%x, " | ||
153 | "PNANDCFG_reg:%x\n", | ||
154 | cy_as_hal_read_register(tag, CY_AS_MEM_CM_WB_CFG_ID), | ||
155 | cy_as_hal_read_register(tag, CY_AS_MEM_PNAND_CFG) | ||
156 | ); | ||
157 | |||
158 | /* set it to LBD */ | ||
159 | cy_as_hal_write_register(tag, CY_AS_MEM_PNAND_CFG, | ||
160 | PNAND_REG_CFG_INIT_VAL); | ||
161 | } | ||
162 | EXPORT_SYMBOL(hal_reset); | ||
163 | |||
164 | |||
165 | /* below structures and functions primarily | ||
166 | * implemented for firmware loading */ | ||
167 | static struct platform_device *westbridge_pd; | ||
168 | |||
169 | static int __devinit wb_probe(struct platform_device *devptr) | ||
170 | { | ||
171 | cy_as_hal_print_message("%s called\n", __func__); | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static int __devexit wb_remove(struct platform_device *devptr) | ||
176 | { | ||
177 | cy_as_hal_print_message("%s called\n", __func__); | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static struct platform_driver west_bridge_driver = { | ||
182 | .probe = wb_probe, | ||
183 | .remove = __devexit_p(wb_remove), | ||
184 | .driver = { | ||
185 | .name = "west_bridge_dev"}, | ||
186 | }; | ||
187 | |||
188 | /* west bridge device driver main init */ | ||
189 | static int cyasdevice_initialize(void) | ||
190 | { | ||
191 | cyasdevice *cy_as_dev = 0; | ||
192 | int ret = 0; | ||
193 | int retval = 0; | ||
194 | cy_as_device_config config; | ||
195 | cy_as_hal_sleep_channel channel; | ||
196 | cy_as_get_firmware_version_data ver_data = {0}; | ||
197 | const char *str = ""; | ||
198 | int spin_lim; | ||
199 | const struct firmware *fw_entry; | ||
200 | |||
201 | cy_as_device_init_done = 0; | ||
202 | |||
203 | cy_as_misc_set_log_level(8); | ||
204 | |||
205 | cy_as_hal_print_message("<1>_cy_as_device initialize called\n"); | ||
206 | |||
207 | if (cy_as_device_controller != 0) { | ||
208 | cy_as_hal_print_message("<1>_cy_as_device: the device " | ||
209 | "has already been initilaized. ignoring\n"); | ||
210 | return -EBUSY; | ||
211 | } | ||
212 | |||
213 | /* cy_as_dev = CyAsHalAlloc (sizeof(cyasdevice), SLAB_KERNEL); */ | ||
214 | cy_as_dev = cy_as_hal_alloc(sizeof(cyasdevice)); | ||
215 | if (cy_as_dev == NULL) { | ||
216 | cy_as_hal_print_message("<1>_cy_as_device: " | ||
217 | "memory allocation failed\n"); | ||
218 | return -ENOMEM; | ||
219 | } | ||
220 | memset(cy_as_dev, 0, sizeof(cyasdevice)); | ||
221 | |||
222 | |||
223 | /* Init the HAL & CyAsDeviceHandle */ | ||
224 | |||
225 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
226 | /* start OMAP HAL init instsnce */ | ||
227 | |||
228 | if (!start_o_m_a_p_kernel(dev_handle_name, | ||
229 | &(cy_as_dev->hal_tag), cy_false)) { | ||
230 | |||
231 | cy_as_hal_print_message( | ||
232 | "<1>_cy_as_device: start OMAP34xx HAL failed\n"); | ||
233 | goto done; | ||
234 | } | ||
235 | #endif | ||
236 | |||
237 | /* Now create the device */ | ||
238 | if (cy_as_misc_create_device(&(cy_as_dev->dev_handle), | ||
239 | cy_as_dev->hal_tag) != CY_AS_ERROR_SUCCESS) { | ||
240 | |||
241 | cy_as_hal_print_message( | ||
242 | "<1>_cy_as_device: create device failed\n"); | ||
243 | goto done; | ||
244 | } | ||
245 | |||
246 | memset(&config, 0, sizeof(config)); | ||
247 | config.dmaintr = cy_true; | ||
248 | |||
249 | ret = cy_as_misc_configure_device(cy_as_dev->dev_handle, &config); | ||
250 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
251 | |||
252 | cy_as_hal_print_message( | ||
253 | "<1>_cy_as_device: configure device " | ||
254 | "failed. reason code: %d\n", ret); | ||
255 | goto done; | ||
256 | } | ||
257 | |||
258 | ret = cy_as_misc_register_callback(cy_as_dev->dev_handle, | ||
259 | cy_misc_callback); | ||
260 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
261 | cy_as_hal_print_message("<1>_cy_as_device: " | ||
262 | "cy_as_misc_register_callback failed. " | ||
263 | "reason code: %d\n", ret); | ||
264 | goto done; | ||
265 | } | ||
266 | |||
267 | ret = platform_driver_register(&west_bridge_driver); | ||
268 | if (unlikely(ret < 0)) | ||
269 | return ret; | ||
270 | westbridge_pd = platform_device_register_simple( | ||
271 | "west_bridge_dev", -1, NULL, 0); | ||
272 | |||
273 | if (IS_ERR(westbridge_pd)) { | ||
274 | platform_driver_unregister(&west_bridge_driver); | ||
275 | return PTR_ERR(westbridge_pd); | ||
276 | } | ||
277 | /* Load the firmware */ | ||
278 | ret = request_firmware(&fw_entry, | ||
279 | "west bridge fw", &westbridge_pd->dev); | ||
280 | if (ret) { | ||
281 | cy_as_hal_print_message("cy_as_device: " | ||
282 | "request_firmware failed return val = %d\n", ret); | ||
283 | } else { | ||
284 | cy_as_hal_print_message("cy_as_device: " | ||
285 | "got the firmware %d size=0x%x\n", ret, fw_entry->size); | ||
286 | |||
287 | ret = cy_as_misc_download_firmware( | ||
288 | cy_as_dev->dev_handle, | ||
289 | fw_entry->data, | ||
290 | fw_entry->size , | ||
291 | 0, 0); | ||
292 | } | ||
293 | |||
294 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
295 | cy_as_hal_print_message("<1>_cy_as_device: cannot download " | ||
296 | "firmware. reason code: %d\n", ret); | ||
297 | goto done; | ||
298 | } | ||
299 | |||
300 | /* spin until the device init is completed */ | ||
301 | /* 50 -MAX wait time for the FW load & init | ||
302 | * to complete is 5sec*/ | ||
303 | spin_lim = 50; | ||
304 | |||
305 | cy_as_hal_create_sleep_channel(&channel); | ||
306 | while (!cy_as_device_init_done) { | ||
307 | |||
308 | cy_as_hal_sleep_on(&channel, 100); | ||
309 | |||
310 | if (spin_lim-- <= 0) { | ||
311 | cy_as_hal_print_message( | ||
312 | "<1>\n_e_r_r_o_r!: " | ||
313 | "wait for FW init has timed out !!!"); | ||
314 | break; | ||
315 | } | ||
316 | } | ||
317 | cy_as_hal_destroy_sleep_channel(&channel); | ||
318 | |||
319 | if (spin_lim > 0) | ||
320 | cy_as_hal_print_message( | ||
321 | "cy_as_device: astoria firmware is loaded\n"); | ||
322 | |||
323 | ret = cy_as_misc_get_firmware_version(cy_as_dev->dev_handle, | ||
324 | &ver_data, 0, 0); | ||
325 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
326 | cy_as_hal_print_message("<1>_cy_as_device: cannot get firmware " | ||
327 | "version. reason code: %d\n", ret); | ||
328 | goto done; | ||
329 | } | ||
330 | |||
331 | if ((ver_data.media_type & 0x01) && (ver_data.media_type & 0x06)) | ||
332 | str = "nand and SD/MMC."; | ||
333 | else if ((ver_data.media_type & 0x01) && (ver_data.media_type & 0x08)) | ||
334 | str = "nand and CEATA."; | ||
335 | else if (ver_data.media_type & 0x01) | ||
336 | str = "nand."; | ||
337 | else if (ver_data.media_type & 0x08) | ||
338 | str = "CEATA."; | ||
339 | else | ||
340 | str = "SD/MMC."; | ||
341 | |||
342 | cy_as_hal_print_message("<1> cy_as_device:_firmware version: %s " | ||
343 | "major=%d minor=%d build=%d,\n_media types supported:%s\n", | ||
344 | ((ver_data.is_debug_mode) ? "debug" : "release"), | ||
345 | ver_data.major, ver_data.minor, ver_data.build, str); | ||
346 | |||
347 | spin_lock_init(&cy_as_dev->common_lock); | ||
348 | |||
349 | /* done now */ | ||
350 | cy_as_device_controller = cy_as_dev; | ||
351 | |||
352 | return 0; | ||
353 | |||
354 | done: | ||
355 | if (cy_as_dev) | ||
356 | cyasdevice_deinit(cy_as_dev); | ||
357 | |||
358 | return -EINVAL; | ||
359 | } | ||
360 | |||
361 | cy_as_device_handle cyasdevice_getdevhandle(void) | ||
362 | { | ||
363 | if (cy_as_device_controller) { | ||
364 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
365 | cy_as_hal_config_c_s_mux(); | ||
366 | #endif | ||
367 | |||
368 | return cy_as_device_controller->dev_handle; | ||
369 | } | ||
370 | return NULL; | ||
371 | } | ||
372 | EXPORT_SYMBOL(cyasdevice_getdevhandle); | ||
373 | |||
374 | cy_as_hal_device_tag cyasdevice_gethaltag(void) | ||
375 | { | ||
376 | if (cy_as_device_controller) | ||
377 | return (cy_as_hal_device_tag) | ||
378 | cy_as_device_controller->hal_tag; | ||
379 | |||
380 | return NULL; | ||
381 | } | ||
382 | EXPORT_SYMBOL(cyasdevice_gethaltag); | ||
383 | |||
384 | |||
385 | /*init Westbridge device driver **/ | ||
386 | static int __init cyasdevice_init(void) | ||
387 | { | ||
388 | if (cyasdevice_initialize() != 0) | ||
389 | return -ENODEV; | ||
390 | |||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | |||
395 | static void __exit cyasdevice_cleanup(void) | ||
396 | { | ||
397 | |||
398 | cyasdevice_deinit(cy_as_device_controller); | ||
399 | } | ||
400 | |||
401 | |||
402 | MODULE_DESCRIPTION("west bridge device driver"); | ||
403 | MODULE_AUTHOR("cypress semiconductor"); | ||
404 | MODULE_LICENSE("GPL"); | ||
405 | |||
406 | module_init(cyasdevice_init); | ||
407 | module_exit(cyasdevice_cleanup); | ||
408 | |||
409 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/gadget/Kconfig b/drivers/staging/westbridge/astoria/gadget/Kconfig deleted file mode 100644 index 6fbdf2277b03..000000000000 --- a/drivers/staging/westbridge/astoria/gadget/Kconfig +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # | ||
2 | # West Bridge gadget driver configuration | ||
3 | # | ||
4 | |||
5 | config WESTBRIDGE_GADGET_DRIVER | ||
6 | tristate "West Bridge Gadget Driver" | ||
7 | help | ||
8 | Include the West Bridge based gadget peripheral controller driver | ||
9 | |||
diff --git a/drivers/staging/westbridge/astoria/gadget/Makefile b/drivers/staging/westbridge/astoria/gadget/Makefile deleted file mode 100644 index a5eef7ee60a4..000000000000 --- a/drivers/staging/westbridge/astoria/gadget/Makefile +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the kernel westbridge hal | ||
3 | # | ||
4 | |||
5 | ifneq ($(CONFIG_WESTBRIDGE_DEBUG),y) | ||
6 | EXTRA_CFLAGS += -DWESTBRIDGE_NDEBUG | ||
7 | endif | ||
8 | |||
9 | obj-$(CONFIG_WESTBRIDGE_GADGET_DRIVER) += cyasgadgetctrl.o | ||
10 | cyasgadgetctrl-y := cyasgadget.o | ||
11 | |||
diff --git a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c b/drivers/staging/westbridge/astoria/gadget/cyasgadget.c deleted file mode 100644 index 92015ecd7829..000000000000 --- a/drivers/staging/westbridge/astoria/gadget/cyasgadget.c +++ /dev/null | |||
@@ -1,2189 +0,0 @@ | |||
1 | /* cyangadget.c - Linux USB Gadget driver file for the Cypress West Bridge | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Cypress West Bridge high/full speed usb device controller code | ||
24 | * Based on the Netchip 2280 device controller by David Brownell | ||
25 | * in the linux 2.6.10 kernel | ||
26 | * | ||
27 | * linux/drivers/usb/gadget/net2280.c | ||
28 | */ | ||
29 | |||
30 | /* | ||
31 | * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com) | ||
32 | * Copyright (C) 2003 David Brownell | ||
33 | * | ||
34 | * This program is free software; you can redistribute it and/or modify | ||
35 | * it under the terms of the GNU General Public License as published by | ||
36 | * the Free Software Foundation; either version 2 of the License, or | ||
37 | * (at your option) any later version. | ||
38 | * | ||
39 | * This program is distributed in the hope that it will be useful, | ||
40 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
41 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
42 | * GNU General Public License for more details. | ||
43 | * | ||
44 | * You should have received a copy of the GNU General Public License | ||
45 | * along with this program; if not, write to the Free Software | ||
46 | * Foundation, Inc., 59 Temple Place, Suite 330 | ||
47 | * Boston, MA 02111-1307 USA | ||
48 | */ | ||
49 | |||
50 | #include "cyasgadget.h" | ||
51 | |||
52 | #define CY_AS_DRIVER_DESC "cypress west bridge usb gadget" | ||
53 | #define CY_AS_DRIVER_VERSION "REV B" | ||
54 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
55 | |||
56 | static const char cy_as_driver_name[] = "cy_astoria_gadget"; | ||
57 | static const char cy_as_driver_desc[] = CY_AS_DRIVER_DESC; | ||
58 | |||
59 | static const char cy_as_ep0name[] = "EP0"; | ||
60 | static const char *cy_as_ep_names[] = { | ||
61 | cy_as_ep0name, "EP1", | ||
62 | "EP2", "EP3", "EP4", "EP5", "EP6", "EP7", "EP8", | ||
63 | "EP9", "EP10", "EP11", "EP12", "EP13", "EP14", "EP15" | ||
64 | }; | ||
65 | |||
66 | /* forward declarations */ | ||
67 | static void | ||
68 | cyas_ep_reset( | ||
69 | struct cyasgadget_ep *an_ep); | ||
70 | |||
71 | static int | ||
72 | cyasgadget_fifo_status( | ||
73 | struct usb_ep *_ep); | ||
74 | |||
75 | static void | ||
76 | cyasgadget_stallcallback( | ||
77 | cy_as_device_handle h, | ||
78 | cy_as_return_status_t status, | ||
79 | uint32_t tag, | ||
80 | cy_as_funct_c_b_type cbtype, | ||
81 | void *cbdata); | ||
82 | |||
83 | /* variables */ | ||
84 | static cyasgadget *cy_as_gadget_controller; | ||
85 | |||
86 | static int append_mtp; | ||
87 | module_param(append_mtp, bool, S_IRUGO | S_IWUSR); | ||
88 | MODULE_PARM_DESC(append_mtp, | ||
89 | "west bridge to append descriptors for mtp 0=no 1=yes"); | ||
90 | |||
91 | static int msc_enum_bus_0; | ||
92 | module_param(msc_enum_bus_0, bool, S_IRUGO | S_IWUSR); | ||
93 | MODULE_PARM_DESC(msc_enum_bus_0, | ||
94 | "west bridge to enumerate bus 0 as msc 0=no 1=yes"); | ||
95 | |||
96 | static int msc_enum_bus_1; | ||
97 | module_param(msc_enum_bus_1, bool, S_IRUGO | S_IWUSR); | ||
98 | MODULE_PARM_DESC(msc_enum_bus_1, | ||
99 | "west bridge to enumerate bus 1 as msc 0=no 1=yes"); | ||
100 | |||
101 | /* all Callbacks are placed in this subsection*/ | ||
102 | static void cy_as_gadget_usb_event_callback( | ||
103 | cy_as_device_handle h, | ||
104 | cy_as_usb_event ev, | ||
105 | void *evdata | ||
106 | ) | ||
107 | { | ||
108 | cyasgadget *cy_as_dev; | ||
109 | #ifndef WESTBRIDGE_NDEBUG | ||
110 | struct usb_ctrlrequest *ctrlreq; | ||
111 | #endif | ||
112 | |||
113 | /* cy_as_dev = container_of(h, cyasgadget, dev_handle); */ | ||
114 | cy_as_dev = cy_as_gadget_controller; | ||
115 | switch (ev) { | ||
116 | case cy_as_event_usb_suspend: | ||
117 | #ifndef WESTBRIDGE_NDEBUG | ||
118 | cy_as_hal_print_message( | ||
119 | "<1>_cy_as_event_usb_suspend received\n"); | ||
120 | #endif | ||
121 | cy_as_dev->driver->suspend(&cy_as_dev->gadget); | ||
122 | break; | ||
123 | |||
124 | case cy_as_event_usb_resume: | ||
125 | #ifndef WESTBRIDGE_NDEBUG | ||
126 | cy_as_hal_print_message( | ||
127 | "<1>_cy_as_event_usb_resume received\n"); | ||
128 | #endif | ||
129 | cy_as_dev->driver->resume(&cy_as_dev->gadget); | ||
130 | break; | ||
131 | |||
132 | case cy_as_event_usb_reset: | ||
133 | #ifndef WESTBRIDGE_NDEBUG | ||
134 | cy_as_hal_print_message( | ||
135 | "<1>_cy_as_event_usb_reset received\n"); | ||
136 | #endif | ||
137 | break; | ||
138 | |||
139 | case cy_as_event_usb_speed_change: | ||
140 | #ifndef WESTBRIDGE_NDEBUG | ||
141 | cy_as_hal_print_message( | ||
142 | "<1>_cy_as_event_usb_speed_change received\n"); | ||
143 | #endif | ||
144 | break; | ||
145 | |||
146 | case cy_as_event_usb_set_config: | ||
147 | #ifndef WESTBRIDGE_NDEBUG | ||
148 | cy_as_hal_print_message( | ||
149 | "<1>_cy_as_event_usb_set_config received\n"); | ||
150 | #endif | ||
151 | break; | ||
152 | |||
153 | case cy_as_event_usb_setup_packet: | ||
154 | #ifndef WESTBRIDGE_NDEBUG | ||
155 | ctrlreq = (struct usb_ctrlrequest *)evdata; | ||
156 | |||
157 | cy_as_hal_print_message("<1>_cy_as_event_usb_setup_packet " | ||
158 | "received" | ||
159 | "bRequestType=0x%x," | ||
160 | "bRequest=0x%x," | ||
161 | "wValue=x%x," | ||
162 | "wIndex=0x%x," | ||
163 | "wLength=0x%x,", | ||
164 | ctrlreq->bRequestType, | ||
165 | ctrlreq->bRequest, | ||
166 | ctrlreq->wValue, | ||
167 | ctrlreq->wIndex, | ||
168 | ctrlreq->wLength | ||
169 | ); | ||
170 | #endif | ||
171 | cy_as_dev->outsetupreq = 0; | ||
172 | if ((((uint8_t *)evdata)[0] & USB_DIR_IN) == USB_DIR_OUT) | ||
173 | cy_as_dev->outsetupreq = 1; | ||
174 | cy_as_dev->driver->setup(&cy_as_dev->gadget, | ||
175 | (struct usb_ctrlrequest *)evdata); | ||
176 | break; | ||
177 | |||
178 | case cy_as_event_usb_status_packet: | ||
179 | #ifndef WESTBRIDGE_NDEBUG | ||
180 | cy_as_hal_print_message( | ||
181 | "<1>_cy_as_event_usb_status_packet received\n"); | ||
182 | #endif | ||
183 | break; | ||
184 | |||
185 | case cy_as_event_usb_inquiry_before: | ||
186 | #ifndef WESTBRIDGE_NDEBUG | ||
187 | cy_as_hal_print_message( | ||
188 | "<1>_cy_as_event_usb_inquiry_before received\n"); | ||
189 | #endif | ||
190 | break; | ||
191 | |||
192 | case cy_as_event_usb_inquiry_after: | ||
193 | #ifndef WESTBRIDGE_NDEBUG | ||
194 | cy_as_hal_print_message( | ||
195 | "<1>_cy_as_event_usb_inquiry_after received\n"); | ||
196 | #endif | ||
197 | break; | ||
198 | |||
199 | case cy_as_event_usb_start_stop: | ||
200 | #ifndef WESTBRIDGE_NDEBUG | ||
201 | cy_as_hal_print_message( | ||
202 | "<1>_cy_as_event_usb_start_stop received\n"); | ||
203 | #endif | ||
204 | break; | ||
205 | |||
206 | default: | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | static void cy_as_gadget_mtp_event_callback( | ||
212 | cy_as_device_handle handle, | ||
213 | cy_as_mtp_event evtype, | ||
214 | void *evdata | ||
215 | ) | ||
216 | { | ||
217 | |||
218 | cyasgadget *dev = cy_as_gadget_controller; | ||
219 | (void) handle; | ||
220 | |||
221 | switch (evtype) { | ||
222 | case cy_as_mtp_send_object_complete: | ||
223 | { | ||
224 | cy_as_mtp_send_object_complete_data *send_obj_data = | ||
225 | (cy_as_mtp_send_object_complete_data *) evdata; | ||
226 | |||
227 | #ifndef WESTBRIDGE_NDEBUG | ||
228 | cy_as_hal_print_message( | ||
229 | "<6>MTP EVENT: send_object_complete\n"); | ||
230 | cy_as_hal_print_message( | ||
231 | "<6>_bytes sent = %d\n_send status = %d", | ||
232 | send_obj_data->byte_count, | ||
233 | send_obj_data->status); | ||
234 | #endif | ||
235 | |||
236 | dev->tmtp_send_complete_data.byte_count = | ||
237 | send_obj_data->byte_count; | ||
238 | dev->tmtp_send_complete_data.status = | ||
239 | send_obj_data->status; | ||
240 | dev->tmtp_send_complete_data.transaction_id = | ||
241 | send_obj_data->transaction_id; | ||
242 | dev->tmtp_send_complete = cy_true; | ||
243 | break; | ||
244 | } | ||
245 | case cy_as_mtp_get_object_complete: | ||
246 | { | ||
247 | cy_as_mtp_get_object_complete_data *get_obj_data = | ||
248 | (cy_as_mtp_get_object_complete_data *) evdata; | ||
249 | |||
250 | #ifndef WESTBRIDGE_NDEBUG | ||
251 | cy_as_hal_print_message( | ||
252 | "<6>MTP EVENT: get_object_complete\n"); | ||
253 | cy_as_hal_print_message( | ||
254 | "<6>_bytes got = %d\n_get status = %d", | ||
255 | get_obj_data->byte_count, get_obj_data->status); | ||
256 | #endif | ||
257 | |||
258 | dev->tmtp_get_complete_data.byte_count = | ||
259 | get_obj_data->byte_count; | ||
260 | dev->tmtp_get_complete_data.status = | ||
261 | get_obj_data->status; | ||
262 | dev->tmtp_get_complete = cy_true; | ||
263 | break; | ||
264 | } | ||
265 | case cy_as_mtp_block_table_needed: | ||
266 | { | ||
267 | dev->tmtp_need_new_blk_tbl = cy_true; | ||
268 | #ifndef WESTBRIDGE_NDEBUG | ||
269 | cy_as_hal_print_message( | ||
270 | "<6>MTP EVENT: cy_as_mtp_block_table_needed\n"); | ||
271 | #endif | ||
272 | break; | ||
273 | } | ||
274 | default: | ||
275 | break; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | static void | ||
280 | cyasgadget_setupreadcallback( | ||
281 | cy_as_device_handle h, | ||
282 | cy_as_end_point_number_t ep, | ||
283 | uint32_t count, | ||
284 | void *buf, | ||
285 | cy_as_return_status_t status) | ||
286 | { | ||
287 | cyasgadget_ep *an_ep; | ||
288 | cyasgadget_req *an_req; | ||
289 | cyasgadget *cy_as_dev; | ||
290 | unsigned stopped; | ||
291 | unsigned long flags; | ||
292 | (void)buf; | ||
293 | |||
294 | cy_as_dev = cy_as_gadget_controller; | ||
295 | if (cy_as_dev->driver == NULL) | ||
296 | return; | ||
297 | |||
298 | an_ep = &cy_as_dev->an_gadget_ep[ep]; | ||
299 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
300 | stopped = an_ep->stopped; | ||
301 | |||
302 | #ifndef WESTBRIDGE_NDEBUG | ||
303 | cy_as_hal_print_message( | ||
304 | "%s: ep=%d, count=%d, " | ||
305 | "status=%d\n", __func__, ep, count, status); | ||
306 | #endif | ||
307 | |||
308 | an_req = list_entry(an_ep->queue.next, | ||
309 | cyasgadget_req, queue); | ||
310 | list_del_init(&an_req->queue); | ||
311 | |||
312 | if (status == CY_AS_ERROR_SUCCESS) | ||
313 | an_req->req.status = 0; | ||
314 | else | ||
315 | an_req->req.status = -status; | ||
316 | an_req->req.actual = count; | ||
317 | an_ep->stopped = 1; | ||
318 | |||
319 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
320 | |||
321 | an_req->req.complete(&an_ep->usb_ep_inst, &an_req->req); | ||
322 | |||
323 | an_ep->stopped = stopped; | ||
324 | |||
325 | } | ||
326 | /*called when the write of a setup packet has been completed*/ | ||
327 | static void cyasgadget_setupwritecallback( | ||
328 | cy_as_device_handle h, | ||
329 | cy_as_end_point_number_t ep, | ||
330 | uint32_t count, | ||
331 | void *buf, | ||
332 | cy_as_return_status_t status | ||
333 | ) | ||
334 | { | ||
335 | cyasgadget_ep *an_ep; | ||
336 | cyasgadget_req *an_req; | ||
337 | cyasgadget *cy_as_dev; | ||
338 | unsigned stopped; | ||
339 | unsigned long flags; | ||
340 | |||
341 | (void)buf; | ||
342 | |||
343 | #ifndef WESTBRIDGE_NDEBUG | ||
344 | cy_as_hal_print_message("<1>%s called status=0x%x\n", | ||
345 | __func__, status); | ||
346 | #endif | ||
347 | |||
348 | cy_as_dev = cy_as_gadget_controller; | ||
349 | |||
350 | if (cy_as_dev->driver == NULL) | ||
351 | return; | ||
352 | |||
353 | an_ep = &cy_as_dev->an_gadget_ep[ep]; | ||
354 | |||
355 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
356 | |||
357 | stopped = an_ep->stopped; | ||
358 | |||
359 | #ifndef WESTBRIDGE_NDEBUG | ||
360 | cy_as_hal_print_message("setup_write_callback: ep=%d, " | ||
361 | "count=%d, status=%d\n", ep, count, status); | ||
362 | #endif | ||
363 | |||
364 | an_req = list_entry(an_ep->queue.next, cyasgadget_req, queue); | ||
365 | list_del_init(&an_req->queue); | ||
366 | |||
367 | an_req->req.actual = count; | ||
368 | an_req->req.status = 0; | ||
369 | an_ep->stopped = 1; | ||
370 | |||
371 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
372 | |||
373 | an_req->req.complete(&an_ep->usb_ep_inst, &an_req->req); | ||
374 | |||
375 | an_ep->stopped = stopped; | ||
376 | |||
377 | } | ||
378 | |||
379 | /* called when a read operation has completed.*/ | ||
380 | static void cyasgadget_readcallback( | ||
381 | cy_as_device_handle h, | ||
382 | cy_as_end_point_number_t ep, | ||
383 | uint32_t count, | ||
384 | void *buf, | ||
385 | cy_as_return_status_t status | ||
386 | ) | ||
387 | { | ||
388 | cyasgadget_ep *an_ep; | ||
389 | cyasgadget_req *an_req; | ||
390 | cyasgadget *cy_as_dev; | ||
391 | unsigned stopped; | ||
392 | cy_as_return_status_t ret; | ||
393 | unsigned long flags; | ||
394 | |||
395 | (void)h; | ||
396 | (void)buf; | ||
397 | |||
398 | cy_as_dev = cy_as_gadget_controller; | ||
399 | |||
400 | if (cy_as_dev->driver == NULL) | ||
401 | return; | ||
402 | |||
403 | an_ep = &cy_as_dev->an_gadget_ep[ep]; | ||
404 | stopped = an_ep->stopped; | ||
405 | |||
406 | #ifndef WESTBRIDGE_NDEBUG | ||
407 | cy_as_hal_print_message("%s: ep=%d, count=%d, status=%d\n", | ||
408 | __func__, ep, count, status); | ||
409 | #endif | ||
410 | |||
411 | if (status == CY_AS_ERROR_CANCELED) | ||
412 | return; | ||
413 | |||
414 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
415 | |||
416 | an_req = list_entry(an_ep->queue.next, cyasgadget_req, queue); | ||
417 | list_del_init(&an_req->queue); | ||
418 | |||
419 | if (status == CY_AS_ERROR_SUCCESS) | ||
420 | an_req->req.status = 0; | ||
421 | else | ||
422 | an_req->req.status = -status; | ||
423 | |||
424 | an_req->complete = 1; | ||
425 | an_req->req.actual = count; | ||
426 | an_ep->stopped = 1; | ||
427 | |||
428 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
429 | an_req->req.complete(&an_ep->usb_ep_inst, &an_req->req); | ||
430 | |||
431 | an_ep->stopped = stopped; | ||
432 | |||
433 | /* We need to call ReadAsync on this end-point | ||
434 | * again, so as to not miss any data packets. */ | ||
435 | if (!an_ep->stopped) { | ||
436 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
437 | an_req = 0; | ||
438 | if (!list_empty(&an_ep->queue)) | ||
439 | an_req = list_entry(an_ep->queue.next, | ||
440 | cyasgadget_req, queue); | ||
441 | |||
442 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
443 | |||
444 | if ((an_req) && (an_req->req.status == -EINPROGRESS)) { | ||
445 | ret = cy_as_usb_read_data_async(cy_as_dev->dev_handle, | ||
446 | an_ep->num, cy_false, an_req->req.length, | ||
447 | an_req->req.buf, cyasgadget_readcallback); | ||
448 | |||
449 | if (ret != CY_AS_ERROR_SUCCESS) | ||
450 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
451 | "cy_as_usb_read_data_async failed " | ||
452 | "with error code %d\n", ret); | ||
453 | else | ||
454 | an_req->req.status = -EALREADY; | ||
455 | } | ||
456 | } | ||
457 | } | ||
458 | |||
459 | /* function is called when a usb write operation has completed*/ | ||
460 | static void cyasgadget_writecallback( | ||
461 | cy_as_device_handle h, | ||
462 | cy_as_end_point_number_t ep, | ||
463 | uint32_t count, | ||
464 | void *buf, | ||
465 | cy_as_return_status_t status | ||
466 | ) | ||
467 | { | ||
468 | cyasgadget_ep *an_ep; | ||
469 | cyasgadget_req *an_req; | ||
470 | cyasgadget *cy_as_dev; | ||
471 | unsigned stopped = 0; | ||
472 | cy_as_return_status_t ret; | ||
473 | unsigned long flags; | ||
474 | |||
475 | (void)h; | ||
476 | (void)buf; | ||
477 | |||
478 | cy_as_dev = cy_as_gadget_controller; | ||
479 | if (cy_as_dev->driver == NULL) | ||
480 | return; | ||
481 | |||
482 | an_ep = &cy_as_dev->an_gadget_ep[ep]; | ||
483 | |||
484 | if (status == CY_AS_ERROR_CANCELED) | ||
485 | return; | ||
486 | |||
487 | #ifndef WESTBRIDGE_NDEBUG | ||
488 | cy_as_hal_print_message("%s: ep=%d, count=%d, status=%d\n", | ||
489 | __func__, ep, count, status); | ||
490 | #endif | ||
491 | |||
492 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
493 | |||
494 | an_req = list_entry(an_ep->queue.next, cyasgadget_req, queue); | ||
495 | list_del_init(&an_req->queue); | ||
496 | an_req->req.actual = count; | ||
497 | |||
498 | /* Verify the status value before setting req.status to zero */ | ||
499 | if (status == CY_AS_ERROR_SUCCESS) | ||
500 | an_req->req.status = 0; | ||
501 | else | ||
502 | an_req->req.status = -status; | ||
503 | |||
504 | an_ep->stopped = 1; | ||
505 | |||
506 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
507 | |||
508 | an_req->req.complete(&an_ep->usb_ep_inst, &an_req->req); | ||
509 | an_ep->stopped = stopped; | ||
510 | |||
511 | /* We need to call WriteAsync on this end-point again, so as to not | ||
512 | miss any data packets. */ | ||
513 | if (!an_ep->stopped) { | ||
514 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
515 | an_req = 0; | ||
516 | if (!list_empty(&an_ep->queue)) | ||
517 | an_req = list_entry(an_ep->queue.next, | ||
518 | cyasgadget_req, queue); | ||
519 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
520 | |||
521 | if ((an_req) && (an_req->req.status == -EINPROGRESS)) { | ||
522 | ret = cy_as_usb_write_data_async(cy_as_dev->dev_handle, | ||
523 | an_ep->num, an_req->req.length, an_req->req.buf, | ||
524 | cy_false, cyasgadget_writecallback); | ||
525 | |||
526 | if (ret != CY_AS_ERROR_SUCCESS) | ||
527 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
528 | "cy_as_usb_write_data_async " | ||
529 | "failed with error code %d\n", ret); | ||
530 | else | ||
531 | an_req->req.status = -EALREADY; | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | |||
536 | static void cyasgadget_stallcallback( | ||
537 | cy_as_device_handle h, | ||
538 | cy_as_return_status_t status, | ||
539 | uint32_t tag, | ||
540 | cy_as_funct_c_b_type cbtype, | ||
541 | void *cbdata | ||
542 | ) | ||
543 | { | ||
544 | #ifndef WESTBRIDGE_NDEBUG | ||
545 | if (status != CY_AS_ERROR_SUCCESS) | ||
546 | cy_as_hal_print_message("<1>_set/_clear stall " | ||
547 | "failed with status %d\n", status); | ||
548 | #endif | ||
549 | } | ||
550 | |||
551 | |||
552 | /*******************************************************************/ | ||
553 | /* All usb_ep_ops (cyasgadget_ep_ops) are placed in this subsection*/ | ||
554 | /*******************************************************************/ | ||
555 | static int cyasgadget_enable( | ||
556 | struct usb_ep *_ep, | ||
557 | const struct usb_endpoint_descriptor *desc | ||
558 | ) | ||
559 | { | ||
560 | cyasgadget *an_dev; | ||
561 | cyasgadget_ep *an_ep; | ||
562 | u32 max, tmp; | ||
563 | unsigned long flags; | ||
564 | |||
565 | an_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
566 | if (!_ep || !desc || an_ep->desc || _ep->name == cy_as_ep0name | ||
567 | || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
568 | return -EINVAL; | ||
569 | |||
570 | an_dev = an_ep->dev; | ||
571 | if (!an_dev->driver || an_dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
572 | return -ESHUTDOWN; | ||
573 | |||
574 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; | ||
575 | |||
576 | spin_lock_irqsave(&an_dev->lock, flags); | ||
577 | _ep->maxpacket = max & 0x7ff; | ||
578 | an_ep->desc = desc; | ||
579 | |||
580 | /* ep_reset() has already been called */ | ||
581 | an_ep->stopped = 0; | ||
582 | an_ep->out_overflow = 0; | ||
583 | |||
584 | if (an_ep->cyepconfig.enabled != cy_true) { | ||
585 | #ifndef WESTBRIDGE_NDEBUG | ||
586 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
587 | "cy_as_usb_end_point_config EP %s mismatch " | ||
588 | "on enabled\n", an_ep->usb_ep_inst.name); | ||
589 | #endif | ||
590 | spin_unlock_irqrestore(&an_dev->lock, flags); | ||
591 | return -EINVAL; | ||
592 | } | ||
593 | |||
594 | tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | ||
595 | an_ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0; | ||
596 | |||
597 | spin_unlock_irqrestore(&an_dev->lock, flags); | ||
598 | |||
599 | switch (tmp) { | ||
600 | case USB_ENDPOINT_XFER_ISOC: | ||
601 | if (an_ep->cyepconfig.type != cy_as_usb_iso) { | ||
602 | #ifndef WESTBRIDGE_NDEBUG | ||
603 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
604 | "cy_as_usb_end_point_config EP %s mismatch " | ||
605 | "on type %d %d\n", an_ep->usb_ep_inst.name, | ||
606 | an_ep->cyepconfig.type, cy_as_usb_iso); | ||
607 | #endif | ||
608 | return -EINVAL; | ||
609 | } | ||
610 | break; | ||
611 | case USB_ENDPOINT_XFER_INT: | ||
612 | if (an_ep->cyepconfig.type != cy_as_usb_int) { | ||
613 | #ifndef WESTBRIDGE_NDEBUG | ||
614 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
615 | "cy_as_usb_end_point_config EP %s mismatch " | ||
616 | "on type %d %d\n", an_ep->usb_ep_inst.name, | ||
617 | an_ep->cyepconfig.type, cy_as_usb_int); | ||
618 | #endif | ||
619 | return -EINVAL; | ||
620 | } | ||
621 | break; | ||
622 | default: | ||
623 | if (an_ep->cyepconfig.type != cy_as_usb_bulk) { | ||
624 | #ifndef WESTBRIDGE_NDEBUG | ||
625 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
626 | "cy_as_usb_end_point_config EP %s mismatch " | ||
627 | "on type %d %d\n", an_ep->usb_ep_inst.name, | ||
628 | an_ep->cyepconfig.type, cy_as_usb_bulk); | ||
629 | #endif | ||
630 | return -EINVAL; | ||
631 | } | ||
632 | break; | ||
633 | } | ||
634 | |||
635 | tmp = desc->bEndpointAddress; | ||
636 | an_ep->is_in = (tmp & USB_DIR_IN) != 0; | ||
637 | |||
638 | if ((an_ep->cyepconfig.dir == cy_as_usb_in) && | ||
639 | (!an_ep->is_in)) { | ||
640 | #ifndef WESTBRIDGE_NDEBUG | ||
641 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
642 | "cy_as_usb_end_point_config EP %s mismatch " | ||
643 | "on dir %d %d\n", an_ep->usb_ep_inst.name, | ||
644 | an_ep->cyepconfig.dir, cy_as_usb_in); | ||
645 | #endif | ||
646 | return -EINVAL; | ||
647 | } else if ((an_ep->cyepconfig.dir == cy_as_usb_out) && | ||
648 | (an_ep->is_in)) { | ||
649 | #ifndef WESTBRIDGE_NDEBUG | ||
650 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
651 | "cy_as_usb_end_point_config EP %s mismatch " | ||
652 | "on dir %d %d\n", an_ep->usb_ep_inst.name, | ||
653 | an_ep->cyepconfig.dir, cy_as_usb_out); | ||
654 | #endif | ||
655 | return -EINVAL; | ||
656 | } | ||
657 | |||
658 | cy_as_usb_clear_stall(an_dev->dev_handle, an_ep->num, | ||
659 | cyasgadget_stallcallback, 0); | ||
660 | |||
661 | cy_as_hal_print_message("%s enabled %s (ep%d-%d) max %04x\n", | ||
662 | __func__, _ep->name, an_ep->num, tmp, max); | ||
663 | |||
664 | return 0; | ||
665 | } | ||
666 | |||
667 | static int cyasgadget_disable( | ||
668 | struct usb_ep *_ep | ||
669 | ) | ||
670 | { | ||
671 | cyasgadget_ep *an_ep; | ||
672 | unsigned long flags; | ||
673 | |||
674 | an_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
675 | if (!_ep || !an_ep->desc || _ep->name == cy_as_ep0name) | ||
676 | return -EINVAL; | ||
677 | |||
678 | spin_lock_irqsave(&an_ep->dev->lock, flags); | ||
679 | cyas_ep_reset(an_ep); | ||
680 | |||
681 | spin_unlock_irqrestore(&an_ep->dev->lock, flags); | ||
682 | return 0; | ||
683 | } | ||
684 | |||
685 | static struct usb_request *cyasgadget_alloc_request( | ||
686 | struct usb_ep *_ep, gfp_t gfp_flags | ||
687 | ) | ||
688 | { | ||
689 | cyasgadget_ep *an_ep; | ||
690 | cyasgadget_req *an_req; | ||
691 | |||
692 | if (!_ep) | ||
693 | return NULL; | ||
694 | |||
695 | an_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
696 | |||
697 | an_req = kzalloc(sizeof(cyasgadget_req), gfp_flags); | ||
698 | if (!an_req) | ||
699 | return NULL; | ||
700 | |||
701 | an_req->req.dma = DMA_ADDR_INVALID; | ||
702 | INIT_LIST_HEAD(&an_req->queue); | ||
703 | |||
704 | return &an_req->req; | ||
705 | } | ||
706 | |||
707 | static void cyasgadget_free_request( | ||
708 | struct usb_ep *_ep, | ||
709 | struct usb_request *_req | ||
710 | ) | ||
711 | { | ||
712 | cyasgadget_req *an_req; | ||
713 | |||
714 | if (!_ep || !_req) | ||
715 | return; | ||
716 | |||
717 | an_req = container_of(_req, cyasgadget_req, req); | ||
718 | |||
719 | kfree(an_req); | ||
720 | } | ||
721 | |||
722 | /* Load a packet into the fifo we use for usb IN transfers. | ||
723 | * works for all endpoints. */ | ||
724 | static int cyasgadget_queue( | ||
725 | struct usb_ep *_ep, | ||
726 | struct usb_request *_req, | ||
727 | gfp_t gfp_flags | ||
728 | ) | ||
729 | { | ||
730 | cyasgadget_req *as_req; | ||
731 | cyasgadget_ep *as_ep; | ||
732 | cyasgadget *cy_as_dev; | ||
733 | unsigned long flags; | ||
734 | cy_as_return_status_t ret = 0; | ||
735 | |||
736 | as_req = container_of(_req, cyasgadget_req, req); | ||
737 | if (!_req || !_req->complete || !_req->buf | ||
738 | || !list_empty(&as_req->queue)) | ||
739 | return -EINVAL; | ||
740 | |||
741 | as_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
742 | |||
743 | if (!_ep || (!as_ep->desc && (as_ep->num != 0))) | ||
744 | return -EINVAL; | ||
745 | |||
746 | cy_as_dev = as_ep->dev; | ||
747 | if (!cy_as_dev->driver || | ||
748 | cy_as_dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
749 | return -ESHUTDOWN; | ||
750 | |||
751 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
752 | |||
753 | _req->status = -EINPROGRESS; | ||
754 | _req->actual = 0; | ||
755 | |||
756 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
757 | |||
758 | /* Call Async functions */ | ||
759 | if (as_ep->is_in) { | ||
760 | #ifndef WESTBRIDGE_NDEBUG | ||
761 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
762 | "cy_as_usb_write_data_async being called " | ||
763 | "on ep %d\n", as_ep->num); | ||
764 | #endif | ||
765 | |||
766 | ret = cy_as_usb_write_data_async(cy_as_dev->dev_handle, | ||
767 | as_ep->num, _req->length, _req->buf, | ||
768 | cy_false, cyasgadget_writecallback); | ||
769 | if (ret != CY_AS_ERROR_SUCCESS) | ||
770 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
771 | "cy_as_usb_write_data_async failed with " | ||
772 | "error code %d\n", ret); | ||
773 | else | ||
774 | _req->status = -EALREADY; | ||
775 | } else if (as_ep->num == 0) { | ||
776 | /* | ||
777 | ret = cy_as_usb_write_data_async(cy_as_dev->dev_handle, | ||
778 | as_ep->num, _req->length, _req->buf, cy_false, | ||
779 | cyasgadget_setupwritecallback); | ||
780 | |||
781 | if (ret != CY_AS_ERROR_SUCCESS) | ||
782 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
783 | "cy_as_usb_write_data_async failed with error " | ||
784 | "code %d\n", ret); | ||
785 | */ | ||
786 | if ((cy_as_dev->outsetupreq) && (_req->length)) { | ||
787 | #ifndef WESTBRIDGE_NDEBUG | ||
788 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
789 | "cy_as_usb_read_data_async " | ||
790 | "being called on ep %d\n", | ||
791 | as_ep->num); | ||
792 | #endif | ||
793 | |||
794 | ret = cy_as_usb_read_data_async ( | ||
795 | cy_as_dev->dev_handle, as_ep->num, | ||
796 | cy_true, _req->length, _req->buf, | ||
797 | cyasgadget_setupreadcallback); | ||
798 | |||
799 | if (ret != CY_AS_ERROR_SUCCESS) | ||
800 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
801 | "cy_as_usb_read_data_async failed with " | ||
802 | "error code %d\n", ret); | ||
803 | |||
804 | } else { | ||
805 | #ifndef WESTBRIDGE_NDEBUG | ||
806 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
807 | "cy_as_usb_write_data_async " | ||
808 | "being called on ep %d\n", | ||
809 | as_ep->num); | ||
810 | #endif | ||
811 | |||
812 | ret = cy_as_usb_write_data_async(cy_as_dev->dev_handle, | ||
813 | as_ep->num, _req->length, _req->buf, cy_false, | ||
814 | cyasgadget_setupwritecallback); | ||
815 | |||
816 | if (ret != CY_AS_ERROR_SUCCESS) | ||
817 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
818 | "cy_as_usb_write_data_async failed with " | ||
819 | "error code %d\n", ret); | ||
820 | } | ||
821 | |||
822 | } else if (list_empty(&as_ep->queue)) { | ||
823 | #ifndef WESTBRIDGE_NDEBUG | ||
824 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
825 | "cy_as_usb_read_data_async being called since " | ||
826 | "ep queue empty%d\n", ret); | ||
827 | #endif | ||
828 | |||
829 | ret = cy_as_usb_read_data_async(cy_as_dev->dev_handle, | ||
830 | as_ep->num, cy_false, _req->length, _req->buf, | ||
831 | cyasgadget_readcallback); | ||
832 | if (ret != CY_AS_ERROR_SUCCESS) | ||
833 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
834 | "cy_as_usb_read_data_async failed with error " | ||
835 | "code %d\n", ret); | ||
836 | else | ||
837 | _req->status = -EALREADY; | ||
838 | } | ||
839 | |||
840 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
841 | |||
842 | if (as_req) | ||
843 | list_add_tail(&as_req->queue, &as_ep->queue); | ||
844 | |||
845 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
846 | |||
847 | return 0; | ||
848 | } | ||
849 | |||
850 | /* dequeue request */ | ||
851 | static int cyasgadget_dequeue( | ||
852 | struct usb_ep *_ep, | ||
853 | struct usb_request *_req | ||
854 | ) | ||
855 | { | ||
856 | cyasgadget_ep *an_ep; | ||
857 | cyasgadget *dev; | ||
858 | an_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
859 | dev = an_ep->dev; | ||
860 | |||
861 | #ifndef WESTBRIDGE_NDEBUG | ||
862 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
863 | #endif | ||
864 | |||
865 | cy_as_usb_cancel_async(dev->dev_handle, an_ep->num); | ||
866 | |||
867 | return 0; | ||
868 | } | ||
869 | |||
870 | static int cyasgadget_set_halt( | ||
871 | struct usb_ep *_ep, | ||
872 | int value | ||
873 | ) | ||
874 | { | ||
875 | cyasgadget_ep *an_ep; | ||
876 | int retval = 0; | ||
877 | |||
878 | #ifndef WESTBRIDGE_NDEBUG | ||
879 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
880 | #endif | ||
881 | |||
882 | an_ep = container_of(_ep, cyasgadget_ep, usb_ep_inst); | ||
883 | if (!_ep || (!an_ep->desc && an_ep->num != 0)) | ||
884 | return -EINVAL; | ||
885 | |||
886 | if (!an_ep->dev->driver || an_ep->dev->gadget.speed == | ||
887 | USB_SPEED_UNKNOWN) | ||
888 | return -ESHUTDOWN; | ||
889 | |||
890 | if (an_ep->desc /* not ep0 */ && | ||
891 | (an_ep->desc->bmAttributes & 0x03) == USB_ENDPOINT_XFER_ISOC) | ||
892 | return -EINVAL; | ||
893 | |||
894 | if (!list_empty(&an_ep->queue)) | ||
895 | retval = -EAGAIN; | ||
896 | else if (an_ep->is_in && value && | ||
897 | cyasgadget_fifo_status(_ep) != 0) | ||
898 | retval = -EAGAIN; | ||
899 | else { | ||
900 | if (value) { | ||
901 | cy_as_usb_set_stall(an_ep->dev->dev_handle, | ||
902 | an_ep->num, cyasgadget_stallcallback, 0); | ||
903 | } else { | ||
904 | cy_as_usb_clear_stall(an_ep->dev->dev_handle, | ||
905 | an_ep->num, cyasgadget_stallcallback, 0); | ||
906 | } | ||
907 | } | ||
908 | |||
909 | return retval; | ||
910 | } | ||
911 | |||
912 | static int cyasgadget_fifo_status( | ||
913 | struct usb_ep *_ep | ||
914 | ) | ||
915 | { | ||
916 | #ifndef WESTBRIDGE_NDEBUG | ||
917 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
918 | #endif | ||
919 | |||
920 | return 0; | ||
921 | } | ||
922 | |||
923 | static void cyasgadget_fifo_flush( | ||
924 | struct usb_ep *_ep | ||
925 | ) | ||
926 | { | ||
927 | #ifndef WESTBRIDGE_NDEBUG | ||
928 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
929 | #endif | ||
930 | } | ||
931 | |||
932 | static struct usb_ep_ops cyasgadget_ep_ops = { | ||
933 | .enable = cyasgadget_enable, | ||
934 | .disable = cyasgadget_disable, | ||
935 | .alloc_request = cyasgadget_alloc_request, | ||
936 | .free_request = cyasgadget_free_request, | ||
937 | .queue = cyasgadget_queue, | ||
938 | .dequeue = cyasgadget_dequeue, | ||
939 | .set_halt = cyasgadget_set_halt, | ||
940 | .fifo_status = cyasgadget_fifo_status, | ||
941 | .fifo_flush = cyasgadget_fifo_flush, | ||
942 | }; | ||
943 | |||
944 | /*************************************************************/ | ||
945 | /*This subsection contains all usb_gadget_ops cyasgadget_ops */ | ||
946 | /*************************************************************/ | ||
947 | static int cyasgadget_get_frame( | ||
948 | struct usb_gadget *_gadget | ||
949 | ) | ||
950 | { | ||
951 | #ifndef WESTBRIDGE_NDEBUG | ||
952 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
953 | #endif | ||
954 | return 0; | ||
955 | } | ||
956 | |||
957 | static int cyasgadget_wakeup( | ||
958 | struct usb_gadget *_gadget | ||
959 | ) | ||
960 | { | ||
961 | #ifndef WESTBRIDGE_NDEBUG | ||
962 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
963 | #endif | ||
964 | return 0; | ||
965 | } | ||
966 | |||
967 | static int cyasgadget_set_selfpowered( | ||
968 | struct usb_gadget *_gadget, | ||
969 | int value | ||
970 | ) | ||
971 | { | ||
972 | #ifndef WESTBRIDGE_NDEBUG | ||
973 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
974 | #endif | ||
975 | return 0; | ||
976 | } | ||
977 | |||
978 | static int cyasgadget_pullup( | ||
979 | struct usb_gadget *_gadget, | ||
980 | int is_on | ||
981 | ) | ||
982 | { | ||
983 | struct cyasgadget *cy_as_dev; | ||
984 | unsigned long flags; | ||
985 | |||
986 | #ifndef WESTBRIDGE_NDEBUG | ||
987 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
988 | #endif | ||
989 | |||
990 | if (!_gadget) | ||
991 | return -ENODEV; | ||
992 | |||
993 | cy_as_dev = container_of(_gadget, cyasgadget, gadget); | ||
994 | |||
995 | spin_lock_irqsave(&cy_as_dev->lock, flags); | ||
996 | cy_as_dev->softconnect = (is_on != 0); | ||
997 | if (is_on) | ||
998 | cy_as_usb_connect(cy_as_dev->dev_handle, 0, 0); | ||
999 | else | ||
1000 | cy_as_usb_disconnect(cy_as_dev->dev_handle, 0, 0); | ||
1001 | |||
1002 | spin_unlock_irqrestore(&cy_as_dev->lock, flags); | ||
1003 | |||
1004 | return 0; | ||
1005 | } | ||
1006 | |||
1007 | static int cyasgadget_ioctl( | ||
1008 | struct usb_gadget *_gadget, | ||
1009 | unsigned code, | ||
1010 | unsigned long param | ||
1011 | ) | ||
1012 | { | ||
1013 | int err = 0; | ||
1014 | int retval = 0; | ||
1015 | int ret_stat = 0; | ||
1016 | cyasgadget *dev = cy_as_gadget_controller; | ||
1017 | |||
1018 | #ifndef WESTBRIDGE_NDEBUG | ||
1019 | cy_as_hal_print_message("<1>%s called, code=%d, param=%ld\n", | ||
1020 | __func__, code, param); | ||
1021 | #endif | ||
1022 | /* | ||
1023 | * extract the type and number bitfields, and don't decode | ||
1024 | * wrong cmds: return ENOTTY (inappropriate ioctl) before access_ok() | ||
1025 | */ | ||
1026 | if (_IOC_TYPE(code) != CYASGADGET_IOC_MAGIC) { | ||
1027 | #ifndef WESTBRIDGE_NDEBUG | ||
1028 | cy_as_hal_print_message("%s, bad magic number = 0x%x\n", | ||
1029 | __func__, _IOC_TYPE(code)); | ||
1030 | #endif | ||
1031 | return -ENOTTY; | ||
1032 | } | ||
1033 | |||
1034 | if (_IOC_NR(code) > CYASGADGET_IOC_MAXNR) { | ||
1035 | #ifndef WESTBRIDGE_NDEBUG | ||
1036 | cy_as_hal_print_message("%s, bad ioctl code = 0x%x\n", | ||
1037 | __func__, _IOC_NR(code)); | ||
1038 | #endif | ||
1039 | return -ENOTTY; | ||
1040 | } | ||
1041 | |||
1042 | /* | ||
1043 | * the direction is a bitmask, and VERIFY_WRITE catches R/W | ||
1044 | * transfers. `Type' is user-oriented, while | ||
1045 | * access_ok is kernel-oriented, so the concept of "read" and | ||
1046 | * "write" is reversed | ||
1047 | */ | ||
1048 | if (_IOC_DIR(code) & _IOC_READ) | ||
1049 | err = !access_ok(VERIFY_WRITE, | ||
1050 | (void __user *)param, _IOC_SIZE(code)); | ||
1051 | else if (_IOC_DIR(code) & _IOC_WRITE) | ||
1052 | err = !access_ok(VERIFY_READ, | ||
1053 | (void __user *)param, _IOC_SIZE(code)); | ||
1054 | |||
1055 | if (err) { | ||
1056 | cy_as_hal_print_message("%s, bad ioctl dir = 0x%x\n", | ||
1057 | __func__, _IOC_DIR(code)); | ||
1058 | return -EFAULT; | ||
1059 | } | ||
1060 | |||
1061 | switch (code) { | ||
1062 | case CYASGADGET_GETMTPSTATUS: | ||
1063 | { | ||
1064 | cy_as_gadget_ioctl_tmtp_status *usr_d = | ||
1065 | (cy_as_gadget_ioctl_tmtp_status *)param; | ||
1066 | |||
1067 | #ifndef WESTBRIDGE_NDEBUG | ||
1068 | cy_as_hal_print_message("%s: got CYASGADGET_GETMTPSTATUS\n", | ||
1069 | __func__); | ||
1070 | #endif | ||
1071 | |||
1072 | retval = __put_user(dev->tmtp_send_complete, | ||
1073 | (uint32_t __user *)(&(usr_d->tmtp_send_complete))); | ||
1074 | retval = __put_user(dev->tmtp_get_complete, | ||
1075 | (uint32_t __user *)(&(usr_d->tmtp_get_complete))); | ||
1076 | retval = __put_user(dev->tmtp_need_new_blk_tbl, | ||
1077 | (uint32_t __user *)(&(usr_d->tmtp_need_new_blk_tbl))); | ||
1078 | |||
1079 | if (copy_to_user((&(usr_d->tmtp_send_complete_data)), | ||
1080 | (&(dev->tmtp_send_complete_data)), | ||
1081 | sizeof(cy_as_gadget_ioctl_send_object))) | ||
1082 | return -EFAULT; | ||
1083 | |||
1084 | if (copy_to_user((&(usr_d->tmtp_get_complete_data)), | ||
1085 | (&(dev->tmtp_get_complete_data)), | ||
1086 | sizeof(cy_as_gadget_ioctl_get_object))) | ||
1087 | return -EFAULT; | ||
1088 | break; | ||
1089 | } | ||
1090 | case CYASGADGET_CLEARTMTPSTATUS: | ||
1091 | { | ||
1092 | #ifndef WESTBRIDGE_NDEBUG | ||
1093 | cy_as_hal_print_message("%s got CYASGADGET_CLEARTMTPSTATUS\n", | ||
1094 | __func__); | ||
1095 | #endif | ||
1096 | |||
1097 | dev->tmtp_send_complete = 0; | ||
1098 | dev->tmtp_get_complete = 0; | ||
1099 | dev->tmtp_need_new_blk_tbl = 0; | ||
1100 | |||
1101 | break; | ||
1102 | } | ||
1103 | case CYASGADGET_INITSOJ: | ||
1104 | { | ||
1105 | cy_as_gadget_ioctl_i_s_o_j_d k_d; | ||
1106 | cy_as_gadget_ioctl_i_s_o_j_d *usr_d = | ||
1107 | (cy_as_gadget_ioctl_i_s_o_j_d *)param; | ||
1108 | cy_as_mtp_block_table blk_table; | ||
1109 | struct scatterlist sg; | ||
1110 | char *alloc_filename; | ||
1111 | struct file *file_to_allocate; | ||
1112 | |||
1113 | #ifndef WESTBRIDGE_NDEBUG | ||
1114 | cy_as_hal_print_message("%s got CYASGADGET_INITSOJ\n", | ||
1115 | __func__); | ||
1116 | #endif | ||
1117 | |||
1118 | memset(&blk_table, 0, sizeof(blk_table)); | ||
1119 | |||
1120 | /* Get user argument structure */ | ||
1121 | if (copy_from_user(&k_d, usr_d, | ||
1122 | sizeof(cy_as_gadget_ioctl_i_s_o_j_d))) | ||
1123 | return -EFAULT; | ||
1124 | |||
1125 | /* better use fixed size buff*/ | ||
1126 | alloc_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL); | ||
1127 | if (alloc_filename == NULL) | ||
1128 | return -ENOMEM; | ||
1129 | |||
1130 | /* get the filename */ | ||
1131 | if (copy_from_user(alloc_filename, k_d.file_name, | ||
1132 | k_d.name_length + 1)) { | ||
1133 | #ifndef WESTBRIDGE_NDEBUG | ||
1134 | cy_as_hal_print_message("%s: CYASGADGET_INITSOJ, " | ||
1135 | "copy file name from user space failed\n", | ||
1136 | __func__); | ||
1137 | #endif | ||
1138 | kfree(alloc_filename); | ||
1139 | return -EFAULT; | ||
1140 | } | ||
1141 | |||
1142 | file_to_allocate = filp_open(alloc_filename, O_RDWR, 0); | ||
1143 | |||
1144 | if (!IS_ERR(file_to_allocate)) { | ||
1145 | |||
1146 | struct address_space *mapping = | ||
1147 | file_to_allocate->f_mapping; | ||
1148 | const struct address_space_operations *a_ops = | ||
1149 | mapping->a_ops; | ||
1150 | struct inode *inode = mapping->host; | ||
1151 | struct inode *alloc_inode = | ||
1152 | file_to_allocate->f_path.dentry->d_inode; | ||
1153 | uint32_t num_clusters = 0; | ||
1154 | struct buffer_head bh; | ||
1155 | struct kstat stat; | ||
1156 | int nr_pages = 0; | ||
1157 | int ret_stat = 0; | ||
1158 | |||
1159 | #ifndef WESTBRIDGE_NDEBUG | ||
1160 | cy_as_hal_print_message("%s: fhandle is OK, " | ||
1161 | "calling vfs_getattr\n", __func__); | ||
1162 | #endif | ||
1163 | |||
1164 | ret_stat = vfs_getattr(file_to_allocate->f_path.mnt, | ||
1165 | file_to_allocate->f_path.dentry, &stat); | ||
1166 | |||
1167 | #ifndef WESTBRIDGE_NDEBUG | ||
1168 | cy_as_hal_print_message("%s: returned from " | ||
1169 | "vfs_getattr() stat->blksize=0x%lx\n", | ||
1170 | __func__, stat.blksize); | ||
1171 | #endif | ||
1172 | |||
1173 | /* TODO: get this from disk properties | ||
1174 | * (from blockdevice)*/ | ||
1175 | #define SECTOR_SIZE 512 | ||
1176 | if (stat.blksize != 0) { | ||
1177 | num_clusters = (k_d.num_bytes) / SECTOR_SIZE; | ||
1178 | |||
1179 | if (((k_d.num_bytes) % SECTOR_SIZE) != 0) | ||
1180 | num_clusters++; | ||
1181 | } else { | ||
1182 | goto initsoj_safe_exit; | ||
1183 | } | ||
1184 | |||
1185 | bh.b_state = 0; | ||
1186 | bh.b_blocknr = 0; | ||
1187 | /* block size is arbitrary , we'll use sector size*/ | ||
1188 | bh.b_size = SECTOR_SIZE; | ||
1189 | |||
1190 | |||
1191 | |||
1192 | /* clear dirty pages in page cache | ||
1193 | * (if were any allocated) */ | ||
1194 | nr_pages = (k_d.num_bytes) / (PAGE_CACHE_SIZE); | ||
1195 | |||
1196 | if (((k_d.num_bytes) % (PAGE_CACHE_SIZE)) != 0) | ||
1197 | nr_pages++; | ||
1198 | |||
1199 | #ifndef WESTBRIDGE_NDEBUG | ||
1200 | /*check out how many pages where actually allocated */ | ||
1201 | if (mapping->nrpages != nr_pages) | ||
1202 | cy_as_hal_print_message("%s mpage_cleardirty " | ||
1203 | "mapping->nrpages %d != num_pages %d\n", | ||
1204 | __func__, (int) mapping->nrpages, | ||
1205 | nr_pages); | ||
1206 | |||
1207 | cy_as_hal_print_message("%s: calling " | ||
1208 | "mpage_cleardirty() " | ||
1209 | "for %d pages\n", __func__, nr_pages); | ||
1210 | #endif | ||
1211 | |||
1212 | ret_stat = mpage_cleardirty(mapping, nr_pages); | ||
1213 | |||
1214 | /*fill up the the block table from the addr mapping */ | ||
1215 | if (a_ops->bmap) { | ||
1216 | int8_t blk_table_idx = -1; | ||
1217 | uint32_t file_block_idx = 0; | ||
1218 | uint32_t last_blk_addr_map = 0, | ||
1219 | curr_blk_addr_map = 0; | ||
1220 | |||
1221 | #ifndef WESTBRIDGE_NDEBUG | ||
1222 | if (alloc_inode->i_bytes == 0) | ||
1223 | cy_as_hal_print_message( | ||
1224 | "%s: alloc_inode->ibytes =0\n", | ||
1225 | __func__); | ||
1226 | #endif | ||
1227 | |||
1228 | /* iterate through the list of | ||
1229 | * blocks (not clusters)*/ | ||
1230 | for (file_block_idx = 0; | ||
1231 | file_block_idx < num_clusters | ||
1232 | /*inode->i_bytes*/; file_block_idx++) { | ||
1233 | |||
1234 | /* returns starting sector number */ | ||
1235 | curr_blk_addr_map = | ||
1236 | a_ops->bmap(mapping, | ||
1237 | file_block_idx); | ||
1238 | |||
1239 | /*no valid mapping*/ | ||
1240 | if (curr_blk_addr_map == 0) { | ||
1241 | #ifndef WESTBRIDGE_NDEBUG | ||
1242 | cy_as_hal_print_message( | ||
1243 | "%s:hit invalid " | ||
1244 | "mapping\n", __func__); | ||
1245 | #endif | ||
1246 | break; | ||
1247 | } else if (curr_blk_addr_map != | ||
1248 | (last_blk_addr_map + 1) || | ||
1249 | (blk_table.num_blocks | ||
1250 | [blk_table_idx] == 65535)) { | ||
1251 | |||
1252 | /* next table entry */ | ||
1253 | blk_table_idx++; | ||
1254 | /* starting sector of a | ||
1255 | * scattered cluster*/ | ||
1256 | blk_table.start_blocks | ||
1257 | [blk_table_idx] = | ||
1258 | curr_blk_addr_map; | ||
1259 | /* ++ num of blocks in cur | ||
1260 | * table entry*/ | ||
1261 | blk_table. | ||
1262 | num_blocks[blk_table_idx]++; | ||
1263 | |||
1264 | #ifndef WESTBRIDGE_NDEBUG | ||
1265 | if (file_block_idx != 0) | ||
1266 | cy_as_hal_print_message( | ||
1267 | "<*> next table " | ||
1268 | "entry:%d required\n", | ||
1269 | blk_table_idx); | ||
1270 | #endif | ||
1271 | } else { | ||
1272 | /*add contiguous block*/ | ||
1273 | blk_table.num_blocks | ||
1274 | [blk_table_idx]++; | ||
1275 | } /*if (curr_blk_addr_map == 0)*/ | ||
1276 | |||
1277 | last_blk_addr_map = curr_blk_addr_map; | ||
1278 | } /* end for (file_block_idx = 0; file_block_idx | ||
1279 | < inode->i_bytes;) */ | ||
1280 | |||
1281 | #ifndef WESTBRIDGE_NDEBUG | ||
1282 | /*print result for verification*/ | ||
1283 | { | ||
1284 | int i; | ||
1285 | cy_as_hal_print_message( | ||
1286 | "%s: print block table " | ||
1287 | "mapping:\n", | ||
1288 | __func__); | ||
1289 | for (i = 0; i <= blk_table_idx; i++) { | ||
1290 | cy_as_hal_print_message( | ||
1291 | "<1> %d 0x%x 0x%x\n", i, | ||
1292 | blk_table.start_blocks[i], | ||
1293 | blk_table.num_blocks[i]); | ||
1294 | } | ||
1295 | } | ||
1296 | #endif | ||
1297 | |||
1298 | /* copy the block table to user | ||
1299 | * space (for debug purposes) */ | ||
1300 | retval = __put_user( | ||
1301 | blk_table.start_blocks[blk_table_idx], | ||
1302 | (uint32_t __user *) | ||
1303 | (&(usr_d->blk_addr_p))); | ||
1304 | |||
1305 | retval = __put_user( | ||
1306 | blk_table.num_blocks[blk_table_idx], | ||
1307 | (uint32_t __user *) | ||
1308 | (&(usr_d->blk_count_p))); | ||
1309 | |||
1310 | blk_table_idx++; | ||
1311 | retval = __put_user(blk_table_idx, | ||
1312 | (uint32_t __user *) | ||
1313 | (&(usr_d->item_count))); | ||
1314 | |||
1315 | } /*end if (a_ops->bmap)*/ | ||
1316 | |||
1317 | filp_close(file_to_allocate, NULL); | ||
1318 | |||
1319 | dev->tmtp_send_complete = 0; | ||
1320 | dev->tmtp_need_new_blk_tbl = 0; | ||
1321 | |||
1322 | #ifndef WESTBRIDGE_NDEBUG | ||
1323 | cy_as_hal_print_message( | ||
1324 | "%s: calling cy_as_mtp_init_send_object()\n", | ||
1325 | __func__); | ||
1326 | #endif | ||
1327 | sg_init_one(&sg, &blk_table, sizeof(blk_table)); | ||
1328 | ret_stat = cy_as_mtp_init_send_object(dev->dev_handle, | ||
1329 | (cy_as_mtp_block_table *)&sg, | ||
1330 | k_d.num_bytes, 0, 0); | ||
1331 | #ifndef WESTBRIDGE_NDEBUG | ||
1332 | cy_as_hal_print_message("%s: returned from " | ||
1333 | "cy_as_mtp_init_send_object()\n", __func__); | ||
1334 | #endif | ||
1335 | |||
1336 | } | ||
1337 | #ifndef WESTBRIDGE_NDEBUG | ||
1338 | else { | ||
1339 | cy_as_hal_print_message( | ||
1340 | "%s: failed to allocate the file %s\n", | ||
1341 | __func__, alloc_filename); | ||
1342 | } /* end if (file_to_allocate)*/ | ||
1343 | #endif | ||
1344 | kfree(alloc_filename); | ||
1345 | initsoj_safe_exit: | ||
1346 | ret_stat = 0; | ||
1347 | retval = __put_user(ret_stat, | ||
1348 | (uint32_t __user *)(&(usr_d->ret_val))); | ||
1349 | |||
1350 | break; | ||
1351 | } | ||
1352 | case CYASGADGET_INITGOJ: | ||
1353 | { | ||
1354 | cy_as_gadget_ioctl_i_g_o_j_d k_d; | ||
1355 | cy_as_gadget_ioctl_i_g_o_j_d *usr_d = | ||
1356 | (cy_as_gadget_ioctl_i_g_o_j_d *)param; | ||
1357 | cy_as_mtp_block_table blk_table; | ||
1358 | struct scatterlist sg; | ||
1359 | char *map_filename; | ||
1360 | struct file *file_to_map; | ||
1361 | |||
1362 | #ifndef WESTBRIDGE_NDEBUG | ||
1363 | cy_as_hal_print_message( | ||
1364 | "%s: got CYASGADGET_INITGOJ\n", | ||
1365 | __func__); | ||
1366 | #endif | ||
1367 | |||
1368 | memset(&blk_table, 0, sizeof(blk_table)); | ||
1369 | |||
1370 | /* Get user argument sturcutre */ | ||
1371 | if (copy_from_user(&k_d, usr_d, | ||
1372 | sizeof(cy_as_gadget_ioctl_i_g_o_j_d))) | ||
1373 | return -EFAULT; | ||
1374 | |||
1375 | map_filename = kmalloc(k_d.name_length + 1, GFP_KERNEL); | ||
1376 | if (map_filename == NULL) | ||
1377 | return -ENOMEM; | ||
1378 | if (copy_from_user(map_filename, k_d.file_name, | ||
1379 | k_d.name_length + 1)) { | ||
1380 | #ifndef WESTBRIDGE_NDEBUG | ||
1381 | cy_as_hal_print_message("%s: copy file name from " | ||
1382 | "user space failed\n", __func__); | ||
1383 | #endif | ||
1384 | kfree(map_filename); | ||
1385 | return -EFAULT; | ||
1386 | } | ||
1387 | |||
1388 | #ifndef WESTBRIDGE_NDEBUG | ||
1389 | cy_as_hal_print_message("<*>%s: opening %s for kernel " | ||
1390 | "mode access map\n", __func__, map_filename); | ||
1391 | #endif | ||
1392 | file_to_map = filp_open(map_filename, O_RDWR, 0); | ||
1393 | if (file_to_map) { | ||
1394 | struct address_space *mapping = file_to_map->f_mapping; | ||
1395 | const struct address_space_operations | ||
1396 | *a_ops = mapping->a_ops; | ||
1397 | struct inode *inode = mapping->host; | ||
1398 | |||
1399 | int8_t blk_table_idx = -1; | ||
1400 | uint32_t file_block_idx = 0; | ||
1401 | uint32_t last_blk_addr_map = 0, curr_blk_addr_map = 0; | ||
1402 | |||
1403 | /*verify operation exists*/ | ||
1404 | if (a_ops->bmap) { | ||
1405 | #ifndef WESTBRIDGE_NDEBUG | ||
1406 | cy_as_hal_print_message( | ||
1407 | "<*>%s: bmap found, i_bytes=0x%x, " | ||
1408 | "i_size=0x%x, i_blocks=0x%x\n", | ||
1409 | __func__, inode->i_bytes, | ||
1410 | (unsigned int) inode->i_size, | ||
1411 | (unsigned int) inode->i_blocks); | ||
1412 | #endif | ||
1413 | |||
1414 | k_d.num_bytes = inode->i_size; | ||
1415 | |||
1416 | #ifndef WESTBRIDGE_NDEBUG | ||
1417 | cy_as_hal_print_message( | ||
1418 | "<*>%s: k_d.num_bytes=0x%x\n", | ||
1419 | __func__, k_d.num_bytes); | ||
1420 | #endif | ||
1421 | |||
1422 | for (file_block_idx = 0; | ||
1423 | file_block_idx < inode->i_size; | ||
1424 | file_block_idx++) { | ||
1425 | curr_blk_addr_map = | ||
1426 | a_ops->bmap(mapping, | ||
1427 | file_block_idx); | ||
1428 | |||
1429 | if (curr_blk_addr_map == 0) { | ||
1430 | /*no valid mapping*/ | ||
1431 | #ifndef WESTBRIDGE_NDEBUG | ||
1432 | cy_as_hal_print_message( | ||
1433 | "%s: no valid " | ||
1434 | "mapping\n", __func__); | ||
1435 | #endif | ||
1436 | break; | ||
1437 | } else if (curr_blk_addr_map != | ||
1438 | (last_blk_addr_map + 1)) { | ||
1439 | /*non-contiguous break*/ | ||
1440 | blk_table_idx++; | ||
1441 | blk_table.start_blocks | ||
1442 | [blk_table_idx] = | ||
1443 | curr_blk_addr_map; | ||
1444 | blk_table.num_blocks | ||
1445 | [blk_table_idx]++; | ||
1446 | #ifndef WESTBRIDGE_NDEBUG | ||
1447 | cy_as_hal_print_message( | ||
1448 | "%s: found non-" | ||
1449 | "contiguous break", | ||
1450 | __func__); | ||
1451 | #endif | ||
1452 | } else { | ||
1453 | /*add contiguous block*/ | ||
1454 | blk_table.num_blocks | ||
1455 | [blk_table_idx]++; | ||
1456 | } | ||
1457 | last_blk_addr_map = curr_blk_addr_map; | ||
1458 | } | ||
1459 | |||
1460 | /*print result for verification*/ | ||
1461 | #ifndef WESTBRIDGE_NDEBUG | ||
1462 | { | ||
1463 | int i = 0; | ||
1464 | |||
1465 | for (i = 0; i <= blk_table_idx; i++) { | ||
1466 | cy_as_hal_print_message( | ||
1467 | "%s %d 0x%x 0x%x\n", | ||
1468 | __func__, i, | ||
1469 | blk_table.start_blocks[i], | ||
1470 | blk_table.num_blocks[i]); | ||
1471 | } | ||
1472 | } | ||
1473 | #endif | ||
1474 | } else { | ||
1475 | #ifndef WESTBRIDGE_NDEBUG | ||
1476 | cy_as_hal_print_message( | ||
1477 | "%s: could not find " | ||
1478 | "a_ops->bmap\n", __func__); | ||
1479 | #endif | ||
1480 | return -EFAULT; | ||
1481 | } | ||
1482 | |||
1483 | filp_close(file_to_map, NULL); | ||
1484 | |||
1485 | dev->tmtp_get_complete = 0; | ||
1486 | dev->tmtp_need_new_blk_tbl = 0; | ||
1487 | |||
1488 | ret_stat = __put_user( | ||
1489 | blk_table.start_blocks[blk_table_idx], | ||
1490 | (uint32_t __user *)(&(usr_d->blk_addr_p))); | ||
1491 | |||
1492 | ret_stat = __put_user( | ||
1493 | blk_table.num_blocks[blk_table_idx], | ||
1494 | (uint32_t __user *)(&(usr_d->blk_count_p))); | ||
1495 | |||
1496 | sg_init_one(&sg, &blk_table, sizeof(blk_table)); | ||
1497 | |||
1498 | #ifndef WESTBRIDGE_NDEBUG | ||
1499 | cy_as_hal_print_message( | ||
1500 | "%s: calling cy_as_mtp_init_get_object() " | ||
1501 | "start=0x%x, num =0x%x, tid=0x%x, " | ||
1502 | "num_bytes=0x%x\n", | ||
1503 | __func__, | ||
1504 | blk_table.start_blocks[0], | ||
1505 | blk_table.num_blocks[0], | ||
1506 | k_d.tid, | ||
1507 | k_d.num_bytes); | ||
1508 | #endif | ||
1509 | |||
1510 | ret_stat = cy_as_mtp_init_get_object( | ||
1511 | dev->dev_handle, | ||
1512 | (cy_as_mtp_block_table *)&sg, | ||
1513 | k_d.num_bytes, k_d.tid, 0, 0); | ||
1514 | if (ret_stat != CY_AS_ERROR_SUCCESS) { | ||
1515 | #ifndef WESTBRIDGE_NDEBUG | ||
1516 | cy_as_hal_print_message( | ||
1517 | "%s: cy_as_mtp_init_get_object " | ||
1518 | "failed ret_stat=0x%x\n", | ||
1519 | __func__, ret_stat); | ||
1520 | #endif | ||
1521 | } | ||
1522 | } | ||
1523 | #ifndef WESTBRIDGE_NDEBUG | ||
1524 | else { | ||
1525 | cy_as_hal_print_message( | ||
1526 | "%s: failed to open file %s\n", | ||
1527 | __func__, map_filename); | ||
1528 | } | ||
1529 | #endif | ||
1530 | kfree(map_filename); | ||
1531 | |||
1532 | ret_stat = 0; | ||
1533 | retval = __put_user(ret_stat, (uint32_t __user *) | ||
1534 | (&(usr_d->ret_val))); | ||
1535 | break; | ||
1536 | } | ||
1537 | case CYASGADGET_CANCELSOJ: | ||
1538 | { | ||
1539 | cy_as_gadget_ioctl_cancel *usr_d = | ||
1540 | (cy_as_gadget_ioctl_cancel *)param; | ||
1541 | |||
1542 | #ifndef WESTBRIDGE_NDEBUG | ||
1543 | cy_as_hal_print_message( | ||
1544 | "%s: got CYASGADGET_CANCELSOJ\n", | ||
1545 | __func__); | ||
1546 | #endif | ||
1547 | |||
1548 | ret_stat = cy_as_mtp_cancel_send_object(dev->dev_handle, 0, 0); | ||
1549 | |||
1550 | retval = __put_user(ret_stat, (uint32_t __user *) | ||
1551 | (&(usr_d->ret_val))); | ||
1552 | break; | ||
1553 | } | ||
1554 | case CYASGADGET_CANCELGOJ: | ||
1555 | { | ||
1556 | cy_as_gadget_ioctl_cancel *usr_d = | ||
1557 | (cy_as_gadget_ioctl_cancel *)param; | ||
1558 | |||
1559 | #ifndef WESTBRIDGE_NDEBUG | ||
1560 | cy_as_hal_print_message("%s: got CYASGADGET_CANCELGOJ\n", | ||
1561 | __func__); | ||
1562 | #endif | ||
1563 | |||
1564 | ret_stat = cy_as_mtp_cancel_get_object(dev->dev_handle, 0, 0); | ||
1565 | |||
1566 | retval = __put_user(ret_stat, | ||
1567 | (uint32_t __user *)(&(usr_d->ret_val))); | ||
1568 | break; | ||
1569 | } | ||
1570 | default: | ||
1571 | { | ||
1572 | #ifndef WESTBRIDGE_NDEBUG | ||
1573 | cy_as_hal_print_message("%s: unknown ioctl received: %d\n", | ||
1574 | __func__, code); | ||
1575 | |||
1576 | cy_as_hal_print_message("%s: known codes:\n" | ||
1577 | "CYASGADGET_GETMTPSTATUS=%d\n" | ||
1578 | "CYASGADGET_CLEARTMTPSTATUS=%d\n" | ||
1579 | "CYASGADGET_INITSOJ=%d\n" | ||
1580 | "CYASGADGET_INITGOJ=%d\n" | ||
1581 | "CYASGADGET_CANCELSOJ=%d\n" | ||
1582 | "CYASGADGET_CANCELGOJ=%d\n", | ||
1583 | __func__, | ||
1584 | CYASGADGET_GETMTPSTATUS, | ||
1585 | CYASGADGET_CLEARTMTPSTATUS, | ||
1586 | CYASGADGET_INITSOJ, | ||
1587 | CYASGADGET_INITGOJ, | ||
1588 | CYASGADGET_CANCELSOJ, | ||
1589 | CYASGADGET_CANCELGOJ); | ||
1590 | #endif | ||
1591 | break; | ||
1592 | } | ||
1593 | } | ||
1594 | |||
1595 | return 0; | ||
1596 | } | ||
1597 | |||
1598 | static int cyasgadget_start(struct usb_gadget_driver *driver, | ||
1599 | int (*bind)(struct usb_gadget *)); | ||
1600 | static int cyasgadget_stop(struct usb_gadget_driver *driver); | ||
1601 | |||
1602 | static const struct usb_gadget_ops cyasgadget_ops = { | ||
1603 | .get_frame = cyasgadget_get_frame, | ||
1604 | .wakeup = cyasgadget_wakeup, | ||
1605 | .set_selfpowered = cyasgadget_set_selfpowered, | ||
1606 | .pullup = cyasgadget_pullup, | ||
1607 | .ioctl = cyasgadget_ioctl, | ||
1608 | .start = cyasgadget_start, | ||
1609 | .stop = cyasgadget_stop, | ||
1610 | }; | ||
1611 | |||
1612 | |||
1613 | /* keeping it simple: | ||
1614 | * - one bus driver, initted first; | ||
1615 | * - one function driver, initted second | ||
1616 | * | ||
1617 | * most of the work to support multiple controllers would | ||
1618 | * be to associate this gadget driver with all of them, or | ||
1619 | * perhaps to bind specific drivers to specific devices. | ||
1620 | */ | ||
1621 | |||
1622 | static void cyas_ep_reset( | ||
1623 | cyasgadget_ep *an_ep | ||
1624 | ) | ||
1625 | { | ||
1626 | #ifndef WESTBRIDGE_NDEBUG | ||
1627 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
1628 | #endif | ||
1629 | |||
1630 | an_ep->desc = NULL; | ||
1631 | INIT_LIST_HEAD(&an_ep->queue); | ||
1632 | |||
1633 | an_ep->stopped = 0; | ||
1634 | an_ep->is_in = 0; | ||
1635 | an_ep->is_iso = 0; | ||
1636 | an_ep->usb_ep_inst.maxpacket = ~0; | ||
1637 | an_ep->usb_ep_inst.ops = &cyasgadget_ep_ops; | ||
1638 | } | ||
1639 | |||
1640 | static void cyas_usb_reset( | ||
1641 | cyasgadget *cy_as_dev | ||
1642 | ) | ||
1643 | { | ||
1644 | cy_as_return_status_t ret; | ||
1645 | cy_as_usb_enum_control config; | ||
1646 | |||
1647 | #ifndef WESTBRIDGE_NDEBUG | ||
1648 | cy_as_device *dev_p = (cy_as_device *)cy_as_dev->dev_handle; | ||
1649 | |||
1650 | cy_as_hal_print_message("<1>%s called mtp_firmware=0x%x\n", | ||
1651 | __func__, dev_p->is_mtp_firmware); | ||
1652 | #endif | ||
1653 | |||
1654 | ret = cy_as_misc_release_resource(cy_as_dev->dev_handle, | ||
1655 | cy_as_bus_u_s_b); | ||
1656 | if (ret != CY_AS_ERROR_SUCCESS && ret != | ||
1657 | CY_AS_ERROR_RESOURCE_NOT_OWNED) { | ||
1658 | cy_as_hal_print_message("<1>_cy_as_gadget: cannot " | ||
1659 | "release usb resource: failed with error code %d\n", | ||
1660 | ret); | ||
1661 | return; | ||
1662 | } | ||
1663 | |||
1664 | cy_as_dev->gadget.speed = USB_SPEED_HIGH; | ||
1665 | |||
1666 | ret = cy_as_usb_start(cy_as_dev->dev_handle, 0, 0); | ||
1667 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1668 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
1669 | "cy_as_usb_start failed with error code %d\n", | ||
1670 | ret); | ||
1671 | return; | ||
1672 | } | ||
1673 | /* P port will do enumeration, not West Bridge */ | ||
1674 | config.antioch_enumeration = cy_false; | ||
1675 | /* 1 2 : 1-BUS_NUM , 2:Storage_device number, SD - is bus 1*/ | ||
1676 | |||
1677 | /* TODO: add module param to enumerate mass storage */ | ||
1678 | config.mass_storage_interface = 0; | ||
1679 | |||
1680 | if (append_mtp) { | ||
1681 | ret = cy_as_mtp_start(cy_as_dev->dev_handle, | ||
1682 | cy_as_gadget_mtp_event_callback, 0, 0); | ||
1683 | if (ret == CY_AS_ERROR_SUCCESS) { | ||
1684 | cy_as_hal_print_message("MTP start passed, enumerating " | ||
1685 | "MTP interface\n"); | ||
1686 | config.mtp_interface = append_mtp; | ||
1687 | /*Do not enumerate NAND storage*/ | ||
1688 | config.devices_to_enumerate[0][0] = cy_false; | ||
1689 | |||
1690 | /*enumerate SD storage as MTP*/ | ||
1691 | config.devices_to_enumerate[1][0] = cy_true; | ||
1692 | } | ||
1693 | } else { | ||
1694 | cy_as_hal_print_message("MTP start not attempted, not " | ||
1695 | "enumerating MTP interface\n"); | ||
1696 | config.mtp_interface = 0; | ||
1697 | /* enumerate mass storage based on module parameters */ | ||
1698 | config.devices_to_enumerate[0][0] = msc_enum_bus_0; | ||
1699 | config.devices_to_enumerate[1][0] = msc_enum_bus_1; | ||
1700 | } | ||
1701 | |||
1702 | ret = cy_as_usb_set_enum_config(cy_as_dev->dev_handle, | ||
1703 | &config, 0, 0); | ||
1704 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1705 | cy_as_hal_print_message("<1>_cy_as_gadget: " | ||
1706 | "cy_as_usb_set_enum_config failed with error " | ||
1707 | "code %d\n", ret); | ||
1708 | return; | ||
1709 | } | ||
1710 | |||
1711 | cy_as_usb_set_physical_configuration(cy_as_dev->dev_handle, 1); | ||
1712 | |||
1713 | } | ||
1714 | |||
1715 | static void cyas_usb_reinit( | ||
1716 | cyasgadget *cy_as_dev | ||
1717 | ) | ||
1718 | { | ||
1719 | int index = 0; | ||
1720 | cyasgadget_ep *an_ep_p; | ||
1721 | cy_as_return_status_t ret; | ||
1722 | cy_as_device *dev_p = (cy_as_device *)cy_as_dev->dev_handle; | ||
1723 | |||
1724 | INIT_LIST_HEAD(&cy_as_dev->gadget.ep_list); | ||
1725 | |||
1726 | #ifndef WESTBRIDGE_NDEBUG | ||
1727 | cy_as_hal_print_message("<1>%s called, is_mtp_firmware = " | ||
1728 | "0x%x\n", __func__, dev_p->is_mtp_firmware); | ||
1729 | #endif | ||
1730 | |||
1731 | /* Init the end points */ | ||
1732 | for (index = 1; index <= 15; index++) { | ||
1733 | an_ep_p = &cy_as_dev->an_gadget_ep[index]; | ||
1734 | cyas_ep_reset(an_ep_p); | ||
1735 | an_ep_p->usb_ep_inst.name = cy_as_ep_names[index]; | ||
1736 | an_ep_p->dev = cy_as_dev; | ||
1737 | an_ep_p->num = index; | ||
1738 | memset(&an_ep_p->cyepconfig, 0, sizeof(an_ep_p->cyepconfig)); | ||
1739 | |||
1740 | /* EP0, EPs 2,4,6,8 need not be added */ | ||
1741 | if ((index <= 8) && (index % 2 == 0) && | ||
1742 | (!dev_p->is_mtp_firmware)) { | ||
1743 | /* EP0 is 64 and EPs 2,4,6,8 not allowed */ | ||
1744 | cy_as_dev->an_gadget_ep[index].fifo_size = 0; | ||
1745 | } else { | ||
1746 | if (index == 1) | ||
1747 | an_ep_p->fifo_size = 64; | ||
1748 | else | ||
1749 | an_ep_p->fifo_size = 512; | ||
1750 | list_add_tail(&an_ep_p->usb_ep_inst.ep_list, | ||
1751 | &cy_as_dev->gadget.ep_list); | ||
1752 | } | ||
1753 | } | ||
1754 | /* need to setendpointconfig before usb connect, this is not | ||
1755 | * quite compatible with gadget methodology (ep_enable called | ||
1756 | * by gadget after connect), therefore need to set config in | ||
1757 | * initialization and verify compatibility in ep_enable, | ||
1758 | * kick up error otherwise*/ | ||
1759 | an_ep_p = &cy_as_dev->an_gadget_ep[3]; | ||
1760 | an_ep_p->cyepconfig.enabled = cy_true; | ||
1761 | an_ep_p->cyepconfig.dir = cy_as_usb_out; | ||
1762 | an_ep_p->cyepconfig.type = cy_as_usb_bulk; | ||
1763 | an_ep_p->cyepconfig.size = 0; | ||
1764 | an_ep_p->cyepconfig.physical = 1; | ||
1765 | ret = cy_as_usb_set_end_point_config(an_ep_p->dev->dev_handle, | ||
1766 | 3, &an_ep_p->cyepconfig); | ||
1767 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1768 | cy_as_hal_print_message("cy_as_usb_set_end_point_config " | ||
1769 | "failed with error code %d\n", ret); | ||
1770 | } | ||
1771 | |||
1772 | cy_as_usb_set_stall(an_ep_p->dev->dev_handle, 3, 0, 0); | ||
1773 | |||
1774 | an_ep_p = &cy_as_dev->an_gadget_ep[5]; | ||
1775 | an_ep_p->cyepconfig.enabled = cy_true; | ||
1776 | an_ep_p->cyepconfig.dir = cy_as_usb_in; | ||
1777 | an_ep_p->cyepconfig.type = cy_as_usb_bulk; | ||
1778 | an_ep_p->cyepconfig.size = 0; | ||
1779 | an_ep_p->cyepconfig.physical = 2; | ||
1780 | ret = cy_as_usb_set_end_point_config(an_ep_p->dev->dev_handle, | ||
1781 | 5, &an_ep_p->cyepconfig); | ||
1782 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1783 | cy_as_hal_print_message("cy_as_usb_set_end_point_config " | ||
1784 | "failed with error code %d\n", ret); | ||
1785 | } | ||
1786 | |||
1787 | cy_as_usb_set_stall(an_ep_p->dev->dev_handle, 5, 0, 0); | ||
1788 | |||
1789 | an_ep_p = &cy_as_dev->an_gadget_ep[9]; | ||
1790 | an_ep_p->cyepconfig.enabled = cy_true; | ||
1791 | an_ep_p->cyepconfig.dir = cy_as_usb_in; | ||
1792 | an_ep_p->cyepconfig.type = cy_as_usb_bulk; | ||
1793 | an_ep_p->cyepconfig.size = 0; | ||
1794 | an_ep_p->cyepconfig.physical = 4; | ||
1795 | ret = cy_as_usb_set_end_point_config(an_ep_p->dev->dev_handle, | ||
1796 | 9, &an_ep_p->cyepconfig); | ||
1797 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1798 | cy_as_hal_print_message("cy_as_usb_set_end_point_config " | ||
1799 | "failed with error code %d\n", ret); | ||
1800 | } | ||
1801 | |||
1802 | cy_as_usb_set_stall(an_ep_p->dev->dev_handle, 9, 0, 0); | ||
1803 | |||
1804 | if (dev_p->mtp_count != 0) { | ||
1805 | /* these need to be set for compatibility with | ||
1806 | * the gadget_enable logic */ | ||
1807 | an_ep_p = &cy_as_dev->an_gadget_ep[2]; | ||
1808 | an_ep_p->cyepconfig.enabled = cy_true; | ||
1809 | an_ep_p->cyepconfig.dir = cy_as_usb_out; | ||
1810 | an_ep_p->cyepconfig.type = cy_as_usb_bulk; | ||
1811 | an_ep_p->cyepconfig.size = 0; | ||
1812 | an_ep_p->cyepconfig.physical = 0; | ||
1813 | cy_as_usb_set_stall(an_ep_p->dev->dev_handle, 2, 0, 0); | ||
1814 | |||
1815 | an_ep_p = &cy_as_dev->an_gadget_ep[6]; | ||
1816 | an_ep_p->cyepconfig.enabled = cy_true; | ||
1817 | an_ep_p->cyepconfig.dir = cy_as_usb_in; | ||
1818 | an_ep_p->cyepconfig.type = cy_as_usb_bulk; | ||
1819 | an_ep_p->cyepconfig.size = 0; | ||
1820 | an_ep_p->cyepconfig.physical = 0; | ||
1821 | cy_as_usb_set_stall(an_ep_p->dev->dev_handle, 6, 0, 0); | ||
1822 | } | ||
1823 | |||
1824 | cyas_ep_reset(&cy_as_dev->an_gadget_ep[0]); | ||
1825 | cy_as_dev->an_gadget_ep[0].usb_ep_inst.name = cy_as_ep_names[0]; | ||
1826 | cy_as_dev->an_gadget_ep[0].dev = cy_as_dev; | ||
1827 | cy_as_dev->an_gadget_ep[0].num = 0; | ||
1828 | cy_as_dev->an_gadget_ep[0].fifo_size = 64; | ||
1829 | |||
1830 | cy_as_dev->an_gadget_ep[0].usb_ep_inst.maxpacket = 64; | ||
1831 | cy_as_dev->gadget.ep0 = &cy_as_dev->an_gadget_ep[0].usb_ep_inst; | ||
1832 | cy_as_dev->an_gadget_ep[0].stopped = 0; | ||
1833 | INIT_LIST_HEAD(&cy_as_dev->gadget.ep0->ep_list); | ||
1834 | } | ||
1835 | |||
1836 | static void cyas_ep0_start( | ||
1837 | cyasgadget *dev | ||
1838 | ) | ||
1839 | { | ||
1840 | cy_as_return_status_t ret; | ||
1841 | |||
1842 | #ifndef WESTBRIDGE_NDEBUG | ||
1843 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
1844 | #endif | ||
1845 | |||
1846 | ret = cy_as_usb_register_callback(dev->dev_handle, | ||
1847 | cy_as_gadget_usb_event_callback); | ||
1848 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1849 | #ifndef WESTBRIDGE_NDEBUG | ||
1850 | cy_as_hal_print_message("%s: cy_as_usb_register_callback " | ||
1851 | "failed with error code %d\n", __func__, ret); | ||
1852 | #endif | ||
1853 | return; | ||
1854 | } | ||
1855 | |||
1856 | ret = cy_as_usb_commit_config(dev->dev_handle, 0, 0); | ||
1857 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1858 | #ifndef WESTBRIDGE_NDEBUG | ||
1859 | cy_as_hal_print_message("%s: cy_as_usb_commit_config " | ||
1860 | "failed with error code %d\n", __func__, ret); | ||
1861 | #endif | ||
1862 | return; | ||
1863 | } | ||
1864 | |||
1865 | #ifndef WESTBRIDGE_NDEBUG | ||
1866 | cy_as_hal_print_message("%s: cy_as_usb_commit_config " | ||
1867 | "message sent\n", __func__); | ||
1868 | #endif | ||
1869 | |||
1870 | ret = cy_as_usb_connect(dev->dev_handle, 0, 0); | ||
1871 | if (ret != CY_AS_ERROR_SUCCESS) { | ||
1872 | #ifndef WESTBRIDGE_NDEBUG | ||
1873 | cy_as_hal_print_message("%s: cy_as_usb_connect failed " | ||
1874 | "with error code %d\n", __func__, ret); | ||
1875 | #endif | ||
1876 | return; | ||
1877 | } | ||
1878 | |||
1879 | #ifndef WESTBRIDGE_NDEBUG | ||
1880 | cy_as_hal_print_message("%s: cy_as_usb_connect message " | ||
1881 | "sent\n", __func__); | ||
1882 | #endif | ||
1883 | } | ||
1884 | |||
1885 | /* | ||
1886 | * When a driver is successfully registered, it will receive | ||
1887 | * control requests including set_configuration(), which enables | ||
1888 | * non-control requests. then usb traffic follows until a | ||
1889 | * disconnect is reported. then a host may connect again, or | ||
1890 | * the driver might get unbound. | ||
1891 | */ | ||
1892 | static int cyasgadget_start(struct usb_gadget_driver *driver, | ||
1893 | int (*bind)(struct usb_gadget *)) | ||
1894 | { | ||
1895 | cyasgadget *dev = cy_as_gadget_controller; | ||
1896 | int retval; | ||
1897 | |||
1898 | #ifndef WESTBRIDGE_NDEBUG | ||
1899 | cy_as_hal_print_message("<1>%s called driver=0x%x\n", | ||
1900 | __func__, (unsigned int) driver); | ||
1901 | #endif | ||
1902 | |||
1903 | /* insist on high speed support from the driver, since | ||
1904 | * "must not be used in normal operation" | ||
1905 | */ | ||
1906 | if (!driver | ||
1907 | || !bind | ||
1908 | || !driver->unbind | ||
1909 | || !driver->setup) | ||
1910 | return -EINVAL; | ||
1911 | |||
1912 | if (!dev) | ||
1913 | return -ENODEV; | ||
1914 | |||
1915 | if (dev->driver) | ||
1916 | return -EBUSY; | ||
1917 | |||
1918 | /* hook up the driver ... */ | ||
1919 | dev->softconnect = 1; | ||
1920 | driver->driver.bus = NULL; | ||
1921 | dev->driver = driver; | ||
1922 | dev->gadget.dev.driver = &driver->driver; | ||
1923 | |||
1924 | /* Do the needful */ | ||
1925 | cyas_usb_reset(dev); /* External usb */ | ||
1926 | cyas_usb_reinit(dev); /* Internal */ | ||
1927 | |||
1928 | retval = bind(&dev->gadget); | ||
1929 | if (retval) { | ||
1930 | #ifndef WESTBRIDGE_NDEBUG | ||
1931 | cy_as_hal_print_message("%s bind to driver %s --> %d\n", | ||
1932 | __func__, driver->driver.name, retval); | ||
1933 | #endif | ||
1934 | |||
1935 | dev->driver = NULL; | ||
1936 | dev->gadget.dev.driver = NULL; | ||
1937 | return retval; | ||
1938 | } | ||
1939 | |||
1940 | /* ... then enable host detection and ep0; and we're ready | ||
1941 | * for set_configuration as well as eventual disconnect. | ||
1942 | */ | ||
1943 | cyas_ep0_start(dev); | ||
1944 | |||
1945 | return 0; | ||
1946 | } | ||
1947 | |||
1948 | static void cyasgadget_nuke( | ||
1949 | cyasgadget_ep *an_ep | ||
1950 | ) | ||
1951 | { | ||
1952 | cyasgadget *dev = cy_as_gadget_controller; | ||
1953 | |||
1954 | #ifndef WESTBRIDGE_NDEBUG | ||
1955 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
1956 | #endif | ||
1957 | |||
1958 | cy_as_usb_cancel_async(dev->dev_handle, an_ep->num); | ||
1959 | an_ep->stopped = 1; | ||
1960 | |||
1961 | while (!list_empty(&an_ep->queue)) { | ||
1962 | cyasgadget_req *an_req = list_entry | ||
1963 | (an_ep->queue.next, cyasgadget_req, queue); | ||
1964 | list_del_init(&an_req->queue); | ||
1965 | an_req->req.status = -ESHUTDOWN; | ||
1966 | an_req->req.complete(&an_ep->usb_ep_inst, &an_req->req); | ||
1967 | } | ||
1968 | } | ||
1969 | |||
1970 | static void cyasgadget_stop_activity( | ||
1971 | cyasgadget *dev, | ||
1972 | struct usb_gadget_driver *driver | ||
1973 | ) | ||
1974 | { | ||
1975 | int index; | ||
1976 | |||
1977 | #ifndef WESTBRIDGE_NDEBUG | ||
1978 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
1979 | #endif | ||
1980 | |||
1981 | /* don't disconnect if it's not connected */ | ||
1982 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1983 | driver = NULL; | ||
1984 | |||
1985 | if (spin_is_locked(&dev->lock)) | ||
1986 | spin_unlock(&dev->lock); | ||
1987 | |||
1988 | /* Stop hardware; prevent new request submissions; | ||
1989 | * and kill any outstanding requests. | ||
1990 | */ | ||
1991 | cy_as_usb_disconnect(dev->dev_handle, 0, 0); | ||
1992 | |||
1993 | for (index = 3; index <= 7; index += 2) { | ||
1994 | cyasgadget_ep *an_ep_p = &dev->an_gadget_ep[index]; | ||
1995 | cyasgadget_nuke(an_ep_p); | ||
1996 | } | ||
1997 | |||
1998 | for (index = 9; index <= 15; index++) { | ||
1999 | cyasgadget_ep *an_ep_p = &dev->an_gadget_ep[index]; | ||
2000 | cyasgadget_nuke(an_ep_p); | ||
2001 | } | ||
2002 | |||
2003 | /* report disconnect; the driver is already quiesced */ | ||
2004 | if (driver) | ||
2005 | driver->disconnect(&dev->gadget); | ||
2006 | |||
2007 | #ifndef WESTBRIDGE_NDEBUG | ||
2008 | cy_as_hal_print_message("cy_as_usb_disconnect returned success"); | ||
2009 | #endif | ||
2010 | |||
2011 | /* Stop Usb */ | ||
2012 | cy_as_usb_stop(dev->dev_handle, 0, 0); | ||
2013 | |||
2014 | #ifndef WESTBRIDGE_NDEBUG | ||
2015 | cy_as_hal_print_message("cy_as_usb_stop returned success"); | ||
2016 | #endif | ||
2017 | } | ||
2018 | |||
2019 | static int cyasgadget_stop( | ||
2020 | struct usb_gadget_driver *driver | ||
2021 | ) | ||
2022 | { | ||
2023 | cyasgadget *dev = cy_as_gadget_controller; | ||
2024 | |||
2025 | #ifndef WESTBRIDGE_NDEBUG | ||
2026 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
2027 | #endif | ||
2028 | |||
2029 | if (!dev) | ||
2030 | return -ENODEV; | ||
2031 | |||
2032 | if (!driver || driver != dev->driver) | ||
2033 | return -EINVAL; | ||
2034 | |||
2035 | cyasgadget_stop_activity(dev, driver); | ||
2036 | |||
2037 | driver->unbind(&dev->gadget); | ||
2038 | dev->gadget.dev.driver = NULL; | ||
2039 | dev->driver = NULL; | ||
2040 | |||
2041 | #ifndef WESTBRIDGE_NDEBUG | ||
2042 | cy_as_hal_print_message("unregistered driver '%s'\n", | ||
2043 | driver->driver.name); | ||
2044 | #endif | ||
2045 | |||
2046 | return 0; | ||
2047 | } | ||
2048 | |||
2049 | static void cyas_gadget_release( | ||
2050 | struct device *_dev | ||
2051 | ) | ||
2052 | { | ||
2053 | cyasgadget *dev = dev_get_drvdata(_dev); | ||
2054 | |||
2055 | #ifndef WESTBRIDGE_NDEBUG | ||
2056 | cy_as_hal_print_message("<1>%s called\n", __func__); | ||
2057 | #endif | ||
2058 | |||
2059 | kfree(dev); | ||
2060 | } | ||
2061 | |||
2062 | /* DeInitialize gadget driver */ | ||
2063 | static void cyasgadget_deinit( | ||
2064 | cyasgadget *cy_as_dev | ||
2065 | ) | ||
2066 | { | ||
2067 | #ifndef WESTBRIDGE_NDEBUG | ||
2068 | cy_as_hal_print_message("<1>_cy_as_gadget deinitialize called\n"); | ||
2069 | #endif | ||
2070 | |||
2071 | if (!cy_as_dev) { | ||
2072 | #ifndef WESTBRIDGE_NDEBUG | ||
2073 | cy_as_hal_print_message("<1>_cy_as_gadget_deinit: " | ||
2074 | "invalid cyasgadget device\n"); | ||
2075 | #endif | ||
2076 | return; | ||
2077 | } | ||
2078 | usb_del_gadget_udc(&cy_as_dev->gadget); | ||
2079 | |||
2080 | if (cy_as_dev->driver) { | ||
2081 | /* should have been done already by driver model core */ | ||
2082 | #ifndef WESTBRIDGE_NDEBUG | ||
2083 | cy_as_hal_print_message("<1> cy_as_gadget: '%s' " | ||
2084 | "is still registered\n", | ||
2085 | cy_as_dev->driver->driver.name); | ||
2086 | #endif | ||
2087 | usb_gadget_unregister_driver(cy_as_dev->driver); | ||
2088 | } | ||
2089 | |||
2090 | kfree(cy_as_dev); | ||
2091 | cy_as_gadget_controller = NULL; | ||
2092 | } | ||
2093 | |||
2094 | /* Initialize gadget driver */ | ||
2095 | static int cyasgadget_initialize(void) | ||
2096 | { | ||
2097 | cyasgadget *cy_as_dev = 0; | ||
2098 | int retval = 0; | ||
2099 | |||
2100 | #ifndef WESTBRIDGE_NDEBUG | ||
2101 | cy_as_hal_print_message("<1>_cy_as_gadget [V1.1] initialize called\n"); | ||
2102 | #endif | ||
2103 | |||
2104 | if (cy_as_gadget_controller != 0) { | ||
2105 | cy_as_hal_print_message("<1> cy_as_gadget: the device has " | ||
2106 | "already been initilaized. ignoring\n"); | ||
2107 | return -EBUSY; | ||
2108 | } | ||
2109 | |||
2110 | cy_as_dev = kzalloc(sizeof(cyasgadget), GFP_ATOMIC); | ||
2111 | if (cy_as_dev == NULL) { | ||
2112 | cy_as_hal_print_message("<1> cy_as_gadget: memory " | ||
2113 | "allocation failed\n"); | ||
2114 | return -ENOMEM; | ||
2115 | } | ||
2116 | |||
2117 | spin_lock_init(&cy_as_dev->lock); | ||
2118 | cy_as_dev->gadget.ops = &cyasgadget_ops; | ||
2119 | cy_as_dev->gadget.is_dualspeed = 1; | ||
2120 | |||
2121 | /* the "gadget" abstracts/virtualizes the controller */ | ||
2122 | /*strcpy(cy_as_dev->gadget.dev.bus_id, "cyasgadget");*/ | ||
2123 | cy_as_dev->gadget.dev.release = cyas_gadget_release; | ||
2124 | cy_as_dev->gadget.name = cy_as_driver_name; | ||
2125 | |||
2126 | /* Get the device handle */ | ||
2127 | cy_as_dev->dev_handle = cyasdevice_getdevhandle(); | ||
2128 | if (0 == cy_as_dev->dev_handle) { | ||
2129 | #ifndef NDEBUG | ||
2130 | cy_as_hal_print_message("<1> cy_as_gadget: " | ||
2131 | "no west bridge device\n"); | ||
2132 | #endif | ||
2133 | retval = -EFAULT; | ||
2134 | goto done; | ||
2135 | } | ||
2136 | |||
2137 | /* We are done now */ | ||
2138 | cy_as_gadget_controller = cy_as_dev; | ||
2139 | #if 0 | ||
2140 | pdev is the platform_device or pci_device or whatever is used here | ||
2141 | retval = usb_add_gadget_udc(&pdev->dev, &cy_as_dev->gadget); | ||
2142 | if (retval) | ||
2143 | goto done; | ||
2144 | #endif | ||
2145 | |||
2146 | return 0; | ||
2147 | |||
2148 | /* | ||
2149 | * in case of an error | ||
2150 | */ | ||
2151 | done: | ||
2152 | if (cy_as_dev) | ||
2153 | cyasgadget_deinit(cy_as_dev); | ||
2154 | |||
2155 | return retval; | ||
2156 | } | ||
2157 | |||
2158 | static int __init cyas_init(void) | ||
2159 | { | ||
2160 | int init_res = 0; | ||
2161 | |||
2162 | init_res = cyasgadget_initialize(); | ||
2163 | |||
2164 | if (init_res != 0) { | ||
2165 | printk(KERN_WARNING "<1> gadget ctl instance " | ||
2166 | "init error:%d\n", init_res); | ||
2167 | if (init_res > 0) { | ||
2168 | /* force -E/0 linux convention */ | ||
2169 | init_res = init_res * -1; | ||
2170 | } | ||
2171 | } | ||
2172 | |||
2173 | return init_res; | ||
2174 | } | ||
2175 | module_init(cyas_init); | ||
2176 | |||
2177 | static void __exit cyas_cleanup(void) | ||
2178 | { | ||
2179 | if (cy_as_gadget_controller != NULL) | ||
2180 | cyasgadget_deinit(cy_as_gadget_controller); | ||
2181 | } | ||
2182 | module_exit(cyas_cleanup); | ||
2183 | |||
2184 | |||
2185 | MODULE_LICENSE("GPL"); | ||
2186 | MODULE_DESCRIPTION(CY_AS_DRIVER_DESC); | ||
2187 | MODULE_AUTHOR("cypress semiconductor"); | ||
2188 | |||
2189 | /*[]*/ | ||
diff --git a/drivers/staging/westbridge/astoria/gadget/cyasgadget.h b/drivers/staging/westbridge/astoria/gadget/cyasgadget.h deleted file mode 100644 index e01cea7eeb77..000000000000 --- a/drivers/staging/westbridge/astoria/gadget/cyasgadget.h +++ /dev/null | |||
@@ -1,193 +0,0 @@ | |||
1 | /* cyangadget.h - Linux USB Gadget driver file for the Cypress West Bridge | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * Cypress West Bridge high/full speed USB device controller code | ||
24 | * Based on the Netchip 2280 device controller by David Brownell | ||
25 | * in the linux 2.6.10 kernel | ||
26 | * | ||
27 | * linux/drivers/usb/gadget/net2280.h | ||
28 | */ | ||
29 | |||
30 | /* | ||
31 | * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com) | ||
32 | * Copyright (C) 2003 David Brownell | ||
33 | * | ||
34 | * This program is free software; you can redistribute it and/or modify | ||
35 | * it under the terms of the GNU General Public License as published by | ||
36 | * the Free Software Foundation; either version 2 of the License, or | ||
37 | * (at your option) any later version. | ||
38 | * | ||
39 | * This program is distributed in the hope that it will be useful, | ||
40 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
41 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
42 | * GNU General Public License for more details. | ||
43 | * | ||
44 | * You should have received a copy of the GNU General Public License | ||
45 | * along with this program; if not, write to the Free Software | ||
46 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
47 | */ | ||
48 | |||
49 | #ifndef _INCLUDED_CYANGADGET_H_ | ||
50 | #define _INCLUDED_CYANGADGET_H_ | ||
51 | |||
52 | #include <linux/device.h> | ||
53 | #include <linux/moduleparam.h> | ||
54 | #include <linux/usb/ch9.h> | ||
55 | #include <linux/usb/gadget.h> | ||
56 | #include <linux/sched.h> | ||
57 | |||
58 | #include "../include/linux/westbridge/cyastoria.h" | ||
59 | #include "../include/linux/westbridge/cyashal.h" | ||
60 | #include "../include/linux/westbridge/cyasdevice.h" | ||
61 | #include "cyasgadget_ioctl.h" | ||
62 | |||
63 | #include <linux/module.h> | ||
64 | #include <linux/init.h> | ||
65 | |||
66 | /*char driver defines, revisit*/ | ||
67 | #include <linux/module.h> | ||
68 | #include <linux/moduleparam.h> | ||
69 | #include <linux/init.h> | ||
70 | #include <linux/fs.h> /* everything... */ | ||
71 | #include <linux/errno.h> /* error codes */ | ||
72 | #include <linux/types.h> /* size_t */ | ||
73 | #include <linux/proc_fs.h> | ||
74 | #include <linux/fcntl.h> /* O_ACCMODE */ | ||
75 | #include <linux/seq_file.h> | ||
76 | #include <linux/cdev.h> | ||
77 | #include <linux/scatterlist.h> | ||
78 | #include <linux/pagemap.h> | ||
79 | #include <linux/vmalloc.h> /* vmalloc(), vfree */ | ||
80 | #include <linux/msdos_fs.h> /*fat_alloc_cluster*/ | ||
81 | #include <linux/buffer_head.h> | ||
82 | #include <asm/system.h> /* cli(), *_flags */ | ||
83 | #include <linux/uaccess.h> /* copy_*_user */ | ||
84 | |||
85 | extern int mpage_cleardirty(struct address_space *mapping, int num_pages); | ||
86 | extern int fat_get_block(struct inode *, sector_t , struct buffer_head *, int); | ||
87 | extern cy_as_device_handle *cyasdevice_getdevhandle(void); | ||
88 | |||
89 | /* Driver data structures and utilities */ | ||
90 | typedef struct cyasgadget_ep { | ||
91 | struct usb_ep usb_ep_inst; | ||
92 | struct cyasgadget *dev; | ||
93 | |||
94 | /* analogous to a host-side qh */ | ||
95 | struct list_head queue; | ||
96 | const struct usb_endpoint_descriptor *desc; | ||
97 | unsigned num:8, | ||
98 | fifo_size:12, | ||
99 | in_fifo_validate:1, | ||
100 | out_overflow:1, | ||
101 | stopped:1, | ||
102 | is_in:1, | ||
103 | is_iso:1; | ||
104 | cy_as_usb_end_point_config cyepconfig; | ||
105 | } cyasgadget_ep; | ||
106 | |||
107 | typedef struct cyasgadget_req { | ||
108 | struct usb_request req; | ||
109 | struct list_head queue; | ||
110 | int ep_num; | ||
111 | unsigned mapped:1, | ||
112 | valid:1, | ||
113 | complete:1, | ||
114 | ep_stopped:1; | ||
115 | } cyasgadget_req; | ||
116 | |||
117 | typedef struct cyasgadget { | ||
118 | /* each device provides one gadget, several endpoints */ | ||
119 | struct usb_gadget gadget; | ||
120 | spinlock_t lock; | ||
121 | struct cyasgadget_ep an_gadget_ep[16]; | ||
122 | struct usb_gadget_driver *driver; | ||
123 | /* Handle to the West Bridge device */ | ||
124 | cy_as_device_handle dev_handle; | ||
125 | unsigned enabled:1, | ||
126 | protocol_stall:1, | ||
127 | softconnect:1, | ||
128 | outsetupreq:1; | ||
129 | struct completion thread_complete; | ||
130 | wait_queue_head_t thread_wq; | ||
131 | struct semaphore thread_sem; | ||
132 | struct list_head thread_queue; | ||
133 | |||
134 | cy_bool tmtp_send_complete; | ||
135 | cy_bool tmtp_get_complete; | ||
136 | cy_bool tmtp_need_new_blk_tbl; | ||
137 | /* Data member used to store the SendObjectComplete event data */ | ||
138 | cy_as_mtp_send_object_complete_data tmtp_send_complete_data; | ||
139 | /* Data member used to store the GetObjectComplete event data */ | ||
140 | cy_as_mtp_get_object_complete_data tmtp_get_complete_data; | ||
141 | |||
142 | } cyasgadget; | ||
143 | |||
144 | static inline void set_halt(cyasgadget_ep *ep) | ||
145 | { | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | static inline void clear_halt(cyasgadget_ep *ep) | ||
150 | { | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | #define xprintk(dev, level, fmt, args...) \ | ||
155 | printk(level "%s %s: " fmt, driver_name, \ | ||
156 | pci_name(dev->pdev), ## args) | ||
157 | |||
158 | #ifdef DEBUG | ||
159 | #undef DEBUG | ||
160 | #define DEBUG(dev, fmt, args...) \ | ||
161 | xprintk(dev, KERN_DEBUG, fmt, ## args) | ||
162 | #else | ||
163 | #define DEBUG(dev, fmt, args...) \ | ||
164 | do { } while (0) | ||
165 | #endif /* DEBUG */ | ||
166 | |||
167 | #ifdef VERBOSE | ||
168 | #define VDEBUG DEBUG | ||
169 | #else | ||
170 | #define VDEBUG(dev, fmt, args...) \ | ||
171 | do { } while (0) | ||
172 | #endif /* VERBOSE */ | ||
173 | |||
174 | #define ERROR(dev, fmt, args...) \ | ||
175 | xprintk(dev, KERN_ERR, fmt, ## args) | ||
176 | #define GADG_WARN(dev, fmt, args...) \ | ||
177 | xprintk(dev, KERN_WARNING, fmt, ## args) | ||
178 | #define INFO(dev, fmt, args...) \ | ||
179 | xprintk(dev, KERN_INFO, fmt, ## args) | ||
180 | |||
181 | /*-------------------------------------------------------------------------*/ | ||
182 | |||
183 | static inline void start_out_naking(struct cyasgadget_ep *ep) | ||
184 | { | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | static inline void stop_out_naking(struct cyasgadget_ep *ep) | ||
189 | { | ||
190 | return; | ||
191 | } | ||
192 | |||
193 | #endif /* _INCLUDED_CYANGADGET_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/gadget/cyasgadget_ioctl.h b/drivers/staging/westbridge/astoria/gadget/cyasgadget_ioctl.h deleted file mode 100644 index 21dd716f116e..000000000000 --- a/drivers/staging/westbridge/astoria/gadget/cyasgadget_ioctl.h +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* cyasgadget_ioctl.h - Linux USB Gadget driver ioctl file for | ||
2 | * Cypress West Bridge | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
19 | ## Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef CYASGADGET_IOCTL_H | ||
24 | #define CYASGADGET_IOCTL_H | ||
25 | |||
26 | |||
27 | #include <linux/types.h> | ||
28 | #include <linux/ioctl.h> | ||
29 | |||
30 | typedef struct cy_as_gadget_ioctl_send_object { | ||
31 | uint32_t status; | ||
32 | uint32_t byte_count; | ||
33 | uint32_t transaction_id; | ||
34 | } cy_as_gadget_ioctl_send_object; | ||
35 | |||
36 | typedef struct cy_as_gadget_ioctl_get_object { | ||
37 | uint32_t status; | ||
38 | uint32_t byte_count; | ||
39 | } cy_as_gadget_ioctl_get_object; | ||
40 | |||
41 | |||
42 | typedef struct cy_as_gadget_ioctl_tmtp_status { | ||
43 | cy_bool tmtp_send_complete; | ||
44 | cy_bool tmtp_get_complete; | ||
45 | cy_bool tmtp_need_new_blk_tbl; | ||
46 | cy_as_gadget_ioctl_send_object tmtp_send_complete_data; | ||
47 | cy_as_gadget_ioctl_get_object tmtp_get_complete_data; | ||
48 | uint32_t t_usec; | ||
49 | } cy_as_gadget_ioctl_tmtp_status; | ||
50 | |||
51 | /*Init send object data*/ | ||
52 | typedef struct cy_as_gadget_ioctl_i_s_o_j_d { | ||
53 | uint32_t *blk_addr_p; /* starting sector */ | ||
54 | uint16_t *blk_count_p; /* num of sectors in the block */ | ||
55 | /* number of entries in the blk table */ | ||
56 | uint32_t item_count; | ||
57 | uint32_t num_bytes; | ||
58 | /* in case if more prcise timestamping is done in kernel mode */ | ||
59 | uint32_t t_usec; | ||
60 | uint32_t ret_val; | ||
61 | char *file_name; | ||
62 | uint32_t name_length; | ||
63 | |||
64 | } cy_as_gadget_ioctl_i_s_o_j_d; | ||
65 | |||
66 | |||
67 | /*Init get object data*/ | ||
68 | typedef struct cy_as_gadget_ioctl_i_g_o_j_d { | ||
69 | uint32_t *blk_addr_p; | ||
70 | uint16_t *blk_count_p; | ||
71 | uint32_t item_count; | ||
72 | uint32_t num_bytes; | ||
73 | uint32_t tid; | ||
74 | uint32_t ret_val; | ||
75 | char *file_name; | ||
76 | uint32_t name_length; | ||
77 | |||
78 | } cy_as_gadget_ioctl_i_g_o_j_d; | ||
79 | |||
80 | typedef struct cy_as_gadget_ioctl_cancel { | ||
81 | uint32_t ret_val; | ||
82 | } cy_as_gadget_ioctl_cancel; | ||
83 | |||
84 | #define CYASGADGET_IOC_MAGIC 0xEF | ||
85 | #define CYASGADGET_GETMTPSTATUS \ | ||
86 | _IOW(CYASGADGET_IOC_MAGIC, 0, cy_as_gadget_ioctl_tmtp_status) | ||
87 | #define CYASGADGET_CLEARTMTPSTATUS \ | ||
88 | _IO(CYASGADGET_IOC_MAGIC, 1) | ||
89 | #define CYASGADGET_INITSOJ \ | ||
90 | _IOW(CYASGADGET_IOC_MAGIC, 2, cy_as_gadget_ioctl_i_s_o_j_d) | ||
91 | #define CYASGADGET_INITGOJ \ | ||
92 | _IOW(CYASGADGET_IOC_MAGIC, 3, cy_as_gadget_ioctl_i_g_o_j_d) | ||
93 | #define CYASGADGET_CANCELSOJ \ | ||
94 | _IOW(CYASGADGET_IOC_MAGIC, 4, cy_as_gadget_ioctl_cancel) | ||
95 | #define CYASGADGET_CANCELGOJ \ | ||
96 | _IOW(CYASGADGET_IOC_MAGIC, 5, cy_as_gadget_ioctl_cancel) | ||
97 | #define CYASGADGET_IOC_MAXNR 6 | ||
98 | |||
99 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanerr.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanerr.h deleted file mode 100644 index c7d4ebb020c9..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanerr.h +++ /dev/null | |||
@@ -1,418 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanerr.h) | ||
2 | ## Symbols for backward compatibility with previous releases of Antioch SDK. | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street | ||
19 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef _INCLUDED_CYANERR_H_ | ||
24 | #define _INCLUDED_CYANERR_H_ | ||
25 | |||
26 | #include "cyaserr.h" | ||
27 | |||
28 | #ifndef __doxygen__ | ||
29 | |||
30 | /* | ||
31 | * Function completed successfully. | ||
32 | */ | ||
33 | #define CY_AN_ERROR_SUCCESS (CY_AS_ERROR_SUCCESS) | ||
34 | |||
35 | /* | ||
36 | * A function trying to acquire a resource was unable to do so. | ||
37 | */ | ||
38 | #define CY_AN_ERROR_NOT_ACQUIRED (CY_AS_ERROR_NOT_ACQUIRED) | ||
39 | |||
40 | /* | ||
41 | * A function trying to acquire a resource was unable to do so. | ||
42 | */ | ||
43 | #define CY_AN_ERROR_NOT_RELEASED (CY_AS_ERROR_NOT_RELEASED) | ||
44 | |||
45 | /* | ||
46 | * The West Bridge firmware is not loaded. | ||
47 | */ | ||
48 | #define CY_AN_ERROR_NO_FIRMWARE (CY_AS_ERROR_NO_FIRMWARE) | ||
49 | |||
50 | /* | ||
51 | * A timeout occurred waiting on a response from the West Bridge device | ||
52 | */ | ||
53 | #define CY_AN_ERROR_TIMEOUT (CY_AS_ERROR_TIMEOUT) | ||
54 | |||
55 | /* | ||
56 | * A request to download firmware was made while not in the CONFIG mode | ||
57 | */ | ||
58 | #define CY_AN_ERROR_NOT_IN_CONFIG_MODE (CY_AS_ERROR_NOT_IN_CONFIG_MODE) | ||
59 | |||
60 | /* | ||
61 | * This error is returned if the firmware size specified is too invalid. | ||
62 | */ | ||
63 | #define CY_AN_ERROR_INVALID_SIZE (CY_AS_ERROR_INVALID_SIZE) | ||
64 | |||
65 | /* | ||
66 | * This error is returned if a request is made to acquire a resource that has | ||
67 | * already been acquired. | ||
68 | */ | ||
69 | #define CY_AN_ERROR_RESOURCE_ALREADY_OWNED (CY_AS_ERROR_RESOURCE_ALREADY_OWNED) | ||
70 | |||
71 | /* | ||
72 | * This error is returned if a request is made to release a resource that has | ||
73 | * not previously been acquired. | ||
74 | */ | ||
75 | #define CY_AN_ERROR_RESOURCE_NOT_OWNED (CY_AS_ERROR_RESOURCE_NOT_OWNED) | ||
76 | |||
77 | /* | ||
78 | * This error is returned when a request is made for a media that does not | ||
79 | * exist | ||
80 | */ | ||
81 | #define CY_AN_ERROR_NO_SUCH_MEDIA (CY_AS_ERROR_NO_SUCH_MEDIA) | ||
82 | |||
83 | /* | ||
84 | * This error is returned when a request is made for a device that does | ||
85 | * not exist | ||
86 | */ | ||
87 | #define CY_AN_ERROR_NO_SUCH_DEVICE (CY_AS_ERROR_NO_SUCH_DEVICE) | ||
88 | |||
89 | /* | ||
90 | * This error is returned when a request is made for a unit that does | ||
91 | * not exist | ||
92 | */ | ||
93 | #define CY_AN_ERROR_NO_SUCH_UNIT (CY_AS_ERROR_NO_SUCH_UNIT) | ||
94 | |||
95 | /* | ||
96 | * This error is returned when a request is made for a block that does | ||
97 | * not exist | ||
98 | */ | ||
99 | #define CY_AN_ERROR_INVALID_BLOCK (CY_AS_ERROR_INVALID_BLOCK) | ||
100 | |||
101 | /* | ||
102 | * This error is returned when an invalid trace level is set. | ||
103 | */ | ||
104 | #define CY_AN_ERROR_INVALID_TRACE_LEVEL (CY_AS_ERROR_INVALID_TRACE_LEVEL) | ||
105 | |||
106 | /* | ||
107 | * This error is returned when West Bridge is already in the standby state | ||
108 | * and an attempt is made to put West Bridge into this state again. | ||
109 | */ | ||
110 | #define CY_AN_ERROR_ALREADY_STANDBY (CY_AS_ERROR_ALREADY_STANDBY) | ||
111 | |||
112 | /* | ||
113 | * This error is returned when the API needs to set a pin on the | ||
114 | * West Bridge device, but this is not supported by the underlying HAL | ||
115 | * layer. | ||
116 | */ | ||
117 | #define CY_AN_ERROR_SETTING_WAKEUP_PIN (CY_AS_ERROR_SETTING_WAKEUP_PIN) | ||
118 | |||
119 | /* | ||
120 | * This error is returned when a module is being started that has | ||
121 | * already been started. | ||
122 | */ | ||
123 | #define CY_AN_ERROR_ALREADY_RUNNING (CY_AS_ERROR_ALREADY_RUNNING) | ||
124 | |||
125 | /* | ||
126 | * This error is returned when a module is being stopped that has | ||
127 | * already been stopped. | ||
128 | */ | ||
129 | #define CY_AN_ERROR_NOT_RUNNING (CY_AS_ERROR_NOT_RUNNING) | ||
130 | |||
131 | /* | ||
132 | * This error is returned when the caller tries to claim a media that has | ||
133 | * already been claimed. | ||
134 | */ | ||
135 | #define CY_AN_ERROR_MEDIA_ALREADY_CLAIMED (CY_AS_ERROR_MEDIA_ALREADY_CLAIMED) | ||
136 | |||
137 | /* | ||
138 | * This error is returned when the caller tries to release a media that | ||
139 | * has already been released. | ||
140 | */ | ||
141 | #define CY_AN_ERROR_MEDIA_NOT_CLAIMED (CY_AS_ERROR_MEDIA_NOT_CLAIMED) | ||
142 | |||
143 | /* | ||
144 | * This error is returned when canceling trying to cancel an asynchronous | ||
145 | * operation when an async operation is not pending. | ||
146 | */ | ||
147 | #define CY_AN_ERROR_NO_OPERATION_PENDING (CY_AS_ERROR_NO_OPERATION_PENDING) | ||
148 | |||
149 | /* | ||
150 | * This error is returned when an invalid endpoint number is provided | ||
151 | * to an API call. | ||
152 | */ | ||
153 | #define CY_AN_ERROR_INVALID_ENDPOINT (CY_AS_ERROR_INVALID_ENDPOINT) | ||
154 | |||
155 | /* | ||
156 | * This error is returned when an invalid descriptor type | ||
157 | * is specified in an API call. | ||
158 | */ | ||
159 | #define CY_AN_ERROR_INVALID_DESCRIPTOR (CY_AS_ERROR_INVALID_DESCRIPTOR) | ||
160 | |||
161 | /* | ||
162 | * This error is returned when an invalid descriptor index | ||
163 | * is specified in an API call. | ||
164 | */ | ||
165 | #define CY_AN_ERROR_BAD_INDEX (CY_AS_ERROR_BAD_INDEX) | ||
166 | |||
167 | /* | ||
168 | * This error is returned if trying to set a USB descriptor | ||
169 | * when in the P port enumeration mode. | ||
170 | */ | ||
171 | #define CY_AN_ERROR_BAD_ENUMERATION_MODE (CY_AS_ERROR_BAD_ENUMERATION_MODE) | ||
172 | |||
173 | /* | ||
174 | * This error is returned when the endpoint configuration specified | ||
175 | * is not valid. | ||
176 | */ | ||
177 | #define CY_AN_ERROR_INVALID_CONFIGURATION (CY_AS_ERROR_INVALID_CONFIGURATION) | ||
178 | |||
179 | /* | ||
180 | * This error is returned when the API cannot verify it is connected | ||
181 | * to an West Bridge device. | ||
182 | */ | ||
183 | #define CY_AN_ERROR_NO_ANTIOCH (CY_AS_ERROR_NO_ANTIOCH) | ||
184 | |||
185 | /* | ||
186 | * This error is returned when an API function is called and | ||
187 | * CyAnMiscConfigureDevice has not been called to configure West | ||
188 | * Bridge for the current environment. | ||
189 | */ | ||
190 | #define CY_AN_ERROR_NOT_CONFIGURED (CY_AS_ERROR_NOT_CONFIGURED) | ||
191 | |||
192 | /* | ||
193 | * This error is returned when West Bridge cannot allocate memory required for | ||
194 | * internal API operations. | ||
195 | */ | ||
196 | #define CY_AN_ERROR_OUT_OF_MEMORY (CY_AS_ERROR_OUT_OF_MEMORY) | ||
197 | |||
198 | /* | ||
199 | * This error is returned when a module is being started that has | ||
200 | * already been started. | ||
201 | */ | ||
202 | #define CY_AN_ERROR_NESTED_SLEEP (CY_AS_ERROR_NESTED_SLEEP) | ||
203 | |||
204 | /* | ||
205 | * This error is returned when an operation is attempted on an endpoint that has | ||
206 | * been disabled. | ||
207 | */ | ||
208 | #define CY_AN_ERROR_ENDPOINT_DISABLED (CY_AS_ERROR_ENDPOINT_DISABLED) | ||
209 | |||
210 | /* | ||
211 | * This error is returned when a call is made to an API function when the device | ||
212 | * is in standby. | ||
213 | */ | ||
214 | #define CY_AN_ERROR_IN_STANDBY (CY_AS_ERROR_IN_STANDBY) | ||
215 | |||
216 | /* | ||
217 | * This error is returned when an API call is made with an invalid handle value. | ||
218 | */ | ||
219 | #define CY_AN_ERROR_INVALID_HANDLE (CY_AS_ERROR_INVALID_HANDLE) | ||
220 | |||
221 | /* | ||
222 | * This error is returned when an invalid response is returned from the West | ||
223 | * Bridge device. | ||
224 | */ | ||
225 | #define CY_AN_ERROR_INVALID_RESPONSE (CY_AS_ERROR_INVALID_RESPONSE) | ||
226 | |||
227 | /* | ||
228 | * This error is returned from the callback function for any asynchronous | ||
229 | * read or write request that is canceled. | ||
230 | */ | ||
231 | #define CY_AN_ERROR_CANCELED (CY_AS_ERROR_CANCELED) | ||
232 | |||
233 | /* | ||
234 | * This error is returned when the call to create sleep channel fails | ||
235 | * in the HAL layer. | ||
236 | */ | ||
237 | #define CY_AN_ERROR_CREATE_SLEEP_CHANNEL_FAILED \ | ||
238 | (CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED) | ||
239 | |||
240 | /* | ||
241 | * This error is returned when the call to CyAnMiscLeaveStandby | ||
242 | * is made and the device is not in standby. | ||
243 | */ | ||
244 | #define CY_AN_ERROR_NOT_IN_STANDBY (CY_AS_ERROR_NOT_IN_STANDBY) | ||
245 | |||
246 | /* | ||
247 | * This error is returned when the call to destroy sleep channel fails | ||
248 | * in the HAL layer. | ||
249 | */ | ||
250 | #define CY_AN_ERROR_DESTROY_SLEEP_CHANNEL_FAILED \ | ||
251 | (CY_AS_ERROR_DESTROY_SLEEP_CHANNEL_FAILED) | ||
252 | |||
253 | /* | ||
254 | * This error is returned when an invalid resource is specified to a call | ||
255 | * to CyAnMiscAcquireResource() or CyAnMiscReleaseResource() | ||
256 | */ | ||
257 | #define CY_AN_ERROR_INVALID_RESOURCE (CY_AS_ERROR_INVALID_RESOURCE) | ||
258 | |||
259 | /* | ||
260 | * This error occurs when an operation is requested on an endpoint that has | ||
261 | * a currently pending async operation. | ||
262 | */ | ||
263 | #define CY_AN_ERROR_ASYNC_PENDING (CY_AS_ERROR_ASYNC_PENDING) | ||
264 | |||
265 | /* | ||
266 | * This error is returned when a call to CyAnStorageCancelAsync() or | ||
267 | * CyAnUsbCancelAsync() is made when no asynchronous request is pending. | ||
268 | */ | ||
269 | #define CY_AN_ERROR_ASYNC_NOT_PENDING (CY_AS_ERROR_ASYNC_NOT_PENDING) | ||
270 | |||
271 | /* | ||
272 | * This error is returned when a request is made to put the West Bridge device | ||
273 | * into standby mode while the USB stack is still active. | ||
274 | */ | ||
275 | #define CY_AN_ERROR_USB_RUNNING (CY_AS_ERROR_USB_RUNNING) | ||
276 | |||
277 | /* | ||
278 | * A request for in the wrong direction was issued on an endpoint. | ||
279 | */ | ||
280 | #define CY_AN_ERROR_USB_BAD_DIRECTION (CY_AS_ERROR_USB_BAD_DIRECTION) | ||
281 | |||
282 | /* | ||
283 | * An invalid request was received | ||
284 | */ | ||
285 | #define CY_AN_ERROR_INVALID_REQUEST (CY_AS_ERROR_INVALID_REQUEST) | ||
286 | |||
287 | /* | ||
288 | * An ACK request was requested while no setup packet was pending. | ||
289 | */ | ||
290 | #define CY_AN_ERROR_NO_SETUP_PACKET_PENDING \ | ||
291 | (CY_AS_ERROR_NO_SETUP_PACKET_PENDING) | ||
292 | |||
293 | /* | ||
294 | * A call was made to a API function that cannot be called from a callback. | ||
295 | */ | ||
296 | #define CY_AN_ERROR_INVALID_IN_CALLBACK (CY_AS_ERROR_INVALID_IN_CALLBACK) | ||
297 | |||
298 | /* | ||
299 | * A call was made to CyAnUsbSetEndPointConfig() before | ||
300 | * CyAnUsbSetPhysicalConfiguration() was called. | ||
301 | */ | ||
302 | #define CY_AN_ERROR_ENDPOINT_CONFIG_NOT_SET \ | ||
303 | (CY_AS_ERROR_ENDPOINT_CONFIG_NOT_SET) | ||
304 | |||
305 | /* | ||
306 | * The physical endpoint referenced is not valid in the current | ||
307 | * physical configuration | ||
308 | */ | ||
309 | #define CY_AN_ERROR_INVALID_PHYSICAL_ENDPOINT \ | ||
310 | (CY_AS_ERROR_INVALID_PHYSICAL_ENDPOINT) | ||
311 | |||
312 | /* | ||
313 | * The data supplied to the CyAnMiscDownloadFirmware() call is not aligned on a | ||
314 | * WORD (16 bit) boundary. | ||
315 | */ | ||
316 | #define CY_AN_ERROR_ALIGNMENT_ERROR (CY_AS_ERROR_ALIGNMENT_ERROR) | ||
317 | |||
318 | /* | ||
319 | * A call was made to destroy the West Bridge device, but the USB stack or the | ||
320 | * storage stack was will running. | ||
321 | */ | ||
322 | #define CY_AN_ERROR_STILL_RUNNING (CY_AS_ERROR_STILL_RUNNING) | ||
323 | |||
324 | /* | ||
325 | * A call was made to the API for a function that is not yet supported. | ||
326 | */ | ||
327 | #define CY_AN_ERROR_NOT_YET_SUPPORTED (CY_AS_ERROR_NOT_YET_SUPPORTED) | ||
328 | |||
329 | /* | ||
330 | * A NULL callback was provided where a non-NULL callback was required | ||
331 | */ | ||
332 | #define CY_AN_ERROR_NULL_CALLBACK (CY_AS_ERROR_NULL_CALLBACK) | ||
333 | |||
334 | /* | ||
335 | * This error is returned when a request is made to put the West Bridge device | ||
336 | * into standby mode while the storage stack is still active. | ||
337 | */ | ||
338 | #define CY_AN_ERROR_STORAGE_RUNNING (CY_AS_ERROR_STORAGE_RUNNING) | ||
339 | |||
340 | /* | ||
341 | * This error is returned when an operation is attempted that cannot be | ||
342 | * completed while the USB stack is connected to a USB host. | ||
343 | */ | ||
344 | #define CY_AN_ERROR_USB_CONNECTED (CY_AS_ERROR_USB_CONNECTED) | ||
345 | |||
346 | /* | ||
347 | * This error is returned when a USB disconnect is attempted and the | ||
348 | * West Bridge device is not connected. | ||
349 | */ | ||
350 | #define CY_AN_ERROR_USB_NOT_CONNECTED (CY_AS_ERROR_USB_NOT_CONNECTED) | ||
351 | |||
352 | /* | ||
353 | * This error is returned when an P2S storage operation attempted and | ||
354 | * data could not be read or written to the storage media. | ||
355 | */ | ||
356 | #define CY_AN_ERROR_MEDIA_ACCESS_FAILURE (CY_AS_ERROR_MEDIA_ACCESS_FAILURE) | ||
357 | |||
358 | /* | ||
359 | * This error is returned when an P2S storage operation attempted and | ||
360 | * the media is write protected. | ||
361 | */ | ||
362 | #define CY_AN_ERROR_MEDIA_WRITE_PROTECTED (CY_AS_ERROR_MEDIA_WRITE_PROTECTED) | ||
363 | |||
364 | /* | ||
365 | * This error is returned when an attempt is made to cancel a request | ||
366 | * that has already been sent to the West Bridge. | ||
367 | */ | ||
368 | #define CY_AN_ERROR_OPERATION_IN_TRANSIT (CY_AS_ERROR_OPERATION_IN_TRANSIT) | ||
369 | |||
370 | /* | ||
371 | * This error is returned when an invalid parameter is passed to one of | ||
372 | * the APIs. | ||
373 | */ | ||
374 | #define CY_AN_ERROR_INVALID_PARAMETER (CY_AS_ERROR_INVALID_PARAMETER) | ||
375 | |||
376 | /* | ||
377 | * This error is returned if an API is not supported by the current | ||
378 | * West Bridge device or the active firmware version. | ||
379 | */ | ||
380 | #define CY_AN_ERROR_NOT_SUPPORTED (CY_AS_ERROR_NOT_SUPPORTED) | ||
381 | |||
382 | /* | ||
383 | * This error is returned when a call is made to one of the Storage or | ||
384 | * USB APIs while the device is in suspend mode. | ||
385 | */ | ||
386 | #define CY_AN_ERROR_IN_SUSPEND (CY_AS_ERROR_IN_SUSPEND) | ||
387 | |||
388 | /* | ||
389 | * This error is returned when the call to CyAnMiscLeaveSuspend | ||
390 | * is made and the device is not in suspend mode. | ||
391 | */ | ||
392 | #define CY_AN_ERROR_NOT_IN_SUSPEND (CY_AS_ERROR_NOT_IN_SUSPEND) | ||
393 | |||
394 | /* | ||
395 | * This error is returned when a command that is disabled by USB is called. | ||
396 | */ | ||
397 | #define CY_AN_ERROR_FEATURE_NOT_ENABLED (CY_AS_ERROR_FEATURE_NOT_ENABLED) | ||
398 | |||
399 | /* | ||
400 | * This error is returned when an Async storage read or write is called before a | ||
401 | * query device call is issued. | ||
402 | */ | ||
403 | #define CY_AN_ERROR_QUERY_DEVICE_NEEDED (CY_AS_ERROR_QUERY_DEVICE_NEEDED) | ||
404 | |||
405 | /* | ||
406 | * This error is returned when a call is made to USB or STORAGE Start or | ||
407 | * Stop before a prior Start or Stop has finished. | ||
408 | */ | ||
409 | #define CY_AN_ERROR_STARTSTOP_PENDING (CY_AS_ERROR_STARTSTOP_PENDING) | ||
410 | |||
411 | /* | ||
412 | * This error is returned when a request is made for a bus that does not exist | ||
413 | */ | ||
414 | #define CY_AN_ERROR_NO_SUCH_BUS (CY_AS_ERROR_NO_SUCH_BUS) | ||
415 | |||
416 | #endif /* __doxygen__ */ | ||
417 | |||
418 | #endif /* _INCLUDED_CYANERR_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmedia.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmedia.h deleted file mode 100644 index be074887f5a3..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmedia.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanmedia.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYANMEDIA_H_ | ||
23 | #define _INCLUDED_CYANMEDIA_H_ | ||
24 | |||
25 | #include "cyas_cplus_start.h" | ||
26 | |||
27 | /* Summary | ||
28 | Specifies a specific type of media supported by West Bridge | ||
29 | |||
30 | Description | ||
31 | The West Bridge device supports five specific types | ||
32 | of media as storage/IO devices attached to it's S-Port. This | ||
33 | type is used to indicate the type of media being referenced in | ||
34 | any API call. | ||
35 | */ | ||
36 | #include "cyasmedia.h" | ||
37 | |||
38 | /* Flash NAND memory (may be SLC or MLC) */ | ||
39 | #define cy_an_media_nand cy_as_media_nand | ||
40 | |||
41 | /* An SD flash memory device */ | ||
42 | #define cy_an_media_sd_flash cy_as_media_sd_flash | ||
43 | |||
44 | /* An MMC flash memory device */ | ||
45 | #define cy_an_media_mmc_flash cy_as_media_mmc_flash | ||
46 | |||
47 | /* A CE-ATA disk drive */ | ||
48 | #define cy_an_media_ce_ata cy_as_media_ce_ata | ||
49 | |||
50 | /* SDIO device. */ | ||
51 | #define cy_an_media_sdio cy_as_media_sdio | ||
52 | #define cy_an_media_max_media_value \ | ||
53 | cy_as_media_max_media_value | ||
54 | |||
55 | typedef cy_as_media_type cy_an_media_type; | ||
56 | |||
57 | #include "cyas_cplus_end.h" | ||
58 | |||
59 | #endif /* _INCLUDED_CYANMEDIA_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmisc.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmisc.h deleted file mode 100644 index 0838648dc169..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanmisc.h +++ /dev/null | |||
@@ -1,614 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanmisc.h) | ||
2 | ## Version for backward compatibility with previous Antioch SDK releases. | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street | ||
19 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef _INCLUDED_CYANMISC_H_ | ||
24 | #define _INCLUDED_CYANMISC_H_ | ||
25 | |||
26 | #include "cyantypes.h" | ||
27 | #include <cyasmisc.h> | ||
28 | #include "cyanmedia.h" | ||
29 | #include "cyas_cplus_start.h" | ||
30 | |||
31 | #define CY_AN_LEAVE_STANDBY_DELAY_CLOCK \ | ||
32 | (CY_AS_LEAVE_STANDBY_DELAY_CLOCK) | ||
33 | #define CY_AN_RESET_DELAY_CLOCK \ | ||
34 | (CY_AS_RESET_DELAY_CLOCK) | ||
35 | |||
36 | #define CY_AN_LEAVE_STANDBY_DELAY_CRYSTAL \ | ||
37 | (CY_AS_LEAVE_STANDBY_DELAY_CRYSTAL) | ||
38 | |||
39 | #define CY_AN_RESET_DELAY_CRYSTAL \ | ||
40 | (CY_AS_RESET_DELAY_CRYSTAL) | ||
41 | |||
42 | /* Defines to convert the old CyAn names to the new | ||
43 | * CyAs names | ||
44 | */ | ||
45 | typedef cy_as_device_handle cy_an_device_handle; | ||
46 | |||
47 | #define cy_an_device_dack_ack cy_as_device_dack_ack | ||
48 | #define cy_an_device_dack_eob cy_as_device_dack_eob | ||
49 | typedef cy_as_device_dack_mode cy_an_device_dack_mode; | ||
50 | |||
51 | typedef cy_as_device_config cy_an_device_config; | ||
52 | |||
53 | #define cy_an_resource_u_s_b cy_as_bus_u_sB | ||
54 | #define cy_an_resource_sdio_MMC cy_as_bus_1 | ||
55 | #define cy_an_resource_nand cy_as_bus_0 | ||
56 | typedef cy_as_resource_type cy_an_resource_type; | ||
57 | |||
58 | #define cy_an_reset_soft cy_as_reset_soft | ||
59 | #define cy_an_reset_hard cy_as_reset_hard | ||
60 | typedef cy_as_reset_type cy_an_reset_type; | ||
61 | typedef cy_as_funct_c_b_type cy_an_funct_c_b_type; | ||
62 | typedef cy_as_function_callback cy_an_function_callback; | ||
63 | |||
64 | #define cy_an_event_misc_initialized \ | ||
65 | cy_as_event_misc_initialized | ||
66 | #define cy_an_event_misc_awake \ | ||
67 | cy_as_event_misc_awake | ||
68 | #define cy_an_event_misc_heart_beat \ | ||
69 | cy_as_event_misc_heart_beat | ||
70 | #define cy_an_event_misc_wakeup \ | ||
71 | cy_as_event_misc_wakeup | ||
72 | #define cy_an_event_misc_device_mismatch \ | ||
73 | cy_as_event_misc_device_mismatch | ||
74 | typedef cy_as_misc_event_type \ | ||
75 | cy_an_misc_event_type; | ||
76 | typedef cy_as_misc_event_callback \ | ||
77 | cy_an_misc_event_callback; | ||
78 | |||
79 | #define cy_an_misc_gpio_0 cy_as_misc_gpio_0 | ||
80 | #define cy_an_misc_gpio_1 cy_as_misc_gpio_1 | ||
81 | #define cy_an_misc_gpio__nand_CE \ | ||
82 | cy_as_misc_gpio__nand_CE | ||
83 | #define cy_an_misc_gpio__nand_CE2 \ | ||
84 | cy_as_misc_gpio__nand_CE2 | ||
85 | #define cy_an_misc_gpio__nand_WP \ | ||
86 | cy_as_misc_gpio__nand_WP | ||
87 | #define cy_an_misc_gpio__nand_CLE \ | ||
88 | cy_as_misc_gpio__nand_CLE | ||
89 | #define cy_an_misc_gpio__nand_ALE \ | ||
90 | cy_as_misc_gpio__nand_ALE | ||
91 | #define cy_an_misc_gpio_U_valid \ | ||
92 | cy_as_misc_gpio_U_valid | ||
93 | #define cy_an_misc_gpio_SD_POW \ | ||
94 | cy_as_misc_gpio_SD_POW | ||
95 | typedef cy_as_misc_gpio cy_an_misc_gpio; | ||
96 | |||
97 | #define CY_AN_SD_DEFAULT_FREQ CY_AS_SD_DEFAULT_FREQ | ||
98 | #define CY_AN_SD_RATED_FREQ CY_AS_SD_RATED_FREQ | ||
99 | typedef cy_as_low_speed_sd_freq cy_an_low_speed_sd_freq; | ||
100 | |||
101 | #define CY_AN_HS_SD_FREQ_48 CY_AS_HS_SD_FREQ_48 | ||
102 | #define CY_AN_HS_SD_FREQ_24 CY_AS_HS_SD_FREQ_24 | ||
103 | typedef cy_as_high_speed_sd_freq \ | ||
104 | cy_an_high_speed_sd_freq; | ||
105 | |||
106 | #define cy_an_misc_active_high cy_as_misc_active_high | ||
107 | #define cy_an_misc_active_low cy_as_misc_active_low | ||
108 | typedef cy_as_misc_signal_polarity cy_an_misc_signal_polarity; | ||
109 | |||
110 | typedef cy_as_get_firmware_version_data \ | ||
111 | cy_an_get_firmware_version_data; | ||
112 | |||
113 | enum { | ||
114 | CYAN_FW_TRACE_LOG_NONE = 0, | ||
115 | CYAN_FW_TRACE_LOG_STATE, | ||
116 | CYAN_FW_TRACE_LOG_CALLS, | ||
117 | CYAN_FW_TRACE_LOG_STACK_TRACE, | ||
118 | CYAN_FW_TRACE_MAX_LEVEL | ||
119 | }; | ||
120 | |||
121 | |||
122 | /***********************************/ | ||
123 | /***********************************/ | ||
124 | /* FUNCTIONS */ | ||
125 | /***********************************/ | ||
126 | /***********************************/ | ||
127 | |||
128 | |||
129 | EXTERN cy_an_return_status_t | ||
130 | cy_an_misc_create_device( | ||
131 | cy_an_device_handle *handle_p, | ||
132 | cy_an_hal_device_tag tag | ||
133 | ); | ||
134 | #define cy_an_misc_create_device(h, tag) \ | ||
135 | cy_as_misc_create_device((cy_as_device_handle *)(h), \ | ||
136 | (cy_as_hal_device_tag)(tag)) | ||
137 | |||
138 | EXTERN cy_an_return_status_t | ||
139 | cy_an_misc_destroy_device( | ||
140 | cy_an_device_handle handle | ||
141 | ); | ||
142 | #define cy_an_misc_destroy_device(h) \ | ||
143 | cy_as_misc_destroy_device((cy_as_device_handle)(h)) | ||
144 | |||
145 | EXTERN cy_an_return_status_t | ||
146 | cy_an_misc_configure_device( | ||
147 | cy_an_device_handle handle, | ||
148 | cy_an_device_config *config_p | ||
149 | ); | ||
150 | #define cy_an_misc_configure_device(h, cfg) \ | ||
151 | cy_as_misc_configure_device((cy_as_device_handle)(h), \ | ||
152 | (cy_as_device_config *)(cfg)) | ||
153 | |||
154 | EXTERN cy_an_return_status_t | ||
155 | cy_an_misc_in_standby( | ||
156 | cy_an_device_handle handle, | ||
157 | cy_bool *standby | ||
158 | ); | ||
159 | #define cy_an_misc_in_standby(h, standby) \ | ||
160 | cy_as_misc_in_standby((cy_as_device_handle)(h), (standby)) | ||
161 | |||
162 | /* Sync version of Download Firmware */ | ||
163 | EXTERN cy_an_return_status_t | ||
164 | cy_an_misc_download_firmware( | ||
165 | cy_an_device_handle handle, | ||
166 | const void *fw_p, | ||
167 | uint16_t size | ||
168 | ); | ||
169 | |||
170 | #define cy_an_misc_download_firmware(handle, fw_p, size) \ | ||
171 | cy_as_misc_download_firmware((cy_as_device_handle)\ | ||
172 | (handle), (fw_p), (size), 0, 0) | ||
173 | |||
174 | /* Async version of Download Firmware */ | ||
175 | EXTERN cy_an_return_status_t | ||
176 | cy_an_misc_download_firmware_e_x( | ||
177 | cy_an_device_handle handle, | ||
178 | const void *fw_p, | ||
179 | uint16_t size, | ||
180 | cy_an_function_callback cb, | ||
181 | uint32_t client | ||
182 | ); | ||
183 | |||
184 | #define cy_an_misc_download_firmware_e_x(h, fw_p, size, cb, client) \ | ||
185 | cy_as_misc_download_firmware((cy_as_device_handle)(h), \ | ||
186 | (fw_p), (size), (cy_as_function_callback)(cb), (client)) | ||
187 | |||
188 | /* Sync version of Get Firmware Version */ | ||
189 | EXTERN cy_an_return_status_t | ||
190 | cy_as_misc_get_firmware_version_dep( | ||
191 | cy_as_device_handle handle, | ||
192 | uint16_t *major, | ||
193 | uint16_t *minor, | ||
194 | uint16_t *build, | ||
195 | uint8_t *media_type, | ||
196 | cy_bool *is_debug_mode); | ||
197 | |||
198 | #define cy_an_misc_get_firmware_version\ | ||
199 | (h, major, minor, bld, type, mode) \ | ||
200 | cy_as_misc_get_firmware_version_dep((cy_as_device_handle)(h), \ | ||
201 | (major), (minor), (bld), (type), (mode)) | ||
202 | |||
203 | /* Async version of Get Firmware Version*/ | ||
204 | EXTERN cy_an_return_status_t | ||
205 | cy_an_misc_get_firmware_version_e_x( | ||
206 | cy_an_device_handle handle, | ||
207 | cy_an_get_firmware_version_data *data, | ||
208 | cy_an_function_callback cb, | ||
209 | uint32_t client | ||
210 | ); | ||
211 | #define cy_an_misc_get_firmware_version_e_x\ | ||
212 | (h, data, cb, client) \ | ||
213 | cy_as_misc_get_firmware_version((cy_as_device_handle)(h), \ | ||
214 | (data), (cy_as_function_callback)(cb), (client)) | ||
215 | |||
216 | /* Sync version of Read MCU Register*/ | ||
217 | EXTERN cy_an_return_status_t | ||
218 | cy_an_misc_read_m_c_u_register( | ||
219 | cy_an_device_handle handle, | ||
220 | uint16_t address, | ||
221 | uint8_t *value | ||
222 | ); | ||
223 | |||
224 | #define cy_an_misc_read_m_c_u_register(handle, address, value) \ | ||
225 | cy_as_misc_read_m_c_u_register((cy_as_device_handle)(handle), \ | ||
226 | (address), (value), 0, 0) | ||
227 | |||
228 | /* Async version of Read MCU Register*/ | ||
229 | EXTERN cy_an_return_status_t | ||
230 | cy_an_misc_read_m_c_u_register_e_x( | ||
231 | cy_an_device_handle handle, | ||
232 | uint16_t address, | ||
233 | uint8_t *value, | ||
234 | cy_an_function_callback cb, | ||
235 | uint32_t client | ||
236 | ); | ||
237 | |||
238 | #define cy_an_misc_read_m_c_u_register_e_x\ | ||
239 | (h, addr, val, cb, client) \ | ||
240 | cy_as_misc_read_m_c_u_register((cy_as_device_handle)(h), \ | ||
241 | (addr), (val), (cy_as_function_callback)(cb), (client)) | ||
242 | |||
243 | /* Sync version of Write MCU Register*/ | ||
244 | EXTERN cy_an_return_status_t | ||
245 | cy_an_misc_write_m_c_u_register( | ||
246 | cy_an_device_handle handle, | ||
247 | uint16_t address, | ||
248 | uint8_t mask, | ||
249 | uint8_t value | ||
250 | ); | ||
251 | #define cy_an_misc_write_m_c_u_register\ | ||
252 | (handle, address, mask, value) \ | ||
253 | cy_as_misc_write_m_c_u_register((cy_as_device_handle)(handle), \ | ||
254 | (address), (mask), (value), 0, 0) | ||
255 | |||
256 | /* Async version of Write MCU Register*/ | ||
257 | EXTERN cy_an_return_status_t | ||
258 | cy_an_misc_write_m_c_u_register_e_x( | ||
259 | cy_an_device_handle handle, | ||
260 | uint16_t address, | ||
261 | uint8_t mask, | ||
262 | uint8_t value, | ||
263 | cy_an_function_callback cb, | ||
264 | uint32_t client | ||
265 | ); | ||
266 | #define cy_an_misc_write_m_c_u_register_e_x\ | ||
267 | (h, addr, mask, val, cb, client) \ | ||
268 | cy_as_misc_write_m_c_u_register((cy_as_device_handle)(h), \ | ||
269 | (addr), (mask), (val), (cy_as_function_callback)(cb), (client)) | ||
270 | |||
271 | /* Sync version of Write MCU Register*/ | ||
272 | EXTERN cy_an_return_status_t | ||
273 | cy_an_misc_reset( | ||
274 | cy_an_device_handle handle, | ||
275 | cy_an_reset_type type, | ||
276 | cy_bool flush | ||
277 | ); | ||
278 | #define cy_an_misc_reset(handle, type, flush) \ | ||
279 | cy_as_misc_reset((cy_as_device_handle)(handle), \ | ||
280 | (type), (flush), 0, 0) | ||
281 | |||
282 | /* Async version of Write MCU Register*/ | ||
283 | EXTERN cy_an_return_status_t | ||
284 | cy_an_misc_reset_e_x( | ||
285 | cy_an_device_handle handle, | ||
286 | cy_an_reset_type type, | ||
287 | cy_bool flush, | ||
288 | cy_an_function_callback cb, | ||
289 | uint32_t client | ||
290 | ); | ||
291 | #define cy_an_misc_reset_e_x(h, type, flush, cb, client) \ | ||
292 | cy_as_misc_reset((cy_as_device_handle)(h), \ | ||
293 | (cy_as_reset_type)(type), (flush), \ | ||
294 | (cy_as_function_callback)(cb), (client)) | ||
295 | |||
296 | /* Synchronous version of CyAnMiscAcquireResource. */ | ||
297 | EXTERN cy_an_return_status_t | ||
298 | cy_an_misc_acquire_resource( | ||
299 | cy_an_device_handle handle, | ||
300 | cy_an_resource_type type, | ||
301 | cy_bool force | ||
302 | ); | ||
303 | #define cy_an_misc_acquire_resource(h, type, force) \ | ||
304 | cy_as_misc_acquire_resource_dep((cy_as_device_handle)(h), \ | ||
305 | (cy_as_resource_type)(type), (force)) | ||
306 | |||
307 | /* Asynchronous version of CyAnMiscAcquireResource. */ | ||
308 | EXTERN cy_an_return_status_t | ||
309 | cy_an_misc_acquire_resource_e_x( | ||
310 | cy_an_device_handle handle, | ||
311 | cy_an_resource_type *type, | ||
312 | cy_bool force, | ||
313 | cy_an_function_callback cb, | ||
314 | uint32_t client | ||
315 | ); | ||
316 | #define cy_an_misc_acquire_resource_e_x\ | ||
317 | (h, type_p, force, cb, client) \ | ||
318 | cy_as_misc_acquire_resource((cy_as_device_handle)(h), \ | ||
319 | (cy_as_resource_type *)(type_p), \ | ||
320 | (force), (cy_as_function_callback)(cb), (client)) | ||
321 | |||
322 | /* The one and only version of Release resource */ | ||
323 | EXTERN cy_an_return_status_t | ||
324 | cy_an_misc_release_resource( | ||
325 | cy_an_device_handle handle, | ||
326 | cy_an_resource_type type | ||
327 | ); | ||
328 | #define cy_an_misc_release_resource(h, type)\ | ||
329 | cy_as_misc_release_resource((cy_as_device_handle)(h), \ | ||
330 | (cy_as_resource_type)(type)) | ||
331 | |||
332 | /* Synchronous version of CyAnMiscSetTraceLevel. */ | ||
333 | EXTERN cy_an_return_status_t | ||
334 | cy_an_misc_set_trace_level( | ||
335 | cy_an_device_handle handle, | ||
336 | uint8_t level, | ||
337 | cy_an_media_type media, | ||
338 | uint32_t device, | ||
339 | uint32_t unit | ||
340 | ); | ||
341 | |||
342 | #define cy_an_misc_set_trace_level\ | ||
343 | (handle, level, media, device, unit) \ | ||
344 | cy_as_misc_set_trace_level_dep((cy_as_device_handle)(handle), \ | ||
345 | (level), (cy_as_media_type)(media), (device), (unit), 0, 0) | ||
346 | |||
347 | /* Asynchronous version of CyAnMiscSetTraceLevel. */ | ||
348 | EXTERN cy_an_return_status_t | ||
349 | cy_an_misc_set_trace_level_e_x( | ||
350 | cy_an_device_handle handle, | ||
351 | uint8_t level, | ||
352 | cy_an_media_type media, | ||
353 | uint32_t device, | ||
354 | uint32_t unit, | ||
355 | cy_an_function_callback cb, | ||
356 | uint32_t client | ||
357 | ); | ||
358 | #define cy_an_misc_set_trace_level_e_x\ | ||
359 | (h, level, media, device, unit, cb, client) \ | ||
360 | cy_as_misc_set_trace_level_dep((cy_as_device_handle)(h), \ | ||
361 | (level), (cy_as_media_type)(media), (device), (unit), \ | ||
362 | (cy_as_function_callback)(cb), (client)) | ||
363 | |||
364 | /* Synchronous version of CyAnMiscEnterStandby. */ | ||
365 | EXTERN cy_an_return_status_t | ||
366 | cy_an_misc_enter_standby( | ||
367 | cy_an_device_handle handle, | ||
368 | cy_bool pin | ||
369 | ); | ||
370 | #define cy_an_misc_enter_standby(handle, pin) \ | ||
371 | cy_as_misc_enter_standby(\ | ||
372 | (cy_as_device_handle)(handle), (pin), 0, 0) | ||
373 | |||
374 | /* Synchronous version of CyAnMiscEnterStandby. */ | ||
375 | EXTERN cy_an_return_status_t | ||
376 | cy_an_misc_enter_standby_e_x( | ||
377 | cy_an_device_handle handle, | ||
378 | cy_bool pin, | ||
379 | cy_an_function_callback cb, | ||
380 | uint32_t client | ||
381 | ); | ||
382 | #define cy_an_misc_enter_standby_e_x(h, pin, cb, client) \ | ||
383 | cy_as_misc_enter_standby((cy_as_device_handle)(h), \ | ||
384 | (pin), (cy_as_function_callback)(cb), (client)) | ||
385 | |||
386 | /* Only one version of CyAnMiscLeaveStandby. */ | ||
387 | EXTERN cy_an_return_status_t | ||
388 | cy_an_misc_leave_standby( | ||
389 | cy_an_device_handle handle, | ||
390 | cy_an_resource_type type | ||
391 | ); | ||
392 | #define cy_an_misc_leave_standby(h, type) \ | ||
393 | cy_as_misc_leave_standby((cy_as_device_handle)(h), \ | ||
394 | (cy_as_resource_type)(type)) | ||
395 | |||
396 | /* The one version of Misc Register Callback */ | ||
397 | EXTERN cy_an_return_status_t | ||
398 | cy_an_misc_register_callback( | ||
399 | cy_an_device_handle handle, | ||
400 | cy_an_misc_event_callback callback | ||
401 | ); | ||
402 | #define cy_an_misc_register_callback(h, cb) \ | ||
403 | cy_as_misc_register_callback((cy_as_device_handle)(h), \ | ||
404 | (cy_as_misc_event_callback)(cb)) | ||
405 | |||
406 | /* The only version of SetLogLevel */ | ||
407 | EXTERN void | ||
408 | cy_an_misc_set_log_level( | ||
409 | uint8_t level | ||
410 | ); | ||
411 | #define cy_an_misc_set_log_level(level) \ | ||
412 | cy_as_misc_set_log_level(level) | ||
413 | |||
414 | /* Sync version of Misc Storage Changed */ | ||
415 | EXTERN cy_an_return_status_t | ||
416 | cy_an_misc_storage_changed( | ||
417 | cy_an_device_handle handle | ||
418 | ); | ||
419 | #define cy_an_misc_storage_changed(handle) \ | ||
420 | cy_as_misc_storage_changed((cy_as_device_handle)(handle), 0, 0) | ||
421 | |||
422 | /* Async version of Misc Storage Changed */ | ||
423 | EXTERN cy_an_return_status_t | ||
424 | cy_an_misc_storage_changed_e_x( | ||
425 | cy_an_device_handle handle, | ||
426 | cy_an_function_callback cb, | ||
427 | uint32_t client | ||
428 | ); | ||
429 | #define cy_an_misc_storage_changed_e_x(h, cb, client) \ | ||
430 | cy_as_misc_storage_changed((cy_as_device_handle)(h), \ | ||
431 | (cy_as_function_callback)(cb), (client)) | ||
432 | |||
433 | /* Sync version of Heartbeat control */ | ||
434 | EXTERN cy_an_return_status_t | ||
435 | cy_an_misc_heart_beat_control( | ||
436 | cy_an_device_handle handle, | ||
437 | cy_bool enable | ||
438 | ); | ||
439 | #define cy_an_misc_heart_beat_control(handle, enable) \ | ||
440 | cy_as_misc_heart_beat_control((cy_as_device_handle)\ | ||
441 | (handle), (enable), 0, 0) | ||
442 | |||
443 | /* Async version of Heartbeat control */ | ||
444 | EXTERN cy_an_return_status_t | ||
445 | cy_an_misc_heart_beat_control_e_x( | ||
446 | cy_an_device_handle handle, | ||
447 | cy_bool enable, | ||
448 | cy_an_function_callback cb, | ||
449 | uint32_t client | ||
450 | ); | ||
451 | #define cy_an_misc_heart_beat_control_e_x(h, enable, cb, client) \ | ||
452 | cy_as_misc_heart_beat_control((cy_as_device_handle)(h), \ | ||
453 | (enable), (cy_as_function_callback)(cb), (client)) | ||
454 | |||
455 | /* Sync version of Get Gpio */ | ||
456 | EXTERN cy_an_return_status_t | ||
457 | cy_an_misc_get_gpio_value( | ||
458 | cy_an_device_handle handle, | ||
459 | cy_an_misc_gpio pin, | ||
460 | uint8_t *value | ||
461 | ); | ||
462 | #define cy_an_misc_get_gpio_value(handle, pin, value) \ | ||
463 | cy_as_misc_get_gpio_value((cy_as_device_handle)(handle), \ | ||
464 | (cy_as_misc_gpio)(pin), (value), 0, 0) | ||
465 | |||
466 | /* Async version of Get Gpio */ | ||
467 | EXTERN cy_an_return_status_t | ||
468 | cy_an_misc_get_gpio_value_e_x( | ||
469 | cy_an_device_handle handle, | ||
470 | cy_an_misc_gpio pin, | ||
471 | uint8_t *value, | ||
472 | cy_an_function_callback cb, | ||
473 | uint32_t client | ||
474 | ); | ||
475 | #define cy_an_misc_get_gpio_value_e_x(h, pin, value, cb, client) \ | ||
476 | cy_as_misc_get_gpio_value((cy_as_device_handle)(h), \ | ||
477 | (cy_as_misc_gpio)(pin), (value), \ | ||
478 | (cy_as_function_callback)(cb), (client)) | ||
479 | |||
480 | /* Sync version of Set Gpio */ | ||
481 | EXTERN cy_an_return_status_t | ||
482 | cy_an_misc_set_gpio_value( | ||
483 | cy_an_device_handle handle, | ||
484 | cy_an_misc_gpio pin, | ||
485 | uint8_t value | ||
486 | ); | ||
487 | #define cy_an_misc_set_gpio_value(handle, pin, value) \ | ||
488 | cy_as_misc_set_gpio_value((cy_as_device_handle)(handle), \ | ||
489 | (cy_as_misc_gpio)(pin), (value), 0, 0) | ||
490 | |||
491 | /* Async version of Set Gpio */ | ||
492 | EXTERN cy_an_return_status_t | ||
493 | cy_an_misc_set_gpio_value_e_x( | ||
494 | cy_an_device_handle handle, | ||
495 | cy_an_misc_gpio pin, | ||
496 | uint8_t value, | ||
497 | cy_an_function_callback cb, | ||
498 | uint32_t client | ||
499 | ); | ||
500 | #define cy_an_misc_set_gpio_value_e_x\ | ||
501 | (h, pin, value, cb, client) \ | ||
502 | cy_as_misc_set_gpio_value((cy_as_device_handle)(h), \ | ||
503 | (cy_as_misc_gpio)(pin), (value), \ | ||
504 | (cy_as_function_callback)(cb), (client)) | ||
505 | |||
506 | /* Sync version of Enter suspend */ | ||
507 | EXTERN cy_an_return_status_t | ||
508 | cy_an_misc_enter_suspend( | ||
509 | cy_an_device_handle handle, | ||
510 | cy_bool usb_wakeup_en, | ||
511 | cy_bool gpio_wakeup_en | ||
512 | ); | ||
513 | #define cy_an_misc_enter_suspend(handle, usb_wakeup_en, \ | ||
514 | gpio_wakeup_en) \ | ||
515 | cy_as_misc_enter_suspend((cy_as_device_handle)(handle), \ | ||
516 | (usb_wakeup_en), (gpio_wakeup_en), 0, 0) | ||
517 | |||
518 | /* Async version of Enter suspend */ | ||
519 | EXTERN cy_an_return_status_t | ||
520 | cy_an_misc_enter_suspend_e_x( | ||
521 | cy_an_device_handle handle, | ||
522 | cy_bool usb_wakeup_en, | ||
523 | cy_bool gpio_wakeup_en, | ||
524 | cy_an_function_callback cb, | ||
525 | uint32_t client | ||
526 | ); | ||
527 | #define cy_an_misc_enter_suspend_e_x(h, usb_en, gpio_en, cb, client)\ | ||
528 | cy_as_misc_enter_suspend((cy_as_device_handle)(h), (usb_en), \ | ||
529 | (gpio_en), (cy_as_function_callback)(cb), (client)) | ||
530 | |||
531 | /* Sync version of Enter suspend */ | ||
532 | EXTERN cy_an_return_status_t | ||
533 | cy_an_misc_leave_suspend( | ||
534 | cy_an_device_handle handle | ||
535 | ); | ||
536 | #define cy_an_misc_leave_suspend(handle) \ | ||
537 | cy_as_misc_leave_suspend((cy_as_device_handle)(handle), 0, 0) | ||
538 | |||
539 | /* Async version of Enter suspend */ | ||
540 | EXTERN cy_an_return_status_t | ||
541 | cy_an_misc_leave_suspend_e_x( | ||
542 | cy_an_device_handle handle, | ||
543 | cy_an_function_callback cb, | ||
544 | uint32_t client | ||
545 | ); | ||
546 | |||
547 | #define cy_an_misc_leave_suspend_e_x(h, cb, client) \ | ||
548 | cy_as_misc_leave_suspend((cy_as_device_handle)(h), \ | ||
549 | (cy_as_function_callback)(cb), (client)) | ||
550 | |||
551 | /* Sync version of SetLowSpeedSDFreq */ | ||
552 | EXTERN cy_an_return_status_t | ||
553 | cy_an_misc_set_low_speed_sd_freq( | ||
554 | cy_an_device_handle handle, | ||
555 | cy_an_low_speed_sd_freq setting | ||
556 | ); | ||
557 | #define cy_an_misc_set_low_speed_sd_freq(h, setting) \ | ||
558 | cy_as_misc_set_low_speed_sd_freq((cy_as_device_handle)(h), \ | ||
559 | (cy_as_low_speed_sd_freq)(setting), 0, 0) | ||
560 | |||
561 | /* Async version of SetLowSpeedSDFreq */ | ||
562 | EXTERN cy_an_return_status_t | ||
563 | cy_an_misc_set_low_speed_sd_freq_e_x( | ||
564 | cy_an_device_handle handle, | ||
565 | cy_an_low_speed_sd_freq setting, | ||
566 | cy_an_function_callback cb, | ||
567 | uint32_t client | ||
568 | ); | ||
569 | #define cy_an_misc_set_low_speed_sd_freq_e_x\ | ||
570 | (h, setting, cb, client) \ | ||
571 | cy_as_misc_set_low_speed_sd_freq((cy_as_device_handle)(h), \ | ||
572 | (cy_as_low_speed_sd_freq)(setting), \ | ||
573 | (cy_as_function_callback)(cb), (client)) | ||
574 | |||
575 | /* SetHighSpeedSDFreq */ | ||
576 | EXTERN cy_an_return_status_t | ||
577 | cy_an_misc_set_high_speed_sd_freq( | ||
578 | cy_an_device_handle handle, | ||
579 | cy_an_high_speed_sd_freq setting, | ||
580 | cy_an_function_callback cb, | ||
581 | uint32_t client | ||
582 | ); | ||
583 | #define cy_an_misc_set_high_speed_sd_freq(h, setting, cb, client) \ | ||
584 | cy_as_misc_set_high_speed_sd_freq((cy_as_device_handle)(h), \ | ||
585 | (cy_as_high_speed_sd_freq)(setting), \ | ||
586 | (cy_as_function_callback)(cb), (client)) | ||
587 | |||
588 | /* ReserveLNABootArea */ | ||
589 | EXTERN cy_an_return_status_t | ||
590 | cy_an_misc_reserve_l_n_a_boot_area( | ||
591 | cy_an_device_handle handle, | ||
592 | uint8_t numzones, | ||
593 | cy_an_function_callback cb, | ||
594 | uint32_t client); | ||
595 | #define cy_an_misc_reserve_l_n_a_boot_area(h, num, cb, client) \ | ||
596 | cy_as_misc_reserve_l_n_a_boot_area((cy_as_device_handle)(h), \ | ||
597 | num, (cy_as_function_callback)(cb), (client)) | ||
598 | |||
599 | /* SetSDPowerPolarity */ | ||
600 | EXTERN cy_an_return_status_t | ||
601 | cy_an_misc_set_sd_power_polarity( | ||
602 | cy_an_device_handle handle, | ||
603 | cy_an_misc_signal_polarity polarity, | ||
604 | cy_an_function_callback cb, | ||
605 | uint32_t client); | ||
606 | #define cy_an_misc_set_sd_power_polarity(h, pol, cb, client) \ | ||
607 | cy_as_misc_set_sd_power_polarity((cy_as_device_handle)(h), \ | ||
608 | (cy_as_misc_signal_polarity)(pol), \ | ||
609 | (cy_as_function_callback)(cb), (client)) | ||
610 | |||
611 | #include "cyas_cplus_end.h" | ||
612 | |||
613 | #endif | ||
614 | |||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanregs.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanregs.h deleted file mode 100644 index d670291bd24d..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanregs.h +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanregs.h) | ||
2 | ## Register and field definitions for the Antioch device. | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street | ||
19 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef _INCLUDED_CYANREG_H_ | ||
24 | #define _INCLUDED_CYANREG_H_ | ||
25 | |||
26 | #if !defined(__doxygen__) | ||
27 | |||
28 | #define CY_AN_MEM_CM_WB_CFG_ID (0x80) | ||
29 | #define CY_AN_MEM_CM_WB_CFG_ID_VER_MASK (0x000F) | ||
30 | #define CY_AN_MEM_CM_WB_CFG_ID_HDID_MASK (0xFFF0) | ||
31 | #define CY_AN_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE (0xA100) | ||
32 | #define CY_AN_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE (0x6800) | ||
33 | #define CY_AN_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE (0xA200) | ||
34 | |||
35 | |||
36 | #define CY_AN_MEM_RST_CTRL_REG (0x81) | ||
37 | #define CY_AN_MEM_RST_CTRL_REG_HARD (0x0003) | ||
38 | #define CY_AN_MEM_RST_CTRL_REG_SOFT (0x0001) | ||
39 | #define CY_AN_MEM_RST_RSTCMPT (0x0004) | ||
40 | |||
41 | #define CY_AN_MEM_P0_ENDIAN (0x82) | ||
42 | #define CY_AN_LITTLE_ENDIAN (0x0000) | ||
43 | #define CY_AN_BIG_ENDIAN (0x0101) | ||
44 | |||
45 | #define CY_AN_MEM_P0_VM_SET (0x83) | ||
46 | #define CY_AN_MEM_P0_VM_SET_VMTYPE_MASK (0x0007) | ||
47 | #define CY_AN_MEM_P0_VM_SET_VMTYPE_RAM (0x0005) | ||
48 | #define CY_AN_MEM_P0_VM_SET_VMTYPE_VMWIDTH (0x0008) | ||
49 | #define CY_AN_MEM_P0_VM_SET_VMTYPE_FLOWCTRL (0x0010) | ||
50 | #define CY_AN_MEM_P0_VM_SET_IFMODE (0x0020) | ||
51 | #define CY_AN_MEM_P0_VM_SET_CFGMODE (0x0040) | ||
52 | #define CY_AN_MEM_P0_VM_SET_DACKEOB (0x0080) | ||
53 | #define CY_AN_MEM_P0_VM_SET_OVERRIDE (0x0100) | ||
54 | #define CY_AN_MEM_P0_VM_SET_INTOVERD (0x0200) | ||
55 | #define CY_AN_MEM_P0_VM_SET_DRQOVERD (0x0400) | ||
56 | #define CY_AN_MEM_P0_VM_SET_DRQPOL (0x0800) | ||
57 | #define CY_AN_MEM_P0_VM_SET_DACKPOL (0x1000) | ||
58 | |||
59 | |||
60 | #define CY_AN_MEM_P0_NV_SET (0x84) | ||
61 | #define CY_AN_MEM_P0_NV_SET_WPSWEN (0x0001) | ||
62 | #define CY_AN_MEM_P0_NV_SET_WPPOLAR (0x0002) | ||
63 | |||
64 | #define CY_AN_MEM_PMU_UPDATE (0x85) | ||
65 | #define CY_AN_MEM_PMU_UPDATE_UVALID (0x0001) | ||
66 | #define CY_AN_MEM_PMU_UPDATE_USBUPDATE (0x0002) | ||
67 | #define CY_AN_MEM_PMU_UPDATE_SDIOUPDATE (0x0004) | ||
68 | |||
69 | #define CY_AN_MEM_P0_INTR_REG (0x90) | ||
70 | #define CY_AN_MEM_P0_INTR_REG_MCUINT (0x0020) | ||
71 | #define CY_AN_MEM_P0_INTR_REG_DRQINT (0x0800) | ||
72 | #define CY_AN_MEM_P0_INTR_REG_MBINT (0x1000) | ||
73 | #define CY_AN_MEM_P0_INTR_REG_PMINT (0x2000) | ||
74 | #define CY_AN_MEM_P0_INTR_REG_PLLLOCKINT (0x4000) | ||
75 | |||
76 | #define CY_AN_MEM_P0_INT_MASK_REG (0x91) | ||
77 | #define CY_AN_MEM_P0_INT_MASK_REG_MMCUINT (0x0020) | ||
78 | #define CY_AN_MEM_P0_INT_MASK_REG_MDRQINT (0x0800) | ||
79 | #define CY_AN_MEM_P0_INT_MASK_REG_MMBINT (0x1000) | ||
80 | #define CY_AN_MEM_P0_INT_MASK_REG_MPMINT (0x2000) | ||
81 | #define CY_AN_MEM_P0_INT_MASK_REG_MPLLLOCKINT (0x4000) | ||
82 | |||
83 | #define CY_AN_MEM_MCU_MB_STAT (0x92) | ||
84 | #define CY_AN_MEM_P0_MCU_MBNOTRD (0x0001) | ||
85 | |||
86 | #define CY_AN_MEM_P0_MCU_STAT (0x94) | ||
87 | #define CY_AN_MEM_P0_MCU_STAT_CARDINS (0x0001) | ||
88 | #define CY_AN_MEM_P0_MCU_STAT_CARDREM (0x0002) | ||
89 | |||
90 | #define CY_AN_MEM_PWR_MAGT_STAT (0x95) | ||
91 | #define CY_AN_MEM_PWR_MAGT_STAT_WAKEUP (0x0001) | ||
92 | |||
93 | #define CY_AN_MEM_P0_RSE_ALLOCATE (0x98) | ||
94 | #define CY_AN_MEM_P0_RSE_ALLOCATE_SDIOAVI (0x0001) | ||
95 | #define CY_AN_MEM_P0_RSE_ALLOCATE_SDIOALLO (0x0002) | ||
96 | #define CY_AN_MEM_P0_RSE_ALLOCATE_NANDAVI (0x0004) | ||
97 | #define CY_AN_MEM_P0_RSE_ALLOCATE_NANDALLO (0x0008) | ||
98 | #define CY_AN_MEM_P0_RSE_ALLOCATE_USBAVI (0x0010) | ||
99 | #define CY_AN_MEM_P0_RSE_ALLOCATE_USBALLO (0x0020) | ||
100 | |||
101 | #define CY_AN_MEM_P0_RSE_MASK (0x9A) | ||
102 | #define CY_AN_MEM_P0_RSE_MASK_MSDIOBUS_RW (0x0003) | ||
103 | #define CY_AN_MEM_P0_RSE_MASK_MNANDBUS_RW (0x00C0) | ||
104 | #define CY_AN_MEM_P0_RSE_MASK_MUSBBUS_RW (0x0030) | ||
105 | |||
106 | #define CY_AN_MEM_P0_DRQ (0xA0) | ||
107 | #define CY_AN_MEM_P0_DRQ_EP2DRQ (0x0004) | ||
108 | #define CY_AN_MEM_P0_DRQ_EP3DRQ (0x0008) | ||
109 | #define CY_AN_MEM_P0_DRQ_EP4DRQ (0x0010) | ||
110 | #define CY_AN_MEM_P0_DRQ_EP5DRQ (0x0020) | ||
111 | #define CY_AN_MEM_P0_DRQ_EP6DRQ (0x0040) | ||
112 | #define CY_AN_MEM_P0_DRQ_EP7DRQ (0x0080) | ||
113 | #define CY_AN_MEM_P0_DRQ_EP8DRQ (0x0100) | ||
114 | #define CY_AN_MEM_P0_DRQ_EP9DRQ (0x0200) | ||
115 | #define CY_AN_MEM_P0_DRQ_EP10DRQ (0x0400) | ||
116 | #define CY_AN_MEM_P0_DRQ_EP11DRQ (0x0800) | ||
117 | #define CY_AN_MEM_P0_DRQ_EP12DRQ (0x1000) | ||
118 | #define CY_AN_MEM_P0_DRQ_EP13DRQ (0x2000) | ||
119 | #define CY_AN_MEM_P0_DRQ_EP14DRQ (0x4000) | ||
120 | #define CY_AN_MEM_P0_DRQ_EP15DRQ (0x8000) | ||
121 | |||
122 | #define CY_AN_MEM_P0_DRQ_MASK (0xA1) | ||
123 | #define CY_AN_MEM_P0_DRQ_MASK_MEP2DRQ (0x0004) | ||
124 | #define CY_AN_MEM_P0_DRQ_MASK_MEP3DRQ (0x0008) | ||
125 | #define CY_AN_MEM_P0_DRQ_MASK_MEP4DRQ (0x0010) | ||
126 | #define CY_AN_MEM_P0_DRQ_MASK_MEP5DRQ (0x0020) | ||
127 | #define CY_AN_MEM_P0_DRQ_MASK_MEP6DRQ (0x0040) | ||
128 | #define CY_AN_MEM_P0_DRQ_MASK_MEP7DRQ (0x0080) | ||
129 | #define CY_AN_MEM_P0_DRQ_MASK_MEP8DRQ (0x0100) | ||
130 | #define CY_AN_MEM_P0_DRQ_MASK_MEP9DRQ (0x0200) | ||
131 | #define CY_AN_MEM_P0_DRQ_MASK_MEP10DRQ (0x0400) | ||
132 | #define CY_AN_MEM_P0_DRQ_MASK_MEP11DRQ (0x0800) | ||
133 | #define CY_AN_MEM_P0_DRQ_MASK_MEP12DRQ (0x1000) | ||
134 | #define CY_AN_MEM_P0_DRQ_MASK_MEP13DRQ (0x2000) | ||
135 | #define CY_AN_MEM_P0_DRQ_MASK_MEP14DRQ (0x4000) | ||
136 | #define CY_AN_MEM_P0_DRQ_MASK_MEP15DRQ (0x8000) | ||
137 | |||
138 | #define CY_AN_MEM_P0_EP2_DMA_REG (0xA2) | ||
139 | #define CY_AN_MEM_P0_E_pn_DMA_REG_COUNT_MASK (0x7FF) | ||
140 | #define CY_AN_MEM_P0_E_pn_DMA_REG_DMAVAL (1 << 12) | ||
141 | #define CY_AN_MEM_P0_EP3_DMA_REG (0xA3) | ||
142 | #define CY_AN_MEM_P0_EP4_DMA_REG (0xA4) | ||
143 | #define CY_AN_MEM_P0_EP5_DMA_REG (0xA5) | ||
144 | #define CY_AN_MEM_P0_EP6_DMA_REG (0xA6) | ||
145 | #define CY_AN_MEM_P0_EP7_DMA_REG (0xA7) | ||
146 | #define CY_AN_MEM_P0_EP8_DMA_REG (0xA8) | ||
147 | #define CY_AN_MEM_P0_EP9_DMA_REG (0xA9) | ||
148 | #define CY_AN_MEM_P0_EP10_DMA_REG (0xAA) | ||
149 | #define CY_AN_MEM_P0_EP11_DMA_REG (0xAB) | ||
150 | #define CY_AN_MEM_P0_EP12_DMA_REG (0xAC) | ||
151 | #define CY_AN_MEM_P0_EP13_DMA_REG (0xAD) | ||
152 | #define CY_AN_MEM_P0_EP14_DMA_REG (0xAE) | ||
153 | #define CY_AN_MEM_P0_EP15_DMA_REG (0xAF) | ||
154 | |||
155 | #define CY_AN_MEM_IROS_IO_CFG (0xC1) | ||
156 | #define CY_AN_MEM_IROS_IO_CFG_GPIODRVST_MASK (0x0003) | ||
157 | #define CY_AN_MEM_IROS_IO_CFG_GPIOSLEW_MASK (0x0004) | ||
158 | #define CY_AN_MEM_IROS_IO_CFG_PPIODRVST_MASK (0x0018) | ||
159 | #define CY_AN_MEM_IROS_IO_CFG_PPIOSLEW_MASK (0x0020) | ||
160 | #define CY_AN_MEM_IROS_IO_CFG_SSIODRVST_MASK (0x0300) | ||
161 | #define CY_AN_MEM_IROS_IO_CFG_SSIOSLEW_MASK (0x0400) | ||
162 | #define CY_AN_MEM_IROS_IO_CFG_SNIODRVST_MASK (0x1800) | ||
163 | #define CY_AN_MEM_IROS_IO_CFG_SNIOSLEW_MASK (0x2000) | ||
164 | |||
165 | #define CY_AN_MEM_PLL_LOCK_LOSS_STAT (0xC4) | ||
166 | #define CY_AN_MEM_PLL_LOCK_LOSS_STAT_PLLSTAT (0x0800) | ||
167 | |||
168 | #define CY_AN_MEM_P0_MAILBOX0 (0xF0) | ||
169 | #define CY_AN_MEM_P0_MAILBOX1 (0xF1) | ||
170 | #define CY_AN_MEM_P0_MAILBOX2 (0xF2) | ||
171 | #define CY_AN_MEM_P0_MAILBOX3 (0xF3) | ||
172 | |||
173 | #define CY_AN_MEM_MCU_MAILBOX0 (0xF8) | ||
174 | #define CY_AN_MEM_MCU_MAILBOX1 (0xF9) | ||
175 | #define CY_AN_MEM_MCU_MAILBOX2 (0xFA) | ||
176 | #define CY_AN_MEM_MCU_MAILBOX3 (0xFB) | ||
177 | |||
178 | #endif /* !defined(__doxygen__) */ | ||
179 | |||
180 | #endif /* _INCLUDED_CYANREG_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyansdkversion.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyansdkversion.h deleted file mode 100644 index ac26b9556dda..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyansdkversion.h +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | /* Cypress Antioch Sdk Version file (cyansdkversion.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYANSDK_VERSION_H_ | ||
23 | #define _INCLUDED_CYANSDK_VERSION_H_ | ||
24 | |||
25 | /* Antioch SDK version 1.3.2 */ | ||
26 | #define CYAN_MAJOR_VERSION (1) | ||
27 | #define CYAN_MINOR_VERSION (3) | ||
28 | #define CYAN_BUILD_NUMBER (473) | ||
29 | |||
30 | #endif /*_INCLUDED_CYANSDK_VERSION_H_*/ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanstorage.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanstorage.h deleted file mode 100644 index deb9af87fff4..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanstorage.h +++ /dev/null | |||
@@ -1,419 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanstorage.h) | ||
2 | ## Header for backward compatibility with previous releases of Antioch SDK. | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street | ||
19 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef _INCLUDED_CYANSTORAGE_H_ | ||
24 | #define _INCLUDED_CYANSTORAGE_H_ | ||
25 | #ifndef __doxygen__ | ||
26 | |||
27 | #include "cyanmedia.h" | ||
28 | #include "cyanmisc.h" | ||
29 | #include "cyasstorage.h" | ||
30 | #include "cyas_cplus_start.h" | ||
31 | |||
32 | #define CY_AN_LUN_PHYSICAL_DEVICE (CY_AS_LUN_PHYSICAL_DEVICE) | ||
33 | #define CY_AN_STORAGE_EP_SIZE (CY_AS_STORAGE_EP_SIZE) | ||
34 | |||
35 | #define cy_an_storage_antioch cy_as_storage_antioch | ||
36 | #define cy_an_storage_processor cy_as_storage_processor | ||
37 | #define cy_an_storage_removed cy_as_storage_removed | ||
38 | #define cy_an_storage_inserted cy_as_storage_inserted | ||
39 | #define cy_an_sdio_interrupt cy_as_sdio_interrupt | ||
40 | typedef cy_as_storage_event cy_an_storage_event; | ||
41 | |||
42 | #define cy_an_op_read cy_as_op_read | ||
43 | #define cy_an_op_write cy_as_op_write | ||
44 | typedef cy_as_oper_type cy_an_oper_type; | ||
45 | |||
46 | typedef cy_as_device_desc cy_an_device_desc; | ||
47 | |||
48 | typedef cy_as_unit_desc cy_an_unit_desc; | ||
49 | |||
50 | typedef cy_as_storage_callback_dep \ | ||
51 | cy_an_storage_callback; | ||
52 | |||
53 | typedef cy_as_storage_event_callback_dep \ | ||
54 | cy_an_storage_event_callback; | ||
55 | |||
56 | #define cy_an_sd_reg_OCR cy_as_sd_reg_OCR | ||
57 | #define cy_an_sd_reg_CID cy_as_sd_reg_CID | ||
58 | #define cy_an_sd_reg_CSD cy_as_sd_reg_CSD | ||
59 | typedef cy_as_sd_card_reg_type \ | ||
60 | cy_an_sd_card_reg_type; | ||
61 | |||
62 | typedef cy_as_storage_query_device_data_dep \ | ||
63 | cy_an_storage_query_device_data; | ||
64 | |||
65 | typedef cy_as_storage_query_unit_data_dep \ | ||
66 | cy_an_storage_query_unit_data; | ||
67 | |||
68 | typedef cy_as_storage_sd_reg_read_data \ | ||
69 | cy_an_storage_sd_reg_read_data; | ||
70 | |||
71 | #define CY_AN_SD_REG_OCR_LENGTH (CY_AS_SD_REG_OCR_LENGTH) | ||
72 | #define CY_AN_SD_REG_CID_LENGTH (CY_AS_SD_REG_CID_LENGTH) | ||
73 | #define CY_AN_SD_REG_CSD_LENGTH (CY_AS_SD_REG_CSD_LENGTH) | ||
74 | #define CY_AN_SD_REG_MAX_RESP_LENGTH \ | ||
75 | (CY_AS_SD_REG_MAX_RESP_LENGTH) | ||
76 | |||
77 | /**** API Functions ******/ | ||
78 | |||
79 | /* Sync version of Storage Start */ | ||
80 | EXTERN cy_an_return_status_t | ||
81 | cy_an_storage_start( | ||
82 | cy_an_device_handle handle | ||
83 | ); | ||
84 | #define cy_an_storage_start(handle) \ | ||
85 | cy_as_storage_start((cy_as_device_handle)(handle), 0, 0) | ||
86 | |||
87 | /* Async version of Storage Start */ | ||
88 | EXTERN cy_an_return_status_t | ||
89 | cy_an_storage_start_e_x( | ||
90 | cy_an_device_handle handle, | ||
91 | cy_an_function_callback cb, | ||
92 | uint32_t client | ||
93 | ); | ||
94 | #define cy_an_storage_start_e_x(h, cb, client) \ | ||
95 | cy_as_storage_start((cy_as_device_handle)(h), \ | ||
96 | (cy_as_function_callback)(cb), (client)) | ||
97 | |||
98 | /* Sync version of Storage Stop */ | ||
99 | EXTERN cy_an_return_status_t | ||
100 | cy_an_storage_stop( | ||
101 | cy_an_device_handle handle | ||
102 | ); | ||
103 | #define cy_an_storage_stop(handle) \ | ||
104 | cy_as_storage_stop((cy_as_device_handle)(handle), 0, 0) | ||
105 | |||
106 | /* Async version of Storage Stop */ | ||
107 | EXTERN cy_an_return_status_t | ||
108 | cy_an_storage_stop_e_x( | ||
109 | cy_an_device_handle handle, | ||
110 | cy_an_function_callback cb, | ||
111 | uint32_t client | ||
112 | ); | ||
113 | #define cy_an_storage_stop_e_x(h, cb, client) \ | ||
114 | cy_as_storage_stop((cy_as_device_handle)(h), \ | ||
115 | (cy_as_function_callback)(cb), (client)) | ||
116 | |||
117 | /* Register Call back api */ | ||
118 | EXTERN cy_an_return_status_t | ||
119 | cy_an_storage_register_callback( | ||
120 | cy_an_device_handle handle, | ||
121 | cy_an_storage_event_callback callback | ||
122 | ); | ||
123 | #define cy_an_storage_register_callback(h, cb) \ | ||
124 | cy_as_storage_register_callback_dep((cy_as_device_handle)(h), \ | ||
125 | (cy_as_storage_event_callback_dep)(cb)) | ||
126 | |||
127 | /* Sync version of Storage Claim */ | ||
128 | EXTERN cy_an_return_status_t | ||
129 | cy_an_storage_claim( | ||
130 | cy_an_device_handle handle, | ||
131 | cy_an_media_type type | ||
132 | ); | ||
133 | #define cy_an_storage_claim(h, type) \ | ||
134 | cy_as_storage_claim_dep((cy_as_device_handle)(h), \ | ||
135 | (cy_as_media_type)(type)) | ||
136 | |||
137 | /* Async version of Storage Claim */ | ||
138 | EXTERN cy_an_return_status_t | ||
139 | cy_an_storage_claim_e_x( | ||
140 | cy_an_device_handle handle, | ||
141 | cy_an_media_type *type, | ||
142 | cy_an_function_callback cb, | ||
143 | uint32_t client | ||
144 | ); | ||
145 | #define cy_an_storage_claim_e_x(h, type_p, cb, client) \ | ||
146 | cy_as_storage_claim_dep_EX((cy_as_device_handle)(h), \ | ||
147 | (cy_as_media_type *)(type_p), \ | ||
148 | (cy_as_function_callback)(cb), (client)) | ||
149 | |||
150 | /* Sync Version of Storage Release */ | ||
151 | EXTERN cy_an_return_status_t | ||
152 | cy_an_storage_release( | ||
153 | cy_an_device_handle handle, | ||
154 | cy_an_media_type type | ||
155 | ); | ||
156 | #define cy_an_storage_release(h, type) \ | ||
157 | cy_as_storage_release_dep((cy_as_device_handle)(h), \ | ||
158 | (cy_as_media_type)(type)) | ||
159 | |||
160 | /* Async Version of Storage Release */ | ||
161 | EXTERN cy_an_return_status_t | ||
162 | cy_an_storage_release_e_x( | ||
163 | cy_an_device_handle handle, | ||
164 | cy_an_media_type *type, | ||
165 | cy_an_function_callback cb, | ||
166 | uint32_t client | ||
167 | ); | ||
168 | #define cy_an_storage_release_e_x(h, type_p, cb, client) \ | ||
169 | cy_as_storage_release_dep_EX((cy_as_device_handle)(h), \ | ||
170 | (cy_as_media_type *)(type_p), \ | ||
171 | (cy_as_function_callback)(cb), (client)) | ||
172 | |||
173 | /* Sync version of Query Media */ | ||
174 | EXTERN cy_an_return_status_t | ||
175 | cy_an_storage_query_media( | ||
176 | cy_an_device_handle handle, | ||
177 | cy_an_media_type type, | ||
178 | uint32_t *count | ||
179 | ); | ||
180 | #define cy_an_storage_query_media(handle, type, count) \ | ||
181 | cy_as_storage_query_media((cy_as_device_handle)(handle), \ | ||
182 | (cy_as_media_type)(type), (count), 0, 0) | ||
183 | |||
184 | /* Async version of Query Media */ | ||
185 | EXTERN cy_an_return_status_t | ||
186 | cy_an_storage_query_media_e_x( | ||
187 | cy_an_device_handle handle, | ||
188 | cy_an_media_type type, | ||
189 | uint32_t *count, | ||
190 | cy_an_function_callback cb, | ||
191 | uint32_t client | ||
192 | ); | ||
193 | #define cy_an_storage_query_media_e_x(h, type, count, cb, client) \ | ||
194 | cy_as_storage_query_media((cy_as_device_handle)(h), \ | ||
195 | (cy_as_media_type)(type), (count), \ | ||
196 | (cy_as_function_callback)(cb), (client)) | ||
197 | |||
198 | /* Sync version of Query device */ | ||
199 | EXTERN cy_an_return_status_t | ||
200 | cy_an_storage_query_device( | ||
201 | cy_an_device_handle handle, | ||
202 | cy_an_media_type type, | ||
203 | uint32_t device, | ||
204 | cy_an_device_desc *desc_p | ||
205 | ); | ||
206 | #define cy_an_storage_query_device(h, type, device, desc_p) \ | ||
207 | cy_as_storage_query_device_dep((cy_as_device_handle)(h), \ | ||
208 | (cy_as_media_type)(type), (device), (cy_as_device_desc *)(desc_p)) | ||
209 | |||
210 | /* Async version of Query device */ | ||
211 | EXTERN cy_an_return_status_t | ||
212 | cy_an_storage_query_device_e_x( | ||
213 | cy_an_device_handle handle, | ||
214 | cy_an_storage_query_device_data *data, | ||
215 | cy_an_function_callback cb, | ||
216 | uint32_t client | ||
217 | ); | ||
218 | #define cy_an_storage_query_device_e_x(h, data, cb, client) \ | ||
219 | cy_as_storage_query_device_dep_EX((cy_as_device_handle)(h), \ | ||
220 | (cy_as_storage_query_device_data_dep *)(data), \ | ||
221 | (cy_as_function_callback)(cb), (client)) | ||
222 | |||
223 | /* Sync version of Query Unit */ | ||
224 | EXTERN cy_an_return_status_t | ||
225 | cy_an_storage_query_unit( | ||
226 | cy_an_device_handle handle, | ||
227 | cy_an_media_type type, | ||
228 | uint32_t device, | ||
229 | uint32_t unit, | ||
230 | cy_an_unit_desc *desc_p | ||
231 | ); | ||
232 | #define cy_an_storage_query_unit(h, type, device, unit, desc_p) \ | ||
233 | cy_as_storage_query_unit_dep((cy_as_device_handle)(h), \ | ||
234 | (cy_as_media_type)(type), (device), \ | ||
235 | (unit), (cy_as_unit_desc *)(desc_p)) | ||
236 | |||
237 | /* Async version of Query Unit */ | ||
238 | EXTERN cy_an_return_status_t | ||
239 | cy_an_storage_query_unit_e_x( | ||
240 | cy_an_device_handle handle, | ||
241 | cy_an_storage_query_unit_data *data_p, | ||
242 | cy_an_function_callback cb, | ||
243 | uint32_t client | ||
244 | ); | ||
245 | #define cy_an_storage_query_unit_e_x(h, data_p, cb, client) \ | ||
246 | cy_as_storage_query_unit_dep_EX((cy_as_device_handle)(h), \ | ||
247 | (cy_as_storage_query_unit_data_dep *)(data_p), \ | ||
248 | (cy_as_function_callback)(cb), (client)) | ||
249 | |||
250 | /* Sync version of device control */ | ||
251 | EXTERN cy_an_return_status_t | ||
252 | cy_an_storage_device_control( | ||
253 | cy_an_device_handle handle, | ||
254 | cy_bool card_detect_en, | ||
255 | cy_bool write_prot_en | ||
256 | ); | ||
257 | #define cy_an_storage_device_control(handle, \ | ||
258 | card_detect_en, write_prot_en) \ | ||
259 | cy_as_storage_device_control_dep((cy_as_device_handle)(handle), \ | ||
260 | (card_detect_en), (write_prot_en), 0, 0) | ||
261 | |||
262 | /* Async version of device control */ | ||
263 | EXTERN cy_an_return_status_t | ||
264 | cy_an_storage_device_control_e_x( | ||
265 | cy_an_device_handle handle, | ||
266 | cy_bool card_detect_en, | ||
267 | cy_bool write_prot_en, | ||
268 | cy_an_function_callback cb, | ||
269 | uint32_t client | ||
270 | ); | ||
271 | #define cy_an_storage_device_control_e_x(h, det_en, prot_en, cb, client) \ | ||
272 | cy_as_storage_device_control_dep((cy_as_device_handle)(h), (det_en), \ | ||
273 | (prot_en), (cy_as_function_callback)(cb), (client)) | ||
274 | |||
275 | /* Sync Read */ | ||
276 | EXTERN cy_an_return_status_t | ||
277 | cy_an_storage_read( | ||
278 | cy_an_device_handle handle, | ||
279 | cy_an_media_type type, | ||
280 | uint32_t device, | ||
281 | uint32_t unit, | ||
282 | uint32_t block, | ||
283 | void *data_p, | ||
284 | uint16_t num_blocks | ||
285 | ); | ||
286 | #define cy_an_storage_read(h, type, device, unit, block, data_p, nblks) \ | ||
287 | cy_as_storage_read_dep((cy_as_device_handle)(h), \ | ||
288 | (cy_as_media_type)(type), (device), (unit), \ | ||
289 | (block), (data_p), (nblks)) | ||
290 | |||
291 | /* Async Read */ | ||
292 | EXTERN cy_an_return_status_t | ||
293 | cy_an_storage_read_async( | ||
294 | cy_an_device_handle handle, | ||
295 | cy_an_media_type type, | ||
296 | uint32_t device, | ||
297 | uint32_t unit, | ||
298 | uint32_t block, | ||
299 | void *data_p, | ||
300 | uint16_t num_blocks, | ||
301 | cy_an_storage_callback callback | ||
302 | ); | ||
303 | #define cy_an_storage_read_async(h, type, device, unit, \ | ||
304 | block, data_p, nblks, cb) \ | ||
305 | cy_as_storage_read_async_dep((cy_as_device_handle)(h), \ | ||
306 | (cy_as_media_type)(type), (device), (unit), (block), \ | ||
307 | (data_p), (nblks), (cy_as_storage_callback_dep)(cb)) | ||
308 | |||
309 | /* Sync Write */ | ||
310 | EXTERN cy_an_return_status_t | ||
311 | cy_an_storage_write( | ||
312 | cy_an_device_handle handle, | ||
313 | cy_an_media_type type, | ||
314 | uint32_t device, | ||
315 | uint32_t unit, | ||
316 | uint32_t block, | ||
317 | void *data_p, | ||
318 | uint16_t num_blocks | ||
319 | ); | ||
320 | #define cy_an_storage_write(h, type, device, unit, \ | ||
321 | block, data_p, nblks) \ | ||
322 | cy_as_storage_write_dep((cy_as_device_handle)(h), \ | ||
323 | (cy_as_media_type)(type), (device), (unit), \ | ||
324 | (block), (data_p), (nblks)) | ||
325 | |||
326 | /* Async Write */ | ||
327 | EXTERN cy_an_return_status_t | ||
328 | cy_an_storage_write_async( | ||
329 | cy_an_device_handle handle, | ||
330 | cy_an_media_type type, | ||
331 | uint32_t device, | ||
332 | uint32_t unit, | ||
333 | uint32_t block, | ||
334 | void *data_p, | ||
335 | uint16_t num_blocks, | ||
336 | cy_an_storage_callback callback | ||
337 | ); | ||
338 | #define cy_an_storage_write_async(h, type, device, unit, \ | ||
339 | block, data_p, nblks, cb) \ | ||
340 | cy_as_storage_write_async_dep((cy_as_device_handle)(h), \ | ||
341 | (cy_as_media_type)(type), (device), (unit), (block), \ | ||
342 | (data_p), (nblks), (cy_as_storage_callback_dep)(cb)) | ||
343 | |||
344 | /* Cancel Async */ | ||
345 | EXTERN cy_an_return_status_t | ||
346 | cy_an_storage_cancel_async( | ||
347 | cy_an_device_handle handle | ||
348 | ); | ||
349 | #define cy_an_storage_cancel_async(h) \ | ||
350 | cy_as_storage_cancel_async((cy_as_device_handle)(h)) | ||
351 | |||
352 | /* Sync SD Register Read*/ | ||
353 | EXTERN cy_an_return_status_t | ||
354 | cy_an_storage_sd_register_read( | ||
355 | cy_an_device_handle handle, | ||
356 | cy_an_media_type type, | ||
357 | uint8_t device, | ||
358 | cy_an_sd_card_reg_type reg_type, | ||
359 | uint8_t read_len, | ||
360 | uint8_t *data_p | ||
361 | ); | ||
362 | #define cy_an_storage_sd_register_read(h, type, device, \ | ||
363 | reg_type, len, data_p) \ | ||
364 | cy_as_storage_sd_register_read_dep((cy_as_device_handle)(h), \ | ||
365 | (cy_as_media_type)(type), (device), \ | ||
366 | (cy_as_sd_card_reg_type)(reg_type), (len), (data_p)) | ||
367 | |||
368 | /*Async SD Register Read*/ | ||
369 | EXTERN cy_an_return_status_t | ||
370 | cy_an_storage_sd_register_read_e_x( | ||
371 | cy_an_device_handle handle, | ||
372 | cy_an_media_type type, | ||
373 | uint8_t device, | ||
374 | cy_an_sd_card_reg_type reg_type, | ||
375 | cy_an_storage_sd_reg_read_data *data_p, | ||
376 | cy_an_function_callback cb, | ||
377 | uint32_t client | ||
378 | ); | ||
379 | #define cy_an_storage_sd_register_read_e_x(h, type, device, \ | ||
380 | reg_type, data_p, cb, client) \ | ||
381 | cy_as_storage_sd_register_read_dep_EX((cy_as_device_handle)(h), \ | ||
382 | (cy_as_media_type)(type), (device), \ | ||
383 | (cy_as_sd_card_reg_type)(reg_type), \ | ||
384 | (cy_as_storage_sd_reg_read_data *)(data_p), \ | ||
385 | (cy_as_function_callback)(cb), (client)) | ||
386 | |||
387 | /* Create partition on storage device */ | ||
388 | EXTERN cy_an_return_status_t | ||
389 | cy_an_storage_create_p_partition( | ||
390 | cy_an_device_handle handle, | ||
391 | cy_an_media_type media, | ||
392 | uint32_t device, | ||
393 | uint32_t size, | ||
394 | cy_an_function_callback cb, | ||
395 | uint32_t client); | ||
396 | #define cy_an_storage_create_p_partition(h, media, dev, \ | ||
397 | size, cb, client) \ | ||
398 | cy_as_storage_create_p_partition_dep((cy_as_device_handle)(h), \ | ||
399 | (cy_as_media_type)(media), (dev), \ | ||
400 | (size), (cy_as_function_callback)(cb), (client)) | ||
401 | |||
402 | /* Remove partition on storage device */ | ||
403 | EXTERN cy_an_return_status_t | ||
404 | cy_an_storage_remove_p_partition( | ||
405 | cy_an_device_handle handle, | ||
406 | cy_an_media_type media, | ||
407 | uint32_t device, | ||
408 | cy_an_function_callback cb, | ||
409 | uint32_t client); | ||
410 | #define cy_an_storage_remove_p_partition\ | ||
411 | (h, media, dev, cb, client) \ | ||
412 | cy_as_storage_remove_p_partition_dep((cy_as_device_handle)(h), \ | ||
413 | (cy_as_media_type)(media), (dev), \ | ||
414 | (cy_as_function_callback)(cb), (client)) | ||
415 | |||
416 | #include "cyas_cplus_end.h" | ||
417 | #endif /*__doxygen__ */ | ||
418 | |||
419 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantioch.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantioch.h deleted file mode 100644 index d65b35a14ae1..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantioch.h +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyastioch.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYANTIOCH_H_ | ||
23 | #define _INCLUDED_CYANTIOCH_H_ | ||
24 | |||
25 | #if !defined(__doxygen__) | ||
26 | |||
27 | #include "cyanerr.h" | ||
28 | #include "cyanmisc.h" | ||
29 | #include "cyanstorage.h" | ||
30 | #include "cyanusb.h" | ||
31 | #include "cyanch9.h" | ||
32 | |||
33 | #endif | ||
34 | |||
35 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantypes.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantypes.h deleted file mode 100644 index 48cd50f13c12..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyantypes.h +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyantypes.h) | ||
2 | ## Type definitions for backward compatibility with previous | ||
3 | ## Antioch SDK releases. | ||
4 | ## =========================== | ||
5 | ## Copyright (C) 2010 Cypress Semiconductor | ||
6 | ## | ||
7 | ## This program is free software; you can redistribute it and/or | ||
8 | ## modify it under the terms of the GNU General Public License | ||
9 | ## as published by the Free Software Foundation; either version 2 | ||
10 | ## of the License, or (at your option) any later version. | ||
11 | ## | ||
12 | ## This program is distributed in the hope that it will be useful, | ||
13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | ## GNU General Public License for more details. | ||
16 | ## | ||
17 | ## You should have received a copy of the GNU General Public License | ||
18 | ## along with this program; if not, write to the Free Software | ||
19 | ## Foundation, Inc., 51 Franklin Street | ||
20 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
21 | ## =========================== | ||
22 | */ | ||
23 | |||
24 | #ifndef _INCLUDED_CYANTYPES_H_ | ||
25 | #define _INCLUDED_CYANTYPES_H_ | ||
26 | |||
27 | #include "cyastypes.h" | ||
28 | typedef cy_as_end_point_number_t cy_an_end_point_number_t; | ||
29 | typedef cy_as_return_status_t cy_an_return_status_t; | ||
30 | typedef cy_as_bus_number_t cy_an_bus_number_t; | ||
31 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanusb.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanusb.h deleted file mode 100644 index 1e4e7dbe31b0..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyanusb.h +++ /dev/null | |||
@@ -1,619 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanusb.h) | ||
2 | ## Header for backward compatibility with previous Antioch SDK releases. | ||
3 | ## =========================== | ||
4 | ## Copyright (C) 2010 Cypress Semiconductor | ||
5 | ## | ||
6 | ## This program is free software; you can redistribute it and/or | ||
7 | ## modify it under the terms of the GNU General Public License | ||
8 | ## as published by the Free Software Foundation; either version 2 | ||
9 | ## of the License, or (at your option) any later version. | ||
10 | ## | ||
11 | ## This program is distributed in the hope that it will be useful, | ||
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | ## GNU General Public License for more details. | ||
15 | ## | ||
16 | ## You should have received a copy of the GNU General Public License | ||
17 | ## along with this program; if not, write to the Free Software | ||
18 | ## Foundation, Inc., 51 Franklin Street | ||
19 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | ## =========================== | ||
21 | */ | ||
22 | |||
23 | #ifndef _INCLUDED_CYANUSB_H_ | ||
24 | #define _INCLUDED_CYANUSB_H_ | ||
25 | |||
26 | #if !defined(__doxygen__) | ||
27 | |||
28 | #include "cyanmisc.h" | ||
29 | #include "cyasusb.h" | ||
30 | #include "cyas_cplus_start.h" | ||
31 | |||
32 | #define CY_AN_MAX_USB_DESCRIPTOR_SIZE (CY_AS_MAX_USB_DESCRIPTOR_SIZE) | ||
33 | |||
34 | typedef cy_as_usb_inquiry_data_dep cy_an_usb_inquiry_data; | ||
35 | typedef cy_as_usb_unknown_command_data_dep \ | ||
36 | cy_an_usb_unknown_command_data; | ||
37 | typedef cy_as_usb_start_stop_data_dep cy_an_usb_start_stop_data; | ||
38 | typedef cy_as_m_s_c_progress_data cy_an_m_s_c_progress_data; | ||
39 | |||
40 | #define cy_an_usb_nand_enum cy_as_usb_nand_enum | ||
41 | #define cy_an_usb_sd_enum cy_as_usb_sd_enum | ||
42 | #define cy_an_usb_mmc_enum cy_as_usb_mmc_enum | ||
43 | #define cy_an_usb_ce_ata_enum cy_as_usb_ce_ata_enum | ||
44 | typedef cy_as_usb_mass_storage_enum cy_an_usb_mass_storage_enum; | ||
45 | |||
46 | #define cy_an_usb_desc_device cy_as_usb_desc_device | ||
47 | #define cy_an_usb_desc_device_qual cy_as_usb_desc_device_qual | ||
48 | #define cy_an_usb_desc_f_s_configuration \ | ||
49 | cy_as_usb_desc_f_s_configuration | ||
50 | #define cy_an_usb_desc_h_s_configuration \ | ||
51 | cy_as_usb_desc_h_s_configuration | ||
52 | #define cy_an_usb_desc_string cy_as_usb_desc_string | ||
53 | typedef cy_as_usb_desc_type cy_an_usb_desc_type; | ||
54 | |||
55 | #define cy_an_usb_in cy_as_usb_in | ||
56 | #define cy_an_usb_out cy_as_usb_out | ||
57 | #define cy_an_usb_in_out cy_as_usb_in_out | ||
58 | typedef cy_as_usb_end_point_dir cy_an_usb_end_point_dir; | ||
59 | |||
60 | |||
61 | #define cy_an_usb_control cy_as_usb_control | ||
62 | #define cy_an_usb_iso cy_as_usb_iso | ||
63 | #define cy_an_usb_bulk cy_as_usb_bulk | ||
64 | #define cy_an_usb_int cy_as_usb_int | ||
65 | typedef cy_as_usb_end_point_type cy_an_usb_end_point_type; | ||
66 | |||
67 | |||
68 | typedef cy_as_usb_enum_control_dep cy_an_usb_enum_control; | ||
69 | typedef cy_as_usb_end_point_config cy_an_usb_end_point_config; | ||
70 | |||
71 | #define cy_an_usb_m_s_unit0 cy_as_usb_m_s_unit0 | ||
72 | #define cy_an_usb_m_s_unit1 cy_as_usb_m_s_unit1 | ||
73 | #define cy_an_usb_m_s_both cy_as_usb_m_s_both | ||
74 | typedef cy_as_usb_m_s_type_t cy_an_usb_m_s_type_t; | ||
75 | |||
76 | #define cy_an_event_usb_suspend cy_as_event_usb_suspend | ||
77 | #define cy_an_event_usb_resume cy_as_event_usb_resume | ||
78 | #define cy_an_event_usb_reset cy_as_event_usb_reset | ||
79 | #define cy_an_event_usb_set_config cy_as_event_usb_set_config | ||
80 | #define cy_an_event_usb_speed_change cy_as_event_usb_speed_change | ||
81 | #define cy_an_event_usb_setup_packet cy_as_event_usb_setup_packet | ||
82 | #define cy_an_event_usb_status_packet cy_as_event_usb_status_packet | ||
83 | #define cy_an_event_usb_inquiry_before cy_as_event_usb_inquiry_before | ||
84 | #define cy_an_event_usb_inquiry_after cy_as_event_usb_inquiry_after | ||
85 | #define cy_an_event_usb_start_stop cy_as_event_usb_start_stop | ||
86 | #define cy_an_event_usb_unknown_storage cy_as_event_usb_unknown_storage | ||
87 | #define cy_an_event_usb_m_s_c_progress cy_as_event_usb_m_s_c_progress | ||
88 | typedef cy_as_usb_event cy_an_usb_event; | ||
89 | |||
90 | typedef cy_as_usb_event_callback_dep cy_an_usb_event_callback; | ||
91 | |||
92 | typedef cy_as_usb_io_callback cy_an_usb_io_callback; | ||
93 | typedef cy_as_usb_function_callback cy_an_usb_function_callback; | ||
94 | |||
95 | /******* USB Functions ********************/ | ||
96 | |||
97 | /* Sync Usb Start */ | ||
98 | extern cy_an_return_status_t | ||
99 | cy_an_usb_start( | ||
100 | cy_an_device_handle handle | ||
101 | ); | ||
102 | #define cy_an_usb_start(handle) \ | ||
103 | cy_as_usb_start((cy_as_device_handle)(handle), 0, 0) | ||
104 | |||
105 | /*Async Usb Start */ | ||
106 | extern cy_an_return_status_t | ||
107 | cy_an_usb_start_e_x( | ||
108 | cy_an_device_handle handle, | ||
109 | cy_an_function_callback cb, | ||
110 | uint32_t client | ||
111 | ); | ||
112 | #define cy_an_usb_start_e_x(h, cb, client) \ | ||
113 | cy_as_usb_start((cy_as_device_handle)(h), \ | ||
114 | (cy_as_function_callback)(cb), (client)) | ||
115 | |||
116 | /* Sync Usb Stop */ | ||
117 | extern cy_an_return_status_t | ||
118 | cy_an_usb_stop( | ||
119 | cy_an_device_handle handle | ||
120 | ); | ||
121 | #define cy_an_usb_stop(handle) \ | ||
122 | cy_as_usb_stop((cy_as_device_handle)(handle), 0, 0) | ||
123 | |||
124 | /*Async Usb Stop */ | ||
125 | extern cy_an_return_status_t | ||
126 | cy_an_usb_stop_e_x( | ||
127 | cy_an_device_handle handle, | ||
128 | cy_an_function_callback cb, | ||
129 | uint32_t client | ||
130 | ); | ||
131 | #define cy_an_usb_stop_e_x(h, cb, client) \ | ||
132 | cy_as_usb_stop((cy_as_device_handle)(h), \ | ||
133 | (cy_as_function_callback)(cb), (client)) | ||
134 | |||
135 | /* Register USB event callback */ | ||
136 | EXTERN cy_an_return_status_t | ||
137 | cy_an_usb_register_callback( | ||
138 | cy_an_device_handle handle, | ||
139 | cy_an_usb_event_callback callback | ||
140 | ); | ||
141 | #define cy_an_usb_register_callback(h, cb) \ | ||
142 | cy_as_usb_register_callback_dep((cy_as_device_handle)(h), \ | ||
143 | (cy_as_usb_event_callback_dep)(cb)) | ||
144 | |||
145 | /*Sync Usb connect */ | ||
146 | EXTERN cy_an_return_status_t | ||
147 | cy_an_usb_connect( | ||
148 | cy_an_device_handle handle | ||
149 | ); | ||
150 | #define cy_an_usb_connect(handle) \ | ||
151 | cy_as_usb_connect((cy_as_device_handle)(handle), 0, 0) | ||
152 | |||
153 | /*Async Usb connect */ | ||
154 | extern cy_an_return_status_t | ||
155 | cy_an_usb_connect_e_x( | ||
156 | cy_an_device_handle handle, | ||
157 | cy_an_function_callback cb, | ||
158 | uint32_t client | ||
159 | ); | ||
160 | #define cy_an_usb_connect_e_x(h, cb, client) \ | ||
161 | cy_as_usb_connect((cy_as_device_handle)(h), \ | ||
162 | (cy_as_function_callback)(cb), (client)) | ||
163 | |||
164 | /*Sync Usb disconnect */ | ||
165 | EXTERN cy_an_return_status_t | ||
166 | cy_an_usb_disconnect( | ||
167 | cy_an_device_handle handle | ||
168 | ); | ||
169 | #define cy_an_usb_disconnect(handle) \ | ||
170 | cy_as_usb_disconnect((cy_as_device_handle)(handle), 0, 0) | ||
171 | |||
172 | /*Async Usb disconnect */ | ||
173 | extern cy_an_return_status_t | ||
174 | cy_an_usb_disconnect_e_x( | ||
175 | cy_an_device_handle handle, | ||
176 | cy_an_function_callback cb, | ||
177 | uint32_t client | ||
178 | ); | ||
179 | #define cy_an_usb_disconnect_e_x(h, cb, client) \ | ||
180 | cy_as_usb_disconnect((cy_as_device_handle)(h), \ | ||
181 | (cy_as_function_callback)(cb), (client)) | ||
182 | |||
183 | /* Sync version of set enum config */ | ||
184 | EXTERN cy_an_return_status_t | ||
185 | cy_an_usb_set_enum_config( | ||
186 | cy_an_device_handle handle, | ||
187 | cy_an_usb_enum_control *config_p | ||
188 | ); | ||
189 | #define cy_an_usb_set_enum_config(handle, config_p) \ | ||
190 | cy_as_usb_set_enum_config_dep((cy_as_device_handle)(handle), \ | ||
191 | (cy_as_usb_enum_control_dep *)(config_p), 0, 0) | ||
192 | |||
193 | /* Async version of set enum config */ | ||
194 | extern cy_an_return_status_t | ||
195 | cy_an_usb_set_enum_config_e_x( | ||
196 | cy_an_device_handle handle, | ||
197 | cy_an_usb_enum_control *config_p, | ||
198 | cy_an_function_callback cb, | ||
199 | uint32_t client | ||
200 | ); | ||
201 | #define cy_an_usb_set_enum_config_e_x(h, config_p, cb, client) \ | ||
202 | cy_as_usb_set_enum_config_dep((cy_as_device_handle)(h), \ | ||
203 | (cy_as_usb_enum_control_dep *)(config_p), \ | ||
204 | (cy_as_function_callback)(cb), (client)) | ||
205 | |||
206 | /* Sync version of get enum config */ | ||
207 | EXTERN cy_an_return_status_t | ||
208 | cy_an_usb_get_enum_config( | ||
209 | cy_an_device_handle handle, | ||
210 | cy_an_usb_enum_control *config_p | ||
211 | ); | ||
212 | #define cy_an_usb_get_enum_config(handle, config_p) \ | ||
213 | cy_as_usb_get_enum_config_dep((cy_as_device_handle)(handle), \ | ||
214 | (cy_as_usb_enum_control_dep *)(config_p), 0, 0) | ||
215 | |||
216 | /* Async version of get enum config */ | ||
217 | extern cy_an_return_status_t | ||
218 | cy_an_usb_get_enum_config_e_x( | ||
219 | cy_an_device_handle handle, | ||
220 | cy_an_usb_enum_control *config_p, | ||
221 | cy_an_function_callback cb, | ||
222 | uint32_t client | ||
223 | ); | ||
224 | #define cy_an_usb_get_enum_config_e_x(h, config_p, cb, client) \ | ||
225 | cy_as_usb_get_enum_config_dep((cy_as_device_handle)(h), \ | ||
226 | (cy_as_usb_enum_control_dep *)(config_p), \ | ||
227 | (cy_as_function_callback)(cb), (client)) | ||
228 | |||
229 | /* Sync Version of Set descriptor */ | ||
230 | EXTERN cy_an_return_status_t | ||
231 | cy_an_usb_set_descriptor( | ||
232 | cy_an_device_handle handle, | ||
233 | cy_an_usb_desc_type type, | ||
234 | uint8_t index, | ||
235 | void *desc_p, | ||
236 | uint16_t length | ||
237 | ); | ||
238 | #define cy_an_usb_set_descriptor(handle, type, index, desc_p, length) \ | ||
239 | cy_as_usb_set_descriptor((cy_as_device_handle)(handle), \ | ||
240 | (cy_as_usb_desc_type)(type), (index), (desc_p), (length), 0, 0) | ||
241 | |||
242 | /* Async Version of Set descriptor */ | ||
243 | extern cy_an_return_status_t | ||
244 | cy_an_usb_set_descriptor_e_x( | ||
245 | cy_an_device_handle handle, | ||
246 | cy_an_usb_desc_type type, | ||
247 | uint8_t index, | ||
248 | void *desc_p, | ||
249 | uint16_t length, | ||
250 | cy_an_function_callback cb, | ||
251 | uint32_t client | ||
252 | ); | ||
253 | #define cy_an_usb_set_descriptor_e_x\ | ||
254 | (h, type, index, desc_p, length, cb, client) \ | ||
255 | cy_as_usb_set_descriptor((cy_as_device_handle)(h), \ | ||
256 | (cy_as_usb_desc_type)(type), (index), (desc_p), (length), \ | ||
257 | (cy_as_function_callback)(cb), (client)) | ||
258 | |||
259 | /* Only version of clear descriptors */ | ||
260 | EXTERN cy_an_return_status_t | ||
261 | cy_an_usb_clear_descriptors( | ||
262 | cy_an_device_handle handle, | ||
263 | cy_an_function_callback cb, | ||
264 | uint32_t client | ||
265 | ); | ||
266 | #define cy_an_usb_clear_descriptors(h, cb, client) \ | ||
267 | cy_as_usb_clear_descriptors((cy_as_device_handle)(h), \ | ||
268 | (cy_as_function_callback)(cb), (client)) | ||
269 | |||
270 | /* Sync version of get descriptor*/ | ||
271 | EXTERN cy_an_return_status_t | ||
272 | cy_an_usb_get_descriptor( | ||
273 | cy_an_device_handle handle, | ||
274 | cy_an_usb_desc_type type, | ||
275 | uint8_t index, | ||
276 | void *desc_p, | ||
277 | uint32_t *length_p | ||
278 | ); | ||
279 | #define cy_an_usb_get_descriptor(h, type, index, desc_p, length_p) \ | ||
280 | cy_as_usb_get_descriptor_dep((cy_as_device_handle)(h), \ | ||
281 | (cy_as_usb_desc_type)(type), (index), (desc_p), (length_p)) | ||
282 | |||
283 | typedef cy_as_get_descriptor_data cy_an_get_descriptor_data; | ||
284 | |||
285 | /* Async version of get descriptor */ | ||
286 | extern cy_an_return_status_t | ||
287 | cy_an_usb_get_descriptor_e_x( | ||
288 | cy_an_device_handle handle, | ||
289 | cy_an_usb_desc_type type, | ||
290 | uint8_t index, | ||
291 | cy_an_get_descriptor_data *data, | ||
292 | cy_an_function_callback cb, | ||
293 | uint32_t client | ||
294 | ); | ||
295 | #define cy_an_usb_get_descriptor_e_x\ | ||
296 | (h, type, index, data, cb, client) \ | ||
297 | cy_as_usb_get_descriptor((cy_as_device_handle)(h), \ | ||
298 | (cy_as_usb_desc_type)(type), (index), \ | ||
299 | (cy_as_get_descriptor_data *)(data), \ | ||
300 | (cy_as_function_callback)(cb), (client)) | ||
301 | |||
302 | EXTERN cy_an_return_status_t | ||
303 | cy_an_usb_set_physical_configuration( | ||
304 | cy_an_device_handle handle, | ||
305 | uint8_t config | ||
306 | ); | ||
307 | #define cy_an_usb_set_physical_configuration(h, config) \ | ||
308 | cy_as_usb_set_physical_configuration\ | ||
309 | ((cy_as_device_handle)(h), (config)) | ||
310 | |||
311 | EXTERN cy_an_return_status_t | ||
312 | cy_an_usb_set_end_point_config( | ||
313 | cy_an_device_handle handle, | ||
314 | cy_an_end_point_number_t ep, | ||
315 | cy_an_usb_end_point_config *config_p | ||
316 | ); | ||
317 | #define cy_an_usb_set_end_point_config(h, ep, config_p) \ | ||
318 | cy_as_usb_set_end_point_config((cy_as_device_handle)(h), \ | ||
319 | (cy_as_end_point_number_t)(ep), \ | ||
320 | (cy_as_usb_end_point_config *)(config_p)) | ||
321 | |||
322 | EXTERN cy_an_return_status_t | ||
323 | cy_an_usb_get_end_point_config( | ||
324 | cy_an_device_handle handle, | ||
325 | cy_an_end_point_number_t ep, | ||
326 | cy_an_usb_end_point_config *config_p | ||
327 | ); | ||
328 | #define cy_an_usb_get_end_point_config(h, ep, config_p) \ | ||
329 | cy_as_usb_get_end_point_config((cy_as_device_handle)(h), \ | ||
330 | (cy_as_end_point_number_t)(ep), \ | ||
331 | (cy_as_usb_end_point_config *)(config_p)) | ||
332 | |||
333 | /* Sync version of commit */ | ||
334 | EXTERN cy_an_return_status_t | ||
335 | cy_an_usb_commit_config( | ||
336 | cy_an_device_handle handle | ||
337 | ); | ||
338 | #define cy_an_usb_commit_config(handle) \ | ||
339 | cy_as_usb_commit_config((cy_as_device_handle)(handle), 0, 0) | ||
340 | |||
341 | /* Async version of commit */ | ||
342 | extern cy_an_return_status_t | ||
343 | cy_an_usb_commit_config_e_x( | ||
344 | cy_an_device_handle handle, | ||
345 | cy_an_function_callback cb, | ||
346 | uint32_t client | ||
347 | ); | ||
348 | #define cy_an_usb_commit_config_e_x(h, cb, client) \ | ||
349 | cy_as_usb_commit_config((cy_as_device_handle)(h), \ | ||
350 | (cy_as_function_callback)(cb), (client)) | ||
351 | |||
352 | EXTERN cy_an_return_status_t | ||
353 | cy_an_usb_read_data( | ||
354 | cy_an_device_handle handle, | ||
355 | cy_an_end_point_number_t ep, | ||
356 | cy_bool pktread, | ||
357 | uint32_t dsize, | ||
358 | uint32_t *dataread, | ||
359 | void *data | ||
360 | ); | ||
361 | #define cy_an_usb_read_data(h, ep, pkt, dsize, dataread, data_p) \ | ||
362 | cy_as_usb_read_data((cy_as_device_handle)(h), \ | ||
363 | (cy_as_end_point_number_t)(ep), (pkt), (dsize), \ | ||
364 | (dataread), (data_p)) | ||
365 | |||
366 | EXTERN cy_an_return_status_t | ||
367 | cy_an_usb_read_data_async( | ||
368 | cy_an_device_handle handle, | ||
369 | cy_an_end_point_number_t ep, | ||
370 | cy_bool pktread, | ||
371 | uint32_t dsize, | ||
372 | void *data, | ||
373 | cy_an_usb_io_callback callback | ||
374 | ); | ||
375 | #define cy_an_usb_read_data_async(h, ep, pkt, dsize, data_p, cb) \ | ||
376 | cy_as_usb_read_data_async((cy_as_device_handle)(h), \ | ||
377 | (cy_as_end_point_number_t)(ep), (pkt), (dsize), (data_p), \ | ||
378 | (cy_as_usb_io_callback)(cb)) | ||
379 | |||
380 | EXTERN cy_an_return_status_t | ||
381 | cy_an_usb_write_data( | ||
382 | cy_an_device_handle handle, | ||
383 | cy_an_end_point_number_t ep, | ||
384 | uint32_t dsize, | ||
385 | void *data | ||
386 | ); | ||
387 | #define cy_an_usb_write_data(h, ep, dsize, data_p) \ | ||
388 | cy_as_usb_write_data((cy_as_device_handle)(h), \ | ||
389 | (cy_as_end_point_number_t)(ep), (dsize), (data_p)) | ||
390 | |||
391 | EXTERN cy_an_return_status_t | ||
392 | cy_an_usb_write_data_async( | ||
393 | cy_an_device_handle handle, | ||
394 | cy_an_end_point_number_t ep, | ||
395 | uint32_t dsize, | ||
396 | void *data, | ||
397 | cy_bool spacket, | ||
398 | cy_an_usb_io_callback callback | ||
399 | ); | ||
400 | #define cy_an_usb_write_data_async(h, ep, dsize, data_p, spacket, cb) \ | ||
401 | cy_as_usb_write_data_async((cy_as_device_handle)(h), \ | ||
402 | (cy_as_end_point_number_t)(ep), (dsize), (data_p), (spacket), \ | ||
403 | (cy_as_usb_io_callback)(cb)) | ||
404 | |||
405 | EXTERN cy_an_return_status_t | ||
406 | cy_an_usb_cancel_async( | ||
407 | cy_an_device_handle handle, | ||
408 | cy_an_end_point_number_t ep | ||
409 | ); | ||
410 | #define cy_an_usb_cancel_async(h, ep) \ | ||
411 | cy_as_usb_cancel_async((cy_as_device_handle)(h), \ | ||
412 | (cy_as_end_point_number_t)(ep)) | ||
413 | |||
414 | /* Sync version of set stall */ | ||
415 | EXTERN cy_an_return_status_t | ||
416 | cy_an_usb_set_stall( | ||
417 | cy_an_device_handle handle, | ||
418 | cy_an_end_point_number_t ep, | ||
419 | cy_an_usb_function_callback cb, | ||
420 | uint32_t client | ||
421 | ); | ||
422 | #define cy_an_usb_set_stall(h, ep, cb, client) \ | ||
423 | cy_as_usb_set_stall_dep((cy_as_device_handle)(h), \ | ||
424 | (cy_as_end_point_number_t)(ep), \ | ||
425 | (cy_as_usb_function_callback)(cb), (client)) | ||
426 | |||
427 | /* Async version of set stall */ | ||
428 | extern cy_an_return_status_t | ||
429 | cy_an_usb_set_stall_e_x( | ||
430 | cy_an_device_handle handle, | ||
431 | cy_an_end_point_number_t ep, | ||
432 | cy_an_function_callback cb, | ||
433 | uint32_t client | ||
434 | ); | ||
435 | #define cy_an_usb_set_stall_e_x(h, ep, cb, client) \ | ||
436 | cy_as_usb_set_stall((cy_as_device_handle)(h), \ | ||
437 | (cy_as_end_point_number_t)(ep), \ | ||
438 | (cy_as_function_callback)(cb), (client)) | ||
439 | |||
440 | /*Sync version of clear stall */ | ||
441 | EXTERN cy_an_return_status_t | ||
442 | cy_an_usb_clear_stall( | ||
443 | cy_an_device_handle handle, | ||
444 | cy_an_end_point_number_t ep, | ||
445 | cy_an_usb_function_callback cb, | ||
446 | uint32_t client | ||
447 | ); | ||
448 | #define cy_an_usb_clear_stall(h, ep, cb, client) \ | ||
449 | cy_as_usb_clear_stall_dep((cy_as_device_handle)(h), \ | ||
450 | (cy_as_end_point_number_t)(ep), \ | ||
451 | (cy_as_usb_function_callback)(cb), (client)) | ||
452 | |||
453 | /*Sync version of clear stall */ | ||
454 | extern cy_an_return_status_t | ||
455 | cy_an_usb_clear_stall_e_x( | ||
456 | cy_an_device_handle handle, | ||
457 | cy_an_end_point_number_t ep, | ||
458 | cy_an_function_callback cb, | ||
459 | uint32_t client | ||
460 | ); | ||
461 | #define cy_an_usb_clear_stall_e_x(h, ep, cb, client) \ | ||
462 | cy_as_usb_clear_stall((cy_as_device_handle)(h), \ | ||
463 | (cy_as_end_point_number_t)(ep), \ | ||
464 | (cy_as_function_callback)(cb), (client)) | ||
465 | |||
466 | /* Sync get stall */ | ||
467 | EXTERN cy_an_return_status_t | ||
468 | cy_an_usb_get_stall( | ||
469 | cy_an_device_handle handle, | ||
470 | cy_an_end_point_number_t ep, | ||
471 | cy_bool *stall_p | ||
472 | ); | ||
473 | #define cy_an_usb_get_stall(handle, ep, stall_p) \ | ||
474 | cy_as_usb_get_stall((cy_as_device_handle)(handle), \ | ||
475 | (cy_as_end_point_number_t)(ep), (stall_p), 0, 0) | ||
476 | |||
477 | /* Async get stall */ | ||
478 | extern cy_an_return_status_t | ||
479 | cy_an_usb_get_stall_e_x( | ||
480 | cy_an_device_handle handle, | ||
481 | cy_an_end_point_number_t ep, | ||
482 | cy_bool *stall_p, | ||
483 | cy_an_function_callback cb, | ||
484 | uint32_t client | ||
485 | ); | ||
486 | #define cy_an_usb_get_stall_e_x(h, ep, stall_p, cb, client) \ | ||
487 | cy_as_usb_get_stall((cy_as_device_handle)(h), \ | ||
488 | (cy_as_end_point_number_t)(ep), (stall_p), \ | ||
489 | (cy_as_function_callback)(cb), (client)) | ||
490 | |||
491 | /* Sync version of Set Nak */ | ||
492 | EXTERN cy_an_return_status_t | ||
493 | cy_an_usb_set_nak( | ||
494 | cy_an_device_handle handle, | ||
495 | cy_an_end_point_number_t ep, | ||
496 | cy_an_usb_function_callback cb, | ||
497 | uint32_t client | ||
498 | ); | ||
499 | |||
500 | #define cy_an_usb_set_nak(h, ep, cb, client) \ | ||
501 | cy_as_usb_set_nak_dep((cy_as_device_handle)(h), \ | ||
502 | (cy_as_end_point_number_t)(ep), \ | ||
503 | (cy_as_usb_function_callback)(cb), (client)) | ||
504 | |||
505 | /* Async version of Set Nak */ | ||
506 | extern cy_an_return_status_t | ||
507 | cy_an_usb_set_nak_e_x( | ||
508 | cy_an_device_handle handle, | ||
509 | cy_an_end_point_number_t ep, | ||
510 | cy_an_function_callback cb, | ||
511 | uint32_t client | ||
512 | ); | ||
513 | #define cy_an_usb_set_nak_e_x(h, ep, cb, client) \ | ||
514 | cy_as_usb_set_nak((cy_as_device_handle)(h), \ | ||
515 | (cy_as_end_point_number_t)(ep), \ | ||
516 | (cy_as_function_callback)(cb), (client)) | ||
517 | |||
518 | /* Sync version of clear nak */ | ||
519 | EXTERN cy_an_return_status_t | ||
520 | cy_an_usb_clear_nak( | ||
521 | cy_an_device_handle handle, | ||
522 | cy_an_end_point_number_t ep, | ||
523 | cy_an_usb_function_callback cb, | ||
524 | uint32_t client | ||
525 | ); | ||
526 | #define cy_an_usb_clear_nak(h, ep, cb, client) \ | ||
527 | cy_as_usb_clear_nak_dep((cy_as_device_handle)(h), \ | ||
528 | (cy_as_end_point_number_t)(ep), \ | ||
529 | (cy_as_usb_function_callback)(cb), (client)) | ||
530 | |||
531 | /* Sync version of clear nak */ | ||
532 | extern cy_an_return_status_t | ||
533 | cy_an_usb_clear_nak_e_x( | ||
534 | cy_an_device_handle handle, | ||
535 | cy_an_end_point_number_t ep, | ||
536 | cy_an_function_callback cb, | ||
537 | uint32_t client | ||
538 | ); | ||
539 | #define cy_an_usb_clear_nak_e_x(h, ep, cb, client) \ | ||
540 | cy_as_usb_clear_nak((cy_as_device_handle)(h), \ | ||
541 | (cy_as_end_point_number_t)(ep), \ | ||
542 | (cy_as_function_callback)(cb), (client)) | ||
543 | |||
544 | /* Sync Get NAK */ | ||
545 | EXTERN cy_an_return_status_t | ||
546 | cy_an_usb_get_nak( | ||
547 | cy_an_device_handle handle, | ||
548 | cy_an_end_point_number_t ep, | ||
549 | cy_bool *nak_p | ||
550 | ); | ||
551 | #define cy_an_usb_get_nak(handle, ep, nak_p) \ | ||
552 | cy_as_usb_get_nak((cy_as_device_handle)(handle), \ | ||
553 | (cy_as_end_point_number_t)(ep), (nak_p), 0, 0) | ||
554 | |||
555 | /* Async Get NAK */ | ||
556 | EXTERN cy_an_return_status_t | ||
557 | cy_an_usb_get_nak_e_x( | ||
558 | cy_an_device_handle handle, | ||
559 | cy_an_end_point_number_t ep, | ||
560 | cy_bool *nak_p, | ||
561 | cy_an_function_callback cb, | ||
562 | uint32_t client | ||
563 | ); | ||
564 | #define cy_an_usb_get_nak_e_x(h, ep, nak_p, cb, client) \ | ||
565 | cy_as_usb_get_nak((cy_as_device_handle)(h), \ | ||
566 | (cy_as_end_point_number_t)(ep), (nak_p), \ | ||
567 | (cy_as_function_callback)(cb), (client)) | ||
568 | |||
569 | /* Sync remote wakup */ | ||
570 | EXTERN cy_an_return_status_t | ||
571 | cy_an_usb_signal_remote_wakeup( | ||
572 | cy_an_device_handle handle | ||
573 | ); | ||
574 | #define cy_an_usb_signal_remote_wakeup(handle) \ | ||
575 | cy_as_usb_signal_remote_wakeup((cy_as_device_handle)(handle), 0, 0) | ||
576 | |||
577 | /* Async remote wakup */ | ||
578 | EXTERN cy_an_return_status_t | ||
579 | cy_an_usb_signal_remote_wakeup_e_x( | ||
580 | cy_an_device_handle handle, | ||
581 | cy_an_function_callback cb, | ||
582 | uint32_t client | ||
583 | ); | ||
584 | #define cy_an_usb_signal_remote_wakeup_e_x(h, cb, client) \ | ||
585 | cy_as_usb_signal_remote_wakeup((cy_as_device_handle)(h), \ | ||
586 | (cy_as_function_callback)(cb), (client)) | ||
587 | |||
588 | /* Only version of SetMSReportThreshold */ | ||
589 | EXTERN cy_an_return_status_t | ||
590 | cy_an_usb_set_m_s_report_threshold( | ||
591 | cy_an_device_handle handle, | ||
592 | uint32_t wr_sectors, | ||
593 | uint32_t rd_sectors, | ||
594 | cy_an_function_callback cb, | ||
595 | uint32_t client | ||
596 | ); | ||
597 | #define cy_an_usb_set_m_s_report_threshold\ | ||
598 | (h, wr_cnt, rd_cnt, cb, client) \ | ||
599 | cy_as_usb_set_m_s_report_threshold((cy_as_device_handle)(h), \ | ||
600 | wr_cnt, rd_cnt, (cy_as_function_callback)(cb), (client)) | ||
601 | |||
602 | /* Select storage partitions to be enumerated. */ | ||
603 | EXTERN cy_an_return_status_t | ||
604 | cy_an_usb_select_m_s_partitions( | ||
605 | cy_an_device_handle handle, | ||
606 | cy_an_media_type media, | ||
607 | uint32_t device, | ||
608 | cy_an_usb_m_s_type_t type, | ||
609 | cy_an_function_callback cb, | ||
610 | uint32_t client | ||
611 | ); | ||
612 | #define cy_an_usb_select_m_s_partitions(h, media, dev, type, cb, client) \ | ||
613 | cy_as_usb_select_m_s_partitions_dep((cy_as_device_handle)(h), \ | ||
614 | (cy_as_media_type)(media), (dev), \ | ||
615 | (cy_as_usb_m_s_type_t)(type), (cy_as_function_callback)(cb), (client)) | ||
616 | |||
617 | #include "cyas_cplus_end.h" | ||
618 | #endif /*__doxygen__*/ | ||
619 | #endif /*_INCLUDED_CYANUSB_H_*/ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_end.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_end.h deleted file mode 100644 index ece44ca34f3b..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_end.h +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | /* | ||
2 | * This file is included at the end of other include files. | ||
3 | * It basically turns off the C++ specific code words that | ||
4 | * insure this code is seen as C code even within | ||
5 | * a C++ compiler. | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #ifdef __cplusplus | ||
10 | } | ||
11 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_start.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_start.h deleted file mode 100644 index b879cefa9d6b..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyas_cplus_start.h +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | /* | ||
2 | * This file is included after all other headers files, but before any other | ||
3 | * definitions in the file. It basically insures that the definitions within | ||
4 | * the file are seen as C defintions even when compiled by a C++ compiler. | ||
5 | */ | ||
6 | |||
7 | #ifdef __cplusplus | ||
8 | |||
9 | extern "C" { | ||
10 | |||
11 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyascast.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyascast.h deleted file mode 100644 index 5f8c852fbb41..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyascast.h +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyascast.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASCAST_H_ | ||
23 | #define _INCLUDED_CYASCAST_H_ | ||
24 | |||
25 | #ifndef __doxygen__ | ||
26 | |||
27 | #ifdef _DEBUG | ||
28 | #define cy_cast_int2U_int16(v) \ | ||
29 | (cy_as_hal_assert(v < 65536), (uint16_t)(v)) | ||
30 | #else /* _DEBUG */ | ||
31 | #define cy_cast_int2U_int16(v) ((uint16_t)(v)) | ||
32 | #endif /* _DEBUG */ | ||
33 | |||
34 | #endif /* __doxygen__ */ | ||
35 | #endif /* _INCLUDED_CYASCAST_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdevice.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdevice.h deleted file mode 100644 index 6452a9070091..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdevice.h +++ /dev/null | |||
@@ -1,1057 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasdevice.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ##Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef __INCLUDED_CYASDEVICE_H__ | ||
23 | #define __INCLUDED_CYASDEVICE_H__ | ||
24 | |||
25 | #include "cyashal.h" | ||
26 | #include "cyasprotocol.h" | ||
27 | #include "cyasusb.h" | ||
28 | #include "cyasstorage.h" | ||
29 | #include "cyasmtp.h" | ||
30 | #include "cyas_cplus_start.h" | ||
31 | |||
32 | /*********************************** | ||
33 | * West Bridge Constants | ||
34 | ***********************************/ | ||
35 | |||
36 | /* The endpoints used by West Bridge for the P port to S port path */ | ||
37 | #define CY_AS_P2S_WRITE_ENDPOINT (0x04) | ||
38 | #define CY_AS_P2S_READ_ENDPOINT (0x08) | ||
39 | |||
40 | /* The endpoint to use for firmware download */ | ||
41 | #define CY_AS_FIRMWARE_ENDPOINT (0x02) | ||
42 | |||
43 | /* The maximum size of the firmware image West Bridge can accept */ | ||
44 | #define CY_AS_MAXIMUM_FIRMWARE_SIZE (24 * 1024) | ||
45 | |||
46 | /* The maximum size of a write for EP0 and EP1 */ | ||
47 | #define CY_AS_EP0_MAX_WRITE_SIZE (128) | ||
48 | #define CY_AS_EP1_MAX_WRITE_SIZE (64) | ||
49 | |||
50 | /* The bitfields for the device state value */ | ||
51 | |||
52 | /* The device is in StandBy mode */ | ||
53 | #define CY_AS_DEVICE_STATE_PIN_STANDBY (0x00000001) | ||
54 | /* The device has been configured */ | ||
55 | #define CY_AS_DEVICE_STATE_CONFIGURED (0x00000002) | ||
56 | /* The firmware has been loaded into the device */ | ||
57 | #define CY_AS_DEVICE_STATE_FIRMWARE_LOADED (0x00000004) | ||
58 | /* The interrupt module has been initialized */ | ||
59 | #define CY_AS_DEVICE_STATE_LOWLEVEL_MODULE (0x00000008) | ||
60 | /* The DMA module has been initialized */ | ||
61 | #define CY_AS_DEVICE_STATE_DMA_MODULE (0x00000010) | ||
62 | /* The interrupt module has been initialized */ | ||
63 | #define CY_AS_DEVICE_STATE_INTR_MODULE (0x00000020) | ||
64 | /* The storage module has been initialized */ | ||
65 | #define CY_AS_DEVICE_STATE_STORAGE_MODULE (0x00000040) | ||
66 | /* The USB module has been initialized */ | ||
67 | #define CY_AS_DEVICE_STATE_USB_MODULE (0x00000080) | ||
68 | /* If set, the API wants SCSI messages */ | ||
69 | #define CY_AS_DEVICE_STATE_STORAGE_SCSIMSG (0x00000100) | ||
70 | /* If set, an ASYNC storage operation is pending */ | ||
71 | #define CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING (0x00000200) | ||
72 | /* If set, the USB port is connected */ | ||
73 | #define CY_AS_DEVICE_STATE_USB_CONNECTED (0x00000400) | ||
74 | /* If set and USB is connected, it is high speed */ | ||
75 | #define CY_AS_DEVICE_STATE_USB_HIGHSPEED (0x00000800) | ||
76 | /* If set, we are in a callback */ | ||
77 | #define CY_AS_DEVICE_STATE_IN_CALLBACK (0x00001000) | ||
78 | /* If set, we are processing a setup packet */ | ||
79 | #define CY_AS_DEVICE_STATE_IN_SETUP_PACKET (0x00004000) | ||
80 | /* The device was placed in standby via register */ | ||
81 | #define CY_AS_DEVICE_STATE_REGISTER_STANDBY (0x00008000) | ||
82 | /* If set, the device is using a crystal */ | ||
83 | #define CY_AS_DEVICE_STATE_CRYSTAL (0x00010000) | ||
84 | /* If set, wakeup has been called */ | ||
85 | #define CY_AS_DEVICE_STATE_WAKING (0x00020000) | ||
86 | /* If set, EP0 has been stalled. */ | ||
87 | #define CY_AS_DEVICE_STATE_EP0_STALLED (0x00040000) | ||
88 | /* If set, device is in suspend mode. */ | ||
89 | #define CY_AS_DEVICE_STATE_SUSPEND (0x00080000) | ||
90 | /* If set, device is a reset is pending. */ | ||
91 | #define CY_AS_DEVICE_STATE_RESETP (0x00100000) | ||
92 | /* If set, device is a standby is pending. */ | ||
93 | #define CY_AS_DEVICE_STATE_STANDP (0x00200000) | ||
94 | /* If set, device has a storage start or stop pending. */ | ||
95 | #define CY_AS_DEVICE_STATE_SSSP (0x00400000) | ||
96 | /* If set, device has a usb start or stop pending. */ | ||
97 | #define CY_AS_DEVICE_STATE_USSP (0x00800000) | ||
98 | /* If set, device has a mtp start or stop pending. */ | ||
99 | #define CY_AS_DEVICE_STATE_MSSP (0x01000000) | ||
100 | /* If set, P2S DMA transfer can be started. */ | ||
101 | #define CY_AS_DEVICE_STATE_P2SDMA_START (0x02000000) | ||
102 | |||
103 | /* The bitfields for the endpoint state value */ | ||
104 | /* DMA requests are accepted into the queue */ | ||
105 | #define CY_AS_DMA_ENDPOINT_STATE_ENABLED (0x0001) | ||
106 | /* The endpoint has a sleeping client, waiting on a queue drain */ | ||
107 | #define CY_AS_DMA_ENDPOINT_STATE_SLEEPING (0x0002) | ||
108 | /* The DMA backend to hardware is running */ | ||
109 | #define CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING (0x0004) | ||
110 | /* There is an outstanding DMA entry deployed to the HAL */ | ||
111 | #define CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT (0x0008) | ||
112 | /* 0 = OUT (West Bridge -> P Port), 1 = IN (P Port -> West Bridge) */ | ||
113 | #define CY_AS_DMA_ENDPOINT_STATE_DIRECTION (0x0010) | ||
114 | |||
115 | /* The state values for the request list */ | ||
116 | /* Mask for getting the state information */ | ||
117 | #define CY_AS_REQUEST_LIST_STATE_MASK (0x0f) | ||
118 | /* The request is queued, nothing further */ | ||
119 | #define CY_AS_REQUEST_LIST_STATE_QUEUED (0x00) | ||
120 | /* The request is sent, waiting for response */ | ||
121 | #define CY_AS_REQUEST_LIST_STATE_WAITING (0x01) | ||
122 | /* The response has been received, processing response */ | ||
123 | #define CY_AS_REQUEST_LIST_STATE_RECEIVED (0x02) | ||
124 | /* The request/response is being canceled */ | ||
125 | #define CY_AS_REQUEST_LIST_STATE_CANCELING (0x03) | ||
126 | /* The request is synchronous */ | ||
127 | #define CY_AS_REQUEST_LIST_STATE_SYNC (0x80) | ||
128 | |||
129 | /* The flag values for a LL RequestResponse */ | ||
130 | /* This request requires an ACK to be sent after it is completed */ | ||
131 | #define CY_AS_REQUEST_RESPONSE_DELAY_ACK (0x01) | ||
132 | /* This request originated from a version V1.1 function call */ | ||
133 | #define CY_AS_REQUEST_RESPONSE_EX (0x02) | ||
134 | /* This request originated from a version V1.2 function call */ | ||
135 | #define CY_AS_REQUEST_RESPONSE_MS (0x04) | ||
136 | |||
137 | |||
138 | #define CY_AS_DEVICE_HANDLE_SIGNATURE (0x01211219) | ||
139 | |||
140 | /* | ||
141 | * This macro returns the endpoint pointer given the | ||
142 | * device pointer and an endpoint number | ||
143 | */ | ||
144 | #define CY_AS_NUM_EP(dev_p, num) ((dev_p)->endp[(num)]) | ||
145 | |||
146 | /**************************************** | ||
147 | * West Bridge Data Structures | ||
148 | ****************************************/ | ||
149 | |||
150 | typedef struct cy_as_device cy_as_device; | ||
151 | |||
152 | /* Summary | ||
153 | This type defines a callback function that will be called | ||
154 | on completion of a DMA operation. | ||
155 | |||
156 | Description | ||
157 | This function definition is for a function that is called when | ||
158 | the DMA operation is complete. This function is called with the | ||
159 | endpoint number, operation type, buffer pointer and size. | ||
160 | |||
161 | See Also | ||
162 | * CyAsDmaOper | ||
163 | * CyAsDmaQueueWrite | ||
164 | */ | ||
165 | typedef void (*cy_as_dma_callback)( | ||
166 | /* The device that completed DMA */ | ||
167 | cy_as_device *dev_p, | ||
168 | /* The endpoint that completed DMA */ | ||
169 | cy_as_end_point_number_t ep, | ||
170 | /* The pointer to the buffer that completed DMA */ | ||
171 | void *mem_p, | ||
172 | /* The amount of data transferred */ | ||
173 | uint32_t size, | ||
174 | /* The error code for this DMA xfer */ | ||
175 | cy_as_return_status_t error | ||
176 | ); | ||
177 | |||
178 | /* Summary | ||
179 | This structure defines a DMA request that is queued | ||
180 | |||
181 | Description | ||
182 | This structure contains the information about a DMA | ||
183 | request that is queued and is to be sent when possible. | ||
184 | */ | ||
185 | typedef struct cy_as_dma_queue_entry { | ||
186 | /* Pointer to memory buffer for this request */ | ||
187 | void *buf_p; | ||
188 | /* Size of the memory buffer for DMA operation */ | ||
189 | uint32_t size; | ||
190 | /* Offset into memory buffer for next DMA operation */ | ||
191 | uint32_t offset; | ||
192 | /* If TRUE and IN request */ | ||
193 | cy_bool packet; | ||
194 | /* If TRUE, this is a read request */ | ||
195 | cy_bool readreq; | ||
196 | /* Callback function for when DMA is complete */ | ||
197 | cy_as_dma_callback cb; | ||
198 | /* Pointer to next entry in queue */ | ||
199 | struct cy_as_dma_queue_entry *next_p; | ||
200 | } cy_as_dma_queue_entry; | ||
201 | |||
202 | /* Summary | ||
203 | This structure defines the endpoint data for a given | ||
204 | |||
205 | Description | ||
206 | This structure defines all of the information required | ||
207 | to manage DMA for a given endpoint. | ||
208 | */ | ||
209 | typedef struct cy_as_dma_end_point { | ||
210 | /* The endpoint number */ | ||
211 | cy_as_end_point_number_t ep; | ||
212 | /* The state of this endpoint */ | ||
213 | uint8_t state; | ||
214 | /* The maximum amount of data accepted in a packet by the hw */ | ||
215 | uint16_t maxhwdata; | ||
216 | /* The maximum amount of data accepted by the HAL layer */ | ||
217 | uint32_t maxhaldata; | ||
218 | /* The queue for DMA operations */ | ||
219 | cy_as_dma_queue_entry *queue_p; | ||
220 | /* The last entry in the DMA queue */ | ||
221 | cy_as_dma_queue_entry *last_p; | ||
222 | /* This sleep channel is used to wait while the DMA queue | ||
223 | * drains for a given endpoint */ | ||
224 | cy_as_hal_sleep_channel channel; | ||
225 | } cy_as_dma_end_point; | ||
226 | |||
227 | #define cy_as_end_point_number_is_usb(n) \ | ||
228 | ((n) != 2 && (n) != 4 && (n) != 6 && (n) != 8) | ||
229 | #define cy_as_end_point_number_is_storage(n) \ | ||
230 | ((n) == 2 || (n) == 4 || (n) == 6 || (n) == 8) | ||
231 | |||
232 | #define cy_as_dma_end_point_is_enabled(ep) \ | ||
233 | ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_ENABLED) | ||
234 | #define cy_as_dma_end_point_enable(ep) \ | ||
235 | ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_ENABLED) | ||
236 | #define cy_as_dma_end_point_disable(ep) \ | ||
237 | ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_ENABLED) | ||
238 | |||
239 | #define cy_as_dma_end_point_is_sleeping(ep) \ | ||
240 | ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_SLEEPING) | ||
241 | #define cy_as_dma_end_point_set_sleep_state(ep) \ | ||
242 | ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_SLEEPING) | ||
243 | #define cy_as_dma_end_point_set_wake_state(ep) \ | ||
244 | ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_SLEEPING) | ||
245 | |||
246 | #define cy_as_dma_end_point_is_running(ep) \ | ||
247 | ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING) | ||
248 | #define cy_as_dma_end_point_set_running(ep) \ | ||
249 | ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING) | ||
250 | #define cy_as_dma_end_point_set_stopped(ep) \ | ||
251 | ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING) | ||
252 | |||
253 | #define cy_as_dma_end_point_in_transit(ep) \ | ||
254 | ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT) | ||
255 | #define cy_as_dma_end_point_set_in_transit(ep) \ | ||
256 | ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT) | ||
257 | #define cy_as_dma_end_point_clear_in_transit(ep) \ | ||
258 | ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT) | ||
259 | |||
260 | #define cy_as_dma_end_point_is_direction_in(ep) \ | ||
261 | (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == \ | ||
262 | CY_AS_DMA_ENDPOINT_STATE_DIRECTION) | ||
263 | #define cy_as_dma_end_point_is_direction_out(ep) \ | ||
264 | (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == 0) | ||
265 | #define cy_as_dma_end_point_set_direction_in(ep) \ | ||
266 | ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DIRECTION) | ||
267 | #define cy_as_dma_end_point_set_direction_out(ep) \ | ||
268 | ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DIRECTION) | ||
269 | |||
270 | #define cy_as_dma_end_point_is_usb(p) \ | ||
271 | cy_as_end_point_number_is_usb((p)->ep) | ||
272 | #define cy_as_dma_end_point_is_storage(p) \ | ||
273 | cy_as_end_point_number_is_storage((p)->ep) | ||
274 | |||
275 | typedef struct cy_as_ll_request_response { | ||
276 | /* The mbox[0] contents - see low level comm section of API doc */ | ||
277 | uint16_t box0; | ||
278 | /* The amount of data stored in this request/response in bytes */ | ||
279 | uint16_t stored; | ||
280 | /* Length of this request in words */ | ||
281 | uint16_t length; | ||
282 | /* Additional status information about the request */ | ||
283 | uint16_t flags; | ||
284 | /* Note: This is over indexed and contains the request/response data */ | ||
285 | uint16_t data[1]; | ||
286 | } cy_as_ll_request_response; | ||
287 | |||
288 | /* | ||
289 | * The callback function for responses | ||
290 | */ | ||
291 | typedef void (*cy_as_response_callback)( | ||
292 | /* The device that had the response */ | ||
293 | cy_as_device *dev_p, | ||
294 | /* The context receiving a response */ | ||
295 | uint8_t context, | ||
296 | /* The request data */ | ||
297 | cy_as_ll_request_response *rqt, | ||
298 | /* The response data */ | ||
299 | cy_as_ll_request_response *resp, | ||
300 | /* The status of the request */ | ||
301 | cy_as_return_status_t status | ||
302 | ); | ||
303 | |||
304 | typedef struct cy_as_ll_request_list_node { | ||
305 | /* The request to send */ | ||
306 | cy_as_ll_request_response *rqt; | ||
307 | /* The associated response for the request */ | ||
308 | cy_as_ll_request_response *resp; | ||
309 | /* Length of the response */ | ||
310 | uint16_t length; | ||
311 | /* The callback to call when done */ | ||
312 | cy_as_response_callback callback; | ||
313 | /* The state of the request */ | ||
314 | uint8_t state; | ||
315 | /* The next request in the list */ | ||
316 | struct cy_as_ll_request_list_node *next; | ||
317 | } cy_as_ll_request_list_node; | ||
318 | |||
319 | #define cy_as_request_get_node_state(node_p) \ | ||
320 | ((node_p)->state & CY_AS_REQUEST_LIST_STATE_MASK) | ||
321 | #define cy_as_request_set_node_state(node_p, st) \ | ||
322 | ((node_p)->state = \ | ||
323 | ((node_p)->state & ~CY_AS_REQUEST_LIST_STATE_MASK) | (st)) | ||
324 | |||
325 | #define cy_as_request_node_is_sync(node_p) \ | ||
326 | ((node_p)->state & CY_AS_REQUEST_LIST_STATE_SYNC) | ||
327 | #define cy_as_request_node_set_sync(node_p) \ | ||
328 | ((node_p)->state |= CY_AS_REQUEST_LIST_STATE_SYNC) | ||
329 | #define cy_as_request_node_clear_sync(node_p) \ | ||
330 | ((node_p)->state &= ~CY_AS_REQUEST_LIST_STATE_SYNC) | ||
331 | |||
332 | #ifndef __doxygen__ | ||
333 | typedef enum cy_as_c_b_node_type { | ||
334 | CYAS_INVALID, | ||
335 | CYAS_USB_FUNC_CB, | ||
336 | CYAS_USB_IO_CB, | ||
337 | CYAS_STORAGE_IO_CB, | ||
338 | CYAS_FUNC_CB | ||
339 | } cy_as_c_b_node_type; | ||
340 | |||
341 | typedef struct cy_as_func_c_b_node { | ||
342 | cy_as_c_b_node_type node_type; | ||
343 | cy_as_function_callback cb_p; | ||
344 | uint32_t client_data; | ||
345 | cy_as_funct_c_b_type data_type; | ||
346 | void *data; | ||
347 | struct cy_as_func_c_b_node *next_p; | ||
348 | } cy_as_func_c_b_node; | ||
349 | |||
350 | extern cy_as_func_c_b_node* | ||
351 | cy_as_create_func_c_b_node_data(cy_as_function_callback | ||
352 | cb, uint32_t client, cy_as_funct_c_b_type type, void *data); | ||
353 | |||
354 | extern cy_as_func_c_b_node* | ||
355 | cy_as_create_func_c_b_node(cy_as_function_callback cb, | ||
356 | uint32_t client); | ||
357 | |||
358 | extern void | ||
359 | cy_as_destroy_func_c_b_node(cy_as_func_c_b_node *node); | ||
360 | |||
361 | typedef struct cy_as_mtp_func_c_b_node { | ||
362 | cy_as_c_b_node_type type; | ||
363 | cy_as_mtp_function_callback cb_p; | ||
364 | uint32_t client_data; | ||
365 | struct cy_as_mtp_func_c_b_node *next_p; | ||
366 | } cy_as_mtp_func_c_b_node; | ||
367 | |||
368 | extern cy_as_mtp_func_c_b_node* | ||
369 | cy_as_create_mtp_func_c_b_node(cy_as_mtp_function_callback cb, | ||
370 | uint32_t client); | ||
371 | |||
372 | extern void | ||
373 | cy_as_destroy_mtp_func_c_b_node(cy_as_mtp_func_c_b_node *node); | ||
374 | |||
375 | typedef struct cy_as_usb_func_c_b_node { | ||
376 | cy_as_c_b_node_type type; | ||
377 | cy_as_usb_function_callback cb_p; | ||
378 | uint32_t client_data; | ||
379 | struct cy_as_usb_func_c_b_node *next_p; | ||
380 | } cy_as_usb_func_c_b_node; | ||
381 | |||
382 | extern cy_as_usb_func_c_b_node* | ||
383 | cy_as_create_usb_func_c_b_node(cy_as_usb_function_callback cb, | ||
384 | uint32_t client); | ||
385 | |||
386 | extern void | ||
387 | cy_as_destroy_usb_func_c_b_node(cy_as_usb_func_c_b_node *node); | ||
388 | |||
389 | typedef struct cy_as_usb_io_c_b_node { | ||
390 | cy_as_c_b_node_type type; | ||
391 | cy_as_usb_io_callback cb_p; | ||
392 | struct cy_as_usb_io_c_b_node *next_p; | ||
393 | } cy_as_usb_io_c_b_node; | ||
394 | |||
395 | extern cy_as_usb_io_c_b_node* | ||
396 | cy_as_create_usb_io_c_b_node(cy_as_usb_io_callback cb); | ||
397 | |||
398 | extern void | ||
399 | cy_as_destroy_usb_io_c_b_node(cy_as_usb_io_c_b_node *node); | ||
400 | |||
401 | typedef struct cy_as_storage_io_c_b_node { | ||
402 | cy_as_c_b_node_type type; | ||
403 | cy_as_storage_callback cb_p; | ||
404 | /* The media for the currently outstanding async storage request */ | ||
405 | cy_as_media_type media; | ||
406 | /* The device index for the currently outstanding async storage | ||
407 | * request */ | ||
408 | uint32_t device_index; | ||
409 | /* The unit index for the currently outstanding async storage | ||
410 | * request */ | ||
411 | uint32_t unit; | ||
412 | /* The block address for the currently outstanding async storage | ||
413 | * request */ | ||
414 | uint32_t block_addr; | ||
415 | /* The operation for the currently outstanding async storage | ||
416 | * request */ | ||
417 | cy_as_oper_type oper; | ||
418 | cy_as_ll_request_response *req_p; | ||
419 | cy_as_ll_request_response *reply_p; | ||
420 | struct cy_as_storage_io_c_b_node *next_p; | ||
421 | } cy_as_storage_io_c_b_node; | ||
422 | |||
423 | extern cy_as_storage_io_c_b_node* | ||
424 | cy_as_create_storage_io_c_b_node(cy_as_storage_callback cb, | ||
425 | cy_as_media_type media, uint32_t device_index, | ||
426 | uint32_t unit, uint32_t block_addr, cy_as_oper_type oper, | ||
427 | cy_as_ll_request_response *req_p, | ||
428 | cy_as_ll_request_response *reply_p); | ||
429 | |||
430 | extern void | ||
431 | cy_as_destroy_storage_io_c_b_node(cy_as_storage_io_c_b_node *node); | ||
432 | |||
433 | typedef struct cy_as_c_b_queue { | ||
434 | void *head_p; | ||
435 | void *tail_p; | ||
436 | uint32_t count; | ||
437 | cy_as_c_b_node_type type; | ||
438 | } cy_as_c_b_queue; | ||
439 | |||
440 | extern cy_as_c_b_queue * | ||
441 | cy_as_create_c_b_queue(cy_as_c_b_node_type type); | ||
442 | |||
443 | extern void | ||
444 | cy_as_destroy_c_b_queue(cy_as_c_b_queue *queue); | ||
445 | |||
446 | /* Allocates a new CyAsCBNode */ | ||
447 | extern void | ||
448 | cy_as_insert_c_b_node(cy_as_c_b_queue *queue_p, void *cbnode); | ||
449 | |||
450 | /* Removes the first CyAsCBNode from the queue and frees it */ | ||
451 | extern void | ||
452 | cy_as_remove_c_b_node(cy_as_c_b_queue *queue_p); | ||
453 | |||
454 | /* Remove the last CyAsCBNode from the queue and frees it */ | ||
455 | extern void | ||
456 | cy_as_remove_c_b_tail_node(cy_as_c_b_queue *queue_p); | ||
457 | |||
458 | /* Removes and frees all pending callbacks */ | ||
459 | extern void | ||
460 | cy_as_clear_c_b_queue(cy_as_c_b_queue *queue_p); | ||
461 | |||
462 | extern cy_as_return_status_t | ||
463 | cy_as_misc_send_request(cy_as_device *dev_p, | ||
464 | cy_as_function_callback cb, | ||
465 | uint32_t client, | ||
466 | cy_as_funct_c_b_type type, | ||
467 | void *data, | ||
468 | cy_as_c_b_queue *queue, | ||
469 | uint16_t req_type, | ||
470 | cy_as_ll_request_response *req_p, | ||
471 | cy_as_ll_request_response *reply_p, | ||
472 | cy_as_response_callback rcb); | ||
473 | |||
474 | extern void | ||
475 | cy_as_misc_cancel_ex_requests(cy_as_device *dev_p); | ||
476 | |||
477 | /* Summary | ||
478 | Free all memory allocated by and zero all | ||
479 | structures initialized by CyAsUsbStart. | ||
480 | */ | ||
481 | extern void | ||
482 | cy_as_usb_cleanup( | ||
483 | cy_as_device *dev_p); | ||
484 | |||
485 | /* Summary | ||
486 | Free all memory allocated and zero all structures initialized | ||
487 | by CyAsStorageStart. | ||
488 | */ | ||
489 | extern void | ||
490 | cy_as_storage_cleanup( | ||
491 | cy_as_device *dev_p); | ||
492 | #endif | ||
493 | |||
494 | /* Summary | ||
495 | This structure defines the data structure to support a | ||
496 | given command context | ||
497 | |||
498 | Description | ||
499 | All commands send to the West Bridge device via the mailbox | ||
500 | registers are sent via a context.Each context is independent | ||
501 | and there can be a parallel stream of requests and responses on | ||
502 | each context. This structure is used to manage a single context. | ||
503 | */ | ||
504 | typedef struct cy_as_context { | ||
505 | /* The context number for this context */ | ||
506 | uint8_t number; | ||
507 | /* This sleep channel is used to sleep while waiting on a | ||
508 | * response from the west bridge device for a request. */ | ||
509 | cy_as_hal_sleep_channel channel; | ||
510 | /* The buffer for received requests */ | ||
511 | cy_as_ll_request_response *req_p; | ||
512 | /* The length of the request being received */ | ||
513 | uint16_t request_length; | ||
514 | /* The callback for the next request received */ | ||
515 | cy_as_response_callback request_callback; | ||
516 | /* A list of low level requests to go to the firmware */ | ||
517 | cy_as_ll_request_list_node *request_queue_p; | ||
518 | /* The list node in the request queue */ | ||
519 | cy_as_ll_request_list_node *last_node_p; | ||
520 | /* Index up to which data is stored. */ | ||
521 | uint16_t queue_index; | ||
522 | /* Index to the next request in the queue. */ | ||
523 | uint16_t rqt_index; | ||
524 | /* Queue of data stored */ | ||
525 | uint16_t data_queue[128]; | ||
526 | |||
527 | } cy_as_context; | ||
528 | |||
529 | #define cy_as_context_is_waiting(ctxt) \ | ||
530 | ((ctxt)->state & CY_AS_CTXT_STATE_WAITING_RESPONSE) | ||
531 | #define cy_as_context_set_waiting(ctxt) \ | ||
532 | ((ctxt)->state |= CY_AS_CTXT_STATE_WAITING_RESPONSE) | ||
533 | #define cy_as_context_clear_waiting(ctxt) \ | ||
534 | ((ctxt)->state &= ~CY_AS_CTXT_STATE_WAITING_RESPONSE) | ||
535 | |||
536 | |||
537 | |||
538 | /* Summary | ||
539 | This data structure stores SDIO function | ||
540 | parameters for a SDIO card | ||
541 | |||
542 | Description | ||
543 | */ | ||
544 | typedef struct cy_as_sdio_device { | ||
545 | /* Keeps track of IO functions initialized*/ | ||
546 | uint8_t function_init_map; | ||
547 | uint8_t function_suspended_map; | ||
548 | /* Function 0 (Card Common) properties*/ | ||
549 | cy_as_sdio_card card; | ||
550 | /* Function 1-7 (Mapped to array element 0-6) properties.*/ | ||
551 | cy_as_sdio_func function[7]; | ||
552 | |||
553 | } cy_as_sdio_device; | ||
554 | |||
555 | /* Summary | ||
556 | Macros to access the SDIO card properties | ||
557 | */ | ||
558 | |||
559 | #define cy_as_sdio_get_function_code(handle, bus, i) \ | ||
560 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].function_code) | ||
561 | |||
562 | #define cy_as_sdio_get_function_ext_code(handle, bus, i) \ | ||
563 | (((cy_as_device *)handle)->sdiocard[bus].\ | ||
564 | function[i-1].extended_func_code) | ||
565 | |||
566 | #define cy_as_sdio_get_function_p_s_n(handle, bus, i) \ | ||
567 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].card_psn) | ||
568 | |||
569 | #define cy_as_sdio_get_function_blocksize(handle, bus, i) \ | ||
570 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].blocksize) | ||
571 | |||
572 | #define cy_as_sdio_get_function_max_blocksize(handle, bus, i) \ | ||
573 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].maxblocksize) | ||
574 | |||
575 | #define cy_as_sdio_get_function_csa_support(handle, bus, i) \ | ||
576 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].csa_bits) | ||
577 | |||
578 | #define cy_as_sdio_get_function_wakeup_support(handle, bus, i) \ | ||
579 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1]. wakeup_support) | ||
580 | |||
581 | #define cy_as_sdio_set_function_block_size(handle, bus, i, blocksize) \ | ||
582 | (((cy_as_device *)handle)->sdiocard[bus].function[i-1].blocksize = \ | ||
583 | blocksize) | ||
584 | |||
585 | #define cy_as_sdio_get_card_num_functions(handle, bus) \ | ||
586 | (((cy_as_device *)handle)->sdiocard[bus].card.num_functions) | ||
587 | |||
588 | #define cy_as_sdio_get_card_mem_present(handle, bus) \ | ||
589 | (((cy_as_device *)handle)->sdiocard[bus].card.memory_present) | ||
590 | |||
591 | #define cy_as_sdio_get_card_manf_id(handle, bus) \ | ||
592 | (((cy_as_device *)handle)->sdiocard[bus].card.manufacturer__id) | ||
593 | |||
594 | #define cy_as_sdio_get_card_manf_info(handle, bus) \ | ||
595 | (((cy_as_device *)handle)->sdiocard[bus].card.manufacturer_info) | ||
596 | |||
597 | #define cy_as_sdio_get_card_blocksize(handle, bus) \ | ||
598 | (((cy_as_device *)handle)->sdiocard[bus].card.blocksize) | ||
599 | |||
600 | #define cy_as_sdio_get_card_max_blocksize(handle, bus) \ | ||
601 | (((cy_as_device *)handle)->sdiocard[bus].card.maxblocksize) | ||
602 | |||
603 | #define cy_as_sdio_get_card_sdio_version(handle, bus) \ | ||
604 | (((cy_as_device *)handle)->sdiocard[bus].card.sdio_version) | ||
605 | |||
606 | #define cy_as_sdio_get_card_capability(handle, bus) \ | ||
607 | (((cy_as_device *)handle)->sdiocard[bus].card.card_capability) | ||
608 | |||
609 | #define cy_as_sdio_get_function_init_map(handle, bus) \ | ||
610 | (((cy_as_device *)handle)->sdiocard[bus].function_init_map) | ||
611 | |||
612 | #define cy_as_sdio_check_function_initialized(handle, bus, i) \ | ||
613 | (((cy_as_sdio_get_function_init_map(handle, bus)) & (0x01<<i)) ? 1 : 0) | ||
614 | |||
615 | #define cy_as_sdio_set_card_block_size(handle, bus, blocksize) \ | ||
616 | (((cy_as_device *)handle)->sdiocard[bus].card.blocksize = blocksize) | ||
617 | |||
618 | #define cy_as_sdio_check_support_bus_suspend(handle, bus) \ | ||
619 | ((cy_as_sdio_get_card_capability(handle, bus) & CY_SDIO_SBS) ? 1 : 0) | ||
620 | |||
621 | #define cy_as_sdio_check_function_suspended(handle, bus, i) \ | ||
622 | ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map & \ | ||
623 | (0x01<<i)) ? 1 : 0) | ||
624 | |||
625 | #define cy_as_sdio_set_function_suspended(handle, bus, i) \ | ||
626 | ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map) \ | ||
627 | |= (0x01<<i)) | ||
628 | |||
629 | #define cy_as_sdio_clear_function_suspended(handle, bus, i) \ | ||
630 | ((((cy_as_device *)handle)->sdiocard[bus].function_suspended_map) \ | ||
631 | &= (~(0x01<<i))) | ||
632 | |||
633 | /* Summary | ||
634 | This data structure represents a single device. | ||
635 | |||
636 | Description | ||
637 | */ | ||
638 | struct cy_as_device { | ||
639 | /* General stuff */ | ||
640 | /* A signature to insure we have a valid handle */ | ||
641 | uint32_t sig; | ||
642 | /* The ID of the silicon */ | ||
643 | uint16_t silicon_id; | ||
644 | /* Pointer to the next device */ | ||
645 | struct cy_as_device *next_p; | ||
646 | /* This is the client specific tag for this device */ | ||
647 | cy_as_hal_device_tag tag; | ||
648 | /* This contains various state information about the device */ | ||
649 | uint32_t state; | ||
650 | /* Flag indicating whether INT# pin is used for DRQ */ | ||
651 | cy_bool use_int_drq; | ||
652 | |||
653 | /* DMA related */ | ||
654 | /* The endpoint pointers associated with this device */ | ||
655 | cy_as_dma_end_point *endp[16]; | ||
656 | /* List of queue entries that can be used for xfers */ | ||
657 | cy_as_dma_queue_entry *dma_freelist_p; | ||
658 | |||
659 | /* Low level comm related */ | ||
660 | /* The contexts available in this device */ | ||
661 | cy_as_context *context[CY_RQT_CONTEXT_COUNT]; | ||
662 | /* The low level error returned from sending an async request */ | ||
663 | cy_as_return_status_t ll_error; | ||
664 | /* A request is currently being sent to West Bridge. */ | ||
665 | cy_bool ll_sending_rqt; | ||
666 | /* The current mailbox request should be aborted. */ | ||
667 | cy_bool ll_abort_curr_rqt; | ||
668 | /* Indicates that the LL layer has queued mailbox data. */ | ||
669 | cy_bool ll_queued_data; | ||
670 | |||
671 | /* MISC API related */ | ||
672 | /* Misc callback */ | ||
673 | cy_as_misc_event_callback misc_event_cb; | ||
674 | |||
675 | /* Storage Related */ | ||
676 | /* The reference count for the Storage API */ | ||
677 | uint32_t storage_count; | ||
678 | /* Callback for storage events */ | ||
679 | cy_as_storage_event_callback_dep storage_event_cb; | ||
680 | /* V1.2+ callback for storage events */ | ||
681 | cy_as_storage_event_callback storage_event_cb_ms; | ||
682 | /* The error for a sleeping storage operation */ | ||
683 | cy_as_return_status_t storage_error; | ||
684 | /* Flag indicating that the storage stack is waiting for an operation */ | ||
685 | cy_bool storage_wait; | ||
686 | /* Request used for storage read/writes. */ | ||
687 | cy_as_ll_request_response *storage_rw_req_p; | ||
688 | /* Response used for storage read/writes. */ | ||
689 | cy_as_ll_request_response *storage_rw_resp_p; | ||
690 | /* The storage callback */ | ||
691 | cy_as_storage_callback_dep storage_cb; | ||
692 | /* The V1.2+ storage callback */ | ||
693 | cy_as_storage_callback storage_cb_ms; | ||
694 | /* The bus index for the currently outstanding async storage request */ | ||
695 | cy_as_bus_number_t storage_bus_index; | ||
696 | /* The device index for the currently outstanding async storage | ||
697 | * request */ | ||
698 | uint32_t storage_device_index; | ||
699 | /* The unit index for the currently outstanding async storage request */ | ||
700 | uint32_t storage_unit; | ||
701 | /* The block address for the currently outstanding async storage | ||
702 | * request */ | ||
703 | uint32_t storage_block_addr; | ||
704 | /* The operation for the currently outstanding async storage request */ | ||
705 | cy_as_oper_type storage_oper; | ||
706 | /* The endpoint used to read Storage data */ | ||
707 | cy_as_end_point_number_t storage_read_endpoint; | ||
708 | /* The endpoint used to write endpoint data */ | ||
709 | cy_as_end_point_number_t storage_write_endpoint; | ||
710 | cy_as_device_desc storage_device_info | ||
711 | [CY_AS_MAX_BUSES][CY_AS_MAX_STORAGE_DEVICES]; | ||
712 | /* The information on each device on each bus */ | ||
713 | |||
714 | /* USB Related */ | ||
715 | /* This conatins the endpoint async state */ | ||
716 | uint16_t epasync; | ||
717 | /* The reference count for the USB API */ | ||
718 | uint32_t usb_count; | ||
719 | /* The physical endpoint configuration */ | ||
720 | uint8_t usb_phy_config; | ||
721 | /* The callbacks for async func calls */ | ||
722 | cy_as_c_b_queue *usb_func_cbs; | ||
723 | /* Endpoint configuration information */ | ||
724 | cy_as_usb_end_point_config usb_config[16]; | ||
725 | /* The USB callback */ | ||
726 | cy_as_usb_event_callback_dep usb_event_cb; | ||
727 | /* The V1.2+ USB callback */ | ||
728 | cy_as_usb_event_callback usb_event_cb_ms; | ||
729 | /* The error for a sleeping usb operation */ | ||
730 | cy_as_return_status_t usb_error; | ||
731 | /* The USB callback for a pending storage operation */ | ||
732 | cy_as_usb_io_callback usb_cb[16]; | ||
733 | /* The buffer pending from a USB operation */ | ||
734 | void *usb_pending_buffer; | ||
735 | /* The size of the buffer pending from a USB operation */ | ||
736 | uint32_t usb_pending_size; | ||
737 | /* If true, send a short packet */ | ||
738 | cy_bool usb_spacket[16]; | ||
739 | /* The amount of data actually xferred */ | ||
740 | uint32_t usb_actual_cnt; | ||
741 | /* EP1OUT and EP1IN config register contents */ | ||
742 | uint8_t usb_ep1cfg[2]; | ||
743 | /* LEP config register contents */ | ||
744 | uint16_t usb_lepcfg[10]; | ||
745 | /* PEP config register contents */ | ||
746 | uint16_t usb_pepcfg[4]; | ||
747 | /* Buffer for EP0 and EP1 data sent via mailboxes */ | ||
748 | uint8_t *usb_ep_data; | ||
749 | /* Used to track how many ack requests are pending */ | ||
750 | uint32_t usb_delay_ack_count; | ||
751 | /* Maximum transfer size for USB endpoints. */ | ||
752 | uint32_t usb_max_tx_size; | ||
753 | |||
754 | /* Request for sending EP0 data to West Bridge */ | ||
755 | cy_as_ll_request_response *usb_ep0_dma_req; | ||
756 | /* Response for EP0 data sent to West Bridge */ | ||
757 | cy_as_ll_request_response *usb_ep0_dma_resp; | ||
758 | /* Request for sending EP1 data to West Bridge */ | ||
759 | cy_as_ll_request_response *usb_ep1_dma_req; | ||
760 | /* Response for EP1 data sent to West Bridge */ | ||
761 | cy_as_ll_request_response *usb_ep1_dma_resp; | ||
762 | |||
763 | cy_as_ll_request_response *usb_ep0_dma_req_save; | ||
764 | cy_as_ll_request_response *usb_ep0_dma_resp_save; | ||
765 | |||
766 | /* MTP Related */ | ||
767 | /* The reference count for the MTP API */ | ||
768 | uint32_t mtp_count; | ||
769 | /* The MTP event callback supplied by the client */ | ||
770 | cy_as_mtp_event_callback mtp_event_cb; | ||
771 | /* The current block table to be transferred */ | ||
772 | cy_as_mtp_block_table *tp_blk_tbl; | ||
773 | |||
774 | cy_as_c_b_queue *func_cbs_mtp; | ||
775 | cy_as_c_b_queue *func_cbs_usb; | ||
776 | cy_as_c_b_queue *func_cbs_stor; | ||
777 | cy_as_c_b_queue *func_cbs_misc; | ||
778 | cy_as_c_b_queue *func_cbs_res; | ||
779 | |||
780 | /* The last USB event that was received */ | ||
781 | cy_as_usb_event usb_last_event; | ||
782 | /* Types of storage media supported by the firmware */ | ||
783 | uint8_t media_supported[CY_AS_MAX_BUSES]; | ||
784 | |||
785 | /* SDIO card parameters*/ | ||
786 | cy_as_sdio_device sdiocard[CY_AS_MAX_BUSES]; | ||
787 | /* if true, MTP enabled Firmware. */ | ||
788 | cy_bool is_mtp_firmware; | ||
789 | /* if true, mailbox message has come already */ | ||
790 | cy_bool is_mtp_data_pending; | ||
791 | /* True between the time an Init was called and | ||
792 | * the complete event is generated */ | ||
793 | cy_bool mtp_turbo_active; | ||
794 | /* mbox reported EP 2 data len */ | ||
795 | uint16_t mtp_data_len; | ||
796 | /* The error for mtp EP4 write operation */ | ||
797 | cy_as_return_status_t mtp_error; | ||
798 | /* mtp send/get operation callback */ | ||
799 | cy_as_function_callback mtp_cb; | ||
800 | /* mtp send/get operation client id */ | ||
801 | uint32_t mtp_client; | ||
802 | /* mtp operation type. To be used in callback */ | ||
803 | cy_as_funct_c_b_type mtp_op; | ||
804 | |||
805 | /* Firmware is running in P2S only mode. */ | ||
806 | cy_bool is_storage_only_mode; | ||
807 | /* Interrupt mask value during device standby. */ | ||
808 | uint32_t stby_int_mask; | ||
809 | }; | ||
810 | |||
811 | #define cy_as_device_is_configured(dp) \ | ||
812 | ((dp)->state & CY_AS_DEVICE_STATE_CONFIGURED) | ||
813 | #define cy_as_device_set_configured(dp) \ | ||
814 | ((dp)->state |= CY_AS_DEVICE_STATE_CONFIGURED) | ||
815 | #define cy_as_device_set_unconfigured(dp) \ | ||
816 | ((dp)->state &= ~CY_AS_DEVICE_STATE_CONFIGURED) | ||
817 | |||
818 | #define cy_as_device_is_dma_running(dp) \ | ||
819 | ((dp)->state & CY_AS_DEVICE_STATE_DMA_MODULE) | ||
820 | #define cy_as_device_set_dma_running(dp) \ | ||
821 | ((dp)->state |= CY_AS_DEVICE_STATE_DMA_MODULE) | ||
822 | #define cy_as_device_set_dma_stopped(dp) \ | ||
823 | ((dp)->state &= ~CY_AS_DEVICE_STATE_DMA_MODULE) | ||
824 | |||
825 | #define cy_as_device_is_low_level_running(dp) \ | ||
826 | ((dp)->state & CY_AS_DEVICE_STATE_LOWLEVEL_MODULE) | ||
827 | #define cy_as_device_set_low_level_running(dp) \ | ||
828 | ((dp)->state |= CY_AS_DEVICE_STATE_LOWLEVEL_MODULE) | ||
829 | #define cy_as_device_set_low_level_stopped(dp) \ | ||
830 | ((dp)->state &= ~CY_AS_DEVICE_STATE_LOWLEVEL_MODULE) | ||
831 | |||
832 | #define cy_as_device_is_intr_running(dp) \ | ||
833 | ((dp)->state & CY_AS_DEVICE_STATE_INTR_MODULE) | ||
834 | #define cy_as_device_set_intr_running(dp) \ | ||
835 | ((dp)->state |= CY_AS_DEVICE_STATE_INTR_MODULE) | ||
836 | #define cy_as_device_set_intr_stopped(dp) \ | ||
837 | ((dp)->state &= ~CY_AS_DEVICE_STATE_INTR_MODULE) | ||
838 | |||
839 | #define cy_as_device_is_firmware_loaded(dp) \ | ||
840 | ((dp)->state & CY_AS_DEVICE_STATE_FIRMWARE_LOADED) | ||
841 | #define cy_as_device_set_firmware_loaded(dp) \ | ||
842 | ((dp)->state |= CY_AS_DEVICE_STATE_FIRMWARE_LOADED) | ||
843 | #define cy_as_device_set_firmware_not_loaded(dp) \ | ||
844 | ((dp)->state &= ~CY_AS_DEVICE_STATE_FIRMWARE_LOADED) | ||
845 | |||
846 | #define cy_as_device_is_storage_running(dp) \ | ||
847 | ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_MODULE) | ||
848 | #define cy_as_device_set_storage_running(dp) \ | ||
849 | ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_MODULE) | ||
850 | #define cy_as_device_set_storage_stopped(dp) \ | ||
851 | ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_MODULE) | ||
852 | |||
853 | #define cy_as_device_is_usb_running(dp) \ | ||
854 | ((dp)->state & CY_AS_DEVICE_STATE_USB_MODULE) | ||
855 | #define cy_as_device_set_usb_running(dp) \ | ||
856 | ((dp)->state |= CY_AS_DEVICE_STATE_USB_MODULE) | ||
857 | #define cy_as_device_set_usb_stopped(dp) \ | ||
858 | ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_MODULE) | ||
859 | |||
860 | #define cy_as_device_wants_scsi_messages(dp) \ | ||
861 | (((dp)->state & CY_AS_DEVICE_STATE_STORAGE_SCSIMSG) \ | ||
862 | ? cy_true : cy_false) | ||
863 | #define cy_as_device_set_scsi_messages(dp) \ | ||
864 | ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_SCSIMSG) | ||
865 | #define cy_as_device_clear_scsi_messages(dp) \ | ||
866 | ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_SCSIMSG) | ||
867 | |||
868 | #define cy_as_device_is_storage_async_pending(dp) \ | ||
869 | ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING) | ||
870 | #define cy_as_device_set_storage_async_pending(dp) \ | ||
871 | ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING) | ||
872 | #define cy_as_device_clear_storage_async_pending(dp) \ | ||
873 | ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING) | ||
874 | |||
875 | #define cy_as_device_is_usb_connected(dp) \ | ||
876 | ((dp)->state & CY_AS_DEVICE_STATE_USB_CONNECTED) | ||
877 | #define cy_as_device_set_usb_connected(dp) \ | ||
878 | ((dp)->state |= CY_AS_DEVICE_STATE_USB_CONNECTED) | ||
879 | #define cy_as_device_clear_usb_connected(dp) \ | ||
880 | ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_CONNECTED) | ||
881 | |||
882 | #define cy_as_device_is_usb_high_speed(dp) \ | ||
883 | ((dp)->state & CY_AS_DEVICE_STATE_USB_HIGHSPEED) | ||
884 | #define cy_as_device_set_usb_high_speed(dp) \ | ||
885 | ((dp)->state |= CY_AS_DEVICE_STATE_USB_HIGHSPEED) | ||
886 | #define cy_as_device_clear_usb_high_speed(dp) \ | ||
887 | ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_HIGHSPEED) | ||
888 | |||
889 | #define cy_as_device_is_in_callback(dp) \ | ||
890 | ((dp)->state & CY_AS_DEVICE_STATE_IN_CALLBACK) | ||
891 | #define cy_as_device_set_in_callback(dp) \ | ||
892 | ((dp)->state |= CY_AS_DEVICE_STATE_IN_CALLBACK) | ||
893 | #define cy_as_device_clear_in_callback(dp) \ | ||
894 | ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_CALLBACK) | ||
895 | |||
896 | #define cy_as_device_is_setup_i_o_performed(dp) \ | ||
897 | ((dp)->state & CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED) | ||
898 | #define cy_as_device_set_setup_i_o_performed(dp) \ | ||
899 | ((dp)->state |= CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED) | ||
900 | #define cy_as_device_clear_setup_i_o_performed(dp) \ | ||
901 | ((dp)->state &= ~CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED) | ||
902 | |||
903 | #define cy_as_device_is_ack_delayed(dp) \ | ||
904 | ((dp)->usb_delay_ack_count > 0) | ||
905 | #define cy_as_device_set_ack_delayed(dp) \ | ||
906 | ((dp)->usb_delay_ack_count++) | ||
907 | #define cy_as_device_rem_ack_delayed(dp) \ | ||
908 | ((dp)->usb_delay_ack_count--) | ||
909 | #define cy_as_device_clear_ack_delayed(dp) \ | ||
910 | ((dp)->usb_delay_ack_count = 0) | ||
911 | |||
912 | #define cy_as_device_is_setup_packet(dp) \ | ||
913 | ((dp)->state & CY_AS_DEVICE_STATE_IN_SETUP_PACKET) | ||
914 | #define cy_as_device_set_setup_packet(dp) \ | ||
915 | ((dp)->state |= CY_AS_DEVICE_STATE_IN_SETUP_PACKET) | ||
916 | #define cy_as_device_clear_setup_packet(dp) \ | ||
917 | ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_SETUP_PACKET) | ||
918 | |||
919 | #define cy_as_device_is_ep0_stalled(dp) \ | ||
920 | ((dp)->state & CY_AS_DEVICE_STATE_EP0_STALLED) | ||
921 | #define cy_as_device_set_ep0_stalled(dp) \ | ||
922 | ((dp)->state |= CY_AS_DEVICE_STATE_EP0_STALLED) | ||
923 | #define cy_as_device_clear_ep0_stalled(dp) \ | ||
924 | ((dp)->state &= ~CY_AS_DEVICE_STATE_EP0_STALLED) | ||
925 | |||
926 | #define cy_as_device_is_register_standby(dp) \ | ||
927 | ((dp)->state & CY_AS_DEVICE_STATE_REGISTER_STANDBY) | ||
928 | #define cy_as_device_set_register_standby(dp) \ | ||
929 | ((dp)->state |= CY_AS_DEVICE_STATE_REGISTER_STANDBY) | ||
930 | #define cy_as_device_clear_register_standby(dp) \ | ||
931 | ((dp)->state &= ~CY_AS_DEVICE_STATE_REGISTER_STANDBY) | ||
932 | |||
933 | #define cy_as_device_is_pin_standby(dp) \ | ||
934 | ((dp)->state & CY_AS_DEVICE_STATE_PIN_STANDBY) | ||
935 | #define cy_as_device_set_pin_standby(dp) \ | ||
936 | ((dp)->state |= CY_AS_DEVICE_STATE_PIN_STANDBY) | ||
937 | #define cy_as_device_clear_pin_standby(dp) \ | ||
938 | ((dp)->state &= ~CY_AS_DEVICE_STATE_PIN_STANDBY) | ||
939 | |||
940 | #define cy_as_device_is_crystal(dp) \ | ||
941 | ((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL) | ||
942 | #define cy_as_device_is_external_clock(dp) \ | ||
943 | (!((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL)) | ||
944 | #define cy_as_device_set_crystal(dp) \ | ||
945 | ((dp)->state |= CY_AS_DEVICE_STATE_CRYSTAL) | ||
946 | #define cy_as_device_set_external_clock(dp) \ | ||
947 | ((dp)->state &= ~CY_AS_DEVICE_STATE_CRYSTAL) | ||
948 | |||
949 | #define cy_as_device_is_waking(dp) \ | ||
950 | ((dp)->state & CY_AS_DEVICE_STATE_WAKING) | ||
951 | #define cy_as_device_set_waking(dp) \ | ||
952 | ((dp)->state |= CY_AS_DEVICE_STATE_WAKING) | ||
953 | #define cy_as_device_clear_waking(dp) \ | ||
954 | ((dp)->state &= ~CY_AS_DEVICE_STATE_WAKING) | ||
955 | |||
956 | #define cy_as_device_is_in_suspend_mode(dp) \ | ||
957 | ((dp)->state & CY_AS_DEVICE_STATE_SUSPEND) | ||
958 | #define cy_as_device_set_suspend_mode(dp) \ | ||
959 | ((dp)->state |= CY_AS_DEVICE_STATE_SUSPEND) | ||
960 | #define cy_as_device_clear_suspend_mode(dp) \ | ||
961 | ((dp)->state &= ~CY_AS_DEVICE_STATE_SUSPEND) | ||
962 | |||
963 | #define cy_as_device_is_reset_pending(dp) \ | ||
964 | ((dp)->state & CY_AS_DEVICE_STATE_RESETP) | ||
965 | #define cy_as_device_set_reset_pending(dp) \ | ||
966 | ((dp)->state |= CY_AS_DEVICE_STATE_RESETP) | ||
967 | #define cy_as_device_clear_reset_pending(dp) \ | ||
968 | ((dp)->state &= ~CY_AS_DEVICE_STATE_RESETP) | ||
969 | |||
970 | #define cy_as_device_is_standby_pending(dp) \ | ||
971 | ((dp)->state & CY_AS_DEVICE_STATE_STANDP) | ||
972 | #define cy_as_device_set_standby_pending(dp) \ | ||
973 | ((dp)->state |= CY_AS_DEVICE_STATE_STANDP) | ||
974 | #define cy_as_device_clear_standby_pending(dp) \ | ||
975 | ((dp)->state &= ~CY_AS_DEVICE_STATE_STANDP) | ||
976 | |||
977 | #define cy_as_device_is_s_s_s_pending(dp) \ | ||
978 | ((dp)->state & CY_AS_DEVICE_STATE_SSSP) | ||
979 | #define cy_as_device_set_s_s_s_pending(dp) \ | ||
980 | ((dp)->state |= CY_AS_DEVICE_STATE_SSSP) | ||
981 | #define cy_as_device_clear_s_s_s_pending(dp) \ | ||
982 | ((dp)->state &= ~CY_AS_DEVICE_STATE_SSSP) | ||
983 | |||
984 | #define cy_as_device_is_u_s_s_pending(dp) \ | ||
985 | ((dp)->state & CY_AS_DEVICE_STATE_USSP) | ||
986 | #define cy_as_device_set_u_s_s_pending(dp) \ | ||
987 | ((dp)->state |= CY_AS_DEVICE_STATE_USSP) | ||
988 | #define cy_as_device_clear_u_s_s_pending(dp) \ | ||
989 | ((dp)->state &= ~CY_AS_DEVICE_STATE_USSP) | ||
990 | |||
991 | #define cy_as_device_is_m_s_s_pending(dp) \ | ||
992 | ((dp)->state & CY_AS_DEVICE_STATE_MSSP) | ||
993 | #define cy_as_device_set_m_s_s_pending(dp) \ | ||
994 | ((dp)->state |= CY_AS_DEVICE_STATE_MSSP) | ||
995 | #define cy_as_device_clear_m_s_s_pending(dp) \ | ||
996 | ((dp)->state &= ~CY_AS_DEVICE_STATE_MSSP) | ||
997 | |||
998 | #define cy_as_device_is_p2s_dma_start_recvd(dp) \ | ||
999 | ((dp)->state & CY_AS_DEVICE_STATE_P2SDMA_START) | ||
1000 | #define cy_as_device_set_p2s_dma_start_recvd(dp) \ | ||
1001 | ((dp)->state |= CY_AS_DEVICE_STATE_P2SDMA_START) | ||
1002 | #define cy_as_device_clear_p2s_dma_start_recvd(dp) \ | ||
1003 | ((dp)->state &= ~CY_AS_DEVICE_STATE_P2SDMA_START) | ||
1004 | |||
1005 | #define cy_as_device_is_usb_async_pending(dp, ep) \ | ||
1006 | ((dp)->epasync & (1 << ep)) | ||
1007 | #define cy_as_device_set_usb_async_pending(dp, ep) \ | ||
1008 | ((dp)->epasync |= (1 << ep)) | ||
1009 | #define cy_as_device_clear_usb_async_pending(dp, ep) \ | ||
1010 | ((dp)->epasync &= ~(1 << ep)) | ||
1011 | |||
1012 | #define cy_as_device_is_nand_storage_supported(dp) \ | ||
1013 | ((dp)->media_supported[0] & 1) | ||
1014 | |||
1015 | /* Macros to check the type of West Bridge device. */ | ||
1016 | #define cy_as_device_is_astoria_dev(dp) \ | ||
1017 | (((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE) || \ | ||
1018 | ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE)) | ||
1019 | #define cy_as_device_is_antioch_dev(dp) \ | ||
1020 | ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE) | ||
1021 | |||
1022 | #ifdef CY_AS_LOG_SUPPORT | ||
1023 | extern void cy_as_log_debug_message(int value, const char *msg); | ||
1024 | #else | ||
1025 | #define cy_as_log_debug_message(value, msg) | ||
1026 | #endif | ||
1027 | |||
1028 | /* Summary | ||
1029 | This function finds the device object given the HAL tag | ||
1030 | |||
1031 | Description | ||
1032 | The user associats a device TAG with each West Bridge device | ||
1033 | created. This tag is passed from the API functions to and HAL | ||
1034 | functions that need to ID a specific West Bridge device. This | ||
1035 | tag is also passed in from the user back into the API via | ||
1036 | interrupt functions. This function allows the API to find the | ||
1037 | device structure associated with a given tag. | ||
1038 | |||
1039 | Notes | ||
1040 | This function does a simple linear search for the device based | ||
1041 | on the TAG. This function is called each time an West Bridge | ||
1042 | interrupt handler is called. Therefore this works fine for a | ||
1043 | small number of West Bridge devices (e.g. less than five). | ||
1044 | Anything more than this and this methodology will need to be | ||
1045 | updated. | ||
1046 | |||
1047 | Returns | ||
1048 | Pointer to a CyAsDevice associated with the tag | ||
1049 | */ | ||
1050 | extern cy_as_device * | ||
1051 | cy_as_device_find_from_tag( | ||
1052 | cy_as_hal_device_tag tag | ||
1053 | ); | ||
1054 | |||
1055 | #include "cyas_cplus_end.h" | ||
1056 | |||
1057 | #endif /* __INCLUDED_CYASDEVICE_H__ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdma.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdma.h deleted file mode 100644 index 16dc9f96018c..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasdma.h +++ /dev/null | |||
@@ -1,375 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasdma.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASDMA_H_ | ||
23 | #define _INCLUDED_CYASDMA_H_ | ||
24 | |||
25 | #include "cyashal.h" | ||
26 | #include "cyasdevice.h" | ||
27 | |||
28 | #include "cyas_cplus_start.h" | ||
29 | |||
30 | |||
31 | /*@@DMA Overview | ||
32 | This module manages the DMA operations to/from the West Bridge | ||
33 | device. The DMA module maintains a DMA queue for each endpoint | ||
34 | so multiple DMA requests may be queued and they will complete | ||
35 | at some future time. | ||
36 | |||
37 | The DMA module must be started before it can be used. It is | ||
38 | started by calling CyAsDmaStart(). This function initializes | ||
39 | all of the endpoint data structures. | ||
40 | |||
41 | In order to perform DMA on a particular endpoint, the endpoint | ||
42 | must be enabled by calling CyAsDmaEnableEndPoint(). In addition | ||
43 | to enabling or disabling the endpoint, this function also sets | ||
44 | the direction for a given endpoint. Direction is given in USB | ||
45 | terms. For P port to West Bridge traffic, the endpoint is a | ||
46 | CyAsDirectionIn endpoint. For West Bridge to P port traffic, | ||
47 | the endpoint is a CyAsDirectionOut endpoint. | ||
48 | |||
49 | Once DMA is started and an endpoint is enabled, DMA requests | ||
50 | are issued by calling CyAsDmaQueueRequest(). This function | ||
51 | queue either a DMA read or DMA write request. The callback | ||
52 | associated with the request is called once the request has been | ||
53 | fulfilled. | ||
54 | |||
55 | See Also | ||
56 | * CyAsDmaStart | ||
57 | * CyAsDmaEnableEndPoint | ||
58 | * CyAsDmaDirection | ||
59 | * CyAsDmaQueueRequest | ||
60 | */ | ||
61 | |||
62 | /************************ | ||
63 | * West Bridge Constants | ||
64 | ************************/ | ||
65 | #define CY_AS_DMA_MAX_SIZE_HW_SIZE (0xffffffff) | ||
66 | |||
67 | /************************ | ||
68 | * West Bridge Data Structures | ||
69 | ************************/ | ||
70 | |||
71 | /* Summary | ||
72 | This type specifies the direction of an endpoint to the | ||
73 | CyAsDmaEnableEndPoint function. | ||
74 | |||
75 | Description | ||
76 | When an endpoint is enabled, the direction of the endpoint | ||
77 | can also be set. This type is used to specify the endpoint | ||
78 | type. Note that the direction is specified in USB terms. | ||
79 | Therefore, if the DMA is from the P port to West Bridge, | ||
80 | the direction is IN. | ||
81 | |||
82 | See Also | ||
83 | * CyAsDmaEnableEndPoint | ||
84 | */ | ||
85 | typedef enum cy_as_dma_direction { | ||
86 | /* Set the endpoint to type IN (P -> West Bridge) */ | ||
87 | cy_as_direction_in = 0, | ||
88 | /* Set the endpoint to type OUT (West Bridge -> P) */ | ||
89 | cy_as_direction_out = 1, | ||
90 | /* Only valid for EP 0 */ | ||
91 | cy_as_direction_in_out = 2, | ||
92 | /* Do no change the endpoint type */ | ||
93 | cy_as_direction_dont_change = 3 | ||
94 | } cy_as_dma_direction; | ||
95 | |||
96 | /********************************* | ||
97 | * West Bridge Functions | ||
98 | *********************************/ | ||
99 | |||
100 | /* Summary | ||
101 | Initialize the DMA module and ready the module for receiving data | ||
102 | |||
103 | Description | ||
104 | This function initializes the DMA module by initializing all of | ||
105 | the endpoint data structures associated with the device given. | ||
106 | This function also register a DMA complete callback with the HAL | ||
107 | DMA code. This callback is called whenever the HAL DMA subsystem | ||
108 | completes a requested DMA operation. | ||
109 | |||
110 | Returns | ||
111 | CY_AS_ERROR_SUCCESS - the module initialized successfully | ||
112 | CY_AS_ERROR_OUT_OF_MEMORY - memory allocation failed during | ||
113 | initialization | ||
114 | CY_AS_ERROR_ALREADY_RUNNING - the DMA module was already running | ||
115 | |||
116 | See Also | ||
117 | * CyAsDmaStop | ||
118 | */ | ||
119 | extern cy_as_return_status_t | ||
120 | cy_as_dma_start( | ||
121 | /* The device to start */ | ||
122 | cy_as_device *dev_p | ||
123 | ); | ||
124 | |||
125 | /* Summary | ||
126 | Shutdown the DMA module | ||
127 | |||
128 | Description | ||
129 | This function shuts down the DMA module for this device by | ||
130 | canceling any DMA requests associated with each endpoint and | ||
131 | then freeing the resources associated with each DMA endpoint. | ||
132 | |||
133 | Returns | ||
134 | CY_AS_ERROR_SUCCESS - the module shutdown successfully | ||
135 | CY_AS_ERROR_NOT_RUNNING - the DMA module was not running | ||
136 | |||
137 | See Also | ||
138 | * CyAsDmaStart | ||
139 | * CyAsDmaCancel | ||
140 | */ | ||
141 | extern cy_as_return_status_t | ||
142 | cy_as_dma_stop( | ||
143 | /* The device to stop */ | ||
144 | cy_as_device *dev_p | ||
145 | ); | ||
146 | |||
147 | /* Summary | ||
148 | This function cancels all outstanding DMA requests on a given endpoint | ||
149 | |||
150 | Description | ||
151 | This function cancels any DMA requests outstanding on a given endpoint | ||
152 | by disabling the transfer of DMA requests from the queue to the HAL | ||
153 | layer and then removing any pending DMA requests from the queue. The | ||
154 | callback associated with any DMA requests that are being removed is | ||
155 | called with an error code of CY_AS_ERROR_CANCELED. | ||
156 | |||
157 | Notes | ||
158 | If a request has already been sent to the HAL layer it will be | ||
159 | completed and not canceled. Only requests that have not been sent to | ||
160 | the HAL layer will be cancelled. | ||
161 | |||
162 | Returns | ||
163 | CY_AS_ERROR_SUCCESS - the traffic on the endpoint is canceled | ||
164 | successfully | ||
165 | |||
166 | See Also | ||
167 | */ | ||
168 | extern cy_as_return_status_t | ||
169 | cy_as_dma_cancel( | ||
170 | /* The device of interest */ | ||
171 | cy_as_device *dev_p, | ||
172 | /* The endpoint to cancel */ | ||
173 | cy_as_end_point_number_t ep, | ||
174 | cy_as_return_status_t err | ||
175 | ); | ||
176 | |||
177 | /* Summary | ||
178 | This function enables a single endpoint for DMA operations | ||
179 | |||
180 | Description | ||
181 | In order to enable the queuing of DMA requests on a given | ||
182 | endpoint, the endpoint must be enabled for DMA. This function | ||
183 | enables a given endpoint. In addition, this function sets the | ||
184 | direction of the DMA operation. | ||
185 | |||
186 | Returns | ||
187 | * CY_AS_ERROR_INVALID_ENDPOINT - invalid endpoint number | ||
188 | * CY_AS_ERROR_SUCCESS - endpoint was enabled or disabled | ||
189 | * successfully | ||
190 | |||
191 | See Also | ||
192 | * CyAsDmaQueueRequest | ||
193 | */ | ||
194 | extern cy_as_return_status_t | ||
195 | cy_as_dma_enable_end_point( | ||
196 | /* The device of interest */ | ||
197 | cy_as_device *dev_p, | ||
198 | /* The endpoint to enable or disable */ | ||
199 | cy_as_end_point_number_t ep, | ||
200 | /* CyTrue to enable, CyFalse to disable */ | ||
201 | cy_bool enable, | ||
202 | /* The direction of the endpoint */ | ||
203 | cy_as_dma_direction dir | ||
204 | ); | ||
205 | |||
206 | /* Summary | ||
207 | This function queue a DMA request for a given endpoint | ||
208 | |||
209 | Description | ||
210 | When an West Bridge API module wishes to do a DMA operation, | ||
211 | this function is called on the associated endpoint to queue | ||
212 | a DMA request. When the DMA request has been fulfilled, the | ||
213 | callback associated with the DMA operation is called. | ||
214 | |||
215 | Notes | ||
216 | The buffer associated with the DMA request, must remain valid | ||
217 | until after the callback function is calld. | ||
218 | |||
219 | Returns | ||
220 | * CY_AS_ERROR_SUCCESS - the DMA operation was queued successfully | ||
221 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint number was invalid | ||
222 | * CY_AS_ERROR_ENDPOINT_DISABLED - the endpoint was disabled | ||
223 | * CY_AS_ERROR_OUT_OF_MEMORY - out of memory processing the request | ||
224 | |||
225 | See Also | ||
226 | * CyAsDmaEnableEndPoint | ||
227 | * CyAsDmaCancel | ||
228 | */ | ||
229 | extern cy_as_return_status_t | ||
230 | cy_as_dma_queue_request( | ||
231 | /* The device of interest */ | ||
232 | cy_as_device *dev_p, | ||
233 | /* The endpoint to receive a new request */ | ||
234 | cy_as_end_point_number_t ep, | ||
235 | /* The memory buffer for the DMA request - | ||
236 | * must be valid until after the callback has been called */ | ||
237 | void *mem_p, | ||
238 | /* The size of the DMA request in bytes */ | ||
239 | uint32_t size, | ||
240 | /* If true and a DMA read request, return the next packet | ||
241 | * regardless of size */ | ||
242 | cy_bool packet, | ||
243 | /* If true, this is a read request, | ||
244 | * otherwise it is a write request */ | ||
245 | cy_bool readreq, | ||
246 | /* The callback to call when the DMA request is complete, | ||
247 | * either successfully or via an error */ | ||
248 | cy_as_dma_callback cb | ||
249 | ); | ||
250 | |||
251 | /* Summary | ||
252 | This function waits until all DMA requests on a given endpoint | ||
253 | have been processed and then return | ||
254 | |||
255 | Description | ||
256 | There are times when a module in the West Bridge API needs to | ||
257 | wait until the DMA operations have been queued. This function | ||
258 | sleeps until all DMA requests have been fulfilled and only then | ||
259 | returns to the caller. | ||
260 | |||
261 | Notes | ||
262 | I don't think we will need a list of sleeping clients to support | ||
263 | multiple parallel client modules sleeping on a single endpoint, | ||
264 | but if we do instead of having a single sleep channel in the | ||
265 | endpoint, each client will have to supply a sleep channel and we | ||
266 | will have to maintain a list of sleep channels to wake. | ||
267 | |||
268 | Returns | ||
269 | * CY_AS_ERROR_SUCCESS - the queue has drained successfully | ||
270 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given is not valid | ||
271 | * CY_AS_ERROR_NESTED_SLEEP - CyAsDmaQueueRequest() was requested | ||
272 | * on an endpoint where CyAsDmaQueueRequest was already called | ||
273 | */ | ||
274 | extern cy_as_return_status_t | ||
275 | cy_as_dma_drain_queue( | ||
276 | /* The device of interest */ | ||
277 | cy_as_device *dev_p, | ||
278 | /* The endpoint to drain */ | ||
279 | cy_as_end_point_number_t ep, | ||
280 | /* If CyTrue, call kickstart to start the DMA process, | ||
281 | if cy_false, west bridge will start the DMA process */ | ||
282 | cy_bool kickstart | ||
283 | ); | ||
284 | |||
285 | /* Summary | ||
286 | Sets the maximum amount of data West Bridge can accept in a single | ||
287 | DMA Operation for the given endpoint | ||
288 | |||
289 | Description | ||
290 | Depending on the configuration of the West Bridge device endpoint, | ||
291 | the amount of data that can be accepted varies. This function | ||
292 | sets the maximum amount of data West Bridge can accept in a single | ||
293 | DMA operation. The value is stored with the endpoint and passed | ||
294 | to the HAL layer in the CyAsHalDmaSetupWrite() and | ||
295 | CyAsHalDmaSetupRead() functoins. | ||
296 | |||
297 | Returns | ||
298 | * CY_AS_ERROR_SUCCESS - the value was set successfully | ||
299 | * CY_AS_ERROR_INVALID_SIZE - the size value was not valid | ||
300 | */ | ||
301 | extern cy_as_return_status_t | ||
302 | cy_as_dma_set_max_dma_size( | ||
303 | /* The device of interest */ | ||
304 | cy_as_device *dev_p, | ||
305 | /* The endpoint to change */ | ||
306 | cy_as_end_point_number_t ep, | ||
307 | /* The max size of this endpoint in bytes */ | ||
308 | uint32_t size | ||
309 | ); | ||
310 | |||
311 | /* Summary | ||
312 | This function starts the DMA process on a given channel. | ||
313 | |||
314 | Description | ||
315 | When transferring data from the P port processor to West | ||
316 | Bridge, the DMA operation must be initiated P Port software | ||
317 | for the first transfer. Subsequent transferrs will be | ||
318 | handled at the interrupt level. | ||
319 | |||
320 | Returns | ||
321 | * CY_AS_ERROR_SUCCESS | ||
322 | */ | ||
323 | extern cy_as_return_status_t | ||
324 | cy_as_dma_kick_start( | ||
325 | /* The device of interest */ | ||
326 | cy_as_device *dev_p, | ||
327 | /* The endpoint to change */ | ||
328 | cy_as_end_point_number_t ep | ||
329 | ); | ||
330 | |||
331 | /* Summary | ||
332 | This function receives endpoint data from a request. | ||
333 | |||
334 | Description | ||
335 | For endpoint 0 and 1 the endpoint data is transferred from | ||
336 | the West Bridge device to the DMA via a lowlevel | ||
337 | requests (via the mailbox registers). | ||
338 | |||
339 | Returns | ||
340 | * CY_AS_ERROR_SUCCESS | ||
341 | */ | ||
342 | extern cy_as_return_status_t | ||
343 | cy_as_dma_received_data( | ||
344 | /* The device of interest */ | ||
345 | cy_as_device *dev_p, | ||
346 | /* The endpoint that received data */ | ||
347 | cy_as_end_point_number_t ep, | ||
348 | /* The data size */ | ||
349 | uint32_t dsize, | ||
350 | /* The data buffer */ | ||
351 | void *data | ||
352 | ); | ||
353 | |||
354 | /* Summary | ||
355 | This function is called when the DMA operation on | ||
356 | an endpoint has been completed. | ||
357 | |||
358 | Returns | ||
359 | * void | ||
360 | */ | ||
361 | extern void | ||
362 | cy_as_dma_completed_callback( | ||
363 | /* Tag to HAL completing the DMA operation. */ | ||
364 | cy_as_hal_device_tag tag, | ||
365 | /* Endpoint on which DMA has been completed. */ | ||
366 | cy_as_end_point_number_t ep, | ||
367 | /* Length of data received. */ | ||
368 | uint32_t length, | ||
369 | /* Status of DMA operation. */ | ||
370 | cy_as_return_status_t status | ||
371 | ); | ||
372 | |||
373 | #include "cyas_cplus_end.h" | ||
374 | |||
375 | #endif /* _INCLUDED_CYASDMA_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaserr.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaserr.h deleted file mode 100644 index 2cd0af1ed781..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaserr.h +++ /dev/null | |||
@@ -1,1094 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyaserr.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASERR_H_ | ||
23 | #define _INCLUDED_CYASERR_H_ | ||
24 | |||
25 | /*@@West Bridge Errors | ||
26 | Summary | ||
27 | This section lists the error codes for West Bridge. | ||
28 | |||
29 | */ | ||
30 | |||
31 | /* Summary | ||
32 | The function completed successfully | ||
33 | */ | ||
34 | #define CY_AS_ERROR_SUCCESS (0) | ||
35 | |||
36 | /* Summary | ||
37 | A function trying to acquire a resource was unable to do so. | ||
38 | |||
39 | Description | ||
40 | This code indicates that a resource that the API was trying to claim | ||
41 | could not be claimed. | ||
42 | |||
43 | See Also | ||
44 | * CyAsMiscAcquireResource | ||
45 | * CyAsStorageClaim | ||
46 | */ | ||
47 | #define CY_AS_ERROR_NOT_ACQUIRED (1) | ||
48 | |||
49 | /* Summary | ||
50 | A function trying to acquire a resource was unable to do so. | ||
51 | |||
52 | Description | ||
53 | The West Bridge API provides the capability to assign the storage media to | ||
54 | either the West Bridge device or the USB port. This error indicates the | ||
55 | P port was trying to release a storage media and was not able to do | ||
56 | so. This generally means it was not owned by the P port processor. | ||
57 | |||
58 | See Also | ||
59 | * CyAsStorageRelease | ||
60 | */ | ||
61 | #define CY_AS_ERROR_NOT_RELEASED (2) | ||
62 | |||
63 | /* Summary | ||
64 | The West Bridge firmware is not loaded. | ||
65 | |||
66 | Description | ||
67 | Most of the API functions that are part of the West Bridge API rely on | ||
68 | firmware running on the West Bridge device. This error code is | ||
69 | returned when one of these functions is called and the firmware has | ||
70 | not yet been loaded. | ||
71 | |||
72 | See Also | ||
73 | * CyAsMiscGetFirmwareVersion | ||
74 | * CyAsMiscReset | ||
75 | * CyAsMiscAcquireResource | ||
76 | * CyAsMiscReleaseResource | ||
77 | * CyAsMiscSetTraceLevel | ||
78 | * CyAsStorageStart | ||
79 | * CyAsStorageStop | ||
80 | * CyAsStorageRegisterCallback | ||
81 | * CyAsStorageClaim | ||
82 | * CyAsStorageRelease | ||
83 | * CyAsStorageQueryMedia | ||
84 | * CyAsStorageQueryDevice | ||
85 | * CyAsStorageQueryUnit | ||
86 | * CyAsStorageRead | ||
87 | * CyAsStorageWrite | ||
88 | * CyAsStorageReadAsync | ||
89 | * CyAsStorageWriteAsync | ||
90 | */ | ||
91 | #define CY_AS_ERROR_NO_FIRMWARE (3) | ||
92 | |||
93 | /* Summary | ||
94 | A timeout occurred waiting on a response from the West Bridge device | ||
95 | |||
96 | Description | ||
97 | When requests are made of the West Bridge device, a response is expected | ||
98 | within a given timeframe. If a response is not recevied within the | ||
99 | given timeframe, a timeout error occurs. | ||
100 | */ | ||
101 | #define CY_AS_ERROR_TIMEOUT (4) | ||
102 | |||
103 | /* Summary | ||
104 | A request to download firmware was made while not in the CONFIG mode | ||
105 | |||
106 | Description | ||
107 | Firmware is downloaded via the CyAsMiscDownloadFirmware() function. This | ||
108 | function can only be called while in the CONFIG mode. This error indicates | ||
109 | that the CyAsMiscDownloadFirmware() call was made while not in the CONFIG | ||
110 | mode. | ||
111 | |||
112 | See Also | ||
113 | * CyAsMiscDownloadFirmware | ||
114 | */ | ||
115 | #define CY_AS_ERROR_NOT_IN_CONFIG_MODE (5) | ||
116 | |||
117 | /* Summary | ||
118 | This error is returned if the firmware size specified is too invalid. | ||
119 | |||
120 | Description | ||
121 | If the size of the firmware to be downloaded into West Bridge is | ||
122 | invalid, this error is issued. Invalid firmware sizes are those | ||
123 | greater than 24K or a size of zero. | ||
124 | |||
125 | See Also | ||
126 | * CyAsMiscDownloadFirmare | ||
127 | */ | ||
128 | #define CY_AS_ERROR_INVALID_SIZE (6) | ||
129 | |||
130 | /* Summary | ||
131 | This error is returned if a request is made to acquire a resource that has | ||
132 | already been acquired. | ||
133 | |||
134 | Description | ||
135 | This error is returned if a request is made to acquire a resource that has | ||
136 | already been acquired. | ||
137 | |||
138 | See Also | ||
139 | * CyAsMiscAcquireResource | ||
140 | * CyAsMiscReleaseResource | ||
141 | */ | ||
142 | #define CY_AS_ERROR_RESOURCE_ALREADY_OWNED (7) | ||
143 | |||
144 | /* Summary | ||
145 | This error is returned if a request is made to release a resource that has | ||
146 | not previously been acquired. | ||
147 | |||
148 | Description | ||
149 | This error is returned if a request is made to release a resource that has | ||
150 | not previously been acquired. | ||
151 | |||
152 | See Also | ||
153 | * CyAsMiscAcquireResource | ||
154 | * CyAsMiscReleaseResource | ||
155 | */ | ||
156 | #define CY_AS_ERROR_RESOURCE_NOT_OWNED (8) | ||
157 | |||
158 | /* Summary | ||
159 | This error is returned when a request is made for a media that | ||
160 | does not exist | ||
161 | |||
162 | Description | ||
163 | This error is returned when a request is made that references | ||
164 | a storage media that does not exist. This error is returned | ||
165 | when the storage media is not present in the current system, | ||
166 | or if the media value given is not valid. | ||
167 | |||
168 | See Also | ||
169 | * CyAsMiscSetTraceLevel | ||
170 | * CyAsStorageClaim | ||
171 | * CyAsStorageRelease | ||
172 | * CyAsStorageRead | ||
173 | * CyAsStorageWrite | ||
174 | * CyAsStorageReadAsync | ||
175 | * CyAsStorageWriteAsync | ||
176 | */ | ||
177 | #define CY_AS_ERROR_NO_SUCH_MEDIA (9) | ||
178 | |||
179 | /* Summary | ||
180 | This error is returned when a request is made for a device | ||
181 | that does not exist | ||
182 | |||
183 | Description | ||
184 | This error is returned when a request is made that references a | ||
185 | storage device that does not exist. This error is returned when | ||
186 | the device index is not present in the current system, or if the | ||
187 | device index exceeds 15. | ||
188 | |||
189 | See Also | ||
190 | * CyAsMiscSetTraceLevel | ||
191 | * CyAsStorageQueryDevice | ||
192 | * CyAsStorageRead | ||
193 | * CyAsStorageWrite | ||
194 | * CyAsStorageReadAsync | ||
195 | * CyAsStorageWriteAsync | ||
196 | */ | ||
197 | #define CY_AS_ERROR_NO_SUCH_DEVICE (10) | ||
198 | |||
199 | /* Summary | ||
200 | This error is returned when a request is made for a unit that | ||
201 | does not exist | ||
202 | |||
203 | Description | ||
204 | This error is returned when a request is made that references | ||
205 | a storage unit that does not exist. This error is returned | ||
206 | when the unit index is not present in the current system, or | ||
207 | if the unit index exceeds 255. | ||
208 | |||
209 | See Also | ||
210 | * CyAsMiscSetTraceLevel | ||
211 | * CyAsStorageQueryDevice | ||
212 | * CyAsStorageQueryUnit | ||
213 | * CyAsStorageRead | ||
214 | * CyAsStorageWrite | ||
215 | * CyAsStorageReadAsync | ||
216 | * CyAsStorageWriteAsync | ||
217 | */ | ||
218 | #define CY_AS_ERROR_NO_SUCH_UNIT (11) | ||
219 | |||
220 | /* Summary | ||
221 | This error is returned when a request is made for a block that | ||
222 | does not exist | ||
223 | |||
224 | Description | ||
225 | This error is returned when a request is made that references | ||
226 | a storage block that does not exist. This error is returned | ||
227 | when the block address reference an address beyond the end of | ||
228 | the unit selected. | ||
229 | |||
230 | See Also | ||
231 | * CyAsStorageRead | ||
232 | * CyAsStorageWrite | ||
233 | * CyAsStorageReadAsync | ||
234 | * CyAsStorageWriteAsync | ||
235 | */ | ||
236 | #define CY_AS_ERROR_INVALID_BLOCK (12) | ||
237 | |||
238 | /* Summary | ||
239 | This error is returned when an invalid trace level is set. | ||
240 | |||
241 | Description | ||
242 | This error is returned when the trace level request is greater | ||
243 | than three. | ||
244 | |||
245 | See Also | ||
246 | * CyAsMiscSetTraceLevel | ||
247 | */ | ||
248 | #define CY_AS_ERROR_INVALID_TRACE_LEVEL (13) | ||
249 | |||
250 | /* Summary | ||
251 | This error is returned when West Bridge is already in the standby state | ||
252 | and an attempt is made to put West Bridge into this state again. | ||
253 | |||
254 | Description | ||
255 | This error is returned when West Bridge is already in the standby state | ||
256 | and an attempt is made to put West Bridge into this state again. | ||
257 | |||
258 | See Also | ||
259 | * CyAsMiscEnterStandby | ||
260 | */ | ||
261 | #define CY_AS_ERROR_ALREADY_STANDBY (14) | ||
262 | |||
263 | /* Summary | ||
264 | This error is returned when the API needs to set a pin on the | ||
265 | West Bridge device, but this is not supported by the underlying HAL | ||
266 | layer. | ||
267 | |||
268 | Description | ||
269 | This error is returned when the API needs to set a pin on the | ||
270 | West Bridge device, but this is not supported by the underlying HAL | ||
271 | layer. | ||
272 | |||
273 | See Also | ||
274 | * CyAsMiscEnterStandby | ||
275 | * CyAsMiscLeaveStandby | ||
276 | */ | ||
277 | #define CY_AS_ERROR_SETTING_WAKEUP_PIN (15) | ||
278 | |||
279 | /* Summary | ||
280 | This error is returned when a module is being started that has | ||
281 | already been started. | ||
282 | |||
283 | Description | ||
284 | This error is returned when a module is being started and that module | ||
285 | has already been started. This error does not occur with the | ||
286 | CyAsStorageStart() or CyAsUsbStart() functions as the storage and | ||
287 | USB modules are reference counted. | ||
288 | |||
289 | Note | ||
290 | At the current time, this error is returned by module internal to | ||
291 | the API but not returned by any of the API functions. | ||
292 | */ | ||
293 | #define CY_AS_ERROR_ALREADY_RUNNING (16) | ||
294 | |||
295 | /* Summary | ||
296 | This error is returned when a module is being stopped that has | ||
297 | already been stopped. | ||
298 | |||
299 | Description | ||
300 | This error is returned when a module is being stopped and that module | ||
301 | has already been stopped. This error does not occur with the | ||
302 | CyAsStorageStop() or CyAsUsbStop() functions as the storage and USB | ||
303 | modules are reference counted. | ||
304 | |||
305 | Note | ||
306 | At the current time, this error is returned by module internal to | ||
307 | the API but not returned by any of the API functions. | ||
308 | */ | ||
309 | |||
310 | #define CY_AS_ERROR_NOT_RUNNING (17) | ||
311 | |||
312 | /* Summary | ||
313 | This error is returned when the caller tries to claim a media that | ||
314 | has already been claimed. | ||
315 | |||
316 | Description | ||
317 | This error is returned when the caller tries to claim a media that | ||
318 | has already been claimed. | ||
319 | |||
320 | See Also | ||
321 | * CyAsStorageClaim | ||
322 | */ | ||
323 | #define CY_AS_ERROR_MEDIA_ALREADY_CLAIMED (18) | ||
324 | |||
325 | /* Summary | ||
326 | This error is returned when the caller tries to release a media that has | ||
327 | already been released. | ||
328 | |||
329 | Description | ||
330 | This error is returned when the caller tries to release a media that has | ||
331 | already been released. | ||
332 | |||
333 | See Also | ||
334 | * CyAsStorageRelease | ||
335 | */ | ||
336 | #define CY_AS_ERROR_MEDIA_NOT_CLAIMED (19) | ||
337 | |||
338 | /* Summary | ||
339 | This error is returned when canceling trying to cancel an asynchronous | ||
340 | operation when an async operation is not pending. | ||
341 | |||
342 | Description | ||
343 | This error is returned when a call is made to a function to cancel an | ||
344 | asynchronous operation and there is no asynchronous operation pending. | ||
345 | |||
346 | See Also | ||
347 | * CyAsStorageCancelAsync | ||
348 | * CyAsUsbCancelAsync | ||
349 | */ | ||
350 | #define CY_AS_ERROR_NO_OPERATION_PENDING (20) | ||
351 | |||
352 | /* Summary | ||
353 | This error is returned when an invalid endpoint number is provided to | ||
354 | an API call. | ||
355 | |||
356 | Description | ||
357 | This error is returned when an invalid endpoint number is specified in | ||
358 | an API call. The endpoint number may be invalid because it is greater | ||
359 | than 15, or because it was a reference to an endpoint that is invalid | ||
360 | for West Bridge (2, 4, 6, or 8). | ||
361 | |||
362 | See Also | ||
363 | * CyAsUsbSetEndPointConfig | ||
364 | * CyAsUsbGetEndPointConfig | ||
365 | * CyAsUsbReadData | ||
366 | * CyAsUsbWriteData | ||
367 | * CyAsUsbReadDataAsync | ||
368 | * CyAsUsbWriteDataAsync | ||
369 | * CyAsUsbSetStall | ||
370 | * CyAsUsbGetStall | ||
371 | */ | ||
372 | #define CY_AS_ERROR_INVALID_ENDPOINT (21) | ||
373 | |||
374 | /* Summary | ||
375 | This error is returned when an invalid descriptor type | ||
376 | is specified in an API call. | ||
377 | |||
378 | Description | ||
379 | This error is returned when an invalid descriptor type | ||
380 | is specified in an API call. | ||
381 | |||
382 | See Also | ||
383 | * CyAsUsbSetDescriptor | ||
384 | * CyAsUsbGetDescriptor | ||
385 | */ | ||
386 | #define CY_AS_ERROR_INVALID_DESCRIPTOR (22) | ||
387 | |||
388 | /* Summary | ||
389 | This error is returned when an invalid descriptor index | ||
390 | is specified in an API call. | ||
391 | |||
392 | Description | ||
393 | This error is returned when an invalid descriptor index | ||
394 | is specified in an API call. | ||
395 | |||
396 | See Also | ||
397 | * CyAsUsbSetDescriptor | ||
398 | * CyAsUsbGetDescriptor | ||
399 | */ | ||
400 | #define CY_AS_ERROR_BAD_INDEX (23) | ||
401 | |||
402 | /* Summary | ||
403 | This error is returned if trying to set a USB descriptor | ||
404 | when in the P port enumeration mode. | ||
405 | |||
406 | Description | ||
407 | This error is returned if trying to set a USB descriptor | ||
408 | when in the P port enumeration mode. | ||
409 | |||
410 | See Also | ||
411 | * CyAsUsbSetDescriptor | ||
412 | * CyAsUsbGetDescriptor | ||
413 | */ | ||
414 | #define CY_AS_ERROR_BAD_ENUMERATION_MODE (24) | ||
415 | |||
416 | /* Summary | ||
417 | This error is returned when the endpoint configuration specified | ||
418 | is not valid. | ||
419 | |||
420 | Description | ||
421 | This error is returned when the endpoint configuration specified | ||
422 | is not valid. | ||
423 | |||
424 | See Also | ||
425 | * CyAsUsbSetDescriptor | ||
426 | * CyAsUsbGetDescriptor | ||
427 | * CyAsUsbCommitConfig | ||
428 | */ | ||
429 | #define CY_AS_ERROR_INVALID_CONFIGURATION (25) | ||
430 | |||
431 | /* Summary | ||
432 | This error is returned when the API cannot verify it is connected | ||
433 | to an West Bridge device. | ||
434 | |||
435 | Description | ||
436 | When the API is initialized, the API tries to read the ID register from | ||
437 | the West Bridge device. The value from this ID register should match the | ||
438 | value expected before communications with West Bridge are established. This | ||
439 | error means that the contents of the ID register cannot be verified. | ||
440 | |||
441 | See Also | ||
442 | * CyAsMiscConfigureDevice | ||
443 | */ | ||
444 | #define CY_AS_ERROR_NO_ANTIOCH (26) | ||
445 | |||
446 | /* Summary | ||
447 | This error is returned when an API function is called and | ||
448 | CyAsMiscConfigureDevice has not been called to configure West Bridge | ||
449 | for the current environment. | ||
450 | |||
451 | Description | ||
452 | This error is returned when an API function is called and | ||
453 | CyAsMiscConfigureDevice has not been called to configure West Bridge for | ||
454 | the current environment. | ||
455 | |||
456 | See Also | ||
457 | * Almost all API function | ||
458 | */ | ||
459 | #define CY_AS_ERROR_NOT_CONFIGURED (27) | ||
460 | |||
461 | /* Summary | ||
462 | This error is returned when West Bridge cannot allocate memory required for | ||
463 | internal API operations. | ||
464 | |||
465 | Description | ||
466 | This error is returned when West Bridge cannot allocate memory required for | ||
467 | internal API operations. | ||
468 | |||
469 | See Also | ||
470 | * Almost all API functoins | ||
471 | */ | ||
472 | #define CY_AS_ERROR_OUT_OF_MEMORY (28) | ||
473 | |||
474 | /* Summary | ||
475 | This error is returned when a module is being started that has | ||
476 | already been started. | ||
477 | |||
478 | Description | ||
479 | This error is returned when a module is being started and that module | ||
480 | has already been started. This error does not occur with the | ||
481 | CyAsStorageStart() or CyAsUsbStart() functions as the storage and | ||
482 | USB modules are reference counted. | ||
483 | |||
484 | Note | ||
485 | At the current time, this error is returned by module internal to the API but | ||
486 | not returned by any of the API functions. | ||
487 | */ | ||
488 | #define CY_AS_ERROR_NESTED_SLEEP (29) | ||
489 | |||
490 | /* Summary | ||
491 | This error is returned when an operation is attempted on an endpoint that has | ||
492 | been disabled. | ||
493 | |||
494 | Description | ||
495 | This error is returned when an operation is attempted on an endpoint that has | ||
496 | been disabled. | ||
497 | |||
498 | See Also | ||
499 | * CyAsUsbReadData | ||
500 | * CyAsUsbWriteData | ||
501 | * CyAsUsbReadDataAsync | ||
502 | * CyAsUsbWriteDataAsync | ||
503 | */ | ||
504 | #define CY_AS_ERROR_ENDPOINT_DISABLED (30) | ||
505 | |||
506 | /* Summary | ||
507 | This error is returned when a call is made to an API function when | ||
508 | the device is in standby. | ||
509 | |||
510 | Description | ||
511 | When the West Bridge device is in standby, the only two API functions that | ||
512 | can be called are CyAsMiscInStandby() and CyAsMiscLeaveStandby(). | ||
513 | Calling any other API function will result in this error. | ||
514 | |||
515 | See Also | ||
516 | */ | ||
517 | #define CY_AS_ERROR_IN_STANDBY (31) | ||
518 | |||
519 | /* Summary | ||
520 | This error is returned when an API call is made with an invalid handle value. | ||
521 | |||
522 | Description | ||
523 | This error is returned when an API call is made with an invalid handle value. | ||
524 | |||
525 | See Also | ||
526 | */ | ||
527 | #define CY_AS_ERROR_INVALID_HANDLE (32) | ||
528 | |||
529 | /* Summary | ||
530 | This error is returned when an invalid response is returned from | ||
531 | the West Bridge device. | ||
532 | |||
533 | Description | ||
534 | Many of the API calls result in requests made to the West Bridge | ||
535 | device. This error occurs when the response from West Bridge is | ||
536 | invalid and generally indicates that the West Bridge device | ||
537 | should be reset. | ||
538 | |||
539 | See Also | ||
540 | */ | ||
541 | #define CY_AS_ERROR_INVALID_RESPONSE (33) | ||
542 | |||
543 | /* Summary | ||
544 | This error is returned from the callback function for any asynchronous | ||
545 | read or write request that is canceled. | ||
546 | |||
547 | Description | ||
548 | When asynchronous requests are canceled, this error is passed to the | ||
549 | callback function associated with the request to indicate that the | ||
550 | request has been canceled | ||
551 | |||
552 | See Also | ||
553 | * CyAsStorageReadAsync | ||
554 | * CyAsStorageWriteAsync | ||
555 | * CyAsUsbReadDataAsync | ||
556 | * CyAsUsbWriteDataAsync | ||
557 | * CyAsStorageCancelAsync | ||
558 | * CyAsUsbCancelAsync | ||
559 | */ | ||
560 | #define CY_AS_ERROR_CANCELED (34) | ||
561 | |||
562 | /* Summary | ||
563 | This error is returned when the call to create sleep channel fails | ||
564 | in the HAL layer. | ||
565 | |||
566 | Description | ||
567 | This error is returned when the call to create sleep channel fails | ||
568 | in the HAL layer. | ||
569 | |||
570 | See Also | ||
571 | * CyAsMiscConfigureDevice | ||
572 | */ | ||
573 | #define CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED (35) | ||
574 | |||
575 | /* Summary | ||
576 | This error is returned when the call to CyAsMiscLeaveStandby | ||
577 | is made and the device is not in standby. | ||
578 | |||
579 | Description | ||
580 | This error is returned when the call to CyAsMiscLeaveStandby | ||
581 | is made and the device is not in standby. | ||
582 | |||
583 | See Also | ||
584 | */ | ||
585 | #define CY_AS_ERROR_NOT_IN_STANDBY (36) | ||
586 | |||
587 | /* Summary | ||
588 | This error is returned when the call to destroy sleep channel fails | ||
589 | in the HAL layer. | ||
590 | |||
591 | Description | ||
592 | This error is returned when the call to destroy sleep channel fails | ||
593 | in the HAL layer. | ||
594 | |||
595 | See Also | ||
596 | * CyAsMiscDestroyDevice | ||
597 | */ | ||
598 | #define CY_AS_ERROR_DESTROY_SLEEP_CHANNEL_FAILED (37) | ||
599 | |||
600 | /* Summary | ||
601 | This error is returned when an invalid resource is specified to a call | ||
602 | to CyAsMiscAcquireResource() or CyAsMiscReleaseResource() | ||
603 | |||
604 | Description | ||
605 | This error is returned when an invalid resource is specified to a call | ||
606 | to CyAsMiscAcquireResource() or CyAsMiscReleaseResource() | ||
607 | |||
608 | See Also | ||
609 | * CyAsMiscAcquireResource | ||
610 | * CyAsMiscReleaseResource | ||
611 | */ | ||
612 | #define CY_AS_ERROR_INVALID_RESOURCE (38) | ||
613 | |||
614 | /* Summary | ||
615 | This error occurs when an operation is requested on an endpoint that has | ||
616 | a currently pending async operation. | ||
617 | |||
618 | Description | ||
619 | There can only be a single asynchronous pending operation on a given | ||
620 | endpoint and while the operation is pending on other operation can occur | ||
621 | on the endpoint. In addition, the device cannot enter standby while | ||
622 | any asynchronous operations are pending. | ||
623 | |||
624 | See Also | ||
625 | * CyAsStorageReadAsync | ||
626 | * CyAsStorageWriteAsync | ||
627 | * CyAsUsbReadDataAsync | ||
628 | * CyAsUsbWriteDataAsync | ||
629 | * CyAsStorageRead | ||
630 | * CyAsStorageWrite | ||
631 | * CyAsUsbReadData | ||
632 | * CyAsUsbWriteData | ||
633 | * CyAsMiscEnterStandby | ||
634 | */ | ||
635 | #define CY_AS_ERROR_ASYNC_PENDING (39) | ||
636 | |||
637 | /* Summary | ||
638 | This error is returned when a call to CyAsStorageCancelAsync() or | ||
639 | CyAsUsbCancelAsync() is made when no asynchronous request is pending. | ||
640 | |||
641 | Description | ||
642 | This error is returned when a call to CyAsStorageCancelAsync() or | ||
643 | CyAsUsbCancelAsync() is made when no asynchronous request is pending. | ||
644 | |||
645 | See Also | ||
646 | * CyAsStorageCancelAsync | ||
647 | * CyAsUsbCancelAsync | ||
648 | */ | ||
649 | #define CY_AS_ERROR_ASYNC_NOT_PENDING (40) | ||
650 | |||
651 | /* Summary | ||
652 | This error is returned when a request is made to put the West Bridge device | ||
653 | into standby mode while the USB stack is still active. | ||
654 | |||
655 | Description | ||
656 | This error is returned when a request is made to put the West Bridge device | ||
657 | into standby mode while the USB stack is still active. You must call the | ||
658 | function CyAsUsbStop() in order to shut down the USB stack in order to go | ||
659 | into the standby mode. | ||
660 | |||
661 | See Also | ||
662 | * CyAsMiscEnterStandby | ||
663 | */ | ||
664 | #define CY_AS_ERROR_USB_RUNNING (41) | ||
665 | |||
666 | /* Summary | ||
667 | A request for in the wrong direction was issued on an endpoint. | ||
668 | |||
669 | Description | ||
670 | This error is returned when a write is attempted on an OUT endpoint or | ||
671 | a read is attempted on an IN endpoint. | ||
672 | |||
673 | See Also | ||
674 | * CyAsUsbReadData | ||
675 | * CyAsUsbWriteData | ||
676 | * CyAsUsbReadDataAsync | ||
677 | * CyAsUsbWriteDataAsync | ||
678 | */ | ||
679 | #define CY_AS_ERROR_USB_BAD_DIRECTION (42) | ||
680 | |||
681 | /* Summary | ||
682 | An invalid request was received | ||
683 | |||
684 | Description | ||
685 | This error is isused if an invalid request is issued. | ||
686 | */ | ||
687 | #define CY_AS_ERROR_INVALID_REQUEST (43) | ||
688 | |||
689 | /* Summary | ||
690 | An ACK request was requested while no setup packet was pending. | ||
691 | |||
692 | Description | ||
693 | This error is issued if CyAsUsbAckSetupPacket() is called when no | ||
694 | setup packet is pending. | ||
695 | */ | ||
696 | #define CY_AS_ERROR_NO_SETUP_PACKET_PENDING (44) | ||
697 | |||
698 | /* Summary | ||
699 | A call was made to a API function that cannot be called from a callback. | ||
700 | |||
701 | Description | ||
702 | Only asynchronous functions can be called from within West Bridge callbacks. | ||
703 | This error results when an invalid function is called from a callback. | ||
704 | */ | ||
705 | #define CY_AS_ERROR_INVALID_IN_CALLBACK (45) | ||
706 | |||
707 | /* Summary | ||
708 | A call was made to CyAsUsbSetEndPointConfig() before | ||
709 | CyAsUsbSetPhysicalConfiguration() was called. | ||
710 | |||
711 | Description | ||
712 | When logical endpoints are configured, you must define the physical | ||
713 | endpoint for the logical endpoint being configured. Therefore | ||
714 | CyAsUsbSetPhysicalConfiguration() must be called to define the | ||
715 | physical endpoints before calling CyAsUsbSetEndPointConfig(). | ||
716 | */ | ||
717 | #define CY_AS_ERROR_ENDPOINT_CONFIG_NOT_SET (46) | ||
718 | |||
719 | /* Summary | ||
720 | The physical endpoint referenced is not valid in the current physical | ||
721 | configuration | ||
722 | |||
723 | Description | ||
724 | When logical endpoints are configured, you must define the physical | ||
725 | endpoint for the logical endpoint being configured. Given the | ||
726 | current physical configuration, the physical endpoint referenced | ||
727 | is not valid. | ||
728 | */ | ||
729 | #define CY_AS_ERROR_INVALID_PHYSICAL_ENDPOINT (47) | ||
730 | |||
731 | /* Summary | ||
732 | The data supplied to the CyAsMiscDownloadFirmware() call is not | ||
733 | aligned on a WORD (16 bit) boundary. | ||
734 | |||
735 | Description | ||
736 | Many systems have problems with the transfer of data a word at a | ||
737 | time when the data is not word aligned. For this reason, we | ||
738 | require that the firmware image be aligned on a word boundary and | ||
739 | be an even number of bytes. This error is returned if these | ||
740 | conditions are not met. | ||
741 | */ | ||
742 | #define CY_AS_ERROR_ALIGNMENT_ERROR (48) | ||
743 | |||
744 | /* Summary | ||
745 | A call was made to destroy the West Bridge device, but the USB | ||
746 | stack or the storage stack was will running. | ||
747 | |||
748 | Description | ||
749 | Before calling CyAsMiscDestroyDevice to destroy an West Bridge | ||
750 | device created via a call to CyAsMiscCreateDevice, the USB and | ||
751 | STORAGE stacks much be stopped via calls to CyAsUsbStop and | ||
752 | CyAsStorageStop. This error indicates that one of these two | ||
753 | stacks have not been stopped. | ||
754 | */ | ||
755 | #define CY_AS_ERROR_STILL_RUNNING (49) | ||
756 | |||
757 | /* Summary | ||
758 | A call was made to the API for a function that is not yet supported. | ||
759 | |||
760 | Description | ||
761 | There are calls that are not yet supported that may be called through | ||
762 | the API. This is done to maintain compatibility in the future with | ||
763 | the API. This error is returned if you are asking for a capability | ||
764 | that does not yet exist. | ||
765 | */ | ||
766 | #define CY_AS_ERROR_NOT_YET_SUPPORTED (50) | ||
767 | |||
768 | /* Summary | ||
769 | A NULL callback was provided where a non-NULL callback was required | ||
770 | |||
771 | Description | ||
772 | When async IO function are called, a callback is required to indicate | ||
773 | that the IO has completed. This callback must be non-NULL. | ||
774 | */ | ||
775 | #define CY_AS_ERROR_NULL_CALLBACK (51) | ||
776 | |||
777 | /* Summary | ||
778 | This error is returned when a request is made to put the West Bridge device | ||
779 | into standby mode while the storage stack is still active. | ||
780 | |||
781 | Description | ||
782 | This error is returned when a request is made to put the West Bridge device | ||
783 | into standby mode while the storage stack is still active. You must call the | ||
784 | function CyAsStorageStop() in order to shut down the storage stack in order | ||
785 | to go into the standby mode. | ||
786 | |||
787 | See Also | ||
788 | * CyAsMiscEnterStandby | ||
789 | */ | ||
790 | #define CY_AS_ERROR_STORAGE_RUNNING (52) | ||
791 | |||
792 | /* Summary | ||
793 | This error is returned when an operation is attempted that cannot be | ||
794 | completed while the USB stack is connected to a USB host. | ||
795 | |||
796 | Description | ||
797 | This error is returned when an operation is attempted that cannot be | ||
798 | completed while the USB stack is connected to a USB host. In order | ||
799 | to successfully complete the desired operation, CyAsUsbDisconnect() | ||
800 | must be called to disconnect from the host. | ||
801 | */ | ||
802 | #define CY_AS_ERROR_USB_CONNECTED (53) | ||
803 | |||
804 | /* Summary | ||
805 | This error is returned when a USB disconnect is attempted and the | ||
806 | West Bridge device is not connected. | ||
807 | |||
808 | Description | ||
809 | This error is returned when a USB disconnect is attempted and the | ||
810 | West Bridge device is not connected. | ||
811 | */ | ||
812 | #define CY_AS_ERROR_USB_NOT_CONNECTED (54) | ||
813 | |||
814 | /* Summary | ||
815 | This error is returned when an P2S storage operation attempted | ||
816 | and data could not be read or written to the storage media. | ||
817 | |||
818 | Description | ||
819 | This error is returned when an P2S storage operation attempted | ||
820 | and data could not be read or written to the storage media. If | ||
821 | this error is recevied then a retry can be done. | ||
822 | */ | ||
823 | #define CY_AS_ERROR_MEDIA_ACCESS_FAILURE (55) | ||
824 | |||
825 | /* Summary | ||
826 | This error is returned when an P2S storage operation attempted | ||
827 | and the media is write protected. | ||
828 | |||
829 | Description | ||
830 | This error is returned when an P2S storage operation attempted | ||
831 | and the media is write protected. | ||
832 | */ | ||
833 | #define CY_AS_ERROR_MEDIA_WRITE_PROTECTED (56) | ||
834 | |||
835 | /* Summary | ||
836 | This error is returned when an attempt is made to cancel a request | ||
837 | that has already been sent to the West Bridge. | ||
838 | |||
839 | Description | ||
840 | It is not possible to cancel an asynchronous storage read/write | ||
841 | operation after the actual data transfer with the West Bridge | ||
842 | has started. This error is returned if CyAsStorageCancelAsync | ||
843 | is called to cancel such a request. | ||
844 | */ | ||
845 | #define CY_AS_ERROR_OPERATION_IN_TRANSIT (57) | ||
846 | |||
847 | /* Summary | ||
848 | This error is returned when an invalid parameter is passed to | ||
849 | one of the APIs. | ||
850 | |||
851 | Description | ||
852 | Some of the West Bridge APIs are applicable to only specific | ||
853 | media types, devices etc. This error code is returned when a | ||
854 | API is called with an invalid parameter type. | ||
855 | */ | ||
856 | #define CY_AS_ERROR_INVALID_PARAMETER (58) | ||
857 | |||
858 | /* Summary | ||
859 | This error is returned if an API is not supported in the current setup. | ||
860 | |||
861 | Description | ||
862 | Some of the West Bridge APIs work only with specific device types | ||
863 | or firmware images. This error is returned when such APIs are called | ||
864 | when the current device or firmware does not support the invoked API | ||
865 | function. | ||
866 | */ | ||
867 | #define CY_AS_ERROR_NOT_SUPPORTED (59) | ||
868 | |||
869 | /* Summary | ||
870 | This error is returned when a call is made to one of the Storage or | ||
871 | USB APIs while the device is in suspend mode. | ||
872 | |||
873 | Description | ||
874 | This error is returned when a call is made to one of the storage or | ||
875 | USB APIs while the device is in suspend mode. | ||
876 | */ | ||
877 | #define CY_AS_ERROR_IN_SUSPEND (60) | ||
878 | |||
879 | /* Summary | ||
880 | This error is returned when the call to CyAsMiscLeaveSuspend | ||
881 | is made and the device is not in suspend mode. | ||
882 | |||
883 | Description | ||
884 | This error is returned when the call to CyAsMiscLeaveSuspend | ||
885 | is made and the device is not in suspend mode. | ||
886 | */ | ||
887 | #define CY_AS_ERROR_NOT_IN_SUSPEND (61) | ||
888 | |||
889 | /* Summary | ||
890 | This error is returned when a command that is disabled by USB is called. | ||
891 | |||
892 | Description | ||
893 | The remote wakeup capability should be exercised only if enabled by the | ||
894 | USB host. This error is returned when the CyAsUsbSignalRemoteWakeup API | ||
895 | is called when the feature has not been enabled by the USB host. | ||
896 | */ | ||
897 | #define CY_AS_ERROR_FEATURE_NOT_ENABLED (62) | ||
898 | |||
899 | /* Summary | ||
900 | This error is returned when an Async storage read or write is called before a | ||
901 | query device call is issued. | ||
902 | |||
903 | Description | ||
904 | In order for the SDK to properly set up a DMA the block size of a given media | ||
905 | needs to be known. This is done by making a call to CyAsStorageQueryDevice. | ||
906 | This call only needs to be made once per device. If this call is not issued | ||
907 | before an Async read or write is issued this error code is returned. | ||
908 | */ | ||
909 | #define CY_AS_ERROR_QUERY_DEVICE_NEEDED (63) | ||
910 | |||
911 | /* Summary | ||
912 | This error is returned when a call is made to USB or STORAGE Start or | ||
913 | Stop before a prior Start or Stop has finished. | ||
914 | |||
915 | Description | ||
916 | The USB and STORAGE start and stop functions can only be called if a | ||
917 | prior start or stop function call has fully completed. This means when | ||
918 | an async EX call is made you must wait until the callback for that call | ||
919 | has been completed before calling start or stop again. | ||
920 | */ | ||
921 | #define CY_AS_ERROR_STARTSTOP_PENDING (64) | ||
922 | |||
923 | /* Summary | ||
924 | This error is returned when a request is made for a bus that does not exist | ||
925 | |||
926 | Description | ||
927 | This error is returned when a request is made that references a bus | ||
928 | number that does not exist. This error is returned when the bus number | ||
929 | is not present in the current system, or if the bus number given is not | ||
930 | valid. | ||
931 | |||
932 | See Also | ||
933 | * CyAsMiscSetTraceLevel | ||
934 | * CyAsStorageClaim | ||
935 | * CyAsStorageRelease | ||
936 | * CyAsStorageRead | ||
937 | * CyAsStorageWrite | ||
938 | * CyAsStorageReadAsync | ||
939 | * CyAsStorageWriteAsync | ||
940 | */ | ||
941 | #define CY_AS_ERROR_NO_SUCH_BUS (65) | ||
942 | |||
943 | /* Summary | ||
944 | This error is returned when the bus corresponding to a media type cannot | ||
945 | be resolved. | ||
946 | |||
947 | Description | ||
948 | In some S-Port configurations, the same media type may be supported on | ||
949 | multiple buses. In this case, it is not possible to resolve the target | ||
950 | address based on the media type. This error indicates that only | ||
951 | bus-based addressing is supported in a particular run-time | ||
952 | configuration. | ||
953 | |||
954 | See Also | ||
955 | * CyAsMediaType | ||
956 | * CyAsBusNumber_t | ||
957 | */ | ||
958 | #define CY_AS_ERROR_ADDRESS_RESOLUTION_ERROR (66) | ||
959 | |||
960 | /* Summary | ||
961 | This error is returned when an invalid command is passed to the | ||
962 | CyAsStorageSDIOSync() function. | ||
963 | |||
964 | Description | ||
965 | This error indiactes an unknown Command type was passed to the SDIO | ||
966 | command handler function. | ||
967 | */ | ||
968 | |||
969 | #define CY_AS_ERROR_INVALID_COMMAND (67) | ||
970 | |||
971 | |||
972 | /* Summary | ||
973 | This error is returned when an invalid function /uninitialized | ||
974 | function is passed to an SDIO function. | ||
975 | |||
976 | Description | ||
977 | This error indiactes an unknown/uninitialized function number was | ||
978 | passed to a SDIO function. | ||
979 | */ | ||
980 | #define CY_AS_ERROR_INVALID_FUNCTION (68) | ||
981 | |||
982 | /* Summary | ||
983 | This error is returned when an invalid block size is passed to | ||
984 | CyAsSdioSetBlocksize(). | ||
985 | |||
986 | Description | ||
987 | This error is returned when an invalid block size (greater than | ||
988 | maximum block size supported) is passed to CyAsSdioSetBlocksize(). | ||
989 | */ | ||
990 | |||
991 | #define CY_AS_ERROR_INVALID_BLOCKSIZE (69) | ||
992 | |||
993 | /* Summary | ||
994 | This error is returned when an tuple requested is not found. | ||
995 | |||
996 | Description | ||
997 | This error is returned when an tuple requested is not found. | ||
998 | */ | ||
999 | #define CY_AS_ERROR_TUPLE_NOT_FOUND (70) | ||
1000 | |||
1001 | /* Summary | ||
1002 | This error is returned when an extended IO operation to an SDIO function is | ||
1003 | Aborted. | ||
1004 | Description | ||
1005 | This error is returned when an extended IO operation to an SDIO function is | ||
1006 | Aborted. */ | ||
1007 | #define CY_AS_ERROR_IO_ABORTED (71) | ||
1008 | |||
1009 | /* Summary | ||
1010 | This error is returned when an extended IO operation to an SDIO function is | ||
1011 | Suspended. | ||
1012 | Description | ||
1013 | This error is returned when an extended IO operation to an SDIO function is | ||
1014 | Suspended. */ | ||
1015 | #define CY_AS_ERROR_IO_SUSPENDED (72) | ||
1016 | |||
1017 | /* Summary | ||
1018 | This error is returned when IO is attempted to a Suspended SDIO function. | ||
1019 | Description | ||
1020 | This error is returned when IO is attempted to a Suspended SDIO function. */ | ||
1021 | #define CY_AS_ERROR_FUNCTION_SUSPENDED (73) | ||
1022 | |||
1023 | /* Summary | ||
1024 | This error is returned if an MTP function is called before MTPStart | ||
1025 | has completed. | ||
1026 | Description | ||
1027 | This error is returned if an MTP function is called before MTPStart | ||
1028 | has completed. | ||
1029 | */ | ||
1030 | #define CY_AS_ERROR_MTP_NOT_STARTED (74) | ||
1031 | |||
1032 | /* Summary | ||
1033 | This error is returned by API functions that are not valid in MTP | ||
1034 | mode (CyAsStorageClaim for example) | ||
1035 | Description | ||
1036 | This error is returned by API functions that are not valid in MTP | ||
1037 | mode (CyAsStorageClaim for example) | ||
1038 | */ | ||
1039 | #define CY_AS_ERROR_NOT_VALID_IN_MTP (75) | ||
1040 | |||
1041 | /* Summary | ||
1042 | This error is returned when an attempt is made to partition a | ||
1043 | storage device that is already partitioned. | ||
1044 | |||
1045 | Description | ||
1046 | This error is returned when an attempt is made to partition a | ||
1047 | storage device that is already partitioned. | ||
1048 | */ | ||
1049 | #define CY_AS_ERROR_ALREADY_PARTITIONED (76) | ||
1050 | |||
1051 | /* Summary | ||
1052 | This error is returned when a call is made to | ||
1053 | CyAsUsbSelectMSPartitions after CyAsUsbSetEnumConfig is called. | ||
1054 | |||
1055 | Description | ||
1056 | This error is returned when a call is made to | ||
1057 | CyAsUsbSelectMSPartitions after CyAsUsbSetEnumConfig is called. | ||
1058 | */ | ||
1059 | #define CY_AS_ERROR_INVALID_CALL_SEQUENCE (77) | ||
1060 | |||
1061 | /* Summary | ||
1062 | This error is returned when a StorageWrite opperation is attempted | ||
1063 | during an ongoing MTP transfer. | ||
1064 | Description | ||
1065 | This error is returned when a StorageWrite opperation is attempted | ||
1066 | during an ongoing MTP transfer. A MTP transfer is initiated by a | ||
1067 | call to CyAsMTPInitSendObject or CyAsMTPInitGetObject and is not | ||
1068 | finished until the CyAsMTPSendObjectComplete or | ||
1069 | CyAsMTPGetObjectComplete event is generated. | ||
1070 | */ | ||
1071 | #define CY_AS_ERROR_NOT_VALID_DURING_MTP (78) | ||
1072 | |||
1073 | /* Summary | ||
1074 | This error is returned when a StorageRead or StorageWrite is | ||
1075 | attempted while a UsbRead or UsbWrite on a Turbo endpoint (2 or 6) is | ||
1076 | pending, or visa versa. | ||
1077 | Description | ||
1078 | When there is a pending usb read or write on a turbo endpoint (2 or 6) | ||
1079 | a storage read or write call may not be performed. Similarly when there | ||
1080 | is a pending storage read or write a usb read or write may not be | ||
1081 | performed on a turbo endpoint (2 or 6). | ||
1082 | */ | ||
1083 | #define CY_AS_ERROR_STORAGE_EP_TURBO_EP_CONFLICT (79) | ||
1084 | |||
1085 | /* Summary | ||
1086 | This error is returned when processor requests to reserve greater | ||
1087 | number of zones than available for proc booting via lna firmware. | ||
1088 | |||
1089 | Description | ||
1090 | Astoria does not allocate any nand zones for the processor in this case. | ||
1091 | */ | ||
1092 | #define CY_AS_ERROR_EXCEEDED_NUM_ZONES_AVAIL (80) | ||
1093 | |||
1094 | #endif /* _INCLUDED_CYASERR_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashal.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashal.h deleted file mode 100644 index b695ba1a9110..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashal.h +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyashal.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASHAL_H_ | ||
23 | #define _INCLUDED_CYASHAL_H_ | ||
24 | |||
25 | #if !defined(__doxygen__) | ||
26 | |||
27 | /* The possible HAL layers defined and implemented by Cypress */ | ||
28 | |||
29 | #ifdef __CY_ASTORIA_FPGA_HAL__ | ||
30 | #ifdef CY_HAL_DEFINED | ||
31 | #error only one HAL layer can be defined | ||
32 | #endif | ||
33 | |||
34 | #define CY_HAL_DEFINED | ||
35 | |||
36 | #include "cyashalfpga.h" | ||
37 | #endif | ||
38 | |||
39 | /***** SCM User space HAL ****/ | ||
40 | #ifdef __CY_ASTORIA_SCM_HAL__ | ||
41 | #ifdef CY_HAL_DEFINED | ||
42 | #error only one HAL layer can be defined | ||
43 | #endif | ||
44 | |||
45 | #define CY_HAL_DEFINEDŚŚ | ||
46 | |||
47 | #include "cyanhalscm.h" | ||
48 | #endif | ||
49 | /***** SCM User space HAL ****/ | ||
50 | |||
51 | /***** SCM Kernel HAL ****/ | ||
52 | #ifdef __CY_ASTORIA_SCM_KERNEL_HAL__ | ||
53 | #ifdef CY_HAL_DEFINED | ||
54 | #error only one HAL layer can be defined | ||
55 | #endif | ||
56 | |||
57 | #define CY_HAL_DEFINEDÅš | ||
58 | |||
59 | #include "cyanhalscm_kernel.h" | ||
60 | #endif | ||
61 | /***** SCM Kernel HAL ****/ | ||
62 | |||
63 | /***** OMAP5912 Kernel HAL ****/ | ||
64 | #ifdef __CY_ASTORIA_OMAP_5912_KERNEL_HAL__ | ||
65 | #ifdef CY_HAL_DEFINED | ||
66 | #error only one HAL layer can be defined | ||
67 | #endif | ||
68 | |||
69 | #define CY_HAL_DEFINED | ||
70 | |||
71 | #include "cyanhalomap_kernel.h" | ||
72 | #endif | ||
73 | /***** eof OMAP5912 Kernel HAL ****/ | ||
74 | |||
75 | |||
76 | |||
77 | /***** OMAP3430 Kernel HAL ****/ | ||
78 | #ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL | ||
79 | |||
80 | #ifdef CY_HAL_DEFINED | ||
81 | #error only one HAL layer can be defined | ||
82 | #endif | ||
83 | |||
84 | #define CY_HAL_DEFINED | ||
85 | /* moved to staging location, eventual implementation | ||
86 | * considered is here | ||
87 | * #include mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h> | ||
88 | */ | ||
89 | #include "../../../arch/arm/plat-omap/include/mach/westbridge/westbridge-omap3-pnand-hal/cyashalomap_kernel.h" | ||
90 | |||
91 | #endif | ||
92 | /*****************************/ | ||
93 | |||
94 | |||
95 | /******/ | ||
96 | #ifdef __CY_ASTORIA_CUSTOMER_HAL__ | ||
97 | #ifdef CY_HAL_DEFINED | ||
98 | #error only one HAL layer can be defined | ||
99 | #endif | ||
100 | br | ||
101 | #define CY_HAL_DEFINED | ||
102 | #include "cyashal_customer.h" | ||
103 | |||
104 | #endif | ||
105 | |||
106 | #endif /* __doxygen__ */ | ||
107 | |||
108 | #endif /* _INCLUDED_CYASHAL_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashalcb.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashalcb.h deleted file mode 100644 index 4d1670ee0476..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashalcb.h +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyashalcb.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASHALCB_H_ | ||
23 | #define _INCLUDED_CYASHALCB_H_ | ||
24 | |||
25 | /* Summary | ||
26 | This type defines a callback function type called when a | ||
27 | DMA operation has completed. | ||
28 | |||
29 | Description | ||
30 | |||
31 | See Also | ||
32 | * CyAsHalDmaRegisterCallback | ||
33 | * CyAsHalDmaSetupWrite | ||
34 | * CyAsHalDmaSetupRead | ||
35 | */ | ||
36 | typedef void (*cy_as_hal_dma_complete_callback)( | ||
37 | cy_as_hal_device_tag tag, | ||
38 | cy_as_end_point_number_t ep, | ||
39 | uint32_t cnt, | ||
40 | cy_as_return_status_t ret); | ||
41 | |||
42 | typedef cy_as_hal_dma_complete_callback \ | ||
43 | cy_an_hal_dma_complete_callback; | ||
44 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashaldoc.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashaldoc.h deleted file mode 100644 index 5bcbe9bf2f5d..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyashaldoc.h +++ /dev/null | |||
@@ -1,800 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyashaldoc.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASHALDOC_H_ | ||
23 | #define _INCLUDED_CYASHALDOC_H_ | ||
24 | |||
25 | #include "cyashaldef.h" | ||
26 | |||
27 | /*@@Hardware Abstraction Layer (HAL) | ||
28 | Summary | ||
29 | This software module is supplied by the user of the West Bridge | ||
30 | API. This module contains the software that is specific to the | ||
31 | hardware implementation or operating system of the client | ||
32 | system. | ||
33 | |||
34 | * Sleep Channels * | ||
35 | A sleep channel is a operating system object that provides that | ||
36 | capability for one thread or process to sleep while waiting on | ||
37 | the completion of some hardware event. The hardware event is | ||
38 | usually processed by a hardware interrupt and the interrupt | ||
39 | handler then wakes the thread or process that is sleeping. | ||
40 | |||
41 | A sleep channel provides the mechanism for this operation. A | ||
42 | sleep channel is created and initialized during the API | ||
43 | initialization. When the API needs to wait for the hardware, | ||
44 | the API performs a SleepOn() operation on the sleep channel. | ||
45 | When hardware event occurs, an interrupt handler processes the | ||
46 | event and then performs a Wake() operation on the sleep channel | ||
47 | to wake the sleeping process or thread. | ||
48 | |||
49 | * DMA Model * | ||
50 | When the West Bridge API needs to transfer USB or storage data | ||
51 | to/from the West Bridge device, this is done using a "DMA" | ||
52 | operation. In this context the term DMA is used loosely as the | ||
53 | West Bridge API does not really care if the data is transferred | ||
54 | using a burst read or write operation, or if the data is | ||
55 | transferred using programmed I/O operations. When a "DMA" | ||
56 | operation is needed, the West Bridge API calls either | ||
57 | CyAsHalDmaSetupRead() or CyAsHalDmaSetupWrite() depending on the | ||
58 | direction of the data flow. The West Bridge API expects the | ||
59 | "DMA" operation requested in the call to be completed and the | ||
60 | registered "DMA complete" callback to be called. | ||
61 | |||
62 | The West Bridge API looks at several factors to determine the | ||
63 | size of the "DMA" request to pass to the HAL layer. First the | ||
64 | West Bridge API calls CyAsHalDmaMaxRequestSize() to determine | ||
65 | the maximum amount of data the HAL layer can accept for a "DMA" | ||
66 | operation on the requested endpoint. The West Bridge API will | ||
67 | never exceed this value in a "DMA" request to the HAL layer. | ||
68 | The West Bridge API also sends the maximum amount of data the | ||
69 | West Bridge device can accept as part of the "DMA" request. If | ||
70 | the amount of data in the "DMA" request to the HAL layer | ||
71 | exceeds the amount of data the West Bridge device can accept, | ||
72 | it is expected that the HAL layer has the ability to break the | ||
73 | request into multiple operations. | ||
74 | |||
75 | If the HAL implementation requires the API to handle the size | ||
76 | of the "DMA" requests for one or more endpoints, the value | ||
77 | CY_AS_DMA_MAX_SIZE_HW_SIZE can be returned from the | ||
78 | CyAsHalDmaMaxRequestSize() call. In this case, the API assumes | ||
79 | that the maximum size of each "DMA" request should be limited | ||
80 | to the maximum that can be accepted by the endpoint in question. | ||
81 | |||
82 | Notes | ||
83 | See the <install>/api/hal/scm_kernel/cyashalscm_kernel.c file | ||
84 | for an example of how the DMA request size can be managed by | ||
85 | the HAL implementation. | ||
86 | |||
87 | * Interrupt Handling * | ||
88 | The HAL implementation is required to handle interrupts arriving | ||
89 | from the West Bridge device, and call the appropriate handlers. | ||
90 | If the interrupt arriving is one of PLLLOCKINT, PMINT, MBINT or | ||
91 | MCUINT, the CyAsIntrServiceInterrupt API should be called to | ||
92 | service the interrupt. If the interrupt arriving is DRQINT, the | ||
93 | HAL should identify the endpoint corresponding to which the DRQ | ||
94 | is being generated and perform the read/write transfer from the | ||
95 | West Bridge. See the <install>/api/hal/scm_kernel/ | ||
96 | cyashalscm_kernel.c or <install>/api/hal/fpga/cyashalfpga.c | ||
97 | reference HAL implementations for examples. | ||
98 | |||
99 | The HAL implementation can choose to poll the West Bridge | ||
100 | interrupt status register instead of using interrupts. In this | ||
101 | case, the polling has to be performed from a different thread/ | ||
102 | task than the one running the APIs. This is required because | ||
103 | there are API calls that block on the reception of data from the | ||
104 | West Bridge, which is delivered only through the interrupt | ||
105 | handlers. | ||
106 | |||
107 | * Required Functions * | ||
108 | This section defines the types and functions that must be | ||
109 | supplied in order to provide a complete HAL layer for the | ||
110 | West Bridge API. | ||
111 | |||
112 | Types that must be supplied: | ||
113 | * CyAsHalSleepChannel | ||
114 | |||
115 | Hardware functions that must be supplied: | ||
116 | * CyAsHalWriteRegister | ||
117 | * CyAsHalReadRegister | ||
118 | * CyAsHalDmaSetupWrite | ||
119 | * CyAsHalDmaSetupRead | ||
120 | * CyAsHalDmaCancelRequest | ||
121 | * CyAsHalDmaRegisterCallback | ||
122 | * CyAsHalDmaMaxRequestSize | ||
123 | * CyAsHalSetWakeupPin | ||
124 | * CyAsHalSyncDeviceClocks | ||
125 | * CyAsHalInitDevRegisters | ||
126 | * CyAsHalReadRegsBeforeStandby | ||
127 | * CyAsHalRestoreRegsAfterStandby | ||
128 | |||
129 | Operating system functions that must be supplied: | ||
130 | * CyAsHalAlloc | ||
131 | * CyAsHalFree | ||
132 | * CyAsHalCBAlloc | ||
133 | * CyAsHalCBFree | ||
134 | * CyAsHalMemSet | ||
135 | * CyAsHalCreateSleepChannel | ||
136 | * CyAsHalDestroySleepChannel | ||
137 | * CyAsHalSleepOn | ||
138 | * CyAsHalWake | ||
139 | * CyAsHalDisableInterrupts | ||
140 | * CyAsHalEnableInterrupts | ||
141 | * CyAsHalSleep150 | ||
142 | * CyAsHalSleep | ||
143 | * CyAsHalAssert | ||
144 | * CyAsHalPrintMessage | ||
145 | * CyAsHalIsPolling | ||
146 | */ | ||
147 | |||
148 | /* Summary | ||
149 | This is the type that represents a sleep channel | ||
150 | |||
151 | Description | ||
152 | A sleep channel is an operating system object that, when a | ||
153 | thread of control waits on the sleep channel, the thread | ||
154 | sleeps until another thread signals the sleep object. This | ||
155 | object is generally used when a high level API is called | ||
156 | and must wait for a response that is supplied in an interrupt | ||
157 | handler. The thread calling the API is put into a sleep | ||
158 | state and when the reply arrives via the interrupt handler, | ||
159 | the interrupt handler wakes the sleeping thread to indicate | ||
160 | that the expect reply is available. | ||
161 | */ | ||
162 | typedef struct cy_as_hal_sleep_channel { | ||
163 | /* This structure is filled in with OS specific information | ||
164 | to implementat a sleep channel */ | ||
165 | int m_channel; | ||
166 | } cy_as_hal_sleep_channel; | ||
167 | |||
168 | /* Summary | ||
169 | This function is called to write a register value | ||
170 | |||
171 | Description | ||
172 | This function is called to write a specific register to a | ||
173 | specific value. The tag identifies the device of interest. | ||
174 | The address is relative to the base address of the West | ||
175 | Bridge device. | ||
176 | |||
177 | Returns | ||
178 | Nothing | ||
179 | |||
180 | See Also | ||
181 | * CyAsHalDeviceTag | ||
182 | * CyAsHalReadRegister | ||
183 | */ | ||
184 | EXTERN void | ||
185 | cy_as_hal_write_register( | ||
186 | /* The tag to ID a specific West Bridge device */ | ||
187 | cy_as_hal_device_tag tag, | ||
188 | /* The address we are writing to */ | ||
189 | uint16_t addr, | ||
190 | /* The value to write to the register */ | ||
191 | uint16_t value | ||
192 | ); | ||
193 | |||
194 | /* Summary | ||
195 | This function is called to read a register value | ||
196 | |||
197 | Description | ||
198 | This function is called to read the contents of a specific | ||
199 | register. The tag identifies the device of interest. The | ||
200 | address is relative to the base address of the West Bridge | ||
201 | device. | ||
202 | |||
203 | Returns | ||
204 | Contents of the register | ||
205 | |||
206 | See Also | ||
207 | * CyAsHalDeviceTag | ||
208 | * CyAsHalWriteRegister | ||
209 | */ | ||
210 | EXTERN uint16_t | ||
211 | cy_as_hal_read_register( | ||
212 | /* The tag to ID a specific West Bridge device */ | ||
213 | cy_as_hal_device_tag tag, | ||
214 | /* The address we are writing to */ | ||
215 | uint16_t addr | ||
216 | ); | ||
217 | |||
218 | /* Summary | ||
219 | This function initiates a DMA write operation to write | ||
220 | to West Bridge | ||
221 | |||
222 | Description | ||
223 | This function initiates a DMA write operation. The request | ||
224 | size will not exceed the value the HAL layer returned via | ||
225 | CyAsHalDmaMaxRequestSize(). This request size may exceed | ||
226 | the size of what the West Bridge device will accept as on | ||
227 | packet and the HAL layer may need to divide the request | ||
228 | into multiple hardware DMA operations. | ||
229 | |||
230 | Returns | ||
231 | None | ||
232 | |||
233 | See Also | ||
234 | * CyAsHalDmaSetupRead | ||
235 | * CyAsHalDmaMaxRequestSize | ||
236 | */ | ||
237 | EXTERN void | ||
238 | cy_as_hal_dma_setup_write( | ||
239 | /* The tag to ID a specific West Bridge device */ | ||
240 | cy_as_hal_device_tag tag, | ||
241 | /* The endpoint we are writing to */ | ||
242 | cy_as_end_point_number_t ep, | ||
243 | /* The data to write via DMA */ | ||
244 | void *buf_p, | ||
245 | /* The size of the data at buf_p */ | ||
246 | uint32_t size, | ||
247 | /* The maximum amount of data that the endpoint | ||
248 | * can accept as one packet */ | ||
249 | uint16_t maxsize | ||
250 | ); | ||
251 | |||
252 | /* Summary | ||
253 | This function initiates a DMA read operation from West Bridge | ||
254 | |||
255 | Description | ||
256 | This function initiates a DMA read operation. The request | ||
257 | size will not exceed the value the HAL layer returned via | ||
258 | CyAsHalDmaMaxRequestSize(). This request size may exceed | ||
259 | the size of what the Anitoch will accept as one packet and | ||
260 | the HAL layer may need to divide the request into multiple | ||
261 | hardware DMA operations. | ||
262 | |||
263 | Returns | ||
264 | None | ||
265 | |||
266 | See Also | ||
267 | * CyAsHalDmaSetupRead | ||
268 | * CyAsHalDmaMaxRequestSize | ||
269 | */ | ||
270 | EXTERN void | ||
271 | cy_as_hal_dma_setup_read( | ||
272 | /* The tag to ID a specific West Bridge device */ | ||
273 | cy_as_hal_device_tag tag, | ||
274 | /* The endpoint we are reading from */ | ||
275 | cy_as_end_point_number_t ep, | ||
276 | /* The buffer to read data into */ | ||
277 | void *buf_p, | ||
278 | /* The amount of data to read */ | ||
279 | uint32_t size, | ||
280 | /* The maximum amount of data that the endpoint | ||
281 | * can provide in one DMA operation */ | ||
282 | uint16_t maxsize | ||
283 | ); | ||
284 | |||
285 | /* Summary | ||
286 | This function cancels a pending DMA request | ||
287 | |||
288 | Description | ||
289 | This function cancels a pending DMA request that has been | ||
290 | passed down to the hardware. The HAL layer can elect to | ||
291 | physically cancel the request if possible, or just ignore | ||
292 | the results of the request if it is not possible. | ||
293 | |||
294 | Returns | ||
295 | None | ||
296 | */ | ||
297 | EXTERN void | ||
298 | cy_as_hal_dma_cancel_request( | ||
299 | /* The tag to ID a specific West Bridge device */ | ||
300 | cy_as_hal_device_tag tag, | ||
301 | /* The endpoint we are reading from */ | ||
302 | cy_as_end_point_number_t ep | ||
303 | ); | ||
304 | |||
305 | /* Summary | ||
306 | This function registers a callback function to be called when | ||
307 | a DMA request is completed | ||
308 | |||
309 | Description | ||
310 | This function registers a callback that is called when a request | ||
311 | issued via CyAsHalDmaSetupWrite() or CyAsHalDmaSetupRead() has | ||
312 | completed. | ||
313 | |||
314 | Returns | ||
315 | None | ||
316 | |||
317 | See Also | ||
318 | * CyAsHalDmaSetupWrite | ||
319 | * CyAsHalDmaSetupRead | ||
320 | */ | ||
321 | EXTERN void | ||
322 | cy_as_hal_dma_register_callback( | ||
323 | /* The tag to ID a specific West Bridge device */ | ||
324 | cy_as_hal_device_tag tag, | ||
325 | /* The callback to call when a request has completed */ | ||
326 | cy_as_hal_dma_complete_callback cb | ||
327 | ); | ||
328 | |||
329 | /* Summary | ||
330 | This function returns the maximum size of a DMA request that can | ||
331 | be handled by the HAL. | ||
332 | |||
333 | Description | ||
334 | When DMA requests are passed to the HAL layer for processing, | ||
335 | the HAL layer may have a limit on the size of the request that | ||
336 | can be handled. This function is called by the DMA manager for | ||
337 | an endpoint when DMA is enabled to get the maximum size of data | ||
338 | the HAL layer can handle. The DMA manager insures that a request | ||
339 | is never sent to the HAL layer that exceeds the size returned by | ||
340 | this function. | ||
341 | |||
342 | Returns | ||
343 | the maximum size of DMA request the HAL layer can handle | ||
344 | */ | ||
345 | EXTERN uint32_t | ||
346 | cy_as_hal_dma_max_request_size( | ||
347 | /* The tag to ID a specific West Bridge device */ | ||
348 | cy_as_hal_device_tag tag, | ||
349 | /* The endpoint of interest */ | ||
350 | cy_as_end_point_number_t ep | ||
351 | ); | ||
352 | |||
353 | /* Summary | ||
354 | This function sets the WAKEUP pin to a specific state on the | ||
355 | West Bridge device. | ||
356 | |||
357 | Description | ||
358 | In order to enter the standby mode, the WAKEUP pin must be | ||
359 | de-asserted. In order to resume from standby mode, the WAKEUP | ||
360 | pin must be asserted. This function provides the mechanism to | ||
361 | do this. | ||
362 | |||
363 | Returns | ||
364 | 1 if the pin was changed, 0 if the HAL layer does not support | ||
365 | changing this pin | ||
366 | */ | ||
367 | EXTERN uint32_t | ||
368 | cy_as_hal_set_wakeup_pin( | ||
369 | /* The tag to ID a specific West Bridge device */ | ||
370 | cy_as_hal_device_tag tag, | ||
371 | /* The desired state of the wakeup pin */ | ||
372 | cy_bool state | ||
373 | ); | ||
374 | |||
375 | /* Summary | ||
376 | Synchronise the West Bridge device clocks to re-establish device | ||
377 | connectivity. | ||
378 | |||
379 | Description | ||
380 | When the Astoria bridge device is working in SPI mode, a long | ||
381 | period of inactivity can cause a loss of serial synchronisation | ||
382 | between the processor and Astoria. This function is called by | ||
383 | the API when it detects such a condition, and is expected to take | ||
384 | the action required to re-establish clock synchronisation between | ||
385 | the devices. | ||
386 | |||
387 | Returns | ||
388 | CyTrue if the attempt to re-synchronise is successful, | ||
389 | CyFalse if not. | ||
390 | */ | ||
391 | EXTERN cy_bool | ||
392 | cy_as_hal_sync_device_clocks( | ||
393 | /* The tag to ID a specific West Bridge device */ | ||
394 | cy_as_hal_device_tag tag, | ||
395 | ); | ||
396 | |||
397 | /* Summary | ||
398 | Initialize West Bridge device registers that may have been | ||
399 | modified while the device was in standby. | ||
400 | |||
401 | Description | ||
402 | The content of some West Bridge registers may be lost when | ||
403 | the device is placed in standby mode. This function restores | ||
404 | these register contents so that the device can continue to | ||
405 | function normally after it wakes up from standby mode. | ||
406 | |||
407 | This function is required to perform operations only when the | ||
408 | API is being used with the Astoria device in one of the PNAND | ||
409 | modes or in the PSPI mode. It can be a no-operation in all | ||
410 | other cases. | ||
411 | |||
412 | Returns | ||
413 | None | ||
414 | */ | ||
415 | EXTERN void | ||
416 | cy_as_hal_init_dev_registers( | ||
417 | /* The tag to ID a specific West Bridge device */ | ||
418 | cy_as_hal_device_tag tag, | ||
419 | /* Indicates whether this is a wake-up from standby. */ | ||
420 | cy_bool is_standby_wakeup | ||
421 | ); | ||
422 | |||
423 | /* Summary | ||
424 | This function reads a set of P-port accessible device registers and | ||
425 | stores their value for later use. | ||
426 | |||
427 | Description | ||
428 | The West Bridge Astoria device silicon has a known problem when | ||
429 | operating in SPI mode on the P-port, where some of the device | ||
430 | registers lose their value when the device goes in and out of | ||
431 | standby mode. The suggested work-around is to reset the Astoria | ||
432 | device as part of the wakeup procedure from standby. | ||
433 | |||
434 | This requires that the values of some of the P-port accessible | ||
435 | registers be restored to their pre-standby values after it has | ||
436 | been reset. This HAL function can be used to read and store | ||
437 | the values of these registers at the point where the device is | ||
438 | being placed in standby mode. | ||
439 | |||
440 | Returns | ||
441 | None | ||
442 | |||
443 | See Also | ||
444 | * CyAsHalRestoreRegsAfterStandby | ||
445 | */ | ||
446 | EXTERN void | ||
447 | cy_as_hal_read_regs_before_standby( | ||
448 | /* The tag to ID a specific West Bridge device */ | ||
449 | cy_as_hal_device_tag tag | ||
450 | ); | ||
451 | |||
452 | /* Summary | ||
453 | This function restores the old values to a set of P-port | ||
454 | accessible device registers. | ||
455 | |||
456 | Description | ||
457 | This function is part of the work-around to a known West | ||
458 | Bridge Astoria device error when operating in SPI mode on | ||
459 | the P-port. This function is used to restore a set of | ||
460 | P-port accessible registers to the values they had before | ||
461 | the device was placed in standby mode. | ||
462 | |||
463 | Returns | ||
464 | None | ||
465 | |||
466 | See Also | ||
467 | * CyAsHalRestoreRegsAfterStandby | ||
468 | */ | ||
469 | EXTERN void | ||
470 | cy_as_hal_restore_regs_after_standby( | ||
471 | /* The tag to ID a specific West Bridge device */ | ||
472 | cy_as_hal_device_tag tag | ||
473 | ); | ||
474 | |||
475 | /* | ||
476 | * The functions below this comment are part of the HAL layer, | ||
477 | * as the HAL layer consists of the abstraction to both the | ||
478 | * hardware platform and the operating system. However; the | ||
479 | * functions below this comment all relate to the operating | ||
480 | * environment and not specifically to the hardware platform | ||
481 | * or specific device. | ||
482 | */ | ||
483 | |||
484 | /* Summary | ||
485 | This function allocates a block of memory | ||
486 | |||
487 | Description | ||
488 | This is the HAL layer equivalent of the malloc() function. | ||
489 | |||
490 | Returns | ||
491 | a pointer to a block of memory | ||
492 | |||
493 | See Also | ||
494 | * CyAsHalFree | ||
495 | */ | ||
496 | EXTERN void * | ||
497 | cy_as_hal_alloc( | ||
498 | /* The size of the memory block to allocate */ | ||
499 | uint32_t size | ||
500 | ); | ||
501 | |||
502 | /* Summary | ||
503 | This function frees a previously allocated block of memory | ||
504 | |||
505 | Description | ||
506 | This is the HAL layer equivalent of the free() function. | ||
507 | |||
508 | Returns | ||
509 | None | ||
510 | |||
511 | See Also | ||
512 | * CyAsHalAlloc | ||
513 | */ | ||
514 | EXTERN void | ||
515 | cy_as_hal_free( | ||
516 | /* Pointer to a memory block to free */ | ||
517 | void *ptr | ||
518 | ); | ||
519 | |||
520 | /* Summary | ||
521 | This function is a malloc equivalent that can be used from an | ||
522 | interrupt context. | ||
523 | |||
524 | Description | ||
525 | This function is a malloc equivalent that will be called from the | ||
526 | API in callbacks. This function is required to be able to provide | ||
527 | memory in interrupt context. | ||
528 | |||
529 | Notes | ||
530 | For platforms where it is not possible to allocate memory in interrupt | ||
531 | context, we provide a reference allocator that takes memory during | ||
532 | initialization and implements malloc/free using this memory. | ||
533 | See the <install>/api/hal/fpga/cyashalblkalloc.[ch] files for the | ||
534 | implementation, and the <install>/api/hal/fpga/cyashalfpga.c file | ||
535 | for an example of the use of this allocator. | ||
536 | |||
537 | Returns | ||
538 | A pointer to the allocated block of memory | ||
539 | |||
540 | See Also | ||
541 | * CyAsHalCBFree | ||
542 | * CyAsHalAlloc | ||
543 | */ | ||
544 | EXTERN void * | ||
545 | cy_as_hal_c_b_alloc( | ||
546 | /* The size of the memory block to allocate */ | ||
547 | uint32_t size | ||
548 | ); | ||
549 | |||
550 | /* Summary | ||
551 | This function frees the memory allocated through the CyAsHalCBAlloc | ||
552 | call. | ||
553 | |||
554 | Description | ||
555 | This function frees memory allocated through the CyAsHalCBAlloc | ||
556 | call, and is also required to support calls from interrupt | ||
557 | context. | ||
558 | |||
559 | Returns | ||
560 | None | ||
561 | |||
562 | See Also | ||
563 | * CyAsHalCBAlloc | ||
564 | * CyAsHalFree | ||
565 | */ | ||
566 | EXTERN void | ||
567 | cy_as_hal_c_b_free( | ||
568 | /* Pointer to the memory block to be freed */ | ||
569 | void *ptr | ||
570 | ); | ||
571 | |||
572 | /* Summary | ||
573 | This function sets a block of memory to a specific value | ||
574 | |||
575 | Description | ||
576 | This function is the HAL layer equivalent of the memset() function. | ||
577 | |||
578 | Returns | ||
579 | None | ||
580 | */ | ||
581 | EXTERN void | ||
582 | cy_as_mem_set( | ||
583 | /* A pointer to a block of memory to set */ | ||
584 | void *ptr, | ||
585 | /* The value to set the memory to */ | ||
586 | uint8_t value, | ||
587 | /* The number of bytes to set */ | ||
588 | uint32_t cnt | ||
589 | ); | ||
590 | |||
591 | /* Summary | ||
592 | This function creates or initializes a sleep channel | ||
593 | |||
594 | Description | ||
595 | This function creates or initializes a sleep channel. The | ||
596 | sleep channel defined using the HAL data structure | ||
597 | CyAsHalSleepChannel. | ||
598 | |||
599 | Returns | ||
600 | CyTrue is the initialization was successful, and CyFalse otherwise | ||
601 | |||
602 | See Also | ||
603 | * CyAsHalSleepChannel | ||
604 | * CyAsHalDestroySleepChannel | ||
605 | * CyAsHalSleepOn | ||
606 | * CyAsHalWake | ||
607 | */ | ||
608 | EXTERN cy_bool | ||
609 | cy_as_hal_create_sleep_channel( | ||
610 | /* Pointer to the sleep channel to create/initialize */ | ||
611 | cy_as_hal_sleep_channel *chan | ||
612 | ); | ||
613 | |||
614 | /* Summary | ||
615 | This function destroys an existing sleep channel | ||
616 | |||
617 | Description | ||
618 | This function destroys an existing sleep channel. The sleep channel | ||
619 | is of type CyAsHalSleepChannel. | ||
620 | |||
621 | Returns | ||
622 | CyTrue if the channel was destroyed, and CyFalse otherwise | ||
623 | |||
624 | See Also | ||
625 | * CyAsHalSleepChannel | ||
626 | * CyAsHalCreateSleepChannel | ||
627 | * CyAsHalSleepOn | ||
628 | * CyAsHalWake | ||
629 | */ | ||
630 | EXTERN cy_bool | ||
631 | cy_as_hal_destroy_sleep_channel( | ||
632 | /* The sleep channel to destroy */ | ||
633 | cy_as_hal_sleep_channel chan | ||
634 | ); | ||
635 | |||
636 | /* Summary | ||
637 | This function causes the calling process or thread to sleep until | ||
638 | CyAsHalWake() is called | ||
639 | |||
640 | Description | ||
641 | This function causes the calling process or threadvto sleep. | ||
642 | When CyAsHalWake() is called on the same sleep channel, this | ||
643 | processes or thread is then wakened and allowed to run | ||
644 | |||
645 | Returns | ||
646 | CyTrue if the thread or process is asleep, and CyFalse otherwise | ||
647 | |||
648 | See Also | ||
649 | * CyAsHalSleepChannel | ||
650 | * CyAsHalWake | ||
651 | */ | ||
652 | EXTERN cy_bool | ||
653 | cy_as_hal_sleep_on( | ||
654 | /* The sleep channel to sleep on */ | ||
655 | cy_as_hal_sleep_channel chan, | ||
656 | /* The maximum time to sleep in milli-seconds */ | ||
657 | uint32_t ms | ||
658 | ); | ||
659 | |||
660 | /* Summary | ||
661 | This function casues the process or thread sleeping on the given | ||
662 | sleep channel to wake | ||
663 | |||
664 | Description | ||
665 | This function causes the process or thread sleeping on the given | ||
666 | sleep channel to wake. The channel | ||
667 | |||
668 | Returns | ||
669 | CyTrue if the thread or process is awake, and CyFalse otherwise | ||
670 | |||
671 | See Also | ||
672 | * CyAsHalSleepChannel | ||
673 | * CyAsHalSleepOn | ||
674 | */ | ||
675 | EXTERN cy_bool | ||
676 | cy_as_hal_wake( | ||
677 | /* The sleep channel to wake */ | ||
678 | cy_as_hal_sleep_channel chan | ||
679 | ); | ||
680 | |||
681 | /* Summary | ||
682 | This function disables interrupts, insuring that short bursts | ||
683 | of code can be run without danger of interrupt handlers running. | ||
684 | |||
685 | Description | ||
686 | There are cases within the API when lists must be manipulated by | ||
687 | both the API and the associated interrupt handlers. In these | ||
688 | cases, interrupts must be disabled to insure the integrity of the | ||
689 | list during the modification. This function is used to disable | ||
690 | interrupts during the short intervals where these lists are being | ||
691 | changed. | ||
692 | |||
693 | The HAL must have the ability to nest calls to | ||
694 | CyAsHalDisableInterrupts and CyAsHalEnableInterrupts. | ||
695 | |||
696 | Returns | ||
697 | Any interrupt related state value which will be passed back into | ||
698 | the subsequent CyAsHalEnableInterrupts call. | ||
699 | |||
700 | See Also | ||
701 | * CyAsHalEnableInterrupts | ||
702 | */ | ||
703 | EXTERN uint32_t | ||
704 | cy_as_hal_disable_interrupts(); | ||
705 | |||
706 | /* Summary | ||
707 | This function re-enables interrupts after a critical section of | ||
708 | code in the API has been completed. | ||
709 | |||
710 | Description | ||
711 | There are cases within the API when lists must be manipulated by | ||
712 | both the API and the associated interrupt handlers. In these | ||
713 | cases, interrupts must be disabled to insure the integrity of the | ||
714 | list during the modification. This function is used to enable | ||
715 | interrupts after the short intervals where these lists are being | ||
716 | changed. | ||
717 | |||
718 | See Also | ||
719 | * CyAsHalDisableInterrupts | ||
720 | */ | ||
721 | EXTERN void | ||
722 | cy_as_hal_enable_interrupts( | ||
723 | /* Value returned by the previous CyAsHalDisableInterrupts call. */ | ||
724 | uint32_t value | ||
725 | ); | ||
726 | |||
727 | /* Summary | ||
728 | This function sleeps for 150 ns. | ||
729 | |||
730 | Description | ||
731 | This function sleeps for 150 ns before allowing the calling function | ||
732 | to continue. This function is used for a specific purpose and the | ||
733 | sleep required is at least 150 ns. | ||
734 | */ | ||
735 | EXTERN void | ||
736 | cy_as_hal_sleep150( | ||
737 | ); | ||
738 | |||
739 | /* Summary | ||
740 | This function sleeps for the given number of milliseconds | ||
741 | |||
742 | Description | ||
743 | This function sleeps for at least the given number of milliseonds | ||
744 | */ | ||
745 | EXTERN void | ||
746 | cy_as_hal_sleep( | ||
747 | uint32_t ms | ||
748 | ); | ||
749 | |||
750 | /* Summary | ||
751 | This function asserts when the condition evaluates to zero | ||
752 | |||
753 | Description | ||
754 | Within the API there are conditions which are checked to insure | ||
755 | the integrity of the code. These conditions are checked only | ||
756 | within a DEBUG build. This function is used to check the condition | ||
757 | and if the result evaluates to zero, it should be considered a | ||
758 | fatal error that should be reported to Cypress. | ||
759 | */ | ||
760 | EXTERN void | ||
761 | cy_as_hal_assert( | ||
762 | /* The condition to evaluate */ | ||
763 | cy_bool cond | ||
764 | ); | ||
765 | |||
766 | /* Summary | ||
767 | This function prints a message from the API to a human readable device | ||
768 | |||
769 | Description | ||
770 | There are places within the West Bridge API where printing a message | ||
771 | is useful to the debug process. This function provides the mechanism | ||
772 | to print a message. | ||
773 | |||
774 | Returns | ||
775 | NONE | ||
776 | */ | ||
777 | EXTERN void | ||
778 | cy_as_hal_print_message( | ||
779 | /* The message to print */ | ||
780 | const char *fmt_p, | ||
781 | ... /* Variable arguments */ | ||
782 | ); | ||
783 | |||
784 | /* Summary | ||
785 | This function reports whether the HAL implementation uses | ||
786 | polling to service data coming from the West Bridge. | ||
787 | |||
788 | Description | ||
789 | This function reports whether the HAL implementation uses | ||
790 | polling to service data coming from the West Bridge. | ||
791 | |||
792 | Returns | ||
793 | CyTrue if the HAL polls the West Bridge Interrupt Status registers | ||
794 | to complete operations, CyFalse if the HAL is interrupt driven. | ||
795 | */ | ||
796 | EXTERN cy_bool | ||
797 | cy_as_hal_is_polling( | ||
798 | void); | ||
799 | |||
800 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasintr.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasintr.h deleted file mode 100644 index 60a6fffb5d53..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasintr.h +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasintr.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASINTR_H_ | ||
23 | #define _INCLUDED_CYASINTR_H_ | ||
24 | |||
25 | #include "cyasdevice.h" | ||
26 | |||
27 | #include "cyas_cplus_start.h" | ||
28 | |||
29 | /* Summary | ||
30 | Initialize the interrupt manager module | ||
31 | |||
32 | Description | ||
33 | This function is called to initialize the interrupt module. | ||
34 | This module enables interrupts as well as servies West Bridge | ||
35 | related interrupts by determining the source of the interrupt | ||
36 | and calling the appropriate handler function. | ||
37 | |||
38 | Notes | ||
39 | If the dmaintr parameter is TRUE, the initialization code | ||
40 | initializes the interrupt mask to have the DMA related interrupt | ||
41 | enabled via the general purpose interrupt. However, the interrupt | ||
42 | service function assumes that the DMA interrupt is handled by the | ||
43 | HAL layer before the interrupt module handler function is called. | ||
44 | |||
45 | Returns | ||
46 | * CY_AS_ERROR_SUCCESS - the interrupt module was initialized | ||
47 | * correctly | ||
48 | * CY_AS_ERROR_ALREADY_RUNNING - the interrupt module was already | ||
49 | * started | ||
50 | |||
51 | See Also | ||
52 | * CyAsIntrStop | ||
53 | * CyAsServiceInterrupt | ||
54 | */ | ||
55 | cy_as_return_status_t | ||
56 | cy_as_intr_start( | ||
57 | /* Device being initialized */ | ||
58 | cy_as_device *dev_p, | ||
59 | /* If true, enable the DMA interrupt through the INT signal */ | ||
60 | cy_bool dmaintr | ||
61 | ); | ||
62 | |||
63 | /* Summary | ||
64 | Stop the interrupt manager module | ||
65 | |||
66 | Description | ||
67 | This function stops the interrupt module and masks all interrupts | ||
68 | from the West Bridge device. | ||
69 | |||
70 | Returns | ||
71 | * CY_AS_ERROR_SUCCESS - the interrupt module was stopped | ||
72 | * successfully | ||
73 | * CY_AS_ERROR_NOT_RUNNING - the interrupt module was not | ||
74 | * running | ||
75 | |||
76 | See Also | ||
77 | * CyAsIntrStart | ||
78 | * CyAsServiceInterrupt | ||
79 | */ | ||
80 | cy_as_return_status_t | ||
81 | cy_as_intr_stop( | ||
82 | /* Device bein stopped */ | ||
83 | cy_as_device *dev_p | ||
84 | ); | ||
85 | |||
86 | |||
87 | /* Summary | ||
88 | The interrupt service routine for West Bridge | ||
89 | |||
90 | Description | ||
91 | When an interrupt is detected, this function is called to | ||
92 | service the West Bridge interrupt. It is safe and efficient | ||
93 | for this function to be called when no West Bridge interrupt | ||
94 | has occurred. This function will determine it is not an West | ||
95 | Bridge interrupt quickly and return. | ||
96 | */ | ||
97 | void cy_as_intr_service_interrupt( | ||
98 | /* The USER supplied tag for this device */ | ||
99 | cy_as_hal_device_tag tag | ||
100 | ); | ||
101 | |||
102 | #include "cyas_cplus_end.h" | ||
103 | |||
104 | #endif /* _INCLUDED_CYASINTR_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslep2pep.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslep2pep.h deleted file mode 100644 index 6626cc454743..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslep2pep.h +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyaslep2pep.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASLEP2PEP_H_ | ||
23 | #define _INCLUDED_CYASLEP2PEP_H_ | ||
24 | |||
25 | #include "cyasdevice.h" | ||
26 | |||
27 | extern cy_as_return_status_t | ||
28 | cy_as_usb_map_logical2_physical(cy_as_device *dev_p); | ||
29 | |||
30 | extern cy_as_return_status_t | ||
31 | cy_as_usb_setup_dma(cy_as_device *dev_p); | ||
32 | |||
33 | extern cy_as_return_status_t | ||
34 | cy_as_usb_set_dma_sizes(cy_as_device *dev_p); | ||
35 | |||
36 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslowlevel.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslowlevel.h deleted file mode 100644 index 5c7972f91ef6..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyaslowlevel.h +++ /dev/null | |||
@@ -1,366 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyaslowlevel.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASLOWLEVEL_H_ | ||
23 | #define _INCLUDED_CYASLOWLEVEL_H_ | ||
24 | |||
25 | /*@@Low Level Communications | ||
26 | |||
27 | Summary | ||
28 | The low level communications module is responsible for | ||
29 | communications between the West Bridge device and the P | ||
30 | port processor. Communications is organized as a series | ||
31 | of requests and subsequent responses. For each request | ||
32 | there is a one and only one response. Requests may go | ||
33 | from the West Bridge device to the P port processor, or | ||
34 | from the P Port processor to the West Bridge device. | ||
35 | |||
36 | Description | ||
37 | Requests are issued across what is called a context. A | ||
38 | context is a single channel of communications from one | ||
39 | processor to another processor. There can be only a single | ||
40 | request outstanding on a context at a given time. Contexts | ||
41 | are used to identify subsystems that can only process a | ||
42 | single request at a time, but are independent of other | ||
43 | contexts in the system. For instance, there is a context | ||
44 | for communicating storage commands from the P port processor | ||
45 | to the West Bridge device. There is also a context for | ||
46 | communicating USB commands from the P port processor to the | ||
47 | West Bridge device. | ||
48 | |||
49 | Requests and responses are identical with the exception of | ||
50 | the type bit in the request/response header. If the type | ||
51 | bit is one, the packet is a request. If this bit is zero, | ||
52 | the packet is a response. Also encoded within the header of | ||
53 | the request/response is the code. The code is a command | ||
54 | code for a request, or a response code for a response. For | ||
55 | a request, the code is a function of the context. The code | ||
56 | 0 has one meaning for the storage context and a different | ||
57 | meaning for the USB context. The code is treated differently | ||
58 | in the response. If the code in the response is less than 16, | ||
59 | then the meaning of the response is global across all | ||
60 | contexts. If the response is greater than or equal to 16, | ||
61 | then the response is specific to the associated context. | ||
62 | |||
63 | Requests and responses are transferred between processors | ||
64 | through the mailbox registers. It may take one or more cycles | ||
65 | to transmit a complete request or response. The context is | ||
66 | encoded into each cycle of the transfer to insure the | ||
67 | receiving processor can route the data to the appropriate | ||
68 | context for processing. In this way, the traffic from multiple | ||
69 | contexts can be multiplexed into a single data stream through | ||
70 | the mailbox registers by the sending processor, and | ||
71 | demultiplexed from the mailbox registers by the receiving | ||
72 | processor. | ||
73 | |||
74 | * Firmware Assumptions * | ||
75 | The firmware assumes that mailbox contents will be consumed | ||
76 | immediately. Therefore for multi-cycle packets, the data is | ||
77 | sent in a tight polling loop from the firmware. This implies | ||
78 | that the data must be read from the mailbox register on the P | ||
79 | port side and processed immediately or performance of the | ||
80 | firmware will suffer. In order to insure this is the case, | ||
81 | the data from the mailboxes is read and stored immediately | ||
82 | in a per context buffer. This occurs until the entire packet | ||
83 | is received at which time the request packet is processed. | ||
84 | Since the protocol is designed to allow for only one | ||
85 | outstanding packet at a time, the firmware can never be in a | ||
86 | position of waiting on the mailbox registers while the P port | ||
87 | is processing a request. Only after the response to the | ||
88 | previous request is sent will another request be sent. | ||
89 | */ | ||
90 | |||
91 | #include "cyashal.h" | ||
92 | #include "cyasdevice.h" | ||
93 | |||
94 | #include "cyas_cplus_start.h" | ||
95 | |||
96 | /* | ||
97 | * Constants | ||
98 | */ | ||
99 | #define CY_AS_REQUEST_RESPONSE_CODE_MASK (0x00ff) | ||
100 | #define CY_AS_REQUEST_RESPONSE_CONTEXT_MASK (0x0F00) | ||
101 | #define CY_AS_REQUEST_RESPONSE_CONTEXT_SHIFT (8) | ||
102 | #define CY_AS_REQUEST_RESPONSE_TYPE_MASK (0x4000) | ||
103 | #define CY_AS_REQUEST_RESPONSE_LAST_MASK (0x8000) | ||
104 | #define CY_AS_REQUEST_RESPONSE_CLEAR_STR_FLAG (0x1000) | ||
105 | |||
106 | /* | ||
107 | * These macros extract the data from a 16 bit value | ||
108 | */ | ||
109 | #define cy_as_mbox_get_code(c) \ | ||
110 | ((uint8_t)((c) & CY_AS_REQUEST_RESPONSE_CODE_MASK)) | ||
111 | #define cy_as_mbox_get_context(c) \ | ||
112 | ((uint8_t)(((c) & CY_AS_REQUEST_RESPONSE_CONTEXT_MASK) \ | ||
113 | >> CY_AS_REQUEST_RESPONSE_CONTEXT_SHIFT)) | ||
114 | #define cy_as_mbox_is_last(c) \ | ||
115 | ((c) & CY_AS_REQUEST_RESPONSE_LAST_MASK) | ||
116 | #define cy_as_mbox_is_request(c) \ | ||
117 | (((c) & CY_AS_REQUEST_RESPONSE_TYPE_MASK) != 0) | ||
118 | #define cy_as_mbox_is_response(c) \ | ||
119 | (((c) & CY_AS_REQUEST_RESPONSE_TYPE_MASK) == 0) | ||
120 | |||
121 | /* | ||
122 | * These macros (not yet written) pack data into or extract data | ||
123 | * from the m_box0 field of the request or response | ||
124 | */ | ||
125 | #define cy_as_ll_request_response__set_code(req, code) \ | ||
126 | ((req)->box0 = \ | ||
127 | ((req)->box0 & ~CY_AS_REQUEST_RESPONSE_CODE_MASK) | \ | ||
128 | (code & CY_AS_REQUEST_RESPONSE_CODE_MASK)) | ||
129 | |||
130 | #define cy_as_ll_request_response__get_code(req) \ | ||
131 | cy_as_mbox_get_code((req)->box0) | ||
132 | |||
133 | #define cy_as_ll_request_response__set_context(req, context) \ | ||
134 | ((req)->box0 |= ((context) << \ | ||
135 | CY_AS_REQUEST_RESPONSE_CONTEXT_SHIFT)) | ||
136 | |||
137 | #define cy_as_ll_request_response__set_clear_storage_flag(req) \ | ||
138 | ((req)->box0 |= CY_AS_REQUEST_RESPONSE_CLEAR_STR_FLAG) | ||
139 | |||
140 | #define cy_as_ll_request_response__get_context(req) \ | ||
141 | cy_as_mbox_get_context((req)->box0) | ||
142 | |||
143 | #define cy_as_ll_request_response__is_last(req) \ | ||
144 | cy_as_mbox_is_last((req)->box0) | ||
145 | |||
146 | #define CY_an_ll_request_response___set_last(req) \ | ||
147 | ((req)->box0 |= CY_AS_REQUEST_RESPONSE_LAST_MASK) | ||
148 | |||
149 | #define cy_as_ll_request_response__is_request(req) \ | ||
150 | cy_as_mbox_is_request((req)->box0) | ||
151 | |||
152 | #define cy_as_ll_request_response__set_request(req) \ | ||
153 | ((req)->box0 |= CY_AS_REQUEST_RESPONSE_TYPE_MASK) | ||
154 | |||
155 | #define cy_as_ll_request_response__set_response(req) \ | ||
156 | ((req)->box0 &= ~CY_AS_REQUEST_RESPONSE_TYPE_MASK) | ||
157 | |||
158 | #define cy_as_ll_request_response__is_response(req) \ | ||
159 | cy_as_mbox_is_response((req)->box0) | ||
160 | |||
161 | #define cy_as_ll_request_response__get_word(req, offset) \ | ||
162 | ((req)->data[(offset)]) | ||
163 | |||
164 | #define cy_as_ll_request_response__set_word(req, offset, \ | ||
165 | value) ((req)->data[(offset)] = value) | ||
166 | |||
167 | typedef enum cy_as_remove_request_result_t { | ||
168 | cy_as_remove_request_sucessful, | ||
169 | cy_as_remove_request_in_transit, | ||
170 | cy_as_remove_request_not_found | ||
171 | } cy_as_remove_request_result_t; | ||
172 | |||
173 | /* Summary | ||
174 | Start the low level communications module | ||
175 | |||
176 | Description | ||
177 | */ | ||
178 | cy_as_return_status_t | ||
179 | cy_as_ll_start( | ||
180 | cy_as_device *dev_p | ||
181 | ); | ||
182 | |||
183 | cy_as_return_status_t | ||
184 | cy_as_ll_stop( | ||
185 | cy_as_device *dev_p | ||
186 | ); | ||
187 | |||
188 | |||
189 | cy_as_ll_request_response * | ||
190 | cy_as_ll_create_request( | ||
191 | cy_as_device *dev_p, | ||
192 | uint16_t code, | ||
193 | uint8_t context, | ||
194 | /* Length of the request in 16 bit words */ | ||
195 | uint16_t length | ||
196 | ); | ||
197 | |||
198 | void | ||
199 | cy_as_ll_init_request( | ||
200 | cy_as_ll_request_response *req_p, | ||
201 | uint16_t code, | ||
202 | uint16_t context, | ||
203 | uint16_t length); | ||
204 | |||
205 | void | ||
206 | cy_as_ll_init_response( | ||
207 | cy_as_ll_request_response *req_p, | ||
208 | uint16_t length); | ||
209 | |||
210 | void | ||
211 | cy_as_ll_destroy_request( | ||
212 | cy_as_device *dev_p, | ||
213 | cy_as_ll_request_response *); | ||
214 | |||
215 | cy_as_ll_request_response * | ||
216 | cy_as_ll_create_response( | ||
217 | cy_as_device *dev_p, | ||
218 | /* Length of the request in 16 bit words */ | ||
219 | uint16_t length | ||
220 | ); | ||
221 | |||
222 | cy_as_remove_request_result_t | ||
223 | cy_as_ll_remove_request( | ||
224 | cy_as_device *dev_p, | ||
225 | cy_as_context *ctxt_p, | ||
226 | cy_as_ll_request_response *req_p, | ||
227 | cy_bool force | ||
228 | ); | ||
229 | void | ||
230 | cy_as_ll_remove_all_requests(cy_as_device *dev_p, | ||
231 | cy_as_context *ctxt_p); | ||
232 | |||
233 | void | ||
234 | cy_as_ll_destroy_response( | ||
235 | cy_as_device *dev_p, | ||
236 | cy_as_ll_request_response *); | ||
237 | |||
238 | cy_as_return_status_t | ||
239 | cy_as_ll_send_request( | ||
240 | /* The West Bridge device */ | ||
241 | cy_as_device *dev_p, | ||
242 | /* The request to send */ | ||
243 | cy_as_ll_request_response *req, | ||
244 | /* Storage for a reply, must be sure it is of sufficient size */ | ||
245 | cy_as_ll_request_response *resp, | ||
246 | /* If true, this is a sync request */ | ||
247 | cy_bool sync, | ||
248 | /* Callback to call when reply is received */ | ||
249 | cy_as_response_callback cb | ||
250 | ); | ||
251 | |||
252 | cy_as_return_status_t | ||
253 | cy_as_ll_send_request_wait_reply( | ||
254 | /* The West Bridge device */ | ||
255 | cy_as_device *dev_p, | ||
256 | /* The request to send */ | ||
257 | cy_as_ll_request_response *req, | ||
258 | /* Storage for a reply, must be sure it is of sufficient size */ | ||
259 | cy_as_ll_request_response *resp | ||
260 | ); | ||
261 | |||
262 | /* Summary | ||
263 | This function registers a callback function to be called when a | ||
264 | request arrives on a given context. | ||
265 | |||
266 | Description | ||
267 | |||
268 | Returns | ||
269 | * CY_AS_ERROR_SUCCESS | ||
270 | */ | ||
271 | extern cy_as_return_status_t | ||
272 | cy_as_ll_register_request_callback( | ||
273 | cy_as_device *dev_p, | ||
274 | uint8_t context, | ||
275 | cy_as_response_callback cb | ||
276 | ); | ||
277 | |||
278 | /* Summary | ||
279 | This function packs a set of bytes given by the data_p pointer | ||
280 | into a request, reply structure. | ||
281 | */ | ||
282 | extern void | ||
283 | cy_as_ll_request_response__pack( | ||
284 | /* The destintation request or response */ | ||
285 | cy_as_ll_request_response *req, | ||
286 | /* The offset of where to pack the data */ | ||
287 | uint32_t offset, | ||
288 | /* The length of the data to pack in bytes */ | ||
289 | uint32_t length, | ||
290 | /* The data to pack */ | ||
291 | void *data_p | ||
292 | ); | ||
293 | |||
294 | /* Summary | ||
295 | This function unpacks a set of bytes from a request/reply | ||
296 | structure into a segment of memory given by the data_p pointer. | ||
297 | */ | ||
298 | extern void | ||
299 | cy_as_ll_request_response__unpack( | ||
300 | /* The source of the data to unpack */ | ||
301 | cy_as_ll_request_response *req, | ||
302 | /* The offset of the data to unpack */ | ||
303 | uint32_t offset, | ||
304 | /* The length of the data to unpack in bytes */ | ||
305 | uint32_t length, | ||
306 | /* The destination of the unpack operation */ | ||
307 | void *data_p | ||
308 | ); | ||
309 | |||
310 | /* Summary | ||
311 | This function sends a status response back to the West Bridge | ||
312 | device in response to a previously send request | ||
313 | */ | ||
314 | extern cy_as_return_status_t | ||
315 | cy_as_ll_send_status_response( | ||
316 | /* The West Bridge device */ | ||
317 | cy_as_device *dev_p, | ||
318 | /* The context to send the response on */ | ||
319 | uint8_t context, | ||
320 | /* The success/failure code to send */ | ||
321 | uint16_t code, | ||
322 | /* Flag to clear wait on storage context */ | ||
323 | uint8_t clear_storage); | ||
324 | |||
325 | /* Summary | ||
326 | This function sends a response back to the West Bridge device. | ||
327 | |||
328 | Description | ||
329 | This function sends a response back to the West Bridge device. | ||
330 | The response is sent on the context given by the 'context' | ||
331 | variable. The code for the response is given by the 'code' | ||
332 | argument. The data for the response is given by the data and | ||
333 | length arguments. | ||
334 | */ | ||
335 | extern cy_as_return_status_t | ||
336 | cy_as_ll_send_data_response( | ||
337 | /* The West Bridge device */ | ||
338 | cy_as_device *dev_p, | ||
339 | /* The context to send the response on */ | ||
340 | uint8_t context, | ||
341 | /* The response code to use */ | ||
342 | uint16_t code, | ||
343 | /* The length of the data for the response */ | ||
344 | uint16_t length, | ||
345 | /* The data for the response */ | ||
346 | void *data | ||
347 | ); | ||
348 | |||
349 | /* Summary | ||
350 | This function removes any requests of the given type | ||
351 | from the given context. | ||
352 | |||
353 | Description | ||
354 | This function removes requests of a given type from the | ||
355 | context given via the context number. | ||
356 | */ | ||
357 | extern cy_as_return_status_t | ||
358 | cy_as_ll_remove_ep_data_requests( | ||
359 | /* The West Bridge device */ | ||
360 | cy_as_device *dev_p, | ||
361 | cy_as_end_point_number_t ep | ||
362 | ); | ||
363 | |||
364 | #include "cyas_cplus_end.h" | ||
365 | |||
366 | #endif /* _INCLUDED_CYASLOWLEVEL_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmedia.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmedia.h deleted file mode 100644 index 0e25ea94481f..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmedia.h +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasmedia.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASMEDIA_H_ | ||
23 | #define _INCLUDED_CYASMEDIA_H_ | ||
24 | |||
25 | #include "cyas_cplus_start.h" | ||
26 | |||
27 | |||
28 | /* Summary | ||
29 | Specifies a specific type of media supported by West Bridge | ||
30 | |||
31 | Description | ||
32 | The West Bridge device supports five specific types of media | ||
33 | as storage/IO devices attached to it's S-Port. This type is | ||
34 | used to indicate the type of media being referenced in any | ||
35 | API call. | ||
36 | */ | ||
37 | typedef enum cy_as_media_type { | ||
38 | /* Flash NAND memory (may be SLC or MLC) */ | ||
39 | cy_as_media_nand = 0x00, | ||
40 | /* An SD flash memory device */ | ||
41 | cy_as_media_sd_flash = 0x01, | ||
42 | /* An MMC flash memory device */ | ||
43 | cy_as_media_mmc_flash = 0x02, | ||
44 | /* A CE-ATA disk drive */ | ||
45 | cy_as_media_ce_ata = 0x03, | ||
46 | /* SDIO device. */ | ||
47 | cy_as_media_sdio = 0x04, | ||
48 | cy_as_media_max_media_value = 0x05 | ||
49 | |||
50 | } cy_as_media_type; | ||
51 | |||
52 | #include "cyas_cplus_end.h" | ||
53 | |||
54 | #endif /* _INCLUDED_CYASMEDIA_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc.h deleted file mode 100644 index df7c2b66cf27..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc.h +++ /dev/null | |||
@@ -1,1549 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasmisc.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASMISC_H_ | ||
23 | #define _INCLUDED_CYASMISC_H_ | ||
24 | |||
25 | #include "cyashal.h" | ||
26 | #include "cyastypes.h" | ||
27 | #include "cyasmedia.h" | ||
28 | |||
29 | #include "cyas_cplus_start.h" | ||
30 | |||
31 | #define CY_AS_LEAVE_STANDBY_DELAY_CLOCK (1) | ||
32 | #define CY_AS_RESET_DELAY_CLOCK (1) | ||
33 | |||
34 | #define CY_AS_LEAVE_STANDBY_DELAY_CRYSTAL (5) | ||
35 | #define CY_AS_RESET_DELAY_CRYSTAL (5) | ||
36 | |||
37 | /* The maximum number of buses supported */ | ||
38 | #define CY_AS_MAX_BUSES (2) | ||
39 | |||
40 | /* The maximum number of storage devices supported per bus */ | ||
41 | #define CY_AS_MAX_STORAGE_DEVICES (1) | ||
42 | |||
43 | #define CY_AS_FUNCTCBTYPE_DATA_MASK (0x60000000U) | ||
44 | #define CY_AS_FUNCTCBTYPE_TYPE_MASK (0x1FFFFFFFU) | ||
45 | |||
46 | #define cy_as_funct_c_b_type_get_type(t) \ | ||
47 | ((cy_as_funct_c_b_type)((t) & CY_AS_FUNCTCBTYPE_TYPE_MASK)) | ||
48 | #define cy_as_funct_c_b_type_contains_data(t) \ | ||
49 | (((cy_as_funct_c_b_type)((t) & \ | ||
50 | CY_AS_FUNCTCBTYPE_DATA_MASK)) == CY_FUNCT_CB_DATA) | ||
51 | |||
52 | /************************************** | ||
53 | * West Bridge Types | ||
54 | **************************************/ | ||
55 | |||
56 | /* Summary | ||
57 | Specifies a handle to an West Bridge device | ||
58 | |||
59 | Description | ||
60 | This type represents an opaque handle to an West Bridge device. | ||
61 | This handle is created via the CyAsMiscCreateDevice() function | ||
62 | and is used in all subsequent calls that communicate to the West | ||
63 | Bridge device. | ||
64 | |||
65 | See Also | ||
66 | * CyAsMiscCreateDevice | ||
67 | * CyAsMiscDestroyDevice | ||
68 | */ | ||
69 | typedef void *cy_as_device_handle; | ||
70 | |||
71 | /* Summary | ||
72 | This data type gives the mode for the DACK# signal | ||
73 | */ | ||
74 | typedef enum cy_as_device_dack_mode { | ||
75 | cy_as_device_dack_ack, /* Operate in the ACK mode */ | ||
76 | cy_as_device_dack_eob /* Operate in the EOB mode */ | ||
77 | } cy_as_device_dack_mode; | ||
78 | |||
79 | /* Summary | ||
80 | This data structure gives the options for all hardware features. | ||
81 | |||
82 | Description | ||
83 | This structure contains the information required to initialize the | ||
84 | West Bridge hardware. Any features of the device that can be | ||
85 | configured by the caller are specified here. | ||
86 | |||
87 | See Also | ||
88 | * CyAsMiscConfigure | ||
89 | */ | ||
90 | typedef struct cy_as_device_config { | ||
91 | /* If TRUE, the P port is running in SRAM mode. */ | ||
92 | cy_bool srammode; | ||
93 | /* If TRUE, the P port is synchronous, otherwise async */ | ||
94 | cy_bool sync; | ||
95 | /* If TRUE, DMA req will be delivered via the interrupt signal */ | ||
96 | cy_bool dmaintr; | ||
97 | /* Mode for the DACK# signal */ | ||
98 | cy_as_device_dack_mode dackmode; | ||
99 | /* If TRUE, the DRQ line is active high, otherwise active low */ | ||
100 | cy_bool drqpol; | ||
101 | /* If TRUE, the DACK line is active high, otherwise active low */ | ||
102 | cy_bool dackpol; | ||
103 | /* If TRUE, the clock is connected to a crystal, otherwise it is | ||
104 | connected to a clock */ | ||
105 | cy_bool crystal; | ||
106 | } cy_as_device_config; | ||
107 | |||
108 | |||
109 | /* Summary | ||
110 | Specifies a resource that can be owned by either the West Bridge | ||
111 | device or by the processor. | ||
112 | |||
113 | Description | ||
114 | This enumerated type identifies a resource that can be owned | ||
115 | either by the West Bridge device, or by the processor attached to | ||
116 | the P port of the West Bridge device. | ||
117 | |||
118 | See Also | ||
119 | * CyAsMiscAcquireResource | ||
120 | * CyAsMiscReleaseResource | ||
121 | */ | ||
122 | typedef enum cy_as_resource_type { | ||
123 | cy_as_bus_u_s_b = 0, /* The USB D+ and D- pins */ | ||
124 | cy_as_bus_1 = 1, /* The SDIO bus */ | ||
125 | cy_as_bus_0 = 2 /* The NAND bus (not implemented) */ | ||
126 | } cy_as_resource_type; | ||
127 | |||
128 | /* Summary | ||
129 | Specifies the reset type for a software reset operation. | ||
130 | |||
131 | Description | ||
132 | When the West Bridge device is reset, there are two types of | ||
133 | reset that arE possible. This type indicates the type of reset | ||
134 | requested. | ||
135 | |||
136 | Notes | ||
137 | Both of these reset types are software based resets; and are | ||
138 | distinct from a chip level HARD reset that is applied through | ||
139 | the reset pin on the West Bridge. | ||
140 | |||
141 | The CyAsResetSoft type resets only the on-chip micro-controller | ||
142 | in the West Bridge. In this case, the previously loaded firmware | ||
143 | will continue running. However, the Storage and USB stack | ||
144 | operations will need to be restarted, as any state relating to | ||
145 | these would have been lost. | ||
146 | |||
147 | The CyAsResetHard type resets the entire West Bridge chip, and will | ||
148 | need a fresh configuration and firmware download. | ||
149 | |||
150 | See Also | ||
151 | * <LINK CyAsMiscReset> | ||
152 | */ | ||
153 | |||
154 | typedef enum cy_as_reset_type { | ||
155 | /* Just resets the West Bridge micro-controller */ | ||
156 | cy_as_reset_soft, | ||
157 | /* Resets entire device, firmware must be reloaded and | ||
158 | the west bridge device must be re-initialized */ | ||
159 | cy_as_reset_hard | ||
160 | } cy_as_reset_type; | ||
161 | |||
162 | |||
163 | |||
164 | /* Summary | ||
165 | This type specifies the polarity of the SD power pin. | ||
166 | |||
167 | Description | ||
168 | Sets the SD power pin ( port C, bit 6) to active low or | ||
169 | active high. | ||
170 | |||
171 | */ | ||
172 | |||
173 | typedef enum cy_as_misc_signal_polarity { | ||
174 | cy_as_misc_active_high, | ||
175 | cy_as_misc_active_low | ||
176 | |||
177 | } cy_as_misc_signal_polarity; | ||
178 | |||
179 | |||
180 | |||
181 | /* Summary | ||
182 | This type specifies the type of the data returned by a Function | ||
183 | Callback. | ||
184 | |||
185 | Description | ||
186 | CY_FUNCT_CB_NODATA - This callback does not return any additional | ||
187 | information in the data field. | ||
188 | CY_FUNCT_CB_DATA - The data field is used, and the CyAsFunctCBType | ||
189 | will also contain the type of this data. | ||
190 | |||
191 | See Also | ||
192 | CyAsFunctionCallback | ||
193 | */ | ||
194 | typedef enum cy_as_funct_c_b_type { | ||
195 | CY_FUNCT_CB_INVALID = 0x0U, | ||
196 | /* Data from a CyAsMiscGetFirmwareVersion call. */ | ||
197 | CY_FUNCT_CB_MISC_GETFIRMWAREVERSION, | ||
198 | /* Data from a CyAsMiscHeartBeatControl call. */ | ||
199 | CY_FUNCT_CB_MISC_HEARTBEATCONTROL, | ||
200 | /* Data from a CyAsMiscAcquireResource call. */ | ||
201 | CY_FUNCT_CB_MISC_ACQUIRERESOURCE, | ||
202 | /* Data from a CyAsMiscReadMCURegister call. */ | ||
203 | CY_FUNCT_CB_MISC_READMCUREGISTER, | ||
204 | /* Data from a CyAsMiscWriteMCURegister call. */ | ||
205 | CY_FUNCT_CB_MISC_WRITEMCUREGISTER, | ||
206 | /* Data from a CyAsMiscSetTraceLevel call. */ | ||
207 | CY_FUNCT_CB_MISC_SETTRACELEVEL, | ||
208 | /* Data from a CyAsMiscStorageChanged call. */ | ||
209 | CY_FUNCT_CB_MISC_STORAGECHANGED, | ||
210 | /* Data from a CyAsMiscGetGpioValue call. */ | ||
211 | CY_FUNCT_CB_MISC_GETGPIOVALUE, | ||
212 | /* Data from a CyAsMiscSetGpioValue call. */ | ||
213 | CY_FUNCT_CB_MISC_SETGPIOVALUE, | ||
214 | /* Data from a CyAsMiscDownloadFirmware call. */ | ||
215 | CY_FUNCT_CB_MISC_DOWNLOADFIRMWARE, | ||
216 | /* Data from a CyAsMiscEnterStandby call. */ | ||
217 | CY_FUNCT_CB_MISC_ENTERSTANDBY, | ||
218 | /* Data from a CyAsMiscEnterSuspend call. */ | ||
219 | CY_FUNCT_CB_MISC_ENTERSUSPEND, | ||
220 | /* Data from a CyAsMiscLeaveSuspend call. */ | ||
221 | CY_FUNCT_CB_MISC_LEAVESUSPEND, | ||
222 | /* Data from a CyAsMiscReset call. */ | ||
223 | CY_FUNCT_CB_MISC_RESET, | ||
224 | /* Data from a CyAsMiscSetLowSpeedSDFreq or | ||
225 | * CyAsMiscSetHighSpeedSDFreq call. */ | ||
226 | CY_FUNCT_CB_MISC_SETSDFREQ, | ||
227 | /* Data from a CyAsMiscSwitchPnandMode call */ | ||
228 | CY_FUNCT_CB_MISC_RESERVELNABOOTAREA, | ||
229 | /* Data from a CyAsMiscSetSDPowerPolarity call */ | ||
230 | CY_FUNCT_CB_MISC_SETSDPOLARITY, | ||
231 | |||
232 | /* Data from a CyAsStorageStart call. */ | ||
233 | CY_FUNCT_CB_STOR_START, | ||
234 | /* Data from a CyAsStorageStop call. */ | ||
235 | CY_FUNCT_CB_STOR_STOP, | ||
236 | /* Data from a CyAsStorageClaim call. */ | ||
237 | CY_FUNCT_CB_STOR_CLAIM, | ||
238 | /* Data from a CyAsStorageRelease call. */ | ||
239 | CY_FUNCT_CB_STOR_RELEASE, | ||
240 | /* Data from a CyAsStorageQueryMedia call. */ | ||
241 | CY_FUNCT_CB_STOR_QUERYMEDIA, | ||
242 | /* Data from a CyAsStorageQueryBus call. */ | ||
243 | CY_FUNCT_CB_STOR_QUERYBUS, | ||
244 | /* Data from a CyAsStorageQueryDevice call. */ | ||
245 | CY_FUNCT_CB_STOR_QUERYDEVICE, | ||
246 | /* Data from a CyAsStorageQueryUnit call. */ | ||
247 | CY_FUNCT_CB_STOR_QUERYUNIT, | ||
248 | /* Data from a CyAsStorageDeviceControl call. */ | ||
249 | CY_FUNCT_CB_STOR_DEVICECONTROL, | ||
250 | /* Data from a CyAsStorageSDRegisterRead call. */ | ||
251 | CY_FUNCT_CB_STOR_SDREGISTERREAD, | ||
252 | /* Data from a CyAsStorageCreatePartition call. */ | ||
253 | CY_FUNCT_CB_STOR_PARTITION, | ||
254 | /* Data from a CyAsStorageGetTransferAmount call. */ | ||
255 | CY_FUNCT_CB_STOR_GETTRANSFERAMOUNT, | ||
256 | /* Data from a CyAsStorageErase call. */ | ||
257 | CY_FUNCT_CB_STOR_ERASE, | ||
258 | /* Data from a CyAsStorageCancelAsync call. */ | ||
259 | CY_FUNCT_CB_ABORT_P2S_XFER, | ||
260 | /* Data from a CyAsUsbStart call. */ | ||
261 | CY_FUNCT_CB_USB_START, | ||
262 | /* Data from a CyAsUsbStop call. */ | ||
263 | CY_FUNCT_CB_USB_STOP, | ||
264 | /* Data from a CyAsUsbConnect call. */ | ||
265 | CY_FUNCT_CB_USB_CONNECT, | ||
266 | /* Data from a CyAsUsbDisconnect call. */ | ||
267 | CY_FUNCT_CB_USB_DISCONNECT, | ||
268 | /* Data from a CyAsUsbSetEnumConfig call. */ | ||
269 | CY_FUNCT_CB_USB_SETENUMCONFIG, | ||
270 | /* Data from a CyAsUsbGetEnumConfig call. */ | ||
271 | CY_FUNCT_CB_USB_GETENUMCONFIG, | ||
272 | /* Data from a CyAsUsbSetDescriptor call. */ | ||
273 | CY_FUNCT_CB_USB_SETDESCRIPTOR, | ||
274 | /* Data from a CyAsUsbGetDescriptor call. */ | ||
275 | CY_FUNCT_CB_USB_GETDESCRIPTOR, | ||
276 | /* Data from a CyAsUsbCommitConfig call. */ | ||
277 | CY_FUNCT_CB_USB_COMMITCONFIG, | ||
278 | /* Data from a CyAsUsbGetNak call. */ | ||
279 | CY_FUNCT_CB_USB_GETNAK, | ||
280 | /* Data from a CyAsUsbGetStall call. */ | ||
281 | CY_FUNCT_CB_USB_GETSTALL, | ||
282 | /* Data from a CyAsUsbSignalRemoteWakeup call. */ | ||
283 | CY_FUNCT_CB_USB_SIGNALREMOTEWAKEUP, | ||
284 | /* Data from a CyAnUsbClearDescriptors call. */ | ||
285 | CY_FUNCT_CB_USB_CLEARDESCRIPTORS, | ||
286 | /* Data from a CyAnUsbSetMSReportThreshold call. */ | ||
287 | CY_FUNCT_CB_USB_SET_MSREPORT_THRESHOLD, | ||
288 | /* Data from a CyAsMTPStart call. */ | ||
289 | CY_FUNCT_CB_MTP_START, | ||
290 | /* Data from a CyAsMTPStop call. */ | ||
291 | CY_FUNCT_CB_MTP_STOP, | ||
292 | /* Data from a CyAsMTPInitSendObject call. */ | ||
293 | CY_FUNCT_CB_MTP_INIT_SEND_OBJECT, | ||
294 | /* Data from a CyAsMTPCancelSendObject call. */ | ||
295 | CY_FUNCT_CB_MTP_CANCEL_SEND_OBJECT, | ||
296 | /* Data from a CyAsMTPInitGetObject call. */ | ||
297 | CY_FUNCT_CB_MTP_INIT_GET_OBJECT, | ||
298 | /* Data from a CyAsMTPCancelGetObject call. */ | ||
299 | CY_FUNCT_CB_MTP_CANCEL_GET_OBJECT, | ||
300 | /* Data from a CyAsMTPSendBlockTable call. */ | ||
301 | CY_FUNCT_CB_MTP_SEND_BLOCK_TABLE, | ||
302 | /* Data from a CyAsMTPStopStorageOnly call. */ | ||
303 | CY_FUNCT_CB_MTP_STOP_STORAGE_ONLY, | ||
304 | CY_FUNCT_CB_NODATA = 0x40000000U, | ||
305 | CY_FUNCT_CB_DATA = 0x20000000U | ||
306 | } cy_as_funct_c_b_type; | ||
307 | |||
308 | /* Summary | ||
309 | This type specifies the general West Bridge function callback. | ||
310 | |||
311 | Description | ||
312 | This callback is supplied as an argument to all asynchronous | ||
313 | functions in the API. It iS called after the asynchronous function | ||
314 | has completed. | ||
315 | |||
316 | See Also | ||
317 | CyAsFunctCBType | ||
318 | */ | ||
319 | typedef void (*cy_as_function_callback)( | ||
320 | cy_as_device_handle handle, | ||
321 | cy_as_return_status_t status, | ||
322 | uint32_t client, | ||
323 | cy_as_funct_c_b_type type, | ||
324 | void *data); | ||
325 | |||
326 | /* Summary | ||
327 | This type specifies the general West Bridge event that has | ||
328 | occurred. | ||
329 | |||
330 | Description | ||
331 | This type is used in the West Bridge misc callback function to | ||
332 | indicate the type of callback. | ||
333 | |||
334 | See Also | ||
335 | */ | ||
336 | typedef enum cy_as_misc_event_type { | ||
337 | /* This event is sent when West Bridge has finished | ||
338 | initialization and is ready to respond to API calls. */ | ||
339 | cy_as_event_misc_initialized = 0, | ||
340 | |||
341 | /* This event is sent when West Bridge has left the | ||
342 | standby state and is ready to respond to commands again. */ | ||
343 | cy_as_event_misc_awake, | ||
344 | |||
345 | /* This event is sent periodically from the firmware | ||
346 | to the processor. */ | ||
347 | cy_as_event_misc_heart_beat, | ||
348 | |||
349 | /* This event is sent when the West Bridge has left the | ||
350 | suspend mode and is ready to respond to commands | ||
351 | again. */ | ||
352 | cy_as_event_misc_wakeup, | ||
353 | |||
354 | /* This event is sent when the firmware image downloaded | ||
355 | cannot run on the active west bridge device. */ | ||
356 | cy_as_event_misc_device_mismatch | ||
357 | } cy_as_misc_event_type; | ||
358 | |||
359 | /* Summary | ||
360 | This type is the type of a callback function that is called when a | ||
361 | West Bridge misc event occurs. | ||
362 | |||
363 | Description | ||
364 | At times West Bridge needs to inform the P port processor of events | ||
365 | that have occurred. These events are asynchronous to the thread of | ||
366 | control on the P port processor and as such are generally delivered | ||
367 | via a callback function that is called as part of an interrupt | ||
368 | handler. This type defines the type of function that must be provided | ||
369 | as a callback function for West Bridge misc events. | ||
370 | |||
371 | See Also | ||
372 | * CyAsMiscEventType | ||
373 | */ | ||
374 | typedef void (*cy_as_misc_event_callback)( | ||
375 | /* Handle to the device to configure */ | ||
376 | cy_as_device_handle handle, | ||
377 | /* The event type being reported */ | ||
378 | cy_as_misc_event_type ev, | ||
379 | /* The data assocaited with the event being reported */ | ||
380 | void *evdata | ||
381 | ); | ||
382 | |||
383 | #ifndef __doxygen__ | ||
384 | /* Summary | ||
385 | This enum provides info of various firmware trace levels. | ||
386 | |||
387 | Description | ||
388 | |||
389 | See Also | ||
390 | * CyAsMiscSetTraceLevel | ||
391 | */ | ||
392 | enum { | ||
393 | CYAS_FW_TRACE_LOG_NONE = 0, /* Log nothing. */ | ||
394 | CYAS_FW_TRACE_LOG_STATE, /* Log state information. */ | ||
395 | CYAS_FW_TRACE_LOG_CALLS, /* Log function calls. */ | ||
396 | CYAS_FW_TRACE_LOG_STACK_TRACE, /* Log function calls with args. */ | ||
397 | CYAS_FW_TRACE_MAX_LEVEL /* Max trace level sentinel. */ | ||
398 | }; | ||
399 | #endif | ||
400 | |||
401 | /* Summary | ||
402 | This enum lists the controllable GPIOs of the West Bridge device. | ||
403 | |||
404 | Description | ||
405 | The West Bridge device has GPIOs that can be used for user defined functions. | ||
406 | This enumeration lists the GPIOs that are available on the device. | ||
407 | |||
408 | Notes | ||
409 | All of the GPIOs except UVALID can only be accessed when using West Bridge | ||
410 | firmware images that support only SD/MMC/MMC+ storage devices. This | ||
411 | functionality is not supported in firmware images that support NAND | ||
412 | storage. | ||
413 | |||
414 | See Also | ||
415 | * CyAsMiscGetGpioValue | ||
416 | * CyAsMiscSetGpioValue | ||
417 | */ | ||
418 | typedef enum { | ||
419 | cy_as_misc_gpio_0 = 0, /* GPIO[0] pin */ | ||
420 | cy_as_misc_gpio_1, /* GPIO[1] pin */ | ||
421 | cy_as_misc_gpio__nand_CE, /* NAND_CE pin, output only */ | ||
422 | cy_as_misc_gpio__nand_CE2, /* NAND_CE2 pin, output only */ | ||
423 | cy_as_misc_gpio__nand_WP, /* NAND_WP pin, output only */ | ||
424 | cy_as_misc_gpio__nand_CLE, /* NAND_CLE pin, output only */ | ||
425 | cy_as_misc_gpio__nand_ALE, /* NAND_ALE pin, output only */ | ||
426 | /* SD_POW pin, output only, do not drive low while storage is active */ | ||
427 | cy_as_misc_gpio_SD_POW, | ||
428 | cy_as_misc_gpio_U_valid /* UVALID pin */ | ||
429 | } cy_as_misc_gpio; | ||
430 | |||
431 | /* Summary | ||
432 | This enum lists the set of clock frequencies that are supported for | ||
433 | working with low speed SD media. | ||
434 | |||
435 | Description | ||
436 | West Bridge firmware uses a clock frequency less than the maximum | ||
437 | possible rate for low speed SD media. This can be changed to a | ||
438 | setting equal to the maximum frequency as desired by the user. This | ||
439 | enumeration lists the different frequency settings that are | ||
440 | supported. | ||
441 | |||
442 | See Also | ||
443 | * CyAsMiscSetLowSpeedSDFreq | ||
444 | */ | ||
445 | typedef enum cy_as_low_speed_sd_freq { | ||
446 | /* Approx. 21.82 MHz, default value */ | ||
447 | CY_AS_SD_DEFAULT_FREQ = 0, | ||
448 | /* 24 MHz */ | ||
449 | CY_AS_SD_RATED_FREQ | ||
450 | } cy_as_low_speed_sd_freq; | ||
451 | |||
452 | /* Summary | ||
453 | This enum lists the set of clock frequencies that are supported | ||
454 | for working with high speed SD media. | ||
455 | |||
456 | Description | ||
457 | West Bridge firmware uses a 48 MHz clock by default to interface | ||
458 | with high speed SD/MMC media. This can be changed to 24 MHz if | ||
459 | so desired by the user. This enum lists the different frequencies | ||
460 | that are supported. | ||
461 | |||
462 | See Also | ||
463 | * CyAsMiscSetHighSpeedSDFreq | ||
464 | */ | ||
465 | typedef enum cy_as_high_speed_sd_freq { | ||
466 | CY_AS_HS_SD_FREQ_48, /* 48 MHz, default value */ | ||
467 | CY_AS_HS_SD_FREQ_24 /* 24 MHz */ | ||
468 | } cy_as_high_speed_sd_freq; | ||
469 | |||
470 | /* Summary | ||
471 | Struct encapsulating all information returned by the | ||
472 | CyAsMiscGetFirmwareVersion call. | ||
473 | |||
474 | Description | ||
475 | This struct encapsulates all return values from the asynchronous | ||
476 | CyAsMiscGetFirmwareVersion call, so that a single data argument | ||
477 | can be passed to the user provided callback function. | ||
478 | |||
479 | See Also | ||
480 | * CyAsMiscGetFirmwareVersion | ||
481 | */ | ||
482 | typedef struct cy_as_get_firmware_version_data { | ||
483 | /* Return value for major version number for the firmware */ | ||
484 | uint16_t major; | ||
485 | /* Return value for minor version number for the firmware */ | ||
486 | uint16_t minor; | ||
487 | /* Return value for build version number for the firmware */ | ||
488 | uint16_t build; | ||
489 | /* Return value for media types supported in the current firmware */ | ||
490 | uint8_t media_type; | ||
491 | /* Return value to indicate the release or debug mode of firmware */ | ||
492 | cy_bool is_debug_mode; | ||
493 | } cy_as_get_firmware_version_data; | ||
494 | |||
495 | |||
496 | /***************************** | ||
497 | * West Bridge Functions | ||
498 | *****************************/ | ||
499 | |||
500 | /* Summary | ||
501 | This function creates a new West Bridge device and returns a | ||
502 | handle to the device. | ||
503 | |||
504 | Description | ||
505 | This function initializes the API object that represents the West | ||
506 | Bridge device and returns a handle to this device. This handle is | ||
507 | required for all West Bridge related functions to identify the | ||
508 | specific West Bridge device. | ||
509 | |||
510 | * Valid In Asynchronous Callback: NO | ||
511 | |||
512 | Returns | ||
513 | * CY_AS_ERROR_SUCCESS | ||
514 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
515 | */ | ||
516 | EXTERN cy_as_return_status_t | ||
517 | cy_as_misc_create_device( | ||
518 | /* Return value for handle to created device */ | ||
519 | cy_as_device_handle *handle_p, | ||
520 | /* The HAL specific tag for this device */ | ||
521 | cy_as_hal_device_tag tag | ||
522 | ); | ||
523 | |||
524 | /* Summary | ||
525 | This functions destroys a previously created West Bridge device. | ||
526 | |||
527 | Description | ||
528 | When an West Bridge device is created, an opaque handle is returned | ||
529 | that represents the device. This function destroys that handle and | ||
530 | frees all resources associated with the handle. | ||
531 | |||
532 | * Valid In Asynchronous Callback: NO | ||
533 | |||
534 | Returns | ||
535 | * CY_AS_ERROR_SUCCESS | ||
536 | * CY_AS_ERROR_INVALID_HANDLE | ||
537 | * CY_AS_ERROR_STILL_RUNNING - The USB or STORAGE stacks are still | ||
538 | * running, they must be stopped before the device can be destroyed | ||
539 | * CY_AS_ERROR_DESTROY_SLEEP_CHANNEL_FAILED - the HAL layer failed to | ||
540 | * destroy a sleep channel | ||
541 | */ | ||
542 | EXTERN cy_as_return_status_t | ||
543 | cy_as_misc_destroy_device( | ||
544 | /* Handle to the device to destroy */ | ||
545 | cy_as_device_handle handle | ||
546 | ); | ||
547 | |||
548 | /* Summary | ||
549 | This function initializes the hardware for basic communication with | ||
550 | West Bridge. | ||
551 | |||
552 | Description | ||
553 | This function initializes the hardware to establish basic | ||
554 | communication with the West Bridge device. This is always the first | ||
555 | function called to initialize communication with the West Bridge | ||
556 | device. | ||
557 | |||
558 | * Valid In Asynchronous Callback: NO | ||
559 | |||
560 | Returns | ||
561 | * CY_AS_ERROR_SUCCESS - the basic initialization was completed | ||
562 | * CY_AS_ERROR_INVALID_HANDLE | ||
563 | * CY_AS_ERROR_IN_STANDBY | ||
564 | * CY_AS_ERROR_ALREADY_RUNNING | ||
565 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
566 | * CY_AS_ERROR_NO_ANTIOCH - cannot find the West Bridge device | ||
567 | * CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED - | ||
568 | * the HAL layer falied to create a sleep channel | ||
569 | |||
570 | See Also | ||
571 | * CyAsDeviceConfig | ||
572 | */ | ||
573 | EXTERN cy_as_return_status_t | ||
574 | cy_as_misc_configure_device( | ||
575 | /* Handle to the device to configure */ | ||
576 | cy_as_device_handle handle, | ||
577 | /* Configuration information */ | ||
578 | cy_as_device_config *config_p | ||
579 | ); | ||
580 | |||
581 | /* Summary | ||
582 | This function returns non-zero if West Bridge is in standby and | ||
583 | zero otherwise. | ||
584 | |||
585 | Description | ||
586 | West Bridge supports a standby mode. This function is used to | ||
587 | query West Bridge to determine if West Bridge is in a standby | ||
588 | mode. | ||
589 | |||
590 | * Valid In Asynchronous Callback: YES | ||
591 | |||
592 | Returns | ||
593 | * CY_AS_ERROR_SUCCESS | ||
594 | * CY_AS_ERROR_INVALID_HANDLE | ||
595 | */ | ||
596 | EXTERN cy_as_return_status_t | ||
597 | cy_as_misc_in_standby( | ||
598 | /* Handle to the device to configure */ | ||
599 | cy_as_device_handle handle, | ||
600 | /* Return value for standby state */ | ||
601 | cy_bool *standby | ||
602 | ); | ||
603 | |||
604 | /* Summary | ||
605 | This function downloads the firmware to West Bridge device. | ||
606 | |||
607 | Description | ||
608 | This function downloads firmware from a given location and with a | ||
609 | given size to the West Bridge device. After the firmware is | ||
610 | downloaded the West Bridge device is moved out of configuration | ||
611 | mode causing the firmware to be executed. It is an error to call | ||
612 | this function when the device is not in configuration mode. The | ||
613 | device is in configuration mode on power up and may be placed in | ||
614 | configuration mode after power up with a hard reset. | ||
615 | |||
616 | Notes | ||
617 | The firmware must be on a word align boundary. | ||
618 | |||
619 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
620 | * Nestable: YES | ||
621 | |||
622 | Returns | ||
623 | * CY_AS_ERROR_SUCCESS - the firmware was successfully downloaded | ||
624 | * CY_AS_ERROR_INVALID_HANDLE | ||
625 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
626 | * was not configured | ||
627 | * CY_AS_ERROR_NOT_IN_CONFIG_MODE | ||
628 | * CY_AS_ERROR_INVALID_SIZE - the size of the firmware | ||
629 | * exceeded 32768 bytes | ||
630 | * CY_AS_ERROR_ALIGNMENT_ERROR | ||
631 | * CY_AS_ERROR_IN_STANDBY - trying to download | ||
632 | * while in standby mode | ||
633 | * CY_AS_ERROR_TIMEOUT | ||
634 | |||
635 | See Also | ||
636 | * CyAsMiscReset | ||
637 | */ | ||
638 | EXTERN cy_as_return_status_t | ||
639 | cy_as_misc_download_firmware( | ||
640 | /* Handle to the device to configure */ | ||
641 | cy_as_device_handle handle, | ||
642 | /* Pointer to the firmware to be downloaded */ | ||
643 | const void *fw_p, | ||
644 | /* The size of the firmware in bytes */ | ||
645 | uint16_t size, | ||
646 | /* Callback to call when the operation is complete. */ | ||
647 | cy_as_function_callback cb, | ||
648 | /* Client data to be passed to the callback. */ | ||
649 | uint32_t client | ||
650 | ); | ||
651 | |||
652 | |||
653 | /* Summary | ||
654 | This function returns the version number of the firmware running in | ||
655 | the West Bridge device. | ||
656 | |||
657 | Description | ||
658 | This function queries the West Bridge device and retreives the | ||
659 | firmware version number. If the firmware is not loaded an error is | ||
660 | returned indicated no firmware has been loaded. | ||
661 | |||
662 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
663 | * Nestable: YES | ||
664 | |||
665 | Returns | ||
666 | * CY_AS_ERROR_SUCCESS - the firmware version number was retreived | ||
667 | * CY_AS_ERROR_INVALID_HANDLE | ||
668 | * CY_AS_ERROR_NOT_CONFIGURED | ||
669 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been downloaded | ||
670 | * to the device | ||
671 | * CY_AS_ERROR_IN_STANDBY | ||
672 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
673 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a response | ||
674 | * from the West Bridge firmware | ||
675 | */ | ||
676 | EXTERN cy_as_return_status_t | ||
677 | cy_as_misc_get_firmware_version( | ||
678 | /* Handle to the device to configure */ | ||
679 | cy_as_device_handle handle, | ||
680 | /* Return values indicating the firmware version. */ | ||
681 | cy_as_get_firmware_version_data *data, | ||
682 | /* Callback to call when the operation is complete. */ | ||
683 | cy_as_function_callback cb, | ||
684 | /* Client data to be passed to the callback. */ | ||
685 | uint32_t client | ||
686 | ); | ||
687 | |||
688 | #if !defined(__doxygen__) | ||
689 | |||
690 | /* Summary | ||
691 | This function reads and returns the contents of an MCU accessible | ||
692 | register on the West Bridge. | ||
693 | |||
694 | Description | ||
695 | This function requests the firmware to read and return the contents | ||
696 | of an MCU accessible register through the mailboxes. | ||
697 | |||
698 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
699 | * Nestable: YES | ||
700 | |||
701 | Returns | ||
702 | * CY_AS_ERROR_SUCCESS - the register content was retrieved. | ||
703 | * CY_AS_ERROR_INVALID_HANDLE | ||
704 | * CY_AS_ERROR_NOT_CONFIGURED | ||
705 | * CY_AS_ERROR_NO_FIRMWARE | ||
706 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
707 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a response | ||
708 | * from the West Bridge firmware | ||
709 | * CY_AS_ERROR_INVALID_RESPONSE - the firmware build does not | ||
710 | * support this command. | ||
711 | */ | ||
712 | EXTERN cy_as_return_status_t | ||
713 | cy_as_misc_read_m_c_u_register( | ||
714 | /* Handle to the device to configure */ | ||
715 | cy_as_device_handle handle, | ||
716 | /* Address of the register to read */ | ||
717 | uint16_t address, | ||
718 | /* Return value for the MCU register content */ | ||
719 | uint8_t *value, | ||
720 | /* Callback to call when the operation is complete. */ | ||
721 | cy_as_function_callback cb, | ||
722 | /* Client data to be passed to the callback. */ | ||
723 | uint32_t client | ||
724 | ); | ||
725 | |||
726 | /* Summary | ||
727 | This function writes to an MCU accessible register on the West Bridge. | ||
728 | |||
729 | Description | ||
730 | This function requests the firmware to write a specified value to an | ||
731 | MCU accessible register through the mailboxes. | ||
732 | |||
733 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
734 | * Nestable: YES | ||
735 | |||
736 | Notes | ||
737 | This function is only for internal use by the West Bridge API layer. | ||
738 | Calling this function directly can cause device malfunction. | ||
739 | |||
740 | Returns | ||
741 | * CY_AS_ERROR_SUCCESS - the register content was updated. | ||
742 | * CY_AS_ERROR_INVALID_HANDLE | ||
743 | * CY_AS_ERROR_NOT_CONFIGURED | ||
744 | * CY_AS_ERROR_NO_FIRMWARE | ||
745 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
746 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a response | ||
747 | * from the West Bridge firmware | ||
748 | * CY_AS_ERROR_INVALID_RESPONSE - the firmware build does not support | ||
749 | * this command. | ||
750 | */ | ||
751 | EXTERN cy_as_return_status_t | ||
752 | cy_as_misc_write_m_c_u_register( | ||
753 | /* Handle to the device to configure */ | ||
754 | cy_as_device_handle handle, | ||
755 | /* Address of the register to write */ | ||
756 | uint16_t address, | ||
757 | /* Mask to be applied on the register contents. */ | ||
758 | uint8_t mask, | ||
759 | /* Data to be ORed with the register contents. */ | ||
760 | uint8_t value, | ||
761 | /* Callback to call when the operation is complete. */ | ||
762 | cy_as_function_callback cb, | ||
763 | /* Client data to be passed to the callback. */ | ||
764 | uint32_t client | ||
765 | ); | ||
766 | |||
767 | #endif | ||
768 | |||
769 | /* Summary | ||
770 | This function will reset the West Bridge device and software API. | ||
771 | |||
772 | Description | ||
773 | This function will reset the West Bridge device and software API. | ||
774 | The reset operation can be a hard reset or a soft reset. A hard | ||
775 | reset will reset all aspects of the West Bridge device. The device | ||
776 | will enter the configuration state and the firmware will have to be | ||
777 | reloaded. The device will also have to be re-initialized. A soft | ||
778 | reset just resets the West Bridge micro-controller. | ||
779 | |||
780 | * Valid In Asynchronous Callback: NO | ||
781 | |||
782 | Notes | ||
783 | When a hard reset is issued, the firmware that may have been | ||
784 | previously loaded will be lost and any configuration information set | ||
785 | via CyAsMiscConfigureDevice() will be lost. This will be reflected | ||
786 | in the API maintained state of the device. In order to re-establish | ||
787 | communications with the West Bridge device, CyAsMiscConfigureDevice() | ||
788 | and CyAsMiscDownloadFirmware() must be called again. | ||
789 | |||
790 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
791 | * Nestable: YES | ||
792 | |||
793 | Returns | ||
794 | * CY_AS_ERROR_SUCCESS - the device has been reset | ||
795 | * CY_AS_ERROR_INVALID_HANDLE | ||
796 | * CY_AS_ERROR_NOT_CONFIGURED | ||
797 | * CY_AS_ERROR_NO_FIRMWARE | ||
798 | * CY_AS_ERROR_NOT_YET_SUPPORTED - current soft reset is not supported | ||
799 | * CY_AS_ERROR_ASYNC_PENDING - Reset is unable to flush pending async | ||
800 | * reads/writes in polling mode. | ||
801 | |||
802 | |||
803 | See Also | ||
804 | * CyAsMiscReset | ||
805 | */ | ||
806 | EXTERN cy_as_return_status_t | ||
807 | cy_as_misc_reset( | ||
808 | /* Handle to the device to configure */ | ||
809 | cy_as_device_handle handle, | ||
810 | /* The type of reset to perform */ | ||
811 | cy_as_reset_type type, | ||
812 | /* If true, flush all pending writes to mass storage | ||
813 | before performing the reset. */ | ||
814 | cy_bool flush, | ||
815 | /* Callback to call when the operation is complete. */ | ||
816 | cy_as_function_callback cb, | ||
817 | /* Client data to be passed to the callback. */ | ||
818 | uint32_t client | ||
819 | ); | ||
820 | |||
821 | /* Summary | ||
822 | This function acquires a given resource. | ||
823 | |||
824 | Description | ||
825 | There are resources in the system that are shared between the | ||
826 | West Bridge device and the processor attached to the P port of | ||
827 | the West Bridge device. This API provides a mechanism for the | ||
828 | P port processor to acquire ownership of a resource. | ||
829 | |||
830 | Notes | ||
831 | The ownership of the resources controlled by CyAsMiscAcquireResource() | ||
832 | and CyAsMiscReleaseResource() defaults to a known state at hardware | ||
833 | reset. After the firmware is loaded and begins execution the state of | ||
834 | these resources may change. At any point if the P Port processor needs | ||
835 | to acquire a resource it should do so explicitly to be sure of | ||
836 | ownership. | ||
837 | |||
838 | Returns | ||
839 | * CY_AS_ERROR_SUCCESS - the p port successfully acquired the | ||
840 | * resource of interest | ||
841 | * CY_AS_ERROR_INVALID_HANDLE | ||
842 | * CY_AS_ERROR_NOT_CONFIGURED | ||
843 | * CY_AS_ERROR_NO_FIRMWARE | ||
844 | * CY_AS_ERROR_INVALID_RESOURCE | ||
845 | * CY_AS_ERROR_RESOURCE_ALREADY_OWNED - the p port already | ||
846 | * owns this resource | ||
847 | * CY_AS_ERROR_NOT_ACQUIRED - the resource cannot be acquired | ||
848 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
849 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a | ||
850 | * response from the West Bridge firmware | ||
851 | |||
852 | See Also | ||
853 | * CyAsResourceType | ||
854 | */ | ||
855 | EXTERN cy_as_return_status_t | ||
856 | cy_as_misc_acquire_resource( | ||
857 | /* Handle to the device to configure */ | ||
858 | cy_as_device_handle handle, | ||
859 | /* The resource to acquire */ | ||
860 | cy_as_resource_type *resource, | ||
861 | /* If true, force West Bridge to release the resource */ | ||
862 | cy_bool force, | ||
863 | /* Callback to call when the operation is complete. */ | ||
864 | cy_as_function_callback cb, | ||
865 | /* Client data to be passed to the callback. */ | ||
866 | uint32_t client | ||
867 | ); | ||
868 | |||
869 | /* Summary | ||
870 | This function releases a given resource. | ||
871 | |||
872 | Description | ||
873 | There are resources in the system that are shared between the | ||
874 | West Bridge device and the processor attached to the P port of | ||
875 | the West Bridge device. This API provides a mechanism for the | ||
876 | P port processor to release a resource that has previously been | ||
877 | acquired via the CyAsMiscAcquireResource() call. | ||
878 | |||
879 | * Valid In Asynchronous Callback: NO | ||
880 | |||
881 | Returns | ||
882 | * CY_AS_ERROR_SUCCESS - the p port successfully released | ||
883 | * the resource of interest | ||
884 | * CY_AS_ERROR_INVALID_HANDLE | ||
885 | * CY_AS_ERROR_NOT_CONFIGURED | ||
886 | * CY_AS_ERROR_NO_FIRMWARE | ||
887 | * CY_AS_ERROR_INVALID_RESOURCE | ||
888 | * CY_AS_ERROR_RESOURCE_NOT_OWNED - the p port does not own the | ||
889 | * resource of interest | ||
890 | |||
891 | See Also | ||
892 | * CyAsResourceType | ||
893 | * CyAsMiscAcquireResource | ||
894 | */ | ||
895 | EXTERN cy_as_return_status_t | ||
896 | cy_as_misc_release_resource( | ||
897 | /* Handle to the device to configure */ | ||
898 | cy_as_device_handle handle, | ||
899 | /* The resource to release */ | ||
900 | cy_as_resource_type resource | ||
901 | ); | ||
902 | |||
903 | #ifndef __doxygen__ | ||
904 | /* Summary | ||
905 | This function sets the trace level for the West Bridge firmware. | ||
906 | |||
907 | Description | ||
908 | The West Bridge firmware has the ability to store information | ||
909 | about the state and execution path of the firmware on a mass storage | ||
910 | device attached to the West Bridge device. This function configures | ||
911 | the specific mass storage device to be used and the type of information | ||
912 | to be stored. This state information is used for debugging purposes | ||
913 | and must be interpreted by a Cypress provided tool. | ||
914 | |||
915 | *Trace Level* | ||
916 | The trace level indicates the amount of information to output. | ||
917 | * 0 = no trace information is output | ||
918 | * 1 = state information is output | ||
919 | * 2 = function call information is output | ||
920 | * 3 = function call, arguments, and return value information is output | ||
921 | |||
922 | * Valid In Asynchronous Callback: NO | ||
923 | |||
924 | Notes | ||
925 | The media device and unit specified in this call will be overwritten | ||
926 | and any data currently stored on this device and unit will be lost. | ||
927 | |||
928 | * NOT IMPLEMENTED YET | ||
929 | |||
930 | Returns | ||
931 | * CY_AS_ERROR_SUCCESS - the trace configuration has been | ||
932 | * successfully changed | ||
933 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not exist | ||
934 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
935 | * pair does not exist | ||
936 | * CY_AS_ERROR_NO_SUCH_UNIT - the unit specified does not exist | ||
937 | * CY_AS_ERROR_INVALID_TRACE_LEVEL - the trace level requested | ||
938 | * does not exist | ||
939 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a | ||
940 | * response from the West Bridge firmware | ||
941 | */ | ||
942 | EXTERN cy_as_return_status_t | ||
943 | cy_as_misc_set_trace_level( | ||
944 | /* Handle to the device to configure */ | ||
945 | cy_as_device_handle handle, | ||
946 | /* The trace level */ | ||
947 | uint8_t level, | ||
948 | /* The bus for the output */ | ||
949 | cy_as_bus_number_t bus, | ||
950 | /* The device for the output */ | ||
951 | uint32_t device, | ||
952 | /* The unit for the output */ | ||
953 | uint32_t unit, | ||
954 | /* Callback to call when the operation is complete. */ | ||
955 | cy_as_function_callback cb, | ||
956 | /* Client data to be passed to the callback. */ | ||
957 | uint32_t client | ||
958 | ); | ||
959 | #endif | ||
960 | |||
961 | /* Summary | ||
962 | This function places West Bridge into the low power standby mode. | ||
963 | |||
964 | Description | ||
965 | This function places West Bridge into a low power (sleep) mode, and | ||
966 | cannot be called while the USB stack is active. This function first | ||
967 | instructs the West Bridge firmware that the device is about to be | ||
968 | placed into sleep mode. This allows West Bridge to complete any pending | ||
969 | storage operations. After the West Bridge device has responded that | ||
970 | pending operations are complete, the device is placed in standby mode. | ||
971 | |||
972 | There are two methods of placing the device in standby mode. If the | ||
973 | WAKEUP pin of the West Bridge is connected to a GPIO on the processor, | ||
974 | the pin is de-asserted (via the HAL layer) and West Bridge enters into | ||
975 | a sleep mode. If the WAKEUP pin is not accessible, the processor can | ||
976 | write into the power management control/status register on the West | ||
977 | Bridge to put the device into sleep mode. | ||
978 | |||
979 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
980 | * Nestable: YES | ||
981 | |||
982 | Returns | ||
983 | * CY_AS_ERROR_SUCCESS - the function completed and West Bridge | ||
984 | * is in sleep mode | ||
985 | * CY_AS_ERROR_INVALID_HANDLE | ||
986 | * CY_AS_ERROR_ALREADY_STANDBY - the West Bridge device is already | ||
987 | * in sleep mode | ||
988 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a response | ||
989 | * from the West Bridge firmware | ||
990 | * CY_AS_ERROR_NOT_SUPPORTED - the HAL layer does not support changing | ||
991 | * the WAKEUP pin | ||
992 | * CY_AS_ERROR_USB_RUNNING - The USB stack is still running when the | ||
993 | * EnterStandby call is made | ||
994 | * CY_AS_ERROR_ASYNC_PENDING | ||
995 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
996 | * CY_AS_ERROR_INVALID_RESPONSE | ||
997 | * CY_AS_ERROR_SETTING_WAKEUP_PIN | ||
998 | * CY_AS_ERROR_ASYNC_PENDING - In polling mode EnterStandby can not | ||
999 | * be called until all pending storage read/write requests have | ||
1000 | * finished. | ||
1001 | |||
1002 | See Also | ||
1003 | * CyAsMiscLeaveStandby | ||
1004 | */ | ||
1005 | EXTERN cy_as_return_status_t | ||
1006 | cy_as_misc_enter_standby_e_x_u( | ||
1007 | /* Handle to the device to configure */ | ||
1008 | cy_as_device_handle handle, | ||
1009 | /* If true, use the wakeup pin, otherwise use the register */ | ||
1010 | cy_bool pin, | ||
1011 | /* Set true to enable specific usages of the | ||
1012 | UVALID signal, please refer to AN xx or ERRATA xx */ | ||
1013 | cy_bool uvalid_special, | ||
1014 | /* Callback to call when the operation is complete. */ | ||
1015 | cy_as_function_callback cb, | ||
1016 | /* Client data to be passed to the callback. */ | ||
1017 | uint32_t client | ||
1018 | ); | ||
1019 | |||
1020 | /* Summary | ||
1021 | This function is provided for backwards compatibility. | ||
1022 | |||
1023 | Description | ||
1024 | Calling this function is the same as calling CyAsMiscEnterStandbyEx | ||
1025 | with True for the lowpower parameter. | ||
1026 | |||
1027 | See Also | ||
1028 | * CyAsMiscEnterStandbyEx | ||
1029 | */ | ||
1030 | EXTERN cy_as_return_status_t | ||
1031 | cy_as_misc_enter_standby(cy_as_device_handle handle, | ||
1032 | cy_bool pin, | ||
1033 | cy_as_function_callback cb, | ||
1034 | uint32_t client | ||
1035 | ); | ||
1036 | |||
1037 | /* Summary | ||
1038 | This function brings West Bridge out of sleep mode. | ||
1039 | |||
1040 | Description | ||
1041 | This function asserts the WAKEUP pin (via the HAL layer). This | ||
1042 | brings the West Bridge out of the sleep state and allows the | ||
1043 | West Bridge firmware to process the event causing the wakeup. | ||
1044 | When all processing associated with the wakeup is complete, a | ||
1045 | callback function is called to tell the P port software that | ||
1046 | the firmware processing associated with wakeup is complete. | ||
1047 | |||
1048 | * Valid In Asynchronous Callback: NO | ||
1049 | |||
1050 | Returns: | ||
1051 | * CY_AS_ERROR_SUCCESS - the function completed and West Bridge | ||
1052 | * is in sleep mode | ||
1053 | * CY_AS_ERROR_INVALID_HANDLE | ||
1054 | * CY_AS_ERROR_SETTING_WAKEUP_PIN | ||
1055 | * CY_AS_ERROR_NOT_IN_STANDBY - the West Bridge device is not in | ||
1056 | * the sleep state | ||
1057 | * CY_AS_ERROR_TIMEOUT - there was a timeout waiting for a | ||
1058 | * response from the West Bridge firmware | ||
1059 | * CY_AS_ERROR_NOT_SUPPORTED - the HAL layer does not support | ||
1060 | * changing the WAKEUP pin | ||
1061 | |||
1062 | See Also | ||
1063 | * CyAsMiscEnterStandby | ||
1064 | */ | ||
1065 | EXTERN cy_as_return_status_t | ||
1066 | cy_as_misc_leave_standby( | ||
1067 | /* Handle to the device to configure */ | ||
1068 | cy_as_device_handle handle, | ||
1069 | /* The resource causing the wakeup */ | ||
1070 | cy_as_resource_type resource | ||
1071 | ); | ||
1072 | |||
1073 | /* Summary | ||
1074 | This function registers a callback function to be called when an | ||
1075 | asynchronous West Bridge MISC event occurs. | ||
1076 | |||
1077 | Description | ||
1078 | When asynchronous misc events occur, a callback function can be | ||
1079 | called to alert the calling program. This functions allows the | ||
1080 | calling program to register a callback. | ||
1081 | |||
1082 | * Valid In Asynchronous Callback: NO | ||
1083 | |||
1084 | Returns: | ||
1085 | * CY_AS_ERROR_SUCCESS | ||
1086 | * CY_AS_ERROR_INVALID_HANDLE | ||
1087 | */ | ||
1088 | EXTERN cy_as_return_status_t | ||
1089 | cy_as_misc_register_callback( | ||
1090 | /* Handle to the West Bridge device */ | ||
1091 | cy_as_device_handle handle, | ||
1092 | /* The function to call */ | ||
1093 | cy_as_misc_event_callback callback | ||
1094 | ); | ||
1095 | |||
1096 | /* Summary | ||
1097 | This function sets the logging level for log messages. | ||
1098 | |||
1099 | Description | ||
1100 | The API can print messages via the CyAsHalPrintMessage capability. | ||
1101 | This function sets the level of detail seen when printing messages | ||
1102 | from the API. | ||
1103 | |||
1104 | * Valid In Asynchronous Callback:NO | ||
1105 | */ | ||
1106 | EXTERN void | ||
1107 | cy_as_misc_set_log_level( | ||
1108 | /* Level to set, 0 is fewer messages, 255 is all */ | ||
1109 | uint8_t level | ||
1110 | ); | ||
1111 | |||
1112 | |||
1113 | /* Summary | ||
1114 | This function tells West Bridge that SD or MMC media has been | ||
1115 | inserted or removed. | ||
1116 | |||
1117 | Description | ||
1118 | In some hardware configurations, SD or MMC media detection is | ||
1119 | handled outside of the West Bridge device. This function is called | ||
1120 | when a change is detected to inform the West Bridge firmware to check | ||
1121 | for storage media changes. | ||
1122 | |||
1123 | * Valid In Asynchronous Callback: NO | ||
1124 | |||
1125 | Returns: | ||
1126 | * CY_AS_ERROR_SUCCESS | ||
1127 | * CY_AS_ERROR_INVALID_HANDLE | ||
1128 | * CY_AS_ERROR_NOT_CONFIGURED | ||
1129 | * CY_AS_ERROR_NO_FIRMWARE | ||
1130 | * CY_AS_ERROR_IN_STANDBY | ||
1131 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1132 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1133 | |||
1134 | See Also | ||
1135 | * CyAsMiscStorageChanged | ||
1136 | |||
1137 | */ | ||
1138 | EXTERN cy_as_return_status_t | ||
1139 | cy_as_misc_storage_changed( | ||
1140 | /* Handle to the West Bridge device */ | ||
1141 | cy_as_device_handle handle, | ||
1142 | /* Callback to call when the operation is complete. */ | ||
1143 | cy_as_function_callback cb, | ||
1144 | /* Client data to be passed to the callback. */ | ||
1145 | uint32_t client | ||
1146 | ); | ||
1147 | |||
1148 | /* Summary | ||
1149 | This function instructs the West Bridge firmware to start/stop | ||
1150 | sending periodic heartbeat messages to the processor. | ||
1151 | |||
1152 | Description | ||
1153 | The West Bridge firmware can send heartbeat messages through the | ||
1154 | mailbox register once every 500 ms. This message can be an overhead | ||
1155 | as it causes regular Mailbox interrupts to happen, and is turned | ||
1156 | off by default. The message can be used to test and verify that the | ||
1157 | West Bridge firmware is alive. This API can be used to enable or | ||
1158 | disable the heartbeat message. | ||
1159 | |||
1160 | * Valid In Asynchronous Callback: NO | ||
1161 | |||
1162 | Returns | ||
1163 | * CY_AS_ERROR_SUCCESS - the function completed successfully | ||
1164 | * CY_AS_ERROR_INVALID_HANDLE | ||
1165 | * CY_AS_ERROR_NOT_CONFIGURED | ||
1166 | * CY_AS_ERROR_NO_FIRMWARE | ||
1167 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1168 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1169 | * been configured yet | ||
1170 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded to | ||
1171 | * the West Bridge device | ||
1172 | |||
1173 | */ | ||
1174 | EXTERN cy_as_return_status_t | ||
1175 | cy_as_misc_heart_beat_control( | ||
1176 | /* Handle to the West Bridge device */ | ||
1177 | cy_as_device_handle handle, | ||
1178 | /* Message enable/disable selection */ | ||
1179 | cy_bool enable, | ||
1180 | /* Callback to call when the operation is complete. */ | ||
1181 | cy_as_function_callback cb, | ||
1182 | /* Client data to be passed to the callback. */ | ||
1183 | uint32_t client | ||
1184 | ); | ||
1185 | |||
1186 | /* Summary | ||
1187 | This function gets the current state of a GPIO pin on the | ||
1188 | West Bridge device. | ||
1189 | |||
1190 | Description | ||
1191 | The West Bridge device has GPIO pins that can be used for user | ||
1192 | defined functions. This function gets the current state of the | ||
1193 | specified GPIO pin. Calling this function will configure the | ||
1194 | corresponding pin as an input. | ||
1195 | |||
1196 | * Valid In Asynchronous Callback: NO | ||
1197 | |||
1198 | Notes | ||
1199 | Only GPIO[0], GPIO[1] and UVALID pins can be used as GP inputs. | ||
1200 | Of these pins, only the UVALID pin is supported by firmware images | ||
1201 | that include NAND storage support. | ||
1202 | |||
1203 | Returns | ||
1204 | * CY_AS_ERROR_SUCCESS - the function completed successfully | ||
1205 | * CY_AS_ERROR_INVALID_HANDLE | ||
1206 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1207 | * been configured yet | ||
1208 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded | ||
1209 | * to the West Bridge device | ||
1210 | * CY_AS_ERROR_BAD_INDEX - an invalid GPIO was specified | ||
1211 | * CY_AS_ERROR_NOT_SUPPORTED - this feature is not supported | ||
1212 | * by the firmware | ||
1213 | |||
1214 | See Also | ||
1215 | * CyAsMiscGpio | ||
1216 | * CyAsMiscSetGpioValue | ||
1217 | */ | ||
1218 | EXTERN cy_as_return_status_t | ||
1219 | cy_as_misc_get_gpio_value( | ||
1220 | /* Handle to the West Bridge device */ | ||
1221 | cy_as_device_handle handle, | ||
1222 | /* Id of the GPIO pin to query */ | ||
1223 | cy_as_misc_gpio pin, | ||
1224 | /* Current value of the GPIO pin */ | ||
1225 | uint8_t *value, | ||
1226 | /* Callback to call when the operation is complete. */ | ||
1227 | cy_as_function_callback cb, | ||
1228 | /* Client data to be passed to the callback. */ | ||
1229 | uint32_t client | ||
1230 | ); | ||
1231 | |||
1232 | /* Summary | ||
1233 | This function updates the state of a GPIO pin on the West | ||
1234 | Bridge device. | ||
1235 | |||
1236 | Description | ||
1237 | The West Bridge device has GPIO pins that can be used for | ||
1238 | user defined functions. This function updates the output | ||
1239 | value driven on a specified GPIO pin. Calling this function | ||
1240 | will configure the corresponding pin as an output. | ||
1241 | |||
1242 | * Valid In Asynchronous Callback: NO | ||
1243 | |||
1244 | Notes | ||
1245 | All of the pins listed under CyAsMiscGpio can be used as GP | ||
1246 | outputs. This feature is note supported by firmware images | ||
1247 | that include NAND storage device support. | ||
1248 | |||
1249 | Returns | ||
1250 | * CY_AS_ERROR_SUCCESS - the function completed successfully | ||
1251 | * CY_AS_ERROR_INVALID_HANDLE | ||
1252 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1253 | * been configured yet | ||
1254 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded | ||
1255 | * to the West Bridge device | ||
1256 | * CY_AS_ERROR_BAD_INDEX - an invalid GPIO was specified | ||
1257 | * CY_AS_ERROR_NOT_SUPPORTED - this feature is not supported | ||
1258 | * by firmware. | ||
1259 | |||
1260 | See Also | ||
1261 | * CyAsMiscGpio | ||
1262 | * CyAsMiscGetGpioValue | ||
1263 | */ | ||
1264 | EXTERN cy_as_return_status_t | ||
1265 | cy_as_misc_set_gpio_value( | ||
1266 | /* Handle to the West Bridge device */ | ||
1267 | cy_as_device_handle handle, | ||
1268 | /* Id of the GPIO pin to set */ | ||
1269 | cy_as_misc_gpio pin, | ||
1270 | /* Value to be set on the GPIO pin */ | ||
1271 | uint8_t value, | ||
1272 | /* Callback to call when the operation is complete. */ | ||
1273 | cy_as_function_callback cb, | ||
1274 | /* Client data to be passed to the callback. */ | ||
1275 | uint32_t client | ||
1276 | ); | ||
1277 | |||
1278 | /* Summary | ||
1279 | Set the West Bridge device in the low power suspend mode. | ||
1280 | |||
1281 | Description | ||
1282 | The West Bridge device has a low power suspend mode where the USB | ||
1283 | core and the internal microcontroller are powered down. This | ||
1284 | function sets the West Bridge device into this low power mode. | ||
1285 | This mode can only be entered when there is no active USB | ||
1286 | connection; i.e., when USB has not been connected or is suspended; | ||
1287 | and there are no pending USB or storage asynchronous calls. The | ||
1288 | device will exit the suspend mode and resume handling USB and | ||
1289 | processor requests when any activity is detected on the CE#, D+/D- | ||
1290 | or GPIO[0] lines. | ||
1291 | |||
1292 | * Valid In Asynchronous Callback: NO | ||
1293 | |||
1294 | Notes | ||
1295 | The GPIO[0] pin needs to be configured as an input for the gpio | ||
1296 | wakeup to work. This flag should not be enabled if the pin is | ||
1297 | being used as a GP output. | ||
1298 | |||
1299 | Returns | ||
1300 | * CY_AS_ERROR_SUCCESS - the device was placed in suspend mode. | ||
1301 | * CY_AS_ERROR_INVALID_HANDLE - the West Bridge handle passed | ||
1302 | * in is invalid. | ||
1303 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1304 | * yet been configured. | ||
1305 | * CY_AS_ERROR_NO_FIRMWARE - no firmware has been downloaded | ||
1306 | * to the device. | ||
1307 | * CY_AS_ERROR_IN_STANDBY - the device is already in sleep mode. | ||
1308 | * CY_AS_ERROR_USB_CONNECTED - the USB connection is active. | ||
1309 | * CY_AS_ERROR_ASYNC_PENDING - asynchronous storage/USB calls | ||
1310 | * are pending. | ||
1311 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to allocate memory for | ||
1312 | * the operation. | ||
1313 | * CY_AS_ERROR_INVALID_RESPONSE - command not recognised by | ||
1314 | * firmware. | ||
1315 | |||
1316 | See Also | ||
1317 | * CyAsMiscLeaveSuspend | ||
1318 | */ | ||
1319 | EXTERN cy_as_return_status_t | ||
1320 | cy_as_misc_enter_suspend( | ||
1321 | /* Handle to the West Bridge device */ | ||
1322 | cy_as_device_handle handle, | ||
1323 | /* Control the USB wakeup source */ | ||
1324 | cy_bool usb_wakeup_en, | ||
1325 | /* Control the GPIO[0] wakeup source */ | ||
1326 | cy_bool gpio_wakeup_en, | ||
1327 | /* Callback to call when suspend mode entry is complete */ | ||
1328 | cy_as_function_callback cb, | ||
1329 | /* Client data to be passed to the callback. */ | ||
1330 | uint32_t client | ||
1331 | ); | ||
1332 | |||
1333 | /* Summary | ||
1334 | Wake up the West Bridge device from suspend mode. | ||
1335 | |||
1336 | Description | ||
1337 | This call wakes up the West Bridge device from suspend mode, | ||
1338 | and makes it ready for accepting other commands from the API. | ||
1339 | A CyAsEventMiscWakeup event will be delivered to the callback | ||
1340 | registered with CyAsMiscRegisterCallback to indicate that the | ||
1341 | wake up is complete. | ||
1342 | |||
1343 | The CyAsEventMiscWakeup event will also be delivered if the | ||
1344 | wakeup happens due to USB or GPIO activity. | ||
1345 | |||
1346 | * Valid In Asynchronous Callback: NO | ||
1347 | |||
1348 | Returns | ||
1349 | * CY_AS_ERROR_SUCCESS - the device was woken up from | ||
1350 | * suspend mode. | ||
1351 | * CY_AS_ERROR_INVALID_HANDLE - invalid device handle | ||
1352 | * passed in. | ||
1353 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has | ||
1354 | * not been configured. | ||
1355 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been | ||
1356 | * downloaded to the device. | ||
1357 | * CY_AS_ERROR_NOT_IN_SUSPEND - the device is not in | ||
1358 | * suspend mode. | ||
1359 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to allocate memory | ||
1360 | * for the operation. | ||
1361 | * CY_AS_ERROR_TIMEOUT - failed to wake up the device. | ||
1362 | |||
1363 | See Also | ||
1364 | * CyAsMiscEnterSuspend | ||
1365 | */ | ||
1366 | EXTERN cy_as_return_status_t | ||
1367 | cy_as_misc_leave_suspend( | ||
1368 | /* Handle to the West Bridge device */ | ||
1369 | cy_as_device_handle handle, | ||
1370 | /* Callback to call when device has resumed operation. */ | ||
1371 | cy_as_function_callback cb, | ||
1372 | /* Client data to be passed to the callback. */ | ||
1373 | uint32_t client | ||
1374 | ); | ||
1375 | |||
1376 | /* Summary | ||
1377 | Reserve first numzones zones of nand device for storing | ||
1378 | processor boot image. LNA firmware works on the first | ||
1379 | numzones zones of nand to enable the processor to boot. | ||
1380 | |||
1381 | Description | ||
1382 | This function reserves first numzones zones of nand device | ||
1383 | for storing processor boot image. This fonction MUST be | ||
1384 | completed before starting the storage stack for the setting | ||
1385 | to be taken into account. | ||
1386 | |||
1387 | * Valid In Asynchronous Callback: YES | ||
1388 | |||
1389 | Returns | ||
1390 | * CY_AS_ERROR_SUCCESS- zones are reserved. | ||
1391 | |||
1392 | */ | ||
1393 | EXTERN cy_as_return_status_t | ||
1394 | cy_as_misc_reserve_l_n_a_boot_area( | ||
1395 | /* Handle to the West Bridge device */ | ||
1396 | cy_as_device_handle handle, | ||
1397 | /* number of nand zones to reserve */ | ||
1398 | uint8_t numzones, | ||
1399 | /* Callback to call when device has resumed operation. */ | ||
1400 | cy_as_function_callback cb, | ||
1401 | /* Client data to be passed to the callback. */ | ||
1402 | uint32_t client | ||
1403 | ); | ||
1404 | |||
1405 | /* Summary | ||
1406 | Select the clock frequency to be used when talking to low | ||
1407 | speed (non-high speed) SD media. | ||
1408 | |||
1409 | Description | ||
1410 | West Bridge firmware uses a clock frequency less than the | ||
1411 | maximum possible rate for low speed SD media. This function | ||
1412 | selects the frequency setting from between the default speed | ||
1413 | and the maximum speed. This fonction MUST be completed before | ||
1414 | starting the storage stack for the setting to be taken into | ||
1415 | account. | ||
1416 | |||
1417 | * Valid in Asynchronous Callback: Yes (if cb is non-zero) | ||
1418 | * Nestable: Yes | ||
1419 | |||
1420 | Returns | ||
1421 | * CY_AS_ERROR_SUCCESS - the operation completed successfully. | ||
1422 | * CY_AS_ERROR_INVALID_HANDLE - invalid device handle passed in. | ||
1423 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not been | ||
1424 | * configured. | ||
1425 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded | ||
1426 | * to the device. | ||
1427 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to allocate memory for | ||
1428 | * the operation. | ||
1429 | * CY_AS_ERROR_IN_SUSPEND - West Bridge is in low power suspend | ||
1430 | * mode. | ||
1431 | * CY_AS_ERROR_INVALID_PARAMETER - invalid frequency setting | ||
1432 | * desired. | ||
1433 | * CY_AS_ERROR_TIMEOUT - West Bridge device did not respond to | ||
1434 | * the operation. | ||
1435 | * CY_AS_ERROR_INVALID_RESPONSE - active firmware does not support | ||
1436 | * the operation. | ||
1437 | |||
1438 | See Also | ||
1439 | * CyAsLowSpeedSDFreq | ||
1440 | */ | ||
1441 | EXTERN cy_as_return_status_t | ||
1442 | cy_as_misc_set_low_speed_sd_freq( | ||
1443 | /* Handle to the West Bridge device */ | ||
1444 | cy_as_device_handle handle, | ||
1445 | /* Frequency setting desired for low speed SD cards */ | ||
1446 | cy_as_low_speed_sd_freq setting, | ||
1447 | /* Callback to call on completion */ | ||
1448 | cy_as_function_callback cb, | ||
1449 | /* Client data to be passed to the callback */ | ||
1450 | uint32_t client | ||
1451 | ); | ||
1452 | |||
1453 | /* Summary | ||
1454 | Select the clock frequency to be used when talking to high speed | ||
1455 | SD/MMC media. | ||
1456 | |||
1457 | Description | ||
1458 | West Bridge firmware uses a 48 MHz clock to interface with high | ||
1459 | speed SD/MMC media. This clock rate can be restricted to 24 MHz | ||
1460 | if desired. This function selects the frequency setting to be | ||
1461 | used. This fonction MUST be completed before starting the storage | ||
1462 | stack for the setting to be taken into account. | ||
1463 | |||
1464 | * Valid in Asynchronous Callback: Yes (if cb is non-zero) | ||
1465 | * Nestable: Yes | ||
1466 | |||
1467 | Returns | ||
1468 | * CY_AS_ERROR_SUCCESS - the operation completed successfully. | ||
1469 | * CY_AS_ERROR_INVALID_HANDLE - invalid device handle passed in. | ||
1470 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not been | ||
1471 | * configured. | ||
1472 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded to | ||
1473 | * the device. | ||
1474 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to allocate memory for the | ||
1475 | * operation. | ||
1476 | * CY_AS_ERROR_IN_SUSPEND - West Bridge is in low power suspend mode. | ||
1477 | * CY_AS_ERROR_INVALID_PARAMETER - invalid frequency setting desired. | ||
1478 | * CY_AS_ERROR_TIMEOUT - West Bridge device did not respond to the | ||
1479 | * operation. | ||
1480 | * CY_AS_ERROR_INVALID_RESPONSE - active firmware does not support | ||
1481 | * the operation. | ||
1482 | |||
1483 | See Also | ||
1484 | * CyAsLowSpeedSDFreq | ||
1485 | */ | ||
1486 | EXTERN cy_as_return_status_t | ||
1487 | cy_as_misc_set_high_speed_sd_freq( | ||
1488 | /* Handle to the West Bridge device */ | ||
1489 | cy_as_device_handle handle, | ||
1490 | /* Frequency setting desired for high speed SD cards */ | ||
1491 | cy_as_high_speed_sd_freq setting, | ||
1492 | /* Callback to call on completion */ | ||
1493 | cy_as_function_callback cb, | ||
1494 | /* Client data to be passed to the callback */ | ||
1495 | uint32_t client | ||
1496 | ); | ||
1497 | /* Summary | ||
1498 | Select the polarity of the SD_POW output driven by West Bridge. | ||
1499 | |||
1500 | Description | ||
1501 | The SD_POW signal driven by West Bridge can be used to control | ||
1502 | the supply of Vcc to the SD/MMC media connected to the device. | ||
1503 | This signal is driven as an active high signal by default. This | ||
1504 | function can be used to change the polarity of this signal if | ||
1505 | required. This fonction MUST be completed before starting the | ||
1506 | storage stack for the setting to be taken into account. | ||
1507 | |||
1508 | * Valid in Asynchronous Callback: Yes (if cb is non-zero) | ||
1509 | * Nestable: Yes | ||
1510 | |||
1511 | Returns | ||
1512 | * CY_AS_ERROR_SUCCESS - the operation completed successfully. | ||
1513 | * CY_AS_ERROR_INVALID_HANDLE - invalid device handle passed in. | ||
1514 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not been | ||
1515 | * configured. | ||
1516 | * CY_AS_ERROR_NO_FIRMWARE - firmware has not been downloaded | ||
1517 | * to the device. | ||
1518 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to allocate memory for | ||
1519 | * the operation. | ||
1520 | * CY_AS_ERROR_IN_SUSPEND - West Bridge is in low power | ||
1521 | * suspend mode. | ||
1522 | * CY_AS_ERROR_INVALID_PARAMETER - invalid frequency setting | ||
1523 | * desired. | ||
1524 | * CY_AS_ERROR_TIMEOUT - West Bridge device did not respond to | ||
1525 | * the operation. | ||
1526 | * CY_AS_ERROR_INVALID_RESPONSE - active firmware does not | ||
1527 | * support the operation. | ||
1528 | |||
1529 | See Also | ||
1530 | * CyAsMiscSignalPolarity | ||
1531 | */ | ||
1532 | EXTERN cy_as_return_status_t | ||
1533 | cy_as_misc_set_sd_power_polarity( | ||
1534 | /* Handle to the West Bridge device */ | ||
1535 | cy_as_device_handle handle, | ||
1536 | /* Desired polarity setting to the SD_POW signal. */ | ||
1537 | cy_as_misc_signal_polarity polarity, | ||
1538 | /* Callback to call on completion. */ | ||
1539 | cy_as_function_callback cb, | ||
1540 | /* Client data to be passed to the callback. */ | ||
1541 | uint32_t client | ||
1542 | ); | ||
1543 | |||
1544 | /* For supporting deprecated functions */ | ||
1545 | #include "cyasmisc_dep.h" | ||
1546 | |||
1547 | #include "cyas_cplus_end.h" | ||
1548 | |||
1549 | #endif /* _INCLUDED_CYASMISC_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc_dep.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc_dep.h deleted file mode 100644 index 8b258efc0182..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmisc_dep.h +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasmisc_dep.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* This header will contain Antioch specific declaration | ||
23 | * of the APIs that are deprecated in Astoria SDK. This is | ||
24 | * for maintaining backward compatibility with prior releases | ||
25 | * of the Antioch SDK. | ||
26 | */ | ||
27 | #ifndef __INCLUDED_CYASMISC_DEP_H__ | ||
28 | #define __INCLUDED_CYASMISC_DEP_H__ | ||
29 | |||
30 | #ifndef __doxygen__ | ||
31 | |||
32 | EXTERN cy_as_return_status_t | ||
33 | cy_as_misc_acquire_resource_dep(cy_as_device_handle handle, | ||
34 | cy_as_resource_type resource, | ||
35 | cy_bool force); | ||
36 | EXTERN cy_as_return_status_t | ||
37 | cy_as_misc_get_firmware_version_dep(cy_as_device_handle handle, | ||
38 | uint16_t *major, | ||
39 | uint16_t *minor, | ||
40 | uint16_t *build, | ||
41 | uint8_t *media_type, | ||
42 | cy_bool *is_debug_mode); | ||
43 | EXTERN cy_as_return_status_t | ||
44 | cy_as_misc_set_trace_level_dep(cy_as_device_handle handle, | ||
45 | uint8_t level, | ||
46 | cy_as_media_type media, | ||
47 | uint32_t device, | ||
48 | uint32_t unit, | ||
49 | cy_as_function_callback cb, | ||
50 | uint32_t client); | ||
51 | #endif /*__doxygen*/ | ||
52 | |||
53 | #endif /*__INCLUDED_CYANSTORAGE_DEP_H__*/ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmtp.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmtp.h deleted file mode 100644 index 05d344969776..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasmtp.h +++ /dev/null | |||
@@ -1,646 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasmtp.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASMTP_H_ | ||
23 | #define _INCLUDED_CYASMTP_H_ | ||
24 | |||
25 | #include "cyasmisc.h" | ||
26 | |||
27 | #include "cyas_cplus_start.h" | ||
28 | |||
29 | /*@@Media Transfer Protocol (MTP) Overview | ||
30 | Summary | ||
31 | The MTP API has been designed to allow MTP enabled West Bridge | ||
32 | devices to implement the MTP protocol while maintaining high | ||
33 | performance. West Bridge has the capability to enter into a | ||
34 | Turbo mode during a MTP SendObject or GetObject operation | ||
35 | enabling it to directly stream the data into or out of the | ||
36 | attached SD card with minimal involvement from the Processor. | ||
37 | |||
38 | Description | ||
39 | The MTP API is designed to act as a pass through implementation | ||
40 | of the MTP protocol for all operations. Each MTP transaction | ||
41 | received from the Host is passed through West Bridge and along | ||
42 | to the Processor. The Processor can then respond to the | ||
43 | transaction and pass data and/or responses back to the Host | ||
44 | through West Bridge. | ||
45 | |||
46 | The MTP API also allows for a high speed handling of MTP | ||
47 | SendObject and GetObject operations, referred to as Turbo MTP. | ||
48 | During a Turbo MTP operation West Bridge is responsible for | ||
49 | reading or writing the data for the MTP operation directly from | ||
50 | or to the SD card with minimal interaction from the Processor. | ||
51 | The is done by having the Processor transfer a Block Table | ||
52 | to West Bridge which contains the locations on the SD card that | ||
53 | need to be read or written. During the handling of a Turbo | ||
54 | Operation the Processor will then only periodically need to | ||
55 | send a new Block Table to West Bridge when the first is used up. | ||
56 | See the CyAsMTPInitSendObject and CyAsMTPInitGetObject functions | ||
57 | for more details. | ||
58 | |||
59 | In order to enable the MTP API you must first have a MTP enabled | ||
60 | West Bridge loaded with MTP firmware. You then must start the USB | ||
61 | and Storage APIs before starting the MTP API. See CyAsMTPStart | ||
62 | for more details. | ||
63 | */ | ||
64 | |||
65 | /*@@Endpoints | ||
66 | Summary | ||
67 | When using MTP firmware endpoints 2 and 6 are dedicated | ||
68 | to bulk MTP traffic and endpoint 1 is available for MTP | ||
69 | events. | ||
70 | |||
71 | Description | ||
72 | When using a MTP enabled West Brdige device endpoints 2 and | ||
73 | 6 are made available for use to implement the MTP protocol. | ||
74 | These endpoints have a few special restrictions noted below | ||
75 | but otherwise the existing USB APIs can be used normally with | ||
76 | these endpoints. | ||
77 | |||
78 | 1. CyAsUsbSetNak, CyAsUsbClearNak, and CyAsUsbGetNak are | ||
79 | disabled for these endpoints | ||
80 | 2. During a turbo operation CyAsUsbSetStall, CyAsUsbClearStall, | ||
81 | and CyAsUsbGetStall are disabled. | ||
82 | |||
83 | */ | ||
84 | |||
85 | |||
86 | /* Summary | ||
87 | This constants defines the maximum number of | ||
88 | entries in the Block Table used to describe | ||
89 | the locations for Send/GetObject operations. | ||
90 | |||
91 | See Also | ||
92 | * CyAsMtpSendObject | ||
93 | * CyAsMtpGetObject | ||
94 | */ | ||
95 | #define CY_AS_MAX_BLOCK_TABLE_ENTRIES 64 | ||
96 | |||
97 | /* Summary | ||
98 | Endpoint to be used for MTP reads from the USB host. | ||
99 | */ | ||
100 | #define CY_AS_MTP_READ_ENDPOINT (2) | ||
101 | |||
102 | /* Summary | ||
103 | Endpoint to be used fro MTP writes to the USB host. | ||
104 | */ | ||
105 | #define CY_AS_MTP_WRITE_ENDPOINT (6) | ||
106 | |||
107 | /****************************************** | ||
108 | * MTP Types | ||
109 | ******************************************/ | ||
110 | |||
111 | /* Summary | ||
112 | The BlockTable used for turbo operations. | ||
113 | |||
114 | Description | ||
115 | This struct is used to specify the blocks | ||
116 | to be used for both read/write and send/getObject | ||
117 | operations. | ||
118 | |||
119 | The start block is a starting Logical Block Address | ||
120 | and num block is the number of blocks in that contiguous | ||
121 | region. | ||
122 | |||
123 | start_blocks[i]->[-------] <- start_blocks[i] + num_blocks[i] | ||
124 | |||
125 | If you need fewer than CY_AS_MAX_BLOCK_TABLE_ENTRIES | ||
126 | the remainder should be left empty. Empty is defined | ||
127 | as num_blocks equal to 0. | ||
128 | |||
129 | See Also | ||
130 | * CyAsMTPInitSendObject | ||
131 | * CyAsMTPInitGetObject | ||
132 | |||
133 | */ | ||
134 | typedef struct cy_as_mtp_block_table { | ||
135 | uint32_t start_blocks[CY_AS_MAX_BLOCK_TABLE_ENTRIES]; | ||
136 | uint16_t num_blocks[CY_AS_MAX_BLOCK_TABLE_ENTRIES]; | ||
137 | } cy_as_mtp_block_table; | ||
138 | |||
139 | /* Summary | ||
140 | This type specifies the type of MTP event that has occurred. | ||
141 | |||
142 | Description | ||
143 | MTP events are used to communicate that West Bridge has | ||
144 | either finished the handling of the given operation, or | ||
145 | that it requires additional data to complete the operation. | ||
146 | |||
147 | In no case does West Bridge send any MTP protocol responses, | ||
148 | this always remain the responsibility of the client. | ||
149 | |||
150 | See Also | ||
151 | * CyAsMTPInitSendObject | ||
152 | * CyAsMTPInitGetObject | ||
153 | * CyAsMTPSendBlockTable | ||
154 | |||
155 | */ | ||
156 | typedef enum cy_as_mtp_event { | ||
157 | /* This event is sent when West Bridge | ||
158 | has finished writing the data from a | ||
159 | send_object. west bridge will -not- send | ||
160 | the MTP response. */ | ||
161 | cy_as_mtp_send_object_complete, | ||
162 | |||
163 | /* This event is sent when West Bridge | ||
164 | has finished sending the data for a | ||
165 | get_object operation. west bridge will | ||
166 | -not- send the MTP response. */ | ||
167 | cy_as_mtp_get_object_complete, | ||
168 | |||
169 | /* This event is called when West Bridge | ||
170 | needs a new block_table. this is only a | ||
171 | notification, to transfer a block_table | ||
172 | to west bridge the cy_as_mtp_send_block_table | ||
173 | use the function. while west bridge is waiting | ||
174 | for a block_table during a send_object it | ||
175 | may need to NAK the endpoint. it is important | ||
176 | that the cy_as_mtp_send_block_table call is made | ||
177 | in a timely manner as eventually a delay | ||
178 | will result in an USB reset. this event has | ||
179 | no data */ | ||
180 | cy_as_mtp_block_table_needed | ||
181 | } cy_as_mtp_event; | ||
182 | |||
183 | /* Summary | ||
184 | Data for the CyAsMTPSendObjectComplete event. | ||
185 | |||
186 | Description | ||
187 | Notification that a SendObject operation has been | ||
188 | completed. The status of the operation is given | ||
189 | (to distinguish between a cancelled and a success | ||
190 | for example) as well as the block count. The blocks | ||
191 | are used in order based on the current block table. | ||
192 | If more than one block table was used for a given | ||
193 | SendObject the count will include the total number | ||
194 | of blocks written. | ||
195 | |||
196 | This callback will be made only once per SendObject | ||
197 | operation and it will only be called after all of | ||
198 | the data has been committed to the SD card. | ||
199 | |||
200 | See Also | ||
201 | * CyAsMTPEvent | ||
202 | |||
203 | */ | ||
204 | typedef struct cy_as_mtp_send_object_complete_data { | ||
205 | cy_as_return_status_t status; | ||
206 | uint32_t byte_count; | ||
207 | uint32_t transaction_id; | ||
208 | } cy_as_mtp_send_object_complete_data; | ||
209 | |||
210 | /* Summary | ||
211 | Data for the CyAsMTPGetObjectComplete event. | ||
212 | |||
213 | Description | ||
214 | Notification that a GetObject has finished. This | ||
215 | event allows the P side to know when to send the MTP | ||
216 | response for the GetObject operation. | ||
217 | |||
218 | See Also | ||
219 | * CyAsMTPEvent | ||
220 | |||
221 | */ | ||
222 | typedef struct cy_as_mtp_get_object_complete_data { | ||
223 | cy_as_return_status_t status; | ||
224 | uint32_t byte_count; | ||
225 | } cy_as_mtp_get_object_complete_data; | ||
226 | |||
227 | /* Summary | ||
228 | MTP Event callback. | ||
229 | |||
230 | Description | ||
231 | Callback used to communicate that a SendObject | ||
232 | operation has finished. | ||
233 | |||
234 | See Also | ||
235 | * CyAsMTPEvent | ||
236 | */ | ||
237 | typedef void (*cy_as_mtp_event_callback)( | ||
238 | cy_as_device_handle handle, | ||
239 | cy_as_mtp_event evtype, | ||
240 | void *evdata | ||
241 | ); | ||
242 | |||
243 | /* Summary | ||
244 | This is the callback function called after asynchronous API | ||
245 | functions have completed. | ||
246 | |||
247 | Description | ||
248 | When calling API functions from callback routines (interrupt | ||
249 | handlers usually) the async version of these functions must | ||
250 | be used. This callback is called when an asynchronous API | ||
251 | function has completed. | ||
252 | */ | ||
253 | typedef void (*cy_as_mtp_function_callback)( | ||
254 | /* Handle to the device to configure */ | ||
255 | cy_as_device_handle handle, | ||
256 | /* The error status of the operation */ | ||
257 | cy_as_return_status_t status, | ||
258 | /* A client supplied 32 bit tag */ | ||
259 | uint32_t client | ||
260 | ); | ||
261 | |||
262 | /************************************** | ||
263 | * MTP Functions | ||
264 | **************************************/ | ||
265 | |||
266 | /* Summary | ||
267 | This function starts the MTP stack. | ||
268 | |||
269 | Description | ||
270 | Initializes West Bridge for MTP activity and registers the MTP | ||
271 | event callback. | ||
272 | |||
273 | Before calling CyAsMTPStart, CyAsUsbStart and CyAsStorageStart must be | ||
274 | called (in either order). | ||
275 | |||
276 | MTPStart must be called before the device is enumerated. Please | ||
277 | see the documentation for CyAsUsbSetEnumConfig and CyAsUsbEnumControl | ||
278 | for details on enumerating a device for MTP. | ||
279 | |||
280 | Calling MTPStart will not affect any ongoing P<->S traffic. | ||
281 | |||
282 | This requires a MTP firmware image to be loaded on West Bridge. | ||
283 | |||
284 | Returns | ||
285 | * CY_AS_ERROR_SUCCESS | ||
286 | * CY_AS_ERROR_INVALID_HANDLE | ||
287 | * CY_AS_ERROR_NOT_CONFIGURED | ||
288 | * CY_AS_ERROR_NO_FIRMWARE | ||
289 | * CY_AS_ERROR_IN_SUSPEND | ||
290 | * CY_AS_ERROR_INVALID_IN_CALLBACK | ||
291 | * CY_AS_ERROR_STARTSTOP_PENDING | ||
292 | * CY_AS_ERROR_NOT_RUNNING - CyAsUsbStart or CyAsStorageStart | ||
293 | * have not been called | ||
294 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
295 | * firmware with MTP support | ||
296 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
297 | * CY_AS_ERROR_INVALID_RESPONSE | ||
298 | |||
299 | |||
300 | See Also | ||
301 | * CyAsMTPStop | ||
302 | * CyAsUsbStart | ||
303 | * CyAsStorageStart | ||
304 | * CyAsUsbSetEnumConfig | ||
305 | * CyAsUsbEnumControl | ||
306 | */ | ||
307 | cy_as_return_status_t | ||
308 | cy_as_mtp_start( | ||
309 | cy_as_device_handle handle, | ||
310 | cy_as_mtp_event_callback event_c_b, | ||
311 | cy_as_function_callback cb, | ||
312 | uint32_t client | ||
313 | ); | ||
314 | |||
315 | |||
316 | /* Summary | ||
317 | This function stops the MTP stack. | ||
318 | |||
319 | Description | ||
320 | Stops all MTP activity. Any ongoing transfers are | ||
321 | canceled. | ||
322 | |||
323 | This will not cause a UsbDisconnect but all | ||
324 | MTP activity (both pass through and turbo) will | ||
325 | stop. | ||
326 | |||
327 | Returns | ||
328 | * CY_AS_ERROR_SUCCESS | ||
329 | * CY_AS_ERROR_INVALID_HANDLE | ||
330 | * CY_AS_ERROR_NOT_CONFIGURED | ||
331 | * CY_AS_ERROR_NO_FIRMWARE | ||
332 | * CY_AS_ERROR_NOT_RUNNING | ||
333 | * CY_AS_ERROR_IN_SUSPEND | ||
334 | * CY_AS_ERROR_INVALID_IN_CALLBACK | ||
335 | * CY_AS_ERROR_STARTSTOP_PENDING | ||
336 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
337 | * CY_AS_ERROR_INVALID_RESPONSE | ||
338 | |||
339 | |||
340 | See Also | ||
341 | * CyAsMTPStart | ||
342 | */ | ||
343 | cy_as_return_status_t | ||
344 | cy_as_mtp_stop( | ||
345 | cy_as_device_handle handle, | ||
346 | cy_as_function_callback cb, | ||
347 | uint32_t client | ||
348 | ); | ||
349 | |||
350 | /* Summary | ||
351 | This function sets up a Turbo SendObject operation. | ||
352 | |||
353 | Description | ||
354 | Calling this function will setup West Bridge to | ||
355 | enable Tubo handling of the next SendObject | ||
356 | operation received. This will pass down the initial | ||
357 | block table to the firmware and setup a direct u->s | ||
358 | write for the SendObject operation. | ||
359 | |||
360 | If this function is not called before a SendObject | ||
361 | operation is seen the SendObject operation and data | ||
362 | will be passed along to the P port like any other MTP | ||
363 | command. It would then be the responsibility of the | ||
364 | client to perform a normal StorageWrite call to | ||
365 | store the data on the SD card. N.B. This will be | ||
366 | very slow compared with the Turbo handling. | ||
367 | |||
368 | The completion of this function only signals that | ||
369 | West Bridge has been set up to receive the next SendObject | ||
370 | operation. When the SendObject operation has been fully | ||
371 | handled and the data written to the SD card a separate | ||
372 | event will be triggered. | ||
373 | |||
374 | Returns | ||
375 | * CY_AS_ERROR_SUCCESS | ||
376 | * CY_AS_ERROR_INVALID_HANDLE | ||
377 | * CY_AS_ERROR_NOT_CONFIGURED | ||
378 | * CY_AS_ERROR_NO_FIRMWARE | ||
379 | * CY_AS_ERROR_IN_SUSPEND | ||
380 | * CY_AS_ERROR_NOT_RUNNING | ||
381 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
382 | * CY_AS_ERROR_ASYNC_PENDING | ||
383 | * CY_AS_ERROR_INVALID_RESPONSE | ||
384 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
385 | * firmware with MTP support | ||
386 | |||
387 | See Also | ||
388 | * CyAsMTPCancelSendObject | ||
389 | * CyAsMTPInitGetObject | ||
390 | * CyAsMTPEvent | ||
391 | * CyAsMTPSendBlockTable | ||
392 | */ | ||
393 | cy_as_return_status_t | ||
394 | cy_as_mtp_init_send_object( | ||
395 | cy_as_device_handle handle, | ||
396 | cy_as_mtp_block_table *blk_table, | ||
397 | uint32_t num_bytes, | ||
398 | cy_as_function_callback cb, | ||
399 | uint32_t client | ||
400 | ); | ||
401 | |||
402 | /* Summary | ||
403 | This function cancels an ongoing MTP operation. | ||
404 | |||
405 | Description | ||
406 | Causes West Bridge to cancel an ongoing SendObject | ||
407 | operation. Note this is only a cancel to West Bridge, | ||
408 | the MTP operation still needs to be canceled by | ||
409 | sending a response. | ||
410 | |||
411 | West Bridge will automatically set a Stall on the endpoint | ||
412 | when the cancel is received. | ||
413 | |||
414 | This function is only valid after CyAsMTPInitSendObject | ||
415 | has been called, but before the CyAsMTPSendObjectComplete | ||
416 | event has been sent. | ||
417 | |||
418 | Returns | ||
419 | * CY_AS_ERROR_SUCCESS | ||
420 | * CY_AS_ERROR_INVALID_HANDLE | ||
421 | * CY_AS_ERROR_NOT_RUNNING | ||
422 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
423 | * CY_AS_ERROR_INVALID_RESPONSE | ||
424 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
425 | * firmware with MTP support | ||
426 | * CY_AS_ERROR_NO_OPERATION_PENDING | ||
427 | |||
428 | See Also | ||
429 | * CyAsMTPInitSendObject | ||
430 | */ | ||
431 | cy_as_return_status_t | ||
432 | cy_as_mtp_cancel_send_object( | ||
433 | cy_as_device_handle handle, | ||
434 | cy_as_function_callback cb, | ||
435 | uint32_t client | ||
436 | ); | ||
437 | |||
438 | /* Summary | ||
439 | This function sets up a turbo GetObject operation. | ||
440 | |||
441 | Description | ||
442 | Called by the P in response to a GetObject | ||
443 | operation. This provides West Bridge with the block | ||
444 | addresses for the Object data that needs to be | ||
445 | transferred. | ||
446 | |||
447 | It is the responsibility of the Processor to send the MTP | ||
448 | operation before calling CyAsMTPInitGetObject. West Bridge | ||
449 | will then send the data phase of the transaction, | ||
450 | automatically creating the required container for Data. | ||
451 | Once all of the Data has been transferred a callback will | ||
452 | be issued to inform the Processor that the Data phase has | ||
453 | completed allowing it to send the required MTP response. | ||
454 | |||
455 | If an entire Block Table is used then after the | ||
456 | last block is transferred the CyAsMTPBtCallback | ||
457 | will be called to allow an additional Block Table(s) | ||
458 | to be specified. | ||
459 | |||
460 | Returns | ||
461 | * CY_AS_ERROR_SUCCESS | ||
462 | * CY_AS_ERROR_INVALID_HANDLE | ||
463 | * CY_AS_ERROR_NOT_CONFIGURED | ||
464 | * CY_AS_ERROR_NO_FIRMWARE | ||
465 | * CY_AS_ERROR_NOT_RUNNING | ||
466 | * CY_AS_ERROR_IN_SUSPEND | ||
467 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
468 | * CY_AS_ERROR_ASYNC_PENDING | ||
469 | * CY_AS_ERROR_INVALID_RESPONSE | ||
470 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
471 | * firmware with MTP support | ||
472 | |||
473 | See Also | ||
474 | * CyAsMTPInitSendObject | ||
475 | * CyAsMTPCancelGetObject | ||
476 | * CyAsMTPEvent | ||
477 | * CyAsMTPSendBlockTable | ||
478 | */ | ||
479 | cy_as_return_status_t | ||
480 | cy_as_mtp_init_get_object( | ||
481 | cy_as_device_handle handle, | ||
482 | cy_as_mtp_block_table *table_p, | ||
483 | uint32_t num_bytes, | ||
484 | uint32_t transaction_id, | ||
485 | cy_as_function_callback cb, | ||
486 | uint32_t client | ||
487 | ); | ||
488 | |||
489 | /* Summary | ||
490 | This function cancels an ongoing turbo GetObject | ||
491 | operation. | ||
492 | |||
493 | Description | ||
494 | Causes West Bridge to cancel an ongoing GetObject | ||
495 | operation. Note this is only a cancel to West Bridge, | ||
496 | the MTP operation still needs to be canceled by | ||
497 | sending a response. | ||
498 | |||
499 | This function is only valid after CyAsMTPGetSendObject | ||
500 | has been called, but before the CyAsMTPGetObjectComplete | ||
501 | event has been sent. | ||
502 | |||
503 | Returns | ||
504 | * CY_AS_ERROR_SUCCESS | ||
505 | * CY_AS_ERROR_INVALID_HANDLE | ||
506 | * CY_AS_ERROR_NOT_RUNNING | ||
507 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
508 | * CY_AS_ERROR_INVALID_RESPONSE | ||
509 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
510 | * firmware with MTP support | ||
511 | * CY_AS_ERROR_NO_OPERATION_PENDING | ||
512 | |||
513 | See Also | ||
514 | * CyAsMTPInitGetObject | ||
515 | */ | ||
516 | cy_as_return_status_t | ||
517 | cy_as_mtp_cancel_get_object( | ||
518 | cy_as_device_handle handle, | ||
519 | cy_as_function_callback cb, | ||
520 | uint32_t client | ||
521 | ); | ||
522 | |||
523 | /* Summary | ||
524 | This function is used to transfer a BlockTable as part of | ||
525 | an ongoing MTP operation. | ||
526 | |||
527 | Description | ||
528 | This function is called in response to the | ||
529 | CyAsMTPBlockTableNeeded event. This allows the client to | ||
530 | pass in a BlockTable structure to West Bridge. | ||
531 | |||
532 | The memory associated with the table will be copied and | ||
533 | can be safely disposed of when the function returns if | ||
534 | called synchronously, or when the callback is made if | ||
535 | called asynchronously. | ||
536 | |||
537 | This function is used for both SendObject and GetObject | ||
538 | as both can generate the CyAsMTPBlockTableNeeded event. | ||
539 | |||
540 | Returns | ||
541 | * CY_AS_ERROR_SUCCESS | ||
542 | * CY_AS_ERROR_INVALID_HANDLE | ||
543 | * CY_AS_ERROR_NOT_CONFIGURED | ||
544 | * CY_AS_ERROR_NO_FIRMWARE | ||
545 | * CY_AS_ERROR_NOT_RUNNING | ||
546 | * CY_AS_ERROR_IN_SUSPEND | ||
547 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
548 | * CY_AS_ERROR_ASYNC_PENDING | ||
549 | * CY_AS_ERROR_INVALID_RESPONSE | ||
550 | * CY_AS_ERROR_NOT_SUPPORTED - West Bridge is not running | ||
551 | * firmware with MTP support | ||
552 | |||
553 | See Also | ||
554 | * CyAsMTPInitSendObject | ||
555 | * CyAsMTPInitGetObject | ||
556 | */ | ||
557 | cy_as_return_status_t | ||
558 | cy_as_mtp_send_block_table( | ||
559 | cy_as_device_handle handle, | ||
560 | cy_as_mtp_block_table *table, | ||
561 | cy_as_function_callback cb, | ||
562 | uint32_t client | ||
563 | ); | ||
564 | |||
565 | /* Summary | ||
566 | This function is used to mark the start of a storage | ||
567 | read/write burst from the P port processor. | ||
568 | |||
569 | Description | ||
570 | This function is used to mark the start of a storage | ||
571 | read/write burst from the processor. All USB host access | ||
572 | into the mass storage / MTP endpoints will be blocked | ||
573 | while the read/write burst is ongoing, and will be allowed | ||
574 | to resume only after CyAsMTPStorageOnlyStop is called. | ||
575 | The burst mode is used to reduce the firmware overhead | ||
576 | due to configuring the internal data paths repeatedly, | ||
577 | and can help improve performance when a sequence of | ||
578 | read/writes is performed in a burst. | ||
579 | |||
580 | This function will not generate a special mailbox request, | ||
581 | it will only set a flag on the next Storage Read/Write | ||
582 | operation. Until such a call is made West Bridge will | ||
583 | continue to accept incoming packets from the Host. | ||
584 | |||
585 | * Valid in Asynchronous Callback: YES | ||
586 | |||
587 | Returns | ||
588 | * CY_AS_ERROR_INVALID_HANDLE - Invalid West Bridge device | ||
589 | * handle was passed in. | ||
590 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not | ||
591 | * been configured. | ||
592 | * CY_AS_ERROR_NO_FIRMWARE - Firmware is not active on West | ||
593 | * Bridge device. | ||
594 | * CY_AS_ERROR_NOT_RUNNING - Storage stack is not running. | ||
595 | * CY_AS_ERROR_SUCCESS - Burst mode has been started. | ||
596 | |||
597 | See Also | ||
598 | * CyAsStorageReadWriteBurstStop | ||
599 | */ | ||
600 | cy_as_return_status_t | ||
601 | cy_as_mtp_storage_only_start( | ||
602 | /* Handle to the West Bridge device. */ | ||
603 | cy_as_device_handle handle | ||
604 | ); | ||
605 | |||
606 | /* Summary | ||
607 | This function is used to mark the end of a storage read/write | ||
608 | burst from the P port processor. | ||
609 | |||
610 | Description | ||
611 | This function is used to mark the end of a storage read/write | ||
612 | burst from the processor. At this point, USB access to the | ||
613 | mass storage / MTP endpoints on the West Bridge device will be | ||
614 | re-enabled. | ||
615 | |||
616 | * Valid in Asynchronous Callback: NO | ||
617 | |||
618 | Returns | ||
619 | * CY_AS_ERROR_INVALID_HANDLE - Invalid West Bridge device handle | ||
620 | * was passed in. | ||
621 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not been | ||
622 | * configured. | ||
623 | * CY_AS_ERROR_NO_FIRMWARE - Firmware is not active on West Bridge | ||
624 | * device. | ||
625 | * CY_AS_ERROR_NOT_RUNNING - Storage stack is not running. | ||
626 | * CY_AS_ERROR_INVALID_IN_CALLBACK - This API cannot be called | ||
627 | * from a callback. | ||
628 | * CY_AS_ERROR_OUT_OF_MEMORY - Failed to allocate memory to | ||
629 | * process the request. | ||
630 | * CY_AS_ERROR_TIMEOUT - Failed to send request to firmware. | ||
631 | * CY_AS_ERROR_SUCCESS - Burst mode has been stopped. | ||
632 | |||
633 | See Also | ||
634 | * CyAsStorageReadWriteBurstStart | ||
635 | */ | ||
636 | cy_as_return_status_t | ||
637 | cy_as_mtp_storage_only_stop( | ||
638 | /* Handle to the West Bridge device. */ | ||
639 | cy_as_device_handle handle, | ||
640 | cy_as_function_callback cb, | ||
641 | uint32_t client | ||
642 | ); | ||
643 | |||
644 | #include "cyas_cplus_end.h" | ||
645 | |||
646 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasprotocol.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasprotocol.h deleted file mode 100644 index 773b645ea7eb..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasprotocol.h +++ /dev/null | |||
@@ -1,3838 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasprotocol.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASPROTOCOL_H_ | ||
23 | #define _INCLUDED_CYASPROTOCOL_H_ | ||
24 | |||
25 | /* | ||
26 | * Constants defining the per context buffer sizes | ||
27 | */ | ||
28 | #ifndef __doxygen__ | ||
29 | #define CY_CTX_GEN_MAX_DATA_SIZE (8) | ||
30 | #define CY_CTX_RES_MAX_DATA_SIZE (8) | ||
31 | #define CY_CTX_STR_MAX_DATA_SIZE (64) | ||
32 | #define CY_CTX_USB_MAX_DATA_SIZE (130 + 23) | ||
33 | #define CY_CTX_TUR_MAX_DATA_SIZE (12) | ||
34 | #endif | ||
35 | |||
36 | /* Summary | ||
37 | This response indicates a command has been processed | ||
38 | and returned a status. | ||
39 | |||
40 | Direction | ||
41 | West Bridge -> P Port Processor | ||
42 | P Port Processor -> West Bridge | ||
43 | |||
44 | Length (in transfers) | ||
45 | 1 | ||
46 | |||
47 | Mailbox0 | ||
48 | * Context = all | ||
49 | * Response Code = 0 | ||
50 | |||
51 | D0 | ||
52 | * 0 = success (CY_AS_ERROR_SUCCESS) | ||
53 | * non-zero = error code | ||
54 | |||
55 | Description | ||
56 | This response indicates that a request was processed | ||
57 | and no data was generated as a result of the request | ||
58 | beyond a single 16 bit status value. This response | ||
59 | contains the 16 bit data value. | ||
60 | */ | ||
61 | #define CY_RESP_SUCCESS_FAILURE (0) | ||
62 | |||
63 | /* Summary | ||
64 | This response indicates an invalid request was sent | ||
65 | |||
66 | Direction | ||
67 | West Bridge -> P Port Processor | ||
68 | P Port Processor -> West Bridge | ||
69 | |||
70 | Length (in transfers) | ||
71 | 1 | ||
72 | |||
73 | Mailbox0 | ||
74 | * Context = all | ||
75 | * Response Code = 1 | ||
76 | |||
77 | D0 | ||
78 | * Mailbox contents for invalid request | ||
79 | |||
80 | Description | ||
81 | This response is returned when a request is sent | ||
82 | that contains an invalid | ||
83 | context or request code. | ||
84 | */ | ||
85 | #define CY_RESP_INVALID_REQUEST (1) | ||
86 | |||
87 | /* Summary | ||
88 | This response indicates a request of invalid length was sent | ||
89 | |||
90 | Direction | ||
91 | West Bridge -> P Port Processor | ||
92 | P Port Processor -> West Bridge | ||
93 | |||
94 | Length (in transfers) | ||
95 | 1 | ||
96 | |||
97 | Mailbox0 | ||
98 | * Context = all | ||
99 | * Response Code = 2 | ||
100 | |||
101 | D0 | ||
102 | * Mailbox contenxt for invalid request | ||
103 | * Length for invalid request | ||
104 | |||
105 | Description | ||
106 | The software API and firmware sends requests across the | ||
107 | P Port to West Bridge interface on different contexts. | ||
108 | Each contexts has a maximum size of the request packet | ||
109 | that can be received. The size of a request can be | ||
110 | determined during the first cycle of a request transfer. | ||
111 | If the request is larger than can be handled by the | ||
112 | receiving context this response is returned. Note that | ||
113 | the complete request is received before this response is | ||
114 | sent, but that the request is dropped after this response | ||
115 | is sent. | ||
116 | */ | ||
117 | #define CY_RESP_INVALID_LENGTH (2) | ||
118 | |||
119 | |||
120 | /* Summary | ||
121 | This response indicates a request was made to an | ||
122 | invalid storage address. | ||
123 | |||
124 | Direction | ||
125 | West Bridge -> P Port Processor | ||
126 | |||
127 | Length (in transfers) | ||
128 | 1 | ||
129 | |||
130 | Mailbox0 | ||
131 | * Context = all | ||
132 | * Response Code = 0 | ||
133 | |||
134 | D0 | ||
135 | Bits 15 - 12 : Media Type | ||
136 | * 0 = NAND | ||
137 | * 1 = SD Flash | ||
138 | * 2 = MMC Flash | ||
139 | * 3 = CE-ATA | ||
140 | |||
141 | Bits 11 - 8 : Zero based device index | ||
142 | |||
143 | Bits 7 - 0 : Zero based unit index | ||
144 | |||
145 | D1 | ||
146 | Upper 16 bits of block address | ||
147 | |||
148 | D2 | ||
149 | Lower 16 bits of block address | ||
150 | |||
151 | D3 | ||
152 | Portion of address that is invalid | ||
153 | * 0 = Media Type | ||
154 | * 1 = Device Index | ||
155 | * 2 = Unit Index | ||
156 | * 3 = Block Address | ||
157 | |||
158 | Description | ||
159 | This response indicates a request to an invalid storage media | ||
160 | address | ||
161 | */ | ||
162 | #define CY_RESP_NO_SUCH_ADDRESS (3) | ||
163 | |||
164 | |||
165 | /******************************************************/ | ||
166 | |||
167 | /*@@General requests | ||
168 | Summary | ||
169 | The general requests include: | ||
170 | * CY_RQT_GET_FIRMWARE_VERSION | ||
171 | * CY_RQT_SET_TRACE_LEVEL | ||
172 | * CY_RQT_INITIALIZATION_COMPLETE | ||
173 | * CY_RQT_READ_MCU_REGISTER | ||
174 | * CY_RQT_WRITE_MCU_REGISTER | ||
175 | * CY_RQT_STORAGE_MEDIA_CHANGED | ||
176 | * CY_RQT_CONTROL_ANTIOCH_HEARTBEAT | ||
177 | * CY_RQT_PREPARE_FOR_STANDBY | ||
178 | * CY_RQT_ENTER_SUSPEND_MODE | ||
179 | * CY_RQT_OUT_OF_SUSPEND | ||
180 | * CY_RQT_GET_GPIO_STATE | ||
181 | * CY_RQT_SET_GPIO_STATE | ||
182 | * CY_RQT_SET_SD_CLOCK_FREQ | ||
183 | * CY_RQT_WB_DEVICE_MISMATCH | ||
184 | * CY_RQT_BOOTLOAD_NO_FIRMWARE | ||
185 | * CY_RQT_RESERVE_LNA_BOOT_AREA | ||
186 | * CY_RQT_ABORT_P2S_XFER | ||
187 | */ | ||
188 | |||
189 | #ifndef __doxygen__ | ||
190 | #define CY_RQT_GENERAL_RQT_CONTEXT (0) | ||
191 | #endif | ||
192 | |||
193 | /* Summary | ||
194 | This command returns the firmware version number, | ||
195 | media types supported and debug/release mode information. | ||
196 | |||
197 | Direction | ||
198 | P Port Processor-> West Bridge | ||
199 | |||
200 | Length (in transfers) | ||
201 | 1 | ||
202 | |||
203 | MailBox0 | ||
204 | * Context = 0 | ||
205 | * Request Code = 0 | ||
206 | |||
207 | Description | ||
208 | The response contains the 16-bit major version, the | ||
209 | 16-bit minor version, the 16 bit build number, media | ||
210 | types supported and release/debug mode information. | ||
211 | |||
212 | Responses | ||
213 | * CY_RESP_FIRMWARE_VERSION | ||
214 | */ | ||
215 | #define CY_RQT_GET_FIRMWARE_VERSION (0) | ||
216 | |||
217 | |||
218 | /* Summary | ||
219 | This command changes the trace level and trace information | ||
220 | destination within the West Bridge firmware. | ||
221 | |||
222 | Direction | ||
223 | P Port Processor-> West Bridge | ||
224 | |||
225 | Length (in transfers) | ||
226 | 1 | ||
227 | |||
228 | MailBox0 | ||
229 | * Context = 0 | ||
230 | * Request Code = 1 | ||
231 | |||
232 | D0 | ||
233 | Trace Level | ||
234 | * 0 = no trace information | ||
235 | * 1 = state information | ||
236 | * 2 = function call | ||
237 | * 3 = function call with args/return value | ||
238 | |||
239 | D1 | ||
240 | Bits 12 - 15 : MediaType | ||
241 | * 0 = NAND | ||
242 | * 1 = SDIO Flash | ||
243 | * 2 = MMC Flash | ||
244 | * 3 = CE-ATA | ||
245 | |||
246 | Bits 8 - 11 : Zero based device index | ||
247 | |||
248 | Bits 0 - 7 : Zero based unit index | ||
249 | |||
250 | Description | ||
251 | The West Bridge firmware contains debugging facilities that can | ||
252 | be used to trace the execution of the firmware. This request | ||
253 | sets the level of tracing information that is stored and the | ||
254 | location where it is stored. | ||
255 | |||
256 | Responses | ||
257 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
258 | * CY_RESP_NO_SUCH_ADDRESS | ||
259 | */ | ||
260 | #define CY_RQT_SET_TRACE_LEVEL (1) | ||
261 | |||
262 | /* Summary | ||
263 | This command indicates that the firmware is up and ready | ||
264 | for communications with the P port processor. | ||
265 | |||
266 | Direction | ||
267 | West Bridge -> P Port Processor | ||
268 | |||
269 | Length (in transfers) | ||
270 | 2 | ||
271 | |||
272 | Mailbox0 | ||
273 | * Context = 0 | ||
274 | * Request Code = 3 | ||
275 | |||
276 | D0 | ||
277 | Major Version | ||
278 | |||
279 | D1 | ||
280 | Minor Version | ||
281 | |||
282 | D2 | ||
283 | Build Number | ||
284 | |||
285 | D3 | ||
286 | Bits 15-8: Media types supported on Bus 1. | ||
287 | Bits 7-0: Media types supported on Bus 0. | ||
288 | Bits 8, 0: NAND support. | ||
289 | * 0: NAND is not supported. | ||
290 | * 1: NAND is supported. | ||
291 | Bits 9, 1: SD memory card support. | ||
292 | * 0: SD memory card is not supported. | ||
293 | * 1: SD memory card is supported. | ||
294 | Bits 10, 2: MMC card support. | ||
295 | * 0: MMC card is not supported. | ||
296 | * 1: MMC card is supported. | ||
297 | Bits 11, 3: CEATA drive support | ||
298 | * 0: CEATA drive is not supported. | ||
299 | * 1: CEATA drive is supported. | ||
300 | Bits 12, 4: SD IO card support. | ||
301 | * 0: SD IO card is not supported. | ||
302 | * 1: SD IO card is supported. | ||
303 | |||
304 | D4 | ||
305 | Bits 15 - 8 : MTP information | ||
306 | * 0 : MTP not supported in firmware | ||
307 | * 1 : MTP supported in firmware | ||
308 | Bits 7 - 0 : Debug/Release mode information. | ||
309 | * 0 : Release mode | ||
310 | * 1 : Debug mode | ||
311 | |||
312 | Description | ||
313 | When the West Bridge firmware is loaded it being by performing | ||
314 | initialization. Initialization must be complete before West | ||
315 | Bridge is ready to accept requests from the P port processor. | ||
316 | This request is sent from West Bridge to the P port processor | ||
317 | to indicate that initialization is complete. | ||
318 | |||
319 | Responses | ||
320 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
321 | */ | ||
322 | #define CY_RQT_INITIALIZATION_COMPLETE (3) | ||
323 | |||
324 | /* Summary | ||
325 | This command requests the firmware to read and return the contents | ||
326 | of a MCU accessible | ||
327 | register. | ||
328 | |||
329 | Direction | ||
330 | P Port Processor -> West Bridge | ||
331 | |||
332 | Length (in transfers) | ||
333 | 1 | ||
334 | |||
335 | Mailbox0 | ||
336 | * Context = 0 | ||
337 | * Request code = 4 | ||
338 | |||
339 | D0 | ||
340 | Address of register to read | ||
341 | |||
342 | Description | ||
343 | This debug command allows the processor to read the contents of | ||
344 | a MCU accessible register. | ||
345 | |||
346 | Responses | ||
347 | * CY_RESP_MCU_REGISTER_DATA | ||
348 | */ | ||
349 | #define CY_RQT_READ_MCU_REGISTER (4) | ||
350 | |||
351 | /* Summary | ||
352 | This command requests the firmware to write to an MCU | ||
353 | accessible register. | ||
354 | |||
355 | Direction | ||
356 | P Port Processor -> West Bridge | ||
357 | |||
358 | Length (in transfers) | ||
359 | 1 | ||
360 | |||
361 | Mailbox0 | ||
362 | * Context = 0 | ||
363 | * Request code = 5 | ||
364 | |||
365 | D0 | ||
366 | Address of register to be written | ||
367 | |||
368 | D1 | ||
369 | Bits 15 - 8 : Mask to be applied to existing data. | ||
370 | Bits 7 - 0 : Data to be ORed with masked data. | ||
371 | |||
372 | Description | ||
373 | This debug command allows the processor to write to an MCU | ||
374 | accessible register. | ||
375 | Note: This has to be used with caution, and is supported by | ||
376 | the firmware only in special debug builds. | ||
377 | |||
378 | Responses | ||
379 | * CY_RESP_SUCCESS_FAILURE | ||
380 | */ | ||
381 | #define CY_RQT_WRITE_MCU_REGISTER (5) | ||
382 | |||
383 | /* Summary | ||
384 | This command tells the West Bridge firmware that a change in | ||
385 | storage media has been detected. | ||
386 | |||
387 | Direction | ||
388 | P Port Processor -> West Bridge | ||
389 | |||
390 | Length (in transfers) | ||
391 | 1 | ||
392 | |||
393 | Mailbox0 | ||
394 | * Context = 0 | ||
395 | * Request code = 6 | ||
396 | |||
397 | Description | ||
398 | If the insertion or removal of SD or MMC cards is detected by | ||
399 | hardware external to West Bridge, this command is used to tell | ||
400 | the West Bridge firmware to re-initialize the storage controlled | ||
401 | by the device. | ||
402 | |||
403 | Responses | ||
404 | * CY_RESP_SUCCESS_FAILURE | ||
405 | */ | ||
406 | #define CY_RQT_STORAGE_MEDIA_CHANGED (6) | ||
407 | |||
408 | /* Summary | ||
409 | This command enables/disables the periodic heartbeat message | ||
410 | from the West Bridge firmware to the processor. | ||
411 | |||
412 | Direction | ||
413 | P Port Processor -> West Bridge | ||
414 | |||
415 | Length (in transfers) | ||
416 | 1 | ||
417 | |||
418 | Mailbox0 | ||
419 | * Context = 0 | ||
420 | * Request code = 7 | ||
421 | |||
422 | Description | ||
423 | This command enables/disables the periodic heartbeat message | ||
424 | from the West Bridge firmware to the processor. The heartbeat | ||
425 | message is left enabled by default, and can lead to a loss | ||
426 | in performance on the P port interface. | ||
427 | |||
428 | Responses | ||
429 | * CY_RESP_SUCCESS_FAILURE | ||
430 | */ | ||
431 | #define CY_RQT_CONTROL_ANTIOCH_HEARTBEAT (7) | ||
432 | |||
433 | /* Summary | ||
434 | This command requests the West Bridge firmware to prepare for | ||
435 | the device going into standby | ||
436 | mode. | ||
437 | |||
438 | Direction | ||
439 | P Port Processor -> West Bridge | ||
440 | |||
441 | Length (in transfers) | ||
442 | 1 | ||
443 | |||
444 | Mailbox0 | ||
445 | * Context = 0 | ||
446 | * Request code = 8 | ||
447 | |||
448 | Description | ||
449 | This command is sent by the processor to the West Bridge as | ||
450 | preparation for going into standby mode. The request allows the | ||
451 | firmware to complete any pending/cached storage operations before | ||
452 | going into the low power state. | ||
453 | |||
454 | Responses | ||
455 | * CY_RESP_SUCCESS_FAILURE | ||
456 | */ | ||
457 | #define CY_RQT_PREPARE_FOR_STANDBY (8) | ||
458 | |||
459 | /* Summary | ||
460 | Requests the firmware to go into suspend mode. | ||
461 | |||
462 | Direction | ||
463 | P Port Processor -> West Bridge | ||
464 | |||
465 | Length (in transfers) | ||
466 | 1 | ||
467 | |||
468 | Mailbox0 | ||
469 | * Context = 0 | ||
470 | * Request code = 9 | ||
471 | |||
472 | D0 | ||
473 | Bits 7-0: Wakeup control information. | ||
474 | |||
475 | Description | ||
476 | This command is sent by the processor to the West Bridge to | ||
477 | request the device to be placed in suspend mode. The firmware | ||
478 | will complete any pending/cached storage operations before | ||
479 | going into the low power state. | ||
480 | |||
481 | Responses | ||
482 | * CY_RESP_SUCCESS_FAILURE | ||
483 | */ | ||
484 | #define CY_RQT_ENTER_SUSPEND_MODE (9) | ||
485 | |||
486 | /* Summary | ||
487 | Indicates that the device has left suspend mode. | ||
488 | |||
489 | Direction | ||
490 | West Bridge -> P Port Processor | ||
491 | |||
492 | Length (in transfers) | ||
493 | 1 | ||
494 | |||
495 | Mailbox0 | ||
496 | * Context = 0 | ||
497 | * Request code = 10 | ||
498 | |||
499 | Description | ||
500 | This message is sent by the West Bridge to the Processor | ||
501 | to indicate that the device has woken up from suspend mode, | ||
502 | and is ready to accept new requests. | ||
503 | |||
504 | Responses | ||
505 | * CY_RESP_SUCCESS_FAILURE | ||
506 | */ | ||
507 | #define CY_RQT_OUT_OF_SUSPEND (10) | ||
508 | |||
509 | /* Summary | ||
510 | Request to get the current state of an West Bridge GPIO pin. | ||
511 | |||
512 | Direction | ||
513 | P Port Processor -> West Bridge | ||
514 | |||
515 | Length (in transfers) | ||
516 | 1 | ||
517 | |||
518 | Mailbox0 | ||
519 | * Context = 0 | ||
520 | * Request code = 11 | ||
521 | |||
522 | D0 | ||
523 | Bits 15 - 8 : GPIO pin identifier | ||
524 | |||
525 | Responses | ||
526 | * CY_RESP_GPIO_STATE | ||
527 | |||
528 | Description | ||
529 | Request from the processor to get the current state of | ||
530 | an West Bridge GPIO pin. | ||
531 | */ | ||
532 | #define CY_RQT_GET_GPIO_STATE (11) | ||
533 | |||
534 | /* Summary | ||
535 | Request to update the output value on an West Bridge | ||
536 | GPIO pin. | ||
537 | |||
538 | Direction | ||
539 | P Port Processor -> West Bridge | ||
540 | |||
541 | Length (in transfers) | ||
542 | 1 | ||
543 | |||
544 | Mailbox0 | ||
545 | * Context = 0 | ||
546 | * Request code = 12 | ||
547 | |||
548 | D0 | ||
549 | Bits 15 - 8 : GPIO pin identifier | ||
550 | Bit 0 : Desired output state | ||
551 | |||
552 | Responses | ||
553 | * CY_RESP_SUCCESS_FAILURE | ||
554 | |||
555 | Description | ||
556 | Request from the processor to update the output value on | ||
557 | an West Bridge GPIO pin. | ||
558 | */ | ||
559 | #define CY_RQT_SET_GPIO_STATE (12) | ||
560 | |||
561 | /* Summary | ||
562 | Set the clock frequency on the SD interface of the West | ||
563 | Bridge device. | ||
564 | |||
565 | Direction | ||
566 | P Port Processor -> West Bridge | ||
567 | |||
568 | Length (in transfers) | ||
569 | 1 | ||
570 | |||
571 | Mailbox0 | ||
572 | * Context = 0 | ||
573 | * Request code = 13 | ||
574 | |||
575 | D0 | ||
576 | Bit 8: Type of SD/MMC media | ||
577 | 0 = low speed media | ||
578 | 1 = high speed media | ||
579 | Bit 0: Clock frequency selection | ||
580 | 0 = Default frequency | ||
581 | 1 = Alternate frequency (24 MHz in both cases) | ||
582 | |||
583 | Description | ||
584 | This request is sent by the processor to set the operating clock | ||
585 | frequency used on the SD interface of the device. | ||
586 | |||
587 | Responses | ||
588 | * CY_RESP_SUCCESS_FAILURE | ||
589 | */ | ||
590 | #define CY_RQT_SET_SD_CLOCK_FREQ (13) | ||
591 | |||
592 | /* Summary | ||
593 | Indicates the firmware downloaded to West Bridge cannot | ||
594 | run on the active device. | ||
595 | |||
596 | Direction | ||
597 | West Bridge -> P Port processor | ||
598 | |||
599 | Length (in transfers) | ||
600 | 1 | ||
601 | |||
602 | Mailbox0 | ||
603 | * Context = 0 | ||
604 | * Request code = 14 | ||
605 | |||
606 | Description | ||
607 | Some versions of West Bridge firmware can only run on specific | ||
608 | types/versions of the West Bridge device. This error is | ||
609 | returned when a firmware image is downloaded onto a device that | ||
610 | does not support it. | ||
611 | |||
612 | Responses | ||
613 | * None | ||
614 | */ | ||
615 | #define CY_RQT_WB_DEVICE_MISMATCH (14) | ||
616 | |||
617 | /* Summary | ||
618 | This command is indicates that no firmware was found in the | ||
619 | storage media. | ||
620 | |||
621 | Direction | ||
622 | West Bridge -> P Port Processor | ||
623 | |||
624 | Length (in transfers) | ||
625 | 1 | ||
626 | |||
627 | Mailbox0 | ||
628 | * Context = 0 | ||
629 | * Request code = 15 | ||
630 | |||
631 | Description | ||
632 | The command is received only in case of silicon with bootloader | ||
633 | ROM. The device sends the request if there is no firmware image | ||
634 | found in the storage media or the image is corrupted. The | ||
635 | device is waiting for P port to download a valid firmware image. | ||
636 | |||
637 | Responses | ||
638 | * None | ||
639 | */ | ||
640 | #define CY_RQT_BOOTLOAD_NO_FIRMWARE (15) | ||
641 | |||
642 | /* Summary | ||
643 | This command reserves first numzones zones of nand device for | ||
644 | storing processor boot image. | ||
645 | |||
646 | Direction | ||
647 | P Port Processor-> West Bridge | ||
648 | |||
649 | Length (in transfers) | ||
650 | 1 | ||
651 | |||
652 | MailBox0 | ||
653 | * Context = 0 | ||
654 | * Request Code = 16 | ||
655 | |||
656 | D0 | ||
657 | Bits 7-0: numzones | ||
658 | |||
659 | Description | ||
660 | The first numzones zones in nand device will be used for storing | ||
661 | proc boot image. LNA firmware in Astoria will work on this nand | ||
662 | area and boots the processor which will then use the remaining | ||
663 | nand for usual purposes. | ||
664 | |||
665 | Responses | ||
666 | * CY_RESP_SUCCESS_FAILURE | ||
667 | */ | ||
668 | #define CY_RQT_RESERVE_LNA_BOOT_AREA (16) | ||
669 | |||
670 | /* Summary | ||
671 | This command cancels the processing of a P2S operation in | ||
672 | firmware. | ||
673 | |||
674 | Direction | ||
675 | P Port Processor -> West Bridge | ||
676 | |||
677 | Length (in transfers) | ||
678 | 1 | ||
679 | |||
680 | MailBox0 | ||
681 | * Context = 0 | ||
682 | * Request Code = 17 | ||
683 | |||
684 | Responses | ||
685 | * CY_RESP_SUCCESS_FAILURE | ||
686 | */ | ||
687 | #define CY_RQT_ABORT_P2S_XFER (17) | ||
688 | |||
689 | /* | ||
690 | * Used for debugging, ignore for normal operations | ||
691 | */ | ||
692 | #ifndef __doxygen__ | ||
693 | #define CY_RQT_DEBUG_MESSAGE (127) | ||
694 | #endif | ||
695 | |||
696 | /******************************************************/ | ||
697 | |||
698 | /*@@General responses | ||
699 | Summary | ||
700 | The general responses include: | ||
701 | * CY_RESP_FIRMWARE_VERSION | ||
702 | * CY_RESP_MCU_REGISTER_DATA | ||
703 | * CY_RESP_GPIO_STATE | ||
704 | */ | ||
705 | |||
706 | |||
707 | /* Summary | ||
708 | This response indicates success and contains the firmware | ||
709 | version number, media types supported by the firmware and | ||
710 | release/debug mode information. | ||
711 | |||
712 | Direction | ||
713 | West Bridge -> P Port Processor | ||
714 | |||
715 | Length (in transfers) | ||
716 | 2 | ||
717 | |||
718 | MailBox0 | ||
719 | * Context = 0 | ||
720 | * Response Code = 16 | ||
721 | |||
722 | D0 | ||
723 | Major Version | ||
724 | |||
725 | D1 | ||
726 | Minor Version | ||
727 | |||
728 | D2 | ||
729 | Build Number | ||
730 | |||
731 | D3 | ||
732 | Bits 15-8: Media types supported on Bus 1. | ||
733 | Bits 7-0: Media types supported on Bus 0. | ||
734 | Bits 8, 0: NAND support. | ||
735 | * 0: NAND is not supported. | ||
736 | * 1: NAND is supported. | ||
737 | Bits 9, 1: SD memory card support. | ||
738 | * 0: SD memory card is not supported. | ||
739 | * 1: SD memory card is supported. | ||
740 | Bits 10, 2: MMC card support. | ||
741 | * 0: MMC card is not supported. | ||
742 | * 1: MMC card is supported. | ||
743 | Bits 11, 3: CEATA drive support | ||
744 | * 0: CEATA drive is not supported. | ||
745 | * 1: CEATA drive is supported. | ||
746 | Bits 12, 4: SD IO card support. | ||
747 | * 0: SD IO card is not supported. | ||
748 | * 1: SD IO card is supported. | ||
749 | |||
750 | D4 | ||
751 | Bits 15 - 8 : MTP information | ||
752 | * 0 : MTP not supported in firmware | ||
753 | * 1 : MTP supported in firmware | ||
754 | Bits 7 - 0 : Debug/Release mode information. | ||
755 | * 0 : Release mode | ||
756 | * 1 : Debug mode | ||
757 | |||
758 | Description | ||
759 | This response is sent to return the firmware version | ||
760 | number to the requestor. | ||
761 | */ | ||
762 | #define CY_RESP_FIRMWARE_VERSION (16) | ||
763 | |||
764 | /* Summary | ||
765 | This response returns the contents of a MCU accessible | ||
766 | register to the processor. | ||
767 | |||
768 | Direction | ||
769 | West Bridge -> P Port Processor | ||
770 | |||
771 | Length (in transfers) | ||
772 | 1 | ||
773 | |||
774 | MailBox0 | ||
775 | * Context = 0 | ||
776 | * Response code = 17 | ||
777 | |||
778 | D0 | ||
779 | Bits 7 - 0 : MCU register contents | ||
780 | |||
781 | Description | ||
782 | This response is sent by the firmware in response to the | ||
783 | CY_RQT_READ_MCU_REGISTER | ||
784 | command. | ||
785 | */ | ||
786 | #define CY_RESP_MCU_REGISTER_DATA (17) | ||
787 | |||
788 | /* Summary | ||
789 | Reports the current state of an West Bridge GPIO pin. | ||
790 | |||
791 | Direction | ||
792 | West Bridge -> P Port Processor | ||
793 | |||
794 | Length (in transfers) | ||
795 | 1 | ||
796 | |||
797 | MailBox0 | ||
798 | * Context = 0 | ||
799 | * Request code = 18 | ||
800 | |||
801 | D0 | ||
802 | Bit 0: Current state of the GP input pin | ||
803 | |||
804 | Description | ||
805 | This response is sent by the West Bridge to report the | ||
806 | current state observed on a general purpose input pin. | ||
807 | */ | ||
808 | #define CY_RESP_GPIO_STATE (18) | ||
809 | |||
810 | |||
811 | /* Summary | ||
812 | This command notifies West Bridge the polarity of the | ||
813 | SD power pin | ||
814 | |||
815 | Direction | ||
816 | P Port Processor -> West Bridge | ||
817 | |||
818 | Length (in transfers) | ||
819 | 1 | ||
820 | |||
821 | MailBox0 | ||
822 | * Context = 0 | ||
823 | * Request Code = 19 | ||
824 | D0: CyAnMiscActivehigh / CyAnMiscActivelow | ||
825 | |||
826 | Responses | ||
827 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
828 | |||
829 | */ | ||
830 | |||
831 | #define CY_RQT_SDPOLARITY (19) | ||
832 | |||
833 | /******************************/ | ||
834 | |||
835 | /*@@Resource requests | ||
836 | Summary | ||
837 | |||
838 | The resource requests include: | ||
839 | * CY_RQT_ACQUIRE_RESOURCE | ||
840 | * CY_RQT_RELEASE_RESOURCE | ||
841 | */ | ||
842 | |||
843 | |||
844 | |||
845 | |||
846 | |||
847 | #ifndef __doxygen__ | ||
848 | #define CY_RQT_RESOURCE_RQT_CONTEXT (1) | ||
849 | #endif | ||
850 | |||
851 | |||
852 | /* Summary | ||
853 | This command is a request from the P port processor | ||
854 | for ownership of a resource. | ||
855 | |||
856 | Direction | ||
857 | P Port Processor -> West Bridge | ||
858 | |||
859 | Length (in transfers) | ||
860 | 1 | ||
861 | |||
862 | MailBox0 | ||
863 | * Context = 1 | ||
864 | * Request Code = 0 | ||
865 | |||
866 | D0 | ||
867 | Resource | ||
868 | * 0 = USB | ||
869 | * 1 = SDIO/MMC | ||
870 | * 2 = NAND | ||
871 | |||
872 | D1 | ||
873 | Force Flag | ||
874 | * 0 = Normal | ||
875 | * 1 = Force | ||
876 | |||
877 | Description | ||
878 | The resource may be the USB pins, the SDIO/MMC bus, | ||
879 | or the NAND bus. | ||
880 | |||
881 | Responses | ||
882 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
883 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_NOT_RELEASED | ||
884 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_RESOURCE | ||
885 | */ | ||
886 | #define CY_RQT_ACQUIRE_RESOURCE (0) | ||
887 | |||
888 | |||
889 | /* Summary | ||
890 | This command is a request from the P port processor | ||
891 | to release ownership of a resource. | ||
892 | |||
893 | Direction | ||
894 | P Port Processor -> West Bridge | ||
895 | |||
896 | Length (in transfers) | ||
897 | 1 | ||
898 | |||
899 | MailBox0 | ||
900 | * Context = 1 | ||
901 | * Request Code = 1 | ||
902 | |||
903 | D0 | ||
904 | Resource | ||
905 | * 0 = USB | ||
906 | * 1 = SDIO/MMC | ||
907 | * 2 = NAND | ||
908 | |||
909 | Description | ||
910 | The resource may be the USB pins, the SDIO/MMC bus, or | ||
911 | the NAND bus. | ||
912 | |||
913 | Responses | ||
914 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
915 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_NOT_OWNER | ||
916 | */ | ||
917 | #define CY_RQT_RELEASE_RESOURCE (1) | ||
918 | |||
919 | |||
920 | /****************************/ | ||
921 | |||
922 | /*@@Storage requests | ||
923 | Summary | ||
924 | The storage commands include: | ||
925 | * CY_RQT_START_STORAGE | ||
926 | * CY_RQT_STOP_STORAGE | ||
927 | * CY_RQT_CLAIM_STORAGE | ||
928 | * CY_RQT_RELEASE_STORAGE | ||
929 | * CY_RQT_QUERY_MEDIA | ||
930 | * CY_RQT_QUERY_DEVICE | ||
931 | * CY_RQT_QUERY_UNIT | ||
932 | * CY_RQT_READ_BLOCK | ||
933 | * CY_RQT_WRITE_BLOCK | ||
934 | * CY_RQT_MEDIA_CHANGED | ||
935 | * CY_RQT_ANTIOCH_CLAIM | ||
936 | * CY_RQT_ANTIOCH_RELEASE | ||
937 | * CY_RQT_SD_INTERFACE_CONTROL | ||
938 | * CY_RQT_SD_REGISTER_READ | ||
939 | * CY_RQT_CHECK_CARD_LOCK | ||
940 | * CY_RQT_QUERY_BUS | ||
941 | * CY_RQT_PARTITION_STORAGE | ||
942 | * CY_RQT_PARTITION_ERASE | ||
943 | * CY_RQT_GET_TRANSFER_AMOUNT | ||
944 | * CY_RQT_ERASE | ||
945 | * CY_RQT_SDIO_READ_DIRECT | ||
946 | * CY_RQT_SDIO_WRITE_DIRECT | ||
947 | * CY_RQT_SDIO_READ_EXTENDED | ||
948 | * CY_RQT_SDIO_WRITE_EXTENDED | ||
949 | * CY_RQT_SDIO_INIT_FUNCTION | ||
950 | * CY_RQT_SDIO_QUERY_CARD | ||
951 | * CY_RQT_SDIO_GET_TUPLE | ||
952 | * CY_RQT_SDIO_ABORT_IO | ||
953 | * CY_RQT_SDIO_INTR | ||
954 | * CY_RQT_SDIO_SUSPEND | ||
955 | * CY_RQT_SDIO_RESUME | ||
956 | * CY_RQT_SDIO_RESET_DEV | ||
957 | * CY_RQT_P2S_DMA_START | ||
958 | */ | ||
959 | #ifndef __doxygen__ | ||
960 | #define CY_RQT_STORAGE_RQT_CONTEXT (2) | ||
961 | #endif | ||
962 | |||
963 | /* Summary | ||
964 | This command requests initialization of the storage stack. | ||
965 | |||
966 | Direction | ||
967 | P Port Processor -> West Bridge | ||
968 | |||
969 | Length (in transfers) | ||
970 | 1 | ||
971 | |||
972 | MailBox0 | ||
973 | * Context = 2 | ||
974 | * Request Code = 0 | ||
975 | |||
976 | Description | ||
977 | This command is required before any other storage related command | ||
978 | can be send to the West Bridge firmware. | ||
979 | |||
980 | Responses | ||
981 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
982 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_ALREADY_RUNNING | ||
983 | */ | ||
984 | #define CY_RQT_START_STORAGE (0) | ||
985 | |||
986 | |||
987 | /* Summary | ||
988 | This command requests shutdown of the storage stack. | ||
989 | |||
990 | Direction | ||
991 | P Port Processor -> West Bridge | ||
992 | |||
993 | Length (in transfers) | ||
994 | 1 | ||
995 | |||
996 | MailBox0 | ||
997 | * Context = 2 | ||
998 | * Request Code = 1 | ||
999 | |||
1000 | Responses | ||
1001 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1002 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_NOT_RUNNING | ||
1003 | */ | ||
1004 | #define CY_RQT_STOP_STORAGE (1) | ||
1005 | |||
1006 | |||
1007 | /* Summary | ||
1008 | This command requests ownership of the given media | ||
1009 | type by the P port processor. | ||
1010 | |||
1011 | Direction | ||
1012 | P Port Processor -> West Bridge | ||
1013 | |||
1014 | Length (in transfers) | ||
1015 | 1 | ||
1016 | |||
1017 | MailBox0 | ||
1018 | * Context = 2 | ||
1019 | * Request Code = 2 | ||
1020 | |||
1021 | D0 | ||
1022 | Bits 12 - 15 : Bus Index | ||
1023 | Bits 8 - 11 : Zero based device index | ||
1024 | |||
1025 | Responses | ||
1026 | * CY_RESP_MEDIA_CLAIMED_RELEASED | ||
1027 | * CY_RESP_NO_SUCH_ADDRESS | ||
1028 | */ | ||
1029 | #define CY_RQT_CLAIM_STORAGE (2) | ||
1030 | |||
1031 | |||
1032 | /* Summary | ||
1033 | This command releases ownership of a given media type | ||
1034 | by the P port processor. | ||
1035 | |||
1036 | Direction | ||
1037 | P Port Processor -> West Bridge | ||
1038 | |||
1039 | Length (in transfers) | ||
1040 | 1 | ||
1041 | |||
1042 | MailBox0 | ||
1043 | * Context = 2 | ||
1044 | * Request Code = 3 | ||
1045 | |||
1046 | D0 | ||
1047 | Bits 12 - 15 : Bus Index | ||
1048 | Bits 8 - 11 : Zero based device index | ||
1049 | |||
1050 | Responses | ||
1051 | * CY_RESP_MEDIA_CLAIMED_RELEASED | ||
1052 | * CY_RESP_NO_SUCH_ADDRESS | ||
1053 | */ | ||
1054 | #define CY_RQT_RELEASE_STORAGE (3) | ||
1055 | |||
1056 | |||
1057 | /* Summary | ||
1058 | This command returns the total number of logical devices | ||
1059 | of the given type of media. | ||
1060 | |||
1061 | Direction | ||
1062 | P Port Processor -> West Bridge | ||
1063 | |||
1064 | Length (in transfers) | ||
1065 | 1 | ||
1066 | |||
1067 | MailBox0 | ||
1068 | * Context = 2 | ||
1069 | * Request Code = 4 | ||
1070 | |||
1071 | D0 | ||
1072 | Bits 12 - 15 : MediaType | ||
1073 | * 0 = NAND | ||
1074 | * 1 = SDIO Flash | ||
1075 | * 2 = MMC Flash | ||
1076 | * 3 = CE-ATA | ||
1077 | |||
1078 | Bits 8 - 11 : Not Used | ||
1079 | |||
1080 | Bits 0 - 7 : Not Used | ||
1081 | |||
1082 | Responses | ||
1083 | * CY_RESP_MEDIA_DESCRIPTOR | ||
1084 | * CY_RESP_NO_SUCH_ADDRESS | ||
1085 | */ | ||
1086 | #define CY_RQT_QUERY_MEDIA (4) | ||
1087 | |||
1088 | |||
1089 | /* Summary | ||
1090 | This command queries a given device to determine | ||
1091 | information about the number of logical units on | ||
1092 | the given device. | ||
1093 | |||
1094 | Direction | ||
1095 | P Port Processor -> West Bridge | ||
1096 | |||
1097 | Length (in transfers) | ||
1098 | 1 | ||
1099 | |||
1100 | MailBox0 | ||
1101 | * Context = 2 | ||
1102 | * Request Code = 5 | ||
1103 | |||
1104 | D0 | ||
1105 | Bits 12 - 15 : Bus index | ||
1106 | Bits 8 - 11 : Zero based device index | ||
1107 | Bits 0 - 7 : Not Used | ||
1108 | |||
1109 | Responses | ||
1110 | * CY_RESP_DEVICE_DESCRIPTOR | ||
1111 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_INVALID_PARTITION_TABLE | ||
1112 | * CY_RESP_NO_SUCH_ADDRESS | ||
1113 | */ | ||
1114 | #define CY_RQT_QUERY_DEVICE (5) | ||
1115 | |||
1116 | |||
1117 | /* Summary | ||
1118 | This command queries a given device to determine | ||
1119 | information about the size and location of a logical unit | ||
1120 | located on a physical device. | ||
1121 | |||
1122 | Direction | ||
1123 | P Port Processor -> West Bridge | ||
1124 | |||
1125 | Length (in transfers) | ||
1126 | 1 | ||
1127 | |||
1128 | MailBox0 | ||
1129 | * Context = 2 | ||
1130 | * Request Code = 6 | ||
1131 | |||
1132 | D0 | ||
1133 | Bits 12 - 15 : Bus index | ||
1134 | Bits 8 - 11 : Zero based device index | ||
1135 | Bits 0 - 7 : Zero based unit index | ||
1136 | |||
1137 | Responses | ||
1138 | * CY_RESP_UNIT_DESCRIPTOR | ||
1139 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_INVALID_PARTITION_TABLE | ||
1140 | * CY_RESP_NO_SUCH_ADDRESS | ||
1141 | */ | ||
1142 | #define CY_RQT_QUERY_UNIT (6) | ||
1143 | |||
1144 | |||
1145 | /* Summary | ||
1146 | This command initiates the read of a specific block | ||
1147 | from the given media, | ||
1148 | device and unit. | ||
1149 | |||
1150 | Direction | ||
1151 | P Port Processor -> West Bridge | ||
1152 | |||
1153 | Length (in transfers) | ||
1154 | 2 | ||
1155 | |||
1156 | MailBox0 | ||
1157 | * Context = 2 | ||
1158 | * Request Code = 7 | ||
1159 | |||
1160 | D0 | ||
1161 | Bits 12 - 15 : Bus index | ||
1162 | Bits 8 - 11 : Zero based device index | ||
1163 | Bits 0 - 7 : Zero based unit index | ||
1164 | |||
1165 | D1 | ||
1166 | Upper 16 bits of block address | ||
1167 | |||
1168 | D2 | ||
1169 | Lower 16 bits of block address | ||
1170 | |||
1171 | D3 | ||
1172 | BIT 8 - 15 : Upper 8 bits of Number of blocks | ||
1173 | |||
1174 | BIT 0 - 7 : Reserved | ||
1175 | |||
1176 | * D4 * | ||
1177 | BITS 8 - 15 : Lower 8 bits of Number of blocks | ||
1178 | BITS 1 - 7 : Not Used | ||
1179 | BIT 0 : Indicates whether this command is a | ||
1180 | part of a P2S only burst. | ||
1181 | |||
1182 | Responses | ||
1183 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1184 | * CY_RESP_ANTIOCH_DEFERRED_ERROR | ||
1185 | */ | ||
1186 | #define CY_RQT_READ_BLOCK (7) | ||
1187 | |||
1188 | |||
1189 | /* Summary | ||
1190 | This command initiates the write of a specific block | ||
1191 | from the given media, device and unit. | ||
1192 | |||
1193 | Direction | ||
1194 | P Port Processor -> West Bridge | ||
1195 | |||
1196 | Length (in transfers) | ||
1197 | 2 | ||
1198 | |||
1199 | MailBox0 | ||
1200 | * Context = 2 | ||
1201 | * Request Code = 8 | ||
1202 | |||
1203 | D0 | ||
1204 | Bits 12 - 15 : Bus index | ||
1205 | Bits 8 - 11 : Zero based device index | ||
1206 | Bits 0 - 7 : Zero based unit index | ||
1207 | |||
1208 | D1 | ||
1209 | Upper 16 bits of block address | ||
1210 | |||
1211 | D2 | ||
1212 | Lower 16 bits of block address | ||
1213 | |||
1214 | D3 | ||
1215 | BIT 8 - 15 : Upper 8 bits of Number of blocks | ||
1216 | |||
1217 | BIT 0 - 7 : Reserved | ||
1218 | |||
1219 | * D4 * | ||
1220 | BITS 8 - 15 : Lower 8 bits of Number of blocks | ||
1221 | BITS 1 - 7 : Not Used | ||
1222 | BIT 0 : Indicates whether this command is a | ||
1223 | part of a P2S only burst. | ||
1224 | |||
1225 | Responses | ||
1226 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1227 | * CY_RESP_ANTIOCH_DEFERRED_ERROR | ||
1228 | */ | ||
1229 | #define CY_RQT_WRITE_BLOCK (8) | ||
1230 | |||
1231 | /* Summary | ||
1232 | This request is sent when the West Bridge device detects | ||
1233 | a change in the status of the media. | ||
1234 | |||
1235 | Direction | ||
1236 | West Bridge -> P Port Processor | ||
1237 | |||
1238 | Length (in transfers) | ||
1239 | 1 | ||
1240 | |||
1241 | Mailbox0 | ||
1242 | * Context = 2 | ||
1243 | * Request Code = 9 | ||
1244 | |||
1245 | D0 | ||
1246 | Bits 12 - 15 : Bus index | ||
1247 | Bits 0 - 7 : Media type | ||
1248 | |||
1249 | D1 | ||
1250 | Bit 0 : Action | ||
1251 | * 0 = Inserted | ||
1252 | * 1 = Removed | ||
1253 | |||
1254 | Description | ||
1255 | When the media manager detects the insertion or removal | ||
1256 | of a media from the West Bridge port, this request is sent | ||
1257 | from the West Bridge device to the P Port processor to | ||
1258 | inform the processor of the change in status of the media. | ||
1259 | This request is sent for both an insert operation and a | ||
1260 | removal operation. | ||
1261 | |||
1262 | Responses | ||
1263 | * CY_RESPO_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1264 | */ | ||
1265 | #define CY_RQT_MEDIA_CHANGED (9) | ||
1266 | |||
1267 | /* Summary | ||
1268 | This request is sent when the USB module wishes to claim | ||
1269 | storage media. | ||
1270 | |||
1271 | Direction | ||
1272 | West Bridge -> P Port Processor | ||
1273 | |||
1274 | Length (in transfers) | ||
1275 | 1 | ||
1276 | |||
1277 | Mailbox0 | ||
1278 | * Context = 2 | ||
1279 | * Request Code = 10 | ||
1280 | |||
1281 | D0 | ||
1282 | Bit 0: | ||
1283 | * 0 = do not release NAND | ||
1284 | * 1 = release NAND | ||
1285 | |||
1286 | Bit 1: | ||
1287 | * 0 = do not release SD Flash | ||
1288 | * 1 = release SD Flash | ||
1289 | |||
1290 | Bit 2: | ||
1291 | * 0 = do not release MMC flash | ||
1292 | * 1 = release MMC flash | ||
1293 | |||
1294 | Bit 3: | ||
1295 | * 0 = do not release CE-ATA storage | ||
1296 | * 1 = release CE-ATA storage | ||
1297 | |||
1298 | Bit 8: | ||
1299 | * 0 = do not release storage on bus 0 | ||
1300 | * 1 = release storage on bus 0 | ||
1301 | |||
1302 | Bit 9: | ||
1303 | * 0 = do not release storage on bus 1 | ||
1304 | * 1 = release storage on bus 1 | ||
1305 | |||
1306 | Description | ||
1307 | When the USB cable is attached to the West Bridge device, | ||
1308 | West Bridge will enumerate the storage devices per the USB | ||
1309 | initialization of West Bridge. In order for West Bridge to | ||
1310 | respond to requests received via USB for the mass storage | ||
1311 | devices, the USB module must claim the storeage. This | ||
1312 | request is a request to the P port processor to release the | ||
1313 | storage medium. The medium will not be visible on the USB | ||
1314 | host, until it has been released by the processor. | ||
1315 | */ | ||
1316 | #define CY_RQT_ANTIOCH_CLAIM (10) | ||
1317 | |||
1318 | /* Summary | ||
1319 | This request is sent when the P port has asked West Bridge to | ||
1320 | release storage media, and the West Bridge device has | ||
1321 | completed this. | ||
1322 | |||
1323 | Direction | ||
1324 | West Bridge -> P Port Processor | ||
1325 | |||
1326 | Length (in transfers) | ||
1327 | 1 | ||
1328 | |||
1329 | Mailbox0 | ||
1330 | * Context = 2 | ||
1331 | * Request Code = 11 | ||
1332 | |||
1333 | D0 | ||
1334 | Bit 0: | ||
1335 | * 0 = No change in ownership of NAND storage | ||
1336 | * 1 = NAND ownership has been given to processor | ||
1337 | |||
1338 | Bit 1: | ||
1339 | * 0 = No change in ownership of SD storage | ||
1340 | * 1 = SD ownership has been given to processor | ||
1341 | |||
1342 | Bit 2: | ||
1343 | * 0 = No change in ownership of MMC storage | ||
1344 | * 1 = MMC ownership has been given to processor | ||
1345 | |||
1346 | Bit 3: | ||
1347 | * 0 = No change in ownership of CE-ATA storage | ||
1348 | * 1 = CE-ATA ownership has been given to processor | ||
1349 | |||
1350 | Bit 4: | ||
1351 | * 0 = No change in ownership of SD IO device | ||
1352 | * 1 = SD IO device ownership has been given to processor | ||
1353 | |||
1354 | Bit 8: | ||
1355 | * 0 = No change in ownership of storage on bus 0 | ||
1356 | * 1 = Bus 0 ownership has been given to processor | ||
1357 | |||
1358 | Bit 9: | ||
1359 | * 0 = No change in ownership of storage on bus 1 | ||
1360 | * 1 = Bus 1 ownership has been given to processor | ||
1361 | |||
1362 | Description | ||
1363 | When the P port asks for control of a particular media, West | ||
1364 | Bridge may be able to release the media immediately. West | ||
1365 | Bridge may also need to complete the flush of buffers before | ||
1366 | releasing the media. In the later case, West Bridge will | ||
1367 | indicated a release is not possible immediately and West Bridge | ||
1368 | will send this request to the P port when the release has been | ||
1369 | completed. | ||
1370 | */ | ||
1371 | #define CY_RQT_ANTIOCH_RELEASE (11) | ||
1372 | |||
1373 | /* Summary | ||
1374 | This request is sent by the Processor to enable/disable the | ||
1375 | handling of SD card detection and SD card write protection | ||
1376 | by the firmware. | ||
1377 | |||
1378 | Direction | ||
1379 | P Port Processor -> West Bridge | ||
1380 | |||
1381 | Length (in transfers) | ||
1382 | 1 | ||
1383 | |||
1384 | Mailbox0 | ||
1385 | * Context = 2 | ||
1386 | * Request code = 12 | ||
1387 | |||
1388 | D0 | ||
1389 | Bit 8: Enable/disable handling of card detection. | ||
1390 | Bit 1: SDAT_3 = 0, GIPO_0 = 1 | ||
1391 | Bit 0: Enable/disable handling of write protection. | ||
1392 | |||
1393 | Description | ||
1394 | This request is sent by the Processor to enable/disable | ||
1395 | the handling of SD card detection and SD card write | ||
1396 | protection by the firmware. | ||
1397 | */ | ||
1398 | #define CY_RQT_SD_INTERFACE_CONTROL (12) | ||
1399 | |||
1400 | /* Summary | ||
1401 | Request from the processor to read a register on the SD | ||
1402 | card, and return the contents. | ||
1403 | |||
1404 | Direction | ||
1405 | P Port Processor -> West Bridge | ||
1406 | |||
1407 | Length (in transfers) | ||
1408 | 1 | ||
1409 | |||
1410 | Mailbox0 | ||
1411 | * Context = 2 | ||
1412 | * Request code = 13 | ||
1413 | |||
1414 | D0 | ||
1415 | Bits 12 - 15 : MediaType | ||
1416 | * 0 = Reserved | ||
1417 | * 1 = SDIO Flash | ||
1418 | * 2 = MMC Flash | ||
1419 | * 3 = Reserved | ||
1420 | |||
1421 | Bits 8 - 11 : Zero based device index | ||
1422 | Bits 0 - 7 : Type of register to read | ||
1423 | |||
1424 | Description | ||
1425 | This request is sent by the processor to instruct the | ||
1426 | West Bridge to read a register on the SD/MMC card, and | ||
1427 | send the contents back through the CY_RESP_SD_REGISTER_DATA | ||
1428 | response. | ||
1429 | */ | ||
1430 | #define CY_RQT_SD_REGISTER_READ (13) | ||
1431 | |||
1432 | /* Summary | ||
1433 | Check if the SD/MMC card connected to West Bridge is | ||
1434 | password locked. | ||
1435 | |||
1436 | Direction | ||
1437 | P Port Processor -> West Bridge | ||
1438 | |||
1439 | Length (in transfers) | ||
1440 | 1 | ||
1441 | |||
1442 | Mailbox0 | ||
1443 | * Context = 2 | ||
1444 | * Request code = 14 | ||
1445 | |||
1446 | D0 | ||
1447 | Bits 12 - 15 : Bus index | ||
1448 | Bits 8 - 11 : Zero based device index | ||
1449 | |||
1450 | Description | ||
1451 | This request is sent by the processor to check if the | ||
1452 | SD/MMC connected to the West Bridge is locked with a | ||
1453 | password. | ||
1454 | */ | ||
1455 | #define CY_RQT_CHECK_CARD_LOCK (14) | ||
1456 | |||
1457 | /* Summary | ||
1458 | This command returns the total number of logical devices on the | ||
1459 | given bus | ||
1460 | |||
1461 | Direction | ||
1462 | P Port Processor -> West Bridge | ||
1463 | |||
1464 | Length (in transfers) | ||
1465 | 1 | ||
1466 | |||
1467 | MailBox0 | ||
1468 | * Context = 2 | ||
1469 | * Request Code = 15 | ||
1470 | |||
1471 | D0 | ||
1472 | Bits 12 - 15 : Bus Number | ||
1473 | |||
1474 | Bits 0 - 11: Not Used | ||
1475 | |||
1476 | Responses | ||
1477 | * CY_RESP_BUS_DESCRIPTOR | ||
1478 | * CY_RESP_NO_SUCH_BUS | ||
1479 | */ | ||
1480 | #define CY_RQT_QUERY_BUS (15) | ||
1481 | |||
1482 | /* Summary | ||
1483 | Divide a storage device into two partitions. | ||
1484 | |||
1485 | Direction | ||
1486 | P Port Processor -> West Bridge | ||
1487 | |||
1488 | Length (in transfers) | ||
1489 | 1 | ||
1490 | |||
1491 | MailBox0 | ||
1492 | * Context = 2 | ||
1493 | * Request code = 16 | ||
1494 | |||
1495 | D0 | ||
1496 | Bits 12 - 15 : Bus number | ||
1497 | Bits 8 - 11 : Device number | ||
1498 | Bits 0 - 7 : Not used | ||
1499 | |||
1500 | D1 | ||
1501 | Size of partition 0 (MS word) | ||
1502 | |||
1503 | D2 | ||
1504 | Size of partition 0 (LS word) | ||
1505 | |||
1506 | Responses | ||
1507 | * CY_RESP_SUCCESS_FAILURE | ||
1508 | */ | ||
1509 | #define CY_RQT_PARTITION_STORAGE (16) | ||
1510 | |||
1511 | /* Summary | ||
1512 | Remove the partition table and unify all partitions on | ||
1513 | a storage device. | ||
1514 | |||
1515 | Direction | ||
1516 | P Port Processor -> West Bridge | ||
1517 | |||
1518 | Length (in transfers) | ||
1519 | 1 | ||
1520 | |||
1521 | MailBox0 | ||
1522 | * Context = 2 | ||
1523 | * Request code = 17 | ||
1524 | |||
1525 | D0 | ||
1526 | Bits 12 - 15 : Bus number | ||
1527 | Bits 8 - 11 : Device number | ||
1528 | |||
1529 | Responses | ||
1530 | * CY_RESP_SUCCESS_FAILURE | ||
1531 | */ | ||
1532 | #define CY_RQT_PARTITION_ERASE (17) | ||
1533 | |||
1534 | /* Summary | ||
1535 | Requests the current transfer amount. | ||
1536 | |||
1537 | Direction | ||
1538 | P Port Processor -> West Bridge | ||
1539 | |||
1540 | Length (in transfers) | ||
1541 | 1 | ||
1542 | |||
1543 | MailBox0 | ||
1544 | * Context = 2 | ||
1545 | * Request code = 18 | ||
1546 | |||
1547 | D0 | ||
1548 | Bits 12 - 15 : Bus number | ||
1549 | Bits 8 - 11 : Device number | ||
1550 | |||
1551 | Responses | ||
1552 | * CY_RESP_TRANSFER_COUNT | ||
1553 | */ | ||
1554 | #define CY_RQT_GET_TRANSFER_AMOUNT (18) | ||
1555 | |||
1556 | /* Summary | ||
1557 | Erases. | ||
1558 | |||
1559 | Direction | ||
1560 | P Port Processor -> West Bridge | ||
1561 | |||
1562 | Length (in transfers) | ||
1563 | 2 | ||
1564 | |||
1565 | MailBox0 | ||
1566 | * Context = 2 | ||
1567 | * Request code = 19 | ||
1568 | |||
1569 | D0 | ||
1570 | Bits 12 - 15 : Bus index | ||
1571 | Bits 8 - 11 : Zero based device index | ||
1572 | Bits 0 - 7 : Zero based unit index | ||
1573 | |||
1574 | D1 | ||
1575 | Upper 16 bits of erase unit | ||
1576 | |||
1577 | D2 | ||
1578 | Lower 16 bits of erase unit | ||
1579 | |||
1580 | D3 | ||
1581 | BIT 8 - 15 : Upper 8 bits of Number of erase units | ||
1582 | BIT 0 - 7 : Reserved | ||
1583 | |||
1584 | * D4 * | ||
1585 | BIT 8 - 15 : Lower 8 bits of Number of erase units | ||
1586 | BIT 0 - 7 : Not Used | ||
1587 | |||
1588 | Responses | ||
1589 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1590 | */ | ||
1591 | #define CY_RQT_ERASE (19) | ||
1592 | |||
1593 | /* Summary | ||
1594 | This command reads 1 byte from an SDIO card. | ||
1595 | |||
1596 | Direction | ||
1597 | P Port Processor -> West Bridge | ||
1598 | |||
1599 | Length (in transfers) | ||
1600 | 1 | ||
1601 | |||
1602 | MailBox0 | ||
1603 | * Context = 2 | ||
1604 | * Request Code = 23 | ||
1605 | |||
1606 | D0 | ||
1607 | Bits 12 - 15 : Bus index | ||
1608 | Bits 8 - 11 : Zero based device index | ||
1609 | Bits 0 - 7 : Zero based function number | ||
1610 | |||
1611 | D1 | ||
1612 | Bits 8 - 15 : 0 | ||
1613 | Bit 7 : 0 to indicate a read | ||
1614 | Bits 4 - 6 : Function number | ||
1615 | Bit 3 : 0 | ||
1616 | Bit 2 : 1 if SDIO interrupt needs to be re-enabled. | ||
1617 | Bits 0 - 1 : Two Most significant bits of Read address | ||
1618 | |||
1619 | D2 | ||
1620 | Bits 1 - 15 : 15 Least significant bits of Read address | ||
1621 | Bit 0 : 0 | ||
1622 | |||
1623 | |||
1624 | Responses | ||
1625 | * CY_RESP_SUCCESS_FAILURE | ||
1626 | * CY_RESP_SDIO_DIRECT | ||
1627 | */ | ||
1628 | #define CY_RQT_SDIO_READ_DIRECT (23) | ||
1629 | |||
1630 | /* Summary | ||
1631 | This command writes 1 byte to an SDIO card. | ||
1632 | |||
1633 | Direction | ||
1634 | P Port Processor -> West Bridge | ||
1635 | |||
1636 | Length (in transfers) | ||
1637 | 1 | ||
1638 | |||
1639 | MailBox0 | ||
1640 | * Context = 2 | ||
1641 | * Request Code = 24 | ||
1642 | |||
1643 | D0 | ||
1644 | Bits 12 - 15 : Bus index | ||
1645 | Bits 8 - 11 : Zero based device index | ||
1646 | Bits 0 - 7 : Zero based function number | ||
1647 | |||
1648 | D1 | ||
1649 | Bits 8 - 15 : Data to write | ||
1650 | Bit 7 : 1 to indicate a write | ||
1651 | Bits 4 - 6 : Function number | ||
1652 | Bit 3 : 1 if Read after write is enabled | ||
1653 | Bit 2 : 1 if SDIO interrupt needs to be re-enabled. | ||
1654 | Bits 0 - 1 : Two Most significant bits of write address | ||
1655 | |||
1656 | D2 | ||
1657 | Bits 1 - 15 : 15 Least significant bits of write address | ||
1658 | Bit 0 : 0 | ||
1659 | |||
1660 | |||
1661 | Responses | ||
1662 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1663 | * CY_RESP_SDIO_DIRECT | ||
1664 | */ | ||
1665 | #define CY_RQT_SDIO_WRITE_DIRECT (24) | ||
1666 | |||
1667 | /* Summary | ||
1668 | This command reads performs a multi block/byte read from | ||
1669 | an SDIO card. | ||
1670 | |||
1671 | Direction | ||
1672 | P Port Processor -> West Bridge | ||
1673 | |||
1674 | Length (in transfers) | ||
1675 | 1 | ||
1676 | |||
1677 | MailBox0 | ||
1678 | * Context = 2 | ||
1679 | * Request Code = 25 | ||
1680 | |||
1681 | D0 | ||
1682 | Bits 12 - 15 : Bus index | ||
1683 | Bits 8 - 11 : Zero based device index | ||
1684 | Bits 0 - 7 : Zero based function number | ||
1685 | |||
1686 | D1 | ||
1687 | Bit 15 : 0 to indicate a read | ||
1688 | Bit 12 - 14 : Function Number | ||
1689 | Bit 11 : Block Mode | ||
1690 | Bit 10 : OpCode | ||
1691 | Bits 0 - 9 : 10 Most significant bits of Read address | ||
1692 | |||
1693 | D2 | ||
1694 | Bits 9 - 15 : 7 Least significant bits of address | ||
1695 | Bits 0 - 8 : Block/Byte Count | ||
1696 | |||
1697 | |||
1698 | Responses | ||
1699 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1700 | * CY_RESP_SDIO_EXT | ||
1701 | */ | ||
1702 | #define CY_RQT_SDIO_READ_EXTENDED (25) | ||
1703 | |||
1704 | /* Summary | ||
1705 | This command reads performs a multi block/byte write | ||
1706 | to an SDIO card. | ||
1707 | |||
1708 | Direction | ||
1709 | P Port Processor -> West Bridge | ||
1710 | |||
1711 | Length (in transfers) | ||
1712 | 1 | ||
1713 | |||
1714 | MailBox0 | ||
1715 | * Context = 2 | ||
1716 | * Request Code = 26 | ||
1717 | |||
1718 | D0 | ||
1719 | Bits 12 - 15 : Bus index | ||
1720 | Bits 8 - 11 : Zero based device index | ||
1721 | Bits 0 - 7 : Zero based function number | ||
1722 | |||
1723 | D1 | ||
1724 | Bit 15 : 1 to indicate a write | ||
1725 | Bit 12 - 14 : Function Number | ||
1726 | Bit 11 : Block Mode | ||
1727 | Bit 10 : OpCode | ||
1728 | Bits 0 - 9 : 10 Most significant bits of Read address | ||
1729 | |||
1730 | D2 | ||
1731 | Bits 9 - 15 : 7 Least significant bits of address | ||
1732 | Bits 0 - 8 : Block/Byte Count | ||
1733 | |||
1734 | |||
1735 | Responses | ||
1736 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1737 | * CY_RESP_SDIO_EXT | ||
1738 | */ | ||
1739 | #define CY_RQT_SDIO_WRITE_EXTENDED (26) | ||
1740 | |||
1741 | /* Summary | ||
1742 | This command initialises an IO function on the SDIO card. | ||
1743 | |||
1744 | Direction | ||
1745 | P Port Processor -> West Bridge | ||
1746 | |||
1747 | Length (in transfers) | ||
1748 | 1 | ||
1749 | |||
1750 | MailBox0 | ||
1751 | * Context = 2 | ||
1752 | * Request Code = 27 | ||
1753 | |||
1754 | D0 | ||
1755 | Bits 12 - 15 : Bus index | ||
1756 | Bits 8 - 11 : Zero based device index | ||
1757 | Bits 0 - 7 : Zero based function number | ||
1758 | |||
1759 | |||
1760 | Responses | ||
1761 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1762 | */ | ||
1763 | #define CY_RQT_SDIO_INIT_FUNCTION (27) | ||
1764 | |||
1765 | /* Summary | ||
1766 | This command gets properties of the SDIO card. | ||
1767 | |||
1768 | Direction | ||
1769 | P Port Processor -> West Bridge | ||
1770 | |||
1771 | Length (in transfers) | ||
1772 | 1 | ||
1773 | |||
1774 | MailBox0 | ||
1775 | * Context = 2 | ||
1776 | * Request Code = 28 | ||
1777 | |||
1778 | D0 | ||
1779 | Bits 12 - 15 : Bus index | ||
1780 | Bits 8 - 11 : Zero based device index | ||
1781 | Bits 0 - 7 : Zero | ||
1782 | |||
1783 | Responses | ||
1784 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1785 | * CY_RESP_QUERY_CARD | ||
1786 | */ | ||
1787 | #define CY_RQT_SDIO_QUERY_CARD (28) | ||
1788 | |||
1789 | /* Summary | ||
1790 | This command reads a tuple from the CIS of an SDIO card. | ||
1791 | |||
1792 | Direction | ||
1793 | P Port Processor -> West Bridge | ||
1794 | |||
1795 | Length (in transfers) | ||
1796 | 1 | ||
1797 | |||
1798 | MailBox0 | ||
1799 | * Context = 2 | ||
1800 | * Request Code = 29 | ||
1801 | |||
1802 | D0 | ||
1803 | Bits 12 - 15 : Bus index | ||
1804 | Bits 8 - 11 : Zero based device index | ||
1805 | Bits 0 - 7 : Zero based function number | ||
1806 | |||
1807 | D1 | ||
1808 | Bits 8 - 15 : Tuple ID to read | ||
1809 | |||
1810 | Responses | ||
1811 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1812 | * CY_RESP_SDIO_GET_TUPLE | ||
1813 | */ | ||
1814 | #define CY_RQT_SDIO_GET_TUPLE (29) | ||
1815 | |||
1816 | /* Summary | ||
1817 | This command Aborts an IO operation. | ||
1818 | |||
1819 | Direction | ||
1820 | P Port Processor -> West Bridge | ||
1821 | |||
1822 | Length (in transfers) | ||
1823 | 1 | ||
1824 | |||
1825 | MailBox0 | ||
1826 | * Context = 2 | ||
1827 | * Request Code = 30 | ||
1828 | |||
1829 | D0 | ||
1830 | Bits 12 - 15 : Bus index | ||
1831 | Bits 8 - 11 : Zero based device index | ||
1832 | Bits 0 - 7 : Zero based function number | ||
1833 | |||
1834 | |||
1835 | Responses | ||
1836 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1837 | */ | ||
1838 | #define CY_RQT_SDIO_ABORT_IO (30) | ||
1839 | |||
1840 | /* Summary | ||
1841 | SDIO Interrupt request sent to the processor from the West Bridge device. | ||
1842 | |||
1843 | Direction | ||
1844 | West Bridge ->P Port Processor | ||
1845 | |||
1846 | Length (in transfers) | ||
1847 | 1 | ||
1848 | |||
1849 | MailBox0 | ||
1850 | * Context = 2 | ||
1851 | * Request Code = 31 | ||
1852 | |||
1853 | D0 | ||
1854 | Bits 0 - 7 : Bus Index | ||
1855 | |||
1856 | Responses | ||
1857 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1858 | */ | ||
1859 | #define CY_RQT_SDIO_INTR (31) | ||
1860 | |||
1861 | /* Summary | ||
1862 | This command Suspends an IO operation. | ||
1863 | |||
1864 | Direction | ||
1865 | P Port Processor -> West Bridge | ||
1866 | |||
1867 | Length (in transfers) | ||
1868 | 1 | ||
1869 | |||
1870 | MailBox0 | ||
1871 | * Context = 2 | ||
1872 | * Request Code = 32 | ||
1873 | |||
1874 | D0 | ||
1875 | Bits 12 - 15 : Bus index | ||
1876 | Bits 8 - 11 : Zero based device index | ||
1877 | Bits 0 - 7 : Zero based function number | ||
1878 | |||
1879 | Responses | ||
1880 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1881 | */ | ||
1882 | #define CY_RQT_SDIO_SUSPEND (32) | ||
1883 | |||
1884 | /* Summary | ||
1885 | This command resumes a suspended operation. | ||
1886 | |||
1887 | Direction | ||
1888 | P Port Processor -> West Bridge | ||
1889 | |||
1890 | Length (in transfers) | ||
1891 | 1 | ||
1892 | |||
1893 | MailBox0 | ||
1894 | * Context = 2 | ||
1895 | * Request Code = 33 | ||
1896 | |||
1897 | D0 | ||
1898 | Bits 12 - 15 : Bus index | ||
1899 | Bits 8 - 11 : Zero based device index | ||
1900 | Bits 0 - 7 : Zero based function number | ||
1901 | |||
1902 | Responses | ||
1903 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1904 | * CY_RESP_SDIO_RESUME | ||
1905 | */ | ||
1906 | #define CY_RQT_SDIO_RESUME (33) | ||
1907 | |||
1908 | /* Summary | ||
1909 | This command resets an SDIO device. | ||
1910 | |||
1911 | Direction | ||
1912 | P Port Processor -> West Bridge | ||
1913 | |||
1914 | Length (in transfers) | ||
1915 | 1 | ||
1916 | |||
1917 | MailBox0 | ||
1918 | * Context = 2 | ||
1919 | * Request Code = 34 | ||
1920 | |||
1921 | D0 | ||
1922 | Bits 12 - 15 : Bus index | ||
1923 | Bits 8 - 11 : Zero based device index | ||
1924 | Bits 0 - 7 : 0 | ||
1925 | |||
1926 | Responses | ||
1927 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1928 | */ | ||
1929 | #define CY_RQT_SDIO_RESET_DEV (34) | ||
1930 | |||
1931 | /* Summary | ||
1932 | This command asks the API to start the DMA transfer | ||
1933 | for a P2S operation. | ||
1934 | |||
1935 | Direction | ||
1936 | West Bridge -> P Port Processor | ||
1937 | |||
1938 | Length (in transfers) | ||
1939 | 1 | ||
1940 | |||
1941 | MailBox0 | ||
1942 | * Context = 2 | ||
1943 | * Request code = 35 | ||
1944 | |||
1945 | Responses | ||
1946 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
1947 | */ | ||
1948 | #define CY_RQT_P2S_DMA_START (35) | ||
1949 | |||
1950 | /******************************************************/ | ||
1951 | |||
1952 | /*@@Storage responses | ||
1953 | Summary | ||
1954 | The storage responses include: | ||
1955 | * CY_RESP_MEDIA_CLAIMED_RELEASED | ||
1956 | * CY_RESP_MEDIA_DESCRIPTOR | ||
1957 | * CY_RESP_DEVICE_DESCRIPTOR | ||
1958 | * CY_RESP_UNIT_DESCRIPTOR | ||
1959 | * CY_RESP_ANTIOCH_DEFERRED_ERROR | ||
1960 | * CY_RESP_SD_REGISTER_DATA | ||
1961 | * CY_RESP_SD_LOCK_STATUS | ||
1962 | * CY_RESP_BUS_DESCRIPTOR | ||
1963 | * CY_RESP_TRANSFER_COUNT | ||
1964 | * CY_RESP_SDIO_EXT | ||
1965 | * CY_RESP_SDIO_INIT_FUNCTION | ||
1966 | * CY_RESP_SDIO_QUERY_CARD | ||
1967 | * CY_RESP_SDIO_GET_TUPLE | ||
1968 | * CY_RESP_SDIO_DIRECT | ||
1969 | * CY_RESP_SDIO_INVALID_FUNCTION | ||
1970 | * CY_RESP_SDIO_RESUME | ||
1971 | */ | ||
1972 | |||
1973 | /* Summary | ||
1974 | Based on the request sent, the state of a given media was | ||
1975 | changed as indicated by this response. | ||
1976 | |||
1977 | Direction | ||
1978 | West Bridge -> P Port Processor | ||
1979 | |||
1980 | Length (in transfers) | ||
1981 | 1 | ||
1982 | |||
1983 | MailBox0 | ||
1984 | * Context = 2 | ||
1985 | * Response Code = 16 | ||
1986 | |||
1987 | D0 | ||
1988 | Bits 12 - 15 : Bus index | ||
1989 | Bits 8 - 11 : Zero based device index | ||
1990 | |||
1991 | D1 | ||
1992 | State of Media | ||
1993 | * 0 = released | ||
1994 | * 1 = claimed | ||
1995 | */ | ||
1996 | #define CY_RESP_MEDIA_CLAIMED_RELEASED (16) | ||
1997 | |||
1998 | |||
1999 | /* Summary | ||
2000 | This response gives the number of physical devices | ||
2001 | associated with a given media type. | ||
2002 | |||
2003 | Direction | ||
2004 | West Bridge -> P Port Processor | ||
2005 | |||
2006 | Length (in transfers) | ||
2007 | 1 | ||
2008 | |||
2009 | MailBox0 | ||
2010 | * Context = 2 | ||
2011 | * Response Code = 17 | ||
2012 | |||
2013 | D0 | ||
2014 | Media Type | ||
2015 | Bits 12 - 15 | ||
2016 | * 0 = NAND | ||
2017 | * 1 = SDIO Flash | ||
2018 | * 2 = MMC Flash | ||
2019 | * 3 = CE-ATA | ||
2020 | |||
2021 | D1 | ||
2022 | Number of devices | ||
2023 | */ | ||
2024 | #define CY_RESP_MEDIA_DESCRIPTOR (17) | ||
2025 | |||
2026 | |||
2027 | /* Summary | ||
2028 | This response gives description of a physical device. | ||
2029 | |||
2030 | Direction | ||
2031 | West Bridge -> P Port Processor | ||
2032 | |||
2033 | Length (in transfers) | ||
2034 | 2 | ||
2035 | |||
2036 | MailBox0 | ||
2037 | * Context = 2 | ||
2038 | * Response Code = 18 | ||
2039 | |||
2040 | D0 | ||
2041 | Bits 12 - 15 : Bus index | ||
2042 | Bits 8 - 11 : Zero based device index | ||
2043 | Bits 0 - 7 : Type of media present on bus | ||
2044 | |||
2045 | D1 | ||
2046 | Block Size in bytes | ||
2047 | |||
2048 | D2 | ||
2049 | Bit 15 : Is device removable | ||
2050 | Bit 9 : Is device password locked | ||
2051 | Bit 8 : Is device writeable | ||
2052 | Bits 0 - 7 : Number Of Units | ||
2053 | |||
2054 | D3 | ||
2055 | ERASE_UNIT_SIZE high 16 bits | ||
2056 | |||
2057 | D4 | ||
2058 | ERASE_UNIT_SIZE low 16 bits | ||
2059 | |||
2060 | */ | ||
2061 | #define CY_RESP_DEVICE_DESCRIPTOR (18) | ||
2062 | |||
2063 | |||
2064 | /* Summary | ||
2065 | This response gives description of a unit on a | ||
2066 | physical device. | ||
2067 | |||
2068 | Direction | ||
2069 | West Bridge -> P Port Processor | ||
2070 | |||
2071 | Length (in transfers) | ||
2072 | 6 | ||
2073 | |||
2074 | MailBox0 | ||
2075 | * Context = 2 | ||
2076 | * Response Code = 19 | ||
2077 | |||
2078 | D0 | ||
2079 | Bits 12 - 15 : Bus index | ||
2080 | Bits 8 - 11 : Zero based device index | ||
2081 | Bits 0 - 7 : Zero based unit index | ||
2082 | |||
2083 | D1 | ||
2084 | Bits 0 - 7 : Media type | ||
2085 | * 1 = NAND | ||
2086 | * 2 = SD FLASH | ||
2087 | * 4 = MMC FLASH | ||
2088 | * 8 = CEATA | ||
2089 | * 16 = SD IO | ||
2090 | |||
2091 | D2 | ||
2092 | Block Size in bytes | ||
2093 | |||
2094 | D3 | ||
2095 | Start Block Low 16 bits | ||
2096 | |||
2097 | D4 | ||
2098 | Start Block High 16 bits | ||
2099 | |||
2100 | D5 | ||
2101 | Unit Size Low 16 bits | ||
2102 | |||
2103 | D6 | ||
2104 | Unit Size High 16 bits | ||
2105 | */ | ||
2106 | #define CY_RESP_UNIT_DESCRIPTOR (19) | ||
2107 | |||
2108 | |||
2109 | /* Summary | ||
2110 | This response is sent as error status for P2S | ||
2111 | Storage operation. | ||
2112 | |||
2113 | Direction | ||
2114 | West Bridge -> P Port Processor | ||
2115 | |||
2116 | Length (in transfers) | ||
2117 | 2 | ||
2118 | |||
2119 | Mailbox0 | ||
2120 | * Context = 2 | ||
2121 | * Request Code = 20 | ||
2122 | |||
2123 | D0 | ||
2124 | Bit 8 : Type of operation (Read / Write) | ||
2125 | Bits 7 - 0 : Error code | ||
2126 | |||
2127 | D1 | ||
2128 | Bits 12 - 15 : Bus index | ||
2129 | Bits 8 - 11 : Zero based device index | ||
2130 | Bits 0 - 7 : Zero based unit index | ||
2131 | |||
2132 | *D2 - D3* | ||
2133 | Address where the error occurred. | ||
2134 | |||
2135 | D4 | ||
2136 | Length of the operation in blocks. | ||
2137 | |||
2138 | Description | ||
2139 | This error is returned by the West Bridge to the | ||
2140 | processor if a storage operation fails due to a | ||
2141 | medium error. | ||
2142 | */ | ||
2143 | #define CY_RESP_ANTIOCH_DEFERRED_ERROR (20) | ||
2144 | |||
2145 | /* Summary | ||
2146 | Contents of a register on the SD/MMC card connected to | ||
2147 | West Bridge. | ||
2148 | |||
2149 | Direction | ||
2150 | West Bridge -> P Port Processor | ||
2151 | |||
2152 | Length (in transfers) | ||
2153 | Variable | ||
2154 | |||
2155 | Mailbox0 | ||
2156 | * Context = 2 | ||
2157 | * Request code = 21 | ||
2158 | |||
2159 | D0 | ||
2160 | Length of data in bytes | ||
2161 | |||
2162 | D1 - Dn | ||
2163 | The register contents | ||
2164 | |||
2165 | Description | ||
2166 | This is the response to a CY_RQT_SD_REGISTER_READ | ||
2167 | request. | ||
2168 | */ | ||
2169 | #define CY_RESP_SD_REGISTER_DATA (21) | ||
2170 | |||
2171 | /* Summary | ||
2172 | Status of whether the SD card is password locked. | ||
2173 | |||
2174 | Direction | ||
2175 | West Bridge -> P Port Processor | ||
2176 | |||
2177 | Length (in transfers) | ||
2178 | 1 | ||
2179 | |||
2180 | Mailbox0 | ||
2181 | * Context = 2 | ||
2182 | * Request code = 22 | ||
2183 | |||
2184 | D0 | ||
2185 | Bit 0 : The card's lock status | ||
2186 | |||
2187 | Description | ||
2188 | Status of whether the SD card is password locked. | ||
2189 | */ | ||
2190 | #define CY_RESP_SD_LOCK_STATUS (22) | ||
2191 | |||
2192 | |||
2193 | /* Summary | ||
2194 | This response gives the types of physical devices | ||
2195 | attached to a given bus. | ||
2196 | |||
2197 | Direction | ||
2198 | West Bridge -> P Port Processor | ||
2199 | |||
2200 | Length (in transfers) | ||
2201 | 1 | ||
2202 | |||
2203 | MailBox0 | ||
2204 | * Context = 2 | ||
2205 | * Response Code = 23 | ||
2206 | |||
2207 | D0 | ||
2208 | Bus Number | ||
2209 | Bits 12 - 15 | ||
2210 | |||
2211 | D1 | ||
2212 | Media present on addressed bus | ||
2213 | */ | ||
2214 | #define CY_RESP_BUS_DESCRIPTOR (23) | ||
2215 | |||
2216 | /* Summary | ||
2217 | Amount of data read/written through the USB mass | ||
2218 | storage/MTP device. | ||
2219 | |||
2220 | Direction | ||
2221 | West Bridge -> P Port Processor | ||
2222 | |||
2223 | Length (in transfers) | ||
2224 | 2 | ||
2225 | |||
2226 | MailBox0 | ||
2227 | * Context = 2 | ||
2228 | * Request code = 24 | ||
2229 | |||
2230 | D0 | ||
2231 | MS 16 bits of number of sectors written | ||
2232 | |||
2233 | D1 | ||
2234 | LS 16 bits of number of sectors written | ||
2235 | |||
2236 | D2 | ||
2237 | MS 16 bits of number of sectors read | ||
2238 | |||
2239 | D3 | ||
2240 | LS 16 bits of number of sectors read | ||
2241 | |||
2242 | Description | ||
2243 | This is the response to the CY_RQT_GET_TRANSFER_AMOUNT | ||
2244 | request, and represents the number of sectors of data | ||
2245 | that has been written to or read from the storage device | ||
2246 | through the USB Mass storage or MTP interface. | ||
2247 | */ | ||
2248 | #define CY_RESP_TRANSFER_COUNT (24) | ||
2249 | |||
2250 | /* Summary | ||
2251 | Status of SDIO Extended read/write operation. | ||
2252 | |||
2253 | Direction | ||
2254 | West Bridge -> P Port Processor | ||
2255 | |||
2256 | Length (in transfers) | ||
2257 | 1 | ||
2258 | |||
2259 | Mailbox0 | ||
2260 | * Context = 2 | ||
2261 | * Request code = 34 | ||
2262 | |||
2263 | D0 | ||
2264 | Bit 8 : 1 if Read response, 0 if write response | ||
2265 | Bits 0-7: Error Status | ||
2266 | |||
2267 | Description | ||
2268 | Status of SDIO Extended read write operation. | ||
2269 | */ | ||
2270 | |||
2271 | #define CY_RESP_SDIO_EXT (34) | ||
2272 | |||
2273 | /* Summary | ||
2274 | Status of SDIO operation to Initialize a function | ||
2275 | |||
2276 | Direction | ||
2277 | West Bridge -> P Port Processor | ||
2278 | |||
2279 | Length (in transfers) | ||
2280 | 2 | ||
2281 | |||
2282 | Mailbox0 | ||
2283 | * Context = 2 | ||
2284 | * Request code = 35 | ||
2285 | |||
2286 | |||
2287 | D0 | ||
2288 | Bits 8-15 : Function Interface Code | ||
2289 | Bits 0-7: Extended Function Interface Code | ||
2290 | |||
2291 | D1 | ||
2292 | Bits 0-15 : Function Block Size | ||
2293 | |||
2294 | D2 | ||
2295 | Bits 0-15 : Most significant Word of Function PSN | ||
2296 | |||
2297 | D3 | ||
2298 | Bits 0-15 : Least significant Word of Function PSN | ||
2299 | |||
2300 | D4 | ||
2301 | Bit 15 : CSA Enabled Status | ||
2302 | Bit 14 : CSA Support Status | ||
2303 | Bit 9 : CSA No Format Status | ||
2304 | Bit 8 : CSA Write Protect Status | ||
2305 | Bit 0 : Function Wake Up Support status | ||
2306 | |||
2307 | Description | ||
2308 | Status of SDIO Function Initialization operation. | ||
2309 | */ | ||
2310 | #define CY_RESP_SDIO_INIT_FUNCTION (35) | ||
2311 | |||
2312 | /* Summary | ||
2313 | Status of SDIO operation to query the Card | ||
2314 | |||
2315 | Direction | ||
2316 | West Bridge -> P Port Processor | ||
2317 | |||
2318 | Length (in transfers) | ||
2319 | 2 | ||
2320 | |||
2321 | Mailbox0 | ||
2322 | * Context = 2 | ||
2323 | * Request code = 36 | ||
2324 | |||
2325 | |||
2326 | D0 | ||
2327 | Bits 8-15 : Number of IO functions present | ||
2328 | Bit 0: 1 if memory is present | ||
2329 | |||
2330 | D1 | ||
2331 | Bits 0-15 : Card Manufacturer ID | ||
2332 | |||
2333 | D2 | ||
2334 | Bits 0-15 : Card Manufacturer Additional Information | ||
2335 | |||
2336 | D3 | ||
2337 | Bits 0-15 : Function 0 Block Size | ||
2338 | |||
2339 | D4 | ||
2340 | Bits 8-15 :SDIO Card Capability register | ||
2341 | Bits 0-7: SDIO Version | ||
2342 | |||
2343 | |||
2344 | Description | ||
2345 | Status of SDIO Card Query operation. | ||
2346 | */ | ||
2347 | #define CY_RESP_SDIO_QUERY_CARD (36) | ||
2348 | /* Summary | ||
2349 | Status of SDIO CIS read operation | ||
2350 | |||
2351 | Direction | ||
2352 | West Bridge -> P Port Processor | ||
2353 | |||
2354 | Length (in transfers) | ||
2355 | 1 | ||
2356 | |||
2357 | Mailbox0 | ||
2358 | * Context = 2 | ||
2359 | * Request code = 37 | ||
2360 | |||
2361 | D0 | ||
2362 | Bit 8 : 1 | ||
2363 | Bits 0-7: Error Status | ||
2364 | |||
2365 | D1 | ||
2366 | Bits 0 - 7 : Size of data read. | ||
2367 | |||
2368 | Description | ||
2369 | Status of SDIO Get Tuple Read operation. | ||
2370 | */ | ||
2371 | #define CY_RESP_SDIO_GET_TUPLE (37) | ||
2372 | |||
2373 | /* Summary | ||
2374 | Status of SDIO Direct read/write operation. | ||
2375 | |||
2376 | Direction | ||
2377 | West Bridge -> P Port Processor | ||
2378 | |||
2379 | Length (in transfers) | ||
2380 | 1 | ||
2381 | |||
2382 | Mailbox0 | ||
2383 | * Context = 2 | ||
2384 | * Request code = 38 | ||
2385 | |||
2386 | D0 | ||
2387 | Bit 8 : Error Status | ||
2388 | Bits 0-7: Data Read(If any) | ||
2389 | |||
2390 | Description | ||
2391 | Status of SDIO Direct read write operation. | ||
2392 | |||
2393 | */ | ||
2394 | #define CY_RESP_SDIO_DIRECT (38) | ||
2395 | |||
2396 | /* Summary | ||
2397 | Indicates an un-initialized function has been used for IO | ||
2398 | |||
2399 | Direction | ||
2400 | West Bridge -> P Port Processor | ||
2401 | |||
2402 | Length (in transfers) | ||
2403 | 1 | ||
2404 | |||
2405 | Mailbox0 | ||
2406 | * Context = 2 | ||
2407 | * Request code = 39 | ||
2408 | |||
2409 | Description | ||
2410 | Indicates an IO request on an uninitialized function. | ||
2411 | */ | ||
2412 | #define CY_RESP_SDIO_INVALID_FUNCTION (39) | ||
2413 | |||
2414 | /* Summary | ||
2415 | Response to a Resume request | ||
2416 | |||
2417 | Direction | ||
2418 | West Bridge -> P Port Processor | ||
2419 | |||
2420 | Length (in transfers) | ||
2421 | 1 | ||
2422 | |||
2423 | Mailbox0 | ||
2424 | * Context = 2 | ||
2425 | * Request code = 40 | ||
2426 | |||
2427 | D0 | ||
2428 | Bits 8-15 : Error Status | ||
2429 | Bit 0: 1 if data is available. 0 otherwise. | ||
2430 | |||
2431 | Description | ||
2432 | Response to a Resume request. Indicates if data is | ||
2433 | available after resum or not. | ||
2434 | */ | ||
2435 | #define CY_RESP_SDIO_RESUME (40) | ||
2436 | |||
2437 | /******************************************************/ | ||
2438 | |||
2439 | /*@@USB requests | ||
2440 | Summary | ||
2441 | The USB requests include: | ||
2442 | * CY_RQT_START_USB | ||
2443 | * CY_RQT_STOP_USB | ||
2444 | * CY_RQT_SET_CONNECT_STATE | ||
2445 | * CY_RQT_GET_CONNECT_STATE | ||
2446 | * CY_RQT_SET_USB_CONFIG | ||
2447 | * CY_RQT_GET_USB_CONFIG | ||
2448 | * CY_RQT_STALL_ENDPOINT | ||
2449 | * CY_RQT_GET_STALL | ||
2450 | * CY_RQT_SET_DESCRIPTOR | ||
2451 | * CY_RQT_GET_DESCRIPTOR | ||
2452 | * CY_RQT_SET_USB_CONFIG_REGISTERS | ||
2453 | * CY_RQT_USB_EVENT | ||
2454 | * CY_RQT_USB_EP_DATA | ||
2455 | * CY_RQT_ENDPOINT_SET_NAK | ||
2456 | * CY_RQT_GET_ENDPOINT_NAK | ||
2457 | * CY_RQT_ACK_SETUP_PACKET | ||
2458 | * CY_RQT_SCSI_INQUIRY_COMMAND | ||
2459 | * CY_RQT_SCSI_START_STOP_COMMAND | ||
2460 | * CY_RQT_SCSI_UNKNOWN_COMMAND | ||
2461 | * CY_RQT_USB_REMOTE_WAKEUP | ||
2462 | * CY_RQT_CLEAR_DESCRIPTORS | ||
2463 | * CY_RQT_USB_STORAGE_MONITOR | ||
2464 | * CY_RQT_USB_ACTIVITY_UPDATE | ||
2465 | * CY_RQT_MS_PARTITION_SELECT | ||
2466 | */ | ||
2467 | #ifndef __doxygen__ | ||
2468 | #define CY_RQT_USB_RQT_CONTEXT (3) | ||
2469 | #endif | ||
2470 | |||
2471 | /* Summary | ||
2472 | This command requests initialization of the USB stack. | ||
2473 | |||
2474 | Direction | ||
2475 | P Port Processor -> West Bridge | ||
2476 | |||
2477 | Length (in transfers) | ||
2478 | 1 | ||
2479 | |||
2480 | MailBox0 | ||
2481 | * Context = 3 | ||
2482 | * Request Code = 0 | ||
2483 | |||
2484 | Description | ||
2485 | This command is required before any other USB related command can be | ||
2486 | sent to the West Bridge firmware. | ||
2487 | |||
2488 | Responses | ||
2489 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2490 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_ALREADY_RUNNING | ||
2491 | */ | ||
2492 | #define CY_RQT_START_USB (0) | ||
2493 | |||
2494 | |||
2495 | /* Summary | ||
2496 | This command requests shutdown of the USB stack. | ||
2497 | |||
2498 | Direction | ||
2499 | P Port Processor -> West Bridge | ||
2500 | |||
2501 | Length (in transfers) | ||
2502 | 1 | ||
2503 | |||
2504 | MailBox0 | ||
2505 | * Context = 3 | ||
2506 | * Request Code = 1 | ||
2507 | |||
2508 | Responses | ||
2509 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2510 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
2511 | */ | ||
2512 | #define CY_RQT_STOP_USB (1) | ||
2513 | |||
2514 | |||
2515 | /* Summary | ||
2516 | This command requests that the USB pins be connected | ||
2517 | or disconnected to/from the West Bridge device. | ||
2518 | |||
2519 | Direction | ||
2520 | P Port Processor -> West Bridge | ||
2521 | |||
2522 | Length (in transfers) | ||
2523 | 1 | ||
2524 | |||
2525 | MailBox0 | ||
2526 | * Context = 3 | ||
2527 | * Request Code = 2 | ||
2528 | |||
2529 | D0 | ||
2530 | Desired Connect State | ||
2531 | * 0 = DISCONNECTED | ||
2532 | * 1 = CONNECTED | ||
2533 | |||
2534 | Responses | ||
2535 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2536 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
2537 | */ | ||
2538 | #define CY_RQT_SET_CONNECT_STATE (2) | ||
2539 | |||
2540 | |||
2541 | /* Summary | ||
2542 | This command requests the connection state of the | ||
2543 | West Bridge USB pins. | ||
2544 | |||
2545 | Direction | ||
2546 | P Port Processor -> West Bridge | ||
2547 | |||
2548 | Length (in transfers) | ||
2549 | 1 | ||
2550 | |||
2551 | MailBox0 | ||
2552 | * Context = 3 | ||
2553 | * Request Code = 3 | ||
2554 | |||
2555 | Responses | ||
2556 | * CY_RESP_CONNECT_STATE | ||
2557 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
2558 | */ | ||
2559 | #define CY_RQT_GET_CONNECT_STATE (3) | ||
2560 | |||
2561 | |||
2562 | /* Summary | ||
2563 | This request configures the USB subsystem. | ||
2564 | |||
2565 | Direction | ||
2566 | P Port Processor -> West Bridge | ||
2567 | |||
2568 | Length (in transfers) | ||
2569 | 2 | ||
2570 | |||
2571 | MailBox0 | ||
2572 | * Context = 3 | ||
2573 | * Request Code = 4 | ||
2574 | |||
2575 | D0 | ||
2576 | Bits 8 - 15: Media to enumerate (bit mask) | ||
2577 | Bits 0 - 7: Enumerate Mass Storage (bit mask) | ||
2578 | * 1 = Enumerate device on bus 0 | ||
2579 | * 2 = Enumerate device on bus 1 | ||
2580 | |||
2581 | D1 | ||
2582 | Enumeration Methodology | ||
2583 | * 1 = West Bridge enumeration | ||
2584 | * 0 = P Port enumeration | ||
2585 | |||
2586 | D2 | ||
2587 | Mass storage interface number - Interface number to | ||
2588 | be used for the mass storage interface | ||
2589 | |||
2590 | D3 | ||
2591 | Mass storage callbacks | ||
2592 | * 1 = relay to P port | ||
2593 | * 0 = completely handle in firmware | ||
2594 | |||
2595 | Description | ||
2596 | This indicates how enumeration should be handled. | ||
2597 | Enumeration can be handled by the West Bridge device | ||
2598 | or by the P port processor. | ||
2599 | |||
2600 | Responses | ||
2601 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2602 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_INVALID_MASK | ||
2603 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_INVALID_STORAGE_MEDIA | ||
2604 | */ | ||
2605 | #define CY_RQT_SET_USB_CONFIG (4) | ||
2606 | |||
2607 | |||
2608 | /* Summary | ||
2609 | This request retrieves the current USB configuration from | ||
2610 | the West Bridge device. | ||
2611 | |||
2612 | Direction | ||
2613 | P Port Processor -> West Bridge | ||
2614 | |||
2615 | Length (in transfers) | ||
2616 | 1 | ||
2617 | |||
2618 | MailBox0 | ||
2619 | * Context = 3 | ||
2620 | * Request Code = 5 | ||
2621 | |||
2622 | Responses | ||
2623 | * CY_RESP_USB_CONFIG | ||
2624 | */ | ||
2625 | #define CY_RQT_GET_USB_CONFIG (5) | ||
2626 | |||
2627 | |||
2628 | /* Summary | ||
2629 | This request stalls the given endpoint. | ||
2630 | |||
2631 | Direction | ||
2632 | P Port Processor -> West Bridge | ||
2633 | |||
2634 | Length (in transfers) | ||
2635 | 1 | ||
2636 | |||
2637 | MailBox0 | ||
2638 | * Context = 3 | ||
2639 | * Request Code = 6 | ||
2640 | |||
2641 | D0 | ||
2642 | Endpoint Number | ||
2643 | |||
2644 | D1 | ||
2645 | * 1 = Stall Endpoint | ||
2646 | * 0 = Clear Stall | ||
2647 | |||
2648 | Responses | ||
2649 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2650 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_INVALID_ENDPOINT | ||
2651 | */ | ||
2652 | #define CY_RQT_STALL_ENDPOINT (6) | ||
2653 | |||
2654 | |||
2655 | /* Summary | ||
2656 | This request retrieves the stall status of the | ||
2657 | requested endpoint. | ||
2658 | |||
2659 | Direction | ||
2660 | P Port Processor -> West Bridge | ||
2661 | |||
2662 | Length (in transfers) | ||
2663 | 1 | ||
2664 | |||
2665 | MailBox0 | ||
2666 | * Context = 3 | ||
2667 | * Request Code = 7 | ||
2668 | |||
2669 | D0 | ||
2670 | Endpoint number | ||
2671 | |||
2672 | Responses | ||
2673 | * CY_RESP_ENDPOINT_STALL | ||
2674 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_INVALID_ENDPOINT | ||
2675 | */ | ||
2676 | #define CY_RQT_GET_STALL (7) | ||
2677 | |||
2678 | |||
2679 | /* Summary | ||
2680 | This command sets the contents of a descriptor. | ||
2681 | |||
2682 | Direction | ||
2683 | P Port Processor -> West Bridge | ||
2684 | |||
2685 | Length (in transfers) | ||
2686 | 1 | ||
2687 | |||
2688 | MailBox0 | ||
2689 | * Context = 3 | ||
2690 | * Request Code = 8 | ||
2691 | |||
2692 | D0 | ||
2693 | Bit 15 - Bit 8 | ||
2694 | Descriptor Index | ||
2695 | |||
2696 | Bit 7 - Bit 0 | ||
2697 | Descriptor Type | ||
2698 | * Device = 1 | ||
2699 | * Device Qualifier = 2 | ||
2700 | * Full Speed Configuration = 3 | ||
2701 | * High Speed Configuration = 4 | ||
2702 | |||
2703 | * D1 - DN * | ||
2704 | Actual data for the descriptor | ||
2705 | |||
2706 | Responses | ||
2707 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2708 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_TYPE | ||
2709 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_INDEX | ||
2710 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_LENGTH | ||
2711 | */ | ||
2712 | #define CY_RQT_SET_DESCRIPTOR (8) | ||
2713 | |||
2714 | /* Summary | ||
2715 | This command gets the contents of a descriptor. | ||
2716 | |||
2717 | Direction | ||
2718 | P Port Processor -> West Bridge | ||
2719 | |||
2720 | Length (in transfers) | ||
2721 | 1 | ||
2722 | |||
2723 | MailBox0 | ||
2724 | * Context = 3 | ||
2725 | * Request Code = 9 | ||
2726 | |||
2727 | D0 | ||
2728 | Bit 15 - Bit 8 | ||
2729 | Descriptor Index | ||
2730 | |||
2731 | Bit 7 - Bit 0 | ||
2732 | Descriptor Type | ||
2733 | * Device = 1 | ||
2734 | * Device Qualifier = 2 | ||
2735 | * Full Speed Configuration = 3 | ||
2736 | * High Speed Configuration = 4 | ||
2737 | |||
2738 | Responses | ||
2739 | * CY_RESP_USB_DESCRIPTOR | ||
2740 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_TYPE | ||
2741 | * CY_RESP_SUCCESS_FAILURE:CY_ERR_BAD_INDEX | ||
2742 | */ | ||
2743 | #define CY_RQT_GET_DESCRIPTOR (9) | ||
2744 | |||
2745 | /* Summary | ||
2746 | This request is sent from the P port processor to the | ||
2747 | West Bridge device to physically configure the endpoints | ||
2748 | in the device. | ||
2749 | |||
2750 | Direction | ||
2751 | P Port Processor -> West Bridge | ||
2752 | |||
2753 | Length (in transfers) | ||
2754 | 3 | ||
2755 | |||
2756 | MailBox0 | ||
2757 | * Context = 3 | ||
2758 | * Request Code = 10 | ||
2759 | |||
2760 | D0 | ||
2761 | Bit 15 - Bit 8 | ||
2762 | EP1OUTCFG register value | ||
2763 | Bit 7 - Bit 0 | ||
2764 | EP1INCFG register value | ||
2765 | |||
2766 | * D1 - D2 * | ||
2767 | PEPxCFS register values where x = 3, 5, 7, 9 | ||
2768 | |||
2769 | * D3 - D7 * | ||
2770 | LEPxCFG register values where x = 3, 5, 7, 9, 10, | ||
2771 | 11, 12, 13, 14, 15 | ||
2772 | |||
2773 | Responses | ||
2774 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2775 | */ | ||
2776 | #define CY_RQT_SET_USB_CONFIG_REGISTERS (10) | ||
2777 | |||
2778 | /* Summary | ||
2779 | This request is sent to the P port processor when a | ||
2780 | USB event occurs and needs to be relayed to the | ||
2781 | P port. | ||
2782 | |||
2783 | Direction | ||
2784 | West Bridge -> P Port Processor | ||
2785 | |||
2786 | Length (in transfers) | ||
2787 | 1 | ||
2788 | |||
2789 | Mailbox0 | ||
2790 | * Context = 3 | ||
2791 | * Request Code = 11 | ||
2792 | |||
2793 | D0 | ||
2794 | Event Type | ||
2795 | * 0 = Reserved | ||
2796 | * 1 = Reserved | ||
2797 | * 2 = USB Suspend | ||
2798 | * 3 = USB Resume | ||
2799 | * 4 = USB Reset | ||
2800 | * 5 = USB Set Configuration | ||
2801 | * 6 = USB Speed change | ||
2802 | |||
2803 | D1 | ||
2804 | If EventTYpe is USB Speed change | ||
2805 | * 0 = Full Speed | ||
2806 | * 1 = High Speed | ||
2807 | |||
2808 | If EventType is USB Set Configuration | ||
2809 | * The number of the configuration to use | ||
2810 | * (may be zero to unconfigure) | ||
2811 | |||
2812 | Responses | ||
2813 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2814 | */ | ||
2815 | #define CY_RQT_USB_EVENT (11) | ||
2816 | |||
2817 | /* Summary | ||
2818 | This request is sent in both directions to transfer | ||
2819 | endpoint data for endpoints 0 and 1. | ||
2820 | |||
2821 | Direction | ||
2822 | West Bridge -> P Port Processor | ||
2823 | P Port Processor -> West Bridge | ||
2824 | |||
2825 | Length (in transfers) | ||
2826 | Variable | ||
2827 | |||
2828 | Mailbox0 | ||
2829 | * Context = 3 | ||
2830 | * Request Code = 12 | ||
2831 | |||
2832 | D0 | ||
2833 | Bit 15 - 14 Data Type | ||
2834 | * 0 = Setup (payload should be the 8 byte setup packet) | ||
2835 | * 1 = Data | ||
2836 | * 2 = Status (payload should be empty) | ||
2837 | |||
2838 | Bit 13 Endpoint Number (only 0 and 1 supported) | ||
2839 | Bit 12 First Packet (only supported for Host -> | ||
2840 | West Bridge traffic) | ||
2841 | Bit 11 Last Packet (only supported for Host -> | ||
2842 | West Bridge traffic) | ||
2843 | |||
2844 | Bit 9 - 0 Data Length (real max data length is 64 bytes | ||
2845 | for EP0 and EP1) | ||
2846 | |||
2847 | *D1-Dn* | ||
2848 | Endpoint data | ||
2849 | */ | ||
2850 | #define CY_RQT_USB_EP_DATA (12) | ||
2851 | |||
2852 | |||
2853 | /* Summary | ||
2854 | This request sets the NAK bit on an endpoint. | ||
2855 | |||
2856 | Direction | ||
2857 | P Port Processor -> West Bridge | ||
2858 | |||
2859 | Length (in transfers) | ||
2860 | 1 | ||
2861 | |||
2862 | MailBox0 | ||
2863 | * Context = 3 | ||
2864 | * Request Code = 13 | ||
2865 | |||
2866 | D0 | ||
2867 | Endpoint Number | ||
2868 | |||
2869 | D1 | ||
2870 | * 1 = NAK Endpoint | ||
2871 | * 0 = Clear NAK | ||
2872 | |||
2873 | Responses | ||
2874 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2875 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_INVALID_ENDPOINT | ||
2876 | */ | ||
2877 | #define CY_RQT_ENDPOINT_SET_NAK (13) | ||
2878 | |||
2879 | |||
2880 | /* Summary | ||
2881 | This request retrieves the NAK config status of the | ||
2882 | requested endpoint. | ||
2883 | |||
2884 | Direction | ||
2885 | P Port Processor -> West Bridge | ||
2886 | |||
2887 | Length (in transfers) | ||
2888 | 1 | ||
2889 | |||
2890 | MailBox0 | ||
2891 | * Context = 3 | ||
2892 | * Request Code = 14 | ||
2893 | |||
2894 | D0 | ||
2895 | Endpoint number | ||
2896 | |||
2897 | Responses | ||
2898 | * CY_RESP_ENDPOINT_NAK | ||
2899 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_INVALID_ENDPOINT | ||
2900 | */ | ||
2901 | #define CY_RQT_GET_ENDPOINT_NAK (14) | ||
2902 | |||
2903 | /* Summary | ||
2904 | This request acknowledges a setup packet that does not | ||
2905 | require any data transfer. | ||
2906 | |||
2907 | Direction | ||
2908 | P Port Processor -> West Bridge | ||
2909 | |||
2910 | Length (in transfers) | ||
2911 | 1 | ||
2912 | |||
2913 | MailBox | ||
2914 | * Context = 3 | ||
2915 | * Request Code = 15 | ||
2916 | |||
2917 | Responses | ||
2918 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
2919 | */ | ||
2920 | #define CY_RQT_ACK_SETUP_PACKET (15) | ||
2921 | |||
2922 | /* Summary | ||
2923 | This request is sent when the USB storage driver within | ||
2924 | West Bridge receives an Inquiry request. | ||
2925 | |||
2926 | Direction | ||
2927 | West Bridge -> P Port Processor | ||
2928 | |||
2929 | Length (in transfers) | ||
2930 | x - variable | ||
2931 | |||
2932 | Mailbox0 | ||
2933 | * Context = 3 | ||
2934 | * Request Code = 16 | ||
2935 | |||
2936 | D0 | ||
2937 | Bits 12 - 15 : Bus index | ||
2938 | Bits 8 - 11 : Zero based device index | ||
2939 | Bits 0 - 7 : Media type being addressed | ||
2940 | |||
2941 | D1 | ||
2942 | Bits 8 : EVPD bit from request | ||
2943 | Bits 0 - 7 : Codepage from the inquiry request | ||
2944 | |||
2945 | D2 | ||
2946 | Length of the inquiry response in bytes | ||
2947 | |||
2948 | * D3 - Dn * | ||
2949 | The inquiry response | ||
2950 | |||
2951 | Description | ||
2952 | When the West Bridge firmware receives an SCSI Inquiry | ||
2953 | request from the USB host, the response to this mass | ||
2954 | storage command is created by West Bridge and forwarded to | ||
2955 | the P port processor. The P port processor may change | ||
2956 | this response before it is returned to the USB host. This | ||
2957 | request is the method by which this may happen. | ||
2958 | */ | ||
2959 | #define CY_RQT_SCSI_INQUIRY_COMMAND (16) | ||
2960 | |||
2961 | /* Summary | ||
2962 | This request is sent when the USB storage driver within | ||
2963 | West Bridge receives a Start/Stop request. | ||
2964 | |||
2965 | Direction | ||
2966 | West Bridge -> P Port Processor | ||
2967 | |||
2968 | Length (in transfers) | ||
2969 | 1 | ||
2970 | |||
2971 | Mailbox0 | ||
2972 | * Context = 3 | ||
2973 | * Request Code = 17 | ||
2974 | |||
2975 | D0 | ||
2976 | Bits 12 - 15 : Bus index | ||
2977 | Bits 8 - 11 : Zero based device index | ||
2978 | Bits 0 - 7 : Media type being addressed | ||
2979 | |||
2980 | D1 | ||
2981 | Bit 1 | ||
2982 | * LoEj Bit (See SCSI-3 specification) | ||
2983 | |||
2984 | Bit 0 | ||
2985 | * Start Bit (See SCSI-3 specification) | ||
2986 | |||
2987 | Description | ||
2988 | When the West Bridge firmware received a SCSI Start/Stop | ||
2989 | request from the USB host, this request is relayed to the | ||
2990 | P port processor. This request is used to relay the command. | ||
2991 | The USB firmware will not response to the USB command until | ||
2992 | the response to this request is recevied by the firmware. | ||
2993 | */ | ||
2994 | #define CY_RQT_SCSI_START_STOP_COMMAND (17) | ||
2995 | |||
2996 | /* Summary | ||
2997 | This request is sent when the USB storage driver | ||
2998 | receives an unknown CBW on mass storage. | ||
2999 | |||
3000 | Direction | ||
3001 | West Bridge -> P Port Processor | ||
3002 | |||
3003 | Length (in transfers) | ||
3004 | 4 | ||
3005 | |||
3006 | Mailbox0 | ||
3007 | * Context = 3 | ||
3008 | * Request Code = 18 | ||
3009 | |||
3010 | D0 | ||
3011 | Bits 12 - 15 : MediaType | ||
3012 | * 0 = NAND | ||
3013 | * 1 = SDIO Flash | ||
3014 | * 2 = MMC Flash | ||
3015 | * 3 = CE-ATA | ||
3016 | |||
3017 | D1 | ||
3018 | The length of the request in bytes | ||
3019 | |||
3020 | D2 - Dn | ||
3021 | CBW command block from the SCSI host controller. | ||
3022 | |||
3023 | Description | ||
3024 | When the firmware recevies a SCSI request that is not | ||
3025 | understood, this request is relayed to the | ||
3026 | P port processor. | ||
3027 | */ | ||
3028 | #define CY_RQT_SCSI_UNKNOWN_COMMAND (18) | ||
3029 | |||
3030 | /* Summary | ||
3031 | Request the West Bridge to signal remote wakeup | ||
3032 | to the USB host. | ||
3033 | |||
3034 | Direction | ||
3035 | P Port Processor -> West Bridge | ||
3036 | |||
3037 | Length (in transfers) | ||
3038 | 1 | ||
3039 | |||
3040 | Mailbox0 | ||
3041 | * Context = 3 | ||
3042 | * Request code = 19 | ||
3043 | |||
3044 | Description | ||
3045 | Request from the processor to West Bridge, to signal | ||
3046 | remote wakeup to the USB host. | ||
3047 | |||
3048 | Responses | ||
3049 | * CY_RESP_SUCCESS_FAILURE | ||
3050 | */ | ||
3051 | #define CY_RQT_USB_REMOTE_WAKEUP (19) | ||
3052 | |||
3053 | /* Summary | ||
3054 | Request the West Bridge to clear all descriptors tha | ||
3055 | were set previously | ||
3056 | using the Set Descriptor calls. | ||
3057 | |||
3058 | Direction | ||
3059 | P Port Processor -> West Bridge | ||
3060 | |||
3061 | Length (in transfers) | ||
3062 | 1 | ||
3063 | |||
3064 | Mailbox0 | ||
3065 | * Context = 3 | ||
3066 | * Request code = 20 | ||
3067 | |||
3068 | Description | ||
3069 | Request from the processor to West Bridge, to clear | ||
3070 | all descriptor information that was previously stored | ||
3071 | on the West Bridge using CyAnUsbSetDescriptor calls. | ||
3072 | |||
3073 | Responses | ||
3074 | * CY_RESP_SUCCESS_FAILURE | ||
3075 | */ | ||
3076 | #define CY_RQT_CLEAR_DESCRIPTORS (20) | ||
3077 | |||
3078 | /* Summary | ||
3079 | Request the West Bridge to monitor USB to storage activity | ||
3080 | and send periodic updates. | ||
3081 | |||
3082 | Direction | ||
3083 | P Port Processor -> West Bridge | ||
3084 | |||
3085 | Length (in transfers) | ||
3086 | 2 | ||
3087 | |||
3088 | Mailbox0 | ||
3089 | * Context = 3 | ||
3090 | * Request code = 21 | ||
3091 | |||
3092 | D0 | ||
3093 | Upper 16 bits of write threshold | ||
3094 | |||
3095 | D1 | ||
3096 | Lower 16 bits of write threshold | ||
3097 | |||
3098 | D2 | ||
3099 | Upper 16 bits of read threshold | ||
3100 | |||
3101 | D3 | ||
3102 | Lower 16 bits of read threshold | ||
3103 | |||
3104 | Description | ||
3105 | Request from the processor to West Bridge, to start | ||
3106 | monitoring the level of read/write activity on the | ||
3107 | USB mass storage drive and to set the threshold | ||
3108 | level at which progress reports are sent. | ||
3109 | |||
3110 | Responses | ||
3111 | * CY_RESP_SUCCESS_FAILURE | ||
3112 | */ | ||
3113 | #define CY_RQT_USB_STORAGE_MONITOR (21) | ||
3114 | |||
3115 | /* Summary | ||
3116 | Event from the West Bridge showing that U2S activity | ||
3117 | since the last event has crossed the threshold. | ||
3118 | |||
3119 | Direction | ||
3120 | West Bridge -> P Port Processor | ||
3121 | |||
3122 | Length (in transfers) | ||
3123 | 2 | ||
3124 | |||
3125 | Mailbox0 | ||
3126 | * Context = 3 | ||
3127 | * Request code = 22 | ||
3128 | |||
3129 | D0 | ||
3130 | Upper 16 bits of sectors written since last event. | ||
3131 | |||
3132 | D1 | ||
3133 | Lower 16 bits of sectors written since last event. | ||
3134 | |||
3135 | D2 | ||
3136 | Upper 16 bits of sectors read since last event. | ||
3137 | |||
3138 | D3 | ||
3139 | Lower 16 bits of sectors read since last event. | ||
3140 | |||
3141 | Description | ||
3142 | Event notification from the West Bridge indicating | ||
3143 | that the number of read/writes on the USB mass | ||
3144 | storage device have crossed a pre-defined threshold | ||
3145 | level. | ||
3146 | |||
3147 | Responses | ||
3148 | * CY_RESP_SUCCESS_FAILURE | ||
3149 | */ | ||
3150 | #define CY_RQT_USB_ACTIVITY_UPDATE (22) | ||
3151 | |||
3152 | /* Summary | ||
3153 | Request to select the partitions to be enumerated on a | ||
3154 | storage device with partitions. | ||
3155 | |||
3156 | Direction | ||
3157 | P Port Processor -> West Bridge | ||
3158 | |||
3159 | Length (in transfers) | ||
3160 | 1 | ||
3161 | |||
3162 | Mailbox0 | ||
3163 | * Context = 3 | ||
3164 | * Request code = 23 | ||
3165 | |||
3166 | D0 | ||
3167 | Bits 8-15 : Bus index | ||
3168 | Bits 0- 7 : Device index | ||
3169 | |||
3170 | D1 | ||
3171 | Bits 8-15 : Control whether to enumerate partition 1. | ||
3172 | Bits 0- 7 : Control whether to enumerate partition 0. | ||
3173 | |||
3174 | Responses | ||
3175 | * CY_RESP_SUCCESS_FAILURE | ||
3176 | */ | ||
3177 | #define CY_RQT_MS_PARTITION_SELECT (23) | ||
3178 | |||
3179 | /************/ | ||
3180 | |||
3181 | /*@@USB responses | ||
3182 | Summary | ||
3183 | The USB responses include: | ||
3184 | * CY_RESP_USB_CONFIG | ||
3185 | * CY_RESP_ENDPOINT_CONFIG | ||
3186 | * CY_RESP_ENDPOINT_STALL | ||
3187 | * CY_RESP_CONNECT_STATE | ||
3188 | * CY_RESP_USB_DESCRIPTOR | ||
3189 | * CY_RESP_USB_INVALID_EVENT | ||
3190 | * CY_RESP_ENDPOINT_NAK | ||
3191 | * CY_RESP_INQUIRY_DATA | ||
3192 | * CY_RESP_UNKNOWN_SCSI_COMMAND | ||
3193 | */ | ||
3194 | |||
3195 | /* Summary | ||
3196 | This response contains the enumeration configuration | ||
3197 | information for the USB module. | ||
3198 | |||
3199 | Direction | ||
3200 | 8051->P | ||
3201 | |||
3202 | Length (in transfers) | ||
3203 | 1 | ||
3204 | |||
3205 | MailBox0 | ||
3206 | * Context = 3 | ||
3207 | * Response Code = 32 | ||
3208 | |||
3209 | D0 | ||
3210 | Bits 8 - 15: Media to enumerate (bit mask) | ||
3211 | Bits 0 - 7: Buses to enumerate (bit mask) | ||
3212 | * 1 = Bus 0 | ||
3213 | * 2 = Bus 1 | ||
3214 | |||
3215 | D1 | ||
3216 | Enumeration Methodology | ||
3217 | * 0 = West Bridge enumeration | ||
3218 | * 1 = P Port enumeration | ||
3219 | |||
3220 | D2 | ||
3221 | Bits 7 - 0 : Interface Count - the number of interfaces | ||
3222 | Bits 15 - 8 : Mass storage callbacks | ||
3223 | |||
3224 | */ | ||
3225 | #define CY_RESP_USB_CONFIG (32) | ||
3226 | |||
3227 | |||
3228 | /* Summary | ||
3229 | This response contains the configuration information | ||
3230 | for the specified endpoint. | ||
3231 | |||
3232 | Direction | ||
3233 | 8051->P | ||
3234 | |||
3235 | Length (in transfers) | ||
3236 | 1 | ||
3237 | |||
3238 | MailBox0 | ||
3239 | * Context = 3 | ||
3240 | * Response Code = 33 | ||
3241 | |||
3242 | D0 | ||
3243 | Bits 15 - 12 : Endpoint Number (0 - 15) | ||
3244 | |||
3245 | Bits 11 - 10 : Endpoint Type | ||
3246 | * 0 = Control | ||
3247 | * 1 = Bulk | ||
3248 | * 2 = Interrupt | ||
3249 | * 3 = Isochronous | ||
3250 | |||
3251 | Bits 9 : Endpoint Size | ||
3252 | * 0 = 512 | ||
3253 | * 1 = 1024 | ||
3254 | |||
3255 | Bits 8 - 7 : Buffering | ||
3256 | * 0 = Double | ||
3257 | * 1 = Triple | ||
3258 | * 2 = Quad | ||
3259 | |||
3260 | Bits 6 : Bit Direction | ||
3261 | * 0 = Input | ||
3262 | * 1 = Output | ||
3263 | */ | ||
3264 | #define CY_RESP_ENDPOINT_CONFIG (33) | ||
3265 | |||
3266 | |||
3267 | /* Summary | ||
3268 | This response contains the stall status for | ||
3269 | the specified endpoint. | ||
3270 | |||
3271 | Direction | ||
3272 | 8051->P | ||
3273 | |||
3274 | Length (in transfers) | ||
3275 | 1 | ||
3276 | |||
3277 | MailBox0 | ||
3278 | * Context = 3 | ||
3279 | * Response Code = 34 | ||
3280 | |||
3281 | D0 | ||
3282 | Stall status | ||
3283 | * 0 = Active | ||
3284 | * 1 = Stalled | ||
3285 | */ | ||
3286 | #define CY_RESP_ENDPOINT_STALL (34) | ||
3287 | |||
3288 | |||
3289 | /* Summary | ||
3290 | This response contains the connected/disconnected | ||
3291 | state of the West Bridge USB pins. | ||
3292 | |||
3293 | Direction | ||
3294 | 8051->P | ||
3295 | |||
3296 | Length (in transfers) | ||
3297 | 1 | ||
3298 | |||
3299 | MailBox0 | ||
3300 | * Context = 3 | ||
3301 | * Response Code = 35 | ||
3302 | |||
3303 | D0 | ||
3304 | Connect state | ||
3305 | * 0 = Disconnected | ||
3306 | * 1 = Connected | ||
3307 | */ | ||
3308 | #define CY_RESP_CONNECT_STATE (35) | ||
3309 | |||
3310 | /* Summary | ||
3311 | This response contains the information | ||
3312 | about the USB configuration | ||
3313 | |||
3314 | Direction | ||
3315 | West Bridge -> P Port Processor | ||
3316 | |||
3317 | Length | ||
3318 | x bytes | ||
3319 | |||
3320 | Mailbox0 | ||
3321 | * Context = 3 | ||
3322 | * Response Code = 36 | ||
3323 | |||
3324 | D0 | ||
3325 | Length in bytes of the descriptor | ||
3326 | |||
3327 | * D1 - DN * | ||
3328 | Descriptor contents | ||
3329 | */ | ||
3330 | #define CY_RESP_USB_DESCRIPTOR (36) | ||
3331 | |||
3332 | /* Summary | ||
3333 | This response is sent in response to a bad USB event code | ||
3334 | |||
3335 | Direction | ||
3336 | P Port Processor -> West Bridge | ||
3337 | |||
3338 | Length | ||
3339 | 1 word (2 bytes) | ||
3340 | |||
3341 | Mailbox0 | ||
3342 | * Context = 3 | ||
3343 | * Response Code = 37 | ||
3344 | |||
3345 | D0 | ||
3346 | The invalid event code in the request | ||
3347 | */ | ||
3348 | #define CY_RESP_USB_INVALID_EVENT (37) | ||
3349 | |||
3350 | /* Summary | ||
3351 | This response contains the current NAK status of | ||
3352 | a USB endpoint. | ||
3353 | |||
3354 | Direction | ||
3355 | West Bridge -> P port processor | ||
3356 | |||
3357 | Length | ||
3358 | 1 transfer | ||
3359 | |||
3360 | Mailbox0 | ||
3361 | * Context = 3 | ||
3362 | * Response Code = 38 | ||
3363 | |||
3364 | D0 | ||
3365 | The NAK status of the endpoint | ||
3366 | 1 : NAK bit set | ||
3367 | 0 : NAK bit clear | ||
3368 | */ | ||
3369 | #define CY_RESP_ENDPOINT_NAK (38) | ||
3370 | |||
3371 | /* Summary | ||
3372 | This response gives the contents of the inquiry | ||
3373 | data back to West Bridge to returns to the USB host. | ||
3374 | |||
3375 | Direction | ||
3376 | West Bridge -> P Port Processor | ||
3377 | |||
3378 | Length | ||
3379 | Variable | ||
3380 | |||
3381 | MailBox0 | ||
3382 | * Context = 3 | ||
3383 | * Response Code = 39 | ||
3384 | |||
3385 | D0 | ||
3386 | Length of the inquiry response | ||
3387 | |||
3388 | *D1 - Dn* | ||
3389 | Inquiry data | ||
3390 | */ | ||
3391 | #define CY_RESP_INQUIRY_DATA (39) | ||
3392 | |||
3393 | /* Summary | ||
3394 | This response gives the status of an unknown SCSI command. | ||
3395 | This also gives three bytes of sense information. | ||
3396 | |||
3397 | Direction | ||
3398 | P Port Processor -> West Bridge | ||
3399 | |||
3400 | Length (in transfers) | ||
3401 | 1 | ||
3402 | |||
3403 | Mailbox0 | ||
3404 | * Context = 3 | ||
3405 | * Response Code = 40 | ||
3406 | |||
3407 | D0 | ||
3408 | The length of the reply in bytes | ||
3409 | |||
3410 | D1 | ||
3411 | * Status of the command | ||
3412 | * Sense Key | ||
3413 | |||
3414 | D2 | ||
3415 | * Additional Sense Code (ASC) | ||
3416 | * Additional Sense Code Qualifier (ASCQ) | ||
3417 | */ | ||
3418 | #define CY_RESP_UNKNOWN_SCSI_COMMAND (40) | ||
3419 | /*******************************************************/ | ||
3420 | |||
3421 | /*@@Turbo requests | ||
3422 | Summary | ||
3423 | The Turbo requests include: | ||
3424 | * CY_RQT_START_MTP | ||
3425 | * CY_RQT_STOP_MTP | ||
3426 | * CY_RQT_INIT_SEND_OBJECT | ||
3427 | * CY_RQT_CANCEL_SEND_OBJECT | ||
3428 | * CY_RQT_INIT_GET_OBJECT | ||
3429 | * CY_RQT_CANCEL_GET_OBJECT | ||
3430 | * CY_RQT_SEND_BLOCK_TABLE | ||
3431 | * CY_RQT_MTP_EVENT | ||
3432 | * CY_RQT_TURBO_CMD_FROM_HOST | ||
3433 | * CY_RQT_TURBO_SEND_RESP_DATA_TO_HOST | ||
3434 | * CY_RQT_TURBO_SWITCH_ENDPOINT | ||
3435 | * CY_RQT_TURBO_START_WRITE_DMA | ||
3436 | * CY_RQT_ENABLE_USB_PATH | ||
3437 | * CY_RQT_CANCEL_ASYNC_TRANSFER | ||
3438 | */ | ||
3439 | #ifndef __doxygen__ | ||
3440 | #define CY_RQT_TUR_RQT_CONTEXT (4) | ||
3441 | #endif | ||
3442 | |||
3443 | /* Summary | ||
3444 | This command requests initialization of the MTP stack. | ||
3445 | |||
3446 | Direction | ||
3447 | P Port Processor -> West Bridge | ||
3448 | |||
3449 | Length (in transfers) | ||
3450 | 1 | ||
3451 | |||
3452 | MailBox0 | ||
3453 | * Context = 4 | ||
3454 | * Request Code = 0 | ||
3455 | |||
3456 | Description | ||
3457 | This command is required before any other MTP related | ||
3458 | command can be sent to the West Bridge firmware. | ||
3459 | |||
3460 | Responses | ||
3461 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3462 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_ALREADY_RUNNING | ||
3463 | */ | ||
3464 | #define CY_RQT_START_MTP (0) | ||
3465 | |||
3466 | /* Summary | ||
3467 | This command requests shutdown of the MTP stack. | ||
3468 | |||
3469 | Direction | ||
3470 | P Port Processor -> West Bridge | ||
3471 | |||
3472 | Length (in transfers) | ||
3473 | 1 | ||
3474 | |||
3475 | MailBox0 | ||
3476 | * Context = 4 | ||
3477 | * Request Code = 1 | ||
3478 | |||
3479 | Responses | ||
3480 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3481 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3482 | */ | ||
3483 | #define CY_RQT_STOP_MTP (1) | ||
3484 | |||
3485 | /* Summary | ||
3486 | This command sets up an MTP SendObject operation. | ||
3487 | |||
3488 | Direction | ||
3489 | P Port Processor -> West Bridge | ||
3490 | |||
3491 | Length (in transfers) | ||
3492 | 1 | ||
3493 | |||
3494 | MailBox0 | ||
3495 | * Context = 4 | ||
3496 | * Request Code = 2 | ||
3497 | |||
3498 | D0 | ||
3499 | Total bytes for send object Low 16 bits | ||
3500 | |||
3501 | D1 | ||
3502 | Total bytes for send object High 16 bits | ||
3503 | |||
3504 | Responses | ||
3505 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3506 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3507 | */ | ||
3508 | #define CY_RQT_INIT_SEND_OBJECT (2) | ||
3509 | |||
3510 | /* Summary | ||
3511 | This command cancels West Bridges handling of | ||
3512 | an ongoing MTP SendObject operation. This | ||
3513 | does NOT send an MTP response. | ||
3514 | |||
3515 | Direction | ||
3516 | P Port Processor -> West Bridge | ||
3517 | |||
3518 | Length (in transfers) | ||
3519 | 1 | ||
3520 | |||
3521 | MailBox0 | ||
3522 | * Context = 4 | ||
3523 | * Request Code = 3 | ||
3524 | |||
3525 | Responses | ||
3526 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3527 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3528 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_NO_OPERATION_PENDING | ||
3529 | */ | ||
3530 | #define CY_RQT_CANCEL_SEND_OBJECT (3) | ||
3531 | |||
3532 | /* Summary | ||
3533 | This command sets up an MTP GetObject operation. | ||
3534 | |||
3535 | Direction | ||
3536 | P Port Processor -> West Bridge | ||
3537 | |||
3538 | Length (in transfers) | ||
3539 | 2 | ||
3540 | |||
3541 | MailBox0 | ||
3542 | * Context = 4 | ||
3543 | * Request Code = 4 | ||
3544 | |||
3545 | D0 | ||
3546 | Total bytes for get object Low 16 bits | ||
3547 | |||
3548 | D1 | ||
3549 | Total bytes for get object High 16 bits | ||
3550 | |||
3551 | D2 | ||
3552 | Transaction Id for get object Low 16 bits | ||
3553 | |||
3554 | D3 | ||
3555 | Transaction Id for get object High 16 bits | ||
3556 | |||
3557 | Responses | ||
3558 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3559 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3560 | */ | ||
3561 | #define CY_RQT_INIT_GET_OBJECT (4) | ||
3562 | |||
3563 | /* Summary | ||
3564 | This command notifies West Bridge of a new | ||
3565 | BlockTable transfer. | ||
3566 | |||
3567 | Direction | ||
3568 | P Port Processor -> West Bridge | ||
3569 | |||
3570 | Length (in transfers) | ||
3571 | 1 | ||
3572 | |||
3573 | MailBox0 | ||
3574 | * Context = 4 | ||
3575 | * Request Code = 5 | ||
3576 | |||
3577 | Responses | ||
3578 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3579 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3580 | */ | ||
3581 | #define CY_RQT_SEND_BLOCK_TABLE (5) | ||
3582 | |||
3583 | /* Summary | ||
3584 | This request is sent to the P port processor when a MTP event occurs | ||
3585 | and needs to be relayed to the P port. | ||
3586 | |||
3587 | Direction | ||
3588 | West Bridge -> P Port Processor | ||
3589 | |||
3590 | Length (in transfers) | ||
3591 | 2 | ||
3592 | |||
3593 | Mailbox0 | ||
3594 | * Context = 4 | ||
3595 | * Request Code = 6 | ||
3596 | |||
3597 | D0 | ||
3598 | Bits 15 - 8 : Return Status for GetObject/SendObject | ||
3599 | Bits 7 - 0 : Event Type | ||
3600 | * 0 = MTP SendObject Complete | ||
3601 | * 1 = MTP GetObject Complete | ||
3602 | * 2 = BlockTable Needed | ||
3603 | |||
3604 | D1 | ||
3605 | Lower 16 bits of the length of the data that got transferred | ||
3606 | in the Turbo Endpoint.(Applicable to "MTP SendObject Complete" | ||
3607 | and "MTP GetObject Complete" events) | ||
3608 | |||
3609 | D2 | ||
3610 | Upper 16 bits of the length of the data that got transferred | ||
3611 | in the Turbo Endpoint. (Applicable to "MTP SendObject Complete" | ||
3612 | and "MTP GetObject Complete" events) | ||
3613 | |||
3614 | D3 | ||
3615 | Lower 16 bits of the Transaction Id of the MTP_SEND_OBJECT | ||
3616 | command. (Applicable to "MTP SendObject Complete" event) | ||
3617 | |||
3618 | D4 | ||
3619 | Upper 16 bits of the Transaction Id of the MTP_SEND_OBJECT | ||
3620 | command. (Applicable to "MTP SendObject Complete" event) | ||
3621 | |||
3622 | Responses | ||
3623 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3624 | */ | ||
3625 | #define CY_RQT_MTP_EVENT (6) | ||
3626 | |||
3627 | /* Summary | ||
3628 | This request is sent to the P port processor when a command | ||
3629 | is received from Host in a Turbo Endpoint. Upon receiving | ||
3630 | this event, P port should read the data from the endpoint as | ||
3631 | soon as possible. | ||
3632 | |||
3633 | Direction | ||
3634 | West Bridge -> P Port Processor | ||
3635 | |||
3636 | Length (in transfers) | ||
3637 | 1 | ||
3638 | |||
3639 | Mailbox0 | ||
3640 | * Context = 4 | ||
3641 | * Request Code = 7 | ||
3642 | |||
3643 | D0 | ||
3644 | This contains the EP number. (This will be always two now). | ||
3645 | |||
3646 | D1 | ||
3647 | Length of the data available in the Turbo Endpoint. | ||
3648 | |||
3649 | Responses | ||
3650 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3651 | */ | ||
3652 | #define CY_RQT_TURBO_CMD_FROM_HOST (7) | ||
3653 | |||
3654 | /* Summary | ||
3655 | This request is sent to the West Bridge when the P port | ||
3656 | needs to send data to the Host in a Turbo Endpoint. | ||
3657 | Upon receiving this event, Firmware will make the end point | ||
3658 | available for the P port. If the length is zero, then | ||
3659 | firmware will send a zero length packet. | ||
3660 | |||
3661 | Direction | ||
3662 | P Port Processor -> West Bridge | ||
3663 | |||
3664 | Length (in transfers) | ||
3665 | 2 | ||
3666 | |||
3667 | Mailbox0 | ||
3668 | * Context = 4 | ||
3669 | * Request Code = 8 | ||
3670 | |||
3671 | D0 | ||
3672 | This contains the EP number. (This will be always six now). | ||
3673 | |||
3674 | D1 | ||
3675 | Lower 16 bits of the length of the data that needs to be | ||
3676 | sent in the Turbo Endpoint. | ||
3677 | |||
3678 | D2 | ||
3679 | Upper 16 bits of the length of the data that needs to be | ||
3680 | sent in the Turbo Endpoint. | ||
3681 | |||
3682 | Responses | ||
3683 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3684 | */ | ||
3685 | #define CY_RQT_TURBO_SEND_RESP_DATA_TO_HOST (8) | ||
3686 | |||
3687 | /* Summary | ||
3688 | This command cancels West Bridges handling of | ||
3689 | an ongoing MTP GetObject operation. This | ||
3690 | does NOT send an MTP response. | ||
3691 | |||
3692 | Direction | ||
3693 | P Port Processor -> West Bridge | ||
3694 | |||
3695 | Length (in transfers) | ||
3696 | 1 | ||
3697 | |||
3698 | MailBox0 | ||
3699 | * Context = 4 | ||
3700 | * Request Code = 9 | ||
3701 | |||
3702 | Responses | ||
3703 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3704 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3705 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_NO_OPERATION_PENDING | ||
3706 | */ | ||
3707 | #define CY_RQT_CANCEL_GET_OBJECT (9) | ||
3708 | |||
3709 | /* Summary | ||
3710 | This command switches a Turbo endpoint | ||
3711 | from the U port to the P port. If no data | ||
3712 | is in the endpoint the endpoint is | ||
3713 | primed to switch as soon as data is placed | ||
3714 | in the endpoint. The endpoint will continue | ||
3715 | to switch until all data has been transferd. | ||
3716 | |||
3717 | Direction | ||
3718 | P Port Processor -> West Bridge | ||
3719 | |||
3720 | Length (in transfers) | ||
3721 | 2 | ||
3722 | |||
3723 | MailBox0 | ||
3724 | * Context = 4 | ||
3725 | * Request Code = 10 | ||
3726 | |||
3727 | D0 | ||
3728 | Whether the read is a packet read. | ||
3729 | |||
3730 | D1 | ||
3731 | Lower 16 bits of the length of the data to switch | ||
3732 | the Turbo Endpoint for. | ||
3733 | |||
3734 | D2 | ||
3735 | Upper 16 bits of the length of the data to switch | ||
3736 | the Turbo Endpoint for. | ||
3737 | |||
3738 | Responses | ||
3739 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3740 | * CY_RESP_SUCCESS_FAILURE:CY_RESP_NOT_RUNNING | ||
3741 | */ | ||
3742 | #define CY_RQT_TURBO_SWITCH_ENDPOINT (10) | ||
3743 | |||
3744 | /* Summary | ||
3745 | This command requests the API to start the DMA | ||
3746 | transfer of a packet of MTP data to the Antioch. | ||
3747 | |||
3748 | Direction | ||
3749 | West Bridge -> P Port Processor | ||
3750 | |||
3751 | Length (in transfers) | ||
3752 | 1 | ||
3753 | |||
3754 | MailBox0 | ||
3755 | * Context = 4 | ||
3756 | * Request Code = 11 | ||
3757 | |||
3758 | Responses | ||
3759 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3760 | */ | ||
3761 | #define CY_RQT_TURBO_START_WRITE_DMA (11) | ||
3762 | |||
3763 | /* Summary | ||
3764 | This command requests the firmware to switch the | ||
3765 | internal data paths to enable USB access to the | ||
3766 | Mass storage / MTP endpoints. | ||
3767 | |||
3768 | Direction | ||
3769 | P Port Processor -> West Bridge | ||
3770 | |||
3771 | Length (in transfers) | ||
3772 | 1 | ||
3773 | |||
3774 | MailBox0 | ||
3775 | * Context = 4 | ||
3776 | * Request code = 12 | ||
3777 | |||
3778 | Responses | ||
3779 | * CY_RESP_SUCCESS_FAILURE:CY_AS_ERROR_SUCCESS | ||
3780 | */ | ||
3781 | #define CY_RQT_ENABLE_USB_PATH (12) | ||
3782 | |||
3783 | /* Summary | ||
3784 | Request to cancel an asynchronous MTP write from | ||
3785 | the processor side. | ||
3786 | |||
3787 | Direction | ||
3788 | P Port processor -> West Bridge | ||
3789 | |||
3790 | Length (in transfers) | ||
3791 | 1 | ||
3792 | |||
3793 | Mailbox0 | ||
3794 | * Context = 4 | ||
3795 | * Request code = 13 | ||
3796 | |||
3797 | D0 | ||
3798 | * EP number | ||
3799 | |||
3800 | Description | ||
3801 | This is a request to the firmware to update internal | ||
3802 | state so that a pending write on the MTP endpoint | ||
3803 | can be cancelled. | ||
3804 | */ | ||
3805 | #define CY_RQT_CANCEL_ASYNC_TRANSFER (13) | ||
3806 | |||
3807 | /******************************************************/ | ||
3808 | |||
3809 | /*@@Turbo responses | ||
3810 | Summary | ||
3811 | The Turbo responses include: | ||
3812 | * CY_RESP_MTP_INVALID_EVENT | ||
3813 | */ | ||
3814 | |||
3815 | /* Summary | ||
3816 | This response is sent in response to a bad MTP event code | ||
3817 | |||
3818 | Direction | ||
3819 | P Port Processor -> West Bridge | ||
3820 | |||
3821 | Length | ||
3822 | 1 word (2 bytes) | ||
3823 | |||
3824 | Mailbox0 | ||
3825 | * Context = 4 | ||
3826 | * Response Code = 16 | ||
3827 | |||
3828 | D0 | ||
3829 | The invalid event code in the request | ||
3830 | */ | ||
3831 | #define CY_RESP_MTP_INVALID_EVENT (16) | ||
3832 | |||
3833 | #ifndef __doxygen__ | ||
3834 | #define CY_RQT_CONTEXT_COUNT (5) | ||
3835 | #endif | ||
3836 | |||
3837 | #endif /* _INCLUDED_CYASPROTOCOL_H_ */ | ||
3838 | |||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasregs.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasregs.h deleted file mode 100644 index f049d7e32a4b..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasregs.h +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasregs.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASREG_H_ | ||
23 | #define _INCLUDED_CYASREG_H_ | ||
24 | |||
25 | #if !defined(__doxygen__) | ||
26 | |||
27 | #define CY_AS_MEM_CM_WB_CFG_ID (0x80) | ||
28 | #define CY_AS_MEM_CM_WB_CFG_ID_VER_MASK (0x000F) | ||
29 | #define CY_AS_MEM_CM_WB_CFG_ID_HDID_MASK (0xFFF0) | ||
30 | #define CY_AS_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE (0xA100) | ||
31 | #define CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE (0x6800) | ||
32 | #define CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE (0xA200) | ||
33 | |||
34 | |||
35 | #define CY_AS_MEM_RST_CTRL_REG (0x81) | ||
36 | #define CY_AS_MEM_RST_CTRL_REG_HARD (0x0003) | ||
37 | #define CY_AS_MEM_RST_CTRL_REG_SOFT (0x0001) | ||
38 | #define CY_AS_MEM_RST_RSTCMPT (0x0004) | ||
39 | |||
40 | #define CY_AS_MEM_P0_ENDIAN (0x82) | ||
41 | #define CY_AS_LITTLE_ENDIAN (0x0000) | ||
42 | #define CY_AS_BIG_ENDIAN (0x0101) | ||
43 | |||
44 | #define CY_AS_MEM_P0_VM_SET (0x83) | ||
45 | #define CY_AS_MEM_P0_VM_SET_VMTYPE_MASK (0x0007) | ||
46 | #define CY_AS_MEM_P0_VM_SET_VMTYPE_RAM (0x0005) | ||
47 | #define CY_AS_MEM_P0_VM_SET_VMTYPE_SRAM (0x0007) | ||
48 | #define CY_AS_MEM_P0_VM_SET_VMTYPE_VMWIDTH (0x0008) | ||
49 | #define CY_AS_MEM_P0_VM_SET_VMTYPE_FLOWCTRL (0x0010) | ||
50 | #define CY_AS_MEM_P0_VM_SET_IFMODE (0x0020) | ||
51 | #define CY_AS_MEM_P0_VM_SET_CFGMODE (0x0040) | ||
52 | #define CY_AS_MEM_P0_VM_SET_DACKEOB (0x0080) | ||
53 | #define CY_AS_MEM_P0_VM_SET_OVERRIDE (0x0100) | ||
54 | #define CY_AS_MEM_P0_VM_SET_INTOVERD (0x0200) | ||
55 | #define CY_AS_MEM_P0_VM_SET_DRQOVERD (0x0400) | ||
56 | #define CY_AS_MEM_P0_VM_SET_DRQPOL (0x0800) | ||
57 | #define CY_AS_MEM_P0_VM_SET_DACKPOL (0x1000) | ||
58 | |||
59 | |||
60 | #define CY_AS_MEM_P0_NV_SET (0x84) | ||
61 | #define CY_AS_MEM_P0_NV_SET_WPSWEN (0x0001) | ||
62 | #define CY_AS_MEM_P0_NV_SET_WPPOLAR (0x0002) | ||
63 | |||
64 | #define CY_AS_MEM_PMU_UPDATE (0x85) | ||
65 | #define CY_AS_MEM_PMU_UPDATE_UVALID (0x0001) | ||
66 | #define CY_AS_MEM_PMU_UPDATE_USBUPDATE (0x0002) | ||
67 | #define CY_AS_MEM_PMU_UPDATE_SDIOUPDATE (0x0004) | ||
68 | |||
69 | #define CY_AS_MEM_P0_INTR_REG (0x90) | ||
70 | #define CY_AS_MEM_P0_INTR_REG_MCUINT (0x0020) | ||
71 | #define CY_AS_MEM_P0_INTR_REG_DRQINT (0x0800) | ||
72 | #define CY_AS_MEM_P0_INTR_REG_MBINT (0x1000) | ||
73 | #define CY_AS_MEM_P0_INTR_REG_PMINT (0x2000) | ||
74 | #define CY_AS_MEM_P0_INTR_REG_PLLLOCKINT (0x4000) | ||
75 | |||
76 | #define CY_AS_MEM_P0_INT_MASK_REG (0x91) | ||
77 | #define CY_AS_MEM_P0_INT_MASK_REG_MMCUINT (0x0020) | ||
78 | #define CY_AS_MEM_P0_INT_MASK_REG_MDRQINT (0x0800) | ||
79 | #define CY_AS_MEM_P0_INT_MASK_REG_MMBINT (0x1000) | ||
80 | #define CY_AS_MEM_P0_INT_MASK_REG_MPMINT (0x2000) | ||
81 | #define CY_AS_MEM_P0_INT_MASK_REG_MPLLLOCKINT (0x4000) | ||
82 | |||
83 | #define CY_AS_MEM_MCU_MB_STAT (0x92) | ||
84 | #define CY_AS_MEM_P0_MCU_MBNOTRD (0x0001) | ||
85 | |||
86 | #define CY_AS_MEM_P0_MCU_STAT (0x94) | ||
87 | #define CY_AS_MEM_P0_MCU_STAT_CARDINS (0x0001) | ||
88 | #define CY_AS_MEM_P0_MCU_STAT_CARDREM (0x0002) | ||
89 | |||
90 | #define CY_AS_MEM_PWR_MAGT_STAT (0x95) | ||
91 | #define CY_AS_MEM_PWR_MAGT_STAT_WAKEUP (0x0001) | ||
92 | |||
93 | #define CY_AS_MEM_P0_RSE_ALLOCATE (0x98) | ||
94 | #define CY_AS_MEM_P0_RSE_ALLOCATE_SDIOAVI (0x0001) | ||
95 | #define CY_AS_MEM_P0_RSE_ALLOCATE_SDIOALLO (0x0002) | ||
96 | #define CY_AS_MEM_P0_RSE_ALLOCATE_NANDAVI (0x0004) | ||
97 | #define CY_AS_MEM_P0_RSE_ALLOCATE_NANDALLO (0x0008) | ||
98 | #define CY_AS_MEM_P0_RSE_ALLOCATE_USBAVI (0x0010) | ||
99 | #define CY_AS_MEM_P0_RSE_ALLOCATE_USBALLO (0x0020) | ||
100 | |||
101 | #define CY_AS_MEM_P0_RSE_MASK (0x9A) | ||
102 | #define CY_AS_MEM_P0_RSE_MASK_MSDIOBUS_RW (0x0003) | ||
103 | #define CY_AS_MEM_P0_RSE_MASK_MNANDBUS_RW (0x00C0) | ||
104 | #define CY_AS_MEM_P0_RSE_MASK_MUSBBUS_RW (0x0030) | ||
105 | |||
106 | #define CY_AS_MEM_P0_DRQ (0xA0) | ||
107 | #define CY_AS_MEM_P0_DRQ_EP2DRQ (0x0004) | ||
108 | #define CY_AS_MEM_P0_DRQ_EP3DRQ (0x0008) | ||
109 | #define CY_AS_MEM_P0_DRQ_EP4DRQ (0x0010) | ||
110 | #define CY_AS_MEM_P0_DRQ_EP5DRQ (0x0020) | ||
111 | #define CY_AS_MEM_P0_DRQ_EP6DRQ (0x0040) | ||
112 | #define CY_AS_MEM_P0_DRQ_EP7DRQ (0x0080) | ||
113 | #define CY_AS_MEM_P0_DRQ_EP8DRQ (0x0100) | ||
114 | #define CY_AS_MEM_P0_DRQ_EP9DRQ (0x0200) | ||
115 | #define CY_AS_MEM_P0_DRQ_EP10DRQ (0x0400) | ||
116 | #define CY_AS_MEM_P0_DRQ_EP11DRQ (0x0800) | ||
117 | #define CY_AS_MEM_P0_DRQ_EP12DRQ (0x1000) | ||
118 | #define CY_AS_MEM_P0_DRQ_EP13DRQ (0x2000) | ||
119 | #define CY_AS_MEM_P0_DRQ_EP14DRQ (0x4000) | ||
120 | #define CY_AS_MEM_P0_DRQ_EP15DRQ (0x8000) | ||
121 | |||
122 | #define CY_AS_MEM_P0_DRQ_MASK (0xA1) | ||
123 | #define CY_AS_MEM_P0_DRQ_MASK_MEP2DRQ (0x0004) | ||
124 | #define CY_AS_MEM_P0_DRQ_MASK_MEP3DRQ (0x0008) | ||
125 | #define CY_AS_MEM_P0_DRQ_MASK_MEP4DRQ (0x0010) | ||
126 | #define CY_AS_MEM_P0_DRQ_MASK_MEP5DRQ (0x0020) | ||
127 | #define CY_AS_MEM_P0_DRQ_MASK_MEP6DRQ (0x0040) | ||
128 | #define CY_AS_MEM_P0_DRQ_MASK_MEP7DRQ (0x0080) | ||
129 | #define CY_AS_MEM_P0_DRQ_MASK_MEP8DRQ (0x0100) | ||
130 | #define CY_AS_MEM_P0_DRQ_MASK_MEP9DRQ (0x0200) | ||
131 | #define CY_AS_MEM_P0_DRQ_MASK_MEP10DRQ (0x0400) | ||
132 | #define CY_AS_MEM_P0_DRQ_MASK_MEP11DRQ (0x0800) | ||
133 | #define CY_AS_MEM_P0_DRQ_MASK_MEP12DRQ (0x1000) | ||
134 | #define CY_AS_MEM_P0_DRQ_MASK_MEP13DRQ (0x2000) | ||
135 | #define CY_AS_MEM_P0_DRQ_MASK_MEP14DRQ (0x4000) | ||
136 | #define CY_AS_MEM_P0_DRQ_MASK_MEP15DRQ (0x8000) | ||
137 | |||
138 | #define CY_AS_MEM_P0_EP2_DMA_REG (0xA2) | ||
139 | #define CY_AS_MEM_P0_E_pn_DMA_REG_COUNT_MASK (0x7FF) | ||
140 | #define CY_AS_MEM_P0_E_pn_DMA_REG_DMAVAL (1 << 12) | ||
141 | #define CY_AS_MEM_P0_EP3_DMA_REG (0xA3) | ||
142 | #define CY_AS_MEM_P0_EP4_DMA_REG (0xA4) | ||
143 | #define CY_AS_MEM_P0_EP5_DMA_REG (0xA5) | ||
144 | #define CY_AS_MEM_P0_EP6_DMA_REG (0xA6) | ||
145 | #define CY_AS_MEM_P0_EP7_DMA_REG (0xA7) | ||
146 | #define CY_AS_MEM_P0_EP8_DMA_REG (0xA8) | ||
147 | #define CY_AS_MEM_P0_EP9_DMA_REG (0xA9) | ||
148 | #define CY_AS_MEM_P0_EP10_DMA_REG (0xAA) | ||
149 | #define CY_AS_MEM_P0_EP11_DMA_REG (0xAB) | ||
150 | #define CY_AS_MEM_P0_EP12_DMA_REG (0xAC) | ||
151 | #define CY_AS_MEM_P0_EP13_DMA_REG (0xAD) | ||
152 | #define CY_AS_MEM_P0_EP14_DMA_REG (0xAE) | ||
153 | #define CY_AS_MEM_P0_EP15_DMA_REG (0xAF) | ||
154 | |||
155 | #define CY_AS_MEM_IROS_SLB_DATARET (0xC0) | ||
156 | |||
157 | #define CY_AS_MEM_IROS_IO_CFG (0xC1) | ||
158 | #define CY_AS_MEM_IROS_IO_CFG_GPIODRVST_MASK (0x0003) | ||
159 | #define CY_AS_MEM_IROS_IO_CFG_GPIOSLEW_MASK (0x0004) | ||
160 | #define CY_AS_MEM_IROS_IO_CFG_PPIODRVST_MASK (0x0018) | ||
161 | #define CY_AS_MEM_IROS_IO_CFG_PPIOSLEW_MASK (0x0020) | ||
162 | #define CY_AS_MEM_IROS_IO_CFG_SSIODRVST_MASK (0x0300) | ||
163 | #define CY_AS_MEM_IROS_IO_CFG_SSIOSLEW_MASK (0x0400) | ||
164 | #define CY_AS_MEM_IROS_IO_CFG_SNIODRVST_MASK (0x1800) | ||
165 | #define CY_AS_MEM_IROS_IO_CFG_SNIOSLEW_MASK (0x2000) | ||
166 | |||
167 | #define CY_AS_MEM_IROS_PLL_CFG (0xC2) | ||
168 | |||
169 | #define CY_AS_MEM_IROS_PXB_DATARET (0xC3) | ||
170 | |||
171 | #define CY_AS_MEM_PLL_LOCK_LOSS_STAT (0xC4) | ||
172 | #define CY_AS_MEM_PLL_LOCK_LOSS_STAT_PLLSTAT (0x0800) | ||
173 | |||
174 | #define CY_AS_MEM_IROS_SLEEP_CFG (0xC5) | ||
175 | |||
176 | #define CY_AS_MEM_PNAND_CFG (0xDA) | ||
177 | #define CY_AS_MEM_PNAND_CFG_IOWIDTH_MASK (0x0001) | ||
178 | #define CY_AS_MEM_PNAND_CFG_IOWIDTH_8BIT (0x0000) | ||
179 | #define CY_AS_MEM_PNAND_CFG_IOWIDTH_16BIT (0x0001) | ||
180 | #define CY_AS_MEM_PNAND_CFG_BLKTYPE_MASK (0x0002) | ||
181 | #define CY_AS_MEM_PNAND_CFG_BLKTYPE_SMALL (0x0002) | ||
182 | #define CY_AS_MEM_PNAND_CFG_BLKTYPE_LARGE (0x0000) | ||
183 | #define CY_AS_MEM_PNAND_CFG_EPABYTE_POS (4) | ||
184 | #define CY_AS_MEM_PNAND_CFG_EPABYTE_MASK (0x0030) | ||
185 | #define CY_AS_MEM_PNAND_CFG_EPABIT_POS (6) | ||
186 | #define CY_AS_MEM_PNAND_CFG_EPABIT_MASK (0x00C0) | ||
187 | #define CY_AS_MEM_PNAND_CFG_LNAEN_MASK (0x0100) | ||
188 | |||
189 | #define CY_AS_MEM_P0_MAILBOX0 (0xF0) | ||
190 | #define CY_AS_MEM_P0_MAILBOX1 (0xF1) | ||
191 | #define CY_AS_MEM_P0_MAILBOX2 (0xF2) | ||
192 | #define CY_AS_MEM_P0_MAILBOX3 (0xF3) | ||
193 | |||
194 | #define CY_AS_MEM_MCU_MAILBOX0 (0xF8) | ||
195 | #define CY_AS_MEM_MCU_MAILBOX1 (0xF9) | ||
196 | #define CY_AS_MEM_MCU_MAILBOX2 (0xFA) | ||
197 | #define CY_AS_MEM_MCU_MAILBOX3 (0xFB) | ||
198 | |||
199 | #endif /* !defined(__doxygen__) */ | ||
200 | |||
201 | #endif /* _INCLUDED_CYASREG_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage.h deleted file mode 100644 index 52b93c3e4813..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage.h +++ /dev/null | |||
@@ -1,2759 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasstorage.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASSTORAGE_H_ | ||
23 | #define _INCLUDED_CYASSTORAGE_H_ | ||
24 | |||
25 | #include "cyasmedia.h" | ||
26 | #include "cyasmisc.h" | ||
27 | #include "cyas_cplus_start.h" | ||
28 | |||
29 | |||
30 | /*@@Storage APIs | ||
31 | Summary | ||
32 | This section documents the storage APIs supported by the | ||
33 | West Bridge API. | ||
34 | |||
35 | Description | ||
36 | The storage API is based on some specific concepts which | ||
37 | are referenced here. | ||
38 | * <LINK Storage API Overview> | ||
39 | * Addressing | ||
40 | * Ownership | ||
41 | * <LINK Asynchronous Versus Synchronous Operation> | ||
42 | */ | ||
43 | |||
44 | /*@@Storage API Overview | ||
45 | Summary | ||
46 | Storage devices are identified by media type. Each media | ||
47 | type is considered a single logical device. | ||
48 | |||
49 | Description | ||
50 | Each media type has a consistent block size and consists | ||
51 | of a set of logical blocks numbered from 0 to N - 1 where | ||
52 | N is the size of the | ||
53 | media type in blocks. The mass storage APIs defined below | ||
54 | provide the | ||
55 | capability to query for devices that are present, and | ||
56 | read/write data to/from | ||
57 | these devices. | ||
58 | */ | ||
59 | |||
60 | /*@@Addressing | ||
61 | Summary | ||
62 | Blocks within a storage device are address by a hierarchal | ||
63 | block address. This | ||
64 | address consists of the bus number, physical device, | ||
65 | logical unit, and finally | ||
66 | block address. | ||
67 | |||
68 | Description | ||
69 | While currently only a single device of each media type | ||
70 | is supported, the address | ||
71 | space reserves space in the future for multiple devices | ||
72 | of each type. Therefore | ||
73 | the second element of the address is the specific device | ||
74 | being addressed within | ||
75 | a given device type. For this release of the software, | ||
76 | this value will always be | ||
77 | zero to address the first device. | ||
78 | |||
79 | The third element of the address is the logical unit. | ||
80 | A device being managed | ||
81 | by West Bridge can be partitioned into multiple logical | ||
82 | units. This partition | ||
83 | information is stored on each device itself. Currently, | ||
84 | one of the storage devices | ||
85 | managed by West Bridge can be partitioned into two | ||
86 | logical units. | ||
87 | |||
88 | Finally a logical block address is given within the | ||
89 | logical unit to address an | ||
90 | individual block. | ||
91 | */ | ||
92 | |||
93 | /*@@Ownership | ||
94 | Summary | ||
95 | While West Bridge supports concurrent block level | ||
96 | operations from both the USB port and | ||
97 | the processor port, this is not desirable in most | ||
98 | situations as the file system | ||
99 | contained on the storage media cannot be accessed | ||
100 | concurrently. To insure access | ||
101 | by only one of USB and the processor, the West Bridge | ||
102 | API provides for ownership of storage | ||
103 | devices based on media type. | ||
104 | |||
105 | Description | ||
106 | The processor requests ownership of a given media type | ||
107 | by calling CyAsStorageClaim(). | ||
108 | The firmware in West Bridge releases control of the | ||
109 | media and signals the processor through | ||
110 | the event callback registered with | ||
111 | CyAsStorageRegisterCallback(). The specific event is | ||
112 | the CyAsStorageProcessor. The processor can later | ||
113 | release the media via a call to | ||
114 | CyAsStorageRelease(). This call is immediate and | ||
115 | no callback is required. | ||
116 | |||
117 | If the processor has claimed storage and the USB port | ||
118 | is connected, West Bridge will need to | ||
119 | claim the storage to manage the mass storage device. | ||
120 | West Bridge requests the storage through | ||
121 | the event callback registered with | ||
122 | CyAsStorageRegisterCallback(). The specific event is | ||
123 | CyAsStorageAntioch and is named as such to reflect | ||
124 | the USB view of storage. This callback | ||
125 | is a request for the processor to release storage. | ||
126 | The storage is not actually released | ||
127 | until the processor calls CyAsStorageRelease(). | ||
128 | |||
129 | Note that the CyAsStorageAntioch is only sent when the | ||
130 | USB storage device is enumerated and | ||
131 | NOT at every USB operation. The ownership of a given | ||
132 | storage media type is assumed to belong | ||
133 | to the processor until the USB connection is established. | ||
134 | At that point, the storage ownership | ||
135 | is transferred to West Bridge. After the USB connection | ||
136 | is broken, ownership can be transferred | ||
137 | back to the processor. | ||
138 | */ | ||
139 | |||
140 | /*@@Asynchronous Versus Synchronous Operation | ||
141 | Summary | ||
142 | When read or write operations are performed to the | ||
143 | storage devices, these operations may be | ||
144 | synchronous or asynchronous. A synchronous operation | ||
145 | is an operation where the read or write | ||
146 | operation is requested and the function does not return | ||
147 | until the operation is complete. This | ||
148 | type of function is the easiest to use but does not | ||
149 | provide for optimal usage of the P port processor time. | ||
150 | |||
151 | Description | ||
152 | An asynchronous operation is one where the function returns | ||
153 | as soon as the request is started. | ||
154 | The specific read and write request will complete at some | ||
155 | time in the future and the P port | ||
156 | processor will be notified via a callback function. While | ||
157 | asynchronous functions provide for | ||
158 | much better usage of the CPU, these function have more | ||
159 | stringent requirements for use. First, | ||
160 | any buffer use for data transfer must be valid from the | ||
161 | function call to request the operation | ||
162 | through when the callback function is called. This basically | ||
163 | implies that stack based buffers | ||
164 | are not acceptable for asynchronous calls. Second, error | ||
165 | handling must be deferred until the | ||
166 | callback function is called indicating any kind of error | ||
167 | that may have occurred. | ||
168 | */ | ||
169 | |||
170 | /*@@Partitioning | ||
171 | Summary | ||
172 | West Bridge API and firmware support the creation of up to | ||
173 | two logical partitions on one | ||
174 | of the storage devices that are managed by West Bridge. The | ||
175 | partitions are managed through | ||
176 | the CyAsStorageCreatePPartition and CyAsStorageRemovePPartition | ||
177 | APIs. | ||
178 | |||
179 | Description | ||
180 | The CyAsStorageCreatePPartition API is used to divide the total | ||
181 | storage on a storage | ||
182 | device into two logical units or partitions. Since the partition | ||
183 | information is stored | ||
184 | on the storage device in a custom format, partitions should | ||
185 | only be created on fixed | ||
186 | storage devices (i.e., no removable SD/MMC cards). Any data | ||
187 | stored on the device | ||
188 | before the creation of the partition, is liable to be lost when | ||
189 | a partition is created. | ||
190 | |||
191 | The CyAsStorageRemovePPartition API is used to remove the | ||
192 | stored partition information, | ||
193 | so that all of the device's capacity is treated as a single | ||
194 | partition again. | ||
195 | |||
196 | When a storage device with two partitions (units) is being | ||
197 | enumerated as a mass storage | ||
198 | device through the West Bridge, it is possible to select the | ||
199 | partitions to be made | ||
200 | visible to the USB host. This is done through the | ||
201 | CyAsUsbSelectMSPartitions API. | ||
202 | */ | ||
203 | |||
204 | /********************************* | ||
205 | * West Bridge Constants | ||
206 | **********************************/ | ||
207 | |||
208 | /* Summary | ||
209 | This constants indicates a raw device access to the read/write | ||
210 | functions | ||
211 | |||
212 | Description | ||
213 | When performing reading and writing operations on the | ||
214 | storage devices attached | ||
215 | to West Bridge, there are cases where writes need to | ||
216 | happen to raw devices, versus | ||
217 | the units contained within a device. This is | ||
218 | specifically required to manage | ||
219 | the partitions within physical devices. This constant | ||
220 | is used in calls to | ||
221 | CyAsStorageRead(), CyAsStorageReadAsync(), | ||
222 | CyAsStorageWrite() and | ||
223 | CyAsStorageWriteAsync(), to indicate that the raw | ||
224 | physical device is being | ||
225 | accessed and not any specific unit on the device. | ||
226 | |||
227 | See Also | ||
228 | * CyAsStorageRead | ||
229 | * CyAsStorageReadAsync | ||
230 | * CyAsStorageWrite | ||
231 | * CyAsStorageWriteAsync | ||
232 | */ | ||
233 | #define CY_AS_LUN_PHYSICAL_DEVICE (0xffffffff) | ||
234 | |||
235 | /* Summary | ||
236 | This constant represents the maximum DMA burst length | ||
237 | supported on a storage endpoint | ||
238 | |||
239 | Description | ||
240 | West Bridge reserves separate endpoints for accessing | ||
241 | storage media through the | ||
242 | CyAsStorageRead() and CyAsStorageWrite() calls. The | ||
243 | maximum size of these | ||
244 | endpoints is always 512 bytes, regardless of status | ||
245 | and speed of the USB | ||
246 | connection. | ||
247 | */ | ||
248 | #define CY_AS_STORAGE_EP_SIZE (512) | ||
249 | |||
250 | /******************************** | ||
251 | * West Bridge Types | ||
252 | *******************************/ | ||
253 | |||
254 | /* Summary | ||
255 | This type indicates the type of event in an event | ||
256 | callback from West Bridge | ||
257 | |||
258 | Description | ||
259 | At times West Bridge needs to inform the P port | ||
260 | processor of events that have | ||
261 | occurred. These events are asynchronous to the | ||
262 | thread of control on the P | ||
263 | port processor and as such are generally delivered | ||
264 | via a callback function that | ||
265 | is called as part of an interrupt handler. This | ||
266 | type indicates the resonse for | ||
267 | the call to the callback function. | ||
268 | |||
269 | See Also | ||
270 | * CyAsStorageEventCallback | ||
271 | * CyAsStorageRegisterCallback | ||
272 | */ | ||
273 | typedef enum cy_as_storage_event { | ||
274 | /* This event occurs when the West Bridge device has | ||
275 | detected a USB connect and has enumerated the | ||
276 | storage controlled by west bridge to the USB port. | ||
277 | this event is the signal that the processor | ||
278 | needs to release the storage media. west bridge will | ||
279 | not have control of the storage media until the | ||
280 | processor calls cy_as_release_storage() to release | ||
281 | the specific media. */ | ||
282 | cy_as_storage_antioch, | ||
283 | |||
284 | /* This event occurs when the processor has requested | ||
285 | ownership of a given media type and west bridge has | ||
286 | released the media. this event is an indicator | ||
287 | that the transfer of ownership is complete and the | ||
288 | processor now owns the given media type. */ | ||
289 | cy_as_storage_processor, | ||
290 | |||
291 | /* This event occurs when a removable media type has | ||
292 | been removed. */ | ||
293 | cy_as_storage_removed, | ||
294 | |||
295 | /* This event occurs when a removable media type has | ||
296 | been inserted. */ | ||
297 | cy_as_storage_inserted, | ||
298 | |||
299 | /* This event occurs when the West Bridge device | ||
300 | * percieves an interrrupt from an SDIO card */ | ||
301 | cy_as_sdio_interrupt | ||
302 | |||
303 | } cy_as_storage_event; | ||
304 | |||
305 | /* Summary | ||
306 | This type gives the type of the operation in a storage | ||
307 | operation callback | ||
308 | |||
309 | Description | ||
310 | This type is used in the callback function for asynchronous | ||
311 | operation. This type indicates whether it is a | ||
312 | CyAsStorageRead() or CyAsStorageWrite() operation that | ||
313 | has completed. | ||
314 | |||
315 | See Also | ||
316 | * <LINK Asynchronous Versus Synchronous Operation> | ||
317 | * CyAsStorageRead | ||
318 | * CyAsStorageWrite | ||
319 | */ | ||
320 | typedef enum cy_as_oper_type { | ||
321 | /* A data read operation */ | ||
322 | cy_as_op_read, | ||
323 | /* A data write operation */ | ||
324 | cy_as_op_write | ||
325 | } cy_as_oper_type; | ||
326 | |||
327 | /* Summary | ||
328 | This data structure describes a specific type of media | ||
329 | |||
330 | Description | ||
331 | This data structure is the return value from the | ||
332 | CyAsStorageQueryDevice function. This structure provides | ||
333 | information about the specific storage device being queried. | ||
334 | |||
335 | See Also | ||
336 | * CyAsStorageQueryDevice | ||
337 | */ | ||
338 | typedef struct cy_as_device_desc { | ||
339 | /* Type of device */ | ||
340 | cy_as_media_type type; | ||
341 | /* Is the device removable */ | ||
342 | cy_bool removable; | ||
343 | /* Is the device writeable */ | ||
344 | cy_bool writeable; | ||
345 | /* Basic block size for device */ | ||
346 | uint16_t block_size; | ||
347 | /* Number of LUNs on the device */ | ||
348 | uint32_t number_units; | ||
349 | /* Is the device password locked */ | ||
350 | cy_bool locked; | ||
351 | /* Size in bytes of an Erase Unit. Block erase operation | ||
352 | is only supported for SD storage, and the erase_unit_size | ||
353 | is invalid for all other kinds of storage. */ | ||
354 | uint32_t erase_unit_size; | ||
355 | } cy_as_device_desc; | ||
356 | |||
357 | /* Summary | ||
358 | This data structure describes a specific unit on a | ||
359 | specific type of media | ||
360 | |||
361 | Description | ||
362 | This data structure is the return value from the | ||
363 | CyAsStorageQueryUnit function. This structure provides | ||
364 | information about the specific unit. | ||
365 | |||
366 | See Also | ||
367 | * CyAsStorageQueryUnit | ||
368 | */ | ||
369 | typedef struct cy_as_unit_desc { | ||
370 | /* Type of device */ | ||
371 | cy_as_media_type type; | ||
372 | /* Basic block size for device */ | ||
373 | uint16_t block_size; | ||
374 | /* Physical start block for LUN */ | ||
375 | uint32_t start_block; | ||
376 | /* Number of blocks in the LUN */ | ||
377 | uint32_t unit_size; | ||
378 | } cy_as_unit_desc; | ||
379 | |||
380 | /* Summary | ||
381 | This function type defines a callback to be called after an | ||
382 | asynchronous operation | ||
383 | |||
384 | Description | ||
385 | This function type defines a callback function that is called | ||
386 | at the completion of any asynchronous read or write operation. | ||
387 | |||
388 | See Also | ||
389 | * CyAsStorageReadAsync() | ||
390 | * CyAsStorageWriteAsync() | ||
391 | */ | ||
392 | typedef void (*cy_as_storage_callback)( | ||
393 | /* Handle to the device completing the storage operation */ | ||
394 | cy_as_device_handle handle, | ||
395 | /* The bus completing the operation */ | ||
396 | cy_as_bus_number_t bus, | ||
397 | /* The device completing the operation */ | ||
398 | uint32_t device, | ||
399 | /* The unit completing the operation */ | ||
400 | uint32_t unit, | ||
401 | /* The block number of the completed operation */ | ||
402 | uint32_t block_number, | ||
403 | /* The type of operation */ | ||
404 | cy_as_oper_type op, | ||
405 | /* The error status */ | ||
406 | cy_as_return_status_t status | ||
407 | ); | ||
408 | |||
409 | /* Summary | ||
410 | This function type defines a callback to be called in the | ||
411 | event of a storage related event | ||
412 | |||
413 | Description | ||
414 | At times West Bridge needs to inform the P port processor | ||
415 | of events that have | ||
416 | occurred. These events are asynchronous to the thread of | ||
417 | control on the P | ||
418 | port processor and as such are generally delivered via a | ||
419 | callback function that | ||
420 | is called as part of an interrupt handler. This type | ||
421 | defines the type of function | ||
422 | that must be provided as a callback function. | ||
423 | |||
424 | See Also | ||
425 | * CyAsStorageEvent | ||
426 | * CyAsStorageRegisterCallback | ||
427 | */ | ||
428 | typedef void (*cy_as_storage_event_callback)( | ||
429 | /* Handle to the device sending the event notification */ | ||
430 | cy_as_device_handle handle, | ||
431 | /* The bus where the event happened */ | ||
432 | cy_as_bus_number_t bus, | ||
433 | /* The device where the event happened */ | ||
434 | uint32_t device, | ||
435 | /* The event type */ | ||
436 | cy_as_storage_event evtype, | ||
437 | /* Event related data */ | ||
438 | void *evdata | ||
439 | ); | ||
440 | |||
441 | /* Summary | ||
442 | This function type defines a callback to be called after | ||
443 | an asynchronous sdio operation | ||
444 | |||
445 | Description | ||
446 | The Callback function is called at the completion of an | ||
447 | asynchronous sdio read or write operation. | ||
448 | |||
449 | See Also | ||
450 | * CyAsSdioExtendedRead() | ||
451 | * CyAsSdioExtendedWrite() | ||
452 | */ | ||
453 | typedef void (*cy_as_sdio_callback)( | ||
454 | /* Handle to the device completing the storage operation */ | ||
455 | cy_as_device_handle handle, | ||
456 | /* The bus completing the operation */ | ||
457 | cy_as_bus_number_t bus, | ||
458 | /* The device completing the operation */ | ||
459 | uint32_t device, | ||
460 | /* The function number of the completing the operation. | ||
461 | if the status of the operation is either CY_AS_ERROR_IO_ABORTED | ||
462 | or CY_AS_IO_SUSPENDED then the most significant word parameter will | ||
463 | contain the number of blocks still pending. */ | ||
464 | uint32_t function, | ||
465 | /* The base address of the completed operation */ | ||
466 | uint32_t address, | ||
467 | /* The type of operation */ | ||
468 | cy_as_oper_type op, | ||
469 | /* The status of the operation */ | ||
470 | cy_as_return_status_t status | ||
471 | ); | ||
472 | |||
473 | /* Summary | ||
474 | Enumeration of SD/MMC card registers that can be read | ||
475 | through the API. | ||
476 | |||
477 | Description | ||
478 | Some of the registers on the SD/MMC card(s) attached to the | ||
479 | West Bridge can be read through the API layers. This type | ||
480 | enumerates the registers that can be read. | ||
481 | |||
482 | See Also | ||
483 | * CyAsStorageSDRegisterRead | ||
484 | */ | ||
485 | typedef enum cy_as_sd_card_reg_type { | ||
486 | cy_as_sd_reg_OCR = 0, | ||
487 | cy_as_sd_reg_CID, | ||
488 | cy_as_sd_reg_CSD | ||
489 | } cy_as_sd_card_reg_type; | ||
490 | |||
491 | /* Summary | ||
492 | Struct encapsulating parameters and return values for a | ||
493 | CyAsStorageQueryDevice call. | ||
494 | |||
495 | Description | ||
496 | This struct holds the input parameters and the return values | ||
497 | for an asynchronous CyAsStorageQueryDevice call. | ||
498 | |||
499 | See Also | ||
500 | * CyAsStorageQueryDevice | ||
501 | */ | ||
502 | typedef struct cy_as_storage_query_device_data { | ||
503 | /* The bus with the device to query */ | ||
504 | cy_as_bus_number_t bus; | ||
505 | /* The logical device number to query */ | ||
506 | uint32_t device; | ||
507 | /* The return value for the device descriptor */ | ||
508 | cy_as_device_desc desc_p; | ||
509 | } cy_as_storage_query_device_data; | ||
510 | |||
511 | |||
512 | /* Summary | ||
513 | Struct encapsulating parameters and return values | ||
514 | for a CyAsStorageQueryUnit call. | ||
515 | |||
516 | Description | ||
517 | This struct holds the input parameters and the return | ||
518 | values for an asynchronous CyAsStorageQueryUnit call. | ||
519 | |||
520 | See Also | ||
521 | * CyAsStorageQueryUnit | ||
522 | */ | ||
523 | typedef struct cy_as_storage_query_unit_data { | ||
524 | /* The bus with the device to query */ | ||
525 | cy_as_bus_number_t bus; | ||
526 | /* The logical device number to query */ | ||
527 | uint32_t device; | ||
528 | /* The unit to query on the device */ | ||
529 | uint32_t unit; | ||
530 | /* The return value for the unit descriptor */ | ||
531 | cy_as_unit_desc desc_p; | ||
532 | } cy_as_storage_query_unit_data; | ||
533 | |||
534 | /* Summary | ||
535 | Struct encapsulating the input parameter and return | ||
536 | values for a CyAsStorageSDRegisterRead call. | ||
537 | |||
538 | Description | ||
539 | This struct holds the input parameter and return | ||
540 | values for an asynchronous CyAsStorageSDRegisterRead | ||
541 | call. | ||
542 | |||
543 | See Also | ||
544 | * CyAsStorageSDRegisterRead | ||
545 | */ | ||
546 | typedef struct cy_as_storage_sd_reg_read_data { | ||
547 | /* Pointer to the result buffer. */ | ||
548 | uint8_t *buf_p; | ||
549 | /* Length of data to be copied in bytes. */ | ||
550 | uint8_t length; | ||
551 | } cy_as_storage_sd_reg_read_data; | ||
552 | |||
553 | /* Summary | ||
554 | Controls which pins are used for card detection | ||
555 | |||
556 | Description | ||
557 | When a StorageDeviceControl call is made to enable or | ||
558 | disable card detection this enum is passed in to | ||
559 | control which pin is used for the detection. | ||
560 | |||
561 | See Also | ||
562 | * CyAsStorageDeviceControl | ||
563 | */ | ||
564 | typedef enum cy_as_storage_card_detect { | ||
565 | cy_as_storage_detect_GPIO, | ||
566 | cy_as_storage_detect_SDAT_3 | ||
567 | } cy_as_storage_card_detect; | ||
568 | |||
569 | #ifndef __doxygen__ | ||
570 | #define cy_as_storage_detect_GPIO_0 cy_as_storage_detect_GPIO | ||
571 | |||
572 | /* Length of OCR value in bytes. */ | ||
573 | #define CY_AS_SD_REG_OCR_LENGTH (4) | ||
574 | /* Length of CID value in bytes. */ | ||
575 | #define CY_AS_SD_REG_CID_LENGTH (16) | ||
576 | /* Length of CSD value in bytes. */ | ||
577 | #define CY_AS_SD_REG_CSD_LENGTH (16) | ||
578 | /* Max. length of register response in words. */ | ||
579 | #define CY_AS_SD_REG_MAX_RESP_LENGTH (10) | ||
580 | |||
581 | #endif | ||
582 | |||
583 | /* Summary | ||
584 | This data structure is the data passed via the evdata | ||
585 | paramater on a usb event callback for the mass storage | ||
586 | device progress event. | ||
587 | |||
588 | Description | ||
589 | This data structure reports the number of sectors that have | ||
590 | been written and read on the USB mass storage device since | ||
591 | the last event report. The corresponding event is only sent | ||
592 | when either the number of writes, or the number of reads has | ||
593 | crossed a pre-set threshold. | ||
594 | |||
595 | See Also | ||
596 | * CyAsUsbEventCallback | ||
597 | * CyAsUsbRegisterCallback | ||
598 | */ | ||
599 | typedef struct cy_as_m_s_c_progress_data { | ||
600 | /* Number of sectors written since the last event. */ | ||
601 | uint32_t wr_count; | ||
602 | /* Number of sectors read since the last event. */ | ||
603 | uint32_t rd_count; | ||
604 | } cy_as_m_s_c_progress_data; | ||
605 | |||
606 | /* Summary | ||
607 | Flag to set Direct Write operation to read back from the | ||
608 | address written to. | ||
609 | |||
610 | |||
611 | See Also | ||
612 | *CyAsSdioDirectWrite() | ||
613 | */ | ||
614 | #define CY_SDIO_RAW (0x01) | ||
615 | |||
616 | |||
617 | /* Summary | ||
618 | Flag to set Extended Read and Write to perform IO | ||
619 | using a FIFO i.e. read or write from the specified | ||
620 | address only. | ||
621 | |||
622 | See Also | ||
623 | *CyAsSdioExtendedRead() | ||
624 | *CyAsSdioExtendedWrite() | ||
625 | */ | ||
626 | #define CY_SDIO_OP_FIFO (0x00) | ||
627 | |||
628 | /* Summary | ||
629 | Flag to set Extended Read and Write to perform incremental | ||
630 | IO using the address provided as the base address. | ||
631 | |||
632 | |||
633 | See Also | ||
634 | *CyAsSdioExtendedRead() | ||
635 | *CyAsSdioExtendedWrite() | ||
636 | */ | ||
637 | #define CY_SDIO_OP_INCR (0x02) | ||
638 | |||
639 | /* Summary | ||
640 | Flag to set Extended Read and Write to Block Mode operation | ||
641 | |||
642 | See Also | ||
643 | *CyAsSdioExtendedRead() | ||
644 | *CyAsSdioExtendedWrite() | ||
645 | */ | ||
646 | #define CY_SDIO_BLOCKMODE (0x04) | ||
647 | |||
648 | /* Summary | ||
649 | Flag to set Extended Read and Write to Byte Mode operation | ||
650 | |||
651 | See Also | ||
652 | *CyAsSdioExtendedRead() | ||
653 | *CyAsSdioExtendedWrite() | ||
654 | */ | ||
655 | #define CY_SDIO_BYTEMODE (0x00) | ||
656 | |||
657 | /* Summary | ||
658 | Flag to force re/initialization of a function. | ||
659 | |||
660 | Description | ||
661 | If not set a call to CyAsSdioInitFunction() | ||
662 | will not initialize a function that has been previously | ||
663 | initialized. | ||
664 | See Also | ||
665 | *CyAsSdioInitFunction() | ||
666 | */ | ||
667 | #define CY_SDIO_FORCE_INIT (0x40) | ||
668 | |||
669 | /* Summary | ||
670 | Flag to re-enable the SDIO interrupts. | ||
671 | |||
672 | Description | ||
673 | Used with a direct read or direct write | ||
674 | after the Interrupt triggerred by SDIO has been serviced | ||
675 | and cleared to reset the West Bridge Sdio Interrupt. | ||
676 | See Also | ||
677 | *CyAsSdioDirectRead() | ||
678 | *CyAsSdioDirectWrite() | ||
679 | */ | ||
680 | |||
681 | #define CY_SDIO_REARM_INT (0x80) | ||
682 | |||
683 | |||
684 | /* Summary | ||
685 | Flag to check if 4 bit support is enabled on a | ||
686 | low speed card | ||
687 | See Also | ||
688 | <link CyAsSDIOCard::card_capability>*/ | ||
689 | #define CY_SDIO_4BLS (0x80) | ||
690 | |||
691 | /* Summary | ||
692 | Flag to check if card is a low speed card | ||
693 | See Also | ||
694 | <link CyAsSDIOCard::card_capability> */ | ||
695 | #define CY_SDIO_LSC (0x40) | ||
696 | |||
697 | /* Summary | ||
698 | Flag to check if interrupt during multiblock data | ||
699 | transfer is enabled | ||
700 | See Also | ||
701 | <link CyAsSDIOCard::card_capability>*/ | ||
702 | #define CY_SDIO_E4MI (0x20) | ||
703 | |||
704 | /* Summary | ||
705 | Flag to check if interrupt during multiblock data | ||
706 | transfer is supported | ||
707 | See Also | ||
708 | <link CyAsSDIOCard::card_capability> */ | ||
709 | #define CY_SDIO_S4MI (0x10) | ||
710 | |||
711 | /* Summary | ||
712 | Flag to check if card supports function suspending. | ||
713 | See Also | ||
714 | <link CyAsSDIOCard::card_capability> */ | ||
715 | #define CY_SDIO_SBS (0x08) | ||
716 | |||
717 | /* Summary | ||
718 | Flag to check if card supports SDIO Read-Wait | ||
719 | See Also | ||
720 | <link CyAsSDIOCard::card_capability> */ | ||
721 | #define CY_SDIO_SRW (0x04) | ||
722 | |||
723 | /* Summary | ||
724 | Flag to check if card supports multi-block transfers | ||
725 | See Also | ||
726 | <link CyAsSDIOCard::card_capability> */ | ||
727 | #define CY_SDIO_SMB (0x02) | ||
728 | |||
729 | /* Summary | ||
730 | Flag to check if card supports Direct IO commands | ||
731 | during execution of an Extended | ||
732 | IO function | ||
733 | See Also | ||
734 | <link CyAsSDIOCard::card_capability>*/ | ||
735 | #define CY_SDIO_SDC (0x01) | ||
736 | |||
737 | /* Summary | ||
738 | Flag to check if function has a CSA area. | ||
739 | See Also | ||
740 | <link CyAsSDIOFunc::csa_bits> */ | ||
741 | #define CY_SDIO_CSA_SUP (0x40) | ||
742 | |||
743 | /* Summary | ||
744 | Flag to check if CSA access is enabled. | ||
745 | See Also | ||
746 | <link CyAsSDIOFunc::csa_bits> */ | ||
747 | #define CY_SDIO_CSA_EN (0x80) | ||
748 | |||
749 | /* Summary | ||
750 | Flag to check if CSA is Write protected. | ||
751 | See Also | ||
752 | <link CyAsSDIOFunc::csa_bits> */ | ||
753 | #define CY_SDIO_CSA_WP (0x01) | ||
754 | |||
755 | /* Summary | ||
756 | Flag to check if CSA formatting is prohibited. | ||
757 | See Also | ||
758 | <link CyAsSDIOFunc::csa_bits>*/ | ||
759 | #define CY_SDIO_CSA_NF (0x02) | ||
760 | |||
761 | /* Summary | ||
762 | Flag to check if the function allows wake-up from low | ||
763 | power mode using some vendor specific method. | ||
764 | See Also | ||
765 | <link CyAsSDIOFunc::wakeup_support>*/ | ||
766 | #define CY_SDIO_FN_WUS (0x01) | ||
767 | |||
768 | |||
769 | /* Summary | ||
770 | This data structure stores SDIO function 0 | ||
771 | parameters for a SDIO card | ||
772 | */ | ||
773 | typedef struct cy_as_sdio_card { | ||
774 | /* Number of functions present on the card. */ | ||
775 | uint8_t num_functions; | ||
776 | /* Memory present(Combo card) or not */ | ||
777 | uint8_t memory_present; | ||
778 | /* 16 bit manufacturer ID */ | ||
779 | uint16_t manufacturer__id; | ||
780 | /* Additional vendor specific info */ | ||
781 | uint16_t manufacturer_info; | ||
782 | /* Max Block size for function 0 */ | ||
783 | uint16_t maxblocksize; | ||
784 | /* Block size used for function 0 */ | ||
785 | uint16_t blocksize; | ||
786 | /* SDIO version supported by the card */ | ||
787 | uint8_t sdio_version; | ||
788 | /* Card capability flags */ | ||
789 | uint8_t card_capability; | ||
790 | } cy_as_sdio_card; | ||
791 | |||
792 | /* Summary | ||
793 | This data structure stores SDIO function 1-7 parameters | ||
794 | for a SDIO card | ||
795 | */ | ||
796 | typedef struct cy_as_sdio_func { | ||
797 | /* SDIO function code. 0 if non standard function */ | ||
798 | uint8_t function_code; | ||
799 | /* Extended function type code for non-standard function */ | ||
800 | uint8_t extended_func_code; | ||
801 | /* Max IO Blocksize supported by the function */ | ||
802 | uint16_t maxblocksize; | ||
803 | /* IO Blocksize used by the function */ | ||
804 | uint16_t blocksize; | ||
805 | /* 32 bit product serial number for the function */ | ||
806 | uint32_t card_psn; | ||
807 | /* Code storage area variables */ | ||
808 | uint8_t csa_bits; | ||
809 | /* Function wake-up support */ | ||
810 | uint8_t wakeup_support; | ||
811 | } cy_as_sdio_func; | ||
812 | |||
813 | /*********************************** | ||
814 | * West Bridge Functions | ||
815 | ************************************/ | ||
816 | |||
817 | /* Summary | ||
818 | This function starts the West Bridge storage module. | ||
819 | |||
820 | Description | ||
821 | This function initializes the West Bridge storage software | ||
822 | stack and readies this module to service storage related | ||
823 | requests. If the stack is already running, the reference | ||
824 | count for the stack is incremented. | ||
825 | |||
826 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
827 | * Nestable: YES | ||
828 | |||
829 | Returns | ||
830 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
831 | * not been configured | ||
832 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
833 | * loaded into West Bridge | ||
834 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
835 | * CY_AS_ERROR_SUCCESS - the module started successfully | ||
836 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
837 | * with the West Bridge device | ||
838 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
839 | * CY_AS_ERROR_INVALID_RESPONSE | ||
840 | |||
841 | See Also | ||
842 | * CyAsStorageStop | ||
843 | */ | ||
844 | EXTERN cy_as_return_status_t | ||
845 | cy_as_storage_start( | ||
846 | /* Handle to the device */ | ||
847 | cy_as_device_handle handle, | ||
848 | /* Callback to be called when the operation is complete */ | ||
849 | cy_as_function_callback cb, | ||
850 | /* Client data to be passed to the callback */ | ||
851 | uint32_t client | ||
852 | ); | ||
853 | |||
854 | /* Summary | ||
855 | This function stops the West Bridge storage module. | ||
856 | |||
857 | Description | ||
858 | This function decrements the reference count for the | ||
859 | storage stack and if this count is zero, the storage | ||
860 | stack is shut down. The shutdown frees all resources | ||
861 | associated with the storage stack. | ||
862 | |||
863 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
864 | * Nestable: YES | ||
865 | |||
866 | Notes | ||
867 | While all resources associated with the storage stack | ||
868 | will be freed is a shutdown occurs, | ||
869 | resources associated with underlying layers of the | ||
870 | software will not be freed if they | ||
871 | are shared by the USB stack and the USB stack is | ||
872 | active. Specifically the DMA manager, | ||
873 | the interrupt manager, and the West Bridge | ||
874 | communications module are all shared by both the | ||
875 | USB stack and the storage stack. | ||
876 | |||
877 | Returns | ||
878 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge | ||
879 | * device has not been configured | ||
880 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not | ||
881 | * been loaded into West Bridge | ||
882 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
883 | * passed in | ||
884 | * CY_AS_ERROR_SUCCESS - this module was shut | ||
885 | * down successfully | ||
886 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
887 | * communicating with the West Bridge device | ||
888 | * CY_AS_ERROR_NOT_RUNNING | ||
889 | * CY_AS_ERROR_ASYNC_PENDING | ||
890 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
891 | |||
892 | See Also | ||
893 | * CyAsStorageStart | ||
894 | */ | ||
895 | EXTERN cy_as_return_status_t | ||
896 | cy_as_storage_stop( | ||
897 | /* Handle to the device to configure */ | ||
898 | cy_as_device_handle handle, | ||
899 | /* Callback to be called when the operation is complete */ | ||
900 | cy_as_function_callback cb, | ||
901 | /* Client data to be passed to the callback */ | ||
902 | uint32_t client | ||
903 | ); | ||
904 | |||
905 | /* Summary | ||
906 | This function is used to register a callback function | ||
907 | for the storage API. | ||
908 | |||
909 | Description | ||
910 | At times West Bridge needs to inform the P port processor | ||
911 | of events that have occurred. These events are asynchronous | ||
912 | to the thread of control on the P | ||
913 | port processor and as such are generally delivered via a | ||
914 | callback function that | ||
915 | is called as part of an interrupt handler. This function | ||
916 | registers the callback | ||
917 | function that is called when an event occurs. Each call | ||
918 | to this function | ||
919 | replaces any old callback function with a new callback | ||
920 | function supplied on | ||
921 | the most recent call. This function can also be called | ||
922 | with a callback function | ||
923 | of NULL in order to remove any existing callback function | ||
924 | |||
925 | * Valid In Asynchronous Callback:YES | ||
926 | |||
927 | Returns | ||
928 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
929 | * has not been configured | ||
930 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
931 | * loaded into West Bridge | ||
932 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has | ||
933 | * not been started | ||
934 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle | ||
935 | * was passed in | ||
936 | * CY_AS_ERROR_SUCCESS - the function was registered | ||
937 | * successfully | ||
938 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
939 | |||
940 | See Also | ||
941 | * CyAsStorageEventCallback | ||
942 | * CyAsStorageEvent | ||
943 | */ | ||
944 | EXTERN cy_as_return_status_t | ||
945 | cy_as_storage_register_callback( | ||
946 | /* Handle to the device of interest */ | ||
947 | cy_as_device_handle handle, | ||
948 | /* The callback function to call for async storage events */ | ||
949 | cy_as_storage_event_callback callback | ||
950 | ); | ||
951 | |||
952 | /* Summary | ||
953 | This function claims a given media type. | ||
954 | |||
955 | Description | ||
956 | This function communicates to West Bridge that the | ||
957 | processor wants control of the | ||
958 | given storage media type. Each media type can be | ||
959 | claimed or released by the | ||
960 | processor independently. As the processor is the | ||
961 | master for the storage, | ||
962 | West Bridge should release control of the requested | ||
963 | media as soon as possible and | ||
964 | signal the processor via the CyAsStorageProcessor event. | ||
965 | |||
966 | * Valid In Asynchronous Callback: NO | ||
967 | |||
968 | Notes | ||
969 | This function just notifies West Bridge that the storage | ||
970 | is desired. The storage | ||
971 | has not actually been released by West Bridge until the | ||
972 | registered callback function | ||
973 | is called with the CyAsStorageProcessor event | ||
974 | |||
975 | Returns | ||
976 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
977 | * has not been configured | ||
978 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
979 | * loaded into West Bridge | ||
980 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
981 | * been started | ||
982 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
983 | * passed in | ||
984 | * CY_AS_ERROR_SUCCESS - this request was successfully | ||
985 | * transmitted to the West Bridge device | ||
986 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
987 | * with the West Bridge device | ||
988 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
989 | * CY_AS_ERROR_NO_SUCH_MEDIA | ||
990 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
991 | * CY_AS_ERROR_INVALID_RESPONSE | ||
992 | * CY_AS_ERROR_NOT_ACQUIRED | ||
993 | |||
994 | See Also: | ||
995 | * CyAsStorageClaim | ||
996 | * CyAsStorageRelease | ||
997 | */ | ||
998 | EXTERN cy_as_return_status_t | ||
999 | cy_as_storage_claim( | ||
1000 | /* Handle to the device of interest */ | ||
1001 | cy_as_device_handle handle, | ||
1002 | /* The bus to claim */ | ||
1003 | cy_as_bus_number_t bus, | ||
1004 | /* The device to claim */ | ||
1005 | uint32_t device, | ||
1006 | /* Callback to be called when the operation is complete */ | ||
1007 | cy_as_function_callback cb, | ||
1008 | /* Client data to be passed to the callback */ | ||
1009 | uint32_t client | ||
1010 | ); | ||
1011 | |||
1012 | /* Summary | ||
1013 | This function releases a given media type. | ||
1014 | |||
1015 | Description | ||
1016 | This function communicates to West Bridge that the | ||
1017 | processor has released control of | ||
1018 | the given storage media type. Each media type can | ||
1019 | be claimed or released by the | ||
1020 | processor independently. As the processor is the | ||
1021 | master for the storage, West Bridge | ||
1022 | can now assume ownership of the media type. No callback | ||
1023 | or event is generated. | ||
1024 | |||
1025 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1026 | * Nestable: YES | ||
1027 | |||
1028 | Returns | ||
1029 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1030 | * has not been configured | ||
1031 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1032 | * loaded into West Bridge | ||
1033 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1034 | * been started | ||
1035 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle | ||
1036 | * was passed in | ||
1037 | * CY_AS_ERROR_SUCCESS - the media was successfully | ||
1038 | * released | ||
1039 | * CY_AS_ERROR_MEDIA_NOT_CLAIMED - the media was not | ||
1040 | * claimed by the P port | ||
1041 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1042 | * communicating with the West Bridge device | ||
1043 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1044 | * CY_AS_ERROR_NO_SUCH_MEDIA | ||
1045 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1046 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1047 | |||
1048 | See Also | ||
1049 | * CyAsStorageClaim | ||
1050 | */ | ||
1051 | EXTERN cy_as_return_status_t | ||
1052 | cy_as_storage_release( | ||
1053 | /* Handle to the device of interest */ | ||
1054 | cy_as_device_handle handle, | ||
1055 | /* The bus to release */ | ||
1056 | cy_as_bus_number_t bus, | ||
1057 | /* The device to release */ | ||
1058 | uint32_t device, | ||
1059 | /* Callback to be called when the operation is complete */ | ||
1060 | cy_as_function_callback cb, | ||
1061 | /* Client data to be passed to the callback */ | ||
1062 | uint32_t client | ||
1063 | ); | ||
1064 | |||
1065 | /* Summary | ||
1066 | This function information about the number of devices present | ||
1067 | on a given bus | ||
1068 | |||
1069 | Description | ||
1070 | This function retrieves information about how many devices on | ||
1071 | on the given | ||
1072 | West Bridge bus. | ||
1073 | |||
1074 | * Valid In Asynchronous Callback: NO | ||
1075 | |||
1076 | Notes | ||
1077 | While the current implementation of West Bridge only | ||
1078 | supports one of logical device of | ||
1079 | each media type, future versions WestBridge/Antioch may | ||
1080 | support multiple devices. | ||
1081 | |||
1082 | Returns | ||
1083 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1084 | * has not been configured | ||
1085 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1086 | * loaded into West Bridge | ||
1087 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1088 | * been started | ||
1089 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1090 | * passed in | ||
1091 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1092 | * returned | ||
1093 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1094 | * communicating with the West Bridge device | ||
1095 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1096 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1097 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1098 | |||
1099 | See Also | ||
1100 | * CyAsStorageQueryDevice | ||
1101 | * CyAsStorageQueryUnit | ||
1102 | */ | ||
1103 | EXTERN cy_as_return_status_t | ||
1104 | cy_as_storage_query_bus( | ||
1105 | /* Handle to the device of interest */ | ||
1106 | cy_as_device_handle handle, | ||
1107 | /* The bus to query */ | ||
1108 | cy_as_bus_number_t bus, | ||
1109 | /* The return value containing the number of | ||
1110 | devices present for this media type */ | ||
1111 | uint32_t *count, | ||
1112 | /* Callback to be called when the operation is complete */ | ||
1113 | cy_as_function_callback cb, | ||
1114 | /* Client data to be passed to the callback */ | ||
1115 | uint32_t client | ||
1116 | ); | ||
1117 | |||
1118 | /* Summary | ||
1119 | This function information about the number of devices | ||
1120 | present for a given media type | ||
1121 | |||
1122 | Description | ||
1123 | This function retrieves information about how many | ||
1124 | devices of a given media type are attached to West Bridge. | ||
1125 | |||
1126 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1127 | * Nestable: YES | ||
1128 | |||
1129 | Notes | ||
1130 | While the current implementation of West Bridge only | ||
1131 | supports one of logical device of each media type, future | ||
1132 | versions West Bridge may support multiple devices. | ||
1133 | |||
1134 | Returns | ||
1135 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1136 | * has not been configured | ||
1137 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1138 | * loaded into West Bridge | ||
1139 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1140 | * been started | ||
1141 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1142 | * passed in | ||
1143 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1144 | * returned | ||
1145 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1146 | * communicating with the West Bridge device | ||
1147 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1148 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1149 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1150 | |||
1151 | See Also | ||
1152 | * CyAsStorageQueryMedia | ||
1153 | * CyAsMediaType | ||
1154 | * CyAsStorageQueryDevice | ||
1155 | * CyAsStorageQueryUnit | ||
1156 | */ | ||
1157 | EXTERN cy_as_return_status_t | ||
1158 | cy_as_storage_query_media( | ||
1159 | /* Handle to the device of interest */ | ||
1160 | cy_as_device_handle handle, | ||
1161 | /* The type of media to query */ | ||
1162 | cy_as_media_type type, | ||
1163 | /* The return value containing the number of | ||
1164 | devices present for this media type */ | ||
1165 | uint32_t *count, | ||
1166 | /* Callback to be called when the operation is complete */ | ||
1167 | cy_as_function_callback cb, | ||
1168 | /* Client data to be passed to the callback */ | ||
1169 | uint32_t client | ||
1170 | ); | ||
1171 | |||
1172 | /* Summary | ||
1173 | This function returns information about a given device | ||
1174 | of a specific media type | ||
1175 | |||
1176 | Description | ||
1177 | This function retrieves information about a device of a | ||
1178 | given type of media. The function is called with a given | ||
1179 | media type and device and a pointer to a media descriptor | ||
1180 | (CyAsDeviceDesc). This function fills in the data in the | ||
1181 | media descriptor to provide information about the | ||
1182 | attributes of the device of the given device. | ||
1183 | |||
1184 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1185 | * Nestable: YES | ||
1186 | |||
1187 | Notes | ||
1188 | Currently this API only supports a single logical device | ||
1189 | of each media type. Therefore the only acceptable value | ||
1190 | for the parameter device is zero (0). | ||
1191 | |||
1192 | Returns | ||
1193 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
1194 | * not been configured | ||
1195 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1196 | * loaded into West Bridge | ||
1197 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1198 | * been started | ||
1199 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1200 | * passed in | ||
1201 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1202 | * returned | ||
1203 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
1204 | * with the West Bridge device | ||
1205 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1206 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1207 | * CY_AS_ERROR_NO_SUCH_MEDIA | ||
1208 | * CY_AS_ERROR_NO_SUCH_DEVICE | ||
1209 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1210 | |||
1211 | See Also | ||
1212 | * CyAsMediaType | ||
1213 | * CyAsStorageQueryMedia | ||
1214 | * CyAsStorageQueryUnit | ||
1215 | * CyAsDeviceDesc | ||
1216 | */ | ||
1217 | EXTERN cy_as_return_status_t | ||
1218 | cy_as_storage_query_device( | ||
1219 | /* Handle to the device of interest */ | ||
1220 | cy_as_device_handle handle, | ||
1221 | /* Parameters and return value for the query call */ | ||
1222 | cy_as_storage_query_device_data *data, | ||
1223 | /* Callback to be called when the operation is complete */ | ||
1224 | cy_as_function_callback cb, | ||
1225 | /* Client data to be passed to the callback */ | ||
1226 | uint32_t client | ||
1227 | ); | ||
1228 | |||
1229 | /* Summary | ||
1230 | This function returns information about a given unit on a | ||
1231 | specific device | ||
1232 | |||
1233 | Description | ||
1234 | This function retrieves information about a device of a | ||
1235 | given logical unit. The function is called with a given | ||
1236 | media type, device address, unit address, and a pointer | ||
1237 | to a unit descriptor (CyAsUnitDesc). This function fills | ||
1238 | in the data in the unit descriptor to provide information | ||
1239 | about the attributes of the device of the given logical | ||
1240 | unit. | ||
1241 | |||
1242 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1243 | * Nestable: YES | ||
1244 | |||
1245 | Returns | ||
1246 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
1247 | * not been configured | ||
1248 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1249 | * loaded into West Bridge | ||
1250 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1251 | * been started | ||
1252 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1253 | * passed in | ||
1254 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
1255 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
1256 | * with the West Bridge device | ||
1257 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1258 | * CY_AS_ERROR_NO_SUCH_DEVICE | ||
1259 | * CY_AS_ERROR_NO_SUCH_UNIT | ||
1260 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1261 | |||
1262 | |||
1263 | See Also | ||
1264 | * CyAsMediaType | ||
1265 | * CyAsStorageQueryMedia | ||
1266 | * CyAsStorageQueryDevice | ||
1267 | * CyAsUnitDesc | ||
1268 | */ | ||
1269 | EXTERN cy_as_return_status_t | ||
1270 | cy_as_storage_query_unit( | ||
1271 | /* Handle to the device of interest */ | ||
1272 | cy_as_device_handle handle, | ||
1273 | /* Parameters and return value for the query call */ | ||
1274 | cy_as_storage_query_unit_data *data_p, | ||
1275 | /* Callback to be called when the operation is complete */ | ||
1276 | cy_as_function_callback cb, | ||
1277 | /* Client data to be passed to the callback */ | ||
1278 | uint32_t client | ||
1279 | ); | ||
1280 | |||
1281 | /* Summary | ||
1282 | This function enables/disables the handling of SD/MMC card | ||
1283 | detection and SD/MMC write protection in West Bridge Firmware. | ||
1284 | |||
1285 | Description | ||
1286 | If the detection of SD/MMC card insertion or removal is being | ||
1287 | done by the Processor directly, the West Bridge firmware needs | ||
1288 | to be instructed to disable the card detect feature. Also, if | ||
1289 | the hardware design does not use the SD_WP GPIO of the West | ||
1290 | Bridge to handle SD card's write protect notch, the handling | ||
1291 | of write protection if firmware should be disabled. This API | ||
1292 | is used to enable/disable the card detect and write protect | ||
1293 | support in West Bridge firmware. | ||
1294 | |||
1295 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1296 | * Nestable: YES | ||
1297 | |||
1298 | Returns | ||
1299 | * CY_AS_ERROR_SUCCESS - the feature controls were | ||
1300 | * set successfully | ||
1301 | * CY_AS_ERROR_NO_SUCH_BUS - the specified bus is invalid | ||
1302 | * CY_AS_ERROR_NOT_SUPPORTED - function not supported on | ||
1303 | * the device in the specified bus | ||
1304 | * CY_AS_ERROR_IN_SUSPEND - the West Brdige device is in | ||
1305 | * suspended mode | ||
1306 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
1307 | * not been configured | ||
1308 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1309 | * loaded into West Bridge | ||
1310 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
1311 | * with the West Bridge device | ||
1312 | * CY_AS_ERROR_INVALID_HANDLE | ||
1313 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1314 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1315 | |||
1316 | */ | ||
1317 | EXTERN cy_as_return_status_t | ||
1318 | cy_as_storage_device_control( | ||
1319 | /* Handle to the West Bridge device */ | ||
1320 | cy_as_device_handle handle, | ||
1321 | /* The bus to control */ | ||
1322 | cy_as_bus_number_t bus, | ||
1323 | /* The device to control */ | ||
1324 | uint32_t device, | ||
1325 | /* Enable/disable control for card detection */ | ||
1326 | cy_bool card_detect_en, | ||
1327 | /* Enable/disable control for write protect handling */ | ||
1328 | cy_bool write_prot_en, | ||
1329 | /* Control which pin is used for card detection */ | ||
1330 | cy_as_storage_card_detect config_detect, | ||
1331 | /* Callback to be called when the operation is complete */ | ||
1332 | cy_as_function_callback cb, | ||
1333 | /* Client data to be passed to the callback */ | ||
1334 | uint32_t client | ||
1335 | ); | ||
1336 | |||
1337 | /* Summary | ||
1338 | This function reads one or more blocks of data from | ||
1339 | the storage system. | ||
1340 | |||
1341 | Description | ||
1342 | This function synchronously reads one or more blocks | ||
1343 | of data from the given media | ||
1344 | type/device and places the data into the data buffer | ||
1345 | given. This function does not | ||
1346 | return until the data is read and placed into the buffer. | ||
1347 | |||
1348 | * Valid In Asynchronous Callback: NO | ||
1349 | |||
1350 | Notes | ||
1351 | If the Samsung CEATA drive is the target for a | ||
1352 | read/write operation, the maximum | ||
1353 | number of sectors that can be accessed through a | ||
1354 | single API call is limited to 2047. | ||
1355 | Longer accesses addressed to a Samsung CEATA drive | ||
1356 | can result in time-out errors. | ||
1357 | |||
1358 | Returns | ||
1359 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1360 | * has not been configured | ||
1361 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1362 | * loaded into West Bridge | ||
1363 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1364 | * been started | ||
1365 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle | ||
1366 | * was passed in | ||
1367 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1368 | * returned | ||
1369 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1370 | * communicating with the West Bridge device | ||
1371 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1372 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified | ||
1373 | * does not exist | ||
1374 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified | ||
1375 | * media/device pair does not exist | ||
1376 | * CY_AS_ERROR_NO_SUCH_UNIT - the unit specified | ||
1377 | * does not exist | ||
1378 | * CY_AS_ERROR_ASYNC_PENDING - an async operation | ||
1379 | * is pending | ||
1380 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was | ||
1381 | * error in reading from the media | ||
1382 | * CY_AS_ERROR_MEDIA_WRITE_PROTECTED - the media is | ||
1383 | * write protected | ||
1384 | * CY_AS_ERROR_INVALID_PARAMETER - Reads/Writes greater | ||
1385 | * than 4095 logic blocks are not allowed | ||
1386 | |||
1387 | See Also | ||
1388 | * CyAsStorageReadAsync | ||
1389 | * CyAsStorageWrite | ||
1390 | * CyAsStorageWriteAsync | ||
1391 | * CyAsStorageCancelAsync | ||
1392 | * <LINK Asynchronous Versus Synchronous Operation> | ||
1393 | */ | ||
1394 | EXTERN cy_as_return_status_t | ||
1395 | cy_as_storage_read( | ||
1396 | /* Handle to the device of interest */ | ||
1397 | cy_as_device_handle handle, | ||
1398 | /* The bus to access */ | ||
1399 | cy_as_bus_number_t bus, | ||
1400 | /* The device to access */ | ||
1401 | uint32_t device, | ||
1402 | /* The unit to access */ | ||
1403 | uint32_t unit, | ||
1404 | /* The first block to access */ | ||
1405 | uint32_t block, | ||
1406 | /* The buffer where data will be placed */ | ||
1407 | void *data_p, | ||
1408 | /* The number of blocks to be read */ | ||
1409 | uint16_t num_blocks | ||
1410 | ); | ||
1411 | |||
1412 | /* Summary | ||
1413 | This function asynchronously reads one or more blocks of data | ||
1414 | from the storage system. | ||
1415 | |||
1416 | Description | ||
1417 | This function asynchronously reads one or more blocks of | ||
1418 | data from the given media | ||
1419 | type/device and places the data into the data buffer given. | ||
1420 | This function returns | ||
1421 | as soon as the request is transmitted to the West Bridge | ||
1422 | device but before the data is | ||
1423 | available. When the read is complete, the callback function | ||
1424 | is called to indicate the | ||
1425 | data has been placed into the data buffer. Note that the | ||
1426 | data buffer must remain | ||
1427 | valid from when the read is requested until the callback | ||
1428 | function is called. | ||
1429 | |||
1430 | * Valid In Asynchronous Callback: YES | ||
1431 | |||
1432 | Notes | ||
1433 | If the Samsung CEATA drive is the target for a read/write | ||
1434 | operation, the maximum | ||
1435 | number of sectors that can be accessed through a single API | ||
1436 | call is limited to 2047. | ||
1437 | Longer accesses addressed to a Samsung CEATA drive can | ||
1438 | result in time-out errors. | ||
1439 | |||
1440 | Returns | ||
1441 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1442 | * has not been configured | ||
1443 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1444 | * loaded into West Bridge | ||
1445 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1446 | * been started | ||
1447 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle | ||
1448 | * was passed in | ||
1449 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1450 | * returned | ||
1451 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1452 | * communicating with the West Bridge device | ||
1453 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1454 | * CY_AS_ERROR_ASYNC_PENDING - an async operation | ||
1455 | * is pending | ||
1456 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error | ||
1457 | * in reading from the media | ||
1458 | * CY_AS_ERROR_MEDIA_WRITE_PROTECTED - the media is | ||
1459 | * write protected | ||
1460 | * CY_AS_ERROR_QUERY_DEVICE_NEEDED - Before an | ||
1461 | * asynchronous read can be issue a call to | ||
1462 | * CyAsStorageQueryDevice must be made | ||
1463 | * CY_AS_ERROR_INVALID_PARAMETER - Reads/Writes greater | ||
1464 | * than 4095 logic blocks are not allowed | ||
1465 | |||
1466 | See Also | ||
1467 | * CyAsStorageRead | ||
1468 | * CyAsStorageWrite | ||
1469 | * CyAsStorageWriteAsync | ||
1470 | * CyAsStorageCancelAsync | ||
1471 | * CyAsStorageQueryDevice | ||
1472 | * <LINK Asynchronous Versus Synchronous Operation> | ||
1473 | */ | ||
1474 | EXTERN cy_as_return_status_t | ||
1475 | cy_as_storage_read_async( | ||
1476 | /* Handle to the device of interest */ | ||
1477 | cy_as_device_handle handle, | ||
1478 | /* The bus to access */ | ||
1479 | cy_as_bus_number_t bus, | ||
1480 | /* The device to access */ | ||
1481 | uint32_t device, | ||
1482 | /* The unit to access */ | ||
1483 | uint32_t unit, | ||
1484 | /* The first block to access */ | ||
1485 | uint32_t block, | ||
1486 | /* The buffer where data will be placed */ | ||
1487 | void *data_p, | ||
1488 | /* The number of blocks to be read */ | ||
1489 | uint16_t num_blocks, | ||
1490 | /* The function to call when the read is complete | ||
1491 | or an error occurs */ | ||
1492 | cy_as_storage_callback callback | ||
1493 | ); | ||
1494 | |||
1495 | /* Summary | ||
1496 | This function writes one or more blocks of data | ||
1497 | to the storage system. | ||
1498 | |||
1499 | Description | ||
1500 | This function synchronously writes one or more blocks of | ||
1501 | data to the given media/device. | ||
1502 | This function does not return until the data is written | ||
1503 | into the media. | ||
1504 | |||
1505 | * Valid In Asynchronous Callback: NO | ||
1506 | |||
1507 | Notes | ||
1508 | If the Samsung CEATA drive is the target for a read/write | ||
1509 | operation, the maximum | ||
1510 | number of sectors that can be accessed through a single | ||
1511 | API call is limited to 2047. | ||
1512 | Longer accesses addressed to a Samsung CEATA drive can | ||
1513 | result in time-out errors. | ||
1514 | |||
1515 | Returns | ||
1516 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1517 | * has not been configured | ||
1518 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1519 | * loaded into West Bridge | ||
1520 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1521 | * been started | ||
1522 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1523 | * passed in | ||
1524 | * CY_AS_ERROR_SUCCESS - the media information was | ||
1525 | * returned | ||
1526 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
1527 | * communicating with the West Bridge device | ||
1528 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1529 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does | ||
1530 | * not exist | ||
1531 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified | ||
1532 | * media/device pair does not exist | ||
1533 | * CY_AS_ERROR_NO_SUCH_UNIT - the unit specified | ||
1534 | * does not exist | ||
1535 | * CY_AS_ERROR_ASYNC_PENDING - an async operation | ||
1536 | * is pending | ||
1537 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error | ||
1538 | * in reading from the media | ||
1539 | * CY_AS_ERROR_MEDIA_WRITE_PROTECTED - the media is | ||
1540 | * write protected | ||
1541 | * CY_AS_ERROR_INVALID_PARAMETER - Reads/Writes greater | ||
1542 | * than 4095 logic blocks are not allowed | ||
1543 | |||
1544 | See Also | ||
1545 | * CyAsStorageRead | ||
1546 | * CyAsStorageReadAsync | ||
1547 | * CyAsStorageWriteAsync | ||
1548 | * CyAsStorageCancelAsync | ||
1549 | * <LINK Asynchronous Versus Synchronous Operation> | ||
1550 | */ | ||
1551 | EXTERN cy_as_return_status_t | ||
1552 | cy_as_storage_write( | ||
1553 | /* Handle to the device of interest */ | ||
1554 | cy_as_device_handle handle, | ||
1555 | /* The bus to access */ | ||
1556 | cy_as_bus_number_t bus, | ||
1557 | /* The device to access */ | ||
1558 | uint32_t device, | ||
1559 | /* The unit to access */ | ||
1560 | uint32_t unit, | ||
1561 | /* The first block to access */ | ||
1562 | uint32_t block, | ||
1563 | /* The buffer containing the data to be written */ | ||
1564 | void *data_p, | ||
1565 | /* The number of blocks to be written */ | ||
1566 | uint16_t num_blocks | ||
1567 | ); | ||
1568 | |||
1569 | /* Summary | ||
1570 | This function asynchronously writes one or more blocks | ||
1571 | of data to the storage system | ||
1572 | |||
1573 | Description | ||
1574 | This function asynchronously writes one or more blocks of | ||
1575 | data to the given media type/device. | ||
1576 | This function returns as soon as the request is transmitted | ||
1577 | to the West Bridge device | ||
1578 | but before the data is actually written. When the write is | ||
1579 | complete, the callback | ||
1580 | function is called to indicate the data has been physically | ||
1581 | written into the media. | ||
1582 | |||
1583 | * Valid In Asynchronous Callback: YES | ||
1584 | |||
1585 | Notes | ||
1586 | If the Samsung CEATA drive is the target for a read/write | ||
1587 | operation, the maximum | ||
1588 | number of sectors that can be accessed through a single API | ||
1589 | call is limited to 2047. | ||
1590 | Longer accesses addressed to a Samsung CEATA drive can | ||
1591 | result in time-out errors. | ||
1592 | |||
1593 | Notes | ||
1594 | The data buffer must remain valid from when the write is | ||
1595 | requested until the callback function is called. | ||
1596 | |||
1597 | Returns | ||
1598 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1599 | * has not been configured | ||
1600 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1601 | * loaded into West Bridge | ||
1602 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has | ||
1603 | * not been started | ||
1604 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
1605 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
1606 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
1607 | * with the West Bridge device | ||
1608 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1609 | * CY_AS_ERROR_ASYNC_PENDING - an async operation is | ||
1610 | * pending | ||
1611 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
1612 | * reading from the media | ||
1613 | * CY_AS_ERROR_MEDIA_WRITE_PROTECTED - the media is write | ||
1614 | * protected | ||
1615 | * CY_AS_ERROR_QUERY_DEVICE_NEEDED - A query device call is | ||
1616 | * required before async writes are allowed | ||
1617 | * CY_AS_ERROR_INVALID_PARAMETER - Reads/Writes greater | ||
1618 | * than 4095 logic blocks are not allowed | ||
1619 | |||
1620 | See Also | ||
1621 | * CyAsStorageRead | ||
1622 | * CyAsStorageWrite | ||
1623 | * CyAsStorageReadAsync | ||
1624 | * CyAsStorageCancelAsync | ||
1625 | * CyAsStorageQueryDevice | ||
1626 | * <LINK Asynchronous Versus Synchronous Operation> | ||
1627 | */ | ||
1628 | EXTERN cy_as_return_status_t | ||
1629 | cy_as_storage_write_async( | ||
1630 | /* Handle to the device of interest */ | ||
1631 | cy_as_device_handle handle, | ||
1632 | /* The bus to access */ | ||
1633 | cy_as_bus_number_t bus, | ||
1634 | /* The device to access */ | ||
1635 | uint32_t device, | ||
1636 | /* The unit to access */ | ||
1637 | uint32_t unit, | ||
1638 | /* The first block to access */ | ||
1639 | uint32_t block, | ||
1640 | /* The buffer where the data to be written is stored */ | ||
1641 | void *data_p, | ||
1642 | /* The number of blocks to be written */ | ||
1643 | uint16_t num_blocks, | ||
1644 | /* The function to call when the write is complete | ||
1645 | or an error occurs */ | ||
1646 | cy_as_storage_callback callback | ||
1647 | ); | ||
1648 | |||
1649 | /* Summary | ||
1650 | This function aborts any outstanding asynchronous operation | ||
1651 | |||
1652 | Description | ||
1653 | This function aborts any asynchronous block read or block | ||
1654 | write operation. As only a single asynchronous block read | ||
1655 | or write operation is possible at one time, this aborts | ||
1656 | the single operation in progress. | ||
1657 | |||
1658 | * Valid In Asynchronous Callback: YES | ||
1659 | |||
1660 | Returns | ||
1661 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
1662 | * has not been configured | ||
1663 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1664 | * loaded into West Bridge | ||
1665 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1666 | * been started | ||
1667 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
1668 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
1669 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
1670 | * CY_AS_ERROR_NO_OPERATION_PENDING - no asynchronous | ||
1671 | * operation is pending | ||
1672 | |||
1673 | See Also | ||
1674 | * CyAsStorageRead | ||
1675 | * CyAsStorageReadAsync | ||
1676 | * CyAsStorageWrite | ||
1677 | * CyAsStorageWriteAsync | ||
1678 | * <LINK Asynchronous Versus Synchronous Operation> | ||
1679 | */ | ||
1680 | EXTERN cy_as_return_status_t | ||
1681 | cy_as_storage_cancel_async( | ||
1682 | /* Handle to the device with outstanding async request */ | ||
1683 | cy_as_device_handle handle | ||
1684 | ); | ||
1685 | |||
1686 | /* Summary | ||
1687 | This function is used to read the content of SD registers | ||
1688 | |||
1689 | Description | ||
1690 | This function is used to read the contents of CSD, CID and | ||
1691 | CSD registers of the SD Card. | ||
1692 | |||
1693 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1694 | * Nestable: YES | ||
1695 | |||
1696 | Returns | ||
1697 | * CY_AS_ERROR_SUCCESS - the read operation was successful | ||
1698 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
1699 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1700 | * been configured | ||
1701 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1702 | * into West Bridge | ||
1703 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
1704 | * started | ||
1705 | * CY_AS_ERROR_IN_SUSPEND - The West Bridge device is in | ||
1706 | * suspend mode | ||
1707 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device pair | ||
1708 | * does not exist | ||
1709 | * CY_AS_ERROR_INVALID_PARAMETER - The register type is invalid | ||
1710 | * or the media is not supported on the bus | ||
1711 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to get memory to process | ||
1712 | * request | ||
1713 | * CY_AS_ERROR_INVALID_RESPONSE - communication failure with | ||
1714 | * West Bridge firmware | ||
1715 | |||
1716 | See Also | ||
1717 | * CyAsStorageSDRegReadData | ||
1718 | */ | ||
1719 | EXTERN cy_as_return_status_t | ||
1720 | cy_as_storage_sd_register_read( | ||
1721 | /* Handle to the West Bridge device. */ | ||
1722 | cy_as_device_handle handle, | ||
1723 | /* The bus to query */ | ||
1724 | cy_as_bus_number_t bus, | ||
1725 | /* The device to query */ | ||
1726 | uint8_t device, | ||
1727 | /* The type of register to read. */ | ||
1728 | cy_as_sd_card_reg_type reg_type, | ||
1729 | /* Output data buffer and length. */ | ||
1730 | cy_as_storage_sd_reg_read_data *data_p, | ||
1731 | /* Callback function to call when done. */ | ||
1732 | cy_as_function_callback cb, | ||
1733 | /* Call context to send to the cb function. */ | ||
1734 | uint32_t client | ||
1735 | ); | ||
1736 | |||
1737 | /* Summary | ||
1738 | Creates a partition starting at the given block and using the | ||
1739 | remaining blocks on the card. | ||
1740 | |||
1741 | Description | ||
1742 | Storage devices attached to West Bridge can be partitioned | ||
1743 | into two units. | ||
1744 | The visibility of these units through the mass storage | ||
1745 | interface can be | ||
1746 | individually controlled. This API is used to partition | ||
1747 | a device into two. | ||
1748 | |||
1749 | * Valid in Asynchronous Callback: Yes (if cb supplied) | ||
1750 | * Nestable: Yes | ||
1751 | |||
1752 | Returns | ||
1753 | * CY_AS_ERROR_SUCCESS - the partition was successfully created | ||
1754 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
1755 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1756 | * been configured | ||
1757 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1758 | * into West Bridge | ||
1759 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
1760 | * started | ||
1761 | * CY_AS_ERROR_IN_SUSPEND - The West Bridge device is in | ||
1762 | * suspend mode | ||
1763 | * CY_AS_ERROR_USB_RUNNING - Partition cannot be created while | ||
1764 | * USB stack is active | ||
1765 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to get memory to | ||
1766 | * process request | ||
1767 | * CY_AS_ERROR_INVALID_REQUEST - feature not supported by | ||
1768 | * active device or firmware | ||
1769 | * CY_AS_ERROR_INVALID_RESPONSE - communication failure with | ||
1770 | * West Bridge firmware | ||
1771 | * CY_AS_ERROR_ALREADY_PARTITIONED - the storage device already | ||
1772 | * has been partitioned | ||
1773 | * CY_AS_ERROR_INVALID_BLOCK - Size specified for the partition | ||
1774 | * exceeds the actual device capacity | ||
1775 | |||
1776 | See Also | ||
1777 | * <LINK Partitioning> | ||
1778 | * CyAsStorageRemovePPartition | ||
1779 | */ | ||
1780 | EXTERN cy_as_return_status_t | ||
1781 | cy_as_storage_create_p_partition( | ||
1782 | /* Handle to the device of interest */ | ||
1783 | cy_as_device_handle handle, | ||
1784 | /* Bus on which the device to be partitioned is connected */ | ||
1785 | cy_as_bus_number_t bus, | ||
1786 | /* Device number to be partitioned */ | ||
1787 | uint32_t device, | ||
1788 | /* Size of partition number 0 in blocks */ | ||
1789 | uint32_t size, | ||
1790 | /* Callback in case of async call */ | ||
1791 | cy_as_function_callback cb, | ||
1792 | /* Client context to pass to the callback */ | ||
1793 | uint32_t client | ||
1794 | ); | ||
1795 | |||
1796 | /* Summary | ||
1797 | Removes the partition table on a storage device connected | ||
1798 | to the West Bridge. | ||
1799 | |||
1800 | Description | ||
1801 | Storage devices attached to West Bridge can be partitioned | ||
1802 | into two units.This partition information is stored on the | ||
1803 | device and is non-volatile. This API is used to remove the | ||
1804 | stored partition information and make the entire device | ||
1805 | visible as a single partition (unit). | ||
1806 | |||
1807 | * Valid in Asynchronous Callback: Yes (if cb supplied) | ||
1808 | * Nestable: Yes | ||
1809 | |||
1810 | Returns | ||
1811 | * CY_AS_ERROR_SUCCESS - the partition was successfully | ||
1812 | * deleted | ||
1813 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1814 | * passed in | ||
1815 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
1816 | * not been configured | ||
1817 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1818 | * loaded into West Bridge | ||
1819 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1820 | * been started | ||
1821 | * CY_AS_ERROR_IN_SUSPEND - The West Bridge device is in | ||
1822 | * suspend mode | ||
1823 | * CY_AS_ERROR_USB_RUNNING - Partition cannot be created | ||
1824 | * while USB stack is active | ||
1825 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to get memory to | ||
1826 | * process request | ||
1827 | * CY_AS_ERROR_INVALID_REQUEST - operation not supported | ||
1828 | * by active device/firmware | ||
1829 | * CY_AS_ERROR_NO_SUCH_UNIT - the addressed device is | ||
1830 | * not partitioned | ||
1831 | |||
1832 | See Also | ||
1833 | * <LINK Partitioning> | ||
1834 | * CyAsStorageCreatePPartition | ||
1835 | */ | ||
1836 | EXTERN cy_as_return_status_t | ||
1837 | cy_as_storage_remove_p_partition( | ||
1838 | /* Handle to the device of interest */ | ||
1839 | cy_as_device_handle handle, | ||
1840 | /* Bus on which device of interest is connected */ | ||
1841 | cy_as_bus_number_t bus, | ||
1842 | /* Device number of interest */ | ||
1843 | uint32_t device, | ||
1844 | /* Callback in case of async call */ | ||
1845 | cy_as_function_callback cb, | ||
1846 | /* Client context to pass to the callback */ | ||
1847 | uint32_t client | ||
1848 | ); | ||
1849 | |||
1850 | /* Summary | ||
1851 | Returns the amount of data read/written to the given | ||
1852 | device from the USB host. | ||
1853 | |||
1854 | Description | ||
1855 | |||
1856 | * Valid in Asynchronous Callback: Yes (if cb supplied) | ||
1857 | * Nestable: Yes | ||
1858 | |||
1859 | Returns | ||
1860 | * CY_AS_ERROR_SUCCESS - API call completed successfully | ||
1861 | * CY_AS_ERROR_INVALID_HANDLE - Invalid West Bridge device | ||
1862 | * handle | ||
1863 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has | ||
1864 | * not been configured | ||
1865 | * CY_AS_ERROR_NO_FIRMWARE - No firmware image has been | ||
1866 | * loaded on West Bridge device | ||
1867 | * CY_AS_ERROR_NOT_RUNNING - Storage stack has not been | ||
1868 | * started | ||
1869 | * CY_AS_ERROR_NOT_SUPPORTED - This function is not | ||
1870 | * supported by active firmware version | ||
1871 | * CY_AS_ERROR_OUT_OF_MEMORY - Failed to get memory to | ||
1872 | * process the request | ||
1873 | * CY_AS_ERROR_TIMEOUT - West Bridge firmware did not | ||
1874 | * respond to request | ||
1875 | * CY_AS_ERROR_INVALID_RESPONSE - Unexpected reply from | ||
1876 | * West Bridge firmware | ||
1877 | |||
1878 | See Also | ||
1879 | * CyAsUsbSetMSReportThreshold | ||
1880 | */ | ||
1881 | EXTERN cy_as_return_status_t | ||
1882 | cy_as_storage_get_transfer_amount( | ||
1883 | /* Handle to the device of interest */ | ||
1884 | cy_as_device_handle handle, | ||
1885 | /* Bus on which device of interest is connected */ | ||
1886 | cy_as_bus_number_t bus, | ||
1887 | /* Device number of interest */ | ||
1888 | uint32_t device, | ||
1889 | /* Return value containing read/write sector counts. */ | ||
1890 | cy_as_m_s_c_progress_data *data_p, | ||
1891 | /* Callback in case of async call */ | ||
1892 | cy_as_function_callback cb, | ||
1893 | /* Client context to pass to the callback */ | ||
1894 | uint32_t client | ||
1895 | ); | ||
1896 | |||
1897 | /* Summary | ||
1898 | Performs a Sector Erase on an attached SD Card | ||
1899 | |||
1900 | Description | ||
1901 | This allows you to erase an attached SD card. The area to erase | ||
1902 | is specified in terms of a starting Erase Unit and a number of | ||
1903 | Erase Units. The size of each Erase Unit is defined in the | ||
1904 | DeviceDesc returned from a StorageQueryDevice call and it can | ||
1905 | differ between SD cards. | ||
1906 | |||
1907 | A large erase can take a while to complete depending on the SD | ||
1908 | card. In such a case it is recommended that an async call is made. | ||
1909 | |||
1910 | Returns | ||
1911 | * CY_AS_ERROR_SUCCESS - API call completed successfully | ||
1912 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1913 | * been configured | ||
1914 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1915 | * into West Bridge | ||
1916 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
1917 | * started | ||
1918 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed in | ||
1919 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1920 | * the West Bridge device | ||
1921 | * CY_AS_ERROR_ASYNC_PENDING - an async operation is pending | ||
1922 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
1923 | * reading from the media | ||
1924 | * CY_AS_ERROR_MEDIA_WRITE_PROTECTED - the media is write protected | ||
1925 | * CY_AS_ERROR_QUERY_DEVICE_NEEDED - A query device call is | ||
1926 | * required before erase is allowed | ||
1927 | * CY_AS_ERROR_NO_SUCH_BUS | ||
1928 | * CY_AS_ERROR_NO_SUCH_DEVICE | ||
1929 | * CY_AS_ERROR_NOT_SUPPORTED - Erase is currently only supported | ||
1930 | * on SD and using SD only firmware | ||
1931 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1932 | |||
1933 | See Also | ||
1934 | * CyAsStorageSDRegisterRead | ||
1935 | */ | ||
1936 | EXTERN cy_as_return_status_t | ||
1937 | cy_as_storage_erase( | ||
1938 | /* Handle to the device of interest */ | ||
1939 | cy_as_device_handle handle, | ||
1940 | /* Bus on which device of interest is connected */ | ||
1941 | cy_as_bus_number_t bus, | ||
1942 | /* Device number of interest */ | ||
1943 | uint32_t device, | ||
1944 | /* Erase Unit to start the erase */ | ||
1945 | uint32_t erase_unit, | ||
1946 | /* Number of Erase Units to erase */ | ||
1947 | uint16_t num_erase_units, | ||
1948 | /* Callback in case of async call */ | ||
1949 | cy_as_function_callback cb, | ||
1950 | /* Client context to pass to the callback */ | ||
1951 | uint32_t client | ||
1952 | ); | ||
1953 | |||
1954 | /* Summary | ||
1955 | This function is used to read a Tuple from the SDIO CIS area. | ||
1956 | |||
1957 | Description | ||
1958 | This function is used to read a Tuple from the SDIO CIS area. | ||
1959 | This function is to be used only for IO to an SDIO card as | ||
1960 | other media will not respond to the SDIO command set. | ||
1961 | |||
1962 | * Valid in Asynchronous Callback: NO | ||
1963 | * Valid on Antioch device: NO | ||
1964 | |||
1965 | Returns | ||
1966 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
1967 | * not been configured | ||
1968 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
1969 | * loaded into West Bridge | ||
1970 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
1971 | * been started | ||
1972 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
1973 | * passed in | ||
1974 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
1975 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device | ||
1976 | * is in suspend mode | ||
1977 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
1978 | * with the West Bridge device | ||
1979 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
1980 | * exist | ||
1981 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
1982 | * pair does not exist | ||
1983 | * CY_AS_ERROR_ASYNC_PENDING - an async operation is pending | ||
1984 | * CY_AS_ERROR_INVALID_REQUEST - an invalid IO request | ||
1985 | * type was made | ||
1986 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
1987 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
1988 | * received from the firmware | ||
1989 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
1990 | * reading from the media | ||
1991 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made to | ||
1992 | * an invalid function | ||
1993 | * CY_AS_ERROR_INVALID_ENDPOINT - A DMA request was made to | ||
1994 | * an invalid endpoint | ||
1995 | * CY_AS_ERROR_ENDPOINT_DISABLED - A DMA request was made to | ||
1996 | * a disabled endpoint | ||
1997 | |||
1998 | */ | ||
1999 | cy_as_return_status_t | ||
2000 | cy_as_sdio_get_c_i_s_info( | ||
2001 | /* Handle to the Westbridge device */ | ||
2002 | cy_as_device_handle handle, | ||
2003 | /* Bus to use */ | ||
2004 | cy_as_bus_number_t bus, | ||
2005 | /* Device number */ | ||
2006 | uint32_t device, | ||
2007 | /* IO function Number */ | ||
2008 | uint8_t n_function_no, | ||
2009 | /* Id of tuple to be fetched */ | ||
2010 | uint16_t tuple_id, | ||
2011 | /* Buffer to hold tuple read from card. | ||
2012 | should be at least 256 bytes in size */ | ||
2013 | uint8_t *data_p | ||
2014 | ); | ||
2015 | |||
2016 | |||
2017 | /* Summary | ||
2018 | This function is used to read properties of the SDIO card. | ||
2019 | |||
2020 | Description | ||
2021 | This function is used to read properties of the SDIO card | ||
2022 | into a CyAsSDIOCard structure. | ||
2023 | This function is to be used only for IO to an SDIO card as | ||
2024 | other media will not respond to the SDIO command set. | ||
2025 | |||
2026 | * Valid in Asynchronous Callback: NO | ||
2027 | * Valid on Antioch device: NO | ||
2028 | |||
2029 | Returns | ||
2030 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2031 | * not been configured | ||
2032 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2033 | * loaded into West Bridge | ||
2034 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
2035 | * started | ||
2036 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2037 | * passed in | ||
2038 | * CY_AS_ERROR_SUCCESS - the card information was returned | ||
2039 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2040 | * suspend mode | ||
2041 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2042 | * with the West Bridge device | ||
2043 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2044 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2045 | * exist | ||
2046 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2047 | * pair does not exist | ||
2048 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2049 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2050 | * received from the firmware | ||
2051 | |||
2052 | */ | ||
2053 | cy_as_return_status_t | ||
2054 | cy_as_sdio_query_card( | ||
2055 | /* Handle to the Westbridge device */ | ||
2056 | cy_as_device_handle handle, | ||
2057 | /* Bus to use */ | ||
2058 | cy_as_bus_number_t bus, | ||
2059 | /* Device number */ | ||
2060 | uint32_t device, | ||
2061 | /* Buffer to store card properties */ | ||
2062 | cy_as_sdio_card *data_p | ||
2063 | ); | ||
2064 | |||
2065 | /* Summary | ||
2066 | This function is used to reset a SDIO card. | ||
2067 | |||
2068 | Description | ||
2069 | This function is used to reset a SDIO card by writing to | ||
2070 | the reset bit in the CCCR and reinitializing the card. This | ||
2071 | function is to be used only for IO to an SDIO card as | ||
2072 | other media will not respond to the SDIO command set. | ||
2073 | |||
2074 | * Valid in Asynchronous Callback: NO | ||
2075 | * Valid on Antioch device: NO | ||
2076 | |||
2077 | Returns | ||
2078 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2079 | * not been configured | ||
2080 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
2081 | * into West Bridge | ||
2082 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2083 | * been started | ||
2084 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2085 | * passed in | ||
2086 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2087 | * suspend mode | ||
2088 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2089 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2090 | * with the West Bridge device | ||
2091 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2092 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2093 | * exist | ||
2094 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2095 | * pair does not exist | ||
2096 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2097 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2098 | * received from the firmware | ||
2099 | */ | ||
2100 | cy_as_return_status_t | ||
2101 | cy_as_sdio_reset_card( | ||
2102 | /* Handle to the Westbridge device */ | ||
2103 | cy_as_device_handle handle, | ||
2104 | /* Bus to use */ | ||
2105 | cy_as_bus_number_t bus, | ||
2106 | /* Device number */ | ||
2107 | uint32_t device | ||
2108 | ); | ||
2109 | |||
2110 | /* Summary | ||
2111 | This function performs a Synchronous 1 byte read from the sdio | ||
2112 | device function. | ||
2113 | |||
2114 | Description | ||
2115 | This function is used to perform a synchronous 1 byte read | ||
2116 | from an SDIO card function. This function is to be used only | ||
2117 | for IO to an SDIO card as other media will not respond to the | ||
2118 | SDIO command set. | ||
2119 | |||
2120 | * Valid in Asynchronous Callback: NO | ||
2121 | * Valid on Antioch device: NO | ||
2122 | |||
2123 | Returns | ||
2124 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
2125 | * been configured | ||
2126 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
2127 | * into West Bridge | ||
2128 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2129 | * been started | ||
2130 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed | ||
2131 | * in | ||
2132 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2133 | * suspend mode | ||
2134 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2135 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
2136 | * the West Bridge device | ||
2137 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2138 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not exist | ||
2139 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device pair | ||
2140 | * does not exist | ||
2141 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2142 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was received | ||
2143 | * from the firmware | ||
2144 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in reading | ||
2145 | * from the media | ||
2146 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made to an | ||
2147 | * invalid function | ||
2148 | * CY_AS_ERROR_FUNCTION_SUSPENDED - The function to which read | ||
2149 | * was attempted is in suspend | ||
2150 | */ | ||
2151 | cy_as_return_status_t | ||
2152 | cy_as_sdio_direct_read( | ||
2153 | /* Handle to the Westbridge device */ | ||
2154 | cy_as_device_handle handle, | ||
2155 | /* Bus to use */ | ||
2156 | cy_as_bus_number_t bus, | ||
2157 | /* Device number */ | ||
2158 | uint32_t device, | ||
2159 | /* IO function Number */ | ||
2160 | uint8_t n_function_no, | ||
2161 | /* Address for IO */ | ||
2162 | uint32_t address, | ||
2163 | /* Set to CY_SDIO_REARM_INT to reinitialize SDIO interrupt */ | ||
2164 | uint8_t misc_buf, | ||
2165 | /* Buffer to hold byte read from card */ | ||
2166 | uint8_t *data_p | ||
2167 | ); | ||
2168 | |||
2169 | /* Summary | ||
2170 | This function performs a Synchronous 1 byte write to the | ||
2171 | sdio device function. | ||
2172 | |||
2173 | Description | ||
2174 | This function is used to perform a synchronous 1 byte write | ||
2175 | to an SDIO card function. | ||
2176 | This function is to be used only for IO to an SDIO card as | ||
2177 | other media will not respond to the SDIO command set. | ||
2178 | |||
2179 | * Valid in Asynchronous Callback: NO | ||
2180 | * Valid on Antioch device: NO | ||
2181 | |||
2182 | Returns | ||
2183 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2184 | * not been configured | ||
2185 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2186 | * loaded into West Bridge | ||
2187 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
2188 | * started | ||
2189 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2190 | * passed in | ||
2191 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2192 | * suspend mode | ||
2193 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2194 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2195 | * with the West Bridge device | ||
2196 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2197 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not exist | ||
2198 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2199 | * pair does not exist | ||
2200 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2201 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was received | ||
2202 | * from the firmware | ||
2203 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
2204 | * reading from the media | ||
2205 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made to | ||
2206 | * an invalid function | ||
2207 | * CY_AS_ERROR_FUNCTION_SUSPENDED - The function to which | ||
2208 | * write was attempted is in suspend | ||
2209 | */ | ||
2210 | cy_as_return_status_t | ||
2211 | cy_as_sdio_direct_write( | ||
2212 | /* Handle to the Westbridge device */ | ||
2213 | cy_as_device_handle handle, | ||
2214 | /* Bus to use */ | ||
2215 | cy_as_bus_number_t bus, | ||
2216 | /* Device number */ | ||
2217 | uint32_t device, | ||
2218 | /* IO function Number */ | ||
2219 | uint8_t n_function_no, | ||
2220 | /* Address for IO */ | ||
2221 | uint32_t address, | ||
2222 | /* Set to CY_SDIO_REARM_INT to reinitialize SDIO interrupt, | ||
2223 | set to CY_SDIO_RAW for read after write */ | ||
2224 | uint8_t misc_buf, | ||
2225 | /* Byte to write */ | ||
2226 | uint16_t argument, | ||
2227 | /* Buffer to hold byte read from card in Read after write mode */ | ||
2228 | uint8_t *data_p | ||
2229 | ); | ||
2230 | |||
2231 | /* Summary | ||
2232 | This function is used to set the blocksize of an SDIO function. | ||
2233 | |||
2234 | Description | ||
2235 | This function is used to set the blocksize of an SDIO function. | ||
2236 | This function is to be used only for IO to an SDIO card as | ||
2237 | other media will not respond to the SDIO command set. | ||
2238 | |||
2239 | * Valid in Asynchronous Callback: NO | ||
2240 | * Valid on Antioch device: NO | ||
2241 | |||
2242 | Returns | ||
2243 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2244 | * not been configured | ||
2245 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2246 | * loaded into West Bridge | ||
2247 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2248 | * been started | ||
2249 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2250 | * passed in | ||
2251 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2252 | * suspend mode | ||
2253 | * CY_AS_ERROR_SUCCESS - the media information was | ||
2254 | * returned | ||
2255 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2256 | * with the West Bridge device | ||
2257 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2258 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2259 | * exist | ||
2260 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2261 | * pair does not exist | ||
2262 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory | ||
2263 | * available | ||
2264 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2265 | * received from the firmware | ||
2266 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
2267 | * reading from the media | ||
2268 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2269 | * to an invalid function | ||
2270 | * CY_AS_ERROR_INVALID_BLOCKSIZE - An incorrect blocksize | ||
2271 | * was passed to the function. | ||
2272 | * CY_AS_ERROR_FUNCTION_SUSPENDED - The function to which | ||
2273 | * write was attempted is in suspend | ||
2274 | */ | ||
2275 | cy_as_return_status_t | ||
2276 | cy_as_sdio_set_blocksize( | ||
2277 | /* Handle to the Westbridge device */ | ||
2278 | cy_as_device_handle handle, | ||
2279 | /* Bus to use */ | ||
2280 | cy_as_bus_number_t bus, | ||
2281 | /* Device number */ | ||
2282 | uint32_t device, | ||
2283 | /* IO function Number */ | ||
2284 | uint8_t n_function_no, | ||
2285 | /* Block size to set. */ | ||
2286 | uint16_t blocksize | ||
2287 | ); | ||
2288 | |||
2289 | /* Summary | ||
2290 | This function is used to read Multibyte/Block data from a | ||
2291 | IO function. | ||
2292 | |||
2293 | Description | ||
2294 | This function is used to read Multibyte/Block data from a | ||
2295 | IO function. This function is to be used only for IO to an | ||
2296 | SDIO card as other media will not respond to the SDIO | ||
2297 | command set. | ||
2298 | |||
2299 | * Valid in Asynchronous Callback: YES | ||
2300 | * Valid on Antioch device: NO | ||
2301 | |||
2302 | Returns | ||
2303 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2304 | * not been configured | ||
2305 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2306 | * loaded into West Bridge | ||
2307 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2308 | * been started | ||
2309 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2310 | * passed in | ||
2311 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2312 | * suspend mode | ||
2313 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2314 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
2315 | * the West Bridge device | ||
2316 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2317 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not exist | ||
2318 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2319 | * pair does not exist | ||
2320 | * CY_AS_ERROR_ASYNC_PENDING - an async operation is pending | ||
2321 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2322 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was received | ||
2323 | * from the firmware | ||
2324 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
2325 | * reading from the media | ||
2326 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made to | ||
2327 | * an invalid function | ||
2328 | * CY_AS_ERROR_INVALID_BLOCKSIZE - An incorrect blocksize or | ||
2329 | * block count was passed to the function. | ||
2330 | * CY_AS_ERROR_FUNCTION_SUSPENDED - The function to which | ||
2331 | * write was attempted is in suspend | ||
2332 | * CY_AS_ERROR_IO_ABORTED - The IO operation was aborted | ||
2333 | * CY_AS_ERROR_IO_SUSPENDED - The IO operation was suspended | ||
2334 | * CY_AS_ERROR_INVALID_REQUEST - An invalid request was | ||
2335 | * passed to the card. | ||
2336 | |||
2337 | */ | ||
2338 | cy_as_return_status_t | ||
2339 | cy_as_sdio_extended_read( | ||
2340 | /* Handle to the Westbridge device */ | ||
2341 | cy_as_device_handle handle, | ||
2342 | /* Bus to use */ | ||
2343 | cy_as_bus_number_t bus, | ||
2344 | /* Device number */ | ||
2345 | uint32_t device, | ||
2346 | /* IO function Number */ | ||
2347 | uint8_t n_function_no, | ||
2348 | /* Base Address for IO */ | ||
2349 | uint32_t address, | ||
2350 | /* Set to CY_SDIO_BLOCKMODE for block IO, | ||
2351 | CY_SDIO_BYTEMODE for multibyte IO, | ||
2352 | CY_SDIO_OP_FIFO to read multiple bytes from the | ||
2353 | same address, CY_SDIO_OP_INCR to read bytes from | ||
2354 | the incrementing addresses */ | ||
2355 | uint8_t misc_buf, | ||
2356 | /* Block/Byte count to read */ | ||
2357 | uint16_t argument, | ||
2358 | /* Buffer to hold data read from card */ | ||
2359 | uint8_t *data_p, | ||
2360 | /* Callback in case of Asyncronous call. 0 if Synchronous */ | ||
2361 | cy_as_sdio_callback callback | ||
2362 | ); | ||
2363 | |||
2364 | /* Summary | ||
2365 | This function is used to write Multibyte/Block data | ||
2366 | to a IO function. | ||
2367 | |||
2368 | Description | ||
2369 | This function is used to write Multibyte/Block data | ||
2370 | to a IO function. This function is to be used only | ||
2371 | for IO to an SDIO card as other media will not respond | ||
2372 | to the SDIO command set. | ||
2373 | |||
2374 | * Valid in Asynchronous Callback: YES | ||
2375 | * Valid on Antioch device: NO | ||
2376 | |||
2377 | Returns | ||
2378 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2379 | * not been configured | ||
2380 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2381 | * loaded into West Bridge | ||
2382 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2383 | * been started | ||
2384 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2385 | * passed in | ||
2386 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2387 | * suspend mode | ||
2388 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2389 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2390 | * with the West Bridge device | ||
2391 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2392 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2393 | * exist | ||
2394 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2395 | * pair does not exist | ||
2396 | * CY_AS_ERROR_ASYNC_PENDING - an async operation is pending | ||
2397 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2398 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2399 | * received from the firmware | ||
2400 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
2401 | * reading from the media | ||
2402 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2403 | * to an invalid function | ||
2404 | * CY_AS_ERROR_INVALID_BLOCKSIZE - An incorrect blocksize or | ||
2405 | * block count was passed to the function. | ||
2406 | * CY_AS_ERROR_FUNCTION_SUSPENDED - The function to which | ||
2407 | * write was attempted is in suspend | ||
2408 | * CY_AS_ERROR_IO_ABORTED - The IO operation was aborted | ||
2409 | * CY_AS_ERROR_IO_SUSPENDED - The IO operation was suspended | ||
2410 | * CY_AS_ERROR_INVALID_REQUEST - An invalid request was | ||
2411 | * passed to the card. | ||
2412 | */ | ||
2413 | cy_as_return_status_t | ||
2414 | cy_as_sdio_extended_write( | ||
2415 | /* Handle to the Westbridge device */ | ||
2416 | cy_as_device_handle handle, | ||
2417 | /* Bus to use */ | ||
2418 | cy_as_bus_number_t bus, | ||
2419 | /* Device number */ | ||
2420 | uint32_t device, | ||
2421 | /* IO function Number */ | ||
2422 | uint8_t n_function_no, | ||
2423 | /* Base Address for IO */ | ||
2424 | uint32_t address, | ||
2425 | /* Set to CY_SDIO_BLOCKMODE for block IO, | ||
2426 | CY_SDIO_BYTEMODE for multibyte IO, | ||
2427 | CY_SDIO_OP_FIFO to write multiple bytes to the same address, | ||
2428 | CY_SDIO_OP_INCR to write multiple bytes to incrementing | ||
2429 | addresses */ | ||
2430 | uint8_t misc_buf, | ||
2431 | /* Block/Byte count to write | ||
2432 | in case of byte mode the count should not exceed the block size | ||
2433 | or 512, whichever is smaller. | ||
2434 | in case of block mode, maximum number of blocks is 511. */ | ||
2435 | uint16_t argument, | ||
2436 | /* Buffer to hold data to be written to card. */ | ||
2437 | uint8_t *data_p, | ||
2438 | /* Callback in case of Asyncronous call. 0 if Synchronous */ | ||
2439 | cy_as_sdio_callback callback | ||
2440 | ); | ||
2441 | |||
2442 | /* Summary | ||
2443 | This function is used to initialize a SDIO card function. | ||
2444 | |||
2445 | Description | ||
2446 | This function is used to initialize a SDIO card function | ||
2447 | (1 - 7). This function is to be used only for IO to an | ||
2448 | SDIO card as other media will not respond to the SDIO | ||
2449 | command set. | ||
2450 | |||
2451 | * Valid in Asynchronous Callback: NO | ||
2452 | * Valid on Antioch device: NO | ||
2453 | |||
2454 | Returns | ||
2455 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2456 | * not been configured | ||
2457 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
2458 | * into West Bridge | ||
2459 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
2460 | * started | ||
2461 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed | ||
2462 | * in | ||
2463 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2464 | * suspend mode | ||
2465 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2466 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2467 | * with the West Bridge device | ||
2468 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2469 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not exist | ||
2470 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2471 | * pair does not exist | ||
2472 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory available | ||
2473 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2474 | * received from the firmware | ||
2475 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error in | ||
2476 | * reading from the media | ||
2477 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2478 | * to an invalid function | ||
2479 | */ | ||
2480 | cy_as_return_status_t | ||
2481 | cy_as_sdio_init_function( | ||
2482 | /* Handle to the Westbridge device */ | ||
2483 | cy_as_device_handle handle, | ||
2484 | /* Bus to use */ | ||
2485 | cy_as_bus_number_t bus, | ||
2486 | /* Device number */ | ||
2487 | uint32_t device, | ||
2488 | /* IO function Number */ | ||
2489 | uint8_t n_function_no, | ||
2490 | /* Set to CY_SDIO_FORCE_INIT to reinitialize function */ | ||
2491 | uint8_t misc_buf | ||
2492 | ); | ||
2493 | |||
2494 | /* Summary | ||
2495 | This function is used to get properties of a SDIO card function. | ||
2496 | |||
2497 | Description | ||
2498 | This function is used to get properties of a SDIO card functio | ||
2499 | (1 - 7) into a CyAsSDIOFunc structure. This function is to be | ||
2500 | used only for IO to an SDIO card as other media will not respond | ||
2501 | to the SDIO command set. | ||
2502 | |||
2503 | * Valid in Asynchronous Callback: NO | ||
2504 | * Valid on Antioch device: NO | ||
2505 | |||
2506 | Returns | ||
2507 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
2508 | * been configured | ||
2509 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
2510 | * into West Bridge | ||
2511 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not been | ||
2512 | * started | ||
2513 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was passed | ||
2514 | * in | ||
2515 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2516 | * suspend mode | ||
2517 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2518 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2519 | * CY_AS_ERROR_NO_SUCH_BUS - the media specified does | ||
2520 | * not exist | ||
2521 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device pair | ||
2522 | * does not exist | ||
2523 | * CY_AS_ERROR_INVALID_FUNCTION - An IO request was made to | ||
2524 | * an invalid function | ||
2525 | */ | ||
2526 | cy_as_return_status_t | ||
2527 | cy_as_sdio_query_function( | ||
2528 | /* Handle to the Westbridge device */ | ||
2529 | cy_as_device_handle handle, | ||
2530 | /* Bus to use */ | ||
2531 | cy_as_bus_number_t bus, | ||
2532 | /* Device number */ | ||
2533 | uint32_t device, | ||
2534 | /* IO function Number */ | ||
2535 | uint8_t n_function_no, | ||
2536 | /* Buffer to store function properties */ | ||
2537 | cy_as_sdio_func *data_p | ||
2538 | ); | ||
2539 | |||
2540 | /* Summary | ||
2541 | This function is used to Abort the current IO function. | ||
2542 | |||
2543 | Description | ||
2544 | This function is used to Abort the current IO function. | ||
2545 | This function is to be used only for IO to an SDIO card as | ||
2546 | other media will not respond to the SDIO command set. | ||
2547 | |||
2548 | * Valid in Asynchronous Callback: NO | ||
2549 | * Valid on Antioch device: NO | ||
2550 | |||
2551 | Returns | ||
2552 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
2553 | * has not been configured | ||
2554 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2555 | * loaded into West Bridge | ||
2556 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2557 | * been started | ||
2558 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2559 | * passed in | ||
2560 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2561 | * suspend mode | ||
2562 | * CY_AS_ERROR_SUCCESS - the media information was | ||
2563 | * returned | ||
2564 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2565 | * with the West Bridge device | ||
2566 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2567 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2568 | * exist | ||
2569 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified | ||
2570 | * media/device pair does not exist | ||
2571 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory | ||
2572 | * available | ||
2573 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2574 | * to an invalid function | ||
2575 | */ | ||
2576 | cy_as_return_status_t | ||
2577 | cy_as_sdio_abort_function( | ||
2578 | /* Handle to the Westbridge device */ | ||
2579 | cy_as_device_handle handle, | ||
2580 | /* Bus to use */ | ||
2581 | cy_as_bus_number_t bus, | ||
2582 | /* Device number */ | ||
2583 | uint32_t device, | ||
2584 | /* IO function Number */ | ||
2585 | uint8_t n_function_no | ||
2586 | ); | ||
2587 | |||
2588 | /* Summary | ||
2589 | This function is used to Disable IO to an SDIO function. | ||
2590 | |||
2591 | Description | ||
2592 | This function is used to Disable IO to an SDIO function. | ||
2593 | This function is to be used only for IO to an SDIO card as | ||
2594 | other media will not respond to the SDIO command set. | ||
2595 | |||
2596 | * Valid in Asynchronous Callback: NO | ||
2597 | * Valid on Antioch device: NO | ||
2598 | |||
2599 | Returns | ||
2600 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
2601 | * has not been configured | ||
2602 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2603 | * loaded into West Bridge | ||
2604 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2605 | * been started | ||
2606 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2607 | * passed in | ||
2608 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is | ||
2609 | * in suspend mode | ||
2610 | * CY_AS_ERROR_SUCCESS - the media information was | ||
2611 | * returned | ||
2612 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2613 | * with the West Bridge device | ||
2614 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2615 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2616 | * exist | ||
2617 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified media/device | ||
2618 | * pair does not exist | ||
2619 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2620 | * to an invalid function | ||
2621 | */ | ||
2622 | cy_as_return_status_t | ||
2623 | cy_as_sdio_de_init_function( | ||
2624 | /* Handle to the Westbridge device */ | ||
2625 | cy_as_device_handle handle, | ||
2626 | /* Bus to use */ | ||
2627 | cy_as_bus_number_t bus, | ||
2628 | /* Device number */ | ||
2629 | uint32_t device, | ||
2630 | /* IO function Number */ | ||
2631 | uint8_t n_function_no | ||
2632 | ); | ||
2633 | |||
2634 | /* Summary | ||
2635 | This function is used to Suspend the current IO function. | ||
2636 | |||
2637 | Description | ||
2638 | This function is used to Suspend the current IO function. | ||
2639 | This function is to be used only for IO to an SDIO card as | ||
2640 | other media will not respond to the SDIO command set. | ||
2641 | |||
2642 | * Valid in Asynchronous Callback: NO | ||
2643 | * Valid on Antioch device: NO | ||
2644 | |||
2645 | Returns | ||
2646 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has | ||
2647 | * not been configured | ||
2648 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2649 | * loaded into West Bridge | ||
2650 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2651 | * been started | ||
2652 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2653 | * passed in | ||
2654 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is in | ||
2655 | * suspend mode | ||
2656 | * CY_AS_ERROR_SUCCESS - the media information was returned | ||
2657 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
2658 | * with the West Bridge device | ||
2659 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2660 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified does not | ||
2661 | * exist | ||
2662 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified | ||
2663 | * media/device pair does not exist | ||
2664 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory | ||
2665 | * available | ||
2666 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was made | ||
2667 | * to an invalid function | ||
2668 | */ | ||
2669 | cy_as_return_status_t | ||
2670 | cy_as_sdio_suspend( | ||
2671 | /* Handle to the Westbridge device */ | ||
2672 | cy_as_device_handle handle, | ||
2673 | /* Bus to use */ | ||
2674 | cy_as_bus_number_t bus, | ||
2675 | /* Device number */ | ||
2676 | uint32_t device, | ||
2677 | /* IO function Number */ | ||
2678 | uint8_t n_function_no | ||
2679 | ); | ||
2680 | |||
2681 | /* Summary | ||
2682 | This function is used to resume a Suspended IO function. | ||
2683 | |||
2684 | Description | ||
2685 | This function is used to resume a Suspended IO function. | ||
2686 | This function is to be used only for IO to an SDIO card as | ||
2687 | other media will not respond to the SDIO command set. | ||
2688 | |||
2689 | * Valid in Asynchronous Callback: NO | ||
2690 | * Valid on Antioch device: NO | ||
2691 | |||
2692 | Returns | ||
2693 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device | ||
2694 | * has not been configured | ||
2695 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been | ||
2696 | * loaded into West Bridge | ||
2697 | * CY_AS_ERROR_NOT_RUNNING - the storage stack has not | ||
2698 | * been started | ||
2699 | * CY_AS_ERROR_INVALID_HANDLE - an invalid handle was | ||
2700 | * passed in | ||
2701 | * CY_AS_ERROR_IN_SUSPEND - the West Bridge device is | ||
2702 | * in suspend mode | ||
2703 | * CY_AS_ERROR_SUCCESS - the media information was | ||
2704 | * returned | ||
2705 | * CY_AS_ERROR_TIMEOUT - a timeout occurred | ||
2706 | * communicating with the West Bridge device | ||
2707 | * CY_AS_ERROR_NOT_RUNNING - the stack is not running | ||
2708 | * CY_AS_ERROR_NO_SUCH_BUS - the bus specified | ||
2709 | * does not exist | ||
2710 | * CY_AS_ERROR_NO_SUCH_DEVICE - the specified | ||
2711 | * media/device pair does not exist | ||
2712 | * CY_AS_ERROR_ASYNC_PENDING - an async operation | ||
2713 | * is pending | ||
2714 | * CY_AS_ERROR_OUT_OF_MEMORY - insufficient memory | ||
2715 | * available | ||
2716 | * CY_AS_ERROR_INVALID_RESPONSE - an error message was | ||
2717 | * received from the firmware | ||
2718 | * CY_AS_ERROR_MEDIA_ACCESS_FAILURE - there was error | ||
2719 | * in reading from the media | ||
2720 | * CY_AS_ERROR_INVALID_FUNCTION - An IO attempt was | ||
2721 | * made to an invalid function | ||
2722 | * CY_AS_ERROR_IO_ABORTED - The IO operation was | ||
2723 | * aborted | ||
2724 | * CY_AS_ERROR_IO_SUSPENDED - The IO operation was | ||
2725 | * suspended | ||
2726 | * CY_AS_ERROR_INVALID_REQUEST - An invalid request was | ||
2727 | * passed to the card. | ||
2728 | |||
2729 | */ | ||
2730 | cy_as_return_status_t | ||
2731 | cy_as_sdio_resume( | ||
2732 | /* Handle to the Westbridge device */ | ||
2733 | cy_as_device_handle handle, | ||
2734 | /* Bus to use */ | ||
2735 | cy_as_bus_number_t bus, | ||
2736 | /* Device number */ | ||
2737 | uint32_t device, | ||
2738 | /* IO function Number */ | ||
2739 | uint8_t n_function_no, | ||
2740 | /* Operation to resume (Read or Write) */ | ||
2741 | cy_as_oper_type op, | ||
2742 | /* Micellaneous buffer same as for Extended read and Write */ | ||
2743 | uint8_t misc_buf, | ||
2744 | /* Number of pending blocks for IO. Should be less | ||
2745 | than or equal to the maximum defined for extended | ||
2746 | read and write */ | ||
2747 | uint16_t pendingblockcount, | ||
2748 | /* Buffer to continue the Suspended IO operation */ | ||
2749 | uint8_t *data_p | ||
2750 | ); | ||
2751 | |||
2752 | |||
2753 | |||
2754 | /* For supporting deprecated functions */ | ||
2755 | #include "cyasstorage_dep.h" | ||
2756 | |||
2757 | #include "cyas_cplus_end.h" | ||
2758 | |||
2759 | #endif /* _INCLUDED_CYASSTORAGE_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage_dep.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage_dep.h deleted file mode 100644 index 566b244bd8c5..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasstorage_dep.h +++ /dev/null | |||
@@ -1,309 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyanstorage_dep.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* This header will contain Antioch specific declaration | ||
23 | * of the APIs that are deprecated in Astoria SDK. This is | ||
24 | * for maintaining backward compatibility | ||
25 | */ | ||
26 | #ifndef __INCLUDED_CYANSTORAGE_DEP_H__ | ||
27 | #define __INCLUDED_CYANSTORAGE_DEP_H__ | ||
28 | |||
29 | #ifndef __doxygen__ | ||
30 | |||
31 | typedef void (*cy_as_storage_callback_dep)( | ||
32 | /* Handle to the device completing the storage operation */ | ||
33 | cy_as_device_handle handle, | ||
34 | /* The media type completing the operation */ | ||
35 | cy_as_media_type type, | ||
36 | /* The device completing the operation */ | ||
37 | uint32_t device, | ||
38 | /* The unit completing the operation */ | ||
39 | uint32_t unit, | ||
40 | /* The block number of the completed operation */ | ||
41 | uint32_t block_number, | ||
42 | /* The type of operation */ | ||
43 | cy_as_oper_type op, | ||
44 | /* The error status */ | ||
45 | cy_as_return_status_t status | ||
46 | ); | ||
47 | |||
48 | typedef void (*cy_as_storage_event_callback_dep)( | ||
49 | /* Handle to the device sending the event notification */ | ||
50 | cy_as_device_handle handle, | ||
51 | /* The media type */ | ||
52 | cy_as_media_type type, | ||
53 | /* The event type */ | ||
54 | cy_as_storage_event evtype, | ||
55 | /* Event related data */ | ||
56 | void *evdata | ||
57 | ); | ||
58 | |||
59 | typedef struct cy_as_storage_query_device_data_dep { | ||
60 | /* The type of media to query */ | ||
61 | cy_as_media_type type; | ||
62 | /* The logical device number to query */ | ||
63 | uint32_t device; | ||
64 | /* The return value for the device descriptor */ | ||
65 | cy_as_device_desc desc_p; | ||
66 | } cy_as_storage_query_device_data_dep; | ||
67 | |||
68 | typedef struct cy_as_storage_query_unit_data_dep { | ||
69 | /* The type of media to query */ | ||
70 | cy_as_media_type type; | ||
71 | /* The logical device number to query */ | ||
72 | uint32_t device; | ||
73 | /* The unit to query on the device */ | ||
74 | uint32_t unit; | ||
75 | /* The return value for the unit descriptor */ | ||
76 | cy_as_unit_desc desc_p; | ||
77 | } cy_as_storage_query_unit_data_dep; | ||
78 | |||
79 | |||
80 | /************ FUNCTIONS *********************/ | ||
81 | |||
82 | EXTERN cy_as_return_status_t | ||
83 | cy_as_storage_register_callback_dep( | ||
84 | /* Handle to the device of interest */ | ||
85 | cy_as_device_handle handle, | ||
86 | /* The callback function to call for async storage events */ | ||
87 | cy_as_storage_event_callback_dep callback | ||
88 | ); | ||
89 | |||
90 | EXTERN cy_as_return_status_t | ||
91 | cy_as_storage_claim_dep(cy_as_device_handle handle, | ||
92 | cy_as_media_type type | ||
93 | ); | ||
94 | |||
95 | EXTERN cy_as_return_status_t | ||
96 | cy_as_storage_claim_dep_EX( | ||
97 | /* Handle to the device of interest */ | ||
98 | cy_as_device_handle handle, | ||
99 | /* The type of media to claim */ | ||
100 | cy_as_media_type *type, | ||
101 | /* Callback to be called when the operation is complete */ | ||
102 | cy_as_function_callback cb, | ||
103 | /* Client data to be passed to the callback */ | ||
104 | uint32_t client | ||
105 | ); | ||
106 | |||
107 | EXTERN cy_as_return_status_t | ||
108 | cy_as_storage_release_dep(cy_as_device_handle handle, | ||
109 | cy_as_media_type type | ||
110 | ); | ||
111 | |||
112 | EXTERN cy_as_return_status_t | ||
113 | cy_as_storage_release_dep_EX( | ||
114 | /* Handle to the device of interest */ | ||
115 | cy_as_device_handle handle, | ||
116 | /* Handle to the device of interest */ | ||
117 | cy_as_media_type *type, | ||
118 | /* Callback to be called when the operation is complete */ | ||
119 | cy_as_function_callback cb, | ||
120 | /* Client data to be passed to the callback */ | ||
121 | uint32_t client | ||
122 | ); | ||
123 | |||
124 | EXTERN cy_as_return_status_t | ||
125 | cy_as_storage_query_device_dep( | ||
126 | cy_as_device_handle handle, | ||
127 | cy_as_media_type media, | ||
128 | uint32_t device, | ||
129 | cy_as_device_desc *desc_p | ||
130 | ); | ||
131 | |||
132 | EXTERN cy_as_return_status_t | ||
133 | cy_as_storage_query_device_dep_EX( | ||
134 | /* Handle to the device of interest */ | ||
135 | cy_as_device_handle handle, | ||
136 | /* Parameters and return value for the query call */ | ||
137 | cy_as_storage_query_device_data_dep *data, | ||
138 | /* Callback to be called when the operation is complete */ | ||
139 | cy_as_function_callback cb, | ||
140 | /* Client data to be passed to the callback */ | ||
141 | uint32_t client | ||
142 | ); | ||
143 | |||
144 | EXTERN cy_as_return_status_t | ||
145 | cy_as_storage_query_unit_dep( | ||
146 | /* Handle to the device of interest */ | ||
147 | cy_as_device_handle handle, | ||
148 | /* The type of media to query */ | ||
149 | cy_as_media_type type, | ||
150 | /* The logical device number to query */ | ||
151 | uint32_t device, | ||
152 | /* The unit to query on the device */ | ||
153 | uint32_t unit, | ||
154 | /* The return value for the unit descriptor */ | ||
155 | cy_as_unit_desc *unit_p | ||
156 | ); | ||
157 | |||
158 | EXTERN cy_as_return_status_t | ||
159 | cy_as_storage_query_unit_dep_EX( | ||
160 | /* Handle to the device of interest */ | ||
161 | cy_as_device_handle handle, | ||
162 | /* Parameters and return value for the query call */ | ||
163 | cy_as_storage_query_unit_data_dep *data_p, | ||
164 | /* Callback to be called when the operation is complete */ | ||
165 | cy_as_function_callback cb, | ||
166 | /* Client data to be passed to the callback */ | ||
167 | uint32_t client | ||
168 | ); | ||
169 | |||
170 | EXTERN cy_as_return_status_t | ||
171 | cy_as_storage_device_control_dep( | ||
172 | /* Handle to the West Bridge device */ | ||
173 | cy_as_device_handle handle, | ||
174 | /* Enable/disable control for card detection */ | ||
175 | cy_bool card_detect_en, | ||
176 | /* Enable/disable control for write protect handling */ | ||
177 | cy_bool write_prot_en, | ||
178 | /* Callback to be called when the operation is complete */ | ||
179 | cy_as_function_callback cb, | ||
180 | /* Client data to be passed to the callback */ | ||
181 | uint32_t client | ||
182 | ); | ||
183 | |||
184 | |||
185 | EXTERN cy_as_return_status_t | ||
186 | cy_as_storage_read_dep( | ||
187 | /* Handle to the device of interest */ | ||
188 | cy_as_device_handle handle, | ||
189 | /* The type of media to access */ | ||
190 | cy_as_media_type type, | ||
191 | /* The device to access */ | ||
192 | uint32_t device, | ||
193 | /* The unit to access */ | ||
194 | uint32_t unit, | ||
195 | /* The first block to access */ | ||
196 | uint32_t block, | ||
197 | /* The buffer where data will be placed */ | ||
198 | void *data_p, | ||
199 | /* The number of blocks to be read */ | ||
200 | uint16_t num_blocks | ||
201 | ); | ||
202 | |||
203 | EXTERN cy_as_return_status_t | ||
204 | cy_as_storage_read_async_dep( | ||
205 | /* Handle to the device of interest */ | ||
206 | cy_as_device_handle handle, | ||
207 | /* The type of media to access */ | ||
208 | cy_as_media_type type, | ||
209 | /* The device to access */ | ||
210 | uint32_t device, | ||
211 | /* The unit to access */ | ||
212 | uint32_t unit, | ||
213 | /* The first block to access */ | ||
214 | uint32_t block, | ||
215 | /* The buffer where data will be placed */ | ||
216 | void *data_p, | ||
217 | /* The number of blocks to be read */ | ||
218 | uint16_t num_blocks, | ||
219 | /* The function to call when the read is complete | ||
220 | or an error occurs */ | ||
221 | cy_as_storage_callback_dep callback | ||
222 | ); | ||
223 | EXTERN cy_as_return_status_t | ||
224 | cy_as_storage_write_dep( | ||
225 | /* Handle to the device of interest */ | ||
226 | cy_as_device_handle handle, | ||
227 | /* The type of media to access */ | ||
228 | cy_as_media_type type, | ||
229 | /* The device to access */ | ||
230 | uint32_t device, | ||
231 | /* The unit to access */ | ||
232 | uint32_t unit, | ||
233 | /* The first block to access */ | ||
234 | uint32_t block, | ||
235 | /* The buffer containing the data to be written */ | ||
236 | void *data_p, | ||
237 | /* The number of blocks to be written */ | ||
238 | uint16_t num_blocks | ||
239 | ); | ||
240 | |||
241 | EXTERN cy_as_return_status_t | ||
242 | cy_as_storage_write_async_dep( | ||
243 | /* Handle to the device of interest */ | ||
244 | cy_as_device_handle handle, | ||
245 | /* The type of media to access */ | ||
246 | cy_as_media_type type, | ||
247 | /* The device to access */ | ||
248 | uint32_t device, | ||
249 | /* The unit to access */ | ||
250 | uint32_t unit, | ||
251 | /* The first block to access */ | ||
252 | uint32_t block, | ||
253 | /* The buffer where the data to be written is stored */ | ||
254 | void *data_p, | ||
255 | /* The number of blocks to be written */ | ||
256 | uint16_t num_blocks, | ||
257 | /* The function to call when the write is complete | ||
258 | or an error occurs */ | ||
259 | cy_as_storage_callback_dep callback | ||
260 | ); | ||
261 | |||
262 | EXTERN cy_as_return_status_t | ||
263 | cy_as_storage_sd_register_read_dep( | ||
264 | cy_as_device_handle handle, | ||
265 | cy_as_media_type type, | ||
266 | uint8_t device, | ||
267 | cy_as_sd_card_reg_type reg_type, | ||
268 | uint8_t read_len, | ||
269 | uint8_t *data_p | ||
270 | ); | ||
271 | |||
272 | EXTERN cy_as_return_status_t | ||
273 | cy_as_storage_sd_register_read_dep_EX( | ||
274 | /* Handle to the West Bridge device. */ | ||
275 | cy_as_device_handle handle, | ||
276 | /* The type of media to query */ | ||
277 | cy_as_media_type type, | ||
278 | /* The device to query */ | ||
279 | uint8_t device, | ||
280 | /* The type of register to read. */ | ||
281 | cy_as_sd_card_reg_type reg_type, | ||
282 | /* Output data buffer and length. */ | ||
283 | cy_as_storage_sd_reg_read_data *data_p, | ||
284 | /* Callback function to call when done. */ | ||
285 | cy_as_function_callback cb, | ||
286 | /* Call context to send to the cb function. */ | ||
287 | uint32_t client | ||
288 | ); | ||
289 | |||
290 | EXTERN cy_as_return_status_t | ||
291 | cy_as_storage_create_p_partition_dep( | ||
292 | cy_as_device_handle handle, | ||
293 | cy_as_media_type media, | ||
294 | uint32_t device, | ||
295 | uint32_t size, | ||
296 | cy_as_function_callback cb, | ||
297 | uint32_t client); | ||
298 | |||
299 | EXTERN cy_as_return_status_t | ||
300 | cy_as_storage_remove_p_partition_dep( | ||
301 | cy_as_device_handle handle, | ||
302 | cy_as_media_type media, | ||
303 | uint32_t device, | ||
304 | cy_as_function_callback cb, | ||
305 | uint32_t client); | ||
306 | |||
307 | #endif /*__doxygen*/ | ||
308 | |||
309 | #endif /*__INCLUDED_CYANSTORAGE_DEP_H__*/ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastoria.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastoria.h deleted file mode 100644 index b1b18d0685e4..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastoria.h +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyastioch.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASTORIA_H_ | ||
23 | #define _INCLUDED_CYASTORIA_H_ | ||
24 | |||
25 | #if !defined(__doxygen__) | ||
26 | |||
27 | #include "cyaserr.h" | ||
28 | #include "cyasmisc.h" | ||
29 | #include "cyasstorage.h" | ||
30 | #include "cyasusb.h" | ||
31 | #include "cyasmtp.h" | ||
32 | |||
33 | #endif | ||
34 | |||
35 | #endif | ||
36 | |||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastsdkversion.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastsdkversion.h deleted file mode 100644 index a3c10aa559e2..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastsdkversion.h +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | /* Cypress Astoria Sdk Version file (cyastsdkversion.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
18 | ## Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASTSDK_VERSION_H_ | ||
23 | #define _INCLUDED_CYASTSDK_VERSION_H_ | ||
24 | |||
25 | /* Astoria SDK version 1.2.1 */ | ||
26 | #define CYAS_MAJOR_VERSION (1) | ||
27 | #define CYAS_MINOR_VERSION (2) | ||
28 | #define CYAS_BUILD_NUMBER (197) | ||
29 | |||
30 | #endif /*_INCLUDED_CYASTSDK_VERSION_H_*/ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastypes.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastypes.h deleted file mode 100644 index 18043c1f38da..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyastypes.h +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyastypes.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASTYPES_H_ | ||
23 | #define _INCLUDED_CYASTYPES_H_ | ||
24 | /* moved to staging location, eventual implementation | ||
25 | * considered is here | ||
26 | #include <mach/westbridge/cyashaldef.h> | ||
27 | */ | ||
28 | #include "../../../arch/arm/plat-omap/include/mach/westbridge/cyashaldef.h" | ||
29 | |||
30 | /* Types that are not available on specific platforms. | ||
31 | * These are used only in the reference HAL implementations and | ||
32 | * are not required for using the API. | ||
33 | */ | ||
34 | #ifdef __unix__ | ||
35 | typedef unsigned long DWORD; | ||
36 | typedef void *LPVOID; | ||
37 | #define WINAPI | ||
38 | #define INFINITE (0xFFFFFFFF) | ||
39 | #define ptr_to_uint(ptr) ((unsigned int)(ptr)) | ||
40 | #endif | ||
41 | |||
42 | /* Basic types used by the entire API */ | ||
43 | |||
44 | /* Summary | ||
45 | This type represents an endpoint number | ||
46 | */ | ||
47 | typedef uint8_t cy_as_end_point_number_t; | ||
48 | |||
49 | /* Summary | ||
50 | This type is used to return status information from | ||
51 | an API call. | ||
52 | */ | ||
53 | typedef uint16_t cy_as_return_status_t; | ||
54 | |||
55 | /* Summary | ||
56 | This type represents a bus number | ||
57 | */ | ||
58 | typedef uint32_t cy_as_bus_number_t; | ||
59 | |||
60 | /* Summary | ||
61 | All APIs provided with this release are marked extern | ||
62 | through this definition. This definition can be changed | ||
63 | to meet the scope changes required in the user build | ||
64 | environment. | ||
65 | |||
66 | For example, this can be changed to __declspec(exportdll) | ||
67 | to enable exporting the API from a DLL. | ||
68 | */ | ||
69 | #define EXTERN extern | ||
70 | |||
71 | #endif | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb.h deleted file mode 100644 index e3ba9ca4c75f..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb.h +++ /dev/null | |||
@@ -1,1862 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasusb.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | #ifndef _INCLUDED_CYASUSB_H_ | ||
23 | #define _INCLUDED_CYASUSB_H_ | ||
24 | |||
25 | #include "cyasmisc.h" | ||
26 | |||
27 | #include "cyas_cplus_start.h" | ||
28 | |||
29 | /*@@Enumeration Model | ||
30 | Summary | ||
31 | The USB enumeration process is the process of communicating | ||
32 | to the USB host information | ||
33 | about the capabilities of the connected device. This | ||
34 | process is completed by servicing | ||
35 | requests for various types of descriptors. In the software | ||
36 | APIs described below, this | ||
37 | process is controlled in one of two ways. | ||
38 | |||
39 | Description | ||
40 | There are advantages to either type of enumeration | ||
41 | and this is why both models are supported. | ||
42 | P Port processor based enumeraton gives the P port | ||
43 | processor maximum control and flexibility | ||
44 | for providing USB configuration information. However, | ||
45 | this does require (near) real time data | ||
46 | responses from the P port processor during the enumeration | ||
47 | process. West Bridge based enumeration | ||
48 | requires no real time information from the P port processor, | ||
49 | ensuring the fastest possible | ||
50 | enumeration times. | ||
51 | |||
52 | * P Port Based Enumeration * | ||
53 | The first method for handling USB enumeration is for the | ||
54 | processor client to handle all | ||
55 | endpoint zero requests for descriptors. This mode is | ||
56 | configured by indicating to the API | ||
57 | that the processor wants to handle all endpoint zero | ||
58 | requests. This is done by setting | ||
59 | bit 0 in the end_point_mask to a 1. The processor uses | ||
60 | CyAsUsbReadDataAsync() to read the request and | ||
61 | CyAsUsbWriteDataAsync() to write the response. | ||
62 | |||
63 | * West Bridge Based Enumeration * | ||
64 | The second method for handling USB enumeration is the | ||
65 | configuration information method. | ||
66 | Before enabling a connection from the West Bridge device | ||
67 | to the USB connector, the P Port | ||
68 | processor sends information about the USB configuration to | ||
69 | West Bridge through the configuration | ||
70 | APIs. This information is stored within the West Bridge | ||
71 | device. When a USB cable is attached, | ||
72 | the West Bridge device then handles all descriptor requests | ||
73 | based on the stored information. | ||
74 | Note that this method of enumeration only supports a single | ||
75 | USB configuration. | ||
76 | |||
77 | In either model of enumeration, the processor client is | ||
78 | responsible for ensuring that | ||
79 | the system meets USB Chapter 9 compliance requirements. This | ||
80 | can be done by providing spec | ||
81 | compliant descriptors, and handling any setup packets that | ||
82 | are sent to the client | ||
83 | appropriately. | ||
84 | |||
85 | Mass storage class compliance will be ensured by the West | ||
86 | Bridge firmware when the mass | ||
87 | storage functionality is enabled. | ||
88 | */ | ||
89 | |||
90 | /*@@Endpoint Configuration | ||
91 | Summary | ||
92 | The West Bridge device has one 64-byte control endpoint, one | ||
93 | 64-byte low bandwidth endpoint, four bulk | ||
94 | endpoints dedicated for mass storage usage, and up to ten | ||
95 | bulk/interrupt/isochronous | ||
96 | endpoints that can be used for USB-to-Processor communication. | ||
97 | |||
98 | Description | ||
99 | The four storage endpoints (Endpoints 2, 4, 6 and 8) are | ||
100 | reserved for accessing storage | ||
101 | devices attached to West Bridge and are not available for use | ||
102 | by the processor. These are | ||
103 | used implicitly when using the storage API to read/write to | ||
104 | the storage media. | ||
105 | |||
106 | Endpoint 0 is the standard USB control pipe used for all | ||
107 | enumeration activity. Though | ||
108 | the endpoint buffer is not directly accessible from the | ||
109 | processor, read/write activity | ||
110 | can be performed on this endpoint through the API layers. | ||
111 | This endpoint is always | ||
112 | configured as a bi-directional control endpoint. | ||
113 | |||
114 | Endpoint 1 is a 64-byte endpoint that can be used for low | ||
115 | bandwidth bulk/interrupt | ||
116 | activity. The physical buffer is not accessible from the | ||
117 | processor, but can be read/written | ||
118 | through the API. As the data coming to this endpoint is | ||
119 | being handled through the | ||
120 | software layers, there can be loss of data if a read call | ||
121 | is not waiting when an OUT | ||
122 | packet arrives. | ||
123 | |||
124 | Endpoints 3, 5, 7, 9, 10, 11, 12, 13, 14 and 15 are ten | ||
125 | configurable endpoints | ||
126 | mapped to parts of a total 4 KB FIFO buffer space on the | ||
127 | West Bridge device. This 4 KB | ||
128 | physical buffer space is divided into up to four endpoints | ||
129 | called PEP1, PEP2, PEP3 and PEP4 | ||
130 | in this software document. There are multiple configurations | ||
131 | in which this buffer space | ||
132 | can be used, and the size and number of buffers available to | ||
133 | each physical endpoint | ||
134 | vary between these configurations. See the West Bridge PDD | ||
135 | for details on the buffer | ||
136 | orientation corresponding to each configuration. | ||
137 | |||
138 | * Note * | ||
139 | PEPs 1, 2, 3 and 4 are called Physical EP 3, 5, 7 and 9 in the | ||
140 | West Bridge PDD. The | ||
141 | sequential number scheme is used in the software to disambiguate | ||
142 | these from the logical | ||
143 | endpoint numbers, and also for convenience of array indexing. | ||
144 | */ | ||
145 | |||
146 | #if !defined(__doxygen__) | ||
147 | |||
148 | |||
149 | #endif | ||
150 | |||
151 | /* Summary | ||
152 | This constants defines the maximum size of a USB descriptor | ||
153 | when referenced via the CyAsUsbSetDescriptor or | ||
154 | CyAsUsbGetDescriptor functions. | ||
155 | |||
156 | See Also | ||
157 | * CyAsUsbSetDescriptor | ||
158 | * CyAsUsbGetDescriptor | ||
159 | */ | ||
160 | #define CY_AS_MAX_USB_DESCRIPTOR_SIZE (128) | ||
161 | |||
162 | /*************************************** | ||
163 | * West Bridge Types | ||
164 | ***************************************/ | ||
165 | |||
166 | |||
167 | /* Summary | ||
168 | This data structure is the data passed via the evdata paramater | ||
169 | on a usb event callback for the inquiry request. | ||
170 | |||
171 | Description | ||
172 | When a SCSI inquiry request arrives via the USB connection and | ||
173 | the P Port has asked | ||
174 | to receive inquiry requests, this request is forwarded to the | ||
175 | client via the USB | ||
176 | callback. This callback is called twice, once before the | ||
177 | inquiry data is forwarded | ||
178 | to the host (CyAsEventUsbInquiryBefore) and once after the | ||
179 | inquiry has been sent to the | ||
180 | USB host (CyAsEventUsbInquiryAfter). The evdata parameter | ||
181 | is a pointer to this data | ||
182 | structure. | ||
183 | |||
184 | *CyAsEventUsbInquiryBefore* | ||
185 | If the client just wishes to see the inquiry request and | ||
186 | associated data, then a simple | ||
187 | return from the callback will forward the inquiry response | ||
188 | to the USB host. If the | ||
189 | client wishes to change the data returned to the USB host, | ||
190 | the updated parameter must | ||
191 | be set to CyTrue and the memory area address by the data | ||
192 | parameter should be updated. | ||
193 | The data pointer can be changed to point to a new memory | ||
194 | area and the length field | ||
195 | changed to change the amount of data returned from the | ||
196 | inquiry request. Note that the | ||
197 | data area pointed to by the data parameter must remain | ||
198 | valid and the contents must | ||
199 | remain consistent until after the CyAsEventUsbInquiryAfter | ||
200 | event has occurred. THE LENGTH | ||
201 | MUST BE LESS THAN 192 BYTES OR THE CUSTOM INQUIRY RESPONSE | ||
202 | WILL NOT BE RETURNED. If the | ||
203 | length is too long, the default inquiry response will be | ||
204 | returned. | ||
205 | |||
206 | *CyAsEventUsbInquiryAfter* | ||
207 | If the client needs to free any data, this event signals that | ||
208 | the data associated with the inquiry is no longer needed. | ||
209 | |||
210 | See Also | ||
211 | * CyAsUsbEventCallback | ||
212 | * CyAsUsbRegisterCallback | ||
213 | */ | ||
214 | typedef struct cy_as_usb_inquiry_data { | ||
215 | /* The bus for the event */ | ||
216 | cy_as_bus_number_t bus; | ||
217 | /* The device the event */ | ||
218 | uint32_t device; | ||
219 | /* The EVPD bit from the SCSI INQUIRY request */ | ||
220 | uint8_t evpd; | ||
221 | /* The codepage in the inquiry request */ | ||
222 | uint8_t codepage; | ||
223 | /* This bool must be set to CyTrue indicate that the inquiry | ||
224 | data was changed */ | ||
225 | cy_bool updated; | ||
226 | /* The length of the data */ | ||
227 | uint16_t length; | ||
228 | /* The inquiry data */ | ||
229 | void *data; | ||
230 | } cy_as_usb_inquiry_data; | ||
231 | |||
232 | |||
233 | /* Summary | ||
234 | This data structure is the data passed via the evdata | ||
235 | parameter on a usb event | ||
236 | callback for the unknown mass storage request. | ||
237 | |||
238 | Description | ||
239 | When a SCSI request is made that the mass storage | ||
240 | firmware in West Bridge does not | ||
241 | know how to process, this request is passed to the | ||
242 | processor for handling via | ||
243 | the usb callback. This data structure is used to | ||
244 | pass the request and the | ||
245 | associated response. The user may set the status | ||
246 | to indicate the status of the | ||
247 | request. The status value is the bCSWStatus value | ||
248 | from the USB mass storage | ||
249 | Command Status Wrapper (0 = command passed, 1 = | ||
250 | command failed). If the status | ||
251 | is set to command failed (1), the sense information | ||
252 | should be set as well. For | ||
253 | more information about sense information, see the | ||
254 | USB mass storage specification | ||
255 | as well as the SCSI specifications for block devices. | ||
256 | By default the status is | ||
257 | initialized to 1 (failure) with a sense information | ||
258 | of 05h/20h/00h which | ||
259 | indicates INVALID COMMAND. | ||
260 | */ | ||
261 | typedef struct cy_as_usb_unknown_command_data { | ||
262 | /* The bus for the event */ | ||
263 | cy_as_bus_number_t bus; | ||
264 | /* The device for the event */ | ||
265 | uint32_t device; | ||
266 | |||
267 | uint16_t reqlen; | ||
268 | /* The request */ | ||
269 | void *request; | ||
270 | |||
271 | /* The returned status value for the command */ | ||
272 | uint8_t status; | ||
273 | /* If status is failed, the sense key */ | ||
274 | uint8_t key; | ||
275 | /* If status is failed, the additional sense code */ | ||
276 | uint8_t asc; | ||
277 | /* If status if failed, the additional sense code qualifier */ | ||
278 | uint8_t ascq; | ||
279 | } cy_as_usb_unknown_command_data; | ||
280 | |||
281 | |||
282 | /* Summary | ||
283 | This data structure is the data passed via the evdata | ||
284 | paramater on a usb event callback for the start/stop request. | ||
285 | |||
286 | Description | ||
287 | When a SCSI start stop request arrives via the USB connection | ||
288 | and the P Port has asked | ||
289 | |||
290 | See Also | ||
291 | * CyAsUsbEventCallback | ||
292 | * CyAsUsbRegisterCallback | ||
293 | */ | ||
294 | typedef struct cy_as_usb_start_stop_data { | ||
295 | /* The bus for the event */ | ||
296 | cy_as_bus_number_t bus; | ||
297 | /* The device for the event */ | ||
298 | uint32_t device; | ||
299 | /* CyTrue means start request, CyFalse means stop request */ | ||
300 | cy_bool start; | ||
301 | /* CyTrue means LoEj bit set, otherwise false */ | ||
302 | cy_bool loej; | ||
303 | } cy_as_usb_start_stop_data; | ||
304 | |||
305 | /* Summary | ||
306 | This data type is used to indicate which mass storage devices | ||
307 | are enumerated. | ||
308 | |||
309 | Description | ||
310 | |||
311 | See Also | ||
312 | * CyAsUsbEnumControl | ||
313 | * CyAsUsbSetEnumConfig | ||
314 | */ | ||
315 | typedef enum cy_as_usb_mass_storage_enum { | ||
316 | cy_as_usb_nand_enum = 0x01, | ||
317 | cy_as_usb_sd_enum = 0x02, | ||
318 | cy_as_usb_mmc_enum = 0x04, | ||
319 | cy_as_usb_ce_ata_enum = 0x08 | ||
320 | } cy_as_usb_mass_storage_enum; | ||
321 | |||
322 | /* Summary | ||
323 | This data type specifies the type of descriptor to transfer | ||
324 | to the West Bridge device | ||
325 | |||
326 | Description | ||
327 | During enumeration, if West Bridge is handling enumeration, | ||
328 | the West Bridge device needs to USB descriptors | ||
329 | to complete the enumeration. The function CyAsUsbSetDescriptor() | ||
330 | is used to transfer the descriptors | ||
331 | to the West Bridge device. This type is an argument to that | ||
332 | function and specifies which descriptor | ||
333 | is being transferred. | ||
334 | |||
335 | See Also | ||
336 | * CyAsUsbSetDescriptor | ||
337 | * CyAsUsbGetDescriptor | ||
338 | */ | ||
339 | typedef enum cy_as_usb_desc_type { | ||
340 | /* A device descriptor - See USB 2.0 specification Chapter 9 */ | ||
341 | cy_as_usb_desc_device = 1, | ||
342 | /* A device descriptor qualifier - | ||
343 | * See USB 2.0 specification Chapter 9 */ | ||
344 | cy_as_usb_desc_device_qual = 2, | ||
345 | /* A configuration descriptor for FS operation - | ||
346 | * See USB 2.0 specification Chapter 9 */ | ||
347 | cy_as_usb_desc_f_s_configuration = 3, | ||
348 | /* A configuration descriptor for HS operation - | ||
349 | * See USB 2.0 specification Chapter 9 */ | ||
350 | cy_as_usb_desc_h_s_configuration = 4, | ||
351 | cy_as_usb_desc_string = 5 | ||
352 | } cy_as_usb_desc_type; | ||
353 | |||
354 | /* Summary | ||
355 | This type specifies the direction of an endpoint | ||
356 | |||
357 | Description | ||
358 | This type is used when configuring the endpoint hardware | ||
359 | to specify the direction | ||
360 | of the endpoint. | ||
361 | |||
362 | See Also | ||
363 | * CyAsUsbEndPointConfig | ||
364 | * CyAsUsbSetEndPointConfig | ||
365 | * CyAsUsbGetEndPointConfig | ||
366 | */ | ||
367 | typedef enum cy_as_usb_end_point_dir { | ||
368 | /* The endpoint direction is IN (West Bridge -> USB Host) */ | ||
369 | cy_as_usb_in = 0, | ||
370 | /* The endpoint direction is OUT (USB Host -> West Bridge) */ | ||
371 | cy_as_usb_out = 1, | ||
372 | /* The endpoint direction is IN/OUT (valid only for EP 0 & 1) */ | ||
373 | cy_as_usb_in_out = 2 | ||
374 | } cy_as_usb_end_point_dir; | ||
375 | |||
376 | /* Summary | ||
377 | This type specifies the type of an endpoint | ||
378 | |||
379 | Description | ||
380 | This type is used when configuring the endpoint hardware | ||
381 | to specify the type of endpoint. | ||
382 | |||
383 | See Also | ||
384 | * CyAsUsbEndPointConfig | ||
385 | * CyAsUsbSetEndPointConfig | ||
386 | * CyAsUsbGetEndPointConfig | ||
387 | */ | ||
388 | typedef enum cy_as_usb_end_point_type { | ||
389 | cy_as_usb_control, | ||
390 | cy_as_usb_iso, | ||
391 | cy_as_usb_bulk, | ||
392 | cy_as_usb_int | ||
393 | } cy_as_usb_end_point_type; | ||
394 | |||
395 | /* Summary | ||
396 | This type is a structure used to indicate the top level | ||
397 | configuration of the USB stack | ||
398 | |||
399 | Description | ||
400 | In order to configure the USB stack, the CyAsUsbSetEnumConfig() | ||
401 | function is called to indicate | ||
402 | how mass storage is to be handled, the specific number of | ||
403 | interfaces to be supported if | ||
404 | West Bridge is handling enumeration, and the end points of | ||
405 | specifi interest. This structure | ||
406 | contains this information. | ||
407 | |||
408 | See Also | ||
409 | * CyAsUsbSetConfig | ||
410 | * CyAsUsbGetConfig | ||
411 | * <LINK Enumeration Model> | ||
412 | */ | ||
413 | typedef struct cy_as_usb_enum_control { | ||
414 | /* Designate which devices on which buses to enumerate */ | ||
415 | cy_bool devices_to_enumerate[CY_AS_MAX_BUSES] | ||
416 | [CY_AS_MAX_STORAGE_DEVICES]; | ||
417 | /* If true, West Bridge will control enumeration. If this | ||
418 | * is false the P port controls enumeration. if the P port | ||
419 | * is controlling enumeration, traffic will be received via | ||
420 | * endpoint zero. */ | ||
421 | cy_bool antioch_enumeration; | ||
422 | /* This is the interface # to use for the mass storage | ||
423 | * interface, if mass storage is enumerated. if mass | ||
424 | * storage is not enumerated this value should be zero. */ | ||
425 | uint8_t mass_storage_interface; | ||
426 | /* This is the interface # to use for the MTP interface, | ||
427 | * if MTP is enumerated. if MTP is not enumerated | ||
428 | * this value should be zero. */ | ||
429 | uint8_t mtp_interface; | ||
430 | /* If true, Inquiry, START/STOP, and unknown mass storage | ||
431 | * requests cause a callback to occur for handling by the | ||
432 | * baseband processor. */ | ||
433 | cy_bool mass_storage_callbacks; | ||
434 | } cy_as_usb_enum_control; | ||
435 | |||
436 | |||
437 | /* Summary | ||
438 | This structure is used to configure a single endpoint | ||
439 | |||
440 | Description | ||
441 | This data structure contains all of the information required | ||
442 | to configure the West Bridge hardware | ||
443 | associated with a given endpoint. | ||
444 | |||
445 | See Also | ||
446 | * CyAsUsbSetEndPointConfig | ||
447 | * CyAsUsbGetEndPointConfig | ||
448 | */ | ||
449 | typedef struct cy_as_usb_end_point_config { | ||
450 | /* If true, this endpoint is enabled */ | ||
451 | cy_bool enabled; | ||
452 | /* The direction of this endpoint */ | ||
453 | cy_as_usb_end_point_dir dir; | ||
454 | /* The type of endpoint */ | ||
455 | cy_as_usb_end_point_type type; | ||
456 | /* The physical endpoint #, 1, 2, 3, 4 */ | ||
457 | cy_as_end_point_number_t physical; | ||
458 | /* The size of the endpoint in bytes */ | ||
459 | uint16_t size; | ||
460 | } cy_as_usb_end_point_config; | ||
461 | |||
462 | /* Summary | ||
463 | List of partition enumeration combinations that can | ||
464 | be selected on a partitioned storage device. | ||
465 | |||
466 | Description | ||
467 | West Bridge firmware supports creating up to two | ||
468 | partitions on mass storage devices connected to | ||
469 | West Bridge. When there are two partitions on a device, | ||
470 | the user can choose which of these partitions should be | ||
471 | made visible to a USB host through the mass storage | ||
472 | interface. This enumeration lists the various enumeration | ||
473 | selections that can be made. | ||
474 | |||
475 | See Also | ||
476 | * CyAsStorageCreatePPartition | ||
477 | * CyAsStorageRemovePPartition | ||
478 | * CyAsUsbSelectMSPartitions | ||
479 | */ | ||
480 | typedef enum cy_as_usb_m_s_type_t { | ||
481 | /* Enumerate only partition 0 as CD (autorun) device */ | ||
482 | cy_as_usb_m_s_unit0 = 0, | ||
483 | /* Enumerate only partition 1 as MS device (default setting) */ | ||
484 | cy_as_usb_m_s_unit1, | ||
485 | /* Enumerate both units */ | ||
486 | cy_as_usb_m_s_both | ||
487 | } cy_as_usb_m_s_type_t; | ||
488 | |||
489 | /* Summary | ||
490 | This type specifies the type of USB event that has occurred | ||
491 | |||
492 | Description | ||
493 | This type is used in the USB event callback function to | ||
494 | indicate the type of USB event that has occurred. The callback | ||
495 | function includes both this reasons for the callback and a data | ||
496 | parameter associated with the reason. The data parameter is used | ||
497 | in a reason specific way and is documented below with each reason. | ||
498 | |||
499 | See Also | ||
500 | * CyAsUsbIoCallback | ||
501 | */ | ||
502 | typedef enum cy_as_usb_event { | ||
503 | /* This event is sent when West Bridge is put into the suspend | ||
504 | state by the USB host. the data parameter is not used and | ||
505 | will be zero. */ | ||
506 | cy_as_event_usb_suspend, | ||
507 | /* This event is sent when West Bridge is taken out of the | ||
508 | suspend state by the USB host. the data parameter is not | ||
509 | used and will be zero. */ | ||
510 | cy_as_event_usb_resume, | ||
511 | /* This event is sent when a USB reset request is received | ||
512 | by the west bridge device. the data parameter is not used and | ||
513 | will be zero. */ | ||
514 | cy_as_event_usb_reset, | ||
515 | /* This event is sent when a USB set configuration request is made. | ||
516 | the data parameter is a pointer to a uint16_t that contains the | ||
517 | configuration number. the configuration number may be zero to | ||
518 | indicate an unconfigure operation. */ | ||
519 | cy_as_event_usb_set_config, | ||
520 | /* This event is sent when the USB connection changes speed. This is | ||
521 | generally a transition from full speed to high speed. the parameter | ||
522 | to this event is a pointer to uint16_t that gives the speed of the | ||
523 | USB connection. zero indicates full speed, one indicates high speed */ | ||
524 | cy_as_event_usb_speed_change, | ||
525 | /* This event is sent when a setup packet is received. | ||
526 | * The data parameter is a pointer to the eight bytes of setup data. */ | ||
527 | cy_as_event_usb_setup_packet, | ||
528 | /* This event is sent when a status packet is received. The data | ||
529 | parameter is not used. */ | ||
530 | cy_as_event_usb_status_packet, | ||
531 | /* This event is sent when mass storage receives an inquiry | ||
532 | request and we have asked to see these requests. */ | ||
533 | cy_as_event_usb_inquiry_before, | ||
534 | /* This event is sent when mass storage has finished processing an | ||
535 | inquiry request and any data associated with the request is no longer | ||
536 | required. */ | ||
537 | cy_as_event_usb_inquiry_after, | ||
538 | /* This event is sent when mass storage receives a start/stop | ||
539 | * request and we have asked to see these requests */ | ||
540 | cy_as_event_usb_start_stop, | ||
541 | /* This event is sent when a Clear Feature request is received. | ||
542 | * The data parameter is the endpoint number. */ | ||
543 | cy_as_event_usb_clear_feature, | ||
544 | /* This event is sent when mass storage receives a request | ||
545 | * that is not known and we have asked to see these requests */ | ||
546 | cy_as_event_usb_unknown_storage, | ||
547 | /* This event is sent when the read/write activity on the USB mass | ||
548 | storage has crossed a pre-set level */ | ||
549 | cy_as_event_usb_m_s_c_progress | ||
550 | } cy_as_usb_event; | ||
551 | |||
552 | /* Summary | ||
553 | This type is the type of a callback function that is | ||
554 | called when a USB event occurs | ||
555 | |||
556 | Description | ||
557 | At times West Bridge needs to inform the P port processor | ||
558 | of events that have | ||
559 | occurred. These events are asynchronous to the thread of | ||
560 | control on the P | ||
561 | port processor and as such are generally delivered via a | ||
562 | callback function that | ||
563 | is called as part of an interrupt handler. This type | ||
564 | defines the type of function | ||
565 | that must be provided as a callback function for USB events. | ||
566 | |||
567 | See Also | ||
568 | * CyAsUsbEvent | ||
569 | */ | ||
570 | typedef void (*cy_as_usb_event_callback)( | ||
571 | /* Handle to the device to configure */ | ||
572 | cy_as_device_handle handle, | ||
573 | /* The event type being reported */ | ||
574 | cy_as_usb_event ev, | ||
575 | /* The data assocaited with the event being reported */ | ||
576 | void *evdata | ||
577 | ); | ||
578 | |||
579 | |||
580 | /* Summary | ||
581 | This type is the callback function called after an | ||
582 | asynchronous USB read/write operation | ||
583 | |||
584 | Description | ||
585 | This function type defines a callback function that is | ||
586 | called at the completion of any | ||
587 | asynchronous read or write operation. | ||
588 | |||
589 | See Also | ||
590 | * CyAsUsbReadDataAsync | ||
591 | * CyAsUsbWriteDataAsync | ||
592 | * CY_AS_ERROR_CANCELED | ||
593 | */ | ||
594 | typedef void (*cy_as_usb_io_callback)( | ||
595 | /* Handle to the device to configure */ | ||
596 | cy_as_device_handle handle, | ||
597 | /* The endpoint that has completed an operation */ | ||
598 | cy_as_end_point_number_t ep, | ||
599 | /* THe amount of data transferred to/from USB */ | ||
600 | uint32_t count, | ||
601 | /* The data buffer for the operation */ | ||
602 | void *buffer, | ||
603 | /* The error status of the operation */ | ||
604 | cy_as_return_status_t status | ||
605 | ); | ||
606 | |||
607 | /* Summary | ||
608 | This type is the callback function called after asynchronous | ||
609 | API functions have completed. | ||
610 | |||
611 | Description | ||
612 | When calling API functions from callback routines (interrupt | ||
613 | handlers usually) the async version of | ||
614 | these functions must be used. This callback is called when an | ||
615 | asynchronous API function has completed. | ||
616 | */ | ||
617 | typedef void (*cy_as_usb_function_callback)( | ||
618 | /* Handle to the device to configure */ | ||
619 | cy_as_device_handle handle, | ||
620 | /* The error status of the operation */ | ||
621 | cy_as_return_status_t status, | ||
622 | /* A client supplied 32 bit tag */ | ||
623 | uint32_t client | ||
624 | ); | ||
625 | |||
626 | |||
627 | /******************************************** | ||
628 | * West Bridge Functions | ||
629 | ********************************************/ | ||
630 | |||
631 | /* Summary | ||
632 | This function starts the USB stack | ||
633 | |||
634 | Description | ||
635 | This function initializes the West Bridge USB software | ||
636 | stack if it has not yet been stared. | ||
637 | This initializes any required data structures and powers | ||
638 | up any USB specific portions of | ||
639 | the West Bridge hardware. If the stack had already been | ||
640 | started, the USB stack reference count | ||
641 | is incremented. | ||
642 | |||
643 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
644 | * Nestable: YES | ||
645 | |||
646 | Notes | ||
647 | This function cannot be called from any type of West Bridge | ||
648 | callback. | ||
649 | |||
650 | Returns | ||
651 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
652 | * been configured | ||
653 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
654 | * into West Bridge | ||
655 | * CY_AS_ERROR_SUCCESS - the stack initialized and is ready | ||
656 | * for use | ||
657 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating | ||
658 | * with the West Bridge device | ||
659 | |||
660 | See Also | ||
661 | * CyAsUsbStop | ||
662 | */ | ||
663 | EXTERN cy_as_return_status_t | ||
664 | cy_as_usb_start( | ||
665 | /* Handle to the West Bridge device */ | ||
666 | cy_as_device_handle handle, | ||
667 | /* The callback if async call */ | ||
668 | cy_as_function_callback cb, | ||
669 | /* Client supplied data */ | ||
670 | uint32_t client | ||
671 | ); | ||
672 | |||
673 | /* Summary | ||
674 | This function stops the USB stack | ||
675 | |||
676 | Description | ||
677 | This function decrements the reference count for | ||
678 | the USB stack and if this count | ||
679 | is zero, the USB stack is shut down. The shutdown | ||
680 | frees all resources associated | ||
681 | with the USB stack. | ||
682 | |||
683 | * Valid In Asynchronous Callback: NO | ||
684 | |||
685 | Notes | ||
686 | While all resources associated with the USB stack will | ||
687 | be freed is a shutdown occurs, | ||
688 | resources associated with underlying layers of the software | ||
689 | will not be freed if they | ||
690 | are shared by the storage stack and the storage stack is active. | ||
691 | Specifically the DMA manager, | ||
692 | the interrupt manager, and the West Bridge communications module | ||
693 | are all shared by both the | ||
694 | USB stack and the storage stack. | ||
695 | |||
696 | Returns | ||
697 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
698 | * been configured | ||
699 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
700 | * into West Bridge | ||
701 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
702 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
703 | * the West Bridge device | ||
704 | |||
705 | See Also | ||
706 | * CyAsUsbStart | ||
707 | */ | ||
708 | EXTERN cy_as_return_status_t | ||
709 | cy_as_usb_stop( | ||
710 | /* Handle to the West Bridge device */ | ||
711 | cy_as_device_handle handle, | ||
712 | /* The callback if async call */ | ||
713 | cy_as_function_callback cb, | ||
714 | /* Client supplied data */ | ||
715 | uint32_t client | ||
716 | ); | ||
717 | |||
718 | /* Summary | ||
719 | This function registers a callback function to be called when an | ||
720 | asynchronous USB event occurs | ||
721 | |||
722 | Description | ||
723 | When asynchronous USB events occur, a callback function can be | ||
724 | called to alert the calling program. This | ||
725 | functions allows the calling program to register a callback. | ||
726 | |||
727 | * Valid In Asynchronous Callback: YES | ||
728 | */ | ||
729 | EXTERN cy_as_return_status_t | ||
730 | cy_as_usb_register_callback( | ||
731 | /* Handle to the West Bridge device */ | ||
732 | cy_as_device_handle handle, | ||
733 | /* The function to call */ | ||
734 | cy_as_usb_event_callback callback | ||
735 | ); | ||
736 | |||
737 | |||
738 | /* Summary | ||
739 | This function connects the West Bridge device D+ and D- signals | ||
740 | physically to the USB host. | ||
741 | |||
742 | Description | ||
743 | The West Bridge device has the ability to programmatically | ||
744 | disconnect the USB pins on the device | ||
745 | from the USB host. This feature allows for re-enumeration of | ||
746 | the West Bridge device as a different | ||
747 | device when necessary. This function connects the D+ and D- | ||
748 | signal physically to the USB host | ||
749 | if they have been previously disconnected. | ||
750 | |||
751 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
752 | * Nestable: YES | ||
753 | |||
754 | Returns | ||
755 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
756 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
757 | * been configured | ||
758 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
759 | * into West Bridge | ||
760 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
761 | * the West Bridge device | ||
762 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
763 | |||
764 | See Also | ||
765 | * CyAsUsbDisconnect | ||
766 | */ | ||
767 | EXTERN cy_as_return_status_t | ||
768 | cy_as_usb_connect( | ||
769 | /* Handle to the West Bridge device */ | ||
770 | cy_as_device_handle handle, | ||
771 | /* The callback if async call */ | ||
772 | cy_as_function_callback cb, | ||
773 | /* Client supplied data */ | ||
774 | uint32_t client | ||
775 | ); | ||
776 | |||
777 | /* Summary | ||
778 | This function disconnects the West Bridge device D+ and D- | ||
779 | signals physically from the USB host. | ||
780 | |||
781 | Description | ||
782 | The West Bridge device has the ability to programmatically | ||
783 | disconnect the USB pins on the device | ||
784 | from the USB host. This feature allows for re-enumeration | ||
785 | of the West Bridge device as a different | ||
786 | device when necessary. This function disconnects the D+ | ||
787 | and D- signal physically from the USB host | ||
788 | if they have been previously connected. | ||
789 | |||
790 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
791 | * Nestable: YES | ||
792 | |||
793 | Returns | ||
794 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
795 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
796 | * been configured | ||
797 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
798 | * into West Bridge | ||
799 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
800 | * the West Bridge device | ||
801 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
802 | |||
803 | See Also | ||
804 | * CyAsUsbConnect | ||
805 | */ | ||
806 | EXTERN cy_as_return_status_t | ||
807 | cy_as_usb_disconnect( | ||
808 | /* Handle to the West Bridge device */ | ||
809 | cy_as_device_handle handle, | ||
810 | /* The callback if async call */ | ||
811 | cy_as_function_callback cb, | ||
812 | /* Client supplied data */ | ||
813 | uint32_t client | ||
814 | ); | ||
815 | |||
816 | /* Summary | ||
817 | This function configures the USB stack | ||
818 | |||
819 | Description | ||
820 | This function is used to configure the USB stack. It is | ||
821 | used to indicate which endpoints are going to | ||
822 | be used, and how to deal with the mass storage USB device | ||
823 | within West Bridge. | ||
824 | |||
825 | * Valid In Asynchronous Callback: Yes (if cb supplied) | ||
826 | |||
827 | Returns | ||
828 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
829 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
830 | * been configured | ||
831 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
832 | * into West Bridge | ||
833 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
834 | * the West Bridge device | ||
835 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
836 | |||
837 | See Also | ||
838 | * CyAsUsbGetEnumConfig | ||
839 | * CyAsUsbEnumControl | ||
840 | */ | ||
841 | EXTERN cy_as_return_status_t | ||
842 | cy_as_usb_set_enum_config( | ||
843 | /* Handle to the West Bridge device */ | ||
844 | cy_as_device_handle handle, | ||
845 | /* The USB configuration information */ | ||
846 | cy_as_usb_enum_control *config_p, | ||
847 | /* The callback if async call */ | ||
848 | cy_as_function_callback cb, | ||
849 | /* Client supplied data */ | ||
850 | uint32_t client | ||
851 | ); | ||
852 | |||
853 | /* Summary | ||
854 | This function retreives the current configuration of | ||
855 | the USB stack | ||
856 | |||
857 | Description | ||
858 | This function sends a request to West Bridge to retrieve | ||
859 | the current configuration | ||
860 | |||
861 | * Valid In Asynchronous Callback: Yes (if cb supplied) | ||
862 | |||
863 | Returns | ||
864 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
865 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
866 | * been configured | ||
867 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
868 | * into West Bridge | ||
869 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
870 | * the West Bridge device | ||
871 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
872 | |||
873 | See Also | ||
874 | * CyAsUsbSetConfig | ||
875 | * CyAsUsbConfig | ||
876 | */ | ||
877 | EXTERN cy_as_return_status_t | ||
878 | cy_as_usb_get_enum_config( | ||
879 | /* Handle to the West Bridge device */ | ||
880 | cy_as_device_handle handle, | ||
881 | /* The return value for USB congifuration information */ | ||
882 | cy_as_usb_enum_control *config_p, | ||
883 | /* The callback if async call */ | ||
884 | cy_as_function_callback cb, | ||
885 | /* Client supplied data */ | ||
886 | uint32_t client | ||
887 | ); | ||
888 | |||
889 | /* Summary | ||
890 | This function sets the USB descriptor | ||
891 | |||
892 | Description | ||
893 | This function is used to set the various descriptors | ||
894 | assocaited with the USB enumeration | ||
895 | process. This function should only be called when the | ||
896 | West Bridge enumeration model is selected. | ||
897 | Descriptors set using this function can be cleared by | ||
898 | stopping the USB stack, or by calling | ||
899 | the CyAsUsbClearDescriptors function. | ||
900 | |||
901 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
902 | * Nestable: YES | ||
903 | |||
904 | Notes | ||
905 | These descriptors are described in the USB 2.0 specification, | ||
906 | Chapter 9. | ||
907 | |||
908 | Returns | ||
909 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
910 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
911 | * been configured | ||
912 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
913 | * into West Bridge | ||
914 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
915 | * the West Bridge device | ||
916 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
917 | * CY_AS_ERROR_INVALID_DESCRIPTOR - the descriptor passed is | ||
918 | * not valid | ||
919 | * CY_AS_ERROR_BAD_INDEX - a bad index was given for the type | ||
920 | * of descriptor given | ||
921 | * CY_AS_ERROR_BAD_ENUMERATION_MODE - this function cannot be | ||
922 | * called if the P port processor doing enumeration | ||
923 | |||
924 | See Also | ||
925 | * CyAsUsbGetDescriptor | ||
926 | * CyAsUsbClearDescriptors | ||
927 | * <LINK Enumeration Model> | ||
928 | */ | ||
929 | EXTERN cy_as_return_status_t | ||
930 | cy_as_usb_set_descriptor( | ||
931 | /* Handle to the West Bridge device */ | ||
932 | cy_as_device_handle handle, | ||
933 | /* The type of descriptor */ | ||
934 | cy_as_usb_desc_type type, | ||
935 | /* Only valid for string descriptors */ | ||
936 | uint8_t index, | ||
937 | /* The descriptor to be transferred */ | ||
938 | void *desc_p, | ||
939 | /* The length of the descriptor in bytes */ | ||
940 | uint16_t length, | ||
941 | /* The callback if async call */ | ||
942 | cy_as_function_callback cb, | ||
943 | /* Client supplied data */ | ||
944 | uint32_t client | ||
945 | ); | ||
946 | |||
947 | /* Summary | ||
948 | This function clears all user descriptors stored | ||
949 | on the West Bridge. | ||
950 | |||
951 | Description | ||
952 | This function is used to clear all descriptors that | ||
953 | were previously | ||
954 | stored on the West Bridge through CyAsUsbSetDescriptor | ||
955 | calls, and go back | ||
956 | to the default descriptor setup in the firmware. This | ||
957 | function should | ||
958 | only be called when the Antioch enumeration model is | ||
959 | selected. | ||
960 | |||
961 | * Valid In Asynchronous Callback: Yes (if cb supplied) | ||
962 | * Nestable: Yes | ||
963 | |||
964 | Returns | ||
965 | * CY_AS_ERROR_SUCCESS - all descriptors cleared successfully | ||
966 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
967 | * been configured | ||
968 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
969 | * into West Bridge | ||
970 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
971 | * the West Bridge device | ||
972 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
973 | * CY_AS_ERROR_BAD_ENUMERATION_MODE - this function cannot be | ||
974 | * called if the P port processor is doing enumeration | ||
975 | |||
976 | See Also | ||
977 | * CyAsUsbSetDescriptor | ||
978 | * <LINK Enumeration Model> | ||
979 | */ | ||
980 | EXTERN cy_as_return_status_t | ||
981 | cy_as_usb_clear_descriptors( | ||
982 | /* Handle to the West Bridge device */ | ||
983 | cy_as_device_handle handle, | ||
984 | /* The callback if async call */ | ||
985 | cy_as_function_callback cb, | ||
986 | /* Client supplied data */ | ||
987 | uint32_t client | ||
988 | ); | ||
989 | /* Summary | ||
990 | This structure contains the descriptor buffer to be | ||
991 | filled by CyAsUsbGetDescriptor API. | ||
992 | |||
993 | Description | ||
994 | This data structure the buffer to hold the descriptor | ||
995 | data, and an in/out parameter ti indicate the | ||
996 | length of the buffer and descriptor data in bytes. | ||
997 | |||
998 | See Also | ||
999 | * CyAsUsbGetDescriptor | ||
1000 | */ | ||
1001 | typedef struct cy_as_get_descriptor_data { | ||
1002 | /* The buffer to hold the returned descriptor */ | ||
1003 | void *desc_p; | ||
1004 | /* This is an input and output parameter. | ||
1005 | * Before the code this pointer points to a uint32_t | ||
1006 | * that contains the length of the buffer. after | ||
1007 | * the call, this value contains the amount of data | ||
1008 | * actually returned. */ | ||
1009 | uint32_t length; | ||
1010 | |||
1011 | } cy_as_get_descriptor_data; | ||
1012 | |||
1013 | /* Summary | ||
1014 | This function retreives a given descriptor from the | ||
1015 | West Bridge device | ||
1016 | |||
1017 | Description | ||
1018 | This function retreives a USB descriptor from the West | ||
1019 | Bridge device. This function should only be called when the | ||
1020 | West Bridge enumeration model is selected. | ||
1021 | |||
1022 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1023 | * Nestable: YES | ||
1024 | |||
1025 | Notes | ||
1026 | These descriptors are described in the USB 2.0 specification, | ||
1027 | Chapter 9. | ||
1028 | |||
1029 | Returns | ||
1030 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1031 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1032 | * been configured | ||
1033 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1034 | * into West Bridge | ||
1035 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1036 | * the West Bridge device | ||
1037 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1038 | * CY_AS_ERROR_BAD_INDEX - a bad index was given for the type of | ||
1039 | * descriptor given | ||
1040 | * CY_AS_ERROR_BAD_ENUMERATION_MODE - this function cannot be | ||
1041 | * called if the P port processor doing enumeration | ||
1042 | |||
1043 | See Also | ||
1044 | * CyAsUsbSetDescriptor | ||
1045 | * <LINK Enumeration Model> | ||
1046 | */ | ||
1047 | |||
1048 | EXTERN cy_as_return_status_t | ||
1049 | cy_as_usb_get_descriptor( | ||
1050 | /* Handle to the West Bridge device */ | ||
1051 | cy_as_device_handle handle, | ||
1052 | /* The type of descriptor */ | ||
1053 | cy_as_usb_desc_type type, | ||
1054 | /* Index for string descriptor */ | ||
1055 | uint8_t index, | ||
1056 | /* Parameters and return value for the get descriptor call */ | ||
1057 | cy_as_get_descriptor_data *data, | ||
1058 | /* The callback if async call */ | ||
1059 | cy_as_function_callback cb, | ||
1060 | /* Client supplied data */ | ||
1061 | uint32_t client | ||
1062 | ); | ||
1063 | |||
1064 | /* Summary | ||
1065 | This function sets the configuration of the physical | ||
1066 | endpoints into one of the twelve supported configuration | ||
1067 | |||
1068 | Description | ||
1069 | USB endpoints are mapped onto one of four physical | ||
1070 | endpoints in the device. Therefore | ||
1071 | USB endpoints are known as logical endpoints and these | ||
1072 | logical endpoints are mapped to | ||
1073 | one of four physical endpoints. In support of these | ||
1074 | four physical endpoints there is | ||
1075 | four kilo-bytes of buffer spaces that can be used as | ||
1076 | buffers for these physical endpoints. | ||
1077 | This 4K of buffer space can be configured in one of | ||
1078 | twelve ways. This function sets the | ||
1079 | buffer configuration for the physical endpoints. | ||
1080 | |||
1081 | * Config 1: PEP1 (2 * 512), PEP2 (2 * 512), | ||
1082 | * PEP3 (2 * 512), PEP4 (2 * 512) | ||
1083 | * Config 2: PEP1 (2 * 512), PEP2 (2 * 512), | ||
1084 | * PEP3 (4 * 512), PEP4 (N/A) | ||
1085 | * Config 3: PEP1 (2 * 512), PEP2 (2 * 512), | ||
1086 | * PEP3 (2 * 1024), PEP4(N/A) | ||
1087 | * Config 4: PEP1 (4 * 512), PEP2 (N/A), | ||
1088 | * PEP3 (2 * 512), PEP4 (2 * 512) | ||
1089 | * Config 5: PEP1 (4 * 512), PEP2 (N/A), | ||
1090 | * PEP3 (4 * 512), PEP4 (N/A) | ||
1091 | * Config 6: PEP1 (4 * 512), PEP2 (N/A), | ||
1092 | * PEP3 (2 * 1024), PEP4 (N/A) | ||
1093 | * Config 7: PEP1 (2 * 1024), PEP2 (N/A), | ||
1094 | * PEP3 (2 * 512), PEP4 (2 * 512) | ||
1095 | * Config 8: PEP1 (2 * 1024), PEP2 (N/A), | ||
1096 | * PEP3 (4 * 512), PEP4 (N/A) | ||
1097 | * Config 9: PEP1 (2 * 1024), PEP2 (N/A), | ||
1098 | * PEP3 (2 * 1024), PEP4 (N/A) | ||
1099 | * Config 10: PEP1 (3 * 512), PEP2 (N/A), | ||
1100 | * PEP3 (3 * 512), PEP4 (2 * 512) | ||
1101 | * Config 11: PEP1 (3 * 1024), PEP2 (N/A), | ||
1102 | * PEP3 (N/A), PEP4 (2 * 512) | ||
1103 | * Config 12: PEP1 (4 * 1024), PEP2 (N/A), | ||
1104 | * PEP3 (N/A), PEP4 (N/A) | ||
1105 | |||
1106 | * Valid In Asynchronous Callback: NO | ||
1107 | |||
1108 | Returns | ||
1109 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1110 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1111 | * been configured | ||
1112 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1113 | * into West Bridge | ||
1114 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1115 | * the West Bridge device | ||
1116 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1117 | * CY_AS_ERROR_INVALID_CONFIGURATION - the configuration given | ||
1118 | * is not between 1 and 12 | ||
1119 | */ | ||
1120 | EXTERN cy_as_return_status_t | ||
1121 | cy_as_usb_set_physical_configuration( | ||
1122 | /* Handle to the West Bridge device */ | ||
1123 | cy_as_device_handle handle, | ||
1124 | /* The physical endpoint configuration number */ | ||
1125 | uint8_t config | ||
1126 | ); | ||
1127 | |||
1128 | /* Summary | ||
1129 | This function sets the hardware configuration for a given endpoint | ||
1130 | |||
1131 | Description | ||
1132 | This function sets the hardware configuration for a given endpoint. | ||
1133 | This is the method to set the direction of the endpoint, the type | ||
1134 | of endpoint, the size of the endpoint buffer, and the buffering | ||
1135 | style for the endpoint. | ||
1136 | |||
1137 | * Valid In Asynchronous Callback: NO | ||
1138 | |||
1139 | Notes | ||
1140 | Add documentation about endpoint configuration limitations | ||
1141 | |||
1142 | Returns | ||
1143 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1144 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1145 | * been configured | ||
1146 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1147 | * into West Bridge | ||
1148 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1149 | * the West Bridge device | ||
1150 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1151 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is invalid | ||
1152 | * CY_AS_ERROR_INVALID_CONFIGURATION - the endpoint configuration | ||
1153 | * given is not valid | ||
1154 | * CY_AS_ERROR_ENDPOINT_CONFIG_NOT_SET - the physical endpoint | ||
1155 | * configuration is not set | ||
1156 | |||
1157 | See Also | ||
1158 | * CyAsUsbGetEndPointConfig | ||
1159 | * CyAsUsbEndPointConfig | ||
1160 | */ | ||
1161 | EXTERN cy_as_return_status_t | ||
1162 | cy_as_usb_set_end_point_config( | ||
1163 | /* Handle to the West Bridge device */ | ||
1164 | cy_as_device_handle handle, | ||
1165 | /* The endpoint of interest */ | ||
1166 | cy_as_end_point_number_t ep, | ||
1167 | /* The configuration information for the endpoint */ | ||
1168 | cy_as_usb_end_point_config *config_p | ||
1169 | ); | ||
1170 | |||
1171 | /* Summary | ||
1172 | This function retreives the hardware configuration for | ||
1173 | a given endpoint | ||
1174 | |||
1175 | Description | ||
1176 | This function gets the hardware configuration for the given | ||
1177 | endpoint. This include information about the direction of | ||
1178 | the endpoint, the type of endpoint, the size of the endpoint | ||
1179 | buffer, and the buffering style for the endpoint. | ||
1180 | |||
1181 | * Valid In Asynchronous Callback: NO | ||
1182 | |||
1183 | Returns | ||
1184 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1185 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1186 | * been configured | ||
1187 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1188 | * into West Bridge | ||
1189 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1190 | * the West Bridge device | ||
1191 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1192 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is | ||
1193 | * invalid | ||
1194 | |||
1195 | See Also | ||
1196 | * CyAsUsbSetEndPointConfig | ||
1197 | * CyAsUsbEndPointConfig | ||
1198 | */ | ||
1199 | EXTERN cy_as_return_status_t | ||
1200 | cy_as_usb_get_end_point_config( | ||
1201 | /* Handle to the West Bridge device */ | ||
1202 | cy_as_device_handle handle, | ||
1203 | /* The endpoint of interest*/ | ||
1204 | cy_as_end_point_number_t ep, | ||
1205 | /* The return value containing the endpoint config | ||
1206 | * information */ | ||
1207 | cy_as_usb_end_point_config *config_p | ||
1208 | ); | ||
1209 | |||
1210 | /* Summary | ||
1211 | This function commits the configuration information that | ||
1212 | has previously been set. | ||
1213 | |||
1214 | Description | ||
1215 | The initialization process involves calling CyAsUsbSetEnumConfig() | ||
1216 | and CyAsUsbSetEndPointConfig(). These | ||
1217 | functions do not actually send the configuration information to | ||
1218 | the West Bridge device. Instead, these | ||
1219 | functions store away the configuration information and this | ||
1220 | CyAsUsbCommitConfig() actually finds the | ||
1221 | best hardware configuration based on the requested endpoint | ||
1222 | configuration and sends this optimal | ||
1223 | confiuration down to the West Bridge device. | ||
1224 | |||
1225 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1226 | * Nestable: YES | ||
1227 | |||
1228 | Returns | ||
1229 | * CY_AS_ERROR_SUCCESS - a configuration was found and sent | ||
1230 | * to West Bridge | ||
1231 | * CY_AS_ERROR_NOT_CONFIGURED - the West Bridge device has not | ||
1232 | * been configured | ||
1233 | * CY_AS_ERROR_NO_FIRMWARE - the firmware has not been loaded | ||
1234 | * into West Bridge | ||
1235 | * CY_AS_ERROR_INVALID_CONFIGURATION - the configuration requested | ||
1236 | * is not possible | ||
1237 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1238 | * the West Bridge device | ||
1239 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1240 | |||
1241 | See Also | ||
1242 | * CyAsUsbSetEndPointConfig | ||
1243 | * CyAsUsbSetEnumConfig | ||
1244 | */ | ||
1245 | |||
1246 | EXTERN cy_as_return_status_t | ||
1247 | cy_as_usb_commit_config( | ||
1248 | /* Handle to the West Bridge device */ | ||
1249 | cy_as_device_handle handle, | ||
1250 | /* The callback if async call */ | ||
1251 | cy_as_function_callback cb, | ||
1252 | /* Client supplied data */ | ||
1253 | uint32_t client | ||
1254 | ); | ||
1255 | |||
1256 | /* Summary | ||
1257 | This function reads data from a USB endpoint. | ||
1258 | |||
1259 | Description | ||
1260 | This function reads data from an OUT. This function blocks | ||
1261 | until the read is complete. | ||
1262 | If this is a packet read, a single received USB packet will | ||
1263 | complete the read. If this | ||
1264 | is not a packet read, this function will block until all of | ||
1265 | the data requested has been | ||
1266 | recevied. | ||
1267 | |||
1268 | * Valid In Asynchronous Callback: NO | ||
1269 | |||
1270 | Returns | ||
1271 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1272 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1273 | * the West Bridge device | ||
1274 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1275 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is | ||
1276 | * invalid | ||
1277 | |||
1278 | See Also | ||
1279 | * CyAsUsbReadDataAsync | ||
1280 | * CyAsUsbWriteData | ||
1281 | * CyAsUsbWriteDataAsync | ||
1282 | */ | ||
1283 | EXTERN cy_as_return_status_t | ||
1284 | cy_as_usb_read_data( | ||
1285 | /* Handle to the West Bridge device */ | ||
1286 | cy_as_device_handle handle, | ||
1287 | /* The endpoint of interest */ | ||
1288 | cy_as_end_point_number_t ep, | ||
1289 | /* If CyTrue, this is a packet read */ | ||
1290 | cy_bool pktread, | ||
1291 | /* The amount of data to read */ | ||
1292 | uint32_t dsize, | ||
1293 | /* The amount of data read */ | ||
1294 | uint32_t *dataread, | ||
1295 | /* The buffer to hold the data read */ | ||
1296 | void *data | ||
1297 | ); | ||
1298 | |||
1299 | /* Summary | ||
1300 | This function reads data from a USB endpoint | ||
1301 | |||
1302 | Description | ||
1303 | This function reads data from an OUT endpoint. This | ||
1304 | function will return immediately and the callback | ||
1305 | provided will be called when the read is complete. | ||
1306 | If this is a packet read, then the callback will be | ||
1307 | called on the next received packet. If this is not a | ||
1308 | packet read, the callback will be called when the | ||
1309 | requested data is received. | ||
1310 | |||
1311 | * Valid In Asynchronous Callback: YES | ||
1312 | |||
1313 | Returns | ||
1314 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1315 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1316 | * the West Bridge device | ||
1317 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1318 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is | ||
1319 | * invalid | ||
1320 | |||
1321 | See Also | ||
1322 | * CyAsUsbReadData | ||
1323 | * CyAsUsbWriteData | ||
1324 | * CyAsUsbWriteDataAsync | ||
1325 | */ | ||
1326 | EXTERN cy_as_return_status_t | ||
1327 | cy_as_usb_read_data_async( | ||
1328 | /* Handle to the West Bridge device */ | ||
1329 | cy_as_device_handle handle, | ||
1330 | /* The endpoint of interest */ | ||
1331 | cy_as_end_point_number_t ep, | ||
1332 | /* If CyTrue, this is a packet read */ | ||
1333 | cy_bool pktread, | ||
1334 | /* The amount of data to read */ | ||
1335 | uint32_t dsize, | ||
1336 | /* The buffer for storing the data */ | ||
1337 | void *data, | ||
1338 | /* The callback function to call when the data is read */ | ||
1339 | cy_as_usb_io_callback callback | ||
1340 | ); | ||
1341 | |||
1342 | /* Summary | ||
1343 | This function writes data to a USB endpoint | ||
1344 | |||
1345 | Description | ||
1346 | This function writes data to an IN endpoint data buffer. | ||
1347 | Multiple USB packets may be sent until all data requeste | ||
1348 | has been sent. This function blocks until all of the data | ||
1349 | has been sent. | ||
1350 | |||
1351 | * Valid In Asynchronous Callback: NO | ||
1352 | |||
1353 | Notes | ||
1354 | Calling this function with a dsize of zero will result in | ||
1355 | a zero length packet transmitted to the USB host. | ||
1356 | |||
1357 | Returns | ||
1358 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1359 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1360 | * the West Bridge device | ||
1361 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1362 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is | ||
1363 | * invalid | ||
1364 | |||
1365 | See Also | ||
1366 | * CyAsUsbReadData | ||
1367 | * CyAsUsbReadDataAsync | ||
1368 | * CyAsUsbWriteDataAsync | ||
1369 | */ | ||
1370 | EXTERN cy_as_return_status_t | ||
1371 | cy_as_usb_write_data( | ||
1372 | /* Handle to the West Bridge device */ | ||
1373 | cy_as_device_handle handle, | ||
1374 | /* The endpoint to write data to */ | ||
1375 | cy_as_end_point_number_t ep, | ||
1376 | /* The size of the data to write */ | ||
1377 | uint32_t dsize, | ||
1378 | /* The data buffer */ | ||
1379 | void *data | ||
1380 | ); | ||
1381 | |||
1382 | /* Summary | ||
1383 | This function writes data to a USB endpoint | ||
1384 | |||
1385 | Description | ||
1386 | This function writes data to an IN endpoint data buffer. | ||
1387 | This function returns immediately and when the write | ||
1388 | completes, or if an error occurs, the callback function | ||
1389 | is called to indicate completion of the write operation. | ||
1390 | |||
1391 | * Valid In Asynchronous Callback: YES | ||
1392 | |||
1393 | Notes | ||
1394 | Calling this function with a dsize of zero will result | ||
1395 | in a zero length packet transmitted to the USB host. | ||
1396 | |||
1397 | Returns | ||
1398 | * CY_AS_ERROR_SUCCESS - this module was shut down successfully | ||
1399 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1400 | * the West Bridge device | ||
1401 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1402 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint parameter is | ||
1403 | * invalid | ||
1404 | |||
1405 | See Also | ||
1406 | * CyAsUsbReadData | ||
1407 | * CyAsUsbReadDataAsync | ||
1408 | * CyAsUsbWriteData | ||
1409 | */ | ||
1410 | EXTERN cy_as_return_status_t | ||
1411 | cy_as_usb_write_data_async( | ||
1412 | /* Handle to the West Bridge device */ | ||
1413 | cy_as_device_handle handle, | ||
1414 | /* The endpoint to write data to */ | ||
1415 | cy_as_end_point_number_t ep, | ||
1416 | /* The size of the data */ | ||
1417 | uint32_t dsize, | ||
1418 | /* The buffer containing the data */ | ||
1419 | void *data, | ||
1420 | /* If true, send a short packet to terminate data */ | ||
1421 | cy_bool spacket, | ||
1422 | /* The callback to call when the data is written */ | ||
1423 | cy_as_usb_io_callback callback | ||
1424 | ); | ||
1425 | |||
1426 | /* Summary | ||
1427 | This function aborts an outstanding asynchronous | ||
1428 | operation on a given endpoint | ||
1429 | |||
1430 | Description | ||
1431 | This function aborts any outstanding operation that is | ||
1432 | pending on the given endpoint. | ||
1433 | |||
1434 | * Valid In Asynchronous Callback: YES | ||
1435 | |||
1436 | Returns | ||
1437 | * CY_AS_ERROR_SUCCESS - this module was shut down | ||
1438 | * successfully | ||
1439 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not | ||
1440 | * running | ||
1441 | * CY_AS_ERROR_ASYNC_NOT_PENDING - no asynchronous USB | ||
1442 | * operation was pending | ||
1443 | |||
1444 | See Also | ||
1445 | * CyAsUsbReadData | ||
1446 | * CyAsUsbReadDataAsync | ||
1447 | * CyAsUsbWriteData | ||
1448 | * CyAsUsbWriteDataAsync | ||
1449 | */ | ||
1450 | EXTERN cy_as_return_status_t | ||
1451 | cy_as_usb_cancel_async( | ||
1452 | /* Handle to the West Bridge device */ | ||
1453 | cy_as_device_handle handle, | ||
1454 | /* The endpoint of interest */ | ||
1455 | cy_as_end_point_number_t ep | ||
1456 | ); | ||
1457 | |||
1458 | /* Summary | ||
1459 | This function sets a stall condition on a given endpoint | ||
1460 | |||
1461 | Description | ||
1462 | This function sets a stall condition on the given endpoint. | ||
1463 | If the callback function is not zero, the function is | ||
1464 | executed asynchronously and the callback is called when | ||
1465 | the function is completed. If the callback function is | ||
1466 | zero, this function executes synchronously and will not | ||
1467 | return until the function has completed. | ||
1468 | |||
1469 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1470 | * Nestable: YES | ||
1471 | |||
1472 | Returns | ||
1473 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1474 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1475 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was invalid, | ||
1476 | * or was not configured as an OUT endpoint | ||
1477 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1478 | * the West Bridge device | ||
1479 | * CY_AS_ERROR_INVALID_HANDLE | ||
1480 | * CY_AS_ERROR_INVALID_IN_CALLBACK (only if no cb supplied) | ||
1481 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1482 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1483 | |||
1484 | See Also | ||
1485 | * CyAsUsbGetStall | ||
1486 | * CyAsUsbClearStall | ||
1487 | */ | ||
1488 | EXTERN cy_as_return_status_t | ||
1489 | cy_as_usb_set_stall( | ||
1490 | /* Handle to the West Bridge device */ | ||
1491 | cy_as_device_handle handle, | ||
1492 | /* The endpoint of interest */ | ||
1493 | cy_as_end_point_number_t ep, | ||
1494 | /* The callback if async call */ | ||
1495 | cy_as_function_callback cb, | ||
1496 | /* Client supplied data */ | ||
1497 | uint32_t client | ||
1498 | ); | ||
1499 | |||
1500 | /* Summary | ||
1501 | This function clears a stall condition on a given endpoint | ||
1502 | |||
1503 | Description | ||
1504 | This function clears a stall condition on the given endpoint. | ||
1505 | If the callback function is not zero, the function is | ||
1506 | executed asynchronously and the callback is called when the | ||
1507 | function is completed. If the callback function is zero, this | ||
1508 | function executes synchronously and will not return until the | ||
1509 | function has completed. | ||
1510 | |||
1511 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1512 | * Nestable: YES | ||
1513 | |||
1514 | Returns | ||
1515 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1516 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1517 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was invalid, | ||
1518 | * or was not configured as an OUT endpoint | ||
1519 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1520 | * the West Bridge device | ||
1521 | * CY_AS_ERROR_INVALID_HANDLE | ||
1522 | * CY_AS_ERROR_INVALID_IN_CALLBACK (only if no cb supplied) | ||
1523 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1524 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1525 | |||
1526 | See Also | ||
1527 | * CyAsUsbGetStall | ||
1528 | * CyAsUsbSetStall | ||
1529 | */ | ||
1530 | |||
1531 | EXTERN cy_as_return_status_t | ||
1532 | cy_as_usb_clear_stall( | ||
1533 | /* Handle to the West Bridge device */ | ||
1534 | cy_as_device_handle handle, | ||
1535 | /* The endpoint of interest */ | ||
1536 | cy_as_end_point_number_t ep, | ||
1537 | /* The callback if async call */ | ||
1538 | cy_as_function_callback cb, | ||
1539 | /* Client supplied data */ | ||
1540 | uint32_t client | ||
1541 | ); | ||
1542 | |||
1543 | |||
1544 | /* Summary | ||
1545 | This function returns the stall status for a given endpoint | ||
1546 | |||
1547 | Description | ||
1548 | This function returns the stall status for a given endpoint | ||
1549 | |||
1550 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1551 | * Nestable: YES | ||
1552 | |||
1553 | Returns | ||
1554 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1555 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1556 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was invalid, | ||
1557 | * or was not configured as an OUT endpoint | ||
1558 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1559 | * the West Bridge device | ||
1560 | * CY_AS_ERROR_INVALID_HANDLE | ||
1561 | * CY_AS_ERROR_INVALID_IN_CALLBACK | ||
1562 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1563 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1564 | |||
1565 | See Also | ||
1566 | * CyAsUsbGetStall | ||
1567 | * CyAsUsbSetStall | ||
1568 | * CyAsUsbClearStall | ||
1569 | */ | ||
1570 | |||
1571 | EXTERN cy_as_return_status_t | ||
1572 | cy_as_usb_get_stall( | ||
1573 | /* Handle to the West Bridge device */ | ||
1574 | cy_as_device_handle handle, | ||
1575 | /* The endpoint of interest */ | ||
1576 | cy_as_end_point_number_t ep, | ||
1577 | /* The return value for the stall state */ | ||
1578 | cy_bool *stall_p, | ||
1579 | /* The callback if async call */ | ||
1580 | cy_as_function_callback cb, | ||
1581 | /* Client supplied data */ | ||
1582 | uint32_t client | ||
1583 | ); | ||
1584 | |||
1585 | /* Summary | ||
1586 | This function sets a NAK condition on a given endpoint | ||
1587 | |||
1588 | Description | ||
1589 | This function sets a NAK condition on the given endpoint. | ||
1590 | If the callback function is not zero, the function is | ||
1591 | executed asynchronously and the callback is called when | ||
1592 | the function is completed. If the callback function is | ||
1593 | zero, this function executes synchronously and will not | ||
1594 | return until the function has completed. | ||
1595 | |||
1596 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1597 | * Nestable: YES | ||
1598 | |||
1599 | Returns | ||
1600 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1601 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1602 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was | ||
1603 | * invalid, or was not configured as an OUT endpoint | ||
1604 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1605 | * the West Bridge device | ||
1606 | * CY_AS_ERROR_INVALID_HANDLE | ||
1607 | * CY_AS_ERROR_INVALID_IN_CALLBACK (only if no cb supplied) | ||
1608 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1609 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1610 | |||
1611 | See Also | ||
1612 | * CyAsUsbGetNak | ||
1613 | * CyAsUsbClearNak | ||
1614 | */ | ||
1615 | EXTERN cy_as_return_status_t | ||
1616 | cy_as_usb_set_nak( | ||
1617 | /* Handle to the West Bridge device */ | ||
1618 | cy_as_device_handle handle, | ||
1619 | /* The endpoint of interest */ | ||
1620 | cy_as_end_point_number_t ep, | ||
1621 | /* The callback if async call */ | ||
1622 | cy_as_function_callback cb, | ||
1623 | /* Client supplied data */ | ||
1624 | uint32_t client | ||
1625 | ); | ||
1626 | |||
1627 | /* Summary | ||
1628 | This function clears a NAK condition on a given endpoint | ||
1629 | |||
1630 | Description | ||
1631 | This function clears a NAK condition on the given endpoint. | ||
1632 | If the callback function is not zero, the function is | ||
1633 | executed asynchronously and the callback is called when the | ||
1634 | function is completed. If the callback function is zero, | ||
1635 | this function executes synchronously and will not return | ||
1636 | until the function has completed. | ||
1637 | |||
1638 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1639 | * Nestable: YES | ||
1640 | |||
1641 | Returns | ||
1642 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1643 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1644 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was invalid, | ||
1645 | * or was not configured as an OUT endpoint | ||
1646 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1647 | * the West Bridge device | ||
1648 | * CY_AS_ERROR_INVALID_HANDLE | ||
1649 | * CY_AS_ERROR_INVALID_IN_CALLBACK (only if no cb supplied) | ||
1650 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1651 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1652 | |||
1653 | See Also | ||
1654 | * CyAsUsbGetNak | ||
1655 | * CyAsUsbSetNak | ||
1656 | */ | ||
1657 | EXTERN cy_as_return_status_t | ||
1658 | cy_as_usb_clear_nak( | ||
1659 | /* Handle to the West Bridge device */ | ||
1660 | cy_as_device_handle handle, | ||
1661 | /* The endpoint of interest */ | ||
1662 | cy_as_end_point_number_t ep, | ||
1663 | /* The callback if async call */ | ||
1664 | cy_as_function_callback cb, | ||
1665 | /* Client supplied data */ | ||
1666 | uint32_t client | ||
1667 | ); | ||
1668 | |||
1669 | /* Summary | ||
1670 | This function returns the NAK status for a given endpoint | ||
1671 | |||
1672 | Description | ||
1673 | This function returns the NAK status for a given endpoint | ||
1674 | |||
1675 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1676 | * Nestable: YES | ||
1677 | |||
1678 | Returns | ||
1679 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1680 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1681 | * CY_AS_ERROR_INVALID_ENDPOINT - the endpoint given was invalid, | ||
1682 | * or was not configured as an OUT endpoint | ||
1683 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1684 | * the West Bridge device | ||
1685 | * CY_AS_ERROR_INVALID_HANDLE | ||
1686 | * CY_AS_ERROR_INVALID_IN_CALLBACK | ||
1687 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1688 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1689 | |||
1690 | See Also | ||
1691 | * CyAsUsbSetNak | ||
1692 | * CyAsUsbClearNak | ||
1693 | */ | ||
1694 | EXTERN cy_as_return_status_t | ||
1695 | cy_as_usb_get_nak( | ||
1696 | /* Handle to the West Bridge device */ | ||
1697 | cy_as_device_handle handle, | ||
1698 | /* The endpoint of interest */ | ||
1699 | cy_as_end_point_number_t ep, | ||
1700 | /* The return value for the stall state */ | ||
1701 | cy_bool *nak_p, | ||
1702 | /* The callback if async call */ | ||
1703 | cy_as_function_callback cb, | ||
1704 | /* Client supplied data */ | ||
1705 | uint32_t client | ||
1706 | ); | ||
1707 | |||
1708 | /* Summary | ||
1709 | This function triggers a USB remote wakeup from the Processor | ||
1710 | API | ||
1711 | |||
1712 | Description | ||
1713 | When there is a Suspend condition on the USB bus, this function | ||
1714 | programmatically takes the USB bus out of thi suspend state. | ||
1715 | |||
1716 | * Valid In Asynchronous Callback: YES (if cb supplied) | ||
1717 | * Nestable: YES | ||
1718 | |||
1719 | Returns | ||
1720 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1721 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1722 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1723 | * the West Bridge device | ||
1724 | * CY_AS_ERROR_INVALID_HANDLE | ||
1725 | * CY_AS_ERROR_INVALID_IN_CALLBACK | ||
1726 | * CY_AS_ERROR_OUT_OF_MEMORY | ||
1727 | * CY_AS_ERROR_INVALID_RESPONSE | ||
1728 | * CY_AS_ERROR_NOT_IN_SUSPEND | ||
1729 | |||
1730 | */ | ||
1731 | EXTERN cy_as_return_status_t | ||
1732 | cy_as_usb_signal_remote_wakeup( | ||
1733 | /* Handle to the West Bridge device */ | ||
1734 | cy_as_device_handle handle, | ||
1735 | /* The callback if async call */ | ||
1736 | cy_as_function_callback cb, | ||
1737 | /* Client supplied data */ | ||
1738 | uint32_t client | ||
1739 | ); | ||
1740 | |||
1741 | /* Summary | ||
1742 | This function sets the threshold levels for mass storage progress | ||
1743 | reports from the West Bridge. | ||
1744 | |||
1745 | Description | ||
1746 | The West Bridge firmware can be configured to track the amount of | ||
1747 | read/write activity on the mass storage device, and send progress | ||
1748 | reports when the activity level has crossed a threshold level. | ||
1749 | This function sets the threshold levels for the progress reports. | ||
1750 | Set wr_sectors and rd_sectors to 0, if the progress reports are to | ||
1751 | be turned off. | ||
1752 | |||
1753 | * Valid In Asynchronous Callback: Yes (if cb supplied) | ||
1754 | * Nestable: Yes | ||
1755 | |||
1756 | Returns | ||
1757 | * CY_AS_ERROR_SUCCESS - the function succeeded | ||
1758 | * CY_AS_ERROR_NOT_RUNNING - the USB stack is not running | ||
1759 | * CY_AS_ERROR_TIMEOUT - a timeout occurred communicating with | ||
1760 | * the West Bridge device | ||
1761 | * CY_AS_ERROR_INVALID_HANDLE - Bad handle | ||
1762 | * CY_AS_ERROR_INVALID_IN_CALLBACK - Synchronous call made | ||
1763 | * while in callback | ||
1764 | * CY_AS_ERROR_OUT_OF_MEMORY - Failed allocating memory for | ||
1765 | * request processing | ||
1766 | * CY_AS_ERROR_NOT_SUPPORTED - Firmware version does not support | ||
1767 | * mass storage progress tracking | ||
1768 | * CY_AS_ERROR_INVALID_RESPONSE - Unexpected response from | ||
1769 | * Firmware | ||
1770 | |||
1771 | See Also | ||
1772 | * CyAsUsbMSCProgressData | ||
1773 | * CyAsEventUsbMSCProgress | ||
1774 | */ | ||
1775 | EXTERN cy_as_return_status_t | ||
1776 | cy_as_usb_set_m_s_report_threshold( | ||
1777 | /* Handle to the West Bridge device */ | ||
1778 | cy_as_device_handle handle, | ||
1779 | /* Number of sectors written before report is sent */ | ||
1780 | uint32_t wr_sectors, | ||
1781 | /* Number of sectors read before report is sent */ | ||
1782 | uint32_t rd_sectors, | ||
1783 | /* The callback if async call */ | ||
1784 | cy_as_function_callback cb, | ||
1785 | /* Client supplied data */ | ||
1786 | uint32_t client | ||
1787 | ); | ||
1788 | |||
1789 | /* Summary | ||
1790 | Specify which of the partitions on a partitioned mass storage | ||
1791 | device should be made visible to USB. | ||
1792 | |||
1793 | Description | ||
1794 | West Bridge firmware supports the creation of up to two | ||
1795 | partitions on mass storage devices connected to the West Bridge | ||
1796 | device. When there are two partitions on a device, the user can | ||
1797 | choose which of these partitions should be made visible to the | ||
1798 | USB host through the USB mass storage interface. This function | ||
1799 | allows the user to configure the partitions that should be | ||
1800 | enumerated. At least one partition should be selected through | ||
1801 | this API. If neither partition needs to be enumerated, use | ||
1802 | CyAsUsbSetEnumConfig to control this. | ||
1803 | |||
1804 | * Valid in Asynchronous callback: Yes (if cb supplied) | ||
1805 | * Nestable: Yes | ||
1806 | |||
1807 | Returns | ||
1808 | * CY_AS_ERROR_SUCCESS - operation completed successfully | ||
1809 | * CY_AS_ERROR_INVALID_HANDLE - invalid handle to the West | ||
1810 | * Bridge device | ||
1811 | * CY_AS_ERROR_NOT_CONFIGURED - West Bridge device has not | ||
1812 | * been configured | ||
1813 | * CY_AS_ERROR_NO_FIRMWARE - no firmware running on West | ||
1814 | * Bridge device | ||
1815 | * CY_AS_ERROR_NOT_RUNNING - USB stack has not been started | ||
1816 | * CY_AS_ERROR_IN_SUSPEND - West Bridge device is in | ||
1817 | * suspend mode | ||
1818 | * CY_AS_ERROR_INVALID_CALL_SEQUENCE - this API has to be | ||
1819 | * called before CyAsUsbSetEnumConfig | ||
1820 | * CY_AS_ERROR_OUT_OF_MEMORY - failed to get memory to | ||
1821 | * process the request | ||
1822 | * CY_AS_ERROR_NO_SUCH_UNIT - Storage device addressed has | ||
1823 | * not been partitioned | ||
1824 | * CY_AS_ERROR_NOT_SUPPORTED - operation is not supported by | ||
1825 | * active device/firmware. | ||
1826 | |||
1827 | See Also | ||
1828 | * CyAsStorageCreatePPartition | ||
1829 | * CyAsStorageRemovePPartition | ||
1830 | * CyAsUsbMsType_t | ||
1831 | */ | ||
1832 | EXTERN cy_as_return_status_t | ||
1833 | cy_as_usb_select_m_s_partitions( | ||
1834 | /* Handle to the West Bridge device */ | ||
1835 | cy_as_device_handle handle, | ||
1836 | /* Bus index of the device being addressed */ | ||
1837 | cy_as_bus_number_t bus, | ||
1838 | /* Device id of the device being addressed */ | ||
1839 | uint32_t device, | ||
1840 | /* Selection of partitions to be enumerated */ | ||
1841 | cy_as_usb_m_s_type_t type, | ||
1842 | /* The callback, if async call */ | ||
1843 | cy_as_function_callback cb, | ||
1844 | /* Client supplied data */ | ||
1845 | uint32_t client | ||
1846 | ); | ||
1847 | |||
1848 | extern cy_as_media_type | ||
1849 | cy_as_storage_get_media_from_address(uint16_t v); | ||
1850 | |||
1851 | extern cy_as_bus_number_t | ||
1852 | cy_as_storage_get_bus_from_address(uint16_t v); | ||
1853 | |||
1854 | extern uint32_t | ||
1855 | cy_as_storage_get_device_from_address(uint16_t v); | ||
1856 | |||
1857 | /* For supporting deprecated functions */ | ||
1858 | #include "cyasusb_dep.h" | ||
1859 | |||
1860 | #include "cyas_cplus_end.h" | ||
1861 | |||
1862 | #endif /* _INCLUDED_CYASUSB_H_ */ | ||
diff --git a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb_dep.h b/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb_dep.h deleted file mode 100644 index 829eddee39b5..000000000000 --- a/drivers/staging/westbridge/astoria/include/linux/westbridge/cyasusb_dep.h +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* Cypress West Bridge API header file (cyasusb_dep.h) | ||
2 | ## =========================== | ||
3 | ## Copyright (C) 2010 Cypress Semiconductor | ||
4 | ## | ||
5 | ## This program is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License | ||
7 | ## as published by the Free Software Foundation; either version 2 | ||
8 | ## of the License, or (at your option) any later version. | ||
9 | ## | ||
10 | ## This program is distributed in the hope that it will be useful, | ||
11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | ## GNU General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with this program; if not, write to the Free Software | ||
17 | ## Foundation, Inc., 51 Franklin Street | ||
18 | ## Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | ## =========================== | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * This header will contain Antioch specific declaration | ||
24 | * of the APIs that are deprecated in Astoria SDK. This is | ||
25 | * for maintaining backward compatibility. | ||
26 | */ | ||
27 | |||
28 | #ifndef __INCLUDED_CYASUSB_DEP_H__ | ||
29 | #define __INCLUDED_CYASUSB_DEP_H__ | ||
30 | |||
31 | #ifndef __doxygen__ | ||
32 | |||
33 | /* | ||
34 | This data structure is the data passed via the evdata | ||
35 | paramater on a usb event callback for the inquiry request. | ||
36 | */ | ||
37 | |||
38 | typedef struct cy_as_usb_inquiry_data_dep { | ||
39 | /* The media for the event */ | ||
40 | cy_as_media_type media; | ||
41 | /* The EVPD bit from the SCSI INQUIRY request */ | ||
42 | uint8_t evpd; | ||
43 | /* The codepage in the inquiry request */ | ||
44 | uint8_t codepage; | ||
45 | /* This bool must be set to CyTrue indicate | ||
46 | * that the inquiry data was changed */ | ||
47 | cy_bool updated; | ||
48 | /* The length of the data */ | ||
49 | uint16_t length; | ||
50 | /* The inquiry data */ | ||
51 | void *data; | ||
52 | } cy_as_usb_inquiry_data_dep; | ||
53 | |||
54 | |||
55 | typedef struct cy_as_usb_unknown_command_data_dep { | ||
56 | /* The media for the event */ | ||
57 | cy_as_media_type media; | ||
58 | /* The length of the requst (should be 16 bytes) */ | ||
59 | uint16_t reqlen; | ||
60 | /* The request */ | ||
61 | void *request; | ||
62 | /* The returned status value for the command */ | ||
63 | uint8_t status; | ||
64 | /* If status is failed, the sense key */ | ||
65 | uint8_t key; | ||
66 | /* If status is failed, the additional sense code */ | ||
67 | uint8_t asc; | ||
68 | /* If status if failed, the additional sense code qualifier */ | ||
69 | uint8_t ascq; | ||
70 | } cy_as_usb_unknown_command_data_dep; | ||
71 | |||
72 | |||
73 | typedef struct cy_as_usb_start_stop_data_dep { | ||
74 | /* The media type for the event */ | ||
75 | cy_as_media_type media; | ||
76 | /* CyTrue means start request, CyFalse means stop request */ | ||
77 | cy_bool start; | ||
78 | /* CyTrue means LoEj bit set, otherwise false */ | ||
79 | cy_bool loej; | ||
80 | } cy_as_usb_start_stop_data_dep; | ||
81 | |||
82 | |||
83 | typedef struct cy_as_usb_enum_control_dep { | ||
84 | /* The bits in this member determine which mass storage devices | ||
85 | are enumerated. see cy_as_usb_mass_storage_enum for more details. */ | ||
86 | uint8_t enum_mass_storage; | ||
87 | /* If true, West Bridge will control enumeration. If this is false the | ||
88 | pport controls enumeration. if the P port is controlling | ||
89 | enumeration, traffic will be received via endpoint zero. */ | ||
90 | cy_bool antioch_enumeration; | ||
91 | /* This is the interface # to use for the mass storage interface, | ||
92 | if mass storage is enumerated. if mass storage is not enumerated | ||
93 | this value should be zero. */ | ||
94 | uint8_t mass_storage_interface; | ||
95 | /* If true, Inquiry, START/STOP, and unknown mass storage | ||
96 | requests cause a callback to occur for handling by the | ||
97 | baseband processor. */ | ||
98 | cy_bool mass_storage_callbacks; | ||
99 | } cy_as_usb_enum_control_dep; | ||
100 | |||
101 | |||
102 | typedef void (*cy_as_usb_event_callback_dep)( | ||
103 | /* Handle to the device to configure */ | ||
104 | cy_as_device_handle handle, | ||
105 | /* The event type being reported */ | ||
106 | cy_as_usb_event ev, | ||
107 | /* The data assocaited with the event being reported */ | ||
108 | void *evdata | ||
109 | ); | ||
110 | |||
111 | |||
112 | |||
113 | /* Register Callback api */ | ||
114 | EXTERN cy_as_return_status_t | ||
115 | cy_as_usb_register_callback_dep( | ||
116 | /* Handle to the West Bridge device */ | ||
117 | cy_as_device_handle handle, | ||
118 | /* The function to call */ | ||
119 | cy_as_usb_event_callback_dep callback | ||
120 | ); | ||
121 | |||
122 | |||
123 | extern cy_as_return_status_t | ||
124 | cy_as_usb_set_enum_config_dep( | ||
125 | /* Handle to the West Bridge device */ | ||
126 | cy_as_device_handle handle, | ||
127 | /* The USB configuration information */ | ||
128 | cy_as_usb_enum_control_dep *config_p, | ||
129 | /* The callback if async call */ | ||
130 | cy_as_function_callback cb, | ||
131 | /* Client supplied data */ | ||
132 | uint32_t client | ||
133 | ); | ||
134 | |||
135 | |||
136 | extern cy_as_return_status_t | ||
137 | cy_as_usb_get_enum_config_dep( | ||
138 | /* Handle to the West Bridge device */ | ||
139 | cy_as_device_handle handle, | ||
140 | /* The return value for USB congifuration information */ | ||
141 | cy_as_usb_enum_control_dep *config_p, | ||
142 | /* The callback if async call */ | ||
143 | cy_as_function_callback cb, | ||
144 | /* Client supplied data */ | ||
145 | uint32_t client | ||
146 | ); | ||
147 | |||
148 | extern cy_as_return_status_t | ||
149 | cy_as_usb_get_descriptor_dep( | ||
150 | /* Handle to the West Bridge device */ | ||
151 | cy_as_device_handle handle, | ||
152 | /* The type of descriptor */ | ||
153 | cy_as_usb_desc_type type, | ||
154 | /* Index for string descriptor */ | ||
155 | uint8_t index, | ||
156 | /* The buffer to hold the returned descriptor */ | ||
157 | void *desc_p, | ||
158 | /* This is an input and output parameter. Before the code this pointer | ||
159 | points to a uint32_t that contains the length of the buffer. after | ||
160 | the call, this value contains the amount of data actually returned. */ | ||
161 | uint32_t *length_p | ||
162 | ); | ||
163 | |||
164 | extern cy_as_return_status_t | ||
165 | cy_as_usb_set_stall_dep( | ||
166 | /* Handle to the West Bridge device */ | ||
167 | cy_as_device_handle handle, | ||
168 | /* The endpoint of interest */ | ||
169 | cy_as_end_point_number_t ep, | ||
170 | /* The callback if async call */ | ||
171 | cy_as_usb_function_callback cb, | ||
172 | /* Client supplied data */ | ||
173 | uint32_t client | ||
174 | ); | ||
175 | |||
176 | EXTERN cy_as_return_status_t | ||
177 | cy_as_usb_clear_stall_dep( | ||
178 | /* Handle to the West Bridge device */ | ||
179 | cy_as_device_handle handle, | ||
180 | /* The endpoint of interest */ | ||
181 | cy_as_end_point_number_t ep, | ||
182 | /* The callback if async call */ | ||
183 | cy_as_usb_function_callback cb, | ||
184 | /* Client supplied data */ | ||
185 | uint32_t client | ||
186 | ); | ||
187 | |||
188 | EXTERN cy_as_return_status_t | ||
189 | cy_as_usb_set_nak_dep( | ||
190 | /* Handle to the West Bridge device */ | ||
191 | cy_as_device_handle handle, | ||
192 | /* The endpoint of interest */ | ||
193 | cy_as_end_point_number_t ep, | ||
194 | /* The callback if async call */ | ||
195 | cy_as_usb_function_callback cb, | ||
196 | /* Client supplied data */ | ||
197 | uint32_t client | ||
198 | ); | ||
199 | |||
200 | EXTERN cy_as_return_status_t | ||
201 | cy_as_usb_clear_nak_dep( | ||
202 | /* Handle to the West Bridge device */ | ||
203 | cy_as_device_handle handle, | ||
204 | /* The endpoint of interest */ | ||
205 | cy_as_end_point_number_t ep, | ||
206 | /* The callback if async call */ | ||
207 | cy_as_usb_function_callback cb, | ||
208 | /* Client supplied data */ | ||
209 | uint32_t client | ||
210 | ); | ||
211 | |||
212 | EXTERN cy_as_return_status_t | ||
213 | cy_as_usb_select_m_s_partitions_dep( | ||
214 | cy_as_device_handle handle, | ||
215 | cy_as_media_type media, | ||
216 | uint32_t device, | ||
217 | cy_as_usb_m_s_type_t type, | ||
218 | cy_as_function_callback cb, | ||
219 | uint32_t client | ||
220 | ); | ||
221 | |||
222 | #endif /*__doxygen*/ | ||
223 | |||
224 | #endif /*__INCLUDED_CYANSTORAGE_DEP_H__*/ | ||