pm9261.c 8.4 KB

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