apc405.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /*
  2. * (C) Copyright 2005-2008
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
  4. *
  5. * (C) Copyright 2001-2003
  6. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/processor.h>
  28. #include <asm/io.h>
  29. #include <command.h>
  30. #include <malloc.h>
  31. #include <flash.h>
  32. #include <mtd/cfi_flash.h>
  33. #include <asm/4xx_pci.h>
  34. #include <pci.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #undef FPGA_DEBUG
  37. extern void lxt971_no_sleep(void);
  38. /* fpga configuration data - gzip compressed and generated by bin2c */
  39. const unsigned char fpgadata[] =
  40. {
  41. #include "fpgadata.c"
  42. };
  43. /*
  44. * include common fpga code (for esd boards)
  45. */
  46. #include "../common/fpga.c"
  47. #ifdef CONFIG_LCD_USED
  48. /* logo bitmap data - gzip compressed and generated by bin2c */
  49. unsigned char logo_bmp[] =
  50. {
  51. #include "logo_640_480_24bpp.c"
  52. };
  53. /*
  54. * include common lcd code (for esd boards)
  55. */
  56. #include "../common/lcd.c"
  57. #include "../common/s1d13505_640_480_16bpp.h"
  58. #include "../common/s1d13806_640_480_16bpp.h"
  59. #endif /* CONFIG_LCD_USED */
  60. /*
  61. * include common auto-update code (for esd boards)
  62. */
  63. #include "../common/auto_update.h"
  64. au_image_t au_image[] = {
  65. {"preinst.img", 0, -1, AU_SCRIPT},
  66. {"u-boot.img", 0xfff80000, 0x00080000, AU_FIRMWARE | AU_PROTECT},
  67. {"pImage", 0xfe000000, 0x00100000, AU_NOR | AU_PROTECT},
  68. {"pImage.initrd", 0xfe100000, 0x00400000, AU_NOR | AU_PROTECT},
  69. {"work.img", 0xfe500000, 0x01400000, AU_NOR},
  70. {"data.img", 0xff900000, 0x00580000, AU_NOR},
  71. {"logo.img", 0xffe80000, 0x00100000, AU_NOR | AU_PROTECT},
  72. {"postinst.img", 0, 0, AU_SCRIPT},
  73. };
  74. int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
  75. int board_revision(void)
  76. {
  77. unsigned long CPC0_CR0Reg;
  78. unsigned long value;
  79. /*
  80. * Get version of APC405 board from GPIO's
  81. */
  82. /* Setup GPIO pins (CS2/GPIO11, CS3/GPIO12 and CS4/GPIO13 as GPIO) */
  83. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  84. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03800000);
  85. out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x001c0000);
  86. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x001c0000);
  87. /* wait some time before reading input */
  88. udelay(1000);
  89. /* get config bits */
  90. value = in_be32((void*)GPIO0_IR) & 0x001c0000;
  91. /*
  92. * Restore GPIO settings
  93. */
  94. mtdcr(CPC0_CR0, CPC0_CR0Reg);
  95. switch (value) {
  96. case 0x001c0000:
  97. /* CS2==1 && CS3==1 && CS4==1 -> version <= 1.2 */
  98. return 2;
  99. case 0x000c0000:
  100. /* CS2==0 && CS3==1 && CS4==1 -> version 1.3 */
  101. return 3;
  102. case 0x00180000:
  103. /* CS2==1 && CS3==1 && CS4==0 -> version 1.6 */
  104. return 6;
  105. case 0x00140000:
  106. /* CS2==1 && CS3==0 && CS4==1 -> version 1.8 */
  107. return 8;
  108. default:
  109. /* should not be reached! */
  110. return 0;
  111. }
  112. }
  113. int board_early_init_f (void)
  114. {
  115. /*
  116. * First pull fpga-prg pin low, to disable fpga logic
  117. */
  118. out_be32((void*)GPIO0_ODR, 0x00000000); /* no open drain pins */
  119. out_be32((void*)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */
  120. out_be32((void*)GPIO0_OR, 0); /* pull prg low */
  121. /*
  122. * IRQ 0-15 405GP internally generated; active high; level sensitive
  123. * IRQ 16 405GP internally generated; active low; level sensitive
  124. * IRQ 17-24 RESERVED
  125. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  126. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  127. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  128. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  129. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  130. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  131. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  132. */
  133. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  134. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  135. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  136. mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */
  137. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  138. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0 */
  139. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  140. /*
  141. * EBC Configuration Register: set ready timeout to 512 ebc-clks
  142. */
  143. mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
  144. /*
  145. * New boards have a single 32MB flash connected to CS0
  146. * instead of two 16MB flashes on CS0+1.
  147. */
  148. if (board_revision() >= 8) {
  149. /* disable CS1 */
  150. mtebc(PB1AP, 0);
  151. mtebc(PB1CR, 0);
  152. /* resize CS0 to 32MB */
  153. mtebc(PB0AP, CONFIG_SYS_EBC_PB0AP_HWREV8);
  154. mtebc(PB0CR, CONFIG_SYS_EBC_PB0CR_HWREV8);
  155. }
  156. return 0;
  157. }
  158. int board_early_init_r(void)
  159. {
  160. if (gd->board_type >= 8)
  161. cfi_flash_num_flash_banks = 1;
  162. return 0;
  163. }
  164. #define FUJI_BASE 0xf0100200
  165. #define LCDBL_PWM 0xa0
  166. #define LCDBL_PWMMIN 0xa4
  167. #define LCDBL_PWMMAX 0xa8
  168. int misc_init_r(void)
  169. {
  170. u16 *fpga_mode = (u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL);
  171. u16 *fpga_ctrl2 =(u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL2);
  172. u8 *duart0_mcr = (u8 *)(DUART0_BA + 4);
  173. u8 *duart1_mcr = (u8 *)(DUART1_BA + 4);
  174. unsigned char *dst;
  175. ulong len = sizeof(fpgadata);
  176. int status;
  177. int index;
  178. int i;
  179. unsigned long CPC0_CR0Reg;
  180. char *str;
  181. uchar *logo_addr;
  182. ulong logo_size;
  183. ushort minb, maxb;
  184. int result;
  185. /*
  186. * Setup GPIO pins (CS6+CS7 as GPIO)
  187. */
  188. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  189. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
  190. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  191. if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  192. printf("GUNZIP ERROR - must RESET board to recover\n");
  193. do_reset(NULL, 0, 0, NULL);
  194. }
  195. status = fpga_boot(dst, len);
  196. if (status != 0) {
  197. printf("\nFPGA: Booting failed ");
  198. switch (status) {
  199. case ERROR_FPGA_PRG_INIT_LOW:
  200. printf("(Timeout: "
  201. "INIT not low after asserting PROGRAM*)\n ");
  202. break;
  203. case ERROR_FPGA_PRG_INIT_HIGH:
  204. printf("(Timeout: "
  205. "INIT not high after deasserting PROGRAM*)\n ");
  206. break;
  207. case ERROR_FPGA_PRG_DONE:
  208. printf("(Timeout: "
  209. "DONE not high after programming FPGA)\n ");
  210. break;
  211. }
  212. /* display infos on fpgaimage */
  213. index = 15;
  214. for (i = 0; i < 4; i++) {
  215. len = dst[index];
  216. printf("FPGA: %s\n", &(dst[index+1]));
  217. index += len + 3;
  218. }
  219. putc('\n');
  220. /* delayed reboot */
  221. for (i = 20; i > 0; i--) {
  222. printf("Rebooting in %2d seconds \r",i);
  223. for (index = 0; index < 1000; index++)
  224. udelay(1000);
  225. }
  226. putc('\n');
  227. do_reset(NULL, 0, 0, NULL);
  228. }
  229. /* restore gpio/cs settings */
  230. mtdcr(CPC0_CR0, CPC0_CR0Reg);
  231. puts("FPGA: ");
  232. /* display infos on fpgaimage */
  233. index = 15;
  234. for (i = 0; i < 4; i++) {
  235. len = dst[index];
  236. printf("%s ", &(dst[index + 1]));
  237. index += len + 3;
  238. }
  239. putc('\n');
  240. free(dst);
  241. /*
  242. * Reset FPGA via FPGA_DATA pin
  243. */
  244. SET_FPGA(FPGA_PRG | FPGA_CLK);
  245. udelay(1000); /* wait 1ms */
  246. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  247. udelay(1000); /* wait 1ms */
  248. /*
  249. * Write board revision in FPGA
  250. */
  251. out_be16(fpga_ctrl2,
  252. (in_be16(fpga_ctrl2) & 0xfff0) | (gd->board_type & 0x000f));
  253. /*
  254. * Enable power on PS/2 interface (with reset)
  255. */
  256. out_be16(fpga_mode, in_be16(fpga_mode) | CONFIG_SYS_FPGA_CTRL_PS2_RESET);
  257. for (i=0;i<100;i++)
  258. udelay(1000);
  259. udelay(1000);
  260. out_be16(fpga_mode, in_be16(fpga_mode) & ~CONFIG_SYS_FPGA_CTRL_PS2_RESET);
  261. /*
  262. * Enable interrupts in exar duart mcr[3]
  263. */
  264. out_8(duart0_mcr, 0x08);
  265. out_8(duart1_mcr, 0x08);
  266. /*
  267. * Init lcd interface and display logo
  268. */
  269. str = getenv("splashimage");
  270. if (str) {
  271. logo_addr = (uchar *)simple_strtoul(str, NULL, 16);
  272. logo_size = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
  273. } else {
  274. logo_addr = logo_bmp;
  275. logo_size = sizeof(logo_bmp);
  276. }
  277. if (gd->board_type >= 6) {
  278. result = lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG,
  279. (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  280. regs_13505_640_480_16bpp,
  281. sizeof(regs_13505_640_480_16bpp) /
  282. sizeof(regs_13505_640_480_16bpp[0]),
  283. logo_addr, logo_size);
  284. if (result && str) {
  285. /* retry with internal image */
  286. logo_addr = logo_bmp;
  287. logo_size = sizeof(logo_bmp);
  288. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG,
  289. (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  290. regs_13505_640_480_16bpp,
  291. sizeof(regs_13505_640_480_16bpp) /
  292. sizeof(regs_13505_640_480_16bpp[0]),
  293. logo_addr, logo_size);
  294. }
  295. } else {
  296. result = lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG,
  297. (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  298. regs_13806_640_480_16bpp,
  299. sizeof(regs_13806_640_480_16bpp) /
  300. sizeof(regs_13806_640_480_16bpp[0]),
  301. logo_addr, logo_size);
  302. if (result && str) {
  303. /* retry with internal image */
  304. logo_addr = logo_bmp;
  305. logo_size = sizeof(logo_bmp);
  306. lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG,
  307. (uchar *)CONFIG_SYS_LCD_BIG_MEM,
  308. regs_13806_640_480_16bpp,
  309. sizeof(regs_13806_640_480_16bpp) /
  310. sizeof(regs_13806_640_480_16bpp[0]),
  311. logo_addr, logo_size);
  312. }
  313. }
  314. /*
  315. * Reset microcontroller and setup backlight PWM controller
  316. */
  317. out_be16(fpga_mode, in_be16(fpga_mode) | 0x0014);
  318. for (i=0;i<10;i++)
  319. udelay(1000);
  320. out_be16(fpga_mode, in_be16(fpga_mode) | 0x001c);
  321. minb = 0;
  322. maxb = 0xff;
  323. str = getenv("lcdbl");
  324. if (str) {
  325. minb = (ushort)simple_strtoul(str, &str, 16) & 0x00ff;
  326. if (str && (*str=',')) {
  327. str++;
  328. maxb = (ushort)simple_strtoul(str, NULL, 16) & 0x00ff;
  329. } else
  330. minb = 0;
  331. out_be16((u16 *)(FUJI_BASE + LCDBL_PWMMIN), minb);
  332. out_be16((u16 *)(FUJI_BASE + LCDBL_PWMMAX), maxb);
  333. printf("LCDBL: min=0x%02x, max=0x%02x\n", minb, maxb);
  334. }
  335. out_be16((u16 *)(FUJI_BASE + LCDBL_PWM), 0xff);
  336. /*
  337. * fix environment for field updated units
  338. */
  339. if (getenv("altbootcmd") == NULL) {
  340. setenv("usb_load", CONFIG_SYS_USB_LOAD_COMMAND);
  341. setenv("usbargs", CONFIG_SYS_USB_ARGS);
  342. setenv("bootcmd", CONFIG_BOOTCOMMAND);
  343. setenv("usb_self", CONFIG_SYS_USB_SELF_COMMAND);
  344. setenv("bootlimit", CONFIG_SYS_BOOTLIMIT);
  345. setenv("altbootcmd", CONFIG_SYS_ALT_BOOTCOMMAND);
  346. saveenv();
  347. }
  348. return (0);
  349. }
  350. /*
  351. * Check Board Identity:
  352. */
  353. int checkboard (void)
  354. {
  355. char str[64];
  356. int i = getenv_f("serial#", str, sizeof(str));
  357. puts ("Board: ");
  358. if (i == -1) {
  359. puts ("### No HW ID - assuming APC405");
  360. } else {
  361. puts(str);
  362. }
  363. gd->board_type = board_revision();
  364. printf(", Rev. 1.%ld\n", gd->board_type);
  365. return 0;
  366. }
  367. #ifdef CONFIG_IDE_RESET
  368. void ide_set_reset(int on)
  369. {
  370. u16 *fpga_mode = (u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL);
  371. /*
  372. * Assert or deassert CompactFlash Reset Pin
  373. */
  374. if (on) {
  375. out_be16(fpga_mode,
  376. in_be16(fpga_mode) & ~CONFIG_SYS_FPGA_CTRL_CF_RESET);
  377. } else {
  378. out_be16(fpga_mode,
  379. in_be16(fpga_mode) | CONFIG_SYS_FPGA_CTRL_CF_RESET);
  380. }
  381. }
  382. #endif /* CONFIG_IDE_RESET */
  383. void reset_phy(void)
  384. {
  385. /*
  386. * Disable sleep mode in LXT971
  387. */
  388. lxt971_no_sleep();
  389. }
  390. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
  391. int usb_board_init(void)
  392. {
  393. return 0;
  394. }
  395. int usb_board_stop(void)
  396. {
  397. unsigned short tmp;
  398. int i;
  399. /*
  400. * reset PCI bus
  401. * This is required to make some very old Linux OHCI driver
  402. * work after U-Boot has used the OHCI controller.
  403. */
  404. pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &tmp);
  405. pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (tmp | 0x1000));
  406. for (i = 0; i < 100; i++)
  407. udelay(1000);
  408. pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, tmp);
  409. return 0;
  410. }
  411. int usb_board_init_fail(void)
  412. {
  413. usb_board_stop();
  414. return 0;
  415. }
  416. #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT) */