pixis.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright 2006 Freescale Semiconductor
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <watchdog.h>
  26. #include <command.h>
  27. #include <asm/cache.h>
  28. #include <mpc86xx.h>
  29. #include "pixis.h"
  30. /*
  31. * Per table 27, page 58 of MPC8641HPCN spec.
  32. */
  33. int set_px_sysclk(ulong sysclk)
  34. {
  35. u8 sysclk_s, sysclk_r, sysclk_v, vclkh, vclkl, sysclk_aux;
  36. switch (sysclk) {
  37. case 33:
  38. sysclk_s = 0x04;
  39. sysclk_r = 0x04;
  40. sysclk_v = 0x07;
  41. sysclk_aux = 0x00;
  42. break;
  43. case 40:
  44. sysclk_s = 0x01;
  45. sysclk_r = 0x1F;
  46. sysclk_v = 0x20;
  47. sysclk_aux = 0x01;
  48. break;
  49. case 50:
  50. sysclk_s = 0x01;
  51. sysclk_r = 0x1F;
  52. sysclk_v = 0x2A;
  53. sysclk_aux = 0x02;
  54. break;
  55. case 66:
  56. sysclk_s = 0x01;
  57. sysclk_r = 0x04;
  58. sysclk_v = 0x04;
  59. sysclk_aux = 0x03;
  60. break;
  61. case 83:
  62. sysclk_s = 0x01;
  63. sysclk_r = 0x1F;
  64. sysclk_v = 0x4B;
  65. sysclk_aux = 0x04;
  66. break;
  67. case 100:
  68. sysclk_s = 0x01;
  69. sysclk_r = 0x1F;
  70. sysclk_v = 0x5C;
  71. sysclk_aux = 0x05;
  72. break;
  73. case 134:
  74. sysclk_s = 0x06;
  75. sysclk_r = 0x1F;
  76. sysclk_v = 0x3B;
  77. sysclk_aux = 0x06;
  78. break;
  79. case 166:
  80. sysclk_s = 0x06;
  81. sysclk_r = 0x1F;
  82. sysclk_v = 0x4B;
  83. sysclk_aux = 0x07;
  84. break;
  85. default:
  86. printf("Unsupported SYSCLK frequency.\n");
  87. return 0;
  88. }
  89. vclkh = (sysclk_s << 5) | sysclk_r;
  90. vclkl = sysclk_v;
  91. out8(PIXIS_BASE + PIXIS_VCLKH, vclkh);
  92. out8(PIXIS_BASE + PIXIS_VCLKL, vclkl);
  93. out8(PIXIS_BASE + PIXIS_AUX, sysclk_aux);
  94. return 1;
  95. }
  96. int set_px_mpxpll(ulong mpxpll)
  97. {
  98. u8 tmp;
  99. u8 val;
  100. switch (mpxpll) {
  101. case 2:
  102. case 4:
  103. case 6:
  104. case 8:
  105. case 10:
  106. case 12:
  107. case 14:
  108. case 16:
  109. val = (u8) mpxpll;
  110. break;
  111. default:
  112. printf("Unsupported MPXPLL ratio.\n");
  113. return 0;
  114. }
  115. tmp = in8(PIXIS_BASE + PIXIS_VSPEED1);
  116. tmp = (tmp & 0xF0) | (val & 0x0F);
  117. out8(PIXIS_BASE + PIXIS_VSPEED1, tmp);
  118. return 1;
  119. }
  120. int set_px_corepll(ulong corepll)
  121. {
  122. u8 tmp;
  123. u8 val;
  124. switch ((int)corepll) {
  125. case 20:
  126. val = 0x08;
  127. break;
  128. case 25:
  129. val = 0x0C;
  130. break;
  131. case 30:
  132. val = 0x10;
  133. break;
  134. case 35:
  135. val = 0x1C;
  136. break;
  137. case 40:
  138. val = 0x14;
  139. break;
  140. case 45:
  141. val = 0x0E;
  142. break;
  143. default:
  144. printf("Unsupported COREPLL ratio.\n");
  145. return 0;
  146. }
  147. tmp = in8(PIXIS_BASE + PIXIS_VSPEED0);
  148. tmp = (tmp & 0xE0) | (val & 0x1F);
  149. out8(PIXIS_BASE + PIXIS_VSPEED0, tmp);
  150. return 1;
  151. }
  152. void read_from_px_regs(int set)
  153. {
  154. u8 mask = 0x1C;
  155. u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  156. if (set)
  157. tmp = tmp | mask;
  158. else
  159. tmp = tmp & ~mask;
  160. out8(PIXIS_BASE + PIXIS_VCFGEN0, tmp);
  161. }
  162. void read_from_px_regs_altbank(int set)
  163. {
  164. u8 mask = 0x04;
  165. u8 tmp = in8(PIXIS_BASE + PIXIS_VCFGEN1);
  166. if (set)
  167. tmp = tmp | mask;
  168. else
  169. tmp = tmp & ~mask;
  170. out8(PIXIS_BASE + PIXIS_VCFGEN1, tmp);
  171. }
  172. void set_altbank(void)
  173. {
  174. u8 tmp;
  175. tmp = in8(PIXIS_BASE + PIXIS_VBOOT);
  176. tmp ^= 0x40;
  177. out8(PIXIS_BASE + PIXIS_VBOOT, tmp);
  178. }
  179. void set_px_go(void)
  180. {
  181. u8 tmp;
  182. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  183. tmp = tmp & 0x1E;
  184. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  185. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  186. tmp = tmp | 0x01;
  187. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  188. }
  189. void set_px_go_with_watchdog(void)
  190. {
  191. u8 tmp;
  192. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  193. tmp = tmp & 0x1E;
  194. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  195. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  196. tmp = tmp | 0x09;
  197. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  198. }
  199. int disable_watchdog(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  200. {
  201. u8 tmp;
  202. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  203. tmp = tmp & 0x1E;
  204. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  205. /* setting VCTL[WDEN] to 0 to disable watch dog */
  206. tmp = in8(PIXIS_BASE + PIXIS_VCTL);
  207. tmp &= ~0x08;
  208. out8(PIXIS_BASE + PIXIS_VCTL, tmp);
  209. return 0;
  210. }
  211. U_BOOT_CMD(
  212. diswd, 1, 0, disable_watchdog,
  213. "diswd - Disable watchdog timer \n",
  214. NULL);
  215. /*
  216. * This function takes the non-integral cpu:mpx pll ratio
  217. * and converts it to an integer that can be used to assign
  218. * FPGA register values.
  219. * input: strptr i.e. argv[2]
  220. */
  221. ulong strfractoint(uchar *strptr)
  222. {
  223. int i, j, retval;
  224. int mulconst;
  225. int intarr_len = 0, decarr_len = 0, no_dec = 0;
  226. ulong intval = 0, decval = 0;
  227. uchar intarr[3], decarr[3];
  228. /* Assign the integer part to intarr[]
  229. * If there is no decimal point i.e.
  230. * if the ratio is an integral value
  231. * simply create the intarr.
  232. */
  233. i = 0;
  234. while (strptr[i] != 46) {
  235. if (strptr[i] == 0) {
  236. no_dec = 1;
  237. break;
  238. }
  239. intarr[i] = strptr[i];
  240. i++;
  241. }
  242. /* Assign length of integer part to intarr_len. */
  243. intarr_len = i;
  244. intarr[i] = '\0';
  245. if (no_dec) {
  246. /* Currently needed only for single digit corepll ratios */
  247. mulconst = 10;
  248. decval = 0;
  249. } else {
  250. j = 0;
  251. i++; /* Skipping the decimal point */
  252. while ((strptr[i] > 47) && (strptr[i] < 58)) {
  253. decarr[j] = strptr[i];
  254. i++;
  255. j++;
  256. }
  257. decarr_len = j;
  258. decarr[j] = '\0';
  259. mulconst = 1;
  260. for (i = 0; i < decarr_len; i++)
  261. mulconst *= 10;
  262. decval = simple_strtoul(decarr, NULL, 10);
  263. }
  264. intval = simple_strtoul(intarr, NULL, 10);
  265. intval = intval * mulconst;
  266. retval = intval + decval;
  267. return retval;
  268. }