apollon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. goto eth_reset_err_out;
  140. --cnt;
  141. } while (__raw_readw(LAN_RESET_REGISTER) != 0x1);
  142. cnt = 20;
  143. do {
  144. __raw_writew(0x0, LAN_RESET_REGISTER);
  145. udelay(100);
  146. if (cnt == 0)
  147. goto eth_reset_err_out;
  148. --cnt;
  149. } while (__raw_readw(LAN_RESET_REGISTER) != 0x0000);
  150. udelay(1000);
  151. mask_config_reg(ETH_CONTROL_REG, 0x01);
  152. udelay(1000);
  153. eth_reset_err_out:
  154. return;
  155. #endif
  156. }
  157. /**********************************************
  158. * Routine: dram_init
  159. * Description: sets uboots idea of sdram size
  160. **********************************************/
  161. int dram_init(void)
  162. {
  163. unsigned int size0 = 0, size1 = 0;
  164. u32 mtype, btype, rev = 0, cpu = 0;
  165. #define NOT_EARLY 0
  166. btype = get_board_type();
  167. mtype = get_mem_type();
  168. rev = get_cpu_rev();
  169. cpu = get_cpu_type();
  170. display_board_info(btype);
  171. if ((mtype == DDR_COMBO) || (mtype == DDR_STACKED)) {
  172. /* init other chip select */
  173. do_sdrc_init(SDRC_CS1_OSET, NOT_EARLY);
  174. }
  175. size0 = get_sdr_cs_size(SDRC_CS0_OSET);
  176. size1 = get_sdr_cs_size(SDRC_CS1_OSET);
  177. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  178. gd->bd->bi_dram[0].size = size0;
  179. #if CONFIG_NR_DRAM_BANKS > 1
  180. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + size0;
  181. gd->bd->bi_dram[1].size = size1;
  182. #endif
  183. return 0;
  184. }
  185. /**********************************************************
  186. * Routine: set_muxconf_regs
  187. * Description: Setting up the configuration Mux registers
  188. * specific to the hardware
  189. *********************************************************/
  190. void set_muxconf_regs(void)
  191. {
  192. muxSetupSDRC();
  193. muxSetupGPMC();
  194. muxSetupUsb0(); /* USB Device */
  195. muxSetupUsbHost(); /* USB Host */
  196. muxSetupUART1();
  197. muxSetupLCD();
  198. muxSetupMMCSD();
  199. muxSetupTouchScreen();
  200. }
  201. /*****************************************************************
  202. * Routine: peripheral_enable
  203. * Description: Enable the clks & power for perifs (GPT2, UART1,...)
  204. ******************************************************************/
  205. void peripheral_enable(void)
  206. {
  207. unsigned int v, if_clks = 0, func_clks = 0;
  208. /* Enable GP2 timer. */
  209. if_clks |= BIT4 | BIT3;
  210. func_clks |= BIT4 | BIT3;
  211. /* Sys_clk input OMAP2420_GPT2 */
  212. v = __raw_readl(CM_CLKSEL2_CORE) | 0x4 | 0x2;
  213. __raw_writel(v, CM_CLKSEL2_CORE);
  214. __raw_writel(0x1, CM_CLKSEL_WKUP);
  215. #ifdef CONFIG_SYS_NS16550
  216. /* Enable UART1 clock */
  217. func_clks |= BIT21;
  218. if_clks |= BIT21;
  219. #endif
  220. /* Interface clocks on */
  221. v = __raw_readl(CM_ICLKEN1_CORE) | if_clks;
  222. __raw_writel(v, CM_ICLKEN1_CORE);
  223. /* Functional Clocks on */
  224. v = __raw_readl(CM_FCLKEN1_CORE) | func_clks;
  225. __raw_writel(v, CM_FCLKEN1_CORE);
  226. delay(1000);
  227. #ifndef KERNEL_UPDATED
  228. {
  229. #define V1 0xffffffff
  230. #define V2 0x00000007
  231. __raw_writel(V1, CM_FCLKEN1_CORE);
  232. __raw_writel(V2, CM_FCLKEN2_CORE);
  233. __raw_writel(V1, CM_ICLKEN1_CORE);
  234. __raw_writel(V1, CM_ICLKEN2_CORE);
  235. }
  236. #endif
  237. }
  238. /****************************************
  239. * Routine: muxSetupUsb0 (ostboot)
  240. * Description: Setup usb muxing
  241. *****************************************/
  242. void muxSetupUsb0(void)
  243. {
  244. mask_config_reg(CONTROL_PADCONF_USB0_PUEN, 0x1f);
  245. mask_config_reg(CONTROL_PADCONF_USB0_VP, 0x1f);
  246. mask_config_reg(CONTROL_PADCONF_USB0_VM, 0x1f);
  247. mask_config_reg(CONTROL_PADCONF_USB0_RCV, 0x1f);
  248. mask_config_reg(CONTROL_PADCONF_USB0_TXEN, 0x1f);
  249. mask_config_reg(CONTROL_PADCONF_USB0_SE0, 0x1f);
  250. mask_config_reg(CONTROL_PADCONF_USB0_DAT, 0x1f);
  251. }
  252. /****************************************
  253. * Routine: muxSetupUSBHost (ostboot)
  254. * Description: Setup USB Host muxing
  255. *****************************************/
  256. void muxSetupUsbHost(void)
  257. {
  258. /* V19 */
  259. write_config_reg(CONTROL_PADCONF_USB1_RCV, 1);
  260. /* W20 */
  261. write_config_reg(CONTROL_PADCONF_USB1_TXEN, 1);
  262. /* N14 */
  263. write_config_reg(CONTROL_PADCONF_GPIO69, 3);
  264. /* P15 */
  265. write_config_reg(CONTROL_PADCONF_GPIO70, 3);
  266. /* L18 */
  267. write_config_reg(CONTROL_PADCONF_GPIO102, 3);
  268. /* L19 */
  269. write_config_reg(CONTROL_PADCONF_GPIO103, 3);
  270. /* K15 */
  271. write_config_reg(CONTROL_PADCONF_GPIO104, 3);
  272. /* K14 */
  273. write_config_reg(CONTROL_PADCONF_GPIO105, 3);
  274. }
  275. /****************************************
  276. * Routine: muxSetupUART1 (ostboot)
  277. * Description: Set up uart1 muxing
  278. *****************************************/
  279. void muxSetupUART1(void)
  280. {
  281. /* UART1_CTS pin configuration, PIN = D21, Mode = 0, PUPD=Disabled */
  282. write_config_reg(CONTROL_PADCONF_UART1_CTS, 0);
  283. /* UART1_RTS pin configuration, PIN = H21, Mode = 0, PUPD=Disabled */
  284. write_config_reg(CONTROL_PADCONF_UART1_RTS, 0);
  285. /* UART1_TX pin configuration, PIN = L20, Mode = 0, PUPD=Disabled */
  286. write_config_reg(CONTROL_PADCONF_UART1_TX, 0);
  287. /* UART1_RX pin configuration, PIN = T21, Mode = 0, PUPD=Disabled */
  288. write_config_reg(CONTROL_PADCONF_UART1_RX, 0);
  289. }
  290. /****************************************
  291. * Routine: muxSetupLCD (ostboot)
  292. * Description: Setup lcd muxing
  293. *****************************************/
  294. void muxSetupLCD(void)
  295. {
  296. /* LCD_D0 pin configuration, PIN = Y7, Mode = 0, PUPD=Disabled */
  297. write_config_reg(CONTROL_PADCONF_DSS_D0, 0);
  298. /* LCD_D1 pin configuration, PIN = P10 , Mode = 0, PUPD=Disabled */
  299. write_config_reg(CONTROL_PADCONF_DSS_D1, 0);
  300. /* LCD_D2 pin configuration, PIN = V8, Mode = 0, PUPD=Disabled */
  301. write_config_reg(CONTROL_PADCONF_DSS_D2, 0);
  302. /* LCD_D3 pin configuration, PIN = Y8, Mode = 0, PUPD=Disabled */
  303. write_config_reg(CONTROL_PADCONF_DSS_D3, 0);
  304. /* LCD_D4 pin configuration, PIN = W8, Mode = 0, PUPD=Disabled */
  305. write_config_reg(CONTROL_PADCONF_DSS_D4, 0);
  306. /* LCD_D5 pin configuration, PIN = R10, Mode = 0, PUPD=Disabled */
  307. write_config_reg(CONTROL_PADCONF_DSS_D5, 0);
  308. /* LCD_D6 pin configuration, PIN = Y9, Mode = 0, PUPD=Disabled */
  309. write_config_reg(CONTROL_PADCONF_DSS_D6, 0);
  310. /* LCD_D7 pin configuration, PIN = V9, Mode = 0, PUPD=Disabled */
  311. write_config_reg(CONTROL_PADCONF_DSS_D7, 0);
  312. /* LCD_D8 pin configuration, PIN = W9, Mode = 0, PUPD=Disabled */
  313. write_config_reg(CONTROL_PADCONF_DSS_D8, 0);
  314. /* LCD_D9 pin configuration, PIN = P11, Mode = 0, PUPD=Disabled */
  315. write_config_reg(CONTROL_PADCONF_DSS_D9, 0);
  316. /* LCD_D10 pin configuration, PIN = V10, Mode = 0, PUPD=Disabled */
  317. write_config_reg(CONTROL_PADCONF_DSS_D10, 0);
  318. /* LCD_D11 pin configuration, PIN = Y10, Mode = 0, PUPD=Disabled */
  319. write_config_reg(CONTROL_PADCONF_DSS_D11, 0);
  320. /* LCD_D12 pin configuration, PIN = W10, Mode = 0, PUPD=Disabled */
  321. write_config_reg(CONTROL_PADCONF_DSS_D12, 0);
  322. /* LCD_D13 pin configuration, PIN = R11, Mode = 0, PUPD=Disabled */
  323. write_config_reg(CONTROL_PADCONF_DSS_D13, 0);
  324. /* LCD_D14 pin configuration, PIN = V11, Mode = 0, PUPD=Disabled */
  325. write_config_reg(CONTROL_PADCONF_DSS_D14, 0);
  326. /* LCD_D15 pin configuration, PIN = W11, Mode = 0, PUPD=Disabled */
  327. write_config_reg(CONTROL_PADCONF_DSS_D15, 0);
  328. /* LCD_D16 pin configuration, PIN = P12, Mode = 0, PUPD=Disabled */
  329. write_config_reg(CONTROL_PADCONF_DSS_D16, 0);
  330. /* LCD_D17 pin configuration, PIN = R12, Mode = 0, PUPD=Disabled */
  331. write_config_reg(CONTROL_PADCONF_DSS_D17, 0);
  332. /* LCD_PCLK pin configuration, PIN = W6, Mode = 0, PUPD=Disabled */
  333. write_config_reg(CONTROL_PADCONF_DSS_PCLK, 0);
  334. /* LCD_VSYNC pin configuration, PIN = V7, Mode = 0, PUPD=Disabled */
  335. write_config_reg(CONTROL_PADCONF_DSS_VSYNC, 0);
  336. /* LCD_HSYNC pin configuration, PIN = Y6, Mode = 0, PUPD=Disabled */
  337. write_config_reg(CONTROL_PADCONF_DSS_HSYNC, 0);
  338. /* LCD_ACBIAS pin configuration, PIN = W7, Mode = 0, PUPD=Disabled */
  339. write_config_reg(CONTROL_PADCONF_DSS_ACBIAS, 0);
  340. }
  341. /****************************************
  342. * Routine: muxSetupMMCSD (ostboot)
  343. * Description: set up MMC muxing
  344. *****************************************/
  345. void muxSetupMMCSD(void)
  346. {
  347. /* SDMMC_CLKI pin configuration, PIN = H15, Mode = 0, PUPD=Disabled */
  348. write_config_reg(CONTROL_PADCONF_MMC_CLKI, 0);
  349. /* SDMMC_CLKO pin configuration, PIN = G19, Mode = 0, PUPD=Disabled */
  350. write_config_reg(CONTROL_PADCONF_MMC_CLKO, 0);
  351. /* SDMMC_CMD pin configuration, PIN = H18, Mode = 0, PUPD=Disabled */
  352. write_config_reg(CONTROL_PADCONF_MMC_CMD, 0);
  353. /* SDMMC_DAT0 pin configuration, PIN = F20, Mode = 0, PUPD=Disabled */
  354. write_config_reg(CONTROL_PADCONF_MMC_DAT0, 0);
  355. /* SDMMC_DAT1 pin configuration, PIN = H14, Mode = 0, PUPD=Disabled */
  356. write_config_reg(CONTROL_PADCONF_MMC_DAT1, 0);
  357. /* SDMMC_DAT2 pin configuration, PIN = E19, Mode = 0, PUPD=Disabled */
  358. write_config_reg(CONTROL_PADCONF_MMC_DAT2, 0);
  359. /* SDMMC_DAT3 pin configuration, PIN = D19, Mode = 0, PUPD=Disabled */
  360. write_config_reg(CONTROL_PADCONF_MMC_DAT3, 0);
  361. /* SDMMC_DDIR0 pin configuration, PIN = F19, Mode = 0, PUPD=Disabled */
  362. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR0, 0);
  363. /* SDMMC_DDIR1 pin configuration, PIN = E20, Mode = 0, PUPD=Disabled */
  364. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR1, 0);
  365. /* SDMMC_DDIR2 pin configuration, PIN = F18, Mode = 0, PUPD=Disabled */
  366. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR2, 0);
  367. /* SDMMC_DDIR3 pin configuration, PIN = E18, Mode = 0, PUPD=Disabled */
  368. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR3, 0);
  369. /* SDMMC_CDIR pin configuration, PIN = G18, Mode = 0, PUPD=Disabled */
  370. write_config_reg(CONTROL_PADCONF_MMC_CMD_DIR, 0);
  371. }
  372. /******************************************
  373. * Routine: muxSetupTouchScreen (ostboot)
  374. * Description: Set up touch screen muxing
  375. *******************************************/
  376. void muxSetupTouchScreen(void)
  377. {
  378. /* SPI1_CLK pin configuration, PIN = U18, Mode = 0, PUPD=Disabled */
  379. write_config_reg(CONTROL_PADCONF_SPI1_CLK, 0);
  380. /* SPI1_MOSI pin configuration, PIN = V20, Mode = 0, PUPD=Disabled */
  381. write_config_reg(CONTROL_PADCONF_SPI1_SIMO, 0);
  382. /* SPI1_MISO pin configuration, PIN = T18, Mode = 0, PUPD=Disabled */
  383. write_config_reg(CONTROL_PADCONF_SPI1_SOMI, 0);
  384. /* SPI1_nCS0 pin configuration, PIN = U19, Mode = 0, PUPD=Disabled */
  385. write_config_reg(CONTROL_PADCONF_SPI1_NCS0, 0);
  386. #define CONTROL_PADCONF_GPIO85 CONTROL_PADCONF_SPI1_NCS1
  387. /* PEN_IRQ pin configuration, PIN = N15, Mode = 3, PUPD=Disabled */
  388. write_config_reg(CONTROL_PADCONF_GPIO85, 3);
  389. }
  390. /***************************************************************
  391. * Routine: muxSetupGPMC (ostboot)
  392. * Description: Configures balls which cam up in protected mode
  393. ***************************************************************/
  394. void muxSetupGPMC(void)
  395. {
  396. /* gpmc_io_dir, MCR */
  397. volatile unsigned int *MCR = (unsigned int *) 0x4800008C;
  398. *MCR = 0x19000000;
  399. /* NOR FLASH CS0 */
  400. /* signal - Gpmc_clk; pin - J4; offset - 0x0088; mode 0; Byte-3 */
  401. write_config_reg(CONTROL_PADCONF_GPMC_D2_BYTE3, 0);
  402. /* MPDB(Multi Port Debug Port) CS1 */
  403. /* signal - gpmc_ncs1; pin - N8; offset - 0x008D; mode 0; Byte-1 */
  404. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE1, 0);
  405. /* signal - Gpmc_ncs2; pin - E2; offset - 0x008E; mode 0; Byte-2 */
  406. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE2, 0);
  407. /* signal - Gpmc_ncs3; pin - N2; offset - 0x008F; mode 0; Byte-3 */
  408. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE3, 0);
  409. /* signal - Gpmc_ncs4; pin - ??; offset - 0x0090; mode 0; Byte-4 */
  410. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE4, 0);
  411. /* signal - Gpmc_ncs5; pin - ??; offset - 0x0091; mode 0; Byte-5 */
  412. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE5, 0);
  413. /* signal - Gpmc_ncs6; pin - ??; offset - 0x0092; mode 0; Byte-6 */
  414. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE6, 0);
  415. /* signal - Gpmc_ncs7; pin - ??; offset - 0x0093; mode 0; Byte-7 */
  416. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE7, 0);
  417. }
  418. /****************************************************************
  419. * Routine: muxSetupSDRC (ostboot)
  420. * Description: Configures balls which come up in protected mode
  421. ****************************************************************/
  422. void muxSetupSDRC(void)
  423. {
  424. /* It's set by IPL */
  425. }