tqm5200.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. /*
  2. * (C) Copyright 2003-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2004-2006
  9. * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <mpc5xxx.h>
  15. #include <pci.h>
  16. #include <asm/processor.h>
  17. #include <libfdt.h>
  18. #include <netdev.h>
  19. #ifdef CONFIG_VIDEO_SM501
  20. #include <sm501.h>
  21. #endif
  22. #if defined(CONFIG_MPC5200_DDR)
  23. #include "mt46v16m16-75.h"
  24. #else
  25. #include "mt48lc16m16a2-75.h"
  26. #endif
  27. #ifdef CONFIG_OF_LIBFDT
  28. #include <fdt_support.h>
  29. #endif /* CONFIG_OF_LIBFDT */
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #ifdef CONFIG_PS2MULT
  32. void ps2mult_early_init(void);
  33. #endif
  34. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) && \
  35. defined(CONFIG_VIDEO)
  36. /*
  37. * EDID block has been generated using Phoenix EDID Designer 1.3.
  38. * This tool creates a text file containing:
  39. *
  40. * EDID BYTES:
  41. *
  42. * 0x 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
  43. * ------------------------------------------------
  44. * 00 | 00 FF FF FF FF FF FF 00 04 21 00 00 00 00 00 00
  45. * 10 | 01 00 01 03 00 00 00 00 00 00 00 00 00 00 00 00
  46. * 20 | 00 00 00 21 00 00 01 01 01 01 01 01 01 01 01 01
  47. * 30 | 01 01 01 01 01 01 64 00 00 00 00 00 00 00 00 00
  48. * 40 | 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00
  49. * 50 | 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00
  50. * 60 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10
  51. * 70 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17
  52. *
  53. * Then this data has been manually converted to the char
  54. * array below.
  55. */
  56. static unsigned char edid_buf[128] = {
  57. 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
  58. 0x04, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x01, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x01, 0x01,
  62. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  63. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x64, 0x00,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17,
  73. };
  74. #endif
  75. #ifndef CONFIG_SYS_RAMBOOT
  76. static void sdram_start (int hi_addr)
  77. {
  78. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  79. /* unlock mode register */
  80. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  81. hi_addr_bit;
  82. __asm__ volatile ("sync");
  83. /* precharge all banks */
  84. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  85. hi_addr_bit;
  86. __asm__ volatile ("sync");
  87. #if SDRAM_DDR
  88. /* set mode register: extended mode */
  89. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  90. __asm__ volatile ("sync");
  91. /* set mode register: reset DLL */
  92. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  93. __asm__ volatile ("sync");
  94. #endif
  95. /* precharge all banks */
  96. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  97. hi_addr_bit;
  98. __asm__ volatile ("sync");
  99. /* auto refresh */
  100. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  101. hi_addr_bit;
  102. __asm__ volatile ("sync");
  103. /* set mode register */
  104. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  105. __asm__ volatile ("sync");
  106. /* normal operation */
  107. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  108. __asm__ volatile ("sync");
  109. }
  110. #endif
  111. /*
  112. * ATTENTION: Although partially referenced initdram does NOT make real use
  113. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  114. * is something else than 0x00000000.
  115. */
  116. phys_size_t initdram (int board_type)
  117. {
  118. ulong dramsize = 0;
  119. ulong dramsize2 = 0;
  120. uint svr, pvr;
  121. #ifndef CONFIG_SYS_RAMBOOT
  122. ulong test1, test2;
  123. /* setup SDRAM chip selects */
  124. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  125. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  126. __asm__ volatile ("sync");
  127. /* setup config registers */
  128. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  129. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  130. __asm__ volatile ("sync");
  131. #if SDRAM_DDR
  132. /* set tap delay */
  133. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  134. __asm__ volatile ("sync");
  135. #endif
  136. /* find RAM size using SDRAM CS0 only */
  137. sdram_start(0);
  138. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  139. sdram_start(1);
  140. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  141. if (test1 > test2) {
  142. sdram_start(0);
  143. dramsize = test1;
  144. } else {
  145. dramsize = test2;
  146. }
  147. /* memory smaller than 1MB is impossible */
  148. if (dramsize < (1 << 20)) {
  149. dramsize = 0;
  150. }
  151. /* set SDRAM CS0 size according to the amount of RAM found */
  152. if (dramsize > 0) {
  153. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  154. __builtin_ffs(dramsize >> 20) - 1;
  155. } else {
  156. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  157. }
  158. /* let SDRAM CS1 start right after CS0 */
  159. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
  160. /* find RAM size using SDRAM CS1 only */
  161. if (!dramsize)
  162. sdram_start(0);
  163. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  164. if (!dramsize) {
  165. sdram_start(1);
  166. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  167. }
  168. if (test1 > test2) {
  169. sdram_start(0);
  170. dramsize2 = test1;
  171. } else {
  172. dramsize2 = test2;
  173. }
  174. /* memory smaller than 1MB is impossible */
  175. if (dramsize2 < (1 << 20)) {
  176. dramsize2 = 0;
  177. }
  178. /* set SDRAM CS1 size according to the amount of RAM found */
  179. if (dramsize2 > 0) {
  180. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  181. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  182. } else {
  183. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  184. }
  185. #else /* CONFIG_SYS_RAMBOOT */
  186. /* retrieve size of memory connected to SDRAM CS0 */
  187. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  188. if (dramsize >= 0x13) {
  189. dramsize = (1 << (dramsize - 0x13)) << 20;
  190. } else {
  191. dramsize = 0;
  192. }
  193. /* retrieve size of memory connected to SDRAM CS1 */
  194. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  195. if (dramsize2 >= 0x13) {
  196. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  197. } else {
  198. dramsize2 = 0;
  199. }
  200. #endif /* CONFIG_SYS_RAMBOOT */
  201. /*
  202. * On MPC5200B we need to set the special configuration delay in the
  203. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  204. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  205. *
  206. * "The SDelay should be written to a value of 0x00000004. It is
  207. * required to account for changes caused by normal wafer processing
  208. * parameters."
  209. */
  210. svr = get_svr();
  211. pvr = get_pvr();
  212. if ((SVR_MJREV(svr) >= 2) &&
  213. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  214. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  215. __asm__ volatile ("sync");
  216. }
  217. #if defined(CONFIG_TQM5200_B)
  218. return dramsize + dramsize2;
  219. #else
  220. return dramsize;
  221. #endif /* CONFIG_TQM5200_B */
  222. }
  223. int checkboard (void)
  224. {
  225. #if defined(CONFIG_AEVFIFO)
  226. puts ("Board: AEVFIFO\n");
  227. return 0;
  228. #endif
  229. #if defined(CONFIG_TQM5200S)
  230. # define MODULE_NAME "TQM5200S"
  231. #else
  232. # define MODULE_NAME "TQM5200"
  233. #endif
  234. #if defined(CONFIG_STK52XX)
  235. # define CARRIER_NAME "STK52xx"
  236. #elif defined(CONFIG_TB5200)
  237. # define CARRIER_NAME "TB5200"
  238. #elif defined(CONFIG_CAM5200)
  239. # define CARRIER_NAME "CAM5200"
  240. #elif defined(CONFIG_FO300)
  241. # define CARRIER_NAME "FO300"
  242. #elif defined(CONFIG_CHARON)
  243. # define CARRIER_NAME "CHARON"
  244. #else
  245. # error "UNKNOWN"
  246. #endif
  247. puts ( "Board: " MODULE_NAME " (TQ-Components GmbH)\n"
  248. " on a " CARRIER_NAME " carrier board\n");
  249. return 0;
  250. }
  251. #undef MODULE_NAME
  252. #undef CARRIER_NAME
  253. void flash_preinit(void)
  254. {
  255. /*
  256. * Now, when we are in RAM, enable flash write
  257. * access for detection process.
  258. * Note that CS_BOOT cannot be cleared when
  259. * executing in flash.
  260. */
  261. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  262. }
  263. #ifdef CONFIG_PCI
  264. static struct pci_controller hose;
  265. extern void pci_mpc5xxx_init(struct pci_controller *);
  266. void pci_init_board(void)
  267. {
  268. pci_mpc5xxx_init(&hose);
  269. }
  270. #endif
  271. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  272. #if defined (CONFIG_MINIFAP)
  273. #define SM501_POWER_MODE0_GATE 0x00000040UL
  274. #define SM501_POWER_MODE1_GATE 0x00000048UL
  275. #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
  276. #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
  277. #define SM501_GPIO_DATA_HIGH 0x00010004UL
  278. #define SM501_GPIO_51 0x00080000UL
  279. #endif /* CONFIG MINIFAP */
  280. void init_ide_reset (void)
  281. {
  282. debug ("init_ide_reset\n");
  283. #if defined (CONFIG_MINIFAP)
  284. /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
  285. /* enable GPIO control (in both power modes) */
  286. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
  287. POWER_MODE_GATE_GPIO_PWM_I2C;
  288. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
  289. POWER_MODE_GATE_GPIO_PWM_I2C;
  290. /* configure GPIO51 as output */
  291. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
  292. SM501_GPIO_51;
  293. #else
  294. /* Configure PSC1_4 as GPIO output for ATA reset */
  295. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  296. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  297. /* by default the ATA reset is de-asserted */
  298. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  299. #endif
  300. }
  301. void ide_set_reset (int idereset)
  302. {
  303. debug ("ide_reset(%d)\n", idereset);
  304. #if defined (CONFIG_MINIFAP)
  305. if (idereset) {
  306. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
  307. ~SM501_GPIO_51;
  308. } else {
  309. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
  310. SM501_GPIO_51;
  311. }
  312. #else
  313. if (idereset) {
  314. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  315. } else {
  316. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  317. }
  318. #endif
  319. }
  320. #endif
  321. #ifdef CONFIG_POST
  322. /*
  323. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  324. * is left open, no keypress is detected.
  325. */
  326. int post_hotkeys_pressed(void)
  327. {
  328. #ifdef CONFIG_STK52XX
  329. struct mpc5xxx_gpio *gpio;
  330. gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
  331. /*
  332. * Configure PSC6_0 through PSC6_3 as GPIO.
  333. */
  334. gpio->port_config &= ~(0x00700000);
  335. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  336. gpio->simple_gpioe |= 0x20000000;
  337. /* Configure GPIO_IRDA_1 as input */
  338. gpio->simple_ddr &= ~(0x20000000);
  339. return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
  340. #else
  341. return 0;
  342. #endif
  343. }
  344. #endif
  345. #ifdef CONFIG_BOARD_EARLY_INIT_R
  346. int board_early_init_r (void)
  347. {
  348. extern int usb_cpu_init(void);
  349. #ifdef CONFIG_PS2MULT
  350. ps2mult_early_init();
  351. #endif /* CONFIG_PS2MULT */
  352. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
  353. /* Low level USB init, required for proper kernel operation */
  354. usb_cpu_init();
  355. #endif
  356. return (0);
  357. }
  358. #endif
  359. #ifdef CONFIG_FO300
  360. int silent_boot (void)
  361. {
  362. vu_long timer3_status;
  363. /* Configure GPT3 as GPIO input */
  364. *(vu_long *)MPC5XXX_GPT3_ENABLE = 0x00000004;
  365. /* Read in TIMER_3 pin status */
  366. timer3_status = *(vu_long *)MPC5XXX_GPT3_STATUS;
  367. #ifdef FO300_SILENT_CONSOLE_WHEN_S1_CLOSED
  368. /* Force silent console mode if S1 switch
  369. * is in closed position (TIMER_3 pin status is LOW). */
  370. if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 0)
  371. return 1;
  372. #else
  373. /* Force silent console mode if S1 switch
  374. * is in open position (TIMER_3 pin status is HIGH). */
  375. if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 1)
  376. return 1;
  377. #endif
  378. return 0;
  379. }
  380. int board_early_init_f (void)
  381. {
  382. if (silent_boot())
  383. gd->flags |= GD_FLG_SILENT;
  384. return 0;
  385. }
  386. #endif /* CONFIG_FO300 */
  387. #if defined(CONFIG_CHARON)
  388. #include <i2c.h>
  389. #include <asm/io.h>
  390. /* The TFP410 registers */
  391. #define TFP410_REG_VEN_ID_L 0x00
  392. #define TFP410_REG_VEN_ID_H 0x01
  393. #define TFP410_REG_DEV_ID_L 0x02
  394. #define TFP410_REG_DEV_ID_H 0x03
  395. #define TFP410_REG_REV_ID 0x04
  396. #define TFP410_REG_CTL_1_MODE 0x08
  397. #define TFP410_REG_CTL_2_MODE 0x09
  398. #define TFP410_REG_CTL_3_MODE 0x0A
  399. #define TFP410_REG_CFG 0x0B
  400. #define TFP410_REG_DE_DLY 0x32
  401. #define TFP410_REG_DE_CTL 0x33
  402. #define TFP410_REG_DE_TOP 0x34
  403. #define TFP410_REG_DE_CNT_L 0x36
  404. #define TFP410_REG_DE_CNT_H 0x37
  405. #define TFP410_REG_DE_LIN_L 0x38
  406. #define TFP410_REG_DE_LIN_H 0x39
  407. #define TFP410_REG_H_RES_L 0x3A
  408. #define TFP410_REG_H_RES_H 0x3B
  409. #define TFP410_REG_V_RES_L 0x3C
  410. #define TFP410_REG_V_RES_H 0x3D
  411. static int tfp410_read_reg(int reg, uchar *buf)
  412. {
  413. if (i2c_read(CONFIG_SYS_TFP410_ADDR, reg, 1, buf, 1) != 0) {
  414. puts ("Error reading the chip.\n");
  415. return 1;
  416. }
  417. return 0;
  418. }
  419. static int tfp410_write_reg(int reg, uchar buf)
  420. {
  421. if (i2c_write(CONFIG_SYS_TFP410_ADDR, reg, 1, &buf, 1) != 0) {
  422. puts ("Error writing the chip.\n");
  423. return 1;
  424. }
  425. return 0;
  426. }
  427. typedef struct _tfp410_config {
  428. int reg;
  429. uchar val;
  430. }TFP410_CONFIG;
  431. static TFP410_CONFIG tfp410_configtbl[] = {
  432. {TFP410_REG_CTL_1_MODE, 0x37},
  433. {TFP410_REG_CTL_2_MODE, 0x20},
  434. {TFP410_REG_CTL_3_MODE, 0x80},
  435. {TFP410_REG_DE_DLY, 0x90},
  436. {TFP410_REG_DE_CTL, 0x00},
  437. {TFP410_REG_DE_TOP, 0x23},
  438. {TFP410_REG_DE_CNT_H, 0x02},
  439. {TFP410_REG_DE_CNT_L, 0x80},
  440. {TFP410_REG_DE_LIN_H, 0x01},
  441. {TFP410_REG_DE_LIN_L, 0xe0},
  442. {-1, 0},
  443. };
  444. static int charon_last_stage_init(void)
  445. {
  446. volatile struct mpc5xxx_lpb *lpb =
  447. (struct mpc5xxx_lpb *) MPC5XXX_LPB;
  448. int oldbus = i2c_get_bus_num();
  449. uchar buf;
  450. int i = 0;
  451. i2c_set_bus_num(CONFIG_SYS_TFP410_BUS);
  452. /* check version */
  453. if (tfp410_read_reg(TFP410_REG_DEV_ID_H, &buf) != 0)
  454. return -1;
  455. if (!(buf & 0x04))
  456. return -1;
  457. if (tfp410_read_reg(TFP410_REG_DEV_ID_L, &buf) != 0)
  458. return -1;
  459. if (!(buf & 0x10))
  460. return -1;
  461. /* OK, now init the chip */
  462. while (tfp410_configtbl[i].reg != -1) {
  463. int ret;
  464. ret = tfp410_write_reg(tfp410_configtbl[i].reg,
  465. tfp410_configtbl[i].val);
  466. if (ret != 0)
  467. return -1;
  468. i++;
  469. }
  470. printf("TFP410 initialized.\n");
  471. i2c_set_bus_num(oldbus);
  472. /* set deadcycle for cs3 to 0 */
  473. setbits_be32(&lpb->cs_deadcycle, 0xffffcfff);
  474. return 0;
  475. }
  476. #endif
  477. int last_stage_init (void)
  478. {
  479. /*
  480. * auto scan for really existing devices and re-set chip select
  481. * configuration.
  482. */
  483. u16 save, tmp;
  484. int restore;
  485. /*
  486. * Check for SRAM and SRAM size
  487. */
  488. /* save original SRAM content */
  489. save = *(volatile u16 *)CONFIG_SYS_CS2_START;
  490. restore = 1;
  491. /* write test pattern to SRAM */
  492. *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
  493. __asm__ volatile ("sync");
  494. /*
  495. * Put a different pattern on the data lines: otherwise they may float
  496. * long enough to read back what we wrote.
  497. */
  498. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  499. if (tmp == 0xA5A5)
  500. puts ("!! possible error in SRAM detection\n");
  501. if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
  502. /* no SRAM at all, disable cs */
  503. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
  504. *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
  505. *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
  506. restore = 0;
  507. __asm__ volatile ("sync");
  508. } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
  509. /* make sure that we access a mirrored address */
  510. *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
  511. __asm__ volatile ("sync");
  512. if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
  513. /* SRAM size = 512 kByte */
  514. *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
  515. 0x80000);
  516. __asm__ volatile ("sync");
  517. puts ("SRAM: 512 kB\n");
  518. }
  519. else
  520. puts ("!! possible error in SRAM detection\n");
  521. } else {
  522. puts ("SRAM: 1 MB\n");
  523. }
  524. /* restore origianl SRAM content */
  525. if (restore) {
  526. *(volatile u16 *)CONFIG_SYS_CS2_START = save;
  527. __asm__ volatile ("sync");
  528. }
  529. #ifndef CONFIG_TQM5200S /* The TQM5200S has no SM501 grafic controller */
  530. /*
  531. * Check for Grafic Controller
  532. */
  533. /* save origianl FB content */
  534. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  535. restore = 1;
  536. /* write test pattern to FB memory */
  537. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  538. __asm__ volatile ("sync");
  539. /*
  540. * Put a different pattern on the data lines: otherwise they may float
  541. * long enough to read back what we wrote.
  542. */
  543. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  544. if (tmp == 0xA5A5)
  545. puts ("!! possible error in grafic controller detection\n");
  546. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  547. /* no grafic controller at all, disable cs */
  548. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
  549. *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
  550. *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
  551. restore = 0;
  552. __asm__ volatile ("sync");
  553. } else {
  554. puts ("VGA: SMI501 (Voyager) with 8 MB\n");
  555. }
  556. /* restore origianl FB content */
  557. if (restore) {
  558. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  559. __asm__ volatile ("sync");
  560. }
  561. #ifdef CONFIG_FO300
  562. if (silent_boot()) {
  563. setenv("bootdelay", "0");
  564. disable_ctrlc(1);
  565. }
  566. #endif
  567. #endif /* !CONFIG_TQM5200S */
  568. #if defined(CONFIG_CHARON)
  569. charon_last_stage_init();
  570. #endif
  571. return 0;
  572. }
  573. #ifdef CONFIG_VIDEO_SM501
  574. #ifdef CONFIG_FO300
  575. #define DISPLAY_WIDTH 800
  576. #else
  577. #define DISPLAY_WIDTH 640
  578. #endif
  579. #define DISPLAY_HEIGHT 480
  580. #ifdef CONFIG_VIDEO_SM501_8BPP
  581. #error CONFIG_VIDEO_SM501_8BPP not supported.
  582. #endif /* CONFIG_VIDEO_SM501_8BPP */
  583. #ifdef CONFIG_VIDEO_SM501_16BPP
  584. #error CONFIG_VIDEO_SM501_16BPP not supported.
  585. #endif /* CONFIG_VIDEO_SM501_16BPP */
  586. #ifdef CONFIG_VIDEO_SM501_32BPP
  587. static const SMI_REGS init_regs [] =
  588. {
  589. #if 0 /* CRT only */
  590. {0x00004, 0x0},
  591. {0x00048, 0x00021807},
  592. {0x0004C, 0x10090a01},
  593. {0x00054, 0x1},
  594. {0x00040, 0x00021807},
  595. {0x00044, 0x10090a01},
  596. {0x00054, 0x0},
  597. {0x80200, 0x00010000},
  598. {0x80204, 0x0},
  599. {0x80208, 0x0A000A00},
  600. {0x8020C, 0x02fa027f},
  601. {0x80210, 0x004a028b},
  602. {0x80214, 0x020c01df},
  603. {0x80218, 0x000201e9},
  604. {0x80200, 0x00013306},
  605. #else /* panel + CRT */
  606. #ifdef CONFIG_FO300
  607. {0x00004, 0x0},
  608. {0x00048, 0x00021807},
  609. {0x0004C, 0x301a0a01},
  610. {0x00054, 0x1},
  611. {0x00040, 0x00021807},
  612. {0x00044, 0x091a0a01},
  613. {0x00054, 0x0},
  614. {0x80000, 0x0f013106},
  615. {0x80004, 0xc428bb17},
  616. {0x8000C, 0x00000000},
  617. {0x80010, 0x0C800C80},
  618. {0x80014, 0x03200000},
  619. {0x80018, 0x01e00000},
  620. {0x8001C, 0x00000000},
  621. {0x80020, 0x01e00320},
  622. {0x80024, 0x042a031f},
  623. {0x80028, 0x0086034a},
  624. {0x8002C, 0x020c01df},
  625. {0x80030, 0x000201ea},
  626. {0x80200, 0x00010000},
  627. #else
  628. {0x00004, 0x0},
  629. {0x00048, 0x00021807},
  630. {0x0004C, 0x091a0a01},
  631. {0x00054, 0x1},
  632. {0x00040, 0x00021807},
  633. {0x00044, 0x091a0a01},
  634. {0x00054, 0x0},
  635. {0x80000, 0x0f013106},
  636. {0x80004, 0xc428bb17},
  637. {0x8000C, 0x00000000},
  638. {0x80010, 0x0a000a00},
  639. {0x80014, 0x02800000},
  640. {0x80018, 0x01e00000},
  641. {0x8001C, 0x00000000},
  642. {0x80020, 0x01e00280},
  643. {0x80024, 0x02fa027f},
  644. {0x80028, 0x004a028b},
  645. {0x8002C, 0x020c01df},
  646. {0x80030, 0x000201e9},
  647. {0x80200, 0x00010000},
  648. #endif /* #ifdef CONFIG_FO300 */
  649. #endif
  650. {0, 0}
  651. };
  652. #endif /* CONFIG_VIDEO_SM501_32BPP */
  653. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  654. /*
  655. * Return text to be printed besides the logo.
  656. */
  657. void video_get_info_str (int line_number, char *info)
  658. {
  659. if (line_number == 1) {
  660. strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
  661. #if defined (CONFIG_CHARON) || defined (CONFIG_FO300) || \
  662. defined(CONFIG_STK52XX) || defined(CONFIG_TB5200)
  663. } else if (line_number == 2) {
  664. #if defined (CONFIG_CHARON)
  665. strcpy (info, " on a CHARON carrier board");
  666. #endif
  667. #if defined (CONFIG_STK52XX)
  668. strcpy (info, " on a STK52xx carrier board");
  669. #endif
  670. #if defined (CONFIG_TB5200)
  671. strcpy (info, " on a TB5200 carrier board");
  672. #endif
  673. #if defined (CONFIG_FO300)
  674. strcpy (info, " on a FO300 carrier board");
  675. #endif
  676. #endif
  677. }
  678. else {
  679. info [0] = '\0';
  680. }
  681. }
  682. #endif
  683. /*
  684. * Returns SM501 register base address. First thing called in the
  685. * driver. Checks if SM501 is physically present.
  686. */
  687. unsigned int board_video_init (void)
  688. {
  689. u16 save, tmp;
  690. int restore, ret;
  691. /*
  692. * Check for Grafic Controller
  693. */
  694. /* save origianl FB content */
  695. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  696. restore = 1;
  697. /* write test pattern to FB memory */
  698. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  699. __asm__ volatile ("sync");
  700. /*
  701. * Put a different pattern on the data lines: otherwise they may float
  702. * long enough to read back what we wrote.
  703. */
  704. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  705. if (tmp == 0xA5A5)
  706. puts ("!! possible error in grafic controller detection\n");
  707. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  708. /* no grafic controller found */
  709. restore = 0;
  710. ret = 0;
  711. } else {
  712. ret = SM501_MMIO_BASE;
  713. }
  714. if (restore) {
  715. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  716. __asm__ volatile ("sync");
  717. }
  718. return ret;
  719. }
  720. /*
  721. * Returns SM501 framebuffer address
  722. */
  723. unsigned int board_video_get_fb (void)
  724. {
  725. return SM501_FB_BASE;
  726. }
  727. /*
  728. * Called after initializing the SM501 and before clearing the screen.
  729. */
  730. void board_validate_screen (unsigned int base)
  731. {
  732. }
  733. /*
  734. * Return a pointer to the initialization sequence.
  735. */
  736. const SMI_REGS *board_get_regs (void)
  737. {
  738. return init_regs;
  739. }
  740. int board_get_width (void)
  741. {
  742. return DISPLAY_WIDTH;
  743. }
  744. int board_get_height (void)
  745. {
  746. return DISPLAY_HEIGHT;
  747. }
  748. #endif /* CONFIG_VIDEO_SM501 */
  749. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  750. int ft_board_setup(void *blob, bd_t *bd)
  751. {
  752. ft_cpu_setup(blob, bd);
  753. #if defined(CONFIG_VIDEO)
  754. fdt_add_edid(blob, "smi,sm501", edid_buf);
  755. #endif
  756. return 0;
  757. }
  758. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  759. #if defined(CONFIG_RESET_PHY_R)
  760. #include <miiphy.h>
  761. void reset_phy(void)
  762. {
  763. /* init Micrel KSZ8993 PHY */
  764. miiphy_write("FEC", CONFIG_PHY_ADDR, 0x01, 0x09);
  765. }
  766. #endif
  767. int board_eth_init(bd_t *bis)
  768. {
  769. cpu_eth_init(bis); /* Built in FEC comes first */
  770. return pci_eth_init(bis);
  771. }