socrates.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. * (C) Copyright 2008
  3. * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com.
  4. *
  5. * Copyright 2004 Freescale Semiconductor.
  6. * (C) Copyright 2002,2003, Motorola Inc.
  7. * Xianghua Xiao, (X.Xiao@motorola.com)
  8. *
  9. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <pci.h>
  31. #include <asm/processor.h>
  32. #include <asm/immap_85xx.h>
  33. #include <ioports.h>
  34. #include <flash.h>
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #include <asm/io.h>
  38. #include <i2c.h>
  39. #include <mb862xx.h>
  40. #include <video_fb.h>
  41. #include "upm_table.h"
  42. DECLARE_GLOBAL_DATA_PTR;
  43. extern flash_info_t flash_info[]; /* FLASH chips info */
  44. extern GraphicDevice mb862xx;
  45. void local_bus_init (void);
  46. ulong flash_get_size (ulong base, int banknum);
  47. int checkboard (void)
  48. {
  49. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  50. char *src;
  51. int f;
  52. char *s = getenv("serial#");
  53. puts("Board: Socrates");
  54. if (s != NULL) {
  55. puts(", serial# ");
  56. puts(s);
  57. }
  58. putc('\n');
  59. #ifdef CONFIG_PCI
  60. /* Check the PCI_clk sel bit */
  61. if (in_be32(&gur->porpllsr) & (1<<15)) {
  62. src = "SYSCLK";
  63. f = CONFIG_SYS_CLK_FREQ;
  64. } else {
  65. src = "PCI_CLK";
  66. f = CONFIG_PCI_CLK_FREQ;
  67. }
  68. printf ("PCI1: 32 bit, %d MHz (%s)\n", f/1000000, src);
  69. #else
  70. printf ("PCI1: disabled\n");
  71. #endif
  72. /*
  73. * Initialize local bus.
  74. */
  75. local_bus_init ();
  76. return 0;
  77. }
  78. int misc_init_r (void)
  79. {
  80. volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  81. /*
  82. * Adjust flash start and offset to detected values
  83. */
  84. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  85. gd->bd->bi_flashoffset = 0;
  86. /*
  87. * Check if boot FLASH isn't max size
  88. */
  89. if (gd->bd->bi_flashsize < (0 - CONFIG_SYS_FLASH0)) {
  90. memctl->or0 = gd->bd->bi_flashstart | (CONFIG_SYS_OR0_PRELIM & 0x00007fff);
  91. memctl->br0 = gd->bd->bi_flashstart | (CONFIG_SYS_BR0_PRELIM & 0x00007fff);
  92. /*
  93. * Re-check to get correct base address
  94. */
  95. flash_get_size(gd->bd->bi_flashstart, CONFIG_SYS_MAX_FLASH_BANKS - 1);
  96. }
  97. /*
  98. * Check if only one FLASH bank is available
  99. */
  100. if (gd->bd->bi_flashsize != CONFIG_SYS_MAX_FLASH_BANKS * (0 - CONFIG_SYS_FLASH0)) {
  101. memctl->or1 = 0;
  102. memctl->br1 = 0;
  103. /*
  104. * Re-do flash protection upon new addresses
  105. */
  106. flash_protect (FLAG_PROTECT_CLEAR,
  107. gd->bd->bi_flashstart, 0xffffffff,
  108. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  109. /* Monitor protection ON by default */
  110. flash_protect (FLAG_PROTECT_SET,
  111. CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
  112. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  113. /* Environment protection ON by default */
  114. flash_protect (FLAG_PROTECT_SET,
  115. CONFIG_ENV_ADDR,
  116. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  117. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  118. /* Redundant environment protection ON by default */
  119. flash_protect (FLAG_PROTECT_SET,
  120. CONFIG_ENV_ADDR_REDUND,
  121. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE_REDUND - 1,
  122. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  123. }
  124. return 0;
  125. }
  126. /*
  127. * Initialize Local Bus
  128. */
  129. void local_bus_init (void)
  130. {
  131. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  132. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  133. sys_info_t sysinfo;
  134. uint clkdiv;
  135. uint lbc_mhz;
  136. uint lcrr = CONFIG_SYS_LBC_LCRR;
  137. get_sys_info (&sysinfo);
  138. clkdiv = lbc->lcrr & LCRR_CLKDIV;
  139. lbc_mhz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  140. /* Disable PLL bypass for Local Bus Clock >= 66 MHz */
  141. if (lbc_mhz >= 66)
  142. lcrr &= ~LCRR_DBYP; /* DLL Enabled */
  143. else
  144. lcrr |= LCRR_DBYP; /* DLL Bypass */
  145. out_be32 (&lbc->lcrr, lcrr);
  146. asm ("sync;isync;msync");
  147. out_be32 (&lbc->ltesr, 0xffffffff); /* Clear LBC error interrupts */
  148. out_be32 (&lbc->lteir, 0xffffffff); /* Enable LBC error interrupts */
  149. out_be32 (&ecm->eedr, 0xffffffff); /* Clear ecm errors */
  150. out_be32 (&ecm->eeer, 0xffffffff); /* Enable ecm errors */
  151. /* Init UPMA for FPGA access */
  152. out_be32 (&lbc->mamr, 0x44440); /* Use a customer-supplied value */
  153. upmconfig (UPMA, (uint *)UPMTableA, sizeof(UPMTableA)/sizeof(int));
  154. /* Init UPMB for Lime controller access */
  155. out_be32 (&lbc->mbmr, 0x444440); /* Use a customer-supplied value */
  156. upmconfig (UPMB, (uint *)UPMTableB, sizeof(UPMTableB)/sizeof(int));
  157. }
  158. #if defined(CONFIG_PCI)
  159. /*
  160. * Initialize PCI Devices, report devices found.
  161. */
  162. #ifndef CONFIG_PCI_PNP
  163. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  164. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  165. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  166. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  167. PCI_ENET0_MEMADDR,
  168. PCI_COMMAND_MEMORY |
  169. PCI_COMMAND_MASTER}},
  170. {}
  171. };
  172. #endif
  173. static struct pci_controller hose = {
  174. #ifndef CONFIG_PCI_PNP
  175. config_table:pci_mpc85xxads_config_table,
  176. #endif
  177. };
  178. #endif /* CONFIG_PCI */
  179. void pci_init_board (void)
  180. {
  181. #ifdef CONFIG_PCI
  182. pci_mpc85xx_init (&hose);
  183. #endif /* CONFIG_PCI */
  184. }
  185. #ifdef CONFIG_BOARD_EARLY_INIT_R
  186. int board_early_init_r (void)
  187. {
  188. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  189. /* set and reset the GPIO pin 2 which will reset the W83782G chip */
  190. out_8((unsigned char*)&gur->gpoutdr, 0x3F );
  191. out_be32((unsigned int*)&gur->gpiocr, 0x200 ); /* enable GPOut */
  192. udelay(200);
  193. out_8( (unsigned char*)&gur->gpoutdr, 0x1F );
  194. return (0);
  195. }
  196. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  197. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  198. void
  199. ft_board_setup(void *blob, bd_t *bd)
  200. {
  201. u32 val[12];
  202. int rc, i = 0;
  203. ft_cpu_setup(blob, bd);
  204. /* Fixup NOR FLASH mapping */
  205. val[i++] = 0; /* chip select number */
  206. val[i++] = 0; /* always 0 */
  207. val[i++] = gd->bd->bi_flashstart;
  208. val[i++] = gd->bd->bi_flashsize;
  209. if (mb862xx.frameAdrs == CONFIG_SYS_LIME_BASE) {
  210. /* Fixup LIME mapping */
  211. val[i++] = 2; /* chip select number */
  212. val[i++] = 0; /* always 0 */
  213. val[i++] = CONFIG_SYS_LIME_BASE;
  214. val[i++] = CONFIG_SYS_LIME_SIZE;
  215. }
  216. /* Fixup FPGA mapping */
  217. val[i++] = 3; /* chip select number */
  218. val[i++] = 0; /* always 0 */
  219. val[i++] = CONFIG_SYS_FPGA_BASE;
  220. val[i++] = CONFIG_SYS_FPGA_SIZE;
  221. rc = fdt_find_and_setprop(blob, "/localbus", "ranges",
  222. val, i * sizeof(u32), 1);
  223. if (rc)
  224. printf("Unable to update localbus ranges, err=%s\n",
  225. fdt_strerror(rc));
  226. }
  227. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  228. #define CONFIG_SYS_LIME_SRST ((CONFIG_SYS_LIME_BASE) + 0x01FC002C)
  229. #define CONFIG_SYS_LIME_CCF ((CONFIG_SYS_LIME_BASE) + 0x01FC0038)
  230. #define CONFIG_SYS_LIME_MMR ((CONFIG_SYS_LIME_BASE) + 0x01FCFFFC)
  231. /* Lime clock frequency */
  232. #define CONFIG_SYS_LIME_CLK_100MHZ 0x00000
  233. #define CONFIG_SYS_LIME_CLK_133MHZ 0x10000
  234. /* SDRAM parameter */
  235. #define CONFIG_SYS_LIME_MMR_VALUE 0x4157BA63
  236. #define DISPLAY_WIDTH 800
  237. #define DISPLAY_HEIGHT 480
  238. #define DEFAULT_BRIGHTNESS 25
  239. #define BACKLIGHT_ENABLE (1 << 31)
  240. static const gdc_regs init_regs [] =
  241. {
  242. {0x0100, 0x00010f00},
  243. {0x0020, 0x801901df},
  244. {0x0024, 0x00000000},
  245. {0x0028, 0x00000000},
  246. {0x002c, 0x00000000},
  247. {0x0110, 0x00000000},
  248. {0x0114, 0x00000000},
  249. {0x0118, 0x01df0320},
  250. {0x0004, 0x041f0000},
  251. {0x0008, 0x031f031f},
  252. {0x000c, 0x017f0349},
  253. {0x0010, 0x020c0000},
  254. {0x0014, 0x01df01e9},
  255. {0x0018, 0x00000000},
  256. {0x001c, 0x01e00320},
  257. {0x0100, 0x80010f00},
  258. {0x0, 0x0}
  259. };
  260. const gdc_regs *board_get_regs (void)
  261. {
  262. return init_regs;
  263. }
  264. #define CONFIG_SYS_LIME_CID ((CONFIG_SYS_LIME_BASE) + 0x01FC00F0)
  265. #define CONFIG_SYS_LIME_REV ((CONFIG_SYS_LIME_BASE) + 0x01FF8084)
  266. int lime_probe(void)
  267. {
  268. volatile ccsr_lbc_t *memctl = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  269. uint cfg_br2;
  270. uint cfg_or2;
  271. uint reg;
  272. cfg_br2 = memctl->br2;
  273. cfg_or2 = memctl->or2;
  274. /* Configure GPCM for CS2 */
  275. memctl->br2 = 0;
  276. memctl->or2 = 0xfc000410;
  277. memctl->br2 = (CONFIG_SYS_LIME_BASE) | 0x00001901;
  278. /* Try to access GDC ID/Revision registers */
  279. reg = in_be32((void *)CONFIG_SYS_LIME_CID);
  280. reg = in_be32((void *)CONFIG_SYS_LIME_CID);
  281. if (reg == 0x303) {
  282. reg = in_be32((void *)CONFIG_SYS_LIME_REV);
  283. reg = in_be32((void *)CONFIG_SYS_LIME_REV);
  284. reg = ((reg & ~0xff) == 0x20050100) ? 1 : 0;
  285. } else
  286. reg = 0;
  287. /* Restore previous CS2 configuration */
  288. memctl->br2 = 0;
  289. memctl->or2 = cfg_or2;
  290. memctl->br2 = cfg_br2;
  291. return reg;
  292. }
  293. /* Returns Lime base address */
  294. unsigned int board_video_init (void)
  295. {
  296. if (!lime_probe())
  297. return 0;
  298. /*
  299. * Reset Lime controller
  300. */
  301. out_be32((void *)CONFIG_SYS_LIME_SRST, 0x1);
  302. udelay(200);
  303. /* Set Lime clock to 133MHz */
  304. out_be32((void *)CONFIG_SYS_LIME_CCF, CONFIG_SYS_LIME_CLK_133MHZ);
  305. /* Delay required */
  306. udelay(300);
  307. /* Set memory parameters */
  308. out_be32((void *)CONFIG_SYS_LIME_MMR, CONFIG_SYS_LIME_MMR_VALUE);
  309. mb862xx.winSizeX = DISPLAY_WIDTH;
  310. mb862xx.winSizeY = DISPLAY_HEIGHT;
  311. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  312. mb862xx.gdfBytesPP = 2;
  313. return CONFIG_SYS_LIME_BASE;
  314. }
  315. #define W83782D_REG_CFG 0x40
  316. #define W83782D_REG_BANK_SEL 0x4e
  317. #define W83782D_REG_ADCCLK 0x4b
  318. #define W83782D_REG_BEEP_CTRL 0x4d
  319. #define W83782D_REG_BEEP_CTRL2 0x57
  320. #define W83782D_REG_PWMOUT1 0x5b
  321. #define W83782D_REG_VBAT 0x5d
  322. static int w83782d_hwmon_init(void)
  323. {
  324. u8 buf;
  325. if (i2c_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG, 1, &buf, 1))
  326. return -1;
  327. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG, 0x80);
  328. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BANK_SEL, 0);
  329. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_ADCCLK, 0x40);
  330. buf = i2c_reg_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL);
  331. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL,
  332. buf | 0x80);
  333. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL2, 0);
  334. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_PWMOUT1, 0x47);
  335. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_VBAT, 0x01);
  336. buf = i2c_reg_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG);
  337. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG,
  338. (buf & 0xf4) | 0x01);
  339. return 0;
  340. }
  341. static void board_backlight_brightness(int br)
  342. {
  343. u32 reg;
  344. u8 buf;
  345. u8 old_buf;
  346. /* Select bank 0 */
  347. if (i2c_read(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &old_buf, 1))
  348. goto err;
  349. else
  350. buf = old_buf & 0xf8;
  351. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &buf, 1))
  352. goto err;
  353. if (br > 0) {
  354. /* PWMOUT1 duty cycle ctrl */
  355. buf = 255 / (100 / br);
  356. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  357. goto err;
  358. /* LEDs on */
  359. reg = in_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c));
  360. if (!(reg & BACKLIGHT_ENABLE));
  361. out_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c),
  362. reg | BACKLIGHT_ENABLE);
  363. } else {
  364. buf = 0;
  365. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  366. goto err;
  367. /* LEDs off */
  368. reg = in_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c));
  369. reg &= ~BACKLIGHT_ENABLE;
  370. out_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c), reg);
  371. }
  372. /* Restore previous bank setting */
  373. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &old_buf, 1))
  374. goto err;
  375. return;
  376. err:
  377. printf("W83782G I2C access failed\n");
  378. }
  379. void board_backlight_switch (int flag)
  380. {
  381. char * param;
  382. int rc;
  383. if (w83782d_hwmon_init())
  384. printf ("hwmon IC init failed\n");
  385. if (flag) {
  386. param = getenv("brightness");
  387. rc = param ? simple_strtol(param, NULL, 10) : -1;
  388. if (rc < 0)
  389. rc = DEFAULT_BRIGHTNESS;
  390. } else {
  391. rc = 0;
  392. }
  393. board_backlight_brightness(rc);
  394. }
  395. #if defined(CONFIG_CONSOLE_EXTRA_INFO)
  396. /*
  397. * Return text to be printed besides the logo.
  398. */
  399. void video_get_info_str (int line_number, char *info)
  400. {
  401. if (line_number == 1) {
  402. strcpy (info, " Board: Socrates");
  403. } else {
  404. info [0] = '\0';
  405. }
  406. }
  407. #endif