top9000.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian.pop@leadtechdesign.com>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * (C) Copyright 2010
  7. * Reinhard Meyer, EMK Elektronik, reinhard.meyer@emk-elektronik.de
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <net.h>
  29. #include <netdev.h>
  30. #include <mmc.h>
  31. #include <i2c.h>
  32. #include <spi.h>
  33. #include <asm/io.h>
  34. #include <asm/arch/hardware.h>
  35. #include <asm/arch/at91sam9260_matrix.h>
  36. #include <asm/arch/at91sam9_smc.h>
  37. #include <asm/arch/at91_common.h>
  38. #include <asm/arch/at91_pmc.h>
  39. #include <asm/arch/at91_rstc.h>
  40. #include <asm/arch/at91_shdwn.h>
  41. #include <asm/arch/gpio.h>
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #ifdef CONFIG_CMD_NAND
  44. static void nand_hw_init(void)
  45. {
  46. struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
  47. struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
  48. unsigned long csa;
  49. /* Assign CS3 to NAND/SmartMedia Interface */
  50. csa = readl(&matrix->ebicsa);
  51. csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
  52. writel(csa, &matrix->ebicsa);
  53. /* Configure SMC CS3 for NAND/SmartMedia */
  54. writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
  55. AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
  56. &smc->cs[3].setup);
  57. writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
  58. AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
  59. &smc->cs[3].pulse);
  60. writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
  61. &smc->cs[3].cycle);
  62. writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
  63. AT91_SMC_MODE_EXNW_DISABLE |
  64. AT91_SMC_MODE_DBW_8 |
  65. AT91_SMC_MODE_TDF_CYCLE(2),
  66. &smc->cs[3].mode);
  67. /* Configure RDY/BSY */
  68. at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
  69. /* Enable NandFlash */
  70. at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
  71. }
  72. #endif
  73. #ifdef CONFIG_MACB
  74. static void macb_hw_init(void)
  75. {
  76. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  77. /* Enable EMAC clock */
  78. writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
  79. /* Initialize EMAC=MACB hardware */
  80. at91_macb_hw_init();
  81. }
  82. #endif
  83. #ifdef CONFIG_GENERIC_ATMEL_MCI
  84. /* this is a weak define that we are overriding */
  85. int board_mmc_init(bd_t *bd)
  86. {
  87. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  88. /* Enable MCI clock */
  89. writel(1 << ATMEL_ID_MCI, &pmc->pcer);
  90. /* Initialize MCI hardware */
  91. at91_mci_hw_init();
  92. /* This calls the atmel_mmc_init in gen_atmel_mci.c */
  93. return atmel_mci_init((void *)ATMEL_BASE_MCI);
  94. }
  95. /* this is a weak define that we are overriding */
  96. int board_mmc_getcd(u8 *cd, struct mmc *mmc)
  97. {
  98. /*
  99. * the only currently existing use of this function
  100. * (fsl_esdhc.c) suggests this function must return
  101. * *cs = TRUE if a card is NOT detected -> in most
  102. * cases the value of the pin when the detect switch
  103. * closes to GND
  104. */
  105. *cd = at91_get_gpio_value(CONFIG_SYS_MMC_CD_PIN) ? 1 : 0;
  106. return 0;
  107. }
  108. #endif
  109. int board_early_init_f(void)
  110. {
  111. struct at91_shdwn *shdwn = (struct at91_shdwn *)ATMEL_BASE_SHDWN;
  112. struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
  113. /*
  114. * make sure the board can be powered on by
  115. * any transition on WKUP
  116. */
  117. writel(AT91_SHDW_MR_WKMODE0H2L | AT91_SHDW_MR_WKMODE0L2H,
  118. &shdwn->mr);
  119. /* Enable clocks for all PIOs */
  120. writel((1 << ATMEL_ID_PIOA) | (1 << ATMEL_ID_PIOB) |
  121. (1 << ATMEL_ID_PIOC),
  122. &pmc->pcer);
  123. /* set SCL0 and SDA0 to open drain */
  124. at91_set_pio_output(I2C0_PORT, SCL0_PIN, 1);
  125. at91_set_pio_multi_drive(I2C0_PORT, SCL0_PIN, 1);
  126. at91_set_pio_pullup(I2C0_PORT, SCL0_PIN, 1);
  127. at91_set_pio_output(I2C0_PORT, SDA0_PIN, 1);
  128. at91_set_pio_multi_drive(I2C0_PORT, SDA0_PIN, 1);
  129. at91_set_pio_pullup(I2C0_PORT, SDA0_PIN, 1);
  130. /* set SCL1 and SDA1 to open drain */
  131. at91_set_pio_output(I2C1_PORT, SCL1_PIN, 1);
  132. at91_set_pio_multi_drive(I2C1_PORT, SCL1_PIN, 1);
  133. at91_set_pio_pullup(I2C1_PORT, SCL1_PIN, 1);
  134. at91_set_pio_output(I2C1_PORT, SDA1_PIN, 1);
  135. at91_set_pio_multi_drive(I2C1_PORT, SDA1_PIN, 1);
  136. at91_set_pio_pullup(I2C1_PORT, SDA1_PIN, 1);
  137. return 0;
  138. }
  139. int board_init(void)
  140. {
  141. /* arch number of TOP9000 Board */
  142. gd->bd->bi_arch_number = MACH_TYPE_TOP9000;
  143. /* adress of boot parameters */
  144. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  145. at91_seriald_hw_init();
  146. #ifdef CONFIG_CMD_NAND
  147. nand_hw_init();
  148. #endif
  149. #ifdef CONFIG_MACB
  150. macb_hw_init();
  151. #endif
  152. #ifdef CONFIG_ATMEL_SPI0
  153. /* (n+4) denotes to use nSPISEL(0) in GPIO mode! */
  154. at91_spi0_hw_init(1 << (FRAM_CS_NUM + 4));
  155. #endif
  156. #ifdef CONFIG_ATMEL_SPI1
  157. at91_spi1_hw_init(1 << (ENC_CS_NUM + 4));
  158. #endif
  159. return 0;
  160. }
  161. #ifdef CONFIG_MISC_INIT_R
  162. int misc_init_r(void)
  163. {
  164. /* read 'factory' part of EEPROM */
  165. read_factory_r();
  166. return 0;
  167. }
  168. #endif
  169. int dram_init(void)
  170. {
  171. gd->ram_size = get_ram_size(
  172. (void *)CONFIG_SYS_SDRAM_BASE,
  173. CONFIG_SYS_SDRAM_SIZE);
  174. return 0;
  175. }
  176. #ifdef CONFIG_RESET_PHY_R
  177. void reset_phy(void)
  178. {
  179. /*
  180. * Initialize ethernet HW addresses prior to starting Linux,
  181. * needed for nfsroot.
  182. * TODO: We need to investigate if that is really necessary.
  183. */
  184. eth_init(gd->bd);
  185. }
  186. #endif
  187. int board_eth_init(bd_t *bis)
  188. {
  189. int rc = 0;
  190. int num = 0;
  191. #ifdef CONFIG_MACB
  192. rc = macb_eth_initialize(0,
  193. (void *)ATMEL_BASE_EMAC0,
  194. CONFIG_SYS_PHY_ID);
  195. if (!rc)
  196. num++;
  197. #endif
  198. #ifdef CONFIG_ENC28J60
  199. rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM,
  200. ENC_SPI_CLOCK, SPI_MODE_0);
  201. if (!rc)
  202. num++;
  203. # ifdef CONFIG_ENC28J60_2
  204. rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+1,
  205. ENC_SPI_CLOCK, SPI_MODE_0);
  206. if (!rc)
  207. num++;
  208. # ifdef CONFIG_ENC28J60_3
  209. rc = enc28j60_initialize(ENC_SPI_BUS, ENC_CS_NUM+2,
  210. ENC_SPI_CLOCK, SPI_MODE_0);
  211. if (!rc)
  212. num++;
  213. # endif
  214. # endif
  215. #endif
  216. return num;
  217. }
  218. /*
  219. * I2C access functions
  220. *
  221. * Note:
  222. * We need to access Bus 0 before relocation to access the
  223. * environment settings.
  224. * However i2c_get_bus_num() cannot be called before
  225. * relocation.
  226. */
  227. #ifdef CONFIG_SOFT_I2C
  228. void iic_init(void)
  229. {
  230. /* ports are now initialized in board_early_init_f() */
  231. }
  232. int iic_read(void)
  233. {
  234. switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
  235. case 0:
  236. return at91_get_pio_value(I2C0_PORT, SDA0_PIN);
  237. case 1:
  238. return at91_get_pio_value(I2C1_PORT, SDA1_PIN);
  239. }
  240. return 1;
  241. }
  242. void iic_sda(int bit)
  243. {
  244. switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
  245. case 0:
  246. at91_set_pio_value(I2C0_PORT, SDA0_PIN, bit);
  247. break;
  248. case 1:
  249. at91_set_pio_value(I2C1_PORT, SDA1_PIN, bit);
  250. break;
  251. }
  252. }
  253. void iic_scl(int bit)
  254. {
  255. switch ((gd->flags & GD_FLG_RELOC) ? i2c_get_bus_num() : 0) {
  256. case 0:
  257. at91_set_pio_value(I2C0_PORT, SCL0_PIN, bit);
  258. break;
  259. case 1:
  260. at91_set_pio_value(I2C1_PORT, SCL1_PIN, bit);
  261. break;
  262. }
  263. }
  264. #endif