]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/adsvix/pxavoltage.S
ppc4xx: ML507: Environment in flash and MTD Support
[karo-tx-uboot.git] / board / adsvix / pxavoltage.S
1 /*
2  * (C) Copyright 2004
3  * Robert Whaley, Applied Data Systems, Inc. rwhaley@applieddata.net
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <asm/arch/pxa-regs.h>
25
26 #define LTC1663_ADDR    0x20
27
28 #define LTC1663_SY      0x01    /* Sync ACK */
29 #define LTC1663_SD      0x04    /* shutdown */
30 #define LTC1663_BG      0x04    /* Internal Voltage Ref */
31
32 #define VOLT_1_55         18    /* DAC value for 1.55V */
33
34                 .global initPXAvoltage
35
36 @ Set the voltage to 1.55V early in the boot process so we can run
37 @ at a high clock speed and boot quickly.  Note that this is necessary
38 @ because the reset button does not reset the CPU voltage, so if the
39 @ voltage was low (say 0.85V) then the CPU would crash without this
40 @ routine
41
42 @ This routine clobbers r0-r4
43
44 initializei2c:
45
46                 ldr     r2, =CKEN
47                 ldr     r3, [r2]
48                 orr     r3, r3, #CKEN15_PWRI2C
49                 str     r3, [r2]
50
51                 ldr     r2, =PCFR
52                 ldr     r3, [r2]
53                 orr     r3, r3, #PCFR_PI2C_EN
54                 str     r3, [r2]
55
56                 /* delay for about 250msec
57                  */
58                 ldr     r3, =OSCR
59                 mov     r2, #0
60                 str     r2, [r3]
61                 ldr     r1, =0xC0000
62
63 1:
64                 ldr     r2, [r3]
65                 cmp     r1, r2
66                 bgt     1b
67                 ldr     r0, =PWRICR
68                 ldr     r1, [r0]
69                 bic     r1, r1, #(ICR_MA | ICR_START | ICR_STOP)
70                 str     r1, [r0]
71
72                 orr     r1, r1, #ICR_UR
73                 str     r1, [r0]
74
75                 ldr     r2, =PWRISR
76                 ldr     r3, =0x7ff
77                 str     r3, [r2]
78
79                 bic     r1, r1, #ICR_UR
80                 str     r1, [r0]
81
82                 mov     r1, #(ICR_GCD | ICR_SCLE)
83                 str     r1, [r0]
84
85                 orr     r1, r1, #ICR_IUE
86                 str     r1, [r0]
87
88                 orr     r1, r1, #ICR_FM
89                 str     r1, [r0]
90
91                 /* delay for about 1msec
92                  */
93                 ldr     r3, =OSCR
94                 mov     r2, #0
95                 str     r2, [r3]
96                 ldr     r1, =0xC00
97
98 1:
99                 ldr     r2, [r3]
100                 cmp     r1, r2
101                 bgt     1b
102                 mov     pc, lr
103
104 sendbytei2c:
105                 ldr     r3, =PWRIDBR
106                 str     r0, [r3]
107                 ldr     r3, =PWRICR
108                 ldr     r0, [r3]
109                 orr     r0, r0, r1
110                 bic     r0, r0, r2
111                 str     r0, [r3]
112                 orr     r0, r0, #ICR_TB
113                 str     r0, [r3]
114
115                 mov     r2, #0x100000
116
117 waitfortxemptyi2c:
118
119                 ldr     r0, =PWRISR
120                 ldr     r1, [r0]
121
122                 /* take it from the top if we don't get empty after a while */
123                 subs    r2, r2, #1
124                 moveq   lr, r4
125                 beq     initPXAvoltage
126
127                 tst     r1, #ISR_ITE
128
129                 beq     waitfortxemptyi2c
130
131                 orr     r1, r1, #ISR_ITE
132                 str     r1, [r0]
133
134                 mov     pc, lr
135
136 initPXAvoltage:
137
138                 mov     r4, lr
139
140                 bl      setleds
141
142                 bl      initializei2c
143
144                 bl      setleds
145
146                 /* now send the real message to set the correct voltage */
147                 ldr     r0, =LTC1663_ADDR
148                 mov     r0, r0, LSL #1
149                 mov     r1, #ICR_START
150                 ldr     r2, =(ICR_STOP | ICR_ALDIE | ICR_ACKNAK)
151                 bl      sendbytei2c
152
153                 bl      setleds
154
155                 mov     r0, #LTC1663_BG
156                 mov     r1, #0
157                 mov     r2, #(ICR_STOP | ICR_START)
158                 bl      sendbytei2c
159
160                 bl      setleds
161
162                 ldr     r0, =VOLT_1_55
163                 and     r0, r0, #0xff
164                 mov     r1, #0
165                 mov     r2, #(ICR_STOP | ICR_START)
166                 bl      sendbytei2c
167
168                 bl      setleds
169
170                 ldr     r0, =VOLT_1_55
171                 mov     r0, r0, ASR #8
172                 and     r0, r0, #0xff
173                 mov     r1, #ICR_STOP
174                 mov     r2, #ICR_START
175                 bl      sendbytei2c
176
177                 bl      setleds
178
179                 @ delay a little for the volatage to stablize
180                 ldr     r3, =OSCR
181                 mov     r2, #0
182                 str     r2, [r3]
183                 ldr     r1, =0xC0
184
185 1:
186                 ldr     r2, [r3]
187                 cmp     r1, r2
188                 bgt     1b
189                 mov     pc, r4
190
191 setleds:
192         mov             pc, lr
193
194         ldr             r5, =0x40e00058
195         ldr             r3, [r5]
196         bic             r3, r3, #0x3
197         str             r3, [r5]
198         ldr             r5, =0x40e0000c
199         ldr             r3, [r5]
200         orr             r3, r3, #0x00010000
201         str             r3, [r5]
202
203         @ inner loop
204         mov             r0, #0x2
205 1:
206
207         ldr             r5, =0x40e00018
208         mov             r3, #0x00010000
209         str             r3, [r5]
210
211         @ outer loop
212         mov             r3, #0x00F00000
213 2:
214         subs            r3, r3, #1
215         bne             2b
216
217         ldr             r5, =0x40e00024
218         mov             r3, #0x00010000
219         str             r3, [r5]
220
221         @ outer loop
222         mov             r3, #0x00F00000
223 3:
224         subs            r3, r3, #1
225         bne             3b
226
227         subs            r0, r0, #1
228         bne             1b
229
230         mov             pc, lr