cms700.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * (C) Copyright 2005
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
  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 <common.h>
  24. #include <asm/processor.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. extern void lxt971_no_sleep(void);
  29. /* fpga configuration data - not compressed, generated by bin2c */
  30. const unsigned char fpgadata[] =
  31. {
  32. #include "fpgadata.c"
  33. };
  34. int filesize = sizeof(fpgadata);
  35. int board_early_init_f (void)
  36. {
  37. /*
  38. * IRQ 0-15 405GP internally generated; active high; level sensitive
  39. * IRQ 16 405GP internally generated; active low; level sensitive
  40. * IRQ 17-24 RESERVED
  41. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  42. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  43. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  44. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  45. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  46. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  47. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  48. */
  49. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  50. mtdcr(uicer, 0x00000000); /* disable all ints */
  51. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  52. mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
  53. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  54. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  55. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  56. /*
  57. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  58. */
  59. mtebc (epcr, 0xa8400000); /* ebc always driven */
  60. /*
  61. * Reset CPLD via GPIO12 (CS3) pin
  62. */
  63. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_PLD_RESET);
  64. udelay(1000); /* wait 1ms */
  65. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_PLD_RESET);
  66. udelay(1000); /* wait 1ms */
  67. return 0;
  68. }
  69. /* ------------------------------------------------------------------------- */
  70. int misc_init_f (void)
  71. {
  72. return 0; /* dummy implementation */
  73. }
  74. int misc_init_r (void)
  75. {
  76. /* adjust flash start and offset */
  77. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  78. gd->bd->bi_flashoffset = 0;
  79. /*
  80. * Setup and enable EEPROM write protection
  81. */
  82. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_EEPROM_WP);
  83. /*
  84. * Set NAND-FLASH GPIO signals to default
  85. */
  86. out32(GPIO0_OR, in32(GPIO0_OR) & ~(CFG_NAND_CLE | CFG_NAND_ALE));
  87. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_NAND_CE);
  88. return (0);
  89. }
  90. /*
  91. * Check Board Identity:
  92. */
  93. int checkboard (void)
  94. {
  95. char str[64];
  96. int flashcnt;
  97. int delay;
  98. volatile unsigned char *led_reg = (unsigned char *)((ulong)CFG_PLD_BASE + 0x1000);
  99. volatile unsigned char *ver_reg = (unsigned char *)((ulong)CFG_PLD_BASE + 0x1001);
  100. puts ("Board: ");
  101. if (getenv_r("serial#", str, sizeof(str)) == -1) {
  102. puts ("### No HW ID - assuming CMS700");
  103. } else {
  104. puts(str);
  105. }
  106. printf(" (PLD-Version=%02d)\n", *ver_reg);
  107. /*
  108. * Flash LEDs
  109. */
  110. for (flashcnt = 0; flashcnt < 3; flashcnt++) {
  111. *led_reg = 0x00; /* LEDs off */
  112. for (delay = 0; delay < 100; delay++)
  113. udelay(1000);
  114. *led_reg = 0x0f; /* LEDs on */
  115. for (delay = 0; delay < 50; delay++)
  116. udelay(1000);
  117. }
  118. *led_reg = 0x70;
  119. return 0;
  120. }
  121. /* ------------------------------------------------------------------------- */
  122. long int initdram (int board_type)
  123. {
  124. unsigned long val;
  125. mtdcr(memcfga, mem_mb0cf);
  126. val = mfdcr(memcfgd);
  127. #if 0
  128. printf("\nmb0cf=%x\n", val); /* test-only */
  129. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  130. #endif
  131. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  132. }
  133. /* ------------------------------------------------------------------------- */
  134. #if defined(CFG_EEPROM_WREN)
  135. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  136. * <state> -1: deliver current state
  137. * 0: disable write
  138. * 1: enable write
  139. * Returns: -1: wrong device address
  140. * 0: dis-/en- able done
  141. * 0/1: current state if <state> was -1.
  142. */
  143. int eeprom_write_enable (unsigned dev_addr, int state)
  144. {
  145. if (CFG_I2C_EEPROM_ADDR != dev_addr) {
  146. return -1;
  147. } else {
  148. switch (state) {
  149. case 1:
  150. /* Enable write access, clear bit GPIO_SINT2. */
  151. out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_EEPROM_WP);
  152. state = 0;
  153. break;
  154. case 0:
  155. /* Disable write access, set bit GPIO_SINT2. */
  156. out32(GPIO0_OR, in32(GPIO0_OR) | CFG_EEPROM_WP);
  157. state = 0;
  158. break;
  159. default:
  160. /* Read current status back. */
  161. state = (0 == (in32(GPIO0_OR) & CFG_EEPROM_WP));
  162. break;
  163. }
  164. }
  165. return state;
  166. }
  167. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  168. {
  169. int query = argc == 1;
  170. int state = 0;
  171. if (query) {
  172. /* Query write access state. */
  173. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, -1);
  174. if (state < 0) {
  175. puts ("Query of write access state failed.\n");
  176. } else {
  177. printf ("Write access for device 0x%0x is %sabled.\n",
  178. CFG_I2C_EEPROM_ADDR, state ? "en" : "dis");
  179. state = 0;
  180. }
  181. } else {
  182. if ('0' == argv[1][0]) {
  183. /* Disable write access. */
  184. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 0);
  185. } else {
  186. /* Enable write access. */
  187. state = eeprom_write_enable (CFG_I2C_EEPROM_ADDR, 1);
  188. }
  189. if (state < 0) {
  190. puts ("Setup of write access state failed.\n");
  191. }
  192. }
  193. return state;
  194. }
  195. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  196. "eepwren - Enable / disable / query EEPROM write access\n",
  197. NULL);
  198. #endif /* #if defined(CFG_EEPROM_WREN) */
  199. /* ------------------------------------------------------------------------- */
  200. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  201. #include <linux/mtd/nand_legacy.h>
  202. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  203. void nand_init(void)
  204. {
  205. nand_probe(CFG_NAND_BASE);
  206. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  207. print_size(nand_dev_desc[0].totlen, "\n");
  208. }
  209. }
  210. #endif
  211. void reset_phy(void)
  212. {
  213. #ifdef CONFIG_LXT971_NO_SLEEP
  214. /*
  215. * Disable sleep mode in LXT971
  216. */
  217. lxt971_no_sleep();
  218. #endif
  219. }