pm9261.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
  6. * Copyright (C) 2009 Jean-Christopher PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <linux/sizes.h>
  12. #include <asm/io.h>
  13. #include <asm/gpio.h>
  14. #include <asm/arch/at91sam9_smc.h>
  15. #include <asm/arch/at91_common.h>
  16. #include <asm/arch/at91_rstc.h>
  17. #include <asm/arch/at91_matrix.h>
  18. #include <asm/arch/clk.h>
  19. #include <asm/arch/gpio.h>
  20. #include <lcd.h>
  21. #include <atmel_lcdc.h>
  22. #include <dataflash.h>
  23. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
  24. #include <net.h>
  25. #endif
  26. #include <netdev.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* ------------------------------------------------------------------------- */
  29. /*
  30. * Miscelaneous platform dependent initialisations
  31. */
  32. #ifdef CONFIG_CMD_NAND
  33. static void pm9261_nand_hw_init(void)
  34. {
  35. unsigned long csa;
  36. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  37. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  38. /* Enable CS3 */
  39. csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
  40. writel(csa, &matrix->csa);
  41. /* Configure SMC CS3 for NAND/SmartMedia */
  42. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  43. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  44. &smc->cs[3].setup);
  45. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  46. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  47. &smc->cs[3].pulse);
  48. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  49. &smc->cs[3].cycle);
  50. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  51. AT91_SMC_MODE_EXNW_DISABLE |
  52. #ifdef CONFIG_SYS_NAND_DBW_16
  53. AT91_SMC_MODE_DBW_16 |
  54. #else /* CONFIG_SYS_NAND_DBW_8 */
  55. AT91_SMC_MODE_DBW_8 |
  56. #endif
  57. AT91_SMC_MODE_TDF_CYCLE(2),
  58. &smc->cs[3].mode);
  59. at91_periph_clk_enable(ATMEL_ID_PIOA);
  60. at91_periph_clk_enable(ATMEL_ID_PIOC);
  61. /* Configure RDY/BSY */
  62. gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
  63. /* Enable NandFlash */
  64. gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  65. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
  66. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
  67. }
  68. #endif
  69. #ifdef CONFIG_DRIVER_DM9000
  70. static void pm9261_dm9000_hw_init(void)
  71. {
  72. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  73. /* Configure SMC CS2 for DM9000 */
  74. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  75. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  76. &smc->cs[2].setup);
  77. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
  78. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
  79. &smc->cs[2].pulse);
  80. writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
  81. &smc->cs[2].cycle);
  82. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  83. AT91_SMC_MODE_EXNW_DISABLE |
  84. AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
  85. AT91_SMC_MODE_TDF_CYCLE(1),
  86. &smc->cs[2].mode);
  87. /* Configure Interrupt pin as input, no pull-up */
  88. at91_periph_clk_enable(ATMEL_ID_PIOA);
  89. at91_set_pio_input(AT91_PIO_PORTA, 24, 0);
  90. }
  91. #endif
  92. #ifdef CONFIG_LCD
  93. vidinfo_t panel_info = {
  94. .vl_col = 240,
  95. .vl_row = 320,
  96. .vl_clk = 4965000,
  97. .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
  98. ATMEL_LCDC_INVFRAME_INVERTED,
  99. .vl_bpix = 3,
  100. .vl_tft = 1,
  101. .vl_hsync_len = 5,
  102. .vl_left_margin = 1,
  103. .vl_right_margin = 33,
  104. .vl_vsync_len = 1,
  105. .vl_upper_margin = 1,
  106. .vl_lower_margin = 0,
  107. .mmio = ATMEL_BASE_LCDC,
  108. };
  109. void lcd_enable(void)
  110. {
  111. at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power up */
  112. }
  113. void lcd_disable(void)
  114. {
  115. at91_set_pio_value(AT91_PIO_PORTA, 22, 1); /* power down */
  116. }
  117. static void pm9261_lcd_hw_init(void)
  118. {
  119. at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* LCDHSYNC */
  120. at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* LCDDOTCK */
  121. at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* LCDDEN */
  122. at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* LCDCC */
  123. at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* LCDD2 */
  124. at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* LCDD3 */
  125. at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* LCDD4 */
  126. at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* LCDD5 */
  127. at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* LCDD6 */
  128. at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* LCDD7 */
  129. at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* LCDD10 */
  130. at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* LCDD11 */
  131. at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* LCDD12 */
  132. at91_set_a_periph(AT91_PIO_PORTB, 18, 0); /* LCDD13 */
  133. at91_set_a_periph(AT91_PIO_PORTB, 19, 0); /* LCDD14 */
  134. at91_set_a_periph(AT91_PIO_PORTB, 20, 0); /* LCDD15 */
  135. at91_set_b_periph(AT91_PIO_PORTB, 23, 0); /* LCDD18 */
  136. at91_set_b_periph(AT91_PIO_PORTB, 24, 0); /* LCDD19 */
  137. at91_set_b_periph(AT91_PIO_PORTB, 25, 0); /* LCDD20 */
  138. at91_set_b_periph(AT91_PIO_PORTB, 26, 0); /* LCDD21 */
  139. at91_set_b_periph(AT91_PIO_PORTB, 27, 0); /* LCDD22 */
  140. at91_set_b_periph(AT91_PIO_PORTB, 28, 0); /* LCDD23 */
  141. at91_system_clk_enable(AT91_PMC_HCK1);
  142. gd->fb_base = ATMEL_BASE_SRAM;
  143. }
  144. #ifdef CONFIG_LCD_INFO
  145. #include <nand.h>
  146. #include <version.h>
  147. extern flash_info_t flash_info[];
  148. void lcd_show_board_info(void)
  149. {
  150. ulong dram_size, nand_size, flash_size, dataflash_size;
  151. int i;
  152. char temp[32];
  153. lcd_printf ("%s\n", U_BOOT_VERSION);
  154. lcd_printf ("(C) 2009 Ronetix GmbH\n");
  155. lcd_printf ("support@ronetix.at\n");
  156. lcd_printf ("%s CPU at %s MHz",
  157. CONFIG_SYS_AT91_CPU_NAME,
  158. strmhz(temp, get_cpu_clk_rate()));
  159. dram_size = 0;
  160. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  161. dram_size += gd->bd->bi_dram[i].size;
  162. nand_size = 0;
  163. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  164. nand_size += nand_info[i]->size;
  165. flash_size = 0;
  166. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
  167. flash_size += flash_info[i].size;
  168. dataflash_size = 0;
  169. for (i = 0; i < CONFIG_SYS_MAX_DATAFLASH_BANKS; i++)
  170. dataflash_size += (unsigned int) dataflash_info[i].Device.pages_number *
  171. dataflash_info[i].Device.pages_size;
  172. lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n"
  173. "%ld MB DataFlash\n",
  174. dram_size >> 20,
  175. nand_size >> 20,
  176. flash_size >> 20,
  177. dataflash_size >> 20);
  178. }
  179. #endif /* CONFIG_LCD_INFO */
  180. #endif /* CONFIG_LCD */
  181. int board_early_init_f(void)
  182. {
  183. at91_periph_clk_enable(ATMEL_ID_PIOA);
  184. at91_periph_clk_enable(ATMEL_ID_PIOC);
  185. at91_seriald_hw_init();
  186. return 0;
  187. }
  188. int board_init(void)
  189. {
  190. /* arch number of PM9261-Board */
  191. gd->bd->bi_arch_number = MACH_TYPE_PM9261;
  192. /* adress of boot parameters */
  193. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  194. #ifdef CONFIG_CMD_NAND
  195. pm9261_nand_hw_init();
  196. #endif
  197. #ifdef CONFIG_HAS_DATAFLASH
  198. at91_spi0_hw_init(1 << 0);
  199. #endif
  200. #ifdef CONFIG_DRIVER_DM9000
  201. pm9261_dm9000_hw_init();
  202. #endif
  203. #ifdef CONFIG_LCD
  204. pm9261_lcd_hw_init();
  205. #endif
  206. return 0;
  207. }
  208. #ifdef CONFIG_DRIVER_DM9000
  209. int board_eth_init(bd_t *bis)
  210. {
  211. return dm9000_initialize(bis);
  212. }
  213. #endif
  214. int dram_init(void)
  215. {
  216. /* dram_init must store complete ramsize in gd->ram_size */
  217. gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
  218. PHYS_SDRAM_SIZE);
  219. return 0;
  220. }
  221. void dram_init_banksize(void)
  222. {
  223. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  224. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  225. }
  226. #ifdef CONFIG_RESET_PHY_R
  227. void reset_phy(void)
  228. {
  229. #ifdef CONFIG_DRIVER_DM9000
  230. /*
  231. * Initialize ethernet HW addr prior to starting Linux,
  232. * needed for nfsroot
  233. */
  234. eth_init();
  235. #endif
  236. }
  237. #endif
  238. #ifdef CONFIG_DISPLAY_BOARDINFO
  239. int checkboard (void)
  240. {
  241. char buf[32];
  242. printf ("Board : Ronetix PM9261\n");
  243. printf ("Crystal frequency: %8s MHz\n",
  244. strmhz(buf, get_main_clk_rate()));
  245. printf ("CPU clock : %8s MHz\n",
  246. strmhz(buf, get_cpu_clk_rate()));
  247. printf ("Master clock : %8s MHz\n",
  248. strmhz(buf, get_mck_clk_rate()));
  249. return 0;
  250. }
  251. #endif