]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/usb/mxc/v2_0/include/mxc-hardware.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / devs / usb / mxc / v2_0 / include / mxc-hardware.h
1 /*
2  * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /* Modified from Belcarra Linux USB driver by Yi Li */
6
7 /*
8  * The code contained herein is licensed under the GNU General Public
9  * License. You may obtain a copy of the GNU General Public License
10  * Version 2 or later at the following locations:
11  *
12  * http://www.opensource.org/licenses/gpl-license.html
13  * http://www.gnu.org/copyleft/gpl.html
14  */
15
16 typedef unsigned short u16;
17 typedef unsigned int u32;
18 typedef unsigned char u8;
19
20 #define CONFIG_ARCH_MXC91321 1
21
22 #define IO_ADDRESS(x)  (x)
23 #define cpu_to_le16(x) (x)
24 #define le16_to_cpu(x) (x)
25
26 #if defined (CONFIG_ARCH_MXC91321)
27 #define MUX_I           0
28 #define MUX_F           8
29 #define PAD_I           10
30 #define _MXC_BUILD_PIN(gp,gi,mi,mf,pi,pf) ((mi << MUX_I) | (mf << MUX_F) | (pi << PAD_I))
31 #define PIN_USB_VPIN   _MXC_BUILD_PIN(0, 4, 70, 3, 93, 1)
32 #define PIN_USB_VPOUT  _MXC_BUILD_PIN(0, 5, 70, 2, 93, 0)
33 #define PIN_USB_VMIN   _MXC_BUILD_PIN(0, 6, 70, 1, 92, 2)
34 #define PIN_USB_XRXD   _MXC_BUILD_PIN(0, 7, 70, 0, 92, 1)
35 #define PIN_USB_VMOUT  _MXC_BUILD_PIN(0, 2, 71, 1, 94, 0)
36 #define PIN_USB_TXENB  _MXC_BUILD_PIN(0, 3, 71, 0, 93, 2)
37 #define PIN_TO_IOMUX_INDEX(pin) ((pin >> MUX_I) & ((1 << (MUX_F - MUX_I)) - 1))
38 #define PIN_TO_IOMUX_FIELD(pin) ((pin >> MUX_F) & ((1 << (PAD_I - MUX_F)) - 1))
39 #define IOMUXC_BASE_ADDR        0x50000000
40 #define MUX_CTL_BIT_LEN         8
41 #endif
42
43 #if defined (CONFIG_ARCH_MXC91321)
44 #define OTG_BASE_ADDR           0x50020000
45 #endif
46
47 #define OTG_CORE_BASE                   (OTG_BASE_ADDR+0x000)   
48 #define OTG_FUNC_BASE                   (OTG_BASE_ADDR+0x040)   
49 #define OTG_DMA_BASE                    (OTG_BASE_ADDR+0x800)   
50 #define OTG_EP_BASE                     (OTG_BASE_ADDR+0x400)   
51 #define OTG_SYS_BASE                    (OTG_BASE_ADDR+0x600)   
52
53 #define OTG_DATA_BASE           (OTG_BASE_ADDR+0x1000)  
54
55 #define SYS_CTRL_OTG_WU_INT_STAT                (1 << 26)
56 #define SYS_CTRL_FNT_WU_INT_STAT                (1 << 24)
57
58 #define SYS_CTRL_OTG_WU_INT_EN                  (1 << 18)
59 #define SYS_CTRL_FNT_WU_INT_EN                  (1 << 16)
60
61 #define OTG_CORE_HWMODE                         (OTG_CORE_BASE+0x00)
62
63 #define XCVR_D_D                                0x00
64 #define XCVR_SE0_D_NEW                          0x02
65 #define XCVR_D_SE0_NEW                          0x01
66 #define XCVR_SE0_SE0                            0x03
67
68 #define MODULE_ANASDBEN                         (1 << 14)
69 #define MODULE_OTGXCVR                          (0x3 << 6)
70 #define MODULE_HOSTXCVR                         (0x3 << 4)
71 #define MODULE_CRECFG                           (0x3)
72 #define MODULE_CRECFG_HHNP                      (0x0)
73 #define MODULE_CRECFG_HOST                      (0x1)
74 #define MODULE_CRECFG_FUNC                      (0x2)
75 #define MODULE_CRECFG_SHNP                      (0x3)
76
77 #define OTG_CORE_CINT_STAT                      (OTG_CORE_BASE+0x04)    //  32bit core int status reg
78
79 #define MODULE_FCINTDSPEN                       (1 << 6)
80
81 #define MODULE_ASHNPINT                         (1 << 5)
82 #define MODULE_ASFCINT                          (1 << 4)
83 #define MODULE_ASHCINT                          (1 << 3)
84 #define MODULE_HNPINT                           (1 << 2)
85 #define MODULE_FCINT                            (1 << 1)
86 #define MODULE_HCINT                            (1)
87
88 #define OTG_CORE_CINT_STEN                      (OTG_CORE_BASE+0x08)    //  32bit core int enable reg
89 #define OTG_CORE_CINT_STEN_CLR                  (OTG_CORE_BASE+0x3c)    //  32bit core int enable clear reg
90
91 #define MODULE_ASHNPINT_EN                      (1 << 5)
92 #define MODULE_ASFCINT_EN                       (1 << 4)
93 #define MODULE_ASHCINT_EN                       (1 << 3)
94 #define MODULE_HNPINT_EN                        (1 << 2)
95 #define MODULE_FCINT_EN                         (1 << 1)
96 #define MODULE_HCINT_EN                         (1)
97
98 #define OTG_CORE_CLK_CTRL                       (OTG_CORE_BASE+0x0C)    //  32bit core clock control reg
99
100 #define MODULE_FUNC_CLK                         (1 << 2)
101 #define MODULE_MAIN_CLK                         (1)
102
103 #define OTG_CORE_RST_CTRL                       (OTG_CORE_BASE+0x10)    // 32bit core reset control reg
104
105 #define MODULE_RSTI2C                           (1 << 15)
106 #define MODULE_RSTCTRL                          (1 << 5)
107 #define MODULE_RSTFC                            (1 << 4)
108 #define MODULE_RSTFSIE                          (1 << 3)
109 #define MODULE_RSTRH                            (1 << 2)
110 #define MODULE_RSTHSIE                          (1 << 1)
111 #define MODULE_RSTHC                            (1)
112
113 #define OTG_CORE_FRM_INTVL                      (OTG_CORE_BASE+0x14)    //  32bit core frame interval reg
114
115 #define MODULE_RESET_FRAME                      (1 << 15)
116
117 #define OTG_CORE_FRM_REMAIN                     (OTG_CORE_BASE+0x18)    //  32bit core frame remaining reg
118
119 #define OTG_CORE_HNP_CSTAT                      (OTG_CORE_BASE+0x1C)    //  32bit core HNP current state reg
120
121 #define MODULE_HNPDAT                           (1 << 30)
122 #define MODULE_VBUSBSE                          (1 << 29)
123 #define MODULE_VBUSABSV                         (1 << 28)
124 #define MODULE_VBUSGTAVV                        (1 << 27)
125
126 #define MODULE_ARMTHNPE                         (1 << 25)
127 #define MODULE_BHNPEN                           (1 << 24)
128
129 #define MODULE_SLAVE                            (1 << 22)
130 #define MODULE_MASTER                           (1 << 21)
131 #define MODULE_BGEN                             (1 << 20)
132 #define MODULE_CMPEN                            (1 << 19)
133
134 #define MODULE_SWVBUSPUL                        (1 << 15)
135
136 #define MODULE_SWAUTORST                        (1 << 12)
137 #define MODULE_SWPUDP                           (1 << 11)
138
139 #define MODULE_HNPSTATE                         (0x1f << 8)
140 #define MODULE_ABBUSREQ                         (1 << 1)
141
142 #define OTG_CORE_CPUEPSEL_STAT                  (OTG_CORE_BASE+0x34)
143 #define OTG_CORE_INTERRUPT_STEN                 (OTG_CORE_BASE+0x3c)
144
145 #define OTG_FUNC_CMD_STAT                       (OTG_FUNC_BASE+0x00)    //  32bit func command status reg
146
147 #define COMMAND_SOFTRESET                       (1 << 7)
148 #define COMMAND_BADISOAP                        (1 << 3)
149 #define COMMAND_SUPDET                          (1 << 2)
150 #define COMMAND_RSMINPROG                       (1 << 1)
151 #define COMMAND_RESETDET                        (1)
152
153 #define OTG_FUNC_DEV_ADDR                       (OTG_FUNC_BASE+0x04)    //  32bit func device address reg
154 #define OTG_FUNC_SINT_STAT                      (OTG_FUNC_BASE+0x08)    //  32bit func system int status reg
155
156 #define SYSTEM_DONEREGINTDS                     (1 << 5)
157 #define SYSTEM_SOFDETINT                        (1 << 4)
158 #define SYSTEM_DONEREGINT                       (1 << 3)
159 #define SYSTEM_SUSPDETINT                       (1 << 2)
160 #define SYSTEM_RSMFININT                        (1 << 1)
161 #define SYSTEM_RESETINT                         (1)
162
163 #define OTG_FUNC_SINT_STEN                      (OTG_FUNC_BASE+0x0C)    //  32bit func system int enable reg
164 #define OTG_FUNC_SINT_STEN_CLR                  (OTG_FUNC_BASE+0x10C)   //  32bit func system int enable clear reg
165
166 #define SYSTEM_DONEREGINTDS_EN                  (1 << 5)
167 #define SYSTEM_SOFDETINT_EN                     (1 << 4)
168 #define SYSTEM_DONEREGINT_EN                    (1 << 3)
169 #define SYSTEM_SUSPDETINT_EN                    (1 << 2)
170 #define SYSTEM_RSMFININT_EN                     (1 << 1)
171 #define SYSTEM_RESETINT_EN                      (1)
172
173 #define OTG_FUNC_XINT_STAT                      (OTG_FUNC_BASE+0x10)    //  32bit func X buf int status reg
174 #define OTG_FUNC_YINT_STAT                      (OTG_FUNC_BASE+0x14)    //  32bit func Y buf int status reg
175
176 #define OTG_FUNC_XYINT_STEN                     (OTG_FUNC_BASE+0x18)    //  32bit func XY buf int enable reg
177 #define OTG_FUNC_XYINT_STEN_CLR                 (OTG_FUNC_BASE+0x118)   //  32bit func XY buf int enable clear reg
178
179 #define OTG_FUNC_XFILL_STAT                     (OTG_FUNC_BASE+0x1C)    //  32bit func X filled status reg
180 #define OTG_FUNC_YFILL_STAT                     (OTG_FUNC_BASE+0x20)    //  32bit func Y filled status reg
181
182 #define OTG_FUNC_EP_EN                          (OTG_FUNC_BASE+0x24)    //  32bit func endpoints enable reg
183 #define OTG_FUNC_EP_EN_CLR                      (OTG_FUNC_BASE+0x124)   //  32bit func endpoints enable clear reg
184
185 #define OTG_FUNC_EP_RDY                         (OTG_FUNC_BASE+0x28)    //  32bit func endpoints ready reg
186 #define OTG_FUNC_EP_RDY_CLR                     (OTG_FUNC_BASE+0x3C)    //  32bit func endpoints ready clear reg
187
188 #define OTG_FUNC_IINT                           (OTG_FUNC_BASE+0x2C)    //  32bit func immediate interrupt reg
189 #define OTG_FUNC_IINT_CLR                       (OTG_FUNC_BASE+0x12C)   //  32bit func immediate interrupt clear reg
190
191 #define OTG_FUNC_EP_DSTAT                       (OTG_FUNC_BASE+0x30)    //  32bit func endpoints done status
192
193 #define OTG_FUNC_EP_DEN                         (OTG_FUNC_BASE+0x34)    //  32bit func endpoints done enable
194 #define OTG_FUNC_EP_DEN_CLR                     (OTG_FUNC_BASE+0x134)   //  32bit func endpoints done clear enable
195
196 #define OTG_FUNC_EP_TOGGLE                      (OTG_FUNC_BASE+0x38)    //  32bit func endpoints toggle bits
197 #define OTG_FUNC_FRM_NUM                        (OTG_FUNC_BASE+0x3C)    //  32bit func frame number reg
198
199 #define EP0_STALL                               (1 << 31)
200 #define EP0_SETUP                               (1 << 30)
201 #define EP0_OVERRUN                             (1 << 29)
202 #define EP0_AUTOISO                             (1 << 27)
203
204 #define EP_FORMAT_CONTROL     0x0
205 #define EP_FORMAT_ISOC        0x1
206 #define EP_FORMAT_BULK        0x2
207 #define EP_FORMAT_INTERRUPT   0x3
208
209 #define EP_OUT                                  0x1
210 #define EP_IN                                   0x2
211 #define EP_BOTH                                 0x3
212
213 #define NUM_ETDS                16
214 #define DATA_BUFF_SIZE          64
215 #define DATA_BUFFER_TOTAL       4096
216 #define NUM_DATA_BUFFS          (4096/DATA_BUFF_SIZE)
217
218 #define ep_num_both(n)                          (EP_BOTH << n)
219 #define ep_num_dir(n, dir)                      ((dir ? EP_IN : EP_OUT) << (n*2))
220 #define ep_num_out(n)                           ep_num_dir(n, USB_DIR_OUT)
221 #define ep_num_in(n)                            ep_num_dir(n, USB_DIR_IN)
222
223 /* ep descriptor access
224  */
225 static __inline__ u32 ep_word(int n, int dir, int word)
226 {
227         u32 offset = n * 2;
228         offset += dir ? 1 : 0;
229         offset *= 16;
230         offset += word * 4;
231         return OTG_EP_BASE + offset;
232 }
233
234 static volatile __inline__ u16 data_x_buf(int n, int dir)
235 {
236         return 0x40 * (n * 4 + 2 * (dir ? 1 : 0));
237 }
238 static volatile __inline__ u16 data_y_buf(int n, int dir)
239 {
240         return 0x40 * (n * 4 + 2 * (dir ? 1 : 0) + 1);
241 }
242
243 static volatile __inline__ u8 *data_x_address(int n, int dir)
244 {
245         return (volatile u8 *)IO_ADDRESS(OTG_DATA_BASE + data_x_buf(n, dir));
246 }
247 static volatile __inline__ u8 *data_y_address(int n, int dir)
248 {
249         return (volatile u8 *)IO_ADDRESS(OTG_DATA_BASE + data_y_buf(n, dir));
250 }
251
252 #define OTG_DMA_MISC_CTRL     (OTG_DMA_BASE+0x040)      //  32bit dma EP misc control reg
253 #define OTG_DMA_MISC_ARBMODE  (1 << 1)
254
255 #define OTG_DMA_ETD_CH_CLR    (OTG_DMA_BASE+0x048)      //  32bit dma ETD clear channel reg
256 #define OTG_DMA_EP_CH_CLR     (OTG_DMA_BASE+0x04c)      //  32bit dma EP clear channel reg
257
258 #define dma_num_dir(n, dir) (n * 2 + (dir ? 1 : 0))
259 #define dma_num_out(n) dma_num_dir(n, USB_DIR_OUT)
260 #define dma_num_in(n) dma_num_dir(n, USB_DIR_IN)
261
262 #define OTG_DMA_ETD_MSA(x)    (OTG_DMA_BASE+0x100+x*4)
263 #define OTG_DMA_EPN_MSA(x)    (OTG_DMA_BASE+0x180+x*4)
264 #define OTG_DMA_ETDN_BPTR(x)  (OTG_DMA_BASE+0x280+x*4)
265 #define OTG_DMA_EPN_BPTR(x)   (OTG_DMA_BASE+0x284+x*4)
266
267 typedef struct transfer_descriptor_w1 {
268         u16 x;
269         u16 y;
270 } volatile transfer_descriptor_w1;
271
272 typedef struct control_bulk_transfer_descriptor_w2 {
273         u8 rtrydelay;
274         u8 reserved;
275         u16 flags;
276 } volatile control_bulk_transfer_descriptor_w2;
277
278 typedef struct interrupt_transfer_descriptor_w2 {
279         u8 polinterv;
280         u8 relpolpos;
281         u16 flags;
282 } volatile interrupt_transfer_descriptor_w2;
283
284 typedef struct isoc_transfer_descriptor_w2 {
285         u16 startfrm;
286         u16 flags;
287 } volatile isoc_transfer_descriptor_w2;
288
289 typedef struct isoc_transfer_descriptor_w3 {
290         u16 pkt0;
291         u16 pkt1;
292 } volatile isoc_transfer_descriptor_w3;
293
294 typedef struct transfer_descriptor {
295         union {
296                 u32 val;
297                 transfer_descriptor_w1 bufsrtad;
298         } volatile w1;
299         union {
300                 u32 val;
301                 control_bulk_transfer_descriptor_w2 cb;
302                 interrupt_transfer_descriptor_w2 intr;
303                 isoc_transfer_descriptor_w2 isoc;
304         } volatile w2;
305         union {
306                 u32 val;
307                 isoc_transfer_descriptor_w3 isoc;
308         } volatile w3;
309 } __attribute__ ((packed))
310 volatile transfer_descriptor;
311
312 static u8 __inline__ fs_rb(u32 port)
313 {
314         return *(volatile u8 *)(IO_ADDRESS(port));
315 }
316
317 static u32 __inline__ fs_rl(u32 port)
318 {
319         return *(volatile u32 *)(IO_ADDRESS(port));
320 }
321
322 static void __inline__ fs_wb(u32 port, u8 val)
323 {
324         *(volatile u8 *)(IO_ADDRESS(port)) = val;
325 }
326
327 static void __inline__ fs_orb(u32 port, u8 val)
328 {
329         u8 set = fs_rb(port) | val;
330         *(volatile u8 *)(IO_ADDRESS(port)) = set;
331 }
332
333 static void __inline__ fs_andb(u32 port, u8 val)
334 {
335         u8 set = fs_rb(port) & val;
336         *(volatile u8 *)(IO_ADDRESS(port)) = set;
337 }
338
339 static void __inline__ fs_wl(u32 port, u32 val)
340 {
341         *(volatile u32 *)(IO_ADDRESS(port)) = val;
342 }
343
344 static void __inline__ fs_orl(u32 port, u32 val)
345 {
346         u32 set = fs_rl(port);
347         *(volatile u32 *)(IO_ADDRESS(port)) = (set | val);
348 }
349
350 static void __inline__ fs_andl(u32 port, u32 val)
351 {
352         u32 set = fs_rl(port);
353         *(volatile u32 *)(IO_ADDRESS(port)) = (set & val);
354 }
355
356 static void inline fs_memcpy32(u32 * dp, u32 * sp, volatile int words)
357 {
358         while (words--)
359                 *dp++ = *sp++;
360 }
361
362 static void inline fs_memcpy(u8 * dp, u8 * sp, volatile int bytes)
363 {
364         while (bytes--)
365                 *dp++ = *sp++;
366 }
367
368 static void inline fs_clear_words(volatile u32 * addr, int words)
369 {
370         while (words--)
371                 *addr++ = 0;
372 }
373
374 #define TIMEOUT_VALUE 1000
375
376 void mxc_main_clock_on(void)
377 {
378         u32 timeout = TIMEOUT_VALUE;
379         fs_orl(OTG_CORE_CLK_CTRL, MODULE_MAIN_CLK);
380         while (!(fs_rl(OTG_CORE_CLK_CTRL) & MODULE_MAIN_CLK)) {
381                 timeout--;
382                 if (!timeout)
383                         break;
384         }
385 }
386
387 void mxc_main_clock_off(void)
388 {
389         u32 timeout = TIMEOUT_VALUE;
390         fs_wl(OTG_CORE_CLK_CTRL, 0);
391         while ((fs_rl(OTG_CORE_CLK_CTRL) & MODULE_MAIN_CLK)) {
392                 timeout--;
393                 if (!timeout)
394                         break;
395         }
396 }
397
398 void mxc_func_clock_on(void)
399 {
400         u32 timeout = TIMEOUT_VALUE;
401         fs_orl(OTG_CORE_CLK_CTRL, MODULE_FUNC_CLK);
402         while (!(fs_rl(OTG_CORE_CLK_CTRL) & MODULE_FUNC_CLK)) {
403                 timeout--;
404                 if (!timeout)
405                         break;
406         }
407 }
408
409 void mxc_func_clock_off(void)
410 {
411         u32 timeout = TIMEOUT_VALUE;
412         fs_andl(OTG_CORE_CLK_CTRL, 0x0);
413         while ((fs_rl(OTG_CORE_CLK_CTRL) & (MODULE_FUNC_CLK | MODULE_MAIN_CLK))) {
414                 timeout--;
415                 if (!timeout)
416                         break;
417         }
418 }