otc570.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * (C) Copyright 2010
  3. * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
  4. * esd electronic system design gmbh <www.esd.eu>
  5. *
  6. * (C) Copyright 2007-2008
  7. * Stelian Pop <stelian.pop@leadtechdesign.com>
  8. * Lead Tech Design <www.leadtechdesign.com>
  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 <atmel_lcdc.h>
  40. #include <lcd.h>
  41. #include <netdev.h>
  42. #ifdef CONFIG_LCD_INFO
  43. #include <nand.h>
  44. #include <version.h>
  45. #endif
  46. DECLARE_GLOBAL_DATA_PTR;
  47. /*
  48. * Miscelaneous platform dependent initialisations
  49. */
  50. static int hw_rev = -1; /* hardware revision */
  51. int get_hw_rev(void)
  52. {
  53. if (hw_rev >= 0)
  54. return hw_rev;
  55. hw_rev = at91_get_pio_value(AT91_PIO_PORTB, 19);
  56. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 20) << 1;
  57. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 21) << 2;
  58. hw_rev |= at91_get_pio_value(AT91_PIO_PORTB, 22) << 3;
  59. if (hw_rev == 15)
  60. hw_rev = 0;
  61. return hw_rev;
  62. }
  63. #ifdef CONFIG_CMD_NAND
  64. static void otc570_nand_hw_init(void)
  65. {
  66. unsigned long csa;
  67. at91_smc_t *smc = (at91_smc_t *) AT91_SMC0_BASE;
  68. at91_matrix_t *matrix = (at91_matrix_t *) AT91_MATRIX_BASE;
  69. /* Enable CS3 */
  70. csa = readl(&matrix->csa[0]) | AT91_MATRIX_CSA_EBI_CS3A;
  71. writel(csa, &matrix->csa[0]);
  72. /* Configure SMC CS3 for NAND/SmartMedia */
  73. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  74. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  75. &smc->cs[3].setup);
  76. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  77. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  78. &smc->cs[3].pulse);
  79. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  80. &smc->cs[3].cycle);
  81. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  82. AT91_SMC_MODE_EXNW_DISABLE |
  83. AT91_SMC_MODE_DBW_8 |
  84. AT91_SMC_MODE_TDF_CYCLE(2),
  85. &smc->cs[3].mode);
  86. /* Configure RDY/BSY */
  87. at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  88. /* Enable NandFlash */
  89. at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  90. }
  91. #endif /* CONFIG_CMD_NAND */
  92. #ifdef CONFIG_MACB
  93. static void otc570_macb_hw_init(void)
  94. {
  95. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  96. /* Enable clock */
  97. writel(1 << AT91SAM9263_ID_EMAC, &pmc->pcer);
  98. at91_macb_hw_init();
  99. }
  100. #endif
  101. /*
  102. * Static memory controller initialization to enable Beckhoff ET1100 EtherCAT
  103. * controller debugging
  104. * The ET1100 is located at physical address 0x70000000
  105. * Its process memory is located at physical address 0x70001000
  106. */
  107. static void otc570_ethercat_hw_init(void)
  108. {
  109. at91_smc_t *smc1 = (at91_smc_t *) AT91_SMC1_BASE;
  110. /* Configure SMC EBI1_CS0 for EtherCAT */
  111. writel(AT91_SMC_SETUP_NWE(0) | AT91_SMC_SETUP_NCS_WR(0) |
  112. AT91_SMC_SETUP_NRD(0) | AT91_SMC_SETUP_NCS_RD(0),
  113. &smc1->cs[0].setup);
  114. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(9) |
  115. AT91_SMC_PULSE_NRD(5) | AT91_SMC_PULSE_NCS_RD(9),
  116. &smc1->cs[0].pulse);
  117. writel(AT91_SMC_CYCLE_NWE(10) | AT91_SMC_CYCLE_NRD(6),
  118. &smc1->cs[0].cycle);
  119. /*
  120. * Configure behavior at external wait signal, byte-select mode, 16 bit
  121. * data bus width, none data float wait states and TDF optimization
  122. */
  123. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_EXNW_READY |
  124. AT91_SMC_MODE_DBW_16 | AT91_SMC_MODE_TDF_CYCLE(0) |
  125. AT91_SMC_MODE_TDF, &smc1->cs[0].mode);
  126. /* Configure RDY/BSY */
  127. at91_set_b_periph(AT91_PIO_PORTE, 20, 0); /* EBI1_NWAIT */
  128. }
  129. #ifdef CONFIG_LCD
  130. /* Number of columns and rows, pixel clock in Hz and hsync/vsync polarity */
  131. vidinfo_t panel_info = {
  132. .vl_col = 640,
  133. .vl_row = 480,
  134. .vl_clk = 25175000,
  135. .vl_sync = ATMEL_LCDC_INVLINE_INVERTED |
  136. ATMEL_LCDC_INVFRAME_INVERTED,
  137. .vl_bpix = 3, /* Bits per pixel, 0 = 1bit, 3 = 8bit */
  138. .vl_tft = 1, /* 0 = passive, 1 = TFT */
  139. .vl_vsync_len = 1, /* Length of vertical sync in NOL */
  140. .vl_upper_margin = 35, /* Idle lines at the frame start */
  141. .vl_lower_margin = 5, /* Idle lines at the end of the frame */
  142. .vl_hsync_len = 5, /* Width of the LCDHSYNC pulse */
  143. .vl_left_margin = 112, /* Idle cycles at the line beginning */
  144. .vl_right_margin = 1, /* Idle cycles at the end of the line */
  145. .mmio = AT91SAM9263_LCDC_BASE,
  146. };
  147. void lcd_enable(void)
  148. {
  149. at91_set_pio_value(AT91_PIO_PORTA, 30, 0); /* power up */
  150. }
  151. void lcd_disable(void)
  152. {
  153. at91_set_pio_value(AT91_PIO_PORTA, 30, 1); /* power down */
  154. }
  155. static void otc570_lcd_hw_init(void)
  156. {
  157. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  158. at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* LCDVSYNC */
  159. at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* LCDHSYNC */
  160. at91_set_a_periph(AT91_PIO_PORTC, 2, 0); /* LCDDOTCK */
  161. at91_set_a_periph(AT91_PIO_PORTC, 3, 0); /* LCDDEN */
  162. at91_set_b_periph(AT91_PIO_PORTB, 9, 0); /* LCDCC */
  163. at91_set_a_periph(AT91_PIO_PORTC, 6, 0); /* LCDD2 */
  164. at91_set_a_periph(AT91_PIO_PORTC, 7, 0); /* LCDD3 */
  165. at91_set_a_periph(AT91_PIO_PORTC, 8, 0); /* LCDD4 */
  166. at91_set_a_periph(AT91_PIO_PORTC, 9, 0); /* LCDD5 */
  167. at91_set_a_periph(AT91_PIO_PORTC, 10, 0); /* LCDD6 */
  168. at91_set_a_periph(AT91_PIO_PORTC, 11, 0); /* LCDD7 */
  169. at91_set_a_periph(AT91_PIO_PORTC, 14, 0); /* LCDD10 */
  170. at91_set_a_periph(AT91_PIO_PORTC, 15, 0); /* LCDD11 */
  171. at91_set_a_periph(AT91_PIO_PORTC, 16, 0); /* LCDD12 */
  172. at91_set_b_periph(AT91_PIO_PORTC, 12, 0); /* LCDD13 */
  173. at91_set_a_periph(AT91_PIO_PORTC, 18, 0); /* LCDD14 */
  174. at91_set_a_periph(AT91_PIO_PORTC, 19, 0); /* LCDD15 */
  175. at91_set_a_periph(AT91_PIO_PORTC, 22, 0); /* LCDD18 */
  176. at91_set_a_periph(AT91_PIO_PORTC, 23, 0); /* LCDD19 */
  177. at91_set_a_periph(AT91_PIO_PORTC, 24, 0); /* LCDD20 */
  178. at91_set_b_periph(AT91_PIO_PORTC, 17, 0); /* LCDD21 */
  179. at91_set_a_periph(AT91_PIO_PORTC, 26, 0); /* LCDD22 */
  180. at91_set_a_periph(AT91_PIO_PORTC, 27, 0); /* LCDD23 */
  181. at91_set_pio_output(AT91_PIO_PORTA, 30, 1); /* PCI */
  182. writel(1 << AT91SAM9263_ID_LCDC, &pmc->pcer);
  183. gd->fb_base = CONFIG_OTC570_LCD_BASE;
  184. }
  185. #ifdef CONFIG_LCD_INFO
  186. void lcd_show_board_info(void)
  187. {
  188. ulong dram_size, nand_size;
  189. int i;
  190. char temp[32];
  191. dram_size = 0;
  192. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
  193. dram_size += gd->bd->bi_dram[i].size;
  194. nand_size = 0;
  195. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  196. nand_size += nand_info[i].size;
  197. lcd_printf("\n%s\n", U_BOOT_VERSION);
  198. lcd_printf("%s CPU at %s MHz\n", CONFIG_SYS_AT91_CPU_NAME,
  199. strmhz(temp, get_cpu_clk_rate()));
  200. lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
  201. dram_size >> 20,
  202. nand_size >> 20 );
  203. lcd_printf(" Board : esd ARM9 HMI Panel - OTC570\n");
  204. lcd_printf(" Hardware-revision: 1.%d\n", get_hw_rev());
  205. lcd_printf(" Mach-type : %lu\n", gd->bd->bi_arch_number);
  206. }
  207. #endif /* CONFIG_LCD_INFO */
  208. #endif /* CONFIG_LCD */
  209. int dram_init(void)
  210. {
  211. gd->bd->bi_dram[0].start = PHYS_SDRAM;
  212. gd->bd->bi_dram[0].size = get_ram_size((long *) PHYS_SDRAM, (1 << 27));
  213. return 0;
  214. }
  215. int board_eth_init(bd_t *bis)
  216. {
  217. int rc = 0;
  218. #ifdef CONFIG_MACB
  219. rc = macb_eth_initialize(0, (void *)AT91_EMAC_BASE, 0x00);
  220. #endif
  221. return rc;
  222. }
  223. int checkboard(void)
  224. {
  225. char str[32];
  226. puts("Board: esd ARM9 HMI Panel - OTC570");
  227. if (getenv_r("serial#", str, sizeof(str)) > 0) {
  228. puts(", serial# ");
  229. puts(str);
  230. }
  231. printf("\nHardware-revision: 1.%d\n", get_hw_rev());
  232. printf("Mach-type: %lu\n", gd->bd->bi_arch_number);
  233. return 0;
  234. }
  235. #ifdef CONFIG_SERIAL_TAG
  236. void get_board_serial(struct tag_serialnr *serialnr)
  237. {
  238. char *str;
  239. char *serial = getenv("serial#");
  240. if (serial) {
  241. str = strchr(serial, '_');
  242. if (str && (strlen(str) >= 4)) {
  243. serialnr->high = (*(str + 1) << 8) | *(str + 2);
  244. serialnr->low = simple_strtoul(str + 3, NULL, 16);
  245. }
  246. } else {
  247. serialnr->high = 0;
  248. serialnr->low = 0;
  249. }
  250. }
  251. #endif
  252. #ifdef CONFIG_REVISION_TAG
  253. u32 get_board_rev(void)
  254. {
  255. return hw_rev | 0x100;
  256. }
  257. #endif
  258. #ifdef CONFIG_MISC_INIT_R
  259. int misc_init_r(void)
  260. {
  261. char str[64];
  262. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  263. at91_set_pio_output(AT91_PIO_PORTA, 29, 1);
  264. at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */
  265. at91_set_a_periph(AT91_PIO_PORTA, 27, 0); /* RXD0 */
  266. writel(1 << AT91SAM9263_ID_US0, &pmc->pcer);
  267. /* Set USART_MODE = 1 (RS485) */
  268. writel(1, 0xFFF8C004);
  269. printf("USART0: ");
  270. if (getenv_r("usart0", str, sizeof(str)) == -1) {
  271. printf("No entry - assuming 1-wire\n");
  272. /* CTS pin, works as mode select pin (0 = 1-wire; 1 = RS485) */
  273. at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
  274. } else {
  275. if (strcmp(str, "1-wire") == 0) {
  276. printf("%s\n", str);
  277. at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
  278. } else if (strcmp(str, "rs485") == 0) {
  279. printf("%s\n", str);
  280. at91_set_pio_output(AT91_PIO_PORTA, 29, 1);
  281. } else {
  282. printf("Wrong entry - assuming 1-wire ");
  283. printf("(valid values are '1-wire' or 'rs485')\n");
  284. at91_set_pio_output(AT91_PIO_PORTA, 29, 0);
  285. }
  286. }
  287. printf("Display memory address: 0x%08lX\n", gd->fb_base);
  288. return 0;
  289. }
  290. #endif /* CONFIG_MISC_INIT_R */
  291. int board_init(void)
  292. {
  293. at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
  294. /* Peripheral Clock Enable Register */
  295. writel( 1 << AT91SAM9263_ID_PIOA |
  296. 1 << AT91SAM9263_ID_PIOB |
  297. 1 << AT91SAM9263_ID_PIOCDE |
  298. 1 << AT91SAM9263_ID_TWI |
  299. 1 << AT91SAM9263_ID_SPI0 |
  300. 1 << AT91SAM9263_ID_LCDC |
  301. 1 << AT91SAM9263_ID_UHP,
  302. &pmc->pcer);
  303. /* arch number of OTC570-Board */
  304. gd->bd->bi_arch_number = MACH_TYPE_OTC570;
  305. /* adress of boot parameters */
  306. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  307. at91_serial_hw_init();
  308. #ifdef CONFIG_CMD_NAND
  309. otc570_nand_hw_init();
  310. #endif
  311. otc570_ethercat_hw_init();
  312. #ifdef CONFIG_HAS_DATAFLASH
  313. at91_spi0_hw_init(1 << 0);
  314. #endif
  315. #ifdef CONFIG_MACB
  316. otc570_macb_hw_init();
  317. #endif
  318. #ifdef CONFIG_AT91_CAN
  319. at91_can_hw_init();
  320. #endif
  321. #ifdef CONFIG_USB_OHCI_NEW
  322. at91_uhp_hw_init();
  323. #endif
  324. #ifdef CONFIG_LCD
  325. otc570_lcd_hw_init();
  326. #endif
  327. return 0;
  328. }