apc405.c 12 KB

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