apollon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 <netdev.h>
  28. #include <asm/arch/omap2420.h>
  29. #include <asm/io.h>
  30. #include <asm/arch/bits.h>
  31. #include <asm/arch/mux.h>
  32. #include <asm/arch/sys_proto.h>
  33. #include <asm/arch/sys_info.h>
  34. #include <asm/arch/mem.h>
  35. #include <asm/mach-types.h>
  36. void wait_for_command_complete(unsigned int wd_base);
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #define write_config_reg(reg, value) \
  39. do { \
  40. writeb(value, reg); \
  41. } while (0)
  42. #define mask_config_reg(reg, mask) \
  43. do { \
  44. char value = readb(reg) & ~(mask); \
  45. writeb(value, reg); \
  46. } while (0)
  47. /*******************************************************
  48. * Routine: delay
  49. * Description: spinning delay to use before udelay works
  50. ******************************************************/
  51. static inline void delay(unsigned long loops)
  52. {
  53. __asm__("1:\n" "subs %0, %1, #1\n"
  54. "bne 1b":"=r" (loops):"0"(loops));
  55. }
  56. /*****************************************
  57. * Routine: board_init
  58. * Description: Early hardware init.
  59. *****************************************/
  60. int board_init(void)
  61. {
  62. gpmc_init(); /* in SRAM or SDRM, finish GPMC */
  63. gd->bd->bi_arch_number = 919;
  64. /* adress of boot parameters */
  65. gd->bd->bi_boot_params = (OMAP2420_SDRC_CS0 + 0x100);
  66. return 0;
  67. }
  68. /**********************************************************
  69. * Routine: s_init
  70. * Description: Does early system init of muxing and clocks.
  71. * - Called path is with sram stack.
  72. **********************************************************/
  73. void s_init(void)
  74. {
  75. watchdog_init();
  76. set_muxconf_regs();
  77. delay(100);
  78. peripheral_enable();
  79. icache_enable();
  80. }
  81. /*******************************************************
  82. * Routine: misc_init_r
  83. * Description: Init ethernet (done here so udelay works)
  84. ********************************************************/
  85. int misc_init_r(void)
  86. {
  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:board_eth_init
  126. * Description: take the Ethernet controller out of reset and wait
  127. * for the EEPROM load to complete.
  128. ******************************************************************/
  129. int board_eth_init(bd_t *bis)
  130. {
  131. int rc = 0;
  132. #ifdef CONFIG_LAN91C96
  133. int cnt = 20;
  134. __raw_writeb(0x03, OMAP2420_CTRL_BASE + 0x0f2); /*protect->gpio74 */
  135. __raw_writew(0x0, LAN_RESET_REGISTER);
  136. do {
  137. __raw_writew(0x1, LAN_RESET_REGISTER);
  138. udelay(100);
  139. if (cnt == 0)
  140. goto eth_reset_err_out;
  141. --cnt;
  142. } while (__raw_readw(LAN_RESET_REGISTER) != 0x1);
  143. cnt = 20;
  144. do {
  145. __raw_writew(0x0, LAN_RESET_REGISTER);
  146. udelay(100);
  147. if (cnt == 0)
  148. goto eth_reset_err_out;
  149. --cnt;
  150. } while (__raw_readw(LAN_RESET_REGISTER) != 0x0000);
  151. udelay(1000);
  152. mask_config_reg(ETH_CONTROL_REG, 0x01);
  153. udelay(1000);
  154. rc = lan91c96_initialize(0, CONFIG_LAN91C96_BASE);
  155. eth_reset_err_out:
  156. #endif
  157. return rc;
  158. }
  159. /**********************************************
  160. * Routine: dram_init
  161. * Description: sets uboots idea of sdram size
  162. **********************************************/
  163. int dram_init(void)
  164. {
  165. unsigned int size0 = 0, size1 = 0;
  166. u32 mtype, btype, rev = 0, cpu = 0;
  167. #define NOT_EARLY 0
  168. btype = get_board_type();
  169. mtype = get_mem_type();
  170. rev = get_cpu_rev();
  171. cpu = get_cpu_type();
  172. display_board_info(btype);
  173. if ((mtype == DDR_COMBO) || (mtype == DDR_STACKED)) {
  174. /* init other chip select */
  175. do_sdrc_init(SDRC_CS1_OSET, NOT_EARLY);
  176. }
  177. size0 = get_sdr_cs_size(SDRC_CS0_OSET);
  178. size1 = get_sdr_cs_size(SDRC_CS1_OSET);
  179. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  180. gd->bd->bi_dram[0].size = size0;
  181. #if CONFIG_NR_DRAM_BANKS > 1
  182. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + size0;
  183. gd->bd->bi_dram[1].size = size1;
  184. #endif
  185. return 0;
  186. }
  187. /**********************************************************
  188. * Routine: set_muxconf_regs
  189. * Description: Setting up the configuration Mux registers
  190. * specific to the hardware
  191. *********************************************************/
  192. void set_muxconf_regs(void)
  193. {
  194. muxSetupSDRC();
  195. muxSetupGPMC();
  196. muxSetupUsb0(); /* USB Device */
  197. muxSetupUsbHost(); /* USB Host */
  198. muxSetupUART1();
  199. muxSetupLCD();
  200. muxSetupMMCSD();
  201. muxSetupTouchScreen();
  202. }
  203. /*****************************************************************
  204. * Routine: peripheral_enable
  205. * Description: Enable the clks & power for perifs (GPT2, UART1,...)
  206. ******************************************************************/
  207. void peripheral_enable(void)
  208. {
  209. unsigned int v, if_clks = 0, func_clks = 0;
  210. /* Enable GP2 timer. */
  211. if_clks |= BIT4 | BIT3;
  212. func_clks |= BIT4 | BIT3;
  213. /* Sys_clk input OMAP2420_GPT2 */
  214. v = __raw_readl(CM_CLKSEL2_CORE) | 0x4 | 0x2;
  215. __raw_writel(v, CM_CLKSEL2_CORE);
  216. __raw_writel(0x1, CM_CLKSEL_WKUP);
  217. #ifdef CONFIG_SYS_NS16550
  218. /* Enable UART1 clock */
  219. func_clks |= BIT21;
  220. if_clks |= BIT21;
  221. #endif
  222. /* Interface clocks on */
  223. v = __raw_readl(CM_ICLKEN1_CORE) | if_clks;
  224. __raw_writel(v, CM_ICLKEN1_CORE);
  225. /* Functional Clocks on */
  226. v = __raw_readl(CM_FCLKEN1_CORE) | func_clks;
  227. __raw_writel(v, CM_FCLKEN1_CORE);
  228. delay(1000);
  229. #ifndef KERNEL_UPDATED
  230. {
  231. #define V1 0xffffffff
  232. #define V2 0x00000007
  233. __raw_writel(V1, CM_FCLKEN1_CORE);
  234. __raw_writel(V2, CM_FCLKEN2_CORE);
  235. __raw_writel(V1, CM_ICLKEN1_CORE);
  236. __raw_writel(V1, CM_ICLKEN2_CORE);
  237. }
  238. #endif
  239. }
  240. /****************************************
  241. * Routine: muxSetupUsb0 (ostboot)
  242. * Description: Setup usb muxing
  243. *****************************************/
  244. void muxSetupUsb0(void)
  245. {
  246. mask_config_reg(CONTROL_PADCONF_USB0_PUEN, 0x1f);
  247. mask_config_reg(CONTROL_PADCONF_USB0_VP, 0x1f);
  248. mask_config_reg(CONTROL_PADCONF_USB0_VM, 0x1f);
  249. mask_config_reg(CONTROL_PADCONF_USB0_RCV, 0x1f);
  250. mask_config_reg(CONTROL_PADCONF_USB0_TXEN, 0x1f);
  251. mask_config_reg(CONTROL_PADCONF_USB0_SE0, 0x1f);
  252. mask_config_reg(CONTROL_PADCONF_USB0_DAT, 0x1f);
  253. }
  254. /****************************************
  255. * Routine: muxSetupUSBHost (ostboot)
  256. * Description: Setup USB Host muxing
  257. *****************************************/
  258. void muxSetupUsbHost(void)
  259. {
  260. /* V19 */
  261. write_config_reg(CONTROL_PADCONF_USB1_RCV, 1);
  262. /* W20 */
  263. write_config_reg(CONTROL_PADCONF_USB1_TXEN, 1);
  264. /* N14 */
  265. write_config_reg(CONTROL_PADCONF_GPIO69, 3);
  266. /* P15 */
  267. write_config_reg(CONTROL_PADCONF_GPIO70, 3);
  268. /* L18 */
  269. write_config_reg(CONTROL_PADCONF_GPIO102, 3);
  270. /* L19 */
  271. write_config_reg(CONTROL_PADCONF_GPIO103, 3);
  272. /* K15 */
  273. write_config_reg(CONTROL_PADCONF_GPIO104, 3);
  274. /* K14 */
  275. write_config_reg(CONTROL_PADCONF_GPIO105, 3);
  276. }
  277. /****************************************
  278. * Routine: muxSetupUART1 (ostboot)
  279. * Description: Set up uart1 muxing
  280. *****************************************/
  281. void muxSetupUART1(void)
  282. {
  283. /* UART1_CTS pin configuration, PIN = D21, Mode = 0, PUPD=Disabled */
  284. write_config_reg(CONTROL_PADCONF_UART1_CTS, 0);
  285. /* UART1_RTS pin configuration, PIN = H21, Mode = 0, PUPD=Disabled */
  286. write_config_reg(CONTROL_PADCONF_UART1_RTS, 0);
  287. /* UART1_TX pin configuration, PIN = L20, Mode = 0, PUPD=Disabled */
  288. write_config_reg(CONTROL_PADCONF_UART1_TX, 0);
  289. /* UART1_RX pin configuration, PIN = T21, Mode = 0, PUPD=Disabled */
  290. write_config_reg(CONTROL_PADCONF_UART1_RX, 0);
  291. }
  292. /****************************************
  293. * Routine: muxSetupLCD (ostboot)
  294. * Description: Setup lcd muxing
  295. *****************************************/
  296. void muxSetupLCD(void)
  297. {
  298. /* LCD_D0 pin configuration, PIN = Y7, Mode = 0, PUPD=Disabled */
  299. write_config_reg(CONTROL_PADCONF_DSS_D0, 0);
  300. /* LCD_D1 pin configuration, PIN = P10 , Mode = 0, PUPD=Disabled */
  301. write_config_reg(CONTROL_PADCONF_DSS_D1, 0);
  302. /* LCD_D2 pin configuration, PIN = V8, Mode = 0, PUPD=Disabled */
  303. write_config_reg(CONTROL_PADCONF_DSS_D2, 0);
  304. /* LCD_D3 pin configuration, PIN = Y8, Mode = 0, PUPD=Disabled */
  305. write_config_reg(CONTROL_PADCONF_DSS_D3, 0);
  306. /* LCD_D4 pin configuration, PIN = W8, Mode = 0, PUPD=Disabled */
  307. write_config_reg(CONTROL_PADCONF_DSS_D4, 0);
  308. /* LCD_D5 pin configuration, PIN = R10, Mode = 0, PUPD=Disabled */
  309. write_config_reg(CONTROL_PADCONF_DSS_D5, 0);
  310. /* LCD_D6 pin configuration, PIN = Y9, Mode = 0, PUPD=Disabled */
  311. write_config_reg(CONTROL_PADCONF_DSS_D6, 0);
  312. /* LCD_D7 pin configuration, PIN = V9, Mode = 0, PUPD=Disabled */
  313. write_config_reg(CONTROL_PADCONF_DSS_D7, 0);
  314. /* LCD_D8 pin configuration, PIN = W9, Mode = 0, PUPD=Disabled */
  315. write_config_reg(CONTROL_PADCONF_DSS_D8, 0);
  316. /* LCD_D9 pin configuration, PIN = P11, Mode = 0, PUPD=Disabled */
  317. write_config_reg(CONTROL_PADCONF_DSS_D9, 0);
  318. /* LCD_D10 pin configuration, PIN = V10, Mode = 0, PUPD=Disabled */
  319. write_config_reg(CONTROL_PADCONF_DSS_D10, 0);
  320. /* LCD_D11 pin configuration, PIN = Y10, Mode = 0, PUPD=Disabled */
  321. write_config_reg(CONTROL_PADCONF_DSS_D11, 0);
  322. /* LCD_D12 pin configuration, PIN = W10, Mode = 0, PUPD=Disabled */
  323. write_config_reg(CONTROL_PADCONF_DSS_D12, 0);
  324. /* LCD_D13 pin configuration, PIN = R11, Mode = 0, PUPD=Disabled */
  325. write_config_reg(CONTROL_PADCONF_DSS_D13, 0);
  326. /* LCD_D14 pin configuration, PIN = V11, Mode = 0, PUPD=Disabled */
  327. write_config_reg(CONTROL_PADCONF_DSS_D14, 0);
  328. /* LCD_D15 pin configuration, PIN = W11, Mode = 0, PUPD=Disabled */
  329. write_config_reg(CONTROL_PADCONF_DSS_D15, 0);
  330. /* LCD_D16 pin configuration, PIN = P12, Mode = 0, PUPD=Disabled */
  331. write_config_reg(CONTROL_PADCONF_DSS_D16, 0);
  332. /* LCD_D17 pin configuration, PIN = R12, Mode = 0, PUPD=Disabled */
  333. write_config_reg(CONTROL_PADCONF_DSS_D17, 0);
  334. /* LCD_PCLK pin configuration, PIN = W6, Mode = 0, PUPD=Disabled */
  335. write_config_reg(CONTROL_PADCONF_DSS_PCLK, 0);
  336. /* LCD_VSYNC pin configuration, PIN = V7, Mode = 0, PUPD=Disabled */
  337. write_config_reg(CONTROL_PADCONF_DSS_VSYNC, 0);
  338. /* LCD_HSYNC pin configuration, PIN = Y6, Mode = 0, PUPD=Disabled */
  339. write_config_reg(CONTROL_PADCONF_DSS_HSYNC, 0);
  340. /* LCD_ACBIAS pin configuration, PIN = W7, Mode = 0, PUPD=Disabled */
  341. write_config_reg(CONTROL_PADCONF_DSS_ACBIAS, 0);
  342. }
  343. /****************************************
  344. * Routine: muxSetupMMCSD (ostboot)
  345. * Description: set up MMC muxing
  346. *****************************************/
  347. void muxSetupMMCSD(void)
  348. {
  349. /* SDMMC_CLKI pin configuration, PIN = H15, Mode = 0, PUPD=Disabled */
  350. write_config_reg(CONTROL_PADCONF_MMC_CLKI, 0);
  351. /* SDMMC_CLKO pin configuration, PIN = G19, Mode = 0, PUPD=Disabled */
  352. write_config_reg(CONTROL_PADCONF_MMC_CLKO, 0);
  353. /* SDMMC_CMD pin configuration, PIN = H18, Mode = 0, PUPD=Disabled */
  354. write_config_reg(CONTROL_PADCONF_MMC_CMD, 0);
  355. /* SDMMC_DAT0 pin configuration, PIN = F20, Mode = 0, PUPD=Disabled */
  356. write_config_reg(CONTROL_PADCONF_MMC_DAT0, 0);
  357. /* SDMMC_DAT1 pin configuration, PIN = H14, Mode = 0, PUPD=Disabled */
  358. write_config_reg(CONTROL_PADCONF_MMC_DAT1, 0);
  359. /* SDMMC_DAT2 pin configuration, PIN = E19, Mode = 0, PUPD=Disabled */
  360. write_config_reg(CONTROL_PADCONF_MMC_DAT2, 0);
  361. /* SDMMC_DAT3 pin configuration, PIN = D19, Mode = 0, PUPD=Disabled */
  362. write_config_reg(CONTROL_PADCONF_MMC_DAT3, 0);
  363. /* SDMMC_DDIR0 pin configuration, PIN = F19, Mode = 0, PUPD=Disabled */
  364. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR0, 0);
  365. /* SDMMC_DDIR1 pin configuration, PIN = E20, Mode = 0, PUPD=Disabled */
  366. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR1, 0);
  367. /* SDMMC_DDIR2 pin configuration, PIN = F18, Mode = 0, PUPD=Disabled */
  368. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR2, 0);
  369. /* SDMMC_DDIR3 pin configuration, PIN = E18, Mode = 0, PUPD=Disabled */
  370. write_config_reg(CONTROL_PADCONF_MMC_DAT_DIR3, 0);
  371. /* SDMMC_CDIR pin configuration, PIN = G18, Mode = 0, PUPD=Disabled */
  372. write_config_reg(CONTROL_PADCONF_MMC_CMD_DIR, 0);
  373. }
  374. /******************************************
  375. * Routine: muxSetupTouchScreen (ostboot)
  376. * Description: Set up touch screen muxing
  377. *******************************************/
  378. void muxSetupTouchScreen(void)
  379. {
  380. /* SPI1_CLK pin configuration, PIN = U18, Mode = 0, PUPD=Disabled */
  381. write_config_reg(CONTROL_PADCONF_SPI1_CLK, 0);
  382. /* SPI1_MOSI pin configuration, PIN = V20, Mode = 0, PUPD=Disabled */
  383. write_config_reg(CONTROL_PADCONF_SPI1_SIMO, 0);
  384. /* SPI1_MISO pin configuration, PIN = T18, Mode = 0, PUPD=Disabled */
  385. write_config_reg(CONTROL_PADCONF_SPI1_SOMI, 0);
  386. /* SPI1_nCS0 pin configuration, PIN = U19, Mode = 0, PUPD=Disabled */
  387. write_config_reg(CONTROL_PADCONF_SPI1_NCS0, 0);
  388. #define CONTROL_PADCONF_GPIO85 CONTROL_PADCONF_SPI1_NCS1
  389. /* PEN_IRQ pin configuration, PIN = N15, Mode = 3, PUPD=Disabled */
  390. write_config_reg(CONTROL_PADCONF_GPIO85, 3);
  391. }
  392. /***************************************************************
  393. * Routine: muxSetupGPMC (ostboot)
  394. * Description: Configures balls which cam up in protected mode
  395. ***************************************************************/
  396. void muxSetupGPMC(void)
  397. {
  398. /* gpmc_io_dir, MCR */
  399. volatile unsigned int *MCR = (unsigned int *) 0x4800008C;
  400. *MCR = 0x19000000;
  401. /* NOR FLASH CS0 */
  402. /* signal - Gpmc_clk; pin - J4; offset - 0x0088; mode 0; Byte-3 */
  403. write_config_reg(CONTROL_PADCONF_GPMC_D2_BYTE3, 0);
  404. /* MPDB(Multi Port Debug Port) CS1 */
  405. /* signal - gpmc_ncs1; pin - N8; offset - 0x008D; mode 0; Byte-1 */
  406. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE1, 0);
  407. /* signal - Gpmc_ncs2; pin - E2; offset - 0x008E; mode 0; Byte-2 */
  408. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE2, 0);
  409. /* signal - Gpmc_ncs3; pin - N2; offset - 0x008F; mode 0; Byte-3 */
  410. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE3, 0);
  411. /* signal - Gpmc_ncs4; pin - ??; offset - 0x0090; mode 0; Byte-4 */
  412. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE4, 0);
  413. /* signal - Gpmc_ncs5; pin - ??; offset - 0x0091; mode 0; Byte-5 */
  414. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE5, 0);
  415. /* signal - Gpmc_ncs6; pin - ??; offset - 0x0092; mode 0; Byte-6 */
  416. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE6, 0);
  417. /* signal - Gpmc_ncs7; pin - ??; offset - 0x0093; mode 0; Byte-7 */
  418. write_config_reg(CONTROL_PADCONF_GPMC_NCS0_BYTE7, 0);
  419. }
  420. /****************************************************************
  421. * Routine: muxSetupSDRC (ostboot)
  422. * Description: Configures balls which come up in protected mode
  423. ****************************************************************/
  424. void muxSetupSDRC(void)
  425. {
  426. /* It's set by IPL */
  427. }