tqm5200.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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_TQM5200S)
  226. # define MODULE_NAME "TQM5200S"
  227. #else
  228. # define MODULE_NAME "TQM5200"
  229. #endif
  230. #if defined(CONFIG_STK52XX)
  231. # define CARRIER_NAME "STK52xx"
  232. #elif defined(CONFIG_CAM5200)
  233. # define CARRIER_NAME "CAM5200"
  234. #elif defined(CONFIG_FO300)
  235. # define CARRIER_NAME "FO300"
  236. #elif defined(CONFIG_CHARON)
  237. # define CARRIER_NAME "CHARON"
  238. #else
  239. # error "UNKNOWN"
  240. #endif
  241. puts ( "Board: " MODULE_NAME " (TQ-Components GmbH)\n"
  242. " on a " CARRIER_NAME " carrier board\n");
  243. return 0;
  244. }
  245. #undef MODULE_NAME
  246. #undef CARRIER_NAME
  247. void flash_preinit(void)
  248. {
  249. /*
  250. * Now, when we are in RAM, enable flash write
  251. * access for detection process.
  252. * Note that CS_BOOT cannot be cleared when
  253. * executing in flash.
  254. */
  255. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  256. }
  257. #ifdef CONFIG_PCI
  258. static struct pci_controller hose;
  259. extern void pci_mpc5xxx_init(struct pci_controller *);
  260. void pci_init_board(void)
  261. {
  262. pci_mpc5xxx_init(&hose);
  263. }
  264. #endif
  265. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  266. #if defined (CONFIG_MINIFAP)
  267. #define SM501_POWER_MODE0_GATE 0x00000040UL
  268. #define SM501_POWER_MODE1_GATE 0x00000048UL
  269. #define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
  270. #define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
  271. #define SM501_GPIO_DATA_HIGH 0x00010004UL
  272. #define SM501_GPIO_51 0x00080000UL
  273. #endif /* CONFIG MINIFAP */
  274. void init_ide_reset (void)
  275. {
  276. debug ("init_ide_reset\n");
  277. #if defined (CONFIG_MINIFAP)
  278. /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
  279. /* enable GPIO control (in both power modes) */
  280. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
  281. POWER_MODE_GATE_GPIO_PWM_I2C;
  282. *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
  283. POWER_MODE_GATE_GPIO_PWM_I2C;
  284. /* configure GPIO51 as output */
  285. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
  286. SM501_GPIO_51;
  287. #else
  288. /* Configure PSC1_4 as GPIO output for ATA reset */
  289. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  290. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  291. /* by default the ATA reset is de-asserted */
  292. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  293. #endif
  294. }
  295. void ide_set_reset (int idereset)
  296. {
  297. debug ("ide_reset(%d)\n", idereset);
  298. #if defined (CONFIG_MINIFAP)
  299. if (idereset) {
  300. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
  301. ~SM501_GPIO_51;
  302. } else {
  303. *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
  304. SM501_GPIO_51;
  305. }
  306. #else
  307. if (idereset) {
  308. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  309. } else {
  310. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  311. }
  312. #endif
  313. }
  314. #endif
  315. #ifdef CONFIG_POST
  316. /*
  317. * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
  318. * is left open, no keypress is detected.
  319. */
  320. int post_hotkeys_pressed(void)
  321. {
  322. #ifdef CONFIG_STK52XX
  323. struct mpc5xxx_gpio *gpio;
  324. gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
  325. /*
  326. * Configure PSC6_0 through PSC6_3 as GPIO.
  327. */
  328. gpio->port_config &= ~(0x00700000);
  329. /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
  330. gpio->simple_gpioe |= 0x20000000;
  331. /* Configure GPIO_IRDA_1 as input */
  332. gpio->simple_ddr &= ~(0x20000000);
  333. return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
  334. #else
  335. return 0;
  336. #endif
  337. }
  338. #endif
  339. #ifdef CONFIG_BOARD_EARLY_INIT_R
  340. int board_early_init_r (void)
  341. {
  342. extern int usb_cpu_init(void);
  343. #ifdef CONFIG_PS2MULT
  344. ps2mult_early_init();
  345. #endif /* CONFIG_PS2MULT */
  346. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
  347. /* Low level USB init, required for proper kernel operation */
  348. usb_cpu_init();
  349. #endif
  350. return (0);
  351. }
  352. #endif
  353. #ifdef CONFIG_FO300
  354. int silent_boot (void)
  355. {
  356. vu_long timer3_status;
  357. /* Configure GPT3 as GPIO input */
  358. *(vu_long *)MPC5XXX_GPT3_ENABLE = 0x00000004;
  359. /* Read in TIMER_3 pin status */
  360. timer3_status = *(vu_long *)MPC5XXX_GPT3_STATUS;
  361. #ifdef FO300_SILENT_CONSOLE_WHEN_S1_CLOSED
  362. /* Force silent console mode if S1 switch
  363. * is in closed position (TIMER_3 pin status is LOW). */
  364. if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 0)
  365. return 1;
  366. #else
  367. /* Force silent console mode if S1 switch
  368. * is in open position (TIMER_3 pin status is HIGH). */
  369. if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 1)
  370. return 1;
  371. #endif
  372. return 0;
  373. }
  374. int board_early_init_f (void)
  375. {
  376. if (silent_boot())
  377. gd->flags |= GD_FLG_SILENT;
  378. return 0;
  379. }
  380. #endif /* CONFIG_FO300 */
  381. #if defined(CONFIG_CHARON)
  382. #include <i2c.h>
  383. #include <asm/io.h>
  384. /* The TFP410 registers */
  385. #define TFP410_REG_VEN_ID_L 0x00
  386. #define TFP410_REG_VEN_ID_H 0x01
  387. #define TFP410_REG_DEV_ID_L 0x02
  388. #define TFP410_REG_DEV_ID_H 0x03
  389. #define TFP410_REG_REV_ID 0x04
  390. #define TFP410_REG_CTL_1_MODE 0x08
  391. #define TFP410_REG_CTL_2_MODE 0x09
  392. #define TFP410_REG_CTL_3_MODE 0x0A
  393. #define TFP410_REG_CFG 0x0B
  394. #define TFP410_REG_DE_DLY 0x32
  395. #define TFP410_REG_DE_CTL 0x33
  396. #define TFP410_REG_DE_TOP 0x34
  397. #define TFP410_REG_DE_CNT_L 0x36
  398. #define TFP410_REG_DE_CNT_H 0x37
  399. #define TFP410_REG_DE_LIN_L 0x38
  400. #define TFP410_REG_DE_LIN_H 0x39
  401. #define TFP410_REG_H_RES_L 0x3A
  402. #define TFP410_REG_H_RES_H 0x3B
  403. #define TFP410_REG_V_RES_L 0x3C
  404. #define TFP410_REG_V_RES_H 0x3D
  405. static int tfp410_read_reg(int reg, uchar *buf)
  406. {
  407. if (i2c_read(CONFIG_SYS_TFP410_ADDR, reg, 1, buf, 1) != 0) {
  408. puts ("Error reading the chip.\n");
  409. return 1;
  410. }
  411. return 0;
  412. }
  413. static int tfp410_write_reg(int reg, uchar buf)
  414. {
  415. if (i2c_write(CONFIG_SYS_TFP410_ADDR, reg, 1, &buf, 1) != 0) {
  416. puts ("Error writing the chip.\n");
  417. return 1;
  418. }
  419. return 0;
  420. }
  421. typedef struct _tfp410_config {
  422. int reg;
  423. uchar val;
  424. }TFP410_CONFIG;
  425. static TFP410_CONFIG tfp410_configtbl[] = {
  426. {TFP410_REG_CTL_1_MODE, 0x37},
  427. {TFP410_REG_CTL_2_MODE, 0x20},
  428. {TFP410_REG_CTL_3_MODE, 0x80},
  429. {TFP410_REG_DE_DLY, 0x90},
  430. {TFP410_REG_DE_CTL, 0x00},
  431. {TFP410_REG_DE_TOP, 0x23},
  432. {TFP410_REG_DE_CNT_H, 0x02},
  433. {TFP410_REG_DE_CNT_L, 0x80},
  434. {TFP410_REG_DE_LIN_H, 0x01},
  435. {TFP410_REG_DE_LIN_L, 0xe0},
  436. {-1, 0},
  437. };
  438. static int charon_last_stage_init(void)
  439. {
  440. volatile struct mpc5xxx_lpb *lpb =
  441. (struct mpc5xxx_lpb *) MPC5XXX_LPB;
  442. int oldbus = i2c_get_bus_num();
  443. uchar buf;
  444. int i = 0;
  445. i2c_set_bus_num(CONFIG_SYS_TFP410_BUS);
  446. /* check version */
  447. if (tfp410_read_reg(TFP410_REG_DEV_ID_H, &buf) != 0)
  448. return -1;
  449. if (!(buf & 0x04))
  450. return -1;
  451. if (tfp410_read_reg(TFP410_REG_DEV_ID_L, &buf) != 0)
  452. return -1;
  453. if (!(buf & 0x10))
  454. return -1;
  455. /* OK, now init the chip */
  456. while (tfp410_configtbl[i].reg != -1) {
  457. int ret;
  458. ret = tfp410_write_reg(tfp410_configtbl[i].reg,
  459. tfp410_configtbl[i].val);
  460. if (ret != 0)
  461. return -1;
  462. i++;
  463. }
  464. printf("TFP410 initialized.\n");
  465. i2c_set_bus_num(oldbus);
  466. /* set deadcycle for cs3 to 0 */
  467. setbits_be32(&lpb->cs_deadcycle, 0xffffcfff);
  468. return 0;
  469. }
  470. #endif
  471. int last_stage_init (void)
  472. {
  473. /*
  474. * auto scan for really existing devices and re-set chip select
  475. * configuration.
  476. */
  477. u16 save, tmp;
  478. int restore;
  479. /*
  480. * Check for SRAM and SRAM size
  481. */
  482. /* save original SRAM content */
  483. save = *(volatile u16 *)CONFIG_SYS_CS2_START;
  484. restore = 1;
  485. /* write test pattern to SRAM */
  486. *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
  487. __asm__ volatile ("sync");
  488. /*
  489. * Put a different pattern on the data lines: otherwise they may float
  490. * long enough to read back what we wrote.
  491. */
  492. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  493. if (tmp == 0xA5A5)
  494. puts ("!! possible error in SRAM detection\n");
  495. if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
  496. /* no SRAM at all, disable cs */
  497. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
  498. *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
  499. *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
  500. restore = 0;
  501. __asm__ volatile ("sync");
  502. } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
  503. /* make sure that we access a mirrored address */
  504. *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
  505. __asm__ volatile ("sync");
  506. if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
  507. /* SRAM size = 512 kByte */
  508. *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
  509. 0x80000);
  510. __asm__ volatile ("sync");
  511. puts ("SRAM: 512 kB\n");
  512. }
  513. else
  514. puts ("!! possible error in SRAM detection\n");
  515. } else {
  516. puts ("SRAM: 1 MB\n");
  517. }
  518. /* restore origianl SRAM content */
  519. if (restore) {
  520. *(volatile u16 *)CONFIG_SYS_CS2_START = save;
  521. __asm__ volatile ("sync");
  522. }
  523. #ifndef CONFIG_TQM5200S /* The TQM5200S has no SM501 grafic controller */
  524. /*
  525. * Check for Grafic Controller
  526. */
  527. /* save origianl FB content */
  528. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  529. restore = 1;
  530. /* write test pattern to FB memory */
  531. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  532. __asm__ volatile ("sync");
  533. /*
  534. * Put a different pattern on the data lines: otherwise they may float
  535. * long enough to read back what we wrote.
  536. */
  537. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  538. if (tmp == 0xA5A5)
  539. puts ("!! possible error in grafic controller detection\n");
  540. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  541. /* no grafic controller at all, disable cs */
  542. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
  543. *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
  544. *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
  545. restore = 0;
  546. __asm__ volatile ("sync");
  547. } else {
  548. puts ("VGA: SMI501 (Voyager) with 8 MB\n");
  549. }
  550. /* restore origianl FB content */
  551. if (restore) {
  552. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  553. __asm__ volatile ("sync");
  554. }
  555. #ifdef CONFIG_FO300
  556. if (silent_boot()) {
  557. setenv("bootdelay", "0");
  558. disable_ctrlc(1);
  559. }
  560. #endif
  561. #endif /* !CONFIG_TQM5200S */
  562. #if defined(CONFIG_CHARON)
  563. charon_last_stage_init();
  564. #endif
  565. return 0;
  566. }
  567. #ifdef CONFIG_VIDEO_SM501
  568. #ifdef CONFIG_FO300
  569. #define DISPLAY_WIDTH 800
  570. #else
  571. #define DISPLAY_WIDTH 640
  572. #endif
  573. #define DISPLAY_HEIGHT 480
  574. #ifdef CONFIG_VIDEO_SM501_8BPP
  575. #error CONFIG_VIDEO_SM501_8BPP not supported.
  576. #endif /* CONFIG_VIDEO_SM501_8BPP */
  577. #ifdef CONFIG_VIDEO_SM501_16BPP
  578. #error CONFIG_VIDEO_SM501_16BPP not supported.
  579. #endif /* CONFIG_VIDEO_SM501_16BPP */
  580. #ifdef CONFIG_VIDEO_SM501_32BPP
  581. static const SMI_REGS init_regs [] =
  582. {
  583. #if 0 /* CRT only */
  584. {0x00004, 0x0},
  585. {0x00048, 0x00021807},
  586. {0x0004C, 0x10090a01},
  587. {0x00054, 0x1},
  588. {0x00040, 0x00021807},
  589. {0x00044, 0x10090a01},
  590. {0x00054, 0x0},
  591. {0x80200, 0x00010000},
  592. {0x80204, 0x0},
  593. {0x80208, 0x0A000A00},
  594. {0x8020C, 0x02fa027f},
  595. {0x80210, 0x004a028b},
  596. {0x80214, 0x020c01df},
  597. {0x80218, 0x000201e9},
  598. {0x80200, 0x00013306},
  599. #else /* panel + CRT */
  600. #ifdef CONFIG_FO300
  601. {0x00004, 0x0},
  602. {0x00048, 0x00021807},
  603. {0x0004C, 0x301a0a01},
  604. {0x00054, 0x1},
  605. {0x00040, 0x00021807},
  606. {0x00044, 0x091a0a01},
  607. {0x00054, 0x0},
  608. {0x80000, 0x0f013106},
  609. {0x80004, 0xc428bb17},
  610. {0x8000C, 0x00000000},
  611. {0x80010, 0x0C800C80},
  612. {0x80014, 0x03200000},
  613. {0x80018, 0x01e00000},
  614. {0x8001C, 0x00000000},
  615. {0x80020, 0x01e00320},
  616. {0x80024, 0x042a031f},
  617. {0x80028, 0x0086034a},
  618. {0x8002C, 0x020c01df},
  619. {0x80030, 0x000201ea},
  620. {0x80200, 0x00010000},
  621. #else
  622. {0x00004, 0x0},
  623. {0x00048, 0x00021807},
  624. {0x0004C, 0x091a0a01},
  625. {0x00054, 0x1},
  626. {0x00040, 0x00021807},
  627. {0x00044, 0x091a0a01},
  628. {0x00054, 0x0},
  629. {0x80000, 0x0f013106},
  630. {0x80004, 0xc428bb17},
  631. {0x8000C, 0x00000000},
  632. {0x80010, 0x0a000a00},
  633. {0x80014, 0x02800000},
  634. {0x80018, 0x01e00000},
  635. {0x8001C, 0x00000000},
  636. {0x80020, 0x01e00280},
  637. {0x80024, 0x02fa027f},
  638. {0x80028, 0x004a028b},
  639. {0x8002C, 0x020c01df},
  640. {0x80030, 0x000201e9},
  641. {0x80200, 0x00010000},
  642. #endif /* #ifdef CONFIG_FO300 */
  643. #endif
  644. {0, 0}
  645. };
  646. #endif /* CONFIG_VIDEO_SM501_32BPP */
  647. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  648. /*
  649. * Return text to be printed besides the logo.
  650. */
  651. void video_get_info_str (int line_number, char *info)
  652. {
  653. if (line_number == 1) {
  654. strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
  655. #if defined (CONFIG_CHARON) || defined (CONFIG_FO300) || \
  656. defined(CONFIG_STK52XX)
  657. } else if (line_number == 2) {
  658. #if defined (CONFIG_CHARON)
  659. strcpy (info, " on a CHARON carrier board");
  660. #endif
  661. #if defined (CONFIG_STK52XX)
  662. strcpy (info, " on a STK52xx carrier board");
  663. #endif
  664. #if defined (CONFIG_FO300)
  665. strcpy (info, " on a FO300 carrier board");
  666. #endif
  667. #endif
  668. }
  669. else {
  670. info [0] = '\0';
  671. }
  672. }
  673. #endif
  674. /*
  675. * Returns SM501 register base address. First thing called in the
  676. * driver. Checks if SM501 is physically present.
  677. */
  678. unsigned int board_video_init (void)
  679. {
  680. u16 save, tmp;
  681. int restore, ret;
  682. /*
  683. * Check for Grafic Controller
  684. */
  685. /* save origianl FB content */
  686. save = *(volatile u16 *)CONFIG_SYS_CS1_START;
  687. restore = 1;
  688. /* write test pattern to FB memory */
  689. *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
  690. __asm__ volatile ("sync");
  691. /*
  692. * Put a different pattern on the data lines: otherwise they may float
  693. * long enough to read back what we wrote.
  694. */
  695. tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
  696. if (tmp == 0xA5A5)
  697. puts ("!! possible error in grafic controller detection\n");
  698. if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
  699. /* no grafic controller found */
  700. restore = 0;
  701. ret = 0;
  702. } else {
  703. ret = SM501_MMIO_BASE;
  704. }
  705. if (restore) {
  706. *(volatile u16 *)CONFIG_SYS_CS1_START = save;
  707. __asm__ volatile ("sync");
  708. }
  709. return ret;
  710. }
  711. /*
  712. * Returns SM501 framebuffer address
  713. */
  714. unsigned int board_video_get_fb (void)
  715. {
  716. return SM501_FB_BASE;
  717. }
  718. /*
  719. * Called after initializing the SM501 and before clearing the screen.
  720. */
  721. void board_validate_screen (unsigned int base)
  722. {
  723. }
  724. /*
  725. * Return a pointer to the initialization sequence.
  726. */
  727. const SMI_REGS *board_get_regs (void)
  728. {
  729. return init_regs;
  730. }
  731. int board_get_width (void)
  732. {
  733. return DISPLAY_WIDTH;
  734. }
  735. int board_get_height (void)
  736. {
  737. return DISPLAY_HEIGHT;
  738. }
  739. #endif /* CONFIG_VIDEO_SM501 */
  740. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  741. int ft_board_setup(void *blob, bd_t *bd)
  742. {
  743. ft_cpu_setup(blob, bd);
  744. #if defined(CONFIG_VIDEO)
  745. fdt_add_edid(blob, "smi,sm501", edid_buf);
  746. #endif
  747. return 0;
  748. }
  749. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  750. #if defined(CONFIG_RESET_PHY_R)
  751. #include <miiphy.h>
  752. void reset_phy(void)
  753. {
  754. /* init Micrel KSZ8993 PHY */
  755. miiphy_write("FEC", CONFIG_PHY_ADDR, 0x01, 0x09);
  756. }
  757. #endif
  758. int board_eth_init(bd_t *bis)
  759. {
  760. cpu_eth_init(bis); /* Built in FEC comes first */
  761. return pci_eth_init(bis);
  762. }