tasreg.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * (C) Copyright 2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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 <command.h>
  25. #include <malloc.h>
  26. #include <asm/m5249.h>
  27. #include <asm/io.h>
  28. /* Prototypes */
  29. int gunzip(void *, int, unsigned char *, unsigned long *);
  30. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  31. int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
  32. int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
  33. #if 0
  34. #define FPGA_DEBUG
  35. #endif
  36. /* predefine these here for FPGA programming (before including fpga.c) */
  37. #define SET_FPGA(data) mbar2_writeLong(MCFSIM_GPIO1_OUT, data)
  38. #define FPGA_DONE_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_DONE)
  39. #define FPGA_INIT_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_INIT)
  40. #define FPGA_PROG_ACTIVE_HIGH /* on this platform is PROG active high! */
  41. #define out32(a,b) /* nothing to do (gpio already configured) */
  42. /* fpga configuration data - generated by bin2cc */
  43. const unsigned char fpgadata[] =
  44. {
  45. #include "fpgadata.c"
  46. };
  47. /*
  48. * include common fpga code (for esd boards)
  49. */
  50. #include "../common/fpga.c"
  51. int checkboard (void) {
  52. ulong val;
  53. uchar val8;
  54. puts ("Board: ");
  55. puts("esd TASREG");
  56. val8 = ((uchar)~((uchar)mbar2_readLong(MCFSIM_GPIO1_READ) >> 4)) & 0xf;
  57. printf(" (Switch=%1X)\n", val8);
  58. /*
  59. * Set LED on
  60. */
  61. val = mbar2_readLong(MCFSIM_GPIO1_OUT) & ~CONFIG_SYS_GPIO1_LED;
  62. mbar2_writeLong(MCFSIM_GPIO1_OUT, val); /* Set LED on */
  63. return 0;
  64. };
  65. phys_size_t initdram (int board_type) {
  66. unsigned long junk = 0xa5a59696;
  67. /*
  68. * Note:
  69. * RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1
  70. */
  71. #ifdef CONFIG_SYS_FAST_CLK
  72. /*
  73. * Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)
  74. * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=39
  75. */
  76. mbar_writeShort(MCFSIM_DCR, 0x8239);
  77. #elif CONFIG_SYS_PLL_BYPASS
  78. /*
  79. * Busclk=5.6448MHz, RefreshTime=64ms, #rows=8192 (8K)
  80. * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=02
  81. */
  82. mbar_writeShort(MCFSIM_DCR, 0x8202);
  83. #else
  84. /*
  85. * Busclk=36MHz, RefreshTime=64ms, #rows=4096 (4K)
  86. * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=22 (562 bus clock cycles)
  87. */
  88. mbar_writeShort(MCFSIM_DCR, 0x8222);
  89. #endif
  90. /*
  91. * SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port),
  92. * PM=1 (continuous page mode)
  93. */
  94. /* RE=0 (keep auto-refresh disabled while setting up registers) */
  95. mbar_writeLong(MCFSIM_DACR0, 0x00003324);
  96. /* BAM=007c (bits 22,21 are bank selects; 256kB blocks) */
  97. mbar_writeLong(MCFSIM_DMR0, 0x01fc0001);
  98. /** Precharge sequence **/
  99. mbar_writeLong(MCFSIM_DACR0, 0x0000332c); /* Set DACR0[IP] (bit 3) */
  100. out_be32((void *)0, junk); /* write to a memory location to init. precharge */
  101. udelay(0x10); /* Allow several Precharge cycles */
  102. /** Refresh Sequence **/
  103. mbar_writeLong(MCFSIM_DACR0, 0x0000b324); /* Enable the refresh bit, DACR0[RE] (bit 15) */
  104. udelay(0x7d0); /* Allow gobs of refresh cycles */
  105. /** Mode Register initialization **/
  106. mbar_writeLong(MCFSIM_DACR0, 0x0000b364); /* Enable DACR0[IMRS] (bit 6); RE remains enabled */
  107. out_be32((void *)0x800, junk); /* Access RAM to initialize the mode register */
  108. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  109. };
  110. int testdram (void) {
  111. /* TODO: XXX XXX XXX */
  112. printf ("DRAM test not implemented!\n");
  113. return (0);
  114. }
  115. int misc_init_r (void)
  116. {
  117. unsigned char *dst;
  118. ulong len = sizeof(fpgadata);
  119. int status;
  120. int index;
  121. int i;
  122. uchar buf[8];
  123. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  124. if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  125. printf ("GUNZIP ERROR - must RESET board to recover\n");
  126. do_reset (NULL, 0, 0, NULL);
  127. }
  128. status = fpga_boot(dst, len);
  129. if (status != 0) {
  130. printf("\nFPGA: Booting failed ");
  131. switch (status) {
  132. case ERROR_FPGA_PRG_INIT_LOW:
  133. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  134. break;
  135. case ERROR_FPGA_PRG_INIT_HIGH:
  136. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  137. break;
  138. case ERROR_FPGA_PRG_DONE:
  139. printf("(Timeout: DONE not high after programming FPGA)\n ");
  140. break;
  141. }
  142. /* display infos on fpgaimage */
  143. index = 15;
  144. for (i=0; i<4; i++) {
  145. len = dst[index];
  146. printf("FPGA: %s\n", &(dst[index+1]));
  147. index += len+3;
  148. }
  149. putc ('\n');
  150. /* delayed reboot */
  151. for (i=20; i>0; i--) {
  152. printf("Rebooting in %2d seconds \r",i);
  153. for (index=0;index<1000;index++)
  154. udelay(1000);
  155. }
  156. putc ('\n');
  157. do_reset(NULL, 0, 0, NULL);
  158. }
  159. puts("FPGA: ");
  160. /* display infos on fpgaimage */
  161. index = 15;
  162. for (i=0; i<4; i++) {
  163. len = dst[index];
  164. printf("%s ", &(dst[index+1]));
  165. index += len+3;
  166. }
  167. putc ('\n');
  168. free(dst);
  169. /*
  170. *
  171. */
  172. buf[0] = 0x00;
  173. buf[1] = 0x32;
  174. buf[2] = 0x3f;
  175. i2c_write(0x38, 0, 0, buf, 3);
  176. return (0);
  177. }
  178. #if 1 /* test-only: board specific test commands */
  179. int i2c_probe(uchar addr);
  180. /*
  181. */
  182. int do_iploop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  183. {
  184. ulong addr;
  185. if (argc < 2) {
  186. puts("ERROR!\n");
  187. return -1;
  188. }
  189. addr = simple_strtol (argv[1], NULL, 16);
  190. printf("i2c probe looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
  191. for (;;) {
  192. i2c_probe(addr);
  193. /* Abort if ctrl-c was pressed */
  194. if (ctrlc()) {
  195. puts("\nAbort\n");
  196. return 0;
  197. }
  198. udelay(1000);
  199. }
  200. return 0;
  201. }
  202. U_BOOT_CMD(
  203. iploop, 2, 1, do_iploop,
  204. "i2c probe loop <addr>",
  205. NULL
  206. );
  207. /*
  208. */
  209. int do_codec(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  210. {
  211. uchar buf[8];
  212. out_be16((void *)0xe0000000, 0x4000);
  213. udelay(5000); /* wait for 5ms */
  214. buf[0] = 0x10;
  215. buf[1] = 0x07;
  216. buf[2] = 0x03;
  217. i2c_write(0x10, 0, 0, buf, 3);
  218. buf[0] = 0x10;
  219. buf[1] = 0x01;
  220. buf[2] = 0x80;
  221. i2c_write(0x10, 0, 0, buf, 3);
  222. buf[0] = 0x10;
  223. buf[1] = 0x02;
  224. buf[2] = 0x03;
  225. i2c_write(0x10, 0, 0, buf, 3);
  226. buf[0] = 0x10;
  227. buf[1] = 0x03;
  228. buf[2] = 0x29;
  229. i2c_write(0x10, 0, 0, buf, 3);
  230. buf[0] = 0x10;
  231. buf[1] = 0x04;
  232. buf[2] = 0x00;
  233. i2c_write(0x10, 0, 0, buf, 3);
  234. buf[0] = 0x10;
  235. buf[1] = 0x05;
  236. buf[2] = 0x00;
  237. i2c_write(0x10, 0, 0, buf, 3);
  238. buf[0] = 0x10;
  239. buf[1] = 0x07;
  240. buf[2] = 0x02;
  241. i2c_write(0x10, 0, 0, buf, 3);
  242. return 0;
  243. }
  244. U_BOOT_CMD(
  245. codec, 1, 1, do_codec,
  246. "Enable codec",
  247. NULL
  248. );
  249. /*
  250. */
  251. int do_saa(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  252. {
  253. ulong addr;
  254. ulong instr;
  255. ulong cntrl;
  256. ulong data;
  257. uchar buf[8];
  258. if (argc < 5) {
  259. puts("ERROR!\n");
  260. return -1;
  261. }
  262. addr = simple_strtol (argv[1], NULL, 16);
  263. instr = simple_strtol (argv[2], NULL, 16);
  264. cntrl = simple_strtol (argv[3], NULL, 16);
  265. data = simple_strtol (argv[4], NULL, 16);
  266. buf[0] = (uchar)instr;
  267. buf[1] = (uchar)cntrl;
  268. buf[2] = (uchar)data;
  269. i2c_write(addr, 0, 0, buf, 3);
  270. return 0;
  271. }
  272. U_BOOT_CMD(
  273. saa, 5, 1, do_saa,
  274. "Write to SAA1064 <addr> <instr> <cntrl> <data>",
  275. NULL
  276. );
  277. /*
  278. */
  279. int do_iwrite(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  280. {
  281. ulong addr;
  282. ulong data0;
  283. ulong data1;
  284. ulong data2;
  285. ulong data3;
  286. uchar buf[8];
  287. int cnt;
  288. if (argc < 3) {
  289. puts("ERROR!\n");
  290. return -1;
  291. }
  292. addr = simple_strtol (argv[1], NULL, 16);
  293. cnt = simple_strtol (argv[2], NULL, 16);
  294. data0 = simple_strtol (argv[3], NULL, 16);
  295. data1 = simple_strtol (argv[4], NULL, 16);
  296. data2 = simple_strtol (argv[5], NULL, 16);
  297. data3 = simple_strtol (argv[6], NULL, 16);
  298. printf("Writing %d bytes to device %lx!\n", cnt, addr);
  299. buf[0] = (uchar)data0;
  300. buf[1] = (uchar)data1;
  301. buf[2] = (uchar)data2;
  302. buf[3] = (uchar)data3;
  303. i2c_write(addr, 0, 0, buf, cnt);
  304. return 0;
  305. }
  306. U_BOOT_CMD(
  307. iwrite, 6, 1, do_iwrite,
  308. "Write n bytes to I2C-device",
  309. "addr cnt data0 ... datan\n"
  310. );
  311. /*
  312. */
  313. int do_iread(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  314. {
  315. ulong addr;
  316. ulong cnt;
  317. uchar buf[32];
  318. int i;
  319. if (argc < 3) {
  320. puts("ERROR!\n");
  321. return -1;
  322. }
  323. addr = simple_strtol (argv[1], NULL, 16);
  324. cnt = simple_strtol (argv[2], NULL, 16);
  325. i2c_read(addr, 0, 0, buf, cnt);
  326. printf("I2C Data:");
  327. for (i=0; i<cnt; i++) {
  328. printf(" %02X", buf[i]);
  329. }
  330. printf("\n");
  331. return 0;
  332. }
  333. U_BOOT_CMD(
  334. iread, 3, 1, do_iread,
  335. "Read from I2C <addr> <cnt>",
  336. NULL
  337. );
  338. /*
  339. */
  340. int do_ireadl(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  341. {
  342. ulong addr;
  343. uchar buf[32];
  344. int cnt;
  345. if (argc < 2) {
  346. puts("ERROR!\n");
  347. return -1;
  348. }
  349. addr = simple_strtol (argv[1], NULL, 16);
  350. cnt = 1;
  351. printf("iread looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
  352. for (;;) {
  353. i2c_read(addr, 0, 0, buf, cnt);
  354. /* Abort if ctrl-c was pressed */
  355. if (ctrlc()) {
  356. puts("\nAbort\n");
  357. return 0;
  358. }
  359. udelay(3000);
  360. }
  361. return 0;
  362. }
  363. U_BOOT_CMD(
  364. ireadl, 2, 1, do_ireadl,
  365. "Read-loop from I2C <addr>",
  366. NULL
  367. );
  368. #endif