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 /* MUSB platform configuration */
19 struct musb_config musb_cfg = {
20 .regs = (struct musb_regs *)USB_FADDR,
26 * This function read or write data to endpoint fifo
27 * Blackfin use DMA polling method to avoid buffer alignment issues
29 * ep - Endpoint number
30 * length - Number of bytes to write to FIFO
31 * fifo_data - Pointer to data buffer to be read/write
32 * is_write - Flag for read or write
34 void rw_fifo(u8 ep, u32 length, void *fifo_data, int is_write)
36 struct bfin_musb_dma_regs *regs;
37 u32 val = (u32)fifo_data;
39 blackfin_dcache_flush_invalidate_range(fifo_data, fifo_data + length);
41 regs = (void *)USB_DMA_INTERRUPT;
44 /* Setup DMA address register */
45 bfin_write16(®s->addr_low, val);
48 bfin_write16(®s->addr_high, val >> 16);
51 /* Setup DMA count register */
52 bfin_write16(®s->count_low, length);
53 bfin_write16(®s->count_high, 0);
57 val = (ep << 4) | DMA_ENA | INT_ENA;
60 bfin_write16(®s->control, val);
63 /* Wait for compelete */
64 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << ep)))
67 /* acknowledge dma interrupt */
68 bfin_write_USB_DMA_INTERRUPT(1 << ep);
72 bfin_write16(®s->control, 0);
76 void write_fifo(u8 ep, u32 length, void *fifo_data)
78 rw_fifo(ep, length, fifo_data, 1);
81 void read_fifo(u8 ep, u32 length, void *fifo_data)
83 rw_fifo(ep, length, fifo_data, 0);
88 * CPU and board-specific MUSB initializations. Aliased function
89 * signals caller to move on.
91 static void __def_musb_init(void)
94 void board_musb_init(void) __attribute__((weak, alias("__def_musb_init")));
96 int musb_platform_init(void)
98 /* board specific initialization */
101 if (ANOMALY_05000346) {
102 bfin_write_USB_APHY_CALIB(ANOMALY_05000346_value);
106 if (ANOMALY_05000347) {
107 bfin_write_USB_APHY_CNTRL(0x0);
111 /* Configure PLL oscillator register */
112 bfin_write_USB_PLLOSC_CTRL(0x30a8);
115 bfin_write_USB_SRP_CLKDIV((get_sclk()/1000) / 32 - 1);
118 bfin_write_USB_EP_NI0_RXMAXP(64);
121 bfin_write_USB_EP_NI0_TXMAXP(64);
124 /* Route INTRUSB/INTR_RX/INTR_TX to USB_INT0*/
125 bfin_write_USB_GLOBINTR(0x7);
128 bfin_write_USB_GLOBAL_CTL(GLOBAL_ENA | EP1_TX_ENA | EP2_TX_ENA |
129 EP3_TX_ENA | EP4_TX_ENA | EP5_TX_ENA |
130 EP6_TX_ENA | EP7_TX_ENA | EP1_RX_ENA |
131 EP2_RX_ENA | EP3_RX_ENA | EP4_RX_ENA |
132 EP5_RX_ENA | EP6_RX_ENA | EP7_RX_ENA);
139 * This function performs Blackfin platform specific deinitialization for usb.
141 void musb_platform_deinit(void)