2 * Blackfin MUSB HCD (Host Controller Driver) for u-boot
4 * Copyright (c) 2008-2009 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
13 #include <asm/blackfin.h>
14 #include <asm/clock.h>
15 #include <asm/mach-common/bits/usb.h>
17 #include "musb_core.h"
19 #ifndef CONFIG_USB_BLACKFIN_CLKIN
20 #define CONFIG_USB_BLACKFIN_CLKIN 24
23 /* MUSB platform configuration */
24 struct musb_config musb_cfg
= {
25 .regs
= (struct musb_regs
*)USB_FADDR
,
31 * This function read or write data to endpoint fifo
32 * Blackfin use DMA polling method to avoid buffer alignment issues
34 * ep - Endpoint number
35 * length - Number of bytes to write to FIFO
36 * fifo_data - Pointer to data buffer to be read/write
37 * is_write - Flag for read or write
39 void rw_fifo(u8 ep
, u32 length
, void *fifo_data
, int is_write
)
41 struct bfin_musb_dma_regs
*regs
;
42 u32 val
= (u32
)fifo_data
;
44 blackfin_dcache_flush_invalidate_range(fifo_data
, fifo_data
+ length
);
46 regs
= (void *)USB_DMA_INTERRUPT
;
49 /* Setup DMA address register */
50 bfin_write16(®s
->addr_low
, val
);
53 bfin_write16(®s
->addr_high
, val
>> 16);
56 /* Setup DMA count register */
57 bfin_write16(®s
->count_low
, length
);
58 bfin_write16(®s
->count_high
, 0);
62 val
= (ep
<< 4) | DMA_ENA
| INT_ENA
;
65 bfin_write16(®s
->control
, val
);
68 /* Wait for compelete */
69 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << ep
)))
72 /* acknowledge dma interrupt */
73 bfin_write_USB_DMA_INTERRUPT(1 << ep
);
77 bfin_write16(®s
->control
, 0);
81 void write_fifo(u8 ep
, u32 length
, void *fifo_data
)
83 rw_fifo(ep
, length
, fifo_data
, 1);
86 void read_fifo(u8 ep
, u32 length
, void *fifo_data
)
88 rw_fifo(ep
, length
, fifo_data
, 0);
93 * CPU and board-specific MUSB initializations. Aliased function
94 * signals caller to move on.
96 static void __def_musb_init(void)
99 void board_musb_init(void) __attribute__((weak
, alias("__def_musb_init")));
101 static void bfin_anomaly_init(void)
105 if (!ANOMALY_05000346
&& !ANOMALY_05000347
)
108 revid
= bfin_revid();
115 if (ANOMALY_BF526
&& revid
> 0)
117 if (ANOMALY_BF527
&& revid
> 1)
121 if (ANOMALY_05000346
) {
122 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value
);
126 if (ANOMALY_05000347
) {
127 bfin_write_USB_APHY_CNTRL(0x0);
132 int musb_platform_init(void)
134 /* board specific initialization */
139 /* Configure PLL oscillator register */
140 bfin_write_USB_PLLOSC_CTRL(0x3080 |
141 ((480 / CONFIG_USB_BLACKFIN_CLKIN
) << 1));
144 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1);
147 bfin_write_USB_EP_NI0_RXMAXP(64);
150 bfin_write_USB_EP_NI0_TXMAXP(64);
153 /* Route INTRUSB/INTR_RX/INTR_TX to USB_INT0*/
154 bfin_write_USB_GLOBINTR(0x7);
157 bfin_write_USB_GLOBAL_CTL(GLOBAL_ENA
| EP1_TX_ENA
| EP2_TX_ENA
|
158 EP3_TX_ENA
| EP4_TX_ENA
| EP5_TX_ENA
|
159 EP6_TX_ENA
| EP7_TX_ENA
| EP1_RX_ENA
|
160 EP2_RX_ENA
| EP3_RX_ENA
| EP4_RX_ENA
|
161 EP5_RX_ENA
| EP6_RX_ENA
| EP7_RX_ENA
);
168 * This function performs Blackfin platform specific deinitialization for usb.
170 void musb_platform_deinit(void)