9 #include "usbfifo_api.h"
13 #define USB_EP4_MAX_PKT_SIZE bUSB_EP_MAX_PKT_SIZE_64
14 #define USB_EP3_MAX_PKT_SIZE bUSB_EP_MAX_PKT_SIZE_64
16 extern USB_FIFO_CONFIG usbFifoConf;
17 extern Action eUsbCxFinishAction;
19 void cold_reboot(void)
21 A_PRINTF("Cold reboot initiated.");
22 #if defined(PROJECT_MAGPIE)
23 HAL_WORD_REG_WRITE(WATCH_DOG_MAGIC_PATTERN_ADDR, 0);
24 #elif defined(PROJECT_K2)
25 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_STATUS_ADDR, 0);
26 #endif /* #if defined(PROJECT_MAGPIE) */
31 * support more than 64 bytes command on ep3
33 void usb_status_in_patch(void)
38 static uint16_t buf_len;
39 static VBUF *evntbuf = NULL;
40 static volatile uint32_t *regaddr;
41 static BOOLEAN cmd_is_new = TRUE;
42 BOOLEAN cmd_end = FALSE;
45 evntbuf = usbFifoConf.get_event_buf();
46 if (evntbuf != NULL) {
47 regaddr = (uint32_t *)VBUF_GET_DATA_ADDR(evntbuf);
48 buf_len = evntbuf->buf_length;
50 mUSB_STATUS_IN_INT_DISABLE();
57 if (buf_len > USB_EP3_MAX_PKT_SIZE) {
58 reg_buf_len = USB_EP3_MAX_PKT_SIZE;
59 buf_len -= USB_EP3_MAX_PKT_SIZE;
62 * controller supposed will take care of zero-length? */
64 reg_buf_len = buf_len;
69 for (count = 0; count < (reg_buf_len / 4); count++)
71 USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
75 remainder = reg_buf_len % 4;
80 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x7);
83 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x3);
86 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x1);
90 USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
92 /* Restore CBus FIFO size to word size */
93 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0xF);
98 if (evntbuf != NULL && cmd_end) {
99 usbFifoConf.send_event_done(evntbuf);
105 * support more than 64 bytes command on ep4
107 void usb_reg_out_patch(void)
112 static volatile uint32_t *regaddr;
113 static uint16_t cmd_len;
115 BOOLEAN cmd_is_last = FALSE;
116 static BOOLEAN cmd_is_new = TRUE;
118 /* get the size of this transcation */
119 usbfifolen = USB_BYTE_REG_READ(ZM_EP4_BYTE_COUNT_LOW_OFFSET);
121 if (usbfifolen > USB_EP4_MAX_PKT_SIZE) {
122 A_PRINTF("EP4 FIFO Bug? Buffer is too big: %x\n", usbfifolen);
126 /* check is command is new */
129 buf = usbFifoConf.get_command_buf();
133 A_PRINTF("%s: Filed to get new buffer.\n", __func__);
137 /* copy free, assignment buffer of the address */
138 regaddr = (uint32_t *)buf->desc_list->buf_addr;
143 /* just in case, suppose should not happen */
147 /* if size is smaller, this is the last command!
148 * zero-length supposed should be set through 0x27/bit7->0x19/bit4, not here
150 if(usbfifolen < USB_EP4_MAX_PKT_SIZE)
153 /* accumulate the size */
154 cmd_len += usbfifolen;
156 if (cmd_len > buf->desc_list->buf_size) {
157 A_PRINTF("%s: Data length on EP4 FIFO is bigger as "
158 "allocated buffer data! Drop it!\n", __func__);
162 /* round it to alignment */
164 usbfifolen = (usbfifolen >> 2) + 1;
166 usbfifolen = usbfifolen >> 2;
168 /* retrieve the data from fifo */
169 for(ii = 0; ii < usbfifolen; ii++) {
170 /* read fifo data out */
171 ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
176 /* if this is the last command, callback to HTC */
178 buf->desc_list->next_desc = NULL;
179 buf->desc_list->data_offset = 0;
180 buf->desc_list->data_size = cmd_len;
181 buf->desc_list->control = 0;
182 buf->next_buf = NULL;
183 buf->buf_length = cmd_len;
185 usbFifoConf.recv_command(buf);
192 /* we might get no command buffer here?
193 * but if we return here, the ep4 fifo will be lock out,
194 * so that we still read them out but just drop it? */
195 for(ii = 0; ii < usbfifolen; ii++)
196 ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
199 /* mUSB_STATUS_IN_INT_ENABLE(); */
206 * - theoretically ep6 configured same way as ep1
207 * so, if there are some problems we should have it
209 * - do we really need support usb1.1?
211 extern uint16_t u8UsbConfigValue;
212 extern uint16_t u8UsbInterfaceValue;
213 extern uint16_t u8UsbInterfaceAlternateSetting;
214 extern SetupPacket ControlCmd;
215 extern void vUsbClrEPx(void);
217 #undef FS_C1_I0_A0_EP_NUMBER
218 #define FS_C1_I0_A0_EP_NUMBER 6
220 #define FS_C1_I0_A0_EP6_BLKSIZE BLK512BYTE
221 #define FS_C1_I0_A0_EP6_BLKNO DOUBLE_BLK
222 #define FS_C1_I0_A0_EP6_DIRECTION DIRECTION_OUT
223 #define FS_C1_I0_A0_EP6_TYPE TF_TYPE_BULK
224 #define FS_C1_I0_A0_EP6_MAX_PACKET 0x0040
225 #define FS_C1_I0_A0_EP6_bInterval 0
228 #define FS_C1_I0_A0_EP6_FIFO_START \
229 (FS_C1_I0_A0_EP5_FIFO_START + FS_C1_I0_A0_EP5_FIFO_NO)
230 #define FS_C1_I0_A0_EP6_FIFO_NO \
231 (FS_C1_I0_A0_EP6_BLKNO * FS_C1_I0_A0_EP6_BLKSIZE)
232 #define FS_C1_I0_A0_EP6_FIFO_CONFIG \
233 (0x80 | ((FS_C1_I0_A0_EP6_BLKSIZE - 1) << 4) | \
234 ((FS_C1_I0_A0_EP6_BLKNO - 1) << 2) | FS_C1_I0_A0_EP6_TYPE)
235 #define FS_C1_I0_A0_EP6_FIFO_MAP \
236 (((1 - FS_C1_I0_A0_EP6_DIRECTION) << 4) | EP6)
237 #define FS_C1_I0_A0_EP6_MAP \
238 (FS_C1_I0_A0_EP6_FIFO_START | (FS_C1_I0_A0_EP6_FIFO_START << 4) | \
239 (MASK_F0 >> (4*FS_C1_I0_A0_EP6_DIRECTION)))
241 void vUSBFIFO_EP6Cfg_FS_patch(void)
243 #if (FS_C1_I0_A0_EP_NUMBER >= 6)
247 mUsbEPMap(EP6, FS_C1_I0_A0_EP6_MAP);
248 mUsbFIFOMap(FS_C1_I0_A0_EP6_FIFO_START, FS_C1_I0_A0_EP6_FIFO_MAP);
249 mUsbFIFOConfig(FS_C1_I0_A0_EP6_FIFO_START, FS_C1_I0_A0_EP6_FIFO_CONFIG);
251 for(i = FS_C1_I0_A0_EP6_FIFO_START + 1 ;
252 i < FS_C1_I0_A0_EP6_FIFO_START + FS_C1_I0_A0_EP6_FIFO_NO ; i ++)
254 mUsbFIFOConfig(i, (FS_C1_I0_A0_EP6_FIFO_CONFIG & (~BIT7)) );
257 mUsbEPMxPtSzHigh(EP6, FS_C1_I0_A0_EP6_DIRECTION,
258 (FS_C1_I0_A0_EP6_MAX_PACKET & 0x7ff));
259 mUsbEPMxPtSzLow(EP6, FS_C1_I0_A0_EP6_DIRECTION,
260 (FS_C1_I0_A0_EP6_MAX_PACKET & 0x7ff));
261 mUsbEPinHighBandSet(EP6, FS_C1_I0_A0_EP6_DIRECTION,
262 FS_C1_I0_A0_EP6_MAX_PACKET);
266 void vUsbFIFO_EPxCfg_FS_patch(void)
268 switch (u8UsbConfigValue)
270 #if (FS_CONFIGURATION_NUMBER >= 1)
271 /* Configuration 0X01 */
273 switch (u8UsbInterfaceValue)
275 #if (FS_C1_INTERFACE_NUMBER >= 1)
278 switch (u8UsbInterfaceAlternateSetting)
281 #if (FS_C1_I0_ALT_NUMBER >= 1)
282 /* AlternateSetting 0 */
287 /* patch up this ep6_fs config */
288 vUSBFIFO_EP6Cfg_FS_patch();
306 /* mCHECK_STACK(); */
309 BOOLEAN bSet_configuration_patch(void)
311 /* do some defaul configuration */
312 bSet_configuration();
314 /* overwrite defaul FIFO configuration for FullSpeed USB */
315 if ((mLOW_BYTE(mDEV_REQ_VALUE()) != 0) && !mUsbHighSpeedST())
316 vUsbFIFO_EPxCfg_FS_patch();
318 eUsbCxFinishAction = ACT_DONE;
322 extern BOOLEAN bStandardCommand(void);
324 BOOLEAN bStandardCommand_patch(void)
326 if (mDEV_REQ_REQ() == USB_SET_CONFIGURATION) {
329 #if ENABLE_SWAP_DATA_MODE
330 /* SWAP FUNCTION should be enabled while DMA engine
331 * is not working, the best place to enable it
332 * is before we trigger the DMA */
333 MAGPIE_REG_USB_RX0_SWAP_DATA = 0x1;
334 MAGPIE_REG_USB_TX0_SWAP_DATA = 0x1;
336 #if SYSTEM_MODULE_HP_EP5
337 MAGPIE_REG_USB_RX1_SWAP_DATA = 0x1;
340 #if SYSTEM_MODULE_HP_EP6
341 MAGPIE_REG_USB_RX2_SWAP_DATA = 0x1;
344 #endif /* ENABLE_SWAP_DATA_MODE */
347 return bStandardCommand();