pxavoltage.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #include <asm/arch/pxa-regs.h>
  24. #define LTC1663_ADDR 0x20
  25. #define LTC1663_SY 0x01 /* Sync ACK */
  26. #define LTC1663_SD 0x04 /* shutdown */
  27. #define LTC1663_BG 0x04 /* Internal Voltage Ref */
  28. #define VOLT_1_55 18 /* DAC value for 1.55V */
  29. .global initPXAvoltage
  30. @ Set the voltage to 1.55V early in the boot process so we can run
  31. @ at a high clock speed and boot quickly. Note that this is necessary
  32. @ because the reset button does not reset the CPU voltage, so if the
  33. @ voltage was low (say 0.85V) then the CPU would crash without this
  34. @ routine
  35. @ This routine clobbers r0-r4
  36. initializei2c:
  37. ldr r2, =CKEN
  38. ldr r3, [r2]
  39. orr r3, r3, #CKEN15_PWRI2C
  40. str r3, [r2]
  41. ldr r2, =PCFR
  42. ldr r3, [r2]
  43. orr r3, r3, #PCFR_PI2C_EN
  44. str r3, [r2]
  45. /* delay for about 250msec
  46. */
  47. ldr r3, =OSCR
  48. mov r2, #0
  49. str r2, [r3]
  50. ldr r1, =0xC0000
  51. 1:
  52. ldr r2, [r3]
  53. cmp r1, r2
  54. bgt 1b
  55. ldr r0, =PWRICR
  56. ldr r1, [r0]
  57. bic r1, r1, #(ICR_MA | ICR_START | ICR_STOP)
  58. str r1, [r0]
  59. orr r1, r1, #ICR_UR
  60. str r1, [r0]
  61. ldr r2, =PWRISR
  62. ldr r3, =0x7ff
  63. str r3, [r2]
  64. bic r1, r1, #ICR_UR
  65. str r1, [r0]
  66. mov r1, #(ICR_GCD | ICR_SCLE)
  67. str r1, [r0]
  68. orr r1, r1, #ICR_IUE
  69. str r1, [r0]
  70. orr r1, r1, #ICR_FM
  71. str r1, [r0]
  72. /* delay for about 1msec
  73. */
  74. ldr r3, =OSCR
  75. mov r2, #0
  76. str r2, [r3]
  77. ldr r1, =0xC00
  78. 1:
  79. ldr r2, [r3]
  80. cmp r1, r2
  81. bgt 1b
  82. mov pc, lr
  83. sendbytei2c:
  84. ldr r3, =PWRIDBR
  85. str r0, [r3]
  86. ldr r3, =PWRICR
  87. ldr r0, [r3]
  88. orr r0, r0, r1
  89. bic r0, r0, r2
  90. str r0, [r3]
  91. orr r0, r0, #ICR_TB
  92. str r0, [r3]
  93. mov r2, #0x100000
  94. waitfortxemptyi2c:
  95. ldr r0, =PWRISR
  96. ldr r1, [r0]
  97. /* take it from the top if we don't get empty after a while */
  98. subs r2, r2, #1
  99. moveq lr, r4
  100. beq initPXAvoltage
  101. tst r1, #ISR_ITE
  102. beq waitfortxemptyi2c
  103. orr r1, r1, #ISR_ITE
  104. str r1, [r0]
  105. mov pc, lr
  106. initPXAvoltage:
  107. mov r4, lr
  108. bl setleds
  109. bl initializei2c
  110. bl setleds
  111. /* now send the real message to set the correct voltage */
  112. ldr r0, =LTC1663_ADDR
  113. mov r0, r0, LSL #1
  114. mov r1, #ICR_START
  115. ldr r2, =(ICR_STOP | ICR_ALDIE | ICR_ACKNAK)
  116. bl sendbytei2c
  117. bl setleds
  118. mov r0, #LTC1663_BG
  119. mov r1, #0
  120. mov r2, #(ICR_STOP | ICR_START)
  121. bl sendbytei2c
  122. bl setleds
  123. ldr r0, =VOLT_1_55
  124. and r0, r0, #0xff
  125. mov r1, #0
  126. mov r2, #(ICR_STOP | ICR_START)
  127. bl sendbytei2c
  128. bl setleds
  129. ldr r0, =VOLT_1_55
  130. mov r0, r0, ASR #8
  131. and r0, r0, #0xff
  132. mov r1, #ICR_STOP
  133. mov r2, #ICR_START
  134. bl sendbytei2c
  135. bl setleds
  136. @ delay a little for the volatage to stablize
  137. ldr r3, =OSCR
  138. mov r2, #0
  139. str r2, [r3]
  140. ldr r1, =0xC0
  141. 1:
  142. ldr r2, [r3]
  143. cmp r1, r2
  144. bgt 1b
  145. mov pc, r4
  146. setleds:
  147. mov pc, lr
  148. ldr r5, =0x40e00058
  149. ldr r3, [r5]
  150. bic r3, r3, #0x3
  151. str r3, [r5]
  152. ldr r5, =0x40e0000c
  153. ldr r3, [r5]
  154. orr r3, r3, #0x00010000
  155. str r3, [r5]
  156. @ inner loop
  157. mov r0, #0x2
  158. 1:
  159. ldr r5, =0x40e00018
  160. mov r3, #0x00010000
  161. str r3, [r5]
  162. @ outer loop
  163. mov r3, #0x00F00000
  164. 2:
  165. subs r3, r3, #1
  166. bne 2b
  167. ldr r5, =0x40e00024
  168. mov r3, #0x00010000
  169. str r3, [r5]
  170. @ outer loop
  171. mov r3, #0x00F00000
  172. 3:
  173. subs r3, r3, #1
  174. bne 3b
  175. subs r0, r0, #1
  176. bne 1b
  177. mov pc, lr