summaryrefslogtreecommitdiff
path: root/src/mainboard/momentum/apache/timerspeed.S
blob: 483a2aa3441d9674062fa9b321d05e7287b327b0 (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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#include <ppc970.h>

/*----------------------------------------------------------------------------+
| Cycle counts ((1/ 9600)* 10) / (1/speed)) - 2%.
+----------------------------------------------------------------------------*/
#define	SPEED_6_25    		(0x0000196E- (65* 2))
#define SPEED_7_159		(0x00001D21- (74* 2))
#define	SPEED_8_33    		(0x000021E5- (86* 2))
#define	SPEED_10_4    		(0x00002A51- (108* 2))
#define SPEED_14_318		(0x00003A42- (149* 2))
#define	SPEED_16_66    		(0x000043D0- (173* 2))
#define	SPEED_25    		(0x000065B9- (260* 2))
#define	SPEED_33    		(0x000087A2- (347* 2))
#define	SPEED_40    		(0x0000A2C2- (416* 2))
#define	SPEED_50    		(0x0000CB73- (520* 2))
#define	SPEED_66    		(0x00010C8E- (687* 2))
#define	SPEED_80    		(0x00014585- (833* 2))
#define	SPEED_100    		(0x000196E6- (1041* 2))
#define	SPEED_125    		(0x0001FCA0- (1302* 2))
#define	SPEED_133    		(0x00021D2D- (1385* 2))
#define	SPEED_150    		(0x0002625A- (1562* 2))
#define	SPEED_166    		(0x0002A374- (1729* 2))
#define	SPEED_175    		(0x0002C813- (1822* 2))
#define	SPEED_200    		(0x00032DCD- (2093* 2))
#define	SPEED_225    		(0x00039387- (2343* 2))
#define	SPEED_250    		(0x0003F940- (2604* 2))
#define	SPEED_275    		(0x00045EFA- (2864* 2))
#define	SPEED_300    		(0x0004C4B4- (3125* 2))
#define	SPEED_3375    		(0x00055D4A- (3515* 2))
#define	SPEED_375    		(0x0005F5E1- (3906* 2))
#define	SPEED_400    		(0x00065B9A- (4166* 2))
#define	SPEED_433    		(0x0006E1E1- (4510* 2))
#define	SPEED_466	    	(0x00076828- (4854* 2))
#define	SPEED_500    		(0x0007F281- (5208* 2))

/*----------------------------------------------------------------------------+
| Timebase_speed_calc
+----------------------------------------------------------------------------*/
	function_prolog(timebase_speed_calc)
	mfmsr	r10
	rlwinm	r11,r10,0,17,15
	mtmsrd	r11,1
	isync
        /*--------------------------------------------------------------------+
        | Make sure that all the characters in the transmit buffer are sent.
        +--------------------------------------------------------------------*/
..sent: lbz	r6,asyncLSR(r3)
	andi.	r6,r6,0x0060
	cmpi	cr0,1,r6,0x0060
	bne	..sent
        /*--------------------------------------------------------------------+
        | Store current serial port settings in r11, r12.
        | r11 BH (baud high), BL (baud low), LCR
        | r12 MCR, IER, FCR
        +--------------------------------------------------------------------*/
	lbz	r4,asyncLCR(r3)
	ori	r11,r4,0x0000
	lbz	r4,asyncFCR(r3)
	ori	r12,r4,0x0000
	lbz	r4,asyncIER(r3)
	rlwimi	r12,r4,8,16,23
	lbz	r4,asyncMCR(r3)
	rlwimi	r12,r4,16,8,15
        /*--------------------------------------------------------------------+
        | Store BH and BL and program new baud rate.
        +--------------------------------------------------------------------*/
	addi    r4,r0,0x80   	
	stb     r4,asyncLCR(r3)
	lbz	r4,asyncDLABMsb(r3)
	rlwimi  r11,r4,16,8,15
	addi    r4,r0,DIV_HIGH_9600
	stb	r4,asyncDLABMsb(r3)
	lbz	r4,asyncDLABLsb(r3)
	rlwimi  r11,r4,8,16,23
	addi    r4,r0,DIV_LOW_9600
	stb     r4,asyncDLABLsb(r3)
	addi    r4,r0,0x03   	
	stb     r4,asyncLCR(r3)
        /*--------------------------------------------------------------------+
        | Put the serial port in loop-back mode.
        +--------------------------------------------------------------------*/
	addi    r4,r0,0x00   	
	stb     r4,asyncFCR(r3)
	stb     r4,asyncIER(r3)
	addi    r4,r0,0x10
	stb     r4,asyncMCR(r3)
        lbz	r4,asyncRxBuffer(r3)
	addi    r4,r0,0x0041	
        /*--------------------------------------------------------------------+
        | Again make sure there are no characters in transmit buffer.
        +--------------------------------------------------------------------*/
        addi	r5,r0,0
..again:lbz	r6,asyncLSR(r3)
	andi.	r6,r6,0x0060
	cmpi	cr0,1,r6,0x0060
	bne	..again
        /*--------------------------------------------------------------------+
        | Take a snapshot of the timebase.
        +--------------------------------------------------------------------*/
        mfspr   r7,tblr
        /*--------------------------------------------------------------------+
        | Send a character while in loopback mode.  This will be done twice.
        | Once to get the instuctions into I-cache, the second time for the
        | real measurement.
        +--------------------------------------------------------------------*/
	stb     r4,asyncTxBuffer(r3)
..spnlp:lbz     r6,asyncLSR(r3)
        andi.   r6,r6,0x01
        beq     ..spnlp
	mfspr	r9,tblr
        /*--------------------------------------------------------------------+
        | Perform subtraction to determine how many timebase ticks it took
        | to transmit the character.
        +--------------------------------------------------------------------*/
        subfc   r9,r7,r9
        /*--------------------------------------------------------------------+
        | Consume the character sent in loopback mode.
        +--------------------------------------------------------------------*/
        lbz     r4,asyncRxBuffer(r3)
	eieio
        /*--------------------------------------------------------------------+
        | If the first character was just sent, go back and send a second.
        +--------------------------------------------------------------------*/
        cmpi	cr0,1,r5,0x0000
        addi	r5,r5,1
        beq	..again
        /*--------------------------------------------------------------------+
        | Restore serial port settings.
        +--------------------------------------------------------------------*/
	addi    r4,r0,0x80   	
	stb     r4,asyncLCR(r3)
	rlwinm	r4,r11,16,24,31
	stb     r4,asyncDLABMsb(r3)
	rlwinm	r4,r11,24,24,31
	stb     r4,asyncDLABLsb(r3)
	rlwinm	r4,r11,0,24,31
	stb     r4,asyncLCR(r3)
	rlwinm	r4,r12,16,24,31
	stb     r4,asyncMCR(r3)
	rlwinm	r4,r12,24,24,31
	stb     r4,asyncIER(r3)
	rlwinm	r4,r12,0,24,31
	stb     r4,asyncFCR(r3)
        /*--------------------------------------------------------------------+
        | Calculate timebase speed (r9 is the time we are referencing).
        +--------------------------------------------------------------------*/
	addis	r4,r0,SPEED_7_159@h
	ori	r4,r4,SPEED_7_159@l
	cmp	cr0,r9,r4
	blt	..freq6		
	addis	r4,r0,SPEED_8_33@h
	ori	r4,r4,SPEED_8_33@l
	cmp	cr0,r9,r4
	blt	..freq7		
        addis   r4,r0,SPEED_10_4@h
        ori     r4,r4,SPEED_10_4@l
	cmp	cr0,r9,r4
	blt	..freq8		
        addis   r4,r0,SPEED_14_318@h
        ori     r4,r4,SPEED_14_318@l
	cmp	cr0,r9,r4
	blt	..freq10
        addis   r4,r0,SPEED_16_66@h
        ori     r4,r4,SPEED_16_66@l
	cmp	cr0,r9,r4
	blt	..freq14
        addis   r4,r0,SPEED_25@h
        ori     r4,r4,SPEED_25@l
	cmp	cr0,r9,r4
	blt	..freq16
        addis   r4,r0,SPEED_33@h
        ori     r4,r4,SPEED_33@l
	cmp	cr0,r9,r4
	blt	..freq25
        addis   r4,r0,SPEED_40@h
        ori     r4,r4,SPEED_40@l
        cmp     cr0,r9,r4
	blt     ..freq33
        addis   r4,r0,SPEED_50@h
        ori     r4,r4,SPEED_50@l
        cmp     cr0,r9,r4
        blt     ..freq40
        addis   r4,r0,SPEED_66@h
        ori     r4,r4,SPEED_66@l
        cmp     cr0,r9,r4
        blt     ..freq50
        addis   r4,r0,SPEED_80@h
        ori     r4,r4,SPEED_80@l
        cmp     cr0,r9,r4
        blt     ..freq66
        addis   r4,r0,SPEED_100@h
        ori     r4,r4,SPEED_100@l
        cmp     cr0,r9,r4
        blt     ..freq80
        addis   r4,r0,SPEED_125@h
        ori     r4,r4,SPEED_125@l
        cmp     cr0,r9,r4
        blt     ..freq100
        addis   r4,r0,SPEED_133@h
        ori     r4,r4,SPEED_133@l
        cmp     cr0,r9,r4
        blt     ..freq125
        addis   r4,r0,SPEED_150@h
        ori     r4,r4,SPEED_150@l
        cmp     cr0,r9,r4
        blt     ..freq133
        addis   r4,r0,SPEED_166@h
        ori     r4,r4,SPEED_166@l
        cmp     cr0,r9,r4
        blt     ..freq150
        addis   r4,r0,SPEED_175@h
        ori     r4,r4,SPEED_175@l
        cmp     cr0,r9,r4
        blt     ..freq166
        addis   r4,r0,SPEED_200@h
        ori     r4,r4,SPEED_200@l
        cmp     cr0,r9,r4
        blt     ..freq175
        addis   r4,r0,SPEED_225@h
        ori     r4,r4,SPEED_225@l
        cmp     cr0,r9,r4
        blt     ..freq200
        addis   r4,r0,SPEED_250@h
	ori	r4,r4,SPEED_250@l
        cmp     cr0,r9,r4
        blt     ..freq225
        addis   r4,r0,SPEED_275@h
	ori	r4,r4,SPEED_275@l
        cmp     cr0,r9,r4
        blt     ..freq250
        addis   r4,r0,SPEED_300@h
	ori	r4,r4,SPEED_300@l
        cmp     cr0,r9,r4
        blt     ..freq275
        addis   r4,r0,SPEED_3375@h
	ori	r4,r4,SPEED_3375@l
        cmp     cr0,r9,r4
        blt     ..freq300
        addis   r4,r0,SPEED_375@h
	ori	r4,r4,SPEED_375@l
        cmp     cr0,r9,r4
        blt     ..freq3375
        addis   r4,r0,SPEED_400@h
	ori	r4,r4,SPEED_400@l
        cmp     cr0,r9,r4
        blt     ..freq375
        addis   r4,r0,SPEED_433@h
	ori	r4,r4,SPEED_433@l
        cmp     cr0,r9,r4
        blt     ..freq400
        addis   r4,r0,SPEED_466@h
	ori	r4,r4,SPEED_466@l
        cmp     cr0,r9,r4
        blt     ..freq433
        addis   r4,r0,SPEED_500@h
	ori	r4,r4,SPEED_500@l
        cmp     cr0,r9,r4
        blt     ..freq466
        b       ..freq500
..freq6:
	addis   r3,r0,0x005F
        ori     r3,r3,0x5e10
	b	..end
..freq7:
	addis   r3,r0,0x006D
        ori     r3,r3,0x3CD8
	b	..end
..freq8:
	addis   r3,r0,0x007F
        ori     r3,r3,0x2815
	b	..end
..freq10:
	addis   r3,r0,0x009e
        ori     r3,r3,0xb100
	b	..end
..freq14:
	addis   r3,r0,0x00da
        ori     r3,r3,0x79b0
	b	..end
..freq16:
	addis   r3,r0,0x00fe
        ori     r3,r3,0x502A
	b	..end
..freq25:
	addis   r3,r0,0x017D
        ori     r3,r3,0x7840
	b	..end
..freq33:
	addis   r3,r0,0x01FC
        ori     r3,r3,0xA055
        b       ..end
..freq40:
	addis   r3,r0,0x0262
        ori     r3,r3,0x5A00
        b       ..end
..freq50:
	addis   r3,r0,0x02FA
        ori     r3,r3,0xF080
        b       ..end
..freq66:
	addis   r3,r0,0x03F9
        ori     r3,r3,0x40AA
        b       ..end
..freq80:
	addis   r3,r0,0x04C4
        ori     r3,r3,0xB400
        b       ..end
..freq100:
	addis   r3,r0,0x05F5
        ori     r3,r3,0xE100
        b       ..end
..freq125:
	addis   r3,r0,0x0773
        ori     r3,r3,0x5940
        b       ..end
..freq133:
	addis   r3,r0,0x07F2
        ori     r3,r3,0x8155
        b       ..end
..freq150:
	addis   r3,r0,0x08F0
        ori     r3,r3,0xD180
        b       ..end
..freq166:
	addis   r3,r0,0x09EF
        ori     r3,r3,0x21AA
        b       ..end
..freq175:
	addis   r3,r0,0x0A6E
        ori     r3,r3,0x49C0
        b       ..end
..freq200:
	addis   r3,r0,0x0BEB
        ori     r3,r3,0xC200
        b       ..end
..freq225:
	addis   r3,r0,0x0D69
        ori     r3,r3,0x3A40
        b       ..end
..freq250:
	addis   r3,r0,0x0EE6
        ori     r3,r3,0xB280
        b       ..end
..freq275:
	addis   r3,r0,0x1064
        ori     r3,r3,0x2AC0
        b       ..end
..freq300:
	addis   r3,r0,0x11E1
        ori     r3,r3,0xA300
        b       ..end
..freq3375:
	addis   r3,r0,0x141D
        ori     r3,r3,0xD760
        b       ..end
..freq375:
	addis   r3,r0,0x165A
        ori     r3,r3,0x0BC0
        b       ..end
..freq400:
	addis   r3,r0,0x17D7
        ori     r3,r3,0x8400
        b       ..end
..freq433:
	addis   r3,r0,0x19CF
        ori     r3,r3,0x0E40
        b       ..end
..freq466:
	addis   r3,r0,0x1BC6
        ori     r3,r3,0x9880
        b       ..end
..freq500:
	addis   r3,r0,0x1DCD
        ori     r3,r3,0x6500
..end:  mtmsrd	r10,1
	isync
	blr
	function_epilog(timebase_speed_calc)