socrates.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 "upm_table.h"
  39. DECLARE_GLOBAL_DATA_PTR;
  40. extern flash_info_t flash_info[]; /* FLASH chips info */
  41. void local_bus_init (void);
  42. ulong flash_get_size (ulong base, int banknum);
  43. int checkboard (void)
  44. {
  45. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  46. char *src;
  47. int f;
  48. char *s = getenv("serial#");
  49. puts("Board: Socrates");
  50. if (s != NULL) {
  51. puts(", serial# ");
  52. puts(s);
  53. }
  54. putc('\n');
  55. #ifdef CONFIG_PCI
  56. /* Check the PCI_clk sel bit */
  57. if (in_be32(&gur->porpllsr) & (1<<15)) {
  58. src = "SYSCLK";
  59. f = CONFIG_SYS_CLK_FREQ;
  60. } else {
  61. src = "PCI_CLK";
  62. f = CONFIG_PCI_CLK_FREQ;
  63. }
  64. printf ("PCI1: 32 bit, %d MHz (%s)\n", f/1000000, src);
  65. #else
  66. printf ("PCI1: disabled\n");
  67. #endif
  68. /*
  69. * Initialize local bus.
  70. */
  71. local_bus_init ();
  72. return 0;
  73. }
  74. int misc_init_r (void)
  75. {
  76. volatile ccsr_lbc_t *memctl = (void *)(CFG_MPC85xx_LBC_ADDR);
  77. /*
  78. * Adjust flash start and offset to detected values
  79. */
  80. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  81. gd->bd->bi_flashoffset = 0;
  82. /*
  83. * Check if boot FLASH isn't max size
  84. */
  85. if (gd->bd->bi_flashsize < (0 - CFG_FLASH0)) {
  86. memctl->or0 = gd->bd->bi_flashstart | (CFG_OR0_PRELIM & 0x00007fff);
  87. memctl->br0 = gd->bd->bi_flashstart | (CFG_BR0_PRELIM & 0x00007fff);
  88. /*
  89. * Re-check to get correct base address
  90. */
  91. flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
  92. }
  93. /*
  94. * Check if only one FLASH bank is available
  95. */
  96. if (gd->bd->bi_flashsize != CFG_MAX_FLASH_BANKS * (0 - CFG_FLASH0)) {
  97. memctl->or1 = 0;
  98. memctl->br1 = 0;
  99. /*
  100. * Re-do flash protection upon new addresses
  101. */
  102. flash_protect (FLAG_PROTECT_CLEAR,
  103. gd->bd->bi_flashstart, 0xffffffff,
  104. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  105. /* Monitor protection ON by default */
  106. flash_protect (FLAG_PROTECT_SET,
  107. CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
  108. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  109. /* Environment protection ON by default */
  110. flash_protect (FLAG_PROTECT_SET,
  111. CFG_ENV_ADDR,
  112. CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
  113. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  114. /* Redundant environment protection ON by default */
  115. flash_protect (FLAG_PROTECT_SET,
  116. CFG_ENV_ADDR_REDUND,
  117. CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
  118. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  119. }
  120. return 0;
  121. }
  122. /*
  123. * Initialize Local Bus
  124. */
  125. void local_bus_init (void)
  126. {
  127. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  128. volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
  129. sys_info_t sysinfo;
  130. uint clkdiv;
  131. uint lbc_mhz;
  132. uint lcrr = CFG_LBC_LCRR;
  133. get_sys_info (&sysinfo);
  134. clkdiv = lbc->lcrr & 0x0f;
  135. lbc_mhz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  136. /* Disable PLL bypass for Local Bus Clock >= 66 MHz */
  137. if (lbc_mhz >= 66)
  138. lcrr &= ~LCRR_DBYP; /* DLL Enabled */
  139. else
  140. lcrr |= LCRR_DBYP; /* DLL Bypass */
  141. out_be32 (&lbc->lcrr, lcrr);
  142. asm ("sync;isync;msync");
  143. out_be32 (&lbc->ltesr, 0xffffffff); /* Clear LBC error interrupts */
  144. out_be32 (&lbc->lteir, 0xffffffff); /* Enable LBC error interrupts */
  145. out_be32 (&ecm->eedr, 0xffffffff); /* Clear ecm errors */
  146. out_be32 (&ecm->eeer, 0xffffffff); /* Enable ecm errors */
  147. /* Init UPMA for FPGA access */
  148. out_be32 (&lbc->mamr, 0x44440); /* Use a customer-supplied value */
  149. upmconfig (UPMA, (uint *)UPMTableA, sizeof(UPMTableA)/sizeof(int));
  150. if (getenv("lime")) {
  151. /* Init UPMB for Lime controller access */
  152. out_be32 (&lbc->mbmr, 0x444440); /* Use a customer-supplied value */
  153. upmconfig (UPMB, (uint *)UPMTableB, sizeof(UPMTableB)/sizeof(int));
  154. }
  155. }
  156. #if defined(CONFIG_PCI)
  157. /*
  158. * Initialize PCI Devices, report devices found.
  159. */
  160. #ifndef CONFIG_PCI_PNP
  161. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  162. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  163. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  164. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  165. PCI_ENET0_MEMADDR,
  166. PCI_COMMAND_MEMORY |
  167. PCI_COMMAND_MASTER}},
  168. {}
  169. };
  170. #endif
  171. static struct pci_controller hose = {
  172. #ifndef CONFIG_PCI_PNP
  173. config_table:pci_mpc85xxads_config_table,
  174. #endif
  175. };
  176. #endif /* CONFIG_PCI */
  177. void pci_init_board (void)
  178. {
  179. #ifdef CONFIG_PCI
  180. pci_mpc85xx_init (&hose);
  181. #endif /* CONFIG_PCI */
  182. }
  183. #ifdef CONFIG_BOARD_EARLY_INIT_R
  184. int board_early_init_r (void)
  185. {
  186. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  187. /* set and reset the GPIO pin 2 which will reset the W83782G chip */
  188. out_8((unsigned char*)&gur->gpoutdr, 0x3F );
  189. out_be32((unsigned int*)&gur->gpiocr, 0x200 ); /* enable GPOut */
  190. udelay(200);
  191. out_8( (unsigned char*)&gur->gpoutdr, 0x1F );
  192. return (0);
  193. }
  194. #endif /* CONFIG_BOARD_EARLY_INIT_R */
  195. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  196. void
  197. ft_board_setup(void *blob, bd_t *bd)
  198. {
  199. u32 val[12];
  200. int rc, i = 0;
  201. ft_cpu_setup(blob, bd);
  202. /* Fixup NOR FLASH mapping */
  203. val[i++] = 0; /* chip select number */
  204. val[i++] = 0; /* always 0 */
  205. val[i++] = gd->bd->bi_flashstart;
  206. val[i++] = gd->bd->bi_flashsize;
  207. if (getenv("lime")) {
  208. /* Fixup LIME mapping */
  209. val[i++] = 2; /* chip select number */
  210. val[i++] = 0; /* always 0 */
  211. val[i++] = CFG_LIME_BASE;
  212. val[i++] = CFG_LIME_SIZE;
  213. }
  214. /* Fixup FPGA mapping */
  215. val[i++] = 3; /* chip select number */
  216. val[i++] = 0; /* always 0 */
  217. val[i++] = CFG_FPGA_BASE;
  218. val[i++] = CFG_FPGA_SIZE;
  219. rc = fdt_find_and_setprop(blob, "/localbus", "ranges",
  220. val, i * sizeof(u32), 1);
  221. if (rc)
  222. printf("Unable to update localbus ranges, err=%s\n",
  223. fdt_strerror(rc));
  224. }
  225. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  226. #include <i2c.h>
  227. #include <mb862xx.h>
  228. #include <video_fb.h>
  229. #define CFG_LIME_SRST ((CFG_LIME_BASE) + 0x01FC002C)
  230. #define CFG_LIME_CCF ((CFG_LIME_BASE) + 0x01FC0038)
  231. #define CFG_LIME_MMR ((CFG_LIME_BASE) + 0x01FCFFFC)
  232. /* Lime clock frequency */
  233. #define CFG_LIME_CLK_100MHZ 0x00000
  234. #define CFG_LIME_CLK_133MHZ 0x10000
  235. /* SDRAM parameter */
  236. #define CFG_LIME_MMR_VALUE 0x4157BA63
  237. #define DISPLAY_WIDTH 800
  238. #define DISPLAY_HEIGHT 480
  239. #define DEFAULT_BRIGHTNESS 25
  240. #define BACKLIGHT_ENABLE (1 << 31)
  241. extern GraphicDevice mb862xx;
  242. static const gdc_regs init_regs [] =
  243. {
  244. {0x0100, 0x00010f00},
  245. {0x0020, 0x801901df},
  246. {0x0024, 0x00000000},
  247. {0x0028, 0x00000000},
  248. {0x002c, 0x00000000},
  249. {0x0110, 0x00000000},
  250. {0x0114, 0x00000000},
  251. {0x0118, 0x01df0320},
  252. {0x0004, 0x041f0000},
  253. {0x0008, 0x031f031f},
  254. {0x000c, 0x017f0349},
  255. {0x0010, 0x020c0000},
  256. {0x0014, 0x01df01e9},
  257. {0x0018, 0x00000000},
  258. {0x001c, 0x01e00320},
  259. {0x0100, 0x80010f00},
  260. {0x0, 0x0}
  261. };
  262. const gdc_regs *board_get_regs (void)
  263. {
  264. return init_regs;
  265. }
  266. /* Returns Lime base address */
  267. unsigned int board_video_init (void)
  268. {
  269. if (!getenv("lime"))
  270. return 0;
  271. /*
  272. * Reset Lime controller
  273. */
  274. out_be32((void *)CFG_LIME_SRST, 0x1);
  275. udelay(200);
  276. /* Set Lime clock to 133MHz */
  277. out_be32((void *)CFG_LIME_CCF, CFG_LIME_CLK_133MHZ);
  278. /* Delay required */
  279. udelay(300);
  280. /* Set memory parameters */
  281. out_be32((void *)CFG_LIME_MMR, CFG_LIME_MMR_VALUE);
  282. mb862xx.winSizeX = DISPLAY_WIDTH;
  283. mb862xx.winSizeY = DISPLAY_HEIGHT;
  284. mb862xx.gdfIndex = GDF_15BIT_555RGB;
  285. mb862xx.gdfBytesPP = 2;
  286. return CFG_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(CFG_I2C_W83782G_ADDR, W83782D_REG_CFG, 1, &buf, 1))
  299. return -1;
  300. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_CFG, 0x80);
  301. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_BANK_SEL, 0);
  302. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_ADCCLK, 0x40);
  303. buf = i2c_reg_read(CFG_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL);
  304. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL,
  305. buf | 0x80);
  306. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_BEEP_CTRL2, 0);
  307. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_PWMOUT1, 0x47);
  308. i2c_reg_write(CFG_I2C_W83782G_ADDR, W83782D_REG_VBAT, 0x01);
  309. buf = i2c_reg_read(CFG_I2C_W83782G_ADDR, W83782D_REG_CFG);
  310. i2c_reg_write(CFG_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(CFG_I2C_W83782G_ADDR, 0x4e, 1, &old_buf, 1))
  321. goto err;
  322. else
  323. buf = old_buf & 0xf8;
  324. if (i2c_write(CFG_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(CFG_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  330. goto err;
  331. /* LEDs on */
  332. reg = in_be32((void *)(CFG_FPGA_BASE + 0x0c));
  333. if (!(reg & BACKLIGHT_ENABLE));
  334. out_be32((void *)(CFG_FPGA_BASE + 0x0c),
  335. reg | BACKLIGHT_ENABLE);
  336. } else {
  337. buf = 0;
  338. if (i2c_write(CFG_I2C_W83782G_ADDR, 0x5b, 1, &buf, 1))
  339. goto err;
  340. /* LEDs off */
  341. reg = in_be32((void *)(CFG_FPGA_BASE + 0x0c));
  342. reg &= ~BACKLIGHT_ENABLE;
  343. out_be32((void *)(CFG_FPGA_BASE + 0x0c), reg);
  344. }
  345. /* Restore previous bank setting */
  346. if (i2c_write(CFG_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