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;
18 void cold_reboot(void)
20 A_PRINTF("Cold reboot initiated.");
21 #if defined(PROJECT_MAGPIE)
22 HAL_WORD_REG_WRITE(WATCH_DOG_MAGIC_PATTERN_ADDR, 0);
23 #elif defined(PROJECT_K2)
24 HAL_WORD_REG_WRITE(MAGPIE_REG_RST_STATUS_ADDR, 0);
25 #endif /* #if defined(PROJECT_MAGPIE) */
30 * support more than 64 bytes command on ep3
32 void usb_status_in_patch(void)
37 static uint16_t buf_len;
38 static VBUF *evntbuf = NULL;
39 static volatile uint32_t *regaddr;
40 static BOOLEAN cmd_is_new = TRUE;
41 BOOLEAN cmd_end = FALSE;
44 evntbuf = usbFifoConf.get_event_buf();
45 if (evntbuf != NULL) {
46 regaddr = (uint32_t *)VBUF_GET_DATA_ADDR(evntbuf);
47 buf_len = evntbuf->buf_length;
49 mUSB_STATUS_IN_INT_DISABLE();
56 if (buf_len > USB_EP3_MAX_PKT_SIZE) {
57 reg_buf_len = USB_EP3_MAX_PKT_SIZE;
58 buf_len -= USB_EP3_MAX_PKT_SIZE;
61 * controller supposed will take care of zero-length? */
63 reg_buf_len = buf_len;
68 for (count = 0; count < (reg_buf_len / 4); count++)
70 USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
74 remainder = reg_buf_len % 4;
79 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x7);
82 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x3);
85 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0x1);
89 USB_WORD_REG_WRITE(ZM_EP3_DATA_OFFSET, *regaddr);
91 /* Restore CBus FIFO size to word size */
92 USB_WORD_REG_WRITE(ZM_CBUS_FIFO_SIZE_OFFSET, 0xF);
97 if (evntbuf != NULL && cmd_end) {
98 usbFifoConf.send_event_done(evntbuf);
104 * support more than 64 bytes command on ep4
106 void usb_reg_out_patch(void)
111 static volatile uint32_t *regaddr;
112 static uint16_t cmd_len;
114 BOOLEAN cmd_is_last = FALSE;
115 static BOOLEAN cmd_is_new = TRUE;
117 /* get the size of this transcation */
118 usbfifolen = USB_BYTE_REG_READ(ZM_EP4_BYTE_COUNT_LOW_OFFSET);
120 if (usbfifolen > USB_EP4_MAX_PKT_SIZE) {
121 A_PRINTF("EP4 FIFO Bug? Buffer is too big: %x\n", usbfifolen);
125 /* check is command is new */
128 buf = usbFifoConf.get_command_buf();
132 A_PRINTF("%s: Filed to get new buffer.\n", __func__);
136 /* copy free, assignment buffer of the address */
137 regaddr = (uint32_t *)buf->desc_list->buf_addr;
142 /* just in case, suppose should not happen */
146 /* if size is smaller, this is the last command!
147 * zero-length supposed should be set through 0x27/bit7->0x19/bit4, not here
149 if(usbfifolen < USB_EP4_MAX_PKT_SIZE)
152 /* accumulate the size */
153 cmd_len += usbfifolen;
155 if (cmd_len > buf->desc_list->buf_size) {
156 A_PRINTF("%s: Data length on EP4 FIFO is bigger as "
157 "allocated buffer data! Drop it!\n", __func__);
161 /* round it to alignment */
163 usbfifolen = (usbfifolen >> 2) + 1;
165 usbfifolen = usbfifolen >> 2;
167 /* retrieve the data from fifo */
168 for(ii = 0; ii < usbfifolen; ii++) {
169 /* read fifo data out */
170 ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
175 /* if this is the last command, callback to HTC */
177 buf->desc_list->next_desc = NULL;
178 buf->desc_list->data_offset = 0;
179 buf->desc_list->data_size = cmd_len;
180 buf->desc_list->control = 0;
181 buf->next_buf = NULL;
182 buf->buf_length = cmd_len;
184 usbFifoConf.recv_command(buf);
191 /* we might get no command buffer here?
192 * but if we return here, the ep4 fifo will be lock out,
193 * so that we still read them out but just drop it? */
194 for(ii = 0; ii < usbfifolen; ii++)
195 ep4_data = USB_WORD_REG_READ(ZM_EP4_DATA_OFFSET);
198 /* mUSB_STATUS_IN_INT_ENABLE(); */