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