summaryrefslogtreecommitdiff
path: root/arch/arm/cpu/arm926ejs/aspeed/IO.c
blob: 86e991846b17477d869d5443a51c9a658cf300ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#define IO_C
static const char ThisFile[] = "IO.c";

#include "SWFUNC.H"

#if defined(LinuxAP)
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
  #include <stdarg.h>
  #include <unistd.h>
  #include <string.h>
  #include <fcntl.h>
  #include <pthread.h>
  #include <sys/mman.h>
  #include <sys/io.h>
#endif
#ifdef SLT_UBOOT
  #include <common.h>
  #include <command.h>
  #include <post.h>
  #include <malloc.h>
  #include <net.h>
  #include <COMMINF.H>
#endif
#ifdef SLT_DOS
  #include <stdlib.h>
  #include <stdio.h>
  #include <time.h>
  #include <conio.h>
  #include <dos.h>
  #include <mem.h>
  #include "TYPEDEF.H"
  #include "LIB.H"
  #include "COMMINF.H"
#endif

#include "TYPEDEF.H"
#include "IO.H"
#include "LIB_SPI.H"

#ifdef SPI_BUS
#endif
#ifdef USE_LPC
    USHORT	usLPCPort;
#endif
#ifdef USE_P2A
#endif

#ifdef USE_LPC
//------------------------------------------------------------
// LPC access
//------------------------------------------------------------
void open_aspeed_sio_password(void)
{
    ob (usLPCPort, 0xaa);

    ob (usLPCPort, 0xa5);
    ob (usLPCPort, 0xa5);
}

//------------------------------------------------------------
void close_aspeed_sio_password(void)
{
    ob (usLPCPort, 0xaa);
}

//------------------------------------------------------------
void enable_aspeed_LDU(BYTE jldu_number)
{
    ob (usLPCPort, 0x07);
    ob ((usLPCPort + 1), jldu_number);
    ob (usLPCPort, 0x30);
    ob ((usLPCPort + 1), 0x01);
}

//------------------------------------------------------------
void disable_aspeed_LDU(BYTE jldu_number)
{
    ob (usLPCPort, 0x07);
    ob ((usLPCPort + 1), jldu_number);
    ob (usLPCPort, 0x30);
    ob ((usLPCPort + 1), 0x00);
}

//------------------------------------------------------------
/*
ulAddress = AHB address
jmode = 0: byte mode
        1: word mode
        2: dword mode
*/
static ULONG lpc_read (ULONG ulAddress, BYTE jmode)
{
    ULONG    uldata = 0;
    ULONG    ultemp = 0;
    BYTE     jtemp;

    //Write Address
    ob (  usLPCPort,        0xf0);
    ob ( (usLPCPort + 1  ), ((ulAddress & 0xff000000) >> 24));
    ob (  usLPCPort,        0xf1);
    ob ( (usLPCPort + 1)  , ((ulAddress & 0x00ff0000) >> 16));
    ob (  usLPCPort,        0xf2);
    ob ( (usLPCPort + 1),   ((ulAddress & 0x0000ff00) >> 8));
    ob (  usLPCPort,        0xf3);
    ob ( (usLPCPort + 1),   ulAddress & 0xff);
    
    //Write Mode
    ob (usLPCPort, 0xf8);
    jtemp = ib ((usLPCPort + 1));
    ob ((usLPCPort + 1), ((jtemp & 0xfc) | jmode));
    
    //Fire
    ob (usLPCPort, 0xfe);
    jtemp = ib ((usLPCPort + 1));
    
    //Get Data
    switch ( jmode )
    {
        case 0:
            ob (usLPCPort, 0xf7);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp);
            break;
        
        case 1:
            ob (usLPCPort, 0xf6);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp << 8);
            ob (usLPCPort, 0xf7);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp << 0);
            break;
        
        case 2:
            ob (usLPCPort, 0xf4);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp << 24);
            ob (usLPCPort, 0xf5);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp << 16);
            ob (usLPCPort, 0xf6);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= (ultemp << 8);
            ob (usLPCPort, 0xf7);
            ultemp  = ib ((usLPCPort + 1));
            uldata |= ultemp;
            break;
    } // End switch ( jmode )

    return uldata;
} // End static ULONG lpc_read (ULONG ulAddress, BYTE jmode)

//------------------------------------------------------------
static void lpc_write (ULONG ulAddress, ULONG uldata, BYTE jmode)
{
    BYTE     jtemp;

    //Write Address
    ob ( usLPCPort,      0xf0);
    ob ((usLPCPort + 1), ((ulAddress & 0xff000000) >> 24));
    ob ( usLPCPort,      0xf1);
    ob ((usLPCPort + 1), ((ulAddress & 0x00ff0000) >> 16));
    ob ( usLPCPort,      0xf2);
    ob ((usLPCPort + 1), ((ulAddress & 0x0000ff00) >> 8));
    ob ( usLPCPort,      0xf3);
    ob ((usLPCPort + 1), ulAddress & 0xff);
    
    //Write Data
    switch ( jmode )
    {
        case 0:
            ob ( usLPCPort,      0xf7);
            ob ((usLPCPort + 1), (uldata & 0xff));
            break;
        case 1:
            ob ( usLPCPort,      0xf6);
            ob ((usLPCPort + 1), ((uldata & 0xff00) >> 8));
            ob ( usLPCPort,      0xf7);
            ob ((usLPCPort + 1), (uldata & 0x00ff));
            break;
        case 2:
            ob ( usLPCPort,      0xf4);
            ob ((usLPCPort + 1), ((uldata & 0xff000000) >> 24));
            ob ( usLPCPort,      0xf5);
            ob ((usLPCPort + 1), ((uldata & 0x00ff0000) >> 16));
            ob ( usLPCPort,      0xf6);
            ob ((usLPCPort + 1), ((uldata & 0x0000ff00) >> 8));
            ob ( usLPCPort,      0xf7);
            ob ((usLPCPort + 1), uldata & 0xff);
            break;
    } // End switch ( jmode )
    
    //Write Mode
    ob (usLPCPort, 0xf8);
    jtemp = ib ((usLPCPort + 1));
    ob ((usLPCPort + 1), ((jtemp & 0xfc) | jmode));

    //Fire
    ob (usLPCPort, 0xfe);
    ob ((usLPCPort + 1), 0xcf);
    
} // End static void lpc_write (ULONG ulAddress, ULONG uldata, BYTE jmode)

//------------------------------------------------------------
static USHORT usLPCPortList[] = {0x2e, 0x4e, 0xff};
int findlpcport(BYTE jldu_number)
{
    USHORT  *jLPCPortPtr;
    ULONG   ulData;

    jLPCPortPtr = usLPCPortList;
    while (*(USHORT *)(jLPCPortPtr) != 0xff )
    {
        usLPCPort = *(USHORT *)(jLPCPortPtr++);

        open_aspeed_sio_password();
        enable_aspeed_LDU(0x0d);

        ulData  = lpc_read(0x1e6e207c, 2);
        
        if ( (ulData != 0x00000000)	&&
             (ulData != 0xFFFFFFFF)   )
        {
            printf("Find LPC IO port at 0x%2x \n", usLPCPort);
            return 1;
        }

        disable_aspeed_LDU(0x0d);
        close_aspeed_sio_password();
    }

    //printf("[Error] Fail to find proper LPC IO Port \n");
    return 0;
}
#endif // End ifdef USE_LPC

#ifdef USE_P2A
//------------------------------------------------------------
// A2P Access
//------------------------------------------------------------
void mm_write (ULONG addr, ULONG data, BYTE jmode)
{
    *(ULONG *) (mmiobase + 0xF004) = (ULONG) ((addr) & 0xFFFF0000);
    *(ULONG *) (mmiobase + 0xF000) = (ULONG) 0x00000001;
    
    switch ( jmode )
    {
        case 0:
            *(BYTE *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) = (BYTE) data;
            break;
        case 1:
            *(USHORT *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) = (USHORT) data;
            break;
        case 2:
        default:
            *(ULONG *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) = data;
            break;
    } //switch
}

//------------------------------------------------------------
ULONG mm_read (ULONG addr, BYTE jmode)
{
    *(ULONG *) (mmiobase + 0xF004) = (ULONG) ((addr) & 0xFFFF0000);
    *(ULONG *) (mmiobase + 0xF000) = (ULONG) 0x00000001;
    switch (jmode)
    {
    case 0:
        return ( *(BYTE *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) );
        break;
    case 1:
        return ( *(USHORT *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) );
        break;
    default:
    case 2:
        return ( *(ULONG *) (mmiobase + 0x10000 + ((addr) & 0x0000FFFF)) );
        break;
    } //switch

    return 0;
}
#endif // End ifdef USE_P2A

//------------------------------------------------------------
// General Access API
//------------------------------------------------------------
#ifdef SLT_UBOOT
BYTE Check_BEorLN ( ULONG chkaddr )
{
    BYTE ret = BIG_ENDIAN_ADDRESS;
    BYTE i   = 0;
    
    do {
        if ( LittleEndianArea[i].StartAddr == LittleEndianArea[i].EndAddr )
            break;
        
        if ( ( LittleEndianArea[i].StartAddr <= chkaddr ) &&
             ( LittleEndianArea[i].EndAddr   >= chkaddr )    ) {
            ret = LITTLE_ENDIAN_ADDRESS;
            break;
        }
        i++;
    } while ( 1 );
    
    return ret;
}
#endif

void WriteSOC_DD(ULONG addr, ULONG data)
{
#ifdef SLT_UBOOT
    if ( Check_BEorLN( addr ) == BIG_ENDIAN_ADDRESS )
        *(volatile unsigned long *)(addr) = cpu_to_le32(data);
    else
        *(volatile unsigned long *)(addr) = data;
#else
    #ifdef USE_LPC
        lpc_write(addr, data, 2);
    #endif
    #ifdef USE_P2A
        mm_write(addr, data, 2);
    #endif
#endif
}

//------------------------------------------------------------
ULONG ReadSOC_DD(ULONG addr)
{
#ifdef SLT_UBOOT
    if ( Check_BEorLN( addr ) == BIG_ENDIAN_ADDRESS )
        return le32_to_cpu(*(volatile unsigned long *) (addr));
    else
        return (*(volatile unsigned long *) (addr));
#else
    #ifdef USE_LPC
        return (lpc_read(addr, 2));
    #endif
    #ifdef USE_P2A
        return (mm_read(addr, 2));
    #endif
#endif
    return 0;
}