taurus.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * Board functions for Siemens TAURUS (AT91SAM9G20) based boards
  3. * (C) Copyright Siemens AG
  4. *
  5. * Based on:
  6. * U-Boot file: board/atmel/at91sam9260ek/at91sam9260ek.c
  7. *
  8. * (C) Copyright 2007-2008
  9. * Stelian Pop <stelian@popies.net>
  10. * Lead Tech Design <www.leadtechdesign.com>
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <command.h>
  15. #include <common.h>
  16. #include <dm.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/at91sam9260_matrix.h>
  19. #include <asm/arch/at91sam9_smc.h>
  20. #include <asm/arch/at91_common.h>
  21. #include <asm/arch/at91_rstc.h>
  22. #include <asm/arch/gpio.h>
  23. #include <asm/arch/at91sam9_sdramc.h>
  24. #include <asm/arch/atmel_serial.h>
  25. #include <asm/arch/clk.h>
  26. #include <asm/gpio.h>
  27. #include <linux/mtd/nand.h>
  28. #include <atmel_mci.h>
  29. #include <asm/arch/at91_spi.h>
  30. #include <spi.h>
  31. #include <net.h>
  32. #ifndef CONFIG_DM_ETH
  33. #include <netdev.h>
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. static void taurus_request_gpio(void)
  37. {
  38. gpio_request(CONFIG_SYS_NAND_ENABLE_PIN, "nand ena");
  39. gpio_request(CONFIG_SYS_NAND_READY_PIN, "nand rdy");
  40. gpio_request(AT91_PIN_PA25, "ena PHY");
  41. }
  42. static void taurus_nand_hw_init(void)
  43. {
  44. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  45. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  46. unsigned long csa;
  47. /* Assign CS3 to NAND/SmartMedia Interface */
  48. csa = readl(&matrix->ebicsa);
  49. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  50. writel(csa, &matrix->ebicsa);
  51. /* Configure SMC CS3 for NAND/SmartMedia */
  52. writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
  53. AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
  54. &smc->cs[3].setup);
  55. writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
  56. AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(3),
  57. &smc->cs[3].pulse);
  58. writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(7),
  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(3),
  64. &smc->cs[3].mode);
  65. /* Configure RDY/BSY */
  66. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  67. /* Enable NandFlash */
  68. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  69. }
  70. #if defined(CONFIG_SPL_BUILD)
  71. #include <spl.h>
  72. #include <nand.h>
  73. #include <spi_flash.h>
  74. void matrix_init(void)
  75. {
  76. struct at91_matrix *mat = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  77. writel((readl(&mat->scfg[3]) & (~AT91_MATRIX_SLOT_CYCLE))
  78. | AT91_MATRIX_SLOT_CYCLE_(0x40),
  79. &mat->scfg[3]);
  80. }
  81. #if defined(CONFIG_BOARD_AXM)
  82. static int at91_is_recovery(void)
  83. {
  84. if ((at91_get_gpio_value(AT91_PIN_PA26) == 0) &&
  85. (at91_get_gpio_value(AT91_PIN_PA27) == 0))
  86. return 1;
  87. return 0;
  88. }
  89. #elif defined(CONFIG_BOARD_TAURUS)
  90. static int at91_is_recovery(void)
  91. {
  92. if (at91_get_gpio_value(AT91_PIN_PA31) == 0)
  93. return 1;
  94. return 0;
  95. }
  96. #endif
  97. void spl_board_init(void)
  98. {
  99. taurus_nand_hw_init();
  100. at91_spi0_hw_init(TAURUS_SPI_MASK);
  101. #if defined(CONFIG_BOARD_AXM)
  102. /* Configure LED PINs */
  103. at91_set_gpio_output(AT91_PIN_PA6, 0);
  104. at91_set_gpio_output(AT91_PIN_PA8, 0);
  105. at91_set_gpio_output(AT91_PIN_PA9, 0);
  106. at91_set_gpio_output(AT91_PIN_PA10, 0);
  107. at91_set_gpio_output(AT91_PIN_PA11, 0);
  108. at91_set_gpio_output(AT91_PIN_PA12, 0);
  109. /* Configure recovery button PINs */
  110. at91_set_gpio_input(AT91_PIN_PA26, 1);
  111. at91_set_gpio_input(AT91_PIN_PA27, 1);
  112. #elif defined(CONFIG_BOARD_TAURUS)
  113. at91_set_gpio_input(AT91_PIN_PA31, 1);
  114. #endif
  115. /* check for recovery mode */
  116. if (at91_is_recovery() == 1) {
  117. struct spi_flash *flash;
  118. puts("Recovery button pressed\n");
  119. nand_init();
  120. spl_nand_erase_one(0, 0);
  121. flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
  122. 0,
  123. CONFIG_SF_DEFAULT_SPEED,
  124. CONFIG_SF_DEFAULT_MODE);
  125. if (!flash) {
  126. puts("no flash\n");
  127. } else {
  128. puts("erase spi flash sector 0\n");
  129. spi_flash_erase(flash, 0,
  130. CONFIG_SYS_NAND_U_BOOT_SIZE);
  131. }
  132. }
  133. }
  134. #define SDRAM_BASE_CONF (AT91_SDRAMC_NR_13 | AT91_SDRAMC_CAS_3 \
  135. |AT91_SDRAMC_NB_4 | AT91_SDRAMC_DBW_32 \
  136. | AT91_SDRAMC_TWR_VAL(3) | AT91_SDRAMC_TRC_VAL(9) \
  137. | AT91_SDRAMC_TRP_VAL(3) | AT91_SDRAMC_TRCD_VAL(3) \
  138. | AT91_SDRAMC_TRAS_VAL(6) | AT91_SDRAMC_TXSR_VAL(10))
  139. void sdramc_configure(unsigned int mask)
  140. {
  141. struct at91_matrix *ma = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  142. struct sdramc_reg setting;
  143. at91_sdram_hw_init();
  144. setting.cr = SDRAM_BASE_CONF | mask;
  145. setting.mdr = AT91_SDRAMC_MD_SDRAM;
  146. setting.tr = (CONFIG_SYS_MASTER_CLOCK * 7) / 1000000;
  147. writel(readl(&ma->ebicsa) | AT91_MATRIX_CS1A_SDRAMC |
  148. AT91_MATRIX_VDDIOMSEL_3_3V | AT91_MATRIX_EBI_IOSR_SEL,
  149. &ma->ebicsa);
  150. sdramc_initialize(ATMEL_BASE_CS1, &setting);
  151. }
  152. void mem_init(void)
  153. {
  154. unsigned int ram_size = 0;
  155. /* Configure SDRAM for 128MB */
  156. sdramc_configure(AT91_SDRAMC_NC_10);
  157. /* Do memtest for 128MB */
  158. ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  159. CONFIG_SYS_SDRAM_SIZE);
  160. /*
  161. * If 32MB or 16MB should be supported check also for
  162. * expected mirroring at A16 and A17
  163. * To find mirror addresses depends how the collumns are connected
  164. * at RAM (internaly or externaly)
  165. * If the collumns are not in inverted order the mirror size effect
  166. * behaves like normal SRAM with A0,A1,A2,etc. connected incremantal
  167. */
  168. /* Mirrors at A15 on ATMEL G20 SDRAM Controller with 64MB*/
  169. if (ram_size == 0x800) {
  170. printf("\n\r 64MB");
  171. sdramc_configure(AT91_SDRAMC_NC_9);
  172. } else {
  173. /* Size already initialized */
  174. printf("\n\r 128MB");
  175. }
  176. }
  177. #endif
  178. #ifdef CONFIG_MACB
  179. static void siemens_phy_reset(void)
  180. {
  181. /*
  182. * we need to reset PHY for 200us
  183. * because of bug in ATMEL G20 CPU (undefined initial state of GPIO)
  184. */
  185. if ((readl(AT91_ASM_RSTC_SR) & AT91_RSTC_RSTTYP) ==
  186. AT91_RSTC_RSTTYP_GENERAL)
  187. at91_set_gpio_value(AT91_PIN_PA25, 0); /* reset eth switch */
  188. }
  189. static void taurus_macb_hw_init(void)
  190. {
  191. /* Enable EMAC clock */
  192. at91_periph_clk_enable(ATMEL_ID_EMAC0);
  193. /*
  194. * Disable pull-up on:
  195. * RXDV (PA17) => PHY normal mode (not Test mode)
  196. * ERX0 (PA14) => PHY ADDR0
  197. * ERX1 (PA15) => PHY ADDR1
  198. * ERX2 (PA25) => PHY ADDR2
  199. * ERX3 (PA26) => PHY ADDR3
  200. * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
  201. *
  202. * PHY has internal pull-down
  203. */
  204. at91_set_pio_pullup(AT91_PIO_PORTA, 14, 0);
  205. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
  206. at91_set_pio_pullup(AT91_PIO_PORTA, 17, 0);
  207. at91_set_pio_pullup(AT91_PIO_PORTA, 25, 0);
  208. at91_set_pio_pullup(AT91_PIO_PORTA, 26, 0);
  209. at91_set_pio_pullup(AT91_PIO_PORTA, 28, 0);
  210. siemens_phy_reset();
  211. at91_phy_reset();
  212. at91_set_gpio_input(AT91_PIN_PA25, 1); /* ERST tri-state */
  213. /* Re-enable pull-up */
  214. at91_set_pio_pullup(AT91_PIO_PORTA, 14, 1);
  215. at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
  216. at91_set_pio_pullup(AT91_PIO_PORTA, 17, 1);
  217. at91_set_pio_pullup(AT91_PIO_PORTA, 25, 1);
  218. at91_set_pio_pullup(AT91_PIO_PORTA, 26, 1);
  219. at91_set_pio_pullup(AT91_PIO_PORTA, 28, 1);
  220. /* Initialize EMAC=MACB hardware */
  221. at91_macb_hw_init();
  222. }
  223. #endif
  224. #ifdef CONFIG_GENERIC_ATMEL_MCI
  225. int board_mmc_init(bd_t *bd)
  226. {
  227. at91_mci_hw_init();
  228. return atmel_mci_init((void *)ATMEL_BASE_MCI);
  229. }
  230. #endif
  231. int board_early_init_f(void)
  232. {
  233. /* Enable clocks for all PIOs */
  234. at91_periph_clk_enable(ATMEL_ID_PIOA);
  235. at91_periph_clk_enable(ATMEL_ID_PIOB);
  236. at91_periph_clk_enable(ATMEL_ID_PIOC);
  237. at91_seriald_hw_init();
  238. taurus_request_gpio();
  239. return 0;
  240. }
  241. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  242. {
  243. return bus == 0 && cs == 0;
  244. }
  245. void spi_cs_activate(struct spi_slave *slave)
  246. {
  247. at91_set_gpio_value(TAURUS_SPI_CS_PIN, 0);
  248. }
  249. void spi_cs_deactivate(struct spi_slave *slave)
  250. {
  251. at91_set_gpio_value(TAURUS_SPI_CS_PIN, 1);
  252. }
  253. #ifdef CONFIG_USB_GADGET_AT91
  254. #include <linux/usb/at91_udc.h>
  255. void at91_udp_hw_init(void)
  256. {
  257. /* Enable PLLB */
  258. at91_pllb_clk_enable(get_pllb_init());
  259. /* Enable UDPCK clock, MCK is enabled in at91_clock_init() */
  260. at91_periph_clk_enable(ATMEL_ID_UDP);
  261. at91_system_clk_enable(AT91SAM926x_PMC_UDP);
  262. }
  263. struct at91_udc_data board_udc_data = {
  264. .baseaddr = ATMEL_BASE_UDP0,
  265. };
  266. #endif
  267. int board_init(void)
  268. {
  269. /* adress of boot parameters */
  270. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  271. taurus_request_gpio();
  272. #ifdef CONFIG_CMD_NAND
  273. taurus_nand_hw_init();
  274. #endif
  275. #ifdef CONFIG_MACB
  276. taurus_macb_hw_init();
  277. #endif
  278. at91_spi0_hw_init(TAURUS_SPI_MASK);
  279. #ifdef CONFIG_USB_GADGET_AT91
  280. at91_udp_hw_init();
  281. at91_udc_probe(&board_udc_data);
  282. #endif
  283. return 0;
  284. }
  285. int dram_init(void)
  286. {
  287. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
  288. CONFIG_SYS_SDRAM_SIZE);
  289. return 0;
  290. }
  291. #ifndef CONFIG_DM_ETH
  292. int board_eth_init(bd_t *bis)
  293. {
  294. int rc = 0;
  295. #ifdef CONFIG_MACB
  296. rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
  297. #endif
  298. return rc;
  299. }
  300. #endif
  301. #if !defined(CONFIG_SPL_BUILD)
  302. #if defined(CONFIG_BOARD_AXM)
  303. /*
  304. * Booting the Fallback Image.
  305. *
  306. * The function is used to provide and
  307. * boot the image with the fallback
  308. * parameters, incase if the faulty image
  309. * in upgraded over the base firmware.
  310. *
  311. */
  312. static int upgrade_failure_fallback(void)
  313. {
  314. char *partitionset_active = NULL;
  315. char *rootfs = NULL;
  316. char *rootfs_fallback = NULL;
  317. char *kern_off;
  318. char *kern_off_fb;
  319. char *kern_size;
  320. char *kern_size_fb;
  321. partitionset_active = getenv("partitionset_active");
  322. if (partitionset_active) {
  323. if (partitionset_active[0] == 'A')
  324. setenv("partitionset_active", "B");
  325. else
  326. setenv("partitionset_active", "A");
  327. } else {
  328. printf("partitionset_active missing.\n");
  329. return -ENOENT;
  330. }
  331. rootfs = getenv("rootfs");
  332. rootfs_fallback = getenv("rootfs_fallback");
  333. setenv("rootfs", rootfs_fallback);
  334. setenv("rootfs_fallback", rootfs);
  335. kern_size = getenv("kernel_size");
  336. kern_size_fb = getenv("kernel_size_fallback");
  337. setenv("kernel_size", kern_size_fb);
  338. setenv("kernel_size_fallback", kern_size);
  339. kern_off = getenv("kernel_Off");
  340. kern_off_fb = getenv("kernel_Off_fallback");
  341. setenv("kernel_Off", kern_off_fb);
  342. setenv("kernel_Off_fallback", kern_off);
  343. setenv("bootargs", '\0');
  344. setenv("upgrade_available", '\0');
  345. setenv("boot_retries", '\0');
  346. saveenv();
  347. return 0;
  348. }
  349. static int do_upgrade_available(cmd_tbl_t *cmdtp, int flag, int argc,
  350. char * const argv[])
  351. {
  352. unsigned long upgrade_available = 0;
  353. unsigned long boot_retry = 0;
  354. char boot_buf[10];
  355. upgrade_available = simple_strtoul(getenv("upgrade_available"), NULL,
  356. 10);
  357. if (upgrade_available) {
  358. boot_retry = simple_strtoul(getenv("boot_retries"), NULL, 10);
  359. boot_retry++;
  360. sprintf(boot_buf, "%lx", boot_retry);
  361. setenv("boot_retries", boot_buf);
  362. saveenv();
  363. /*
  364. * Here the boot_retries count is checked, and if the
  365. * count becomes greater than 2 switch back to the
  366. * fallback, and reset the board.
  367. */
  368. if (boot_retry > 2) {
  369. if (upgrade_failure_fallback() == 0)
  370. do_reset(NULL, 0, 0, NULL);
  371. return -1;
  372. }
  373. }
  374. return 0;
  375. }
  376. U_BOOT_CMD(
  377. upgrade_available, 1, 1, do_upgrade_available,
  378. "check Siemens update",
  379. "no parameters"
  380. );
  381. #endif
  382. #endif
  383. static struct atmel_serial_platdata at91sam9260_serial_plat = {
  384. .base_addr = ATMEL_BASE_DBGU,
  385. };
  386. U_BOOT_DEVICE(at91sam9260_serial) = {
  387. .name = "serial_atmel",
  388. .platdata = &at91sam9260_serial_plat,
  389. };