apollon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  2. * (C) Copyright 2005-2007
  3. * Samsung Electronics.
  4. * Kyungmin Park <kyungmin.park@samsung.com>
  5. *
  6. * Derived from omap2420
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/arch/omap2420.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/bits.h>
  30. #include <asm/arch/mux.h>
  31. #include <asm/arch/sys_proto.h>
  32. #include <asm/arch/sys_info.h>
  33. #include <asm/arch/mem.h>
  34. #include <asm/mach-types.h>
  35. void wait_for_command_complete(unsigned int wd_base);
  36. DECLARE_GLOBAL_DATA_PTR;
  37. #define write_config_reg(reg, value) \
  38. do { \
  39. writeb(value, reg); \
  40. } while (0)
  41. #define mask_config_reg(reg, mask) \
  42. do { \
  43. char value = readb(reg) & ~(mask); \
  44. writeb(value, reg); \
  45. } while (0)
  46. /*******************************************************
  47. * Routine: delay
  48. * Description: spinning delay to use before udelay works
  49. ******************************************************/
  50. static inline void delay(unsigned long loops)
  51. {
  52. __asm__("1:\n" "subs %0, %1, #1\n"
  53. "bne 1b":"=r" (loops):"0"(loops));
  54. }
  55. /*****************************************
  56. * Routine: board_init
  57. * Description: Early hardware init.
  58. *****************************************/
  59. int board_init(void)
  60. {
  61. gpmc_init(); /* in SRAM or SDRM, finish GPMC */
  62. gd->bd->bi_arch_number = 919;
  63. /* adress of boot parameters */
  64. gd->bd->bi_boot_params = (OMAP2420_SDRC_CS0 + 0x100);
  65. return 0;
  66. }
  67. /**********************************************************
  68. * Routine: s_init
  69. * Description: Does early system init of muxing and clocks.
  70. * - Called path is with sram stack.
  71. **********************************************************/
  72. void s_init(void)
  73. {
  74. watchdog_init();
  75. set_muxconf_regs();
  76. delay(100);
  77. peripheral_enable();
  78. icache_enable();
  79. }
  80. /*******************************************************
  81. * Routine: misc_init_r
  82. * Description: Init ethernet (done here so udelay works)
  83. ********************************************************/
  84. int misc_init_r(void)
  85. {
  86. ether_init(); /* better done here so timers are init'ed */
  87. return (0);
  88. }
  89. /****************************************
  90. * Routine: watchdog_init
  91. * Description: Shut down watch dogs
  92. *****************************************/
  93. void watchdog_init(void)
  94. {
  95. /* There are 4 watch dogs. 1 secure, and 3 general purpose.
  96. * The ROM takes care of the secure one. Of the 3 GP ones,
  97. * 1 can reset us directly, the other 2 only generate MPU interrupts.
  98. */
  99. __raw_writel(WD_UNLOCK1, WD2_BASE + WSPR);
  100. wait_for_command_complete(WD2_BASE);
  101. __raw_writel(WD_UNLOCK2, WD2_BASE + WSPR);
  102. #define MPU_WD_CLOCKED 1
  103. #if MPU_WD_CLOCKED
  104. /* value 0x10 stick on aptix, BIT4 polarity seems oppsite */
  105. __raw_writel(WD_UNLOCK1, WD3_BASE + WSPR);
  106. wait_for_command_complete(WD3_BASE);
  107. __raw_writel(WD_UNLOCK2, WD3_BASE + WSPR);
  108. __raw_writel(WD_UNLOCK1, WD4_BASE + WSPR);
  109. wait_for_command_complete(WD4_BASE);
  110. __raw_writel(WD_UNLOCK2, WD4_BASE + WSPR);
  111. #endif
  112. }
  113. /******************************************************
  114. * Routine: wait_for_command_complete
  115. * Description: Wait for posting to finish on watchdog
  116. ******************************************************/
  117. void wait_for_command_complete(unsigned int wd_base)
  118. {
  119. int pending = 1;
  120. do {
  121. pending = __raw_readl(wd_base + WWPS);
  122. } while (pending);
  123. }
  124. /*******************************************************************
  125. * Routine:ether_init
  126. * Description: take the Ethernet controller out of reset and wait
  127. * for the EEPROM load to complete.
  128. ******************************************************************/
  129. void ether_init(void)
  130. {
  131. #ifdef CONFIG_DRIVER_LAN91C96
  132. int cnt = 20;
  133. __raw_writeb(0x03, OMAP2420_CTRL_BASE + 0x0f2); /*protect->gpio74 */
  134. __raw_writew(0x0, LAN_RESET_REGISTER);
  135. do {
  136. __raw_writew(0x1, LAN_RESET_REGISTER);
  137. udelay(100);
  138. if (cnt == 0) {
  139. printf("1. eth reset err\n");
  140. goto eth_reset_err_out;
  141. }
  142. --cnt;
  143. } while (__raw_readw(LAN_RESET_REGISTER) != 0x1);
  144. cnt = 20;
  145. do {
  146. __raw_writew(0x0, LAN_RESET_REGISTER);
  147. udelay(100);
  148. if (cnt == 0) {
  149. printf("2. eth reset err\n");
  150. goto eth_reset_err_out;
  151. }
  152. --cnt;
  153. } while (__raw_readw(LAN_RESET_REGISTER) != 0x0000);
  154. udelay(1000);
  155. mask_config_reg(ETH_CONTROL_REG, 0x01);
  156. udelay(1000);
  157. eth_reset_err_out:
  158. return;
  159. #endif
  160. }
  161. /**********************************************
  162. * Routine: dram_init
  163. * Description: sets uboots idea of sdram size
  164. **********************************************/
  165. int dram_init(void)
  166. {
  167. unsigned int size0 = 0, size1 = 0;
  168. u32 mtype, btype, rev = 0, cpu = 0;
  169. #define NOT_EARLY 0
  170. btype = get_board_type();
  171. mtype = get_mem_type();
  172. rev = get_cpu_rev();
  173. cpu = get_cpu_type();
  174. display_board_info(btype);
  175. if ((mtype == DDR_COMBO) || (mtype == DDR_STACKED)) {
  176. /* init other chip select */
  177. do_sdrc_init(SDRC_CS1_OSET, NOT_EARLY);
  178. }
  179. size0 = get_sdr_cs_size(SDRC_CS0_OSET);
  180. size1 = get_sdr_cs_size(SDRC_CS1_OSET);
  181. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  182. gd->bd->bi_dram[0].size = size0;
  183. #if CONFIG_NR_DRAM_BANKS > 1
  184. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + size0;
  185. gd->bd->bi_dram[1].size = size1;
  186. #endif
  187. return 0;
  188. }
  189. /**********************************************************
  190. * Routine: set_muxconf_regs
  191. * Description: Setting up the configuration Mux registers
  192. * specific to the hardware
  193. *********************************************************/
  194. void set_muxconf_regs(void)
  195. {
  196. muxSetupSDRC();
  197. muxSetupGPMC();
  198. muxSetupUsb0(); /* USB Device */
  199. muxSetupUsbHost(); /* USB Host */
  200. muxSetupUART1();
  201. muxSetupLCD();
  202. muxSetupMMCSD();
  203. muxSetupTouchScreen();
  204. }
  205. /*****************************************************************
  206. * Routine: peripheral_enable
  207. * Description: Enable the clks & power for perifs (GPT2, UART1,...)
  208. ******************************************************************/
  209. void peripheral_enable(void)
  210. {
  211. unsigned int v, if_clks = 0, func_clks = 0;
  212. /* Enable GP2 timer. */
  213. if_clks |= BIT4 | BIT3;
  214. func_clks |= BIT4 | BIT3;
  215. /* Sys_clk input OMAP2420_GPT2 */
  216. v = __raw_readl(CM_CLKSEL2_CORE) | 0x4 | 0x2;
  217. __raw_writel(v, CM_CLKSEL2_CORE);
  218. __raw_writel(0x1, CM_CLKSEL_WKUP);
  219. #ifdef CFG_NS16550
  220. /* Enable UART1 clock */
  221. func_clks |= BIT21;
  222. if_clks |= BIT21;
  223. #endif
  224. /* Interface clocks on */
  225. v = __raw_readl(CM_ICLKEN1_CORE) | if_clks;
  226. __raw_writel(v, CM_ICLKEN1_CORE);
  227. /* Functional Clocks on */
  228. v = __raw_readl(CM_FCLKEN1_CORE) | func_clks;
  229. __raw_writel(v, CM_FCLKEN1_CORE);
  230. delay(1000);
  231. #ifndef KERNEL_UPDATED
  232. {
  233. #define V1 0xffffffff
  234. #define V2 0x00000007
  235. __raw_writel(V1, CM_FCLKEN1_CORE);
  236. __raw_writel(V2, CM_FCLKEN2_CORE);
  237. __raw_writel(V1, CM_ICLKEN1_CORE);
  238. __raw_writel(V1, CM_ICLKEN2_CORE);
  239. }
  240. #endif
  241. }
  242. /****************************************
  243. * Routine: muxSetupUsb0 (ostboot)
  244. * Description: Setup usb muxing
  245. *****************************************/
  246. void muxSetupUsb0(void)
  247. {
  248. mask_config_reg(CONTROL_PADCONF_USB0_PUEN, 0x1f);
  249. mask_config_reg(CONTROL_PADCONF_USB0_VP, 0x1f);
  250. mask_config_reg(CONTROL_PADCONF_USB0_VM, 0x1f);
  251. mask_config_reg(CONTROL_PADCONF_USB0_RCV, 0x1f);
  252. mask_config_reg(CONTROL_PADCONF_USB0_TXEN, 0x1f);
  253. mask_config_reg(CONTROL_PADCONF_USB0_SE0, 0x1f);
  254. mask_config_reg(CONTROL_PADCONF_USB0_DAT, 0x1f);
  255. }
  256. /****************************************
  257. * Routine: muxSetupUSBHost (ostboot)
  258. * Description: Setup USB Host muxing
  259. *****************************************/
  260. void muxSetupUsbHost(void)
  261. {
  262. /* V19 */
  263. write_config_reg(CONTROL_PADCONF_USB1_RCV, 1);
  264. /* W20 */
  265. write_config_reg(CONTROL_PADCONF_USB1_TXEN, 1);
  266. /* N14 */
  267. write_config_reg(CONTROL_PADCONF_GPIO69, 3);
  268. /* P15 */
  269. write_config_reg(CONTROL_PADCONF_GPIO70, 3);
  270. /* L18 */
  271. write_config_reg(CONTROL_PADCONF_GPIO102, 3);
  272. /* L19 */
  273. write_config_reg(CONTROL_PADCONF_GPIO103, 3);
  274. /* K15 */
  275. write_config_reg(CONTROL_PADCONF_GPIO104, 3);
  276. /* K14 */
  277. write_config_reg(CONTROL_PADCONF_GPIO105, 3);
  278. }
  279. /****************************************
  280. * Routine: muxSetupUART1 (ostboot)
  281. * Description: Set up uart1 muxing
  282. *****************************************/
  283. void muxSetupUART1(void)
  284. {
  285. /* UART1_CTS pin configuration, PIN = D21, Mode = 0, PUPD=Disabled */
  286. write_config_reg(CONTROL_PADCONF_UART1_CTS, 0);
  287. /* UART1_RTS pin configuration, PIN = H21, Mode = 0, PUPD=Disabled */
  288. write_config_reg(CONTROL_PADCONF_UART1_RTS, 0);
  289. /* UART1_TX pin configuration, PIN = L20, Mode = 0, PUPD=Disabled */
  290. write_config_reg(CONTROL_PADCONF_UART1_TX, 0);
  291. /* UART1_RX pin configuration, PIN = T21, Mode = 0, PUPD=Disabled */
  292. write_config_reg(CONTROL_PADCONF_UART1_RX, 0);
  293. }
  294. /****************************************
  295. * Routine: muxSetupLCD (ostboot)
  296. * Description: Setup lcd muxing
  297. *****************************************/
  298. void muxSetupLCD(void)
  299. {
  300. /* LCD_D0 pin configuration, PIN = Y7, Mode = 0, PUPD=Disabled */
  301. write_config_reg(CONTROL_PADCONF_DSS_D0, 0);
  302. /* LCD_D1 pin configuration, PIN = P10 , Mode = 0, PUPD=Disabled */
  303. write_config_reg(CONTROL_PADCONF_DSS_D1, 0);
  304. /* LCD_D2 pin configuration, PIN = V8, Mode = 0, PUPD=Disabled */
  305. write_config_reg(CONTROL_PADCONF_DSS_D2, 0);
  306. /* LCD_D3 pin configuration, PIN = Y8, Mode = 0, PUPD=Disabled */
  307. write_config_reg(CONTROL_PADCONF_DSS_D3, 0);
  308. /* LCD_D4 pin configuration, PIN = W8, Mode = 0, PUPD=Disabled */
  309. write_config_reg(CONTROL_PADCONF_DSS_D4, 0);
  310. /* LCD_D5 pin configuration, PIN = R10, Mode = 0, PUPD=Disabled */
  311. write_config_reg(CONTROL_PADCONF_DSS_D5, 0);
  312. /* LCD_D6 pin configuration, PIN = Y9, Mode = 0, PUPD=Disabled */
  313. write_config_reg(CONTROL_PADCONF_DSS_D6, 0);
  314. /* LCD_D7 pin configuration, PIN = V9, Mode = 0, PUPD=Disabled */
  315. write_config_reg(CONTROL_PADCONF_DSS_D7, 0);
  316. /* LCD_D8 pin configuration, PIN = W9, Mode = 0, PUPD=Disabled */
  317. write_config_reg(CONTROL_PADCONF_DSS_D8, 0);
  318. /* LCD_D9 pin configuration, PIN = P11, Mode = 0, PUPD=Disabled */
  319. write_config_reg(CONTROL_PADCONF_DSS_D9, 0);
  320. /* LCD_D10 pin configuration, PIN = V10, Mode = 0, PUPD=Disabled */
  321. write_config_reg(CONTROL_PADCONF_DSS_D10, 0);
  322. /* LCD_D11 pin configuration, PIN = Y10, Mode = 0, PUPD=Disabled */
  323. write_config_reg(CONTROL_PADCONF_DSS_D11, 0);
  324. /* LCD_D12 pin configuration, PIN = W10, Mode = 0, PUPD=Disabled */
  325. write_config_reg(CONTROL_PADCONF_DSS_D12, 0);
  326. /* LCD_D13 pin configuration, PIN = R11, Mode = 0, PUPD=Disabled */
  327. write_config_reg(CONTROL_PADCONF_DSS_D13, 0);
  328. /* LCD_D14 pin configuration, PIN = V11, Mode = 0, PUPD=Disabled */
  329. write_config_reg(CONTROL_PADCONF_DSS_D14, 0);
  330. /* LCD_D15 pin configuration, PIN = W11, Mode = 0, PUPD=Disabled */
  331. write_config_reg(CONTROL_PADCONF_DSS_D15, 0);
  332. /* LCD_D16 pin configuration, PIN = P12, Mode = 0, PUPD=Disabled */
  333. write_config_reg(CONTROL_PADCONF_DSS_D16, 0);
  334. /* LCD_D17 pin configuration, PIN = R12, Mode = 0, PUPD=Disabled */
  335. write_config_reg(CONTROL_PADCONF_DSS_D17, 0);
  336. /* LCD_PCLK pin configuration, PIN = W6, Mode = 0, PUPD=Disabled */
  337. write_config_reg(CONTROL_PADCONF_DSS_PCLK, 0);
  338. /* LCD_VSYNC pin configuration, PIN = V7, Mode = 0, PUPD=Disabled */
  339. write_config_reg(CONTROL_PADCONF_DSS_VSYNC, 0);
  340. /* LCD_HSYNC pin configuration, PIN = Y6, Mode = 0, PUPD=Disabled */
  341. write_config_reg(CONTROL_PADCONF_DSS_HSYNC, 0);
  342. /* LCD_ACBIAS pin configuration, PIN = W7, Mode = 0, PUPD=Disabled */
  343. write_config_reg(CONTROL_PADCONF_DSS_ACBIAS, 0);
  344. }
  345. /****************************************
  346. * Routine: muxSetupMMCSD (ostboot)
  347. * Description: set up MMC muxing
  348. *****************************************/
  349. void muxSetupMMCSD(void)
  350. {
  351. /* SDMMC_CLKI pin configuration, PIN = H15, Mode = 0, PUPD=Disabled */
  352. write_config_reg(CONTROL_PADCONF_MMC_CLKI, 0);
  353. /* SDMMC_CLKO pin configuration, PIN = G19, Mode = 0, PUPD=Disabled */
  354. write_config_reg(CONTROL_PADCONF_MMC_CLKO, 0);
  355. /* SDMMC_CMD pin configuration, PIN = H18, Mode = 0, PUPD=Disabled */
  356. write_config_reg(CONTROL_PADCONF_MMC_CMD, 0);
  357. /* SDMMC_DAT0 pin configuration, PIN = F20, Mode = 0, PUPD=Disabled */
  358. write_config_reg(CONTROL_PADCONF_MMC_DAT0, 0);
  359. /* SDMMC_DAT1 pin configuration, PIN = H14, Mode = 0, PUPD=Disabled */
  360. write_config_reg(CONTROL_PADCONF_MMC_DAT1, 0);
  361. /* SDMMC_DAT2 pin configuration, PIN = E19, Mode = 0, PUPD=Disabled */
  362. write_config_reg(CONTROL_PADCONF_MMC_DAT2, 0);
  363. /* SDMMC_DAT3 pin configuration, PIN = D19, Mode = 0, PUPD=Disabled */
  364. write_config_reg(CONTROL_PADCONF_MMC_DAT3, 0);
  365. /* SDMMC_DDIR0 pin configuration, PIN = F19, Mode = 0, PUPD=Disabled */
  366. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR0, 0);
  367. /* SDMMC_DDIR1 pin configuration, PIN = E20, Mode = 0, PUPD=Disabled */
  368. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR1, 0);
  369. /* SDMMC_DDIR2 pin configuration, PIN = F18, Mode = 0, PUPD=Disabled */
  370. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR2, 0);
  371. /* SDMMC_DDIR3 pin configuration, PIN = E18, Mode = 0, PUPD=Disabled */
  372. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR3, 0);
  373. /* SDMMC_CDIR pin configuration, PIN = G18, Mode = 0, PUPD=Disabled */
  374. write_config_reg(CONTROL_PADCONF_MMC_CMD_DIR, 0);
  375. }
  376. /******************************************
  377. * Routine: muxSetupTouchScreen (ostboot)
  378. * Description: Set up touch screen muxing
  379. *******************************************/
  380. void muxSetupTouchScreen(void)
  381. {
  382. /* SPI1_CLK pin configuration, PIN = U18, Mode = 0, PUPD=Disabled */
  383. write_config_reg(CONTROL_PADCONF_SPI1_CLK, 0);
  384. /* SPI1_MOSI pin configuration, PIN = V20, Mode = 0, PUPD=Disabled */
  385. write_config_reg(CONTROL_PADCONF_SPI1_SIMO, 0);
  386. /* SPI1_MISO pin configuration, PIN = T18, Mode = 0, PUPD=Disabled */
  387. write_config_reg(CONTROL_PADCONF_SPI1_SOMI, 0);
  388. /* SPI1_nCS0 pin configuration, PIN = U19, Mode = 0, PUPD=Disabled */
  389. write_config_reg(CONTROL_PADCONF_SPI1_NCS0, 0);
  390. #define CONTROL_PADCONF_GPIO85 CONTROL_PADCONF_SPI1_NCS1
  391. /* PEN_IRQ pin configuration, PIN = N15, Mode = 3, PUPD=Disabled */
  392. write_config_reg(CONTROL_PADCONF_GPIO85, 3);
  393. }
  394. /***************************************************************
  395. * Routine: muxSetupGPMC (ostboot)
  396. * Description: Configures balls which cam up in protected mode
  397. ***************************************************************/
  398. void muxSetupGPMC(void)
  399. {
  400. /* gpmc_io_dir, MCR */
  401. volatile unsigned int *MCR = (unsigned int *) 0x4800008C;
  402. *MCR = 0x19000000;
  403. /* NOR FLASH CS0 */
  404. /* signal - Gpmc_clk; pin - J4; offset - 0x0088; mode 0; Byte-3 */
  405. write_config_reg(CONTROL_PADCONF_GPMC_D2_BYTE3, 0);
  406. /* MPDB(Multi Port Debug Port) CS1 */
  407. /* signal - gpmc_ncs1; pin - N8; offset - 0x008D; mode 0; Byte-1 */
  408. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE1, 0);
  409. /* signal - Gpmc_ncs2; pin - E2; offset - 0x008E; mode 0; Byte-2 */
  410. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE2, 0);
  411. /* signal - Gpmc_ncs3; pin - N2; offset - 0x008F; mode 0; Byte-3 */
  412. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE3, 0);
  413. /* signal - Gpmc_ncs4; pin - ??; offset - 0x0090; mode 0; Byte-4 */
  414. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE4, 0);
  415. /* signal - Gpmc_ncs5; pin - ??; offset - 0x0091; mode 0; Byte-5 */
  416. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE5, 0);
  417. /* signal - Gpmc_ncs6; pin - ??; offset - 0x0092; mode 0; Byte-6 */
  418. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE6, 0);
  419. /* signal - Gpmc_ncs7; pin - ??; offset - 0x0093; mode 0; Byte-7 */
  420. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE7, 0);
  421. }
  422. /****************************************************************
  423. * Routine: muxSetupSDRC (ostboot)
  424. * Description: Configures balls which come up in protected mode
  425. ****************************************************************/
  426. void muxSetupSDRC(void)
  427. {
  428. /* It's set by IPL */
  429. }