Merge branch 'pstore-efi' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[deliverable/linux.git] / arch / arm / mach-ux500 / usb.c
1 /*
2 * Copyright (C) ST-Ericsson SA 2011
3 *
4 * Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
5 * License terms: GNU General Public License (GPL) version 2
6 */
7 #include <linux/platform_device.h>
8 #include <linux/usb/musb.h>
9 #include <linux/dma-mapping.h>
10 #include <plat/ste_dma40.h>
11 #include <mach/hardware.h>
12 #include <mach/usb.h>
13
14 #define MUSB_DMA40_RX_CH { \
15 .mode = STEDMA40_MODE_LOGICAL, \
16 .dir = STEDMA40_PERIPH_TO_MEM, \
17 .dst_dev_type = STEDMA40_DEV_DST_MEMORY, \
18 .src_info.data_width = STEDMA40_WORD_WIDTH, \
19 .dst_info.data_width = STEDMA40_WORD_WIDTH, \
20 .src_info.psize = STEDMA40_PSIZE_LOG_16, \
21 .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
22 }
23
24 #define MUSB_DMA40_TX_CH { \
25 .mode = STEDMA40_MODE_LOGICAL, \
26 .dir = STEDMA40_MEM_TO_PERIPH, \
27 .src_dev_type = STEDMA40_DEV_SRC_MEMORY, \
28 .src_info.data_width = STEDMA40_WORD_WIDTH, \
29 .dst_info.data_width = STEDMA40_WORD_WIDTH, \
30 .src_info.psize = STEDMA40_PSIZE_LOG_16, \
31 .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
32 }
33
34 static struct stedma40_chan_cfg musb_dma_rx_ch[UX500_MUSB_DMA_NUM_RX_CHANNELS]
35 = {
36 MUSB_DMA40_RX_CH,
37 MUSB_DMA40_RX_CH,
38 MUSB_DMA40_RX_CH,
39 MUSB_DMA40_RX_CH,
40 MUSB_DMA40_RX_CH,
41 MUSB_DMA40_RX_CH,
42 MUSB_DMA40_RX_CH,
43 MUSB_DMA40_RX_CH
44 };
45
46 static struct stedma40_chan_cfg musb_dma_tx_ch[UX500_MUSB_DMA_NUM_TX_CHANNELS]
47 = {
48 MUSB_DMA40_TX_CH,
49 MUSB_DMA40_TX_CH,
50 MUSB_DMA40_TX_CH,
51 MUSB_DMA40_TX_CH,
52 MUSB_DMA40_TX_CH,
53 MUSB_DMA40_TX_CH,
54 MUSB_DMA40_TX_CH,
55 MUSB_DMA40_TX_CH,
56 };
57
58 static void *ux500_dma_rx_param_array[UX500_MUSB_DMA_NUM_RX_CHANNELS] = {
59 &musb_dma_rx_ch[0],
60 &musb_dma_rx_ch[1],
61 &musb_dma_rx_ch[2],
62 &musb_dma_rx_ch[3],
63 &musb_dma_rx_ch[4],
64 &musb_dma_rx_ch[5],
65 &musb_dma_rx_ch[6],
66 &musb_dma_rx_ch[7]
67 };
68
69 static void *ux500_dma_tx_param_array[UX500_MUSB_DMA_NUM_TX_CHANNELS] = {
70 &musb_dma_tx_ch[0],
71 &musb_dma_tx_ch[1],
72 &musb_dma_tx_ch[2],
73 &musb_dma_tx_ch[3],
74 &musb_dma_tx_ch[4],
75 &musb_dma_tx_ch[5],
76 &musb_dma_tx_ch[6],
77 &musb_dma_tx_ch[7]
78 };
79
80 static struct ux500_musb_board_data musb_board_data = {
81 .dma_rx_param_array = ux500_dma_rx_param_array,
82 .dma_tx_param_array = ux500_dma_tx_param_array,
83 .num_rx_channels = UX500_MUSB_DMA_NUM_RX_CHANNELS,
84 .num_tx_channels = UX500_MUSB_DMA_NUM_TX_CHANNELS,
85 .dma_filter = stedma40_filter,
86 };
87
88 static u64 ux500_musb_dmamask = DMA_BIT_MASK(32);
89
90 static struct musb_hdrc_config musb_hdrc_config = {
91 .multipoint = true,
92 .dyn_fifo = true,
93 .num_eps = 16,
94 .ram_bits = 16,
95 };
96
97 static struct musb_hdrc_platform_data musb_platform_data = {
98 #if defined(CONFIG_USB_MUSB_OTG)
99 .mode = MUSB_OTG,
100 #elif defined(CONFIG_USB_MUSB_PERIPHERAL)
101 .mode = MUSB_PERIPHERAL,
102 #else /* defined(CONFIG_USB_MUSB_HOST) */
103 .mode = MUSB_HOST,
104 #endif
105 .config = &musb_hdrc_config,
106 .board_data = &musb_board_data,
107 };
108
109 static struct resource usb_resources[] = {
110 [0] = {
111 .name = "usb-mem",
112 .flags = IORESOURCE_MEM,
113 },
114
115 [1] = {
116 .name = "mc", /* hard-coded in musb */
117 .flags = IORESOURCE_IRQ,
118 },
119 };
120
121 struct platform_device ux500_musb_device = {
122 .name = "musb-ux500",
123 .id = 0,
124 .dev = {
125 .platform_data = &musb_platform_data,
126 .dma_mask = &ux500_musb_dmamask,
127 .coherent_dma_mask = DMA_BIT_MASK(32),
128 },
129 .num_resources = ARRAY_SIZE(usb_resources),
130 .resource = usb_resources,
131 };
132
133 static inline void ux500_usb_dma_update_rx_ch_config(int *src_dev_type)
134 {
135 u32 idx;
136
137 for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_CHANNELS; idx++)
138 musb_dma_rx_ch[idx].src_dev_type = src_dev_type[idx];
139 }
140
141 static inline void ux500_usb_dma_update_tx_ch_config(int *dst_dev_type)
142 {
143 u32 idx;
144
145 for (idx = 0; idx < UX500_MUSB_DMA_NUM_TX_CHANNELS; idx++)
146 musb_dma_tx_ch[idx].dst_dev_type = dst_dev_type[idx];
147 }
148
149 void ux500_add_usb(resource_size_t base, int irq, int *dma_rx_cfg,
150 int *dma_tx_cfg)
151 {
152 ux500_musb_device.resource[0].start = base;
153 ux500_musb_device.resource[0].end = base + SZ_64K - 1;
154 ux500_musb_device.resource[1].start = irq;
155 ux500_musb_device.resource[1].end = irq;
156
157 ux500_usb_dma_update_rx_ch_config(dma_rx_cfg);
158 ux500_usb_dma_update_tx_ch_config(dma_tx_cfg);
159
160 platform_device_register(&ux500_musb_device);
161 }
This page took 0.067182 seconds and 5 git commands to generate.