picosam9g45.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Board functions for mini-box PICOSAM9G45 (AT91SAM9G45) based board
  3. * (C) Copyright 2015 Inter Act B.V.
  4. *
  5. * Based on:
  6. * U-Boot file: board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
  7. * (C) Copyright 2007-2008
  8. * Stelian Pop <stelian@popies.net>
  9. * Lead Tech Design <www.leadtechdesign.com>
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/clk.h>
  16. #include <asm/arch/at91sam9g45_matrix.h>
  17. #include <asm/arch/at91sam9_smc.h>
  18. #include <asm/arch/at91_common.h>
  19. #include <asm/arch/gpio.h>
  20. #include <asm/arch/clk.h>
  21. #include <lcd.h>
  22. #include <linux/mtd/nand.h>
  23. #include <atmel_lcdc.h>
  24. #include <atmel_mci.h>
  25. #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
  26. #include <net.h>
  27. #endif
  28. #include <netdev.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. /* ------------------------------------------------------------------------- */
  31. /*
  32. * Miscelaneous platform dependent initialisations
  33. */
  34. #if defined(CONFIG_SPL_BUILD)
  35. #include <spl.h>
  36. void at91_spl_board_init(void)
  37. {
  38. #ifdef CONFIG_SYS_USE_MMC
  39. at91_mci_hw_init();
  40. #endif
  41. }
  42. #include <asm/arch/atmel_mpddrc.h>
  43. static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
  44. {
  45. ddr2->md = (ATMEL_MPDDRC_MD_DBW_16_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
  46. ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
  47. ATMEL_MPDDRC_CR_NR_ROW_14 |
  48. ATMEL_MPDDRC_CR_DQMS_SHARED |
  49. ATMEL_MPDDRC_CR_CAS_DDR_CAS3);
  50. ddr2->rtr = 0x24b;
  51. ddr2->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |/* 6*7.5 = 45 ns */
  52. 2 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |/* 2*7.5 = 15 ns */
  53. 2 << ATMEL_MPDDRC_TPR0_TWR_OFFSET | /* 2*7.5 = 15 ns */
  54. 8 << ATMEL_MPDDRC_TPR0_TRC_OFFSET | /* 8*7.5 = 60 ns */
  55. 2 << ATMEL_MPDDRC_TPR0_TRP_OFFSET | /* 2*7.5 = 15 ns */
  56. 1 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET | /* 1*7.5= 7.5 ns*/
  57. 1 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET | /* 1 clk cycle */
  58. 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET); /* 2 clk cycles */
  59. ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET | /* 2*7.5 = 15 ns */
  60. 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
  61. 16 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
  62. 14 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
  63. ddr2->tpr2 = (1 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
  64. 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
  65. 7 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
  66. 2 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
  67. }
  68. void mem_init(void)
  69. {
  70. struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  71. struct atmel_mpddrc_config ddr2;
  72. unsigned long csa;
  73. ddr2_conf(&ddr2);
  74. at91_system_clk_enable(AT91_PMC_DDR);
  75. /* Chip select 1 is for DDR2/SDRAM */
  76. csa = readl(&mat->ebicsa);
  77. csa |= AT91_MATRIX_EBI_CS1A_SDRAMC;
  78. csa &= ~AT91_MATRIX_EBI_VDDIOMSEL_3_3V;
  79. writel(csa, &mat->ebicsa);
  80. /* DDRAM2 Controller initialize */
  81. ddr2_init(ATMEL_BASE_DDRSDRC0, ATMEL_BASE_CS6, &ddr2);
  82. ddr2_init(ATMEL_BASE_DDRSDRC1, ATMEL_BASE_CS1, &ddr2);
  83. }
  84. #endif
  85. #ifdef CONFIG_CMD_USB
  86. static void picosam9g45_usb_hw_init(void)
  87. {
  88. at91_periph_clk_enable(ATMEL_ID_PIODE);
  89. at91_set_gpio_output(AT91_PIN_PD1, 0);
  90. at91_set_gpio_output(AT91_PIN_PD3, 0);
  91. }
  92. #endif
  93. #ifdef CONFIG_MACB
  94. static void picosam9g45_macb_hw_init(void)
  95. {
  96. struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
  97. at91_periph_clk_enable(ATMEL_ID_EMAC);
  98. /*
  99. * Disable pull-up on:
  100. * RXDV (PA15) => PHY normal mode (not Test mode)
  101. * ERX0 (PA12) => PHY ADDR0
  102. * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
  103. *
  104. * PHY has internal pull-down
  105. */
  106. writel(pin_to_mask(AT91_PIN_PA15) |
  107. pin_to_mask(AT91_PIN_PA12) |
  108. pin_to_mask(AT91_PIN_PA13),
  109. &pioa->pudr);
  110. at91_phy_reset();
  111. /* Re-enable pull-up */
  112. writel(pin_to_mask(AT91_PIN_PA15) |
  113. pin_to_mask(AT91_PIN_PA12) |
  114. pin_to_mask(AT91_PIN_PA13),
  115. &pioa->puer);
  116. /* And the pins. */
  117. at91_macb_hw_init();
  118. }
  119. #endif
  120. #ifdef CONFIG_LCD
  121. vidinfo_t panel_info = {
  122. .vl_col = 480,
  123. .vl_row = 272,
  124. .vl_clk = 9000000,
  125. .vl_sync = ATMEL_LCDC_INVLINE_NORMAL |
  126. ATMEL_LCDC_INVFRAME_NORMAL,
  127. .vl_bpix = 3,
  128. .vl_tft = 1,
  129. .vl_hsync_len = 45,
  130. .vl_left_margin = 1,
  131. .vl_right_margin = 1,
  132. .vl_vsync_len = 1,
  133. .vl_upper_margin = 40,
  134. .vl_lower_margin = 1,
  135. .mmio = ATMEL_BASE_LCDC,
  136. };
  137. void lcd_enable(void)
  138. {
  139. at91_set_A_periph(AT91_PIN_PE6, 1); /* power up */
  140. }
  141. void lcd_disable(void)
  142. {
  143. at91_set_A_periph(AT91_PIN_PE6, 0); /* power down */
  144. }
  145. static void picosam9g45_lcd_hw_init(void)
  146. {
  147. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  148. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  149. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  150. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  151. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  152. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  153. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  154. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  155. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  156. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  157. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  158. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  159. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  160. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  161. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  162. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  163. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  164. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  165. at91_set_B_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  166. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  167. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  168. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  169. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  170. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  171. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  172. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  173. at91_set_B_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  174. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  175. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  176. at91_periph_clk_enable(ATMEL_ID_LCDC);
  177. gd->fb_base = CONFIG_AT91SAM9G45_LCD_BASE;
  178. }
  179. #ifdef CONFIG_LCD_INFO
  180. #include <nand.h>
  181. #include <version.h>
  182. void lcd_show_board_info(void)
  183. {
  184. ulong dram_size;
  185. int i;
  186. char temp[32];
  187. lcd_printf("%s\n", U_BOOT_VERSION);
  188. lcd_printf("(C) 2015 Inter Act B.V.\n");
  189. lcd_printf("support@interact.nl\n");
  190. lcd_printf("%s CPU at %s MHz\n",
  191. ATMEL_CPU_NAME,
  192. strmhz(temp, get_cpu_clk_rate()));
  193. dram_size = 0;
  194. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  195. dram_size += gd->bd->bi_dram[i].size;
  196. lcd_printf(" %ld MB SDRAM\n", dram_size >> 20);
  197. }
  198. #endif /* CONFIG_LCD_INFO */
  199. #endif
  200. #ifdef CONFIG_GENERIC_ATMEL_MCI
  201. int board_mmc_init(bd_t *bis)
  202. {
  203. at91_mci_hw_init();
  204. return atmel_mci_init((void *)ATMEL_BASE_MCI0);
  205. }
  206. #endif
  207. int board_early_init_f(void)
  208. {
  209. at91_seriald_hw_init();
  210. return 0;
  211. }
  212. int board_init(void)
  213. {
  214. gd->bd->bi_arch_number = MACH_TYPE_PICOSAM9G45;
  215. /* adress of boot parameters */
  216. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  217. #ifdef CONFIG_CMD_USB
  218. picosam9g45_usb_hw_init();
  219. #endif
  220. #ifdef CONFIG_HAS_DATAFLASH
  221. at91_spi0_hw_init(1 << 0);
  222. #endif
  223. #ifdef CONFIG_ATMEL_SPI
  224. at91_spi0_hw_init(1 << 4);
  225. #endif
  226. #ifdef CONFIG_MACB
  227. picosam9g45_macb_hw_init();
  228. #endif
  229. #ifdef CONFIG_LCD
  230. picosam9g45_lcd_hw_init();
  231. #endif
  232. return 0;
  233. }
  234. int dram_init(void)
  235. {
  236. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE)
  237. + get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
  238. return 0;
  239. }
  240. void dram_init_banksize(void)
  241. {
  242. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  243. gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1,
  244. PHYS_SDRAM_1_SIZE);
  245. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  246. gd->bd->bi_dram[1].size = get_ram_size((long *)PHYS_SDRAM_2,
  247. PHYS_SDRAM_2_SIZE);
  248. }
  249. #ifdef CONFIG_RESET_PHY_R
  250. void reset_phy(void)
  251. {
  252. }
  253. #endif
  254. int board_eth_init(bd_t *bis)
  255. {
  256. int rc = 0;
  257. #ifdef CONFIG_MACB
  258. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  259. #endif
  260. return rc;
  261. }
  262. /* SPI chip select control */
  263. #ifdef CONFIG_ATMEL_SPI
  264. #include <spi.h>
  265. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  266. {
  267. return bus == 0 && cs < 2;
  268. }
  269. void spi_cs_activate(struct spi_slave *slave)
  270. {
  271. switch (slave->cs) {
  272. case 1:
  273. at91_set_gpio_output(AT91_PIN_PB18, 0);
  274. break;
  275. case 0:
  276. default:
  277. at91_set_gpio_output(AT91_PIN_PB3, 0);
  278. break;
  279. }
  280. }
  281. void spi_cs_deactivate(struct spi_slave *slave)
  282. {
  283. switch (slave->cs) {
  284. case 1:
  285. at91_set_gpio_output(AT91_PIN_PB18, 1);
  286. break;
  287. case 0:
  288. default:
  289. at91_set_gpio_output(AT91_PIN_PB3, 1);
  290. break;
  291. }
  292. }
  293. #endif /* CONFIG_ATMEL_SPI */