tqm5200.c 21 KB

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