apollon.c 16 KB

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