socrates.c 11 KB

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