1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright © 2010 Tobias Diedrich
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "clock-target.h"
31 /*#define LOGF_ENABLE*/
37 #if defined(USE_ROCKBOX_USB)
39 #include "usb-drv-as3525.h"
41 static struct usb_endpoint endpoints
[USB_NUM_EPS
][2];
44 * dma/setup descriptors and buffers should avoid sharing
45 * a cacheline with other data.
46 * dmadescs may share with each other, since we only access them uncached.
48 static struct usb_dev_dma_desc dmadescs
[USB_NUM_EPS
][2] __attribute__((aligned(32)));
49 /* reuse unused EP2 OUT descriptor here */
50 static struct usb_dev_setup_buf
*setup_desc
= (void*)&dmadescs
[2][1];
52 #if AS3525_MCLK_SEL != AS3525_CLK_PLLB
53 static inline void usb_enable_pll(void)
55 CGU_COUNTB
= CGU_LOCK_CNT
;
56 CGU_PLLB
= AS3525_PLLB_SETTING
;
57 CGU_PLLBSUP
= 0; /* enable PLLB */
58 while(!(CGU_INTCTRL
& CGU_PLLB_LOCK
)); /* wait until PLLB is locked */
61 static inline void usb_disable_pll(void)
63 CGU_PLLBSUP
= CGU_PLL_POWERDOWN
;
66 static inline void usb_enable_pll(void)
70 static inline void usb_disable_pll(void)
73 #endif /* AS3525_MCLK_SEL != AS3525_CLK_PLLB */
80 /* delay is in milliseconds */
81 static inline void usb_delay(int delay
)
87 static void usb_phy_on(void)
90 CGU_USB
= 1<<5 /* enable */
91 | (CLK_DIV(AS3525_PLLB_FREQ
, 48000000) / 2) << 2
92 | 2; /* source = PLLB */
95 ascodec_write(AS3515_USB_UTIL
, ascodec_read(AS3515_USB_UTIL
) | (1<<4));
99 CCU_SRC
= CCU_SRC_USB_AHB_EN
|CCU_SRC_USB_PHY_EN
;
100 CCU_SRL
= CCU_SRL_MAGIC_NUMBER
;
102 CCU_SRC
= CCU_SRC_USB_AHB_EN
;
104 CCU_SRC
= CCU_SRL
= 0;
106 USB_GPIO_CSR
= USB_GPIO_TX_ENABLE_N
107 | USB_GPIO_TX_BIT_STUFF_EN
109 | USB_GPIO_CLK_SEL10
; /* 0x06180000; */
112 static void usb_phy_suspend(void)
114 USB_GPIO_CSR
|= USB_GPIO_ASESSVLD_EXT
|
115 USB_GPIO_BSESSVLD_EXT
|
116 USB_GPIO_VBUS_VLD_EXT
;
118 USB_GPIO_CSR
|= USB_GPIO_VBUS_VLD_EXT_SEL
;
122 static void usb_phy_resume(void)
124 USB_GPIO_CSR
&= ~(USB_GPIO_ASESSVLD_EXT
|
125 USB_GPIO_BSESSVLD_EXT
|
126 USB_GPIO_VBUS_VLD_EXT
);
128 USB_GPIO_CSR
&= ~USB_GPIO_VBUS_VLD_EXT_SEL
;
132 static void setup_desc_init(struct usb_dev_setup_buf
*desc
)
134 struct usb_dev_setup_buf
*uc_desc
= AS3525_UNCACHED_ADDR(desc
);
136 uc_desc
->status
= USB_DMA_DESC_BS_HST_RDY
;
137 uc_desc
->resv
= 0xffffffff;
138 uc_desc
->data1
= 0xffffffff;
139 uc_desc
->data2
= 0xffffffff;
142 static void dma_desc_init(int ep
, int dir
)
144 struct usb_dev_dma_desc
*desc
= &dmadescs
[ep
][dir
];
145 struct usb_dev_dma_desc
*uc_desc
= AS3525_UNCACHED_ADDR(desc
);
147 endpoints
[ep
][dir
].uc_desc
= uc_desc
;
149 uc_desc
->status
= USB_DMA_DESC_BS_DMA_DONE
| \
150 USB_DMA_DESC_LAST
| \
151 USB_DMA_DESC_ZERO_LEN
;
152 uc_desc
->resv
= 0xffffffff;
153 uc_desc
->data_ptr
= 0;
154 uc_desc
->next_desc
= 0;
157 static void reset_endpoints(int init
)
162 * OUT EP 2 is an alias for OUT EP 0 on this HW!
164 * Resonates with "3 bidirectional- plus 1 in-endpoints in device mode"
165 * from the datasheet, but why ep2 and not ep3?
167 * Reserve it here so we will skip over it in request_endpoint().
169 endpoints
[2][1].state
|= EP_STATE_ALLOCATED
;
171 for(i
= 0; i
< USB_NUM_EPS
; i
++) {
173 * LS: 8 (control), no bulk available
174 * FS: 64 (control), 64 (bulk)
175 * HS: 64 (control), 512 (bulk)
176 * TODO: switch depending on speed.
178 int mps
= i
== 0 ? 64 : 512;
181 endpoints
[i
][0].state
= 0;
182 wakeup_init(&endpoints
[i
][0].complete
);
184 if (i
!= 2) { /* Skip the OUT EP0 alias */
185 endpoints
[i
][1].state
= 0;
186 wakeup_init(&endpoints
[i
][1].complete
);
187 USB_OEP_SUP_PTR(i
) = 0;
192 USB_IEP_CTRL (i
) = USB_EP_CTRL_FLUSH
|USB_EP_CTRL_SNAK
;
193 USB_IEP_MPS (i
) = mps
; /* in bytes */
194 /* We don't care about the 'IN token received' event */
195 USB_IEP_STS_MASK(i
) = USB_EP_STAT_IN
; /* OF: 0x840 */
196 USB_IEP_TXFSIZE (i
) = mps
/2; /* in dwords => mps*2 bytes */
197 USB_IEP_STS (i
) = 0xffffffff; /* clear status */
198 USB_IEP_DESC_PTR(i
) = 0;
200 if (i
!= 2) { /* Skip the OUT EP0 alias */
202 USB_OEP_CTRL (i
) = USB_EP_CTRL_FLUSH
|USB_EP_CTRL_SNAK
;
203 USB_OEP_MPS (i
) = (mps
/2 << 23) | mps
;
204 USB_OEP_STS_MASK(i
) = 0x0000; /* OF: 0x1800 */
205 USB_OEP_RXFR (i
) = 0; /* Always 0 in OF trace? */
206 USB_OEP_STS (i
) = 0xffffffff; /* clear status */
207 USB_OEP_DESC_PTR(i
) = 0;
211 setup_desc_init(setup_desc
);
212 USB_OEP_SUP_PTR(0) = (int)setup_desc
;
215 void usb_drv_init(void)
217 logf("usb_drv_init() !!!!\n");
221 /* length regulator: normal operation */
222 ascodec_write(AS3514_CVDD_DCDC3
, ascodec_read(AS3514_CVDD_DCDC3
) | 1<<2);
225 CGU_PERI
|= CGU_USB_CLOCK_ENABLE
;
228 CCU_SRC
= CCU_SRC_USB_AHB_EN
;
229 CCU_SRL
= CCU_SRL_MAGIC_NUMBER
;
231 CCU_SRC
= CCU_SRL
= 0;
233 USB_GPIO_CSR
= USB_GPIO_TX_ENABLE_N
234 | USB_GPIO_TX_BIT_STUFF_EN
236 | USB_GPIO_CLK_SEL10
; /* 0x06180000; */
238 /* bug workaround according to linux patch */
239 USB_DEV_CFG
= (USB_DEV_CFG
& ~3) | 1; /* full speed */
241 /* enable soft disconnect */
242 USB_DEV_CTRL
|= USB_DEV_CTRL_SOFT_DISCONN
;
246 USB_DEV_CTRL
|= USB_DEV_CTRL_SOFT_DISCONN
;
248 /* We don't care about SVC or SOF events */
249 /* Right now we don't handle suspend, so mask those too */
250 USB_DEV_INTR_MASK
= USB_DEV_INTR_SVC
|
252 USB_DEV_INTR_USB_SUSPEND
|
253 USB_DEV_INTR_EARLY_SUSPEND
;
255 USB_DEV_CFG
= USB_DEV_CFG_STAT_ACK
|
256 USB_DEV_CFG_UNI_DIR
|
257 USB_DEV_CFG_PI_16BIT
|
259 USB_DEV_CFG_SELF_POWERED
|
260 USB_DEV_CFG_CSR_PRG
|
261 USB_DEV_CFG_PHY_ERR_DETECT
;
263 USB_DEV_CTRL
= USB_DEV_CTRL_BLEN_1DWORD
|
264 USB_DEV_CTRL_DESC_UPDATE
|
265 USB_DEV_CTRL_THRES_ENABLE
|
269 USB_DEV_EP_INTR_MASK
&= ~((1<<0) | (1<<16)); /* ep 0 */
273 /* clear pending interrupts */
274 USB_DEV_EP_INTR
= 0xffffffff;
275 USB_DEV_INTR
= 0xffffffff;
277 VIC_INT_ENABLE
= INTERRUPT_USB
;
280 USB_DEV_CTRL
&= ~USB_DEV_CTRL_SOFT_DISCONN
;
282 USB_GPIO_CSR
= USB_GPIO_TX_ENABLE_N
283 | USB_GPIO_TX_BIT_STUFF_EN
286 | USB_GPIO_CLK_SEL10
; /* 0x06180000; */
290 void usb_drv_exit(void)
292 USB_DEV_CTRL
|= (1<<10); /* soft disconnect */
294 * mask all interrupts _before_ writing to VIC_INT_EN_CLEAR,
295 * or else the core might latch the interrupt while
296 * the write ot VIC_INT_EN_CLEAR is in the pipeline and
297 * so cause a fake spurious interrupt.
299 USB_DEV_EP_INTR_MASK
= 0xffffffff;
300 USB_DEV_INTR_MASK
= 0xffffffff;
301 VIC_INT_EN_CLEAR
= INTERRUPT_USB
;
303 CGU_PERI
&= ~CGU_USB_CLOCK_ENABLE
;
304 /* Disable UVDD generating LDO */
305 ascodec_write(AS3515_USB_UTIL
, ascodec_read(AS3515_USB_UTIL
) & ~(1<<4));
307 logf("usb_drv_exit() !!!!\n");
310 int usb_drv_port_speed(void)
312 return (USB_DEV_STS
& USB_DEV_STS_MASK_SPD
) ? 0 : 1;
315 int usb_drv_request_endpoint(int type
, int dir
)
317 int d
= dir
== USB_DIR_IN
? 0 : 1;
318 int i
= 1; /* skip the control EP */
320 for(; i
< USB_NUM_EPS
; i
++) {
321 if (endpoints
[i
][d
].state
& EP_STATE_ALLOCATED
)
324 endpoints
[i
][d
].state
|= EP_STATE_ALLOCATED
;
326 if (dir
== USB_DIR_IN
) {
327 USB_IEP_CTRL(i
) = USB_EP_CTRL_FLUSH
|
331 USB_DEV_EP_INTR_MASK
&= ~(1<<i
);
333 USB_OEP_CTRL(i
) = USB_EP_CTRL_FLUSH
|
337 USB_DEV_EP_INTR_MASK
&= ~(1<<(16+i
));
339 /* logf("usb_drv_request_endpoint(%d, %d): returning %02x\n", type, dir, i | dir); */
343 logf("usb_drv_request_endpoint(%d, %d): no free endpoint found\n", type
, dir
);
347 void usb_drv_release_endpoint(int ep
)
350 int d
= ep
& USB_DIR_IN
? 0 : 1;
352 if (i
>= USB_NUM_EPS
)
355 * Check for control EP and ignore it.
356 * Unfortunately the usb core calls
357 * usb_drv_release_endpoint() for ep=0..(USB_NUM_ENDPOINTS-1),
358 * but doesn't request a new control EP after that...
360 if (i
== 0 || /* Don't mask control EP */
361 (i
== 2 && d
== 1)) /* See reset_endpoints(), EP2_OUT == EP0_OUT */
364 if (!(endpoints
[i
][d
].state
& EP_STATE_ALLOCATED
))
367 /* logf("usb_drv_release_endpoint(%d, %d)\n", i, d); */
368 endpoints
[i
][d
].state
= 0;
369 USB_DEV_EP_INTR_MASK
|= (1<<(16*d
+i
));
370 USB_EP_CTRL(i
, !d
) = USB_EP_CTRL_FLUSH
| USB_EP_CTRL_SNAK
;
373 void usb_drv_cancel_all_transfers(void)
375 logf("usb_drv_cancel_all_transfers()\n");
378 int flags
= disable_irq_save();
383 int usb_drv_recv(int ep
, void *ptr
, int len
)
385 struct usb_dev_dma_desc
*uc_desc
= endpoints
[ep
][1].uc_desc
;
388 logf("usb_drv_recv(%d,%x,%d)\n", ep
, (int)ptr
, len
);
391 logf("addr %08x not aligned!\n", (int)ptr
);
394 endpoints
[ep
][1].state
|= EP_STATE_BUSY
;
395 endpoints
[ep
][1].len
= len
;
396 endpoints
[ep
][1].rc
= -1;
398 /* remove data buffer from cache */
402 uc_desc
->status
= USB_DMA_DESC_BS_HST_RDY
|
406 uc_desc
->status
|= USB_DMA_DESC_ZERO_LEN
;
407 uc_desc
->data_ptr
= 0;
409 uc_desc
->data_ptr
= ptr
;
411 USB_OEP_DESC_PTR(ep
) = (int)&dmadescs
[ep
][1];
412 USB_OEP_STS(ep
) = USB_EP_STAT_OUT_RCVD
; /* clear status */
413 USB_OEP_CTRL(ep
) |= USB_EP_CTRL_CNAK
;
418 #if defined(LOGF_ENABLE)
419 static char hexbuf
[1025];
420 static char hextab
[16] = "0123456789abcdef";
422 char *make_hex(char *data
, int len
)
425 if (!((int)data
& 0x40000000))
426 data
= AS3525_UNCACHED_ADDR(data
); /* don't pollute the cache */
431 for (i
=0; i
<len
; i
++) {
432 hexbuf
[2*i
] = hextab
[(unsigned char)data
[i
] >> 4 ];
433 hexbuf
[2*i
+1] = hextab
[(unsigned char)data
[i
] & 0xf];
441 void ep_send(int ep
, void *ptr
, int len
)
443 struct usb_dev_dma_desc
*uc_desc
= endpoints
[ep
][0].uc_desc
;
445 endpoints
[ep
][0].state
|= EP_STATE_BUSY
;
446 endpoints
[ep
][0].len
= len
;
447 endpoints
[ep
][0].rc
= -1;
449 /* Make sure data is committed to memory */
452 logf("xx%s\n", make_hex(ptr
, len
));
454 uc_desc
->status
= USB_DMA_DESC_BS_HST_RDY
|
458 uc_desc
->status
|= USB_DMA_DESC_ZERO_LEN
;
460 uc_desc
->data_ptr
= ptr
;
462 USB_IEP_DESC_PTR(ep
) = (int)&dmadescs
[ep
][0];
463 USB_IEP_STS(ep
) = 0xffffffff; /* clear status */
465 USB_IEP_CTRL(ep
) |= USB_EP_CTRL_CNAK
| USB_EP_CTRL_PD
;
466 /* HW automatically sets NAK bit later */
469 int usb_drv_send(int ep
, void *ptr
, int len
)
471 logf("usb_drv_send(%d,%x,%d): ", ep
, (int)ptr
, len
);
474 ep_send(ep
, ptr
, len
);
475 while (endpoints
[ep
][0].state
& EP_STATE_BUSY
)
476 wakeup_wait(&endpoints
[ep
][0].complete
, TIMEOUT_BLOCK
);
478 return endpoints
[ep
][0].rc
;
481 int usb_drv_send_nonblocking(int ep
, void *ptr
, int len
)
483 logf("usb_drv_send_nonblocking(%d,%x,%d): ", ep
, (int)ptr
, len
);
485 endpoints
[ep
][0].state
|= EP_STATE_ASYNC
;
486 ep_send(ep
, ptr
, len
);
490 static void handle_in_ep(int ep
)
492 int ep_sts
= USB_IEP_STS(ep
) & ~USB_IEP_STS_MASK(ep
);
495 panicf("in_ep > 3?!");
497 USB_IEP_STS(ep
) = ep_sts
; /* ack */
499 if (ep_sts
& USB_EP_STAT_BNA
) { /* Buffer was not set up */
500 logf("ep%d IN, status %x (BNA)\n", ep
, ep_sts
);
501 panicf("ep%d IN 0x%x (BNA)", ep
, ep_sts
);
504 if (ep_sts
& USB_EP_STAT_TDC
) {
505 endpoints
[ep
][0].state
&= ~EP_STATE_BUSY
;
506 endpoints
[ep
][0].rc
= 0;
507 logf("EP%d %x %stx done len %x stat %08x\n",
508 ep
, ep_sts
, endpoints
[ep
][0].state
& EP_STATE_ASYNC
? "async " :"",
509 endpoints
[ep
][0].len
,
510 endpoints
[ep
][0].uc_desc
->status
);
511 if (endpoints
[ep
][0].state
& EP_STATE_ASYNC
) {
512 endpoints
[ep
][0].state
&= ~EP_STATE_ASYNC
;
513 usb_core_transfer_complete(ep
, USB_DIR_IN
, 0, endpoints
[ep
][0].len
);
515 wakeup_signal(&endpoints
[ep
][0].complete
);
517 ep_sts
&= ~USB_EP_STAT_TDC
;
521 logf("ep%d IN, hwstat %lx, epstat %x\n", ep
, USB_IEP_STS(ep
), endpoints
[ep
][0].state
);
522 panicf("ep%d IN 0x%x", ep
, ep_sts
);
525 /* HW automatically disables RDE, re-enable it */
526 /* But this an IN ep, I wonder... */
527 USB_DEV_CTRL
|= USB_DEV_CTRL_RDE
;
530 static void handle_out_ep(int ep
)
532 struct usb_ctrlrequest
*req
= (void*)AS3525_UNCACHED_ADDR(&setup_desc
->data1
);
533 int ep_sts
= USB_OEP_STS(ep
) & ~USB_OEP_STS_MASK(ep
);
534 struct usb_dev_dma_desc
*uc_desc
= endpoints
[ep
][1].uc_desc
;
537 panicf("out_ep > 3!?");
539 USB_OEP_STS(ep
) = ep_sts
; /* ACK */
541 if (ep_sts
& USB_EP_STAT_BNA
) { /* Buffer was not set up */
542 logf("ep%d OUT, status %x (BNA)\n", ep
, ep_sts
);
543 panicf("ep%d OUT 0x%x (BNA)", ep
, ep_sts
);
546 if (ep_sts
& USB_EP_STAT_OUT_RCVD
) {
547 int dma_sts
= uc_desc
->status
;
548 int dma_len
= dma_sts
& 0xffff;
550 if (!(dma_sts
& USB_DMA_DESC_ZERO_LEN
)) {
551 logf("EP%d OUT token, st:%08x len:%d frm:%x data=%s epstate=%d\n",
552 ep
, dma_sts
& 0xf8000000, dma_len
, (dma_sts
>> 16) & 0x7ff,
553 make_hex(uc_desc
->data_ptr
, dma_len
), endpoints
[ep
][1].state
);
555 * If parts of the just dmaed range are in cache, dump them now.
557 dump_dcache_range(uc_desc
->data_ptr
, dma_len
);
559 logf("EP%d OUT token, st:%08x frm:%x (no data)\n", ep
,
563 if (endpoints
[ep
][1].state
& EP_STATE_BUSY
) {
564 endpoints
[ep
][1].state
&= ~EP_STATE_BUSY
;
565 endpoints
[ep
][1].rc
= 0;
566 usb_core_transfer_complete(ep
, USB_DIR_OUT
, 0, dma_len
);
568 logf("EP%d OUT, but no one was listening?\n", ep
);
571 USB_OEP_CTRL(ep
) |= USB_EP_CTRL_SNAK
; /* make sure NAK is set */
573 ep_sts
&= ~USB_EP_STAT_OUT_RCVD
;
576 if (ep_sts
& USB_EP_STAT_SETUP_RCVD
) {
577 static struct usb_ctrlrequest req_copy
;
580 logf("t%ld:got SETUP packet: type=%d req=%d val=%d ind=%d len=%d\n",
588 usb_core_control_request(&req_copy
);
589 setup_desc_init(setup_desc
);
591 ep_sts
&= ~USB_EP_STAT_SETUP_RCVD
;
595 logf("ep%d OUT, status %x\n", ep
, ep_sts
);
596 panicf("ep%d OUT 0x%x", ep
, ep_sts
);
599 /* HW automatically disables RDE, re-enable it */
600 /* THEORY: Because we only set up one DMA buffer... */
601 USB_DEV_CTRL
|= USB_DEV_CTRL_RDE
;
604 /* interrupt service routine */
607 int ep
= USB_DEV_EP_INTR
& ~USB_DEV_EP_INTR_MASK
;
608 int intr
= USB_DEV_INTR
& ~USB_DEV_INTR_MASK
;
610 /* ACK interrupt sources */
611 USB_DEV_EP_INTR
= ep
;
614 /* Handle endpoint interrupts */
616 int onebit
= 31-__builtin_clz(ep
);
618 if (onebit
< 16) handle_in_ep(onebit
);
619 else handle_out_ep(onebit
-16);
621 ep
&= ~(1 << onebit
);
624 /* Handle general device interrupts */
626 if (intr
& USB_DEV_INTR_SET_INTERFACE
) {/* SET_INTERFACE received */
627 logf("set interface\n");
628 panicf("set interface");
629 intr
&= ~USB_DEV_INTR_SET_INTERFACE
;
631 if (intr
& USB_DEV_INTR_SET_CONFIG
) {/* SET_CONFIGURATION received */
633 * This is handled in HW, we have to fake a request here
636 static struct usb_ctrlrequest set_config
= {
637 bRequestType
: USB_TYPE_STANDARD
| USB_RECIP_DEVICE
,
638 bRequest
: USB_REQ_SET_CONFIGURATION
,
644 logf("set config\n");
646 set_config
.wValue
= USB_DEV_STS
& USB_DEV_STS_MASK_CFG
;
647 usb_core_control_request(&set_config
);
649 /* Tell the HW we handled the request */
650 USB_DEV_CTRL
|= USB_DEV_CTRL_APCSR_DONE
;
651 intr
&= ~USB_DEV_INTR_SET_CONFIG
;
653 if (intr
& USB_DEV_INTR_EARLY_SUSPEND
) {/* idle >3ms detected */
655 intr
&= ~USB_DEV_INTR_EARLY_SUSPEND
;
657 if (intr
& USB_DEV_INTR_USB_RESET
) {/* usb reset from host? */
660 usb_core_bus_reset();
661 intr
&= ~USB_DEV_INTR_USB_RESET
;
663 if (intr
& USB_DEV_INTR_USB_SUSPEND
) {/* suspend req from host? */
664 logf("usb suspend\n");
665 intr
&= ~USB_DEV_INTR_USB_SUSPEND
;
667 if (intr
& USB_DEV_INTR_SOF
) {/* sof received */
669 intr
&= ~USB_DEV_INTR_SOF
;
671 if (intr
& USB_DEV_INTR_SVC
) {/* device status changed */
672 logf("svc: %08x otg: %08x\n", (int)USB_DEV_STS
, (int)USB_OTG_CSR
);
673 intr
&= ~USB_DEV_INTR_SVC
;
675 if (intr
& USB_DEV_INTR_ENUM_DONE
) {/* speed enumeration complete */
676 int spd
= USB_DEV_STS
& USB_DEV_STS_MASK_SPD
; /* Enumerated Speed */
678 logf("speed enum complete: ");
679 if (spd
== USB_DEV_STS_SPD_HS
) logf("hs\n");
680 if (spd
== USB_DEV_STS_SPD_FS
) logf("fs\n");
681 if (spd
== USB_DEV_STS_SPD_LS
) logf("ls\n");
683 USB_PHY_EP0_INFO
= 0x00200000 |
686 USB_PHY_EP1_INFO
= 0x00200000 |
689 USB_PHY_EP2_INFO
= 0x00200001 |
692 USB_PHY_EP3_INFO
= 0x00200001 |
695 USB_DEV_CTRL
|= USB_DEV_CTRL_APCSR_DONE
;
696 USB_IEP_CTRL(0) |= USB_EP_CTRL_ACT
;
697 USB_OEP_CTRL(0) |= USB_EP_CTRL_ACT
;
698 intr
&= ~USB_DEV_INTR_ENUM_DONE
;
701 panicf("usb devirq 0x%x", intr
);
704 if (!(USB_DEV_CTRL
& USB_DEV_CTRL_RDE
)){
705 logf("re-enabling receive DMA\n");
706 USB_DEV_CTRL
|= USB_DEV_CTRL_RDE
;
711 /* (not essential? , not implemented in usb-tcc.c) */
712 void usb_drv_set_test_mode(int mode
)
717 /* handled internally by controller */
718 void usb_drv_set_address(int address
)
723 void usb_drv_stall(int ep
, bool stall
, bool in
)
725 if (stall
) USB_EP_CTRL(ep
, in
) |= USB_EP_CTRL_STALL
;
726 else USB_EP_CTRL(ep
, in
) &= ~USB_EP_CTRL_STALL
;
729 bool usb_drv_stalled(int ep
, bool in
)
731 return USB_EP_CTRL(ep
, in
) & USB_EP_CTRL_STALL
;
736 void usb_attach(void)
740 void usb_drv_init(void)
744 void usb_drv_exit(void)
748 int usb_drv_port_speed(void)
753 int usb_drv_request_endpoint(int type
, int dir
)
761 void usb_drv_release_endpoint(int ep
)
766 void usb_drv_cancel_all_transfers(void)
770 void usb_drv_set_test_mode(int mode
)
775 void usb_drv_set_address(int address
)
780 int usb_drv_recv(int ep
, void *ptr
, int len
)
789 int usb_drv_send(int ep
, void *ptr
, int len
)
798 int usb_drv_send_nonblocking(int ep
, void *ptr
, int len
)
807 void usb_drv_stall(int ep
, bool stall
, bool in
)
814 bool usb_drv_stalled(int ep
, bool in
)