]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx25/karo/v1_0/include/karo_tx25.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / arm / mx25 / karo / v1_0 / include / karo_tx25.h
1 #ifndef CYGONCE_KARO_TX25_H
2 #define CYGONCE_KARO_TX25_H
3
4 //=============================================================================
5 //
6 //      Platform specific support (register layout, etc)
7 //
8 //=============================================================================
9 //####ECOSGPLCOPYRIGHTBEGIN####
10 // -------------------------------------------
11 // This file is part of eCos, the Embedded Configurable Operating System.
12 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 //
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //===========================================================================
42
43 #include <cyg/hal/hal_soc.h>    // Hardware definitions
44
45 #include CYGHWR_MEMORY_LAYOUT_H
46
47 #define SZ_1K                   0x00000400
48 #define SZ_2K                   0x00000800
49 #define SZ_4K                   0x00001000
50 #define SZ_8K                   0x00002000
51 #define SZ_16K                  0x00004000
52 #define SZ_32K                  0x00008000
53 #define SZ_64K                  0x00010000
54 #define SZ_128K                 0x00020000
55 #define SZ_256K                 0x00040000
56 #define SZ_512K                 0x00080000
57 #define SZ_1M                   0x00100000
58 #define SZ_2M                   0x00200000
59 #define SZ_4M                   0x00400000
60 #define SZ_8M                   0x00800000
61 #define SZ_16M                  0x01000000
62 #define SZ_32M                  0x02000000
63 #define SZ_64M                  0x04000000
64 #define SZ_128M                 0x08000000
65 #define SZ_256M                 0x10000000
66 #define SZ_512M                 0x20000000
67 #define SZ_1G                   0x40000000
68
69 #define RAM_BANK0_BASE          CSD0_BASE_ADDR
70 #define RAM_BANK1_BASE          CSD1_BASE_ADDR
71 #if SDRAM_SIZE > SZ_32M
72 #define RAM_BANK0_SIZE          (SDRAM_SIZE / 2)
73 #define RAM_BANK1_SIZE          (SDRAM_SIZE / 2)
74 #else
75 #define RAM_BANK0_SIZE          SDRAM_SIZE
76 #endif
77 #define TX25_SDRAM_SIZE         SDRAM_SIZE
78
79 #define TX25_LED_MASK           (1 << 7)
80 #define TX25_LED_REG_ADDR       (GPIO2_BASE_ADDR + GPIO_DR)
81
82 #define LED_MAX_NUM             1
83
84 #define LED_IS_ON(n) ({                                                 \
85         CYG_WORD32 __val;                                                       \
86         HAL_READ_UINT32(TX25_LED_REG_ADDR, __val);      \
87         __val & TX25_LED_MASK;                                          \
88 })
89
90 #define TURN_LED_ON(n)                                                  \
91     CYG_MACRO_START                                                             \
92         CYG_WORD32 __val;                                                       \
93         HAL_READ_UINT32(TX25_LED_REG_ADDR, __val);      \
94         __val |= TX25_LED_MASK;                                         \
95         HAL_WRITE_UINT32(TX25_LED_REG_ADDR, __val);     \
96     CYG_MACRO_END
97
98 #define TURN_LED_OFF(n)                                                 \
99     CYG_MACRO_START                                                             \
100         CYG_WORD32 __val;                                                       \
101         HAL_READ_UINT32(TX25_LED_REG_ADDR, __val);      \
102         __val &= ~TX25_LED_MASK;                                        \
103         HAL_WRITE_UINT32(TX25_LED_REG_ADDR, __val);     \
104     CYG_MACRO_END
105
106 #define BOARD_DEBUG_LED(n)                                              \
107     CYG_MACRO_START                                                             \
108         if (n >= 0 && n < LED_MAX_NUM) {                        \
109                 if (LED_IS_ON(n))                                               \
110                         TURN_LED_OFF(n);                                        \
111                 else                                                                    \
112                         TURN_LED_ON(n);                                         \
113         }                                                                                       \
114     CYG_MACRO_END
115
116 #define BLINK_LED(l, n)                                                 \
117     CYG_MACRO_START                                                             \
118         int _i;                                                                         \
119         for (_i = 0; _i < (n); _i++) {                          \
120                 BOARD_DEBUG_LED(l);                                             \
121                 HAL_DELAY_US(200000);                                   \
122                 BOARD_DEBUG_LED(l);                                             \
123                 HAL_DELAY_US(300000);                                   \
124         }                                                                                       \
125         HAL_DELAY_US(1000000);                                          \
126     CYG_MACRO_END
127
128 #if !defined(__ASSEMBLER__)
129 enum {
130         BOARD_TYPE_TX25KARO,
131 };
132
133 #define gpio_tst_bit(grp, gpio)         _gpio_tst_bit(grp, gpio, __FUNCTION__, __LINE__)
134 static inline int _gpio_tst_bit(int grp, int gpio, const char *func, int line)
135 {
136         unsigned long val;
137         CYG_ADDRESS reg;
138
139         switch (grp) {
140         case 1:
141                 reg = GPIO1_BASE_ADDR;
142                 break;
143         case 2:
144                 reg = GPIO2_BASE_ADDR;
145                 break;
146         case 3:
147                 reg = GPIO3_BASE_ADDR;
148                 break;
149         case 4:
150                 reg = GPIO4_BASE_ADDR;
151                 break;
152         default:
153                 return 0;
154         }
155
156         if (gpio < 0 || gpio > 31) {
157                 return 0;
158         }
159         val = readl(reg + GPIO_PSR0);
160         return !!(val & (1 << gpio));
161 }
162
163 static inline void gpio_set_bit(int grp, int gpio)
164 {
165         unsigned long val;
166         CYG_ADDRESS reg;
167
168         switch (grp) {
169         case 1:
170                 reg = GPIO1_BASE_ADDR;
171                 break;
172         case 2:
173                 reg = GPIO2_BASE_ADDR;
174                 break;
175         case 3:
176                 reg = GPIO3_BASE_ADDR;
177                 break;
178         case 4:
179                 reg = GPIO4_BASE_ADDR;
180                 break;
181         default:
182                 return;
183         }
184
185         if (gpio < 0 || gpio > 31) {
186                 return;
187         }
188         val = readl(reg + GPIO_DR);
189         writel(val | (1 << gpio), reg + GPIO_DR);
190 }
191
192 static inline void gpio_clr_bit(int grp, int gpio)
193 {
194         unsigned long val;
195         CYG_ADDRESS reg;
196
197         switch (grp) {
198         case 1:
199                 reg = GPIO1_BASE_ADDR;
200                 break;
201         case 2:
202                 reg = GPIO2_BASE_ADDR;
203                 break;
204         case 3:
205                 reg = GPIO3_BASE_ADDR;
206                 break;
207         case 4:
208                 reg = GPIO4_BASE_ADDR;
209                 break;
210         default:
211                 return;
212         }
213
214         if (gpio < 0 || gpio > 31) {
215                 return;
216         }
217         val = readl(reg + GPIO_DR);
218         writel(val & ~(1 << gpio), reg + GPIO_DR);
219 }
220 #endif
221
222 #endif /* CYGONCE_KARO_TX25_H */