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/mach-common/bits/usb.h>
16 #include "musb_core.h"
18 #ifndef CONFIG_USB_BLACKFIN_CLKIN
19 #define CONFIG_USB_BLACKFIN_CLKIN 24
22 /* MUSB platform configuration */
23 struct musb_config musb_cfg = {
24 .regs = (struct musb_regs *)USB_FADDR,
30 * This function read or write data to endpoint fifo
31 * Blackfin use DMA polling method to avoid buffer alignment issues
33 * ep - Endpoint number
34 * length - Number of bytes to write to FIFO
35 * fifo_data - Pointer to data buffer to be read/write
36 * is_write - Flag for read or write
38 void rw_fifo(u8 ep, u32 length, void *fifo_data, int is_write)
40 struct bfin_musb_dma_regs *regs;
41 u32 val = (u32)fifo_data;
43 blackfin_dcache_flush_invalidate_range(fifo_data, fifo_data + length);
45 regs = (void *)USB_DMA_INTERRUPT;
48 /* Setup DMA address register */
49 bfin_write16(®s->addr_low, val);
52 bfin_write16(®s->addr_high, val >> 16);
55 /* Setup DMA count register */
56 bfin_write16(®s->count_low, length);
57 bfin_write16(®s->count_high, 0);
61 val = (ep << 4) | DMA_ENA | INT_ENA;
64 bfin_write16(®s->control, val);
67 /* Wait for compelete */
68 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << ep)))
71 /* acknowledge dma interrupt */
72 bfin_write_USB_DMA_INTERRUPT(1 << ep);
76 bfin_write16(®s->control, 0);
80 void write_fifo(u8 ep, u32 length, void *fifo_data)
82 rw_fifo(ep, length, fifo_data, 1);
85 void read_fifo(u8 ep, u32 length, void *fifo_data)
87 rw_fifo(ep, length, fifo_data, 0);
92 * CPU and board-specific MUSB initializations. Aliased function
93 * signals caller to move on.
95 static void __def_musb_init(void)
98 void board_musb_init(void) __attribute__((weak, alias("__def_musb_init")));
100 static void bfin_anomaly_init(void)
104 if (!ANOMALY_05000346 && !ANOMALY_05000347)
107 revid = bfin_revid();
114 if (ANOMALY_BF526 && revid > 0)
116 if (ANOMALY_BF527 && revid > 1)
120 if (ANOMALY_05000346) {
121 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value);
125 if (ANOMALY_05000347) {
126 bfin_write_USB_APHY_CNTRL(0x0);
131 int musb_platform_init(void)
133 /* board specific initialization */
138 /* Configure PLL oscillator register */
139 bfin_write_USB_PLLOSC_CTRL(0x3080 |
140 ((480 / CONFIG_USB_BLACKFIN_CLKIN) << 1));
143 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1);
146 bfin_write_USB_EP_NI0_RXMAXP(64);
149 bfin_write_USB_EP_NI0_TXMAXP(64);
152 /* Route INTRUSB/INTR_RX/INTR_TX to USB_INT0*/
153 bfin_write_USB_GLOBINTR(0x7);
156 bfin_write_USB_GLOBAL_CTL(GLOBAL_ENA | EP1_TX_ENA | EP2_TX_ENA |
157 EP3_TX_ENA | EP4_TX_ENA | EP5_TX_ENA |
158 EP6_TX_ENA | EP7_TX_ENA | EP1_RX_ENA |
159 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA |
160 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA);
167 * This function performs Blackfin platform specific deinitialization for usb.
169 void musb_platform_deinit(void)