meesc.c 7.3 KB

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