socrates.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. /*
  81. * Adjust flash start and offset to detected values
  82. */
  83. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  84. gd->bd->bi_flashoffset = 0;
  85. /*
  86. * Check if boot FLASH isn't max size
  87. */
  88. if (gd->bd->bi_flashsize < (0 - CONFIG_SYS_FLASH0)) {
  89. set_lbc_or(0, gd->bd->bi_flashstart |
  90. (CONFIG_SYS_OR0_PRELIM & 0x00007fff));
  91. set_lbc_br(0, gd->bd->bi_flashstart |
  92. (CONFIG_SYS_BR0_PRELIM & 0x00007fff));
  93. /*
  94. * Re-check to get correct base address
  95. */
  96. flash_get_size(gd->bd->bi_flashstart, CONFIG_SYS_MAX_FLASH_BANKS - 1);
  97. }
  98. /*
  99. * Check if only one FLASH bank is available
  100. */
  101. if (gd->bd->bi_flashsize != CONFIG_SYS_MAX_FLASH_BANKS * (0 - CONFIG_SYS_FLASH0)) {
  102. set_lbc_or(1, 0);
  103. set_lbc_br(1, 0);
  104. /*
  105. * Re-do flash protection upon new addresses
  106. */
  107. flash_protect (FLAG_PROTECT_CLEAR,
  108. gd->bd->bi_flashstart, 0xffffffff,
  109. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  110. /* Monitor protection ON by default */
  111. flash_protect (FLAG_PROTECT_SET,
  112. CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
  113. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  114. /* Environment protection ON by default */
  115. flash_protect (FLAG_PROTECT_SET,
  116. CONFIG_ENV_ADDR,
  117. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  118. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  119. /* Redundant environment protection ON by default */
  120. flash_protect (FLAG_PROTECT_SET,
  121. CONFIG_ENV_ADDR_REDUND,
  122. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  123. &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
  124. }
  125. return 0;
  126. }
  127. /*
  128. * Initialize Local Bus
  129. */
  130. void local_bus_init (void)
  131. {
  132. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  133. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  134. sys_info_t sysinfo;
  135. uint clkdiv;
  136. uint lbc_mhz;
  137. uint lcrr = CONFIG_SYS_LBC_LCRR;
  138. get_sys_info (&sysinfo);
  139. clkdiv = lbc->lcrr & LCRR_CLKDIV;
  140. lbc_mhz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  141. /* Disable PLL bypass for Local Bus Clock >= 66 MHz */
  142. if (lbc_mhz >= 66)
  143. lcrr &= ~LCRR_DBYP; /* DLL Enabled */
  144. else
  145. lcrr |= LCRR_DBYP; /* DLL Bypass */
  146. out_be32 (&lbc->lcrr, lcrr);
  147. asm ("sync;isync;msync");
  148. out_be32 (&lbc->ltesr, 0xffffffff); /* Clear LBC error interrupts */
  149. out_be32 (&lbc->lteir, 0xffffffff); /* Enable LBC error interrupts */
  150. out_be32 (&ecm->eedr, 0xffffffff); /* Clear ecm errors */
  151. out_be32 (&ecm->eeer, 0xffffffff); /* Enable ecm errors */
  152. /* Init UPMA for FPGA access */
  153. out_be32 (&lbc->mamr, 0x44440); /* Use a customer-supplied value */
  154. upmconfig (UPMA, (uint *)UPMTableA, sizeof(UPMTableA)/sizeof(int));
  155. /* Init UPMB for Lime controller access */
  156. out_be32 (&lbc->mbmr, 0x444440); /* Use a customer-supplied value */
  157. upmconfig (UPMB, (uint *)UPMTableB, sizeof(UPMTableB)/sizeof(int));
  158. }
  159. #if defined(CONFIG_PCI)
  160. /*
  161. * Initialize PCI Devices, report devices found.
  162. */
  163. #ifndef CONFIG_PCI_PNP
  164. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  165. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  166. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  167. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  168. PCI_ENET0_MEMADDR,
  169. PCI_COMMAND_MEMORY |
  170. PCI_COMMAND_MASTER}},
  171. {}
  172. };
  173. #endif
  174. static struct pci_controller hose = {
  175. #ifndef CONFIG_PCI_PNP
  176. config_table:pci_mpc85xxads_config_table,
  177. #endif
  178. };
  179. #endif /* CONFIG_PCI */
  180. void pci_init_board (void)
  181. {
  182. #ifdef CONFIG_PCI
  183. pci_mpc85xx_init (&hose);
  184. #endif /* CONFIG_PCI */
  185. }
  186. #ifdef CONFIG_BOARD_EARLY_INIT_R
  187. int board_early_init_r (void)
  188. {
  189. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  190. /* set and reset the GPIO pin 2 which will reset the W83782G chip */
  191. out_8((unsigned char*)&gur->gpoutdr, 0x3F );
  192. out_be32((unsigned int*)&gur->gpiocr, 0x200 ); /* enable GPOut */
  193. udelay(200);
  194. out_8( (unsigned char*)&gur->gpoutdr, 0x1F );
  195. return (0);
  196. }
  197. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  198. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  199. void
  200. ft_board_setup(void *blob, bd_t *bd)
  201. {
  202. u32 val[12];
  203. int rc, i = 0;
  204. ft_cpu_setup(blob, bd);
  205. /* Fixup NOR FLASH mapping */
  206. val[i++] = 0; /* chip select number */
  207. val[i++] = 0; /* always 0 */
  208. val[i++] = gd->bd->bi_flashstart;
  209. val[i++] = gd->bd->bi_flashsize;
  210. if (mb862xx.frameAdrs == CONFIG_SYS_LIME_BASE) {
  211. /* Fixup LIME mapping */
  212. val[i++] = 2; /* chip select number */
  213. val[i++] = 0; /* always 0 */
  214. val[i++] = CONFIG_SYS_LIME_BASE;
  215. val[i++] = CONFIG_SYS_LIME_SIZE;
  216. }
  217. /* Fixup FPGA mapping */
  218. val[i++] = 3; /* chip select number */
  219. val[i++] = 0; /* always 0 */
  220. val[i++] = CONFIG_SYS_FPGA_BASE;
  221. val[i++] = CONFIG_SYS_FPGA_SIZE;
  222. rc = fdt_find_and_setprop(blob, "/localbus", "ranges",
  223. val, i * sizeof(u32), 1);
  224. if (rc)
  225. printf("Unable to update localbus ranges, err=%s\n",
  226. fdt_strerror(rc));
  227. }
  228. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  229. #define DEFAULT_BRIGHTNESS 25
  230. #define BACKLIGHT_ENABLE (1 << 31)
  231. static const gdc_regs init_regs [] =
  232. {
  233. {0x0100, 0x00010f00},
  234. {0x0020, 0x801901df},
  235. {0x0024, 0x00000000},
  236. {0x0028, 0x00000000},
  237. {0x002c, 0x00000000},
  238. {0x0110, 0x00000000},
  239. {0x0114, 0x00000000},
  240. {0x0118, 0x01df0320},
  241. {0x0004, 0x041f0000},
  242. {0x0008, 0x031f031f},
  243. {0x000c, 0x017f0349},
  244. {0x0010, 0x020c0000},
  245. {0x0014, 0x01df01e9},
  246. {0x0018, 0x00000000},
  247. {0x001c, 0x01e00320},
  248. {0x0100, 0x80010f00},
  249. {0x0, 0x0}
  250. };
  251. const gdc_regs *board_get_regs (void)
  252. {
  253. return init_regs;
  254. }
  255. int lime_probe(void)
  256. {
  257. uint cfg_br2;
  258. uint cfg_or2;
  259. int type;
  260. cfg_br2 = get_lbc_br(2);
  261. cfg_or2 = get_lbc_or(2);
  262. /* Configure GPCM for CS2 */
  263. set_lbc_br(2, 0);
  264. set_lbc_or(2, 0xfc000410);
  265. set_lbc_br(2, (CONFIG_SYS_LIME_BASE) | 0x00001901);
  266. /* Get controller type */
  267. type = mb862xx_probe(CONFIG_SYS_LIME_BASE);
  268. /* Restore previous CS2 configuration */
  269. set_lbc_br(2, 0);
  270. set_lbc_or(2, cfg_or2);
  271. set_lbc_br(2, cfg_br2);
  272. return (type == MB862XX_TYPE_LIME) ? 1 : 0;
  273. }
  274. /* Returns Lime base address */
  275. unsigned int board_video_init (void)
  276. {
  277. if (!lime_probe())
  278. return 0;
  279. mb862xx.winSizeX = 800;
  280. mb862xx.winSizeY = 480;
  281. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  282. mb862xx.gdfBytesPP = 2;
  283. return CONFIG_SYS_LIME_BASE;
  284. }
  285. #define W83782D_REG_CFG 0x40
  286. #define W83782D_REG_BANK_SEL 0x4e
  287. #define W83782D_REG_ADCCLK 0x4b
  288. #define W83782D_REG_BEEP_CTRL 0x4d
  289. #define W83782D_REG_BEEP_CTRL2 0x57
  290. #define W83782D_REG_PWMOUT1 0x5b
  291. #define W83782D_REG_VBAT 0x5d
  292. static int w83782d_hwmon_init(void)
  293. {
  294. u8 buf;
  295. if (i2c_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG, 1, &buf, 1))
  296. return -1;
  297. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG, 0x80);
  298. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BANK_SEL, 0);
  299. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_ADCCLK, 0x40);
  300. buf = i2c_reg_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL);
  301. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL,
  302. buf | 0x80);
  303. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL2, 0);
  304. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_PWMOUT1, 0x47);
  305. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_VBAT, 0x01);
  306. buf = i2c_reg_read(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG);
  307. i2c_reg_write(CONFIG_SYS_I2C_W83782G_ADDR, W83782D_REG_CFG,
  308. (buf & 0xf4) | 0x01);
  309. return 0;
  310. }
  311. static void board_backlight_brightness(int br)
  312. {
  313. u32 reg;
  314. u8 buf;
  315. u8 old_buf;
  316. /* Select bank 0 */
  317. if (i2c_read(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &old_buf, 1))
  318. goto err;
  319. else
  320. buf = old_buf & 0xf8;
  321. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &buf, 1))
  322. goto err;
  323. if (br > 0) {
  324. /* PWMOUT1 duty cycle ctrl */
  325. buf = 255 / (100 / br);
  326. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  327. goto err;
  328. /* LEDs on */
  329. reg = in_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c));
  330. if (!(reg & BACKLIGHT_ENABLE));
  331. out_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c),
  332. reg | BACKLIGHT_ENABLE);
  333. } else {
  334. buf = 0;
  335. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  336. goto err;
  337. /* LEDs off */
  338. reg = in_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c));
  339. reg &= ~BACKLIGHT_ENABLE;
  340. out_be32((void *)(CONFIG_SYS_FPGA_BASE + 0x0c), reg);
  341. }
  342. /* Restore previous bank setting */
  343. if (i2c_write(CONFIG_SYS_I2C_W83782G_ADDR, 0x4e, 1, &old_buf, 1))
  344. goto err;
  345. return;
  346. err:
  347. printf("W83782G I2C access failed\n");
  348. }
  349. void board_backlight_switch (int flag)
  350. {
  351. char * param;
  352. int rc;
  353. if (w83782d_hwmon_init())
  354. printf ("hwmon IC init failed\n");
  355. if (flag) {
  356. param = getenv("brightness");
  357. rc = param ? simple_strtol(param, NULL, 10) : -1;
  358. if (rc < 0)
  359. rc = DEFAULT_BRIGHTNESS;
  360. } else {
  361. rc = 0;
  362. }
  363. board_backlight_brightness(rc);
  364. }
  365. #if defined(CONFIG_CONSOLE_EXTRA_INFO)
  366. /*
  367. * Return text to be printed besides the logo.
  368. */
  369. void video_get_info_str (int line_number, char *info)
  370. {
  371. if (line_number == 1) {
  372. strcpy (info, " Board: Socrates");
  373. } else {
  374. info [0] = '\0';
  375. }
  376. }
  377. #endif