meesc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * (C) Copyright 2009-2015
  7. * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
  8. * esd electronic system design gmbh <www.esd.eu>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <asm/io.h>
  14. #include <asm/gpio.h>
  15. #include <asm/arch/at91sam9_smc.h>
  16. #include <asm/arch/at91_common.h>
  17. #include <asm/arch/at91_pmc.h>
  18. #include <asm/arch/at91_rstc.h>
  19. #include <asm/arch/at91_matrix.h>
  20. #include <asm/arch/at91_pio.h>
  21. #include <asm/arch/clk.h>
  22. #include <netdev.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. /*
  25. * Miscelaneous platform dependent initialisations
  26. */
  27. #ifdef CONFIG_REVISION_TAG
  28. static int hw_rev = -1; /* hardware revision */
  29. int get_hw_rev(void)
  30. {
  31. if (hw_rev >= 0)
  32. return hw_rev;
  33. hw_rev = at91_get_pio_value(AT91_PIO_PORTB, 19);
  34. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 20) << 1;
  35. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 21) << 2;
  36. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 22) << 3;
  37. if (hw_rev == 15)
  38. hw_rev = 0;
  39. return hw_rev;
  40. }
  41. #endif /* CONFIG_REVISION_TAG */
  42. #ifdef CONFIG_CMD_NAND
  43. static void meesc_nand_hw_init(void)
  44. {
  45. unsigned long csa;
  46. at91_smc_t *smc = (at91_smc_t *) ATMEL_BASE_SMC0;
  47. at91_matrix_t *matrix = (at91_matrix_t *) ATMEL_BASE_MATRIX;
  48. /* Enable CS3 */
  49. csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
  50. writel(csa, &matrix->csa[0]);
  51. /* Configure SMC CS3 for NAND/SmartMedia */
  52. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(1) |
  53. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(2),
  54. &smc->cs[3].setup);
  55. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  56. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  57. &smc->cs[3].pulse);
  58. writel(AT91_SMC_CYCLE_NWE(6) | AT91_SMC_CYCLE_NRD(6),
  59. &smc->cs[3].cycle);
  60. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  61. AT91_SMC_MODE_EXNW_DISABLE |
  62. AT91_SMC_MODE_DBW_8 |
  63. AT91_SMC_MODE_TDF_CYCLE(12),
  64. &smc->cs[3].mode);
  65. /* Configure RDY/BSY */
  66. gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
  67. /* Enable NandFlash */
  68. gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  69. }
  70. #endif /* CONFIG_CMD_NAND */
  71. #ifdef CONFIG_MACB
  72. static void meesc_macb_hw_init(void)
  73. {
  74. at91_periph_clk_enable(ATMEL_ID_EMAC);
  75. at91_macb_hw_init();
  76. }
  77. #endif
  78. /*
  79. * Static memory controller initialization to enable Beckhoff ET1100 EtherCAT
  80. * controller debugging
  81. * The ET1100 is located at physical address 0x70000000
  82. * Its process memory is located at physical address 0x70001000
  83. */
  84. static void meesc_ethercat_hw_init(void)
  85. {
  86. at91_smc_t *smc1 = (at91_smc_t *) ATMEL_BASE_SMC1;
  87. /* Configure SMC EBI1_CS0 for EtherCAT */
  88. writel(AT91_SMC_SETUP_NWE(0) | AT91_SMC_SETUP_NCS_WR(0) |
  89. AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(0),
  90. &smc1->cs[0].setup);
  91. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(9) |
  92. AT91_SMC_PULSE_NRD(5) | AT91_SMC_PULSE_NCS_RD(9),
  93. &smc1->cs[0].pulse);
  94. writel(AT91_SMC_CYCLE_NWE(10) | AT91_SMC_CYCLE_NRD(6),
  95. &smc1->cs[0].cycle);
  96. /*
  97. * Configure behavior at external wait signal, byte-select mode, 16 bit
  98. * data bus width, none data float wait states and TDF optimization
  99. */
  100. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_EXNW_READY |
  101. AT91_SMC_MODE_DBW_16 | AT91_SMC_MODE_TDF_CYCLE(0) |
  102. AT91_SMC_MODE_TDF, &smc1->cs[0].mode);
  103. /* Configure RDY/BSY */
  104. at91_set_b_periph(AT91_PIO_PORTE, 20, 0); /* EBI1_NWAIT */
  105. }
  106. int dram_init(void)
  107. {
  108. /* dram_init must store complete ramsize in gd->ram_size */
  109. gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
  110. PHYS_SDRAM_SIZE);
  111. return 0;
  112. }
  113. void dram_init_banksize(void)
  114. {
  115. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  116. gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
  117. }
  118. int board_eth_init(bd_t *bis)
  119. {
  120. int rc = 0;
  121. #ifdef CONFIG_MACB
  122. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x00);
  123. #endif
  124. return rc;
  125. }
  126. #ifdef CONFIG_DISPLAY_BOARDINFO
  127. int checkboard(void)
  128. {
  129. char str[32];
  130. u_char hw_type; /* hardware type */
  131. /* read the "Type" register of the ET1100 controller */
  132. hw_type = readb(CONFIG_ET1100_BASE);
  133. switch (hw_type) {
  134. case 0x11:
  135. case 0x3F:
  136. /* ET1100 present, arch number of MEESC-Board */
  137. gd->bd->bi_arch_number = MACH_TYPE_MEESC;
  138. puts("Board: CAN-EtherCAT Gateway");
  139. break;
  140. case 0xFF:
  141. /* no ET1100 present, arch number of EtherCAN/2-Board */
  142. gd->bd->bi_arch_number = MACH_TYPE_ETHERCAN2;
  143. puts("Board: EtherCAN/2 Gateway");
  144. /* switch on LED1D */
  145. at91_set_pio_output(AT91_PIO_PORTB, 12, 1);
  146. break;
  147. default:
  148. /* assume, no ET1100 present, arch number of EtherCAN/2-Board */
  149. gd->bd->bi_arch_number = MACH_TYPE_ETHERCAN2;
  150. printf("ERROR! Read invalid hw_type: %02X\n", hw_type);
  151. puts("Board: EtherCAN/2 Gateway");
  152. break;
  153. }
  154. if (getenv_f("serial#", str, sizeof(str)) > 0) {
  155. puts(", serial# ");
  156. puts(str);
  157. }
  158. #ifdef CONFIG_REVISION_TAG
  159. printf("\nHardware-revision: 1.%d\n", get_hw_rev());
  160. #endif
  161. printf("Mach-type: %lu\n", gd->bd->bi_arch_number);
  162. return 0;
  163. }
  164. #endif /* CONFIG_DISPLAY_BOARDINFO */
  165. #ifdef CONFIG_SERIAL_TAG
  166. void get_board_serial(struct tag_serialnr *serialnr)
  167. {
  168. char *str;
  169. char *serial = getenv("serial#");
  170. if (serial) {
  171. str = strchr(serial, '_');
  172. if (str && (strlen(str) >= 4)) {
  173. serialnr->high = (*(str + 1) << 8) | *(str + 2);
  174. serialnr->low = simple_strtoul(str + 3, NULL, 16);
  175. }
  176. } else {
  177. serialnr->high = 0;
  178. serialnr->low = 0;
  179. }
  180. }
  181. #endif
  182. #ifdef CONFIG_REVISION_TAG
  183. u32 get_board_rev(void)
  184. {
  185. return hw_rev | 0x100;
  186. }
  187. #endif
  188. #ifdef CONFIG_MISC_INIT_R
  189. int misc_init_r(void)
  190. {
  191. char *str;
  192. char buf[32];
  193. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  194. /*
  195. * Normally the processor clock has a divisor of 2.
  196. * In some cases this this needs to be set to 4.
  197. * Check the user has set environment mdiv to 4 to change the divisor.
  198. */
  199. if ((str = getenv("mdiv")) && (strcmp(str, "4") == 0)) {
  200. writel((readl(&pmc->mckr) & ~AT91_PMC_MDIV) |
  201. AT91SAM9_PMC_MDIV_4, &pmc->mckr);
  202. at91_clock_init(CONFIG_SYS_AT91_MAIN_CLOCK);
  203. serial_setbrg();
  204. /* Notify the user that the clock is not default */
  205. printf("Setting master clock to %s MHz\n",
  206. strmhz(buf, get_mck_clk_rate()));
  207. }
  208. return 0;
  209. }
  210. #endif /* CONFIG_MISC_INIT_R */
  211. int board_early_init_f(void)
  212. {
  213. at91_periph_clk_enable(ATMEL_ID_PIOA);
  214. at91_periph_clk_enable(ATMEL_ID_PIOB);
  215. at91_periph_clk_enable(ATMEL_ID_PIOCDE);
  216. at91_periph_clk_enable(ATMEL_ID_UHP);
  217. at91_seriald_hw_init();
  218. return 0;
  219. }
  220. int board_init(void)
  221. {
  222. /* initialize ET1100 Controller */
  223. meesc_ethercat_hw_init();
  224. /* adress of boot parameters */
  225. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  226. #ifdef CONFIG_CMD_NAND
  227. meesc_nand_hw_init();
  228. #endif
  229. #ifdef CONFIG_HAS_DATAFLASH
  230. at91_spi0_hw_init(1 << 0);
  231. #endif
  232. #ifdef CONFIG_MACB
  233. meesc_macb_hw_init();
  234. #endif
  235. #ifdef CONFIG_AT91_CAN
  236. at91_can_hw_init();
  237. #endif
  238. #ifdef CONFIG_USB_OHCI_NEW
  239. at91_uhp_hw_init();
  240. #endif
  241. return 0;
  242. }