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
11 #include <plat/ste_dma40.h>
12 #include <mach/hardware.h>
13 #include <mach/usb.h>
14
15 #define MUSB_DMA40_RX_CH { \
16 .mode = STEDMA40_MODE_LOGICAL, \
17 .dir = STEDMA40_PERIPH_TO_MEM, \
18 .dst_dev_type = STEDMA40_DEV_DST_MEMORY, \
19 .src_info.data_width = STEDMA40_WORD_WIDTH, \
20 .dst_info.data_width = STEDMA40_WORD_WIDTH, \
21 .src_info.psize = STEDMA40_PSIZE_LOG_16, \
22 .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
23 }
24
25 #define MUSB_DMA40_TX_CH { \
26 .mode = STEDMA40_MODE_LOGICAL, \
27 .dir = STEDMA40_MEM_TO_PERIPH, \
28 .src_dev_type = STEDMA40_DEV_SRC_MEMORY, \
29 .src_info.data_width = STEDMA40_WORD_WIDTH, \
30 .dst_info.data_width = STEDMA40_WORD_WIDTH, \
31 .src_info.psize = STEDMA40_PSIZE_LOG_16, \
32 .dst_info.psize = STEDMA40_PSIZE_LOG_16, \
33 }
34
35 static struct stedma40_chan_cfg musb_dma_rx_ch[UX500_MUSB_DMA_NUM_RX_CHANNELS]
36 = {
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 MUSB_DMA40_RX_CH
45 };
46
47 static struct stedma40_chan_cfg musb_dma_tx_ch[UX500_MUSB_DMA_NUM_TX_CHANNELS]
48 = {
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 MUSB_DMA40_TX_CH,
57 };
58
59 static void *ux500_dma_rx_param_array[UX500_MUSB_DMA_NUM_RX_CHANNELS] = {
60 &musb_dma_rx_ch[0],
61 &musb_dma_rx_ch[1],
62 &musb_dma_rx_ch[2],
63 &musb_dma_rx_ch[3],
64 &musb_dma_rx_ch[4],
65 &musb_dma_rx_ch[5],
66 &musb_dma_rx_ch[6],
67 &musb_dma_rx_ch[7]
68 };
69
70 static void *ux500_dma_tx_param_array[UX500_MUSB_DMA_NUM_TX_CHANNELS] = {
71 &musb_dma_tx_ch[0],
72 &musb_dma_tx_ch[1],
73 &musb_dma_tx_ch[2],
74 &musb_dma_tx_ch[3],
75 &musb_dma_tx_ch[4],
76 &musb_dma_tx_ch[5],
77 &musb_dma_tx_ch[6],
78 &musb_dma_tx_ch[7]
79 };
80
81 static struct ux500_musb_board_data musb_board_data = {
82 .dma_rx_param_array = ux500_dma_rx_param_array,
83 .dma_tx_param_array = ux500_dma_tx_param_array,
84 .num_rx_channels = UX500_MUSB_DMA_NUM_RX_CHANNELS,
85 .num_tx_channels = UX500_MUSB_DMA_NUM_TX_CHANNELS,
86 .dma_filter = stedma40_filter,
87 };
88
89 static u64 ux500_musb_dmamask = DMA_BIT_MASK(32);
90
91 static struct musb_hdrc_config musb_hdrc_config = {
92 .multipoint = true,
93 .dyn_fifo = true,
94 .num_eps = 16,
95 .ram_bits = 16,
96 };
97
98 static struct musb_hdrc_platform_data musb_platform_data = {
99 .mode = MUSB_OTG,
100 .config = &musb_hdrc_config,
101 .board_data = &musb_board_data,
102 };
103
104 static struct resource usb_resources[] = {
105 [0] = {
106 .name = "usb-mem",
107 .flags = IORESOURCE_MEM,
108 },
109
110 [1] = {
111 .name = "mc", /* hard-coded in musb */
112 .flags = IORESOURCE_IRQ,
113 },
114 };
115
116 struct platform_device ux500_musb_device = {
117 .name = "musb-ux500",
118 .id = 0,
119 .dev = {
120 .platform_data = &musb_platform_data,
121 .dma_mask = &ux500_musb_dmamask,
122 .coherent_dma_mask = DMA_BIT_MASK(32),
123 },
124 .num_resources = ARRAY_SIZE(usb_resources),
125 .resource = usb_resources,
126 };
127
ux500_usb_dma_update_rx_ch_config(int * src_dev_type)128 static inline void ux500_usb_dma_update_rx_ch_config(int *src_dev_type)
129 {
130 u32 idx;
131
132 for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_CHANNELS; idx++)
133 musb_dma_rx_ch[idx].src_dev_type = src_dev_type[idx];
134 }
135
ux500_usb_dma_update_tx_ch_config(int * dst_dev_type)136 static inline void ux500_usb_dma_update_tx_ch_config(int *dst_dev_type)
137 {
138 u32 idx;
139
140 for (idx = 0; idx < UX500_MUSB_DMA_NUM_TX_CHANNELS; idx++)
141 musb_dma_tx_ch[idx].dst_dev_type = dst_dev_type[idx];
142 }
143
ux500_add_usb(struct device * parent,resource_size_t base,int irq,int * dma_rx_cfg,int * dma_tx_cfg)144 void ux500_add_usb(struct device *parent, resource_size_t base, int irq,
145 int *dma_rx_cfg, int *dma_tx_cfg)
146 {
147 ux500_musb_device.resource[0].start = base;
148 ux500_musb_device.resource[0].end = base + SZ_64K - 1;
149 ux500_musb_device.resource[1].start = irq;
150 ux500_musb_device.resource[1].end = irq;
151
152 ux500_usb_dma_update_rx_ch_config(dma_rx_cfg);
153 ux500_usb_dma_update_tx_ch_config(dma_tx_cfg);
154
155 ux500_musb_device.dev.parent = parent;
156
157 platform_device_register(&ux500_musb_device);
158 }
159