cpux9k2.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * (C) Copyright 2008-2009
  3. * BuS Elektronik GmbH & Co. KG <www.bus-elektronik.de>
  4. * Jens Scharsig <esw@bus-elektronik.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <exports.h>
  26. #include <net.h>
  27. #include <netdev.h>
  28. #include <nand.h>
  29. #include <asm/io.h>
  30. #include <asm/arch/hardware.h>
  31. #include <asm/arch/at91_pio.h>
  32. #include <asm/arch/at91_pmc.h>
  33. #include <asm/arch/at91_mc.h>
  34. #include <asm/arch/at91_common.h>
  35. #ifdef CONFIG_STATUS_LED
  36. #include <status_led.h>
  37. #endif
  38. #ifdef CONFIG_VIDEO
  39. #include <bus_vcxk.h>
  40. extern unsigned long display_width;
  41. extern unsigned long display_height;
  42. #endif
  43. #ifdef CONFIG_CMD_NAND
  44. void cpux9k2_nand_hw_init(void);
  45. #endif
  46. DECLARE_GLOBAL_DATA_PTR;
  47. /*
  48. * Miscelaneous platform dependent initialisations
  49. */
  50. int board_init(void)
  51. {
  52. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  53. /* Correct IRDA resistor problem / Set PA23_TXD in Output */
  54. writel(ATMEL_PMX_AA_TXD2, &pio->pioa.oer);
  55. gd->bd->bi_arch_number = MACH_TYPE_EB_CPUX9K2;
  56. /* adress of boot parameters */
  57. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  58. #ifdef CONFIG_STATUS_LED
  59. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  60. #endif
  61. #ifdef CONFIG_CMD_NAND
  62. cpux9k2_nand_hw_init();
  63. #endif
  64. return 0;
  65. }
  66. int board_early_init_f(void)
  67. {
  68. at91_seriald_hw_init();
  69. return 0;
  70. }
  71. #ifdef CONFIG_MISC_INIT_R
  72. int misc_init_r(void)
  73. {
  74. uchar mac[8];
  75. uchar tm;
  76. uchar midx;
  77. uchar macn6, macn7;
  78. if (getenv("ethaddr") == NULL) {
  79. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x00,
  80. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  81. (uchar *) &mac, sizeof(mac)) != 0) {
  82. puts("Error reading MAC from EEPROM\n");
  83. } else {
  84. tm = 0;
  85. macn6 = 0;
  86. macn7 = 0xFF;
  87. for (midx = 0; midx < 6; midx++) {
  88. if ((mac[midx] != 0) && (mac[midx] != 0xFF))
  89. tm++;
  90. macn6 += mac[midx];
  91. macn7 ^= mac[midx];
  92. }
  93. if ((macn6 != mac[6]) || (macn7 != mac[7]))
  94. tm = 0;
  95. if (tm)
  96. eth_setenv_enetaddr("ethaddr", mac);
  97. else
  98. puts("Error: invalid MAC at EEPROM\n");
  99. }
  100. }
  101. gd->jt[XF_do_reset] = (void *) do_reset;
  102. #ifdef CONFIG_STATUS_LED
  103. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  104. #endif
  105. return 0;
  106. }
  107. #endif
  108. #ifdef CONFIG_RESET_PHY_R
  109. void reset_phy(void)
  110. {
  111. udelay(10000);
  112. eth_init(gd->bd);
  113. }
  114. #endif
  115. /*
  116. * DRAM initialisations
  117. */
  118. int dram_init(void)
  119. {
  120. gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
  121. CONFIG_SYS_SDRAM_SIZE);
  122. return 0;
  123. }
  124. /*
  125. * Ethernet initialisations
  126. */
  127. #ifdef CONFIG_DRIVER_AT91EMAC
  128. int board_eth_init(bd_t *bis)
  129. {
  130. int rc = 0;
  131. rc = at91emac_register(bis, (u32) ATMEL_BASE_EMAC);
  132. return rc;
  133. }
  134. #endif
  135. /*
  136. * Disk On Chip (NAND) Millenium initialization.
  137. * The NAND lives in the CS2* space
  138. */
  139. #if defined(CONFIG_CMD_NAND)
  140. #define MASK_ALE (1 << 22) /* our ALE is AD22 */
  141. #define MASK_CLE (1 << 21) /* our CLE is AD21 */
  142. void cpux9k2_nand_hw_init(void)
  143. {
  144. unsigned long csr;
  145. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  146. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  147. at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
  148. /* Setup Smart Media, fitst enable the address range of CS3 */
  149. writel(readl(&mc->ebi.csa) | AT91_EBI_CSA_CS3A, &mc->ebi.csa);
  150. /* RWH = 1 | RWS = 0 | TDF = 1 | NWS = 3 */
  151. csr = AT91_SMC_CSR_RWHOLD(1) | AT91_SMC_CSR_TDF(1) |
  152. AT91_SMC_CSR_NWS(3) |
  153. AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_8 |
  154. AT91_SMC_CSR_WSEN;
  155. writel(csr, &mc->smc.csr[3]);
  156. writel(ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE, &pio->pioc.asr);
  157. writel(ATMEL_PMX_CA_BFCK | ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE,
  158. &pio->pioc.pdr);
  159. /* Configure PC2 as input (signal Nand READY ) */
  160. writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.per);
  161. writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.odr); /* disable output */
  162. writel(ATMEL_PMX_CA_BFCK, &pio->pioc.codr);
  163. /* PIOC clock enabling */
  164. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  165. }
  166. static void board_nand_hwcontrol(struct mtd_info *mtd,
  167. int cmd, unsigned int ctrl)
  168. {
  169. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  170. struct nand_chip *this = mtd->priv;
  171. ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
  172. if (ctrl & NAND_CTRL_CHANGE) {
  173. IO_ADDR_W &= ~(MASK_ALE | MASK_CLE);
  174. if (ctrl & NAND_CLE)
  175. IO_ADDR_W |= MASK_CLE;
  176. if (ctrl & NAND_ALE)
  177. IO_ADDR_W |= MASK_ALE;
  178. if ((ctrl & NAND_NCE))
  179. writel(1, &pio->pioc.codr);
  180. else
  181. writel(1, &pio->pioc.sodr);
  182. this->IO_ADDR_W = (void *) IO_ADDR_W;
  183. }
  184. if (cmd != NAND_CMD_NONE)
  185. writeb(cmd, this->IO_ADDR_W);
  186. }
  187. static int board_nand_dev_ready(struct mtd_info *mtd)
  188. {
  189. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  190. return ((readl(&pio->pioc.pdsr) & (1 << 2)) != 0);
  191. }
  192. int board_nand_init(struct nand_chip *nand)
  193. {
  194. cpux9k2_nand_hw_init();
  195. nand->ecc.mode = NAND_ECC_SOFT;
  196. nand->cmd_ctrl = board_nand_hwcontrol;
  197. nand->dev_ready = board_nand_dev_ready;
  198. nand->chip_delay = 20;
  199. return 0;
  200. }
  201. #endif
  202. #if defined(CONFIG_VIDEO)
  203. /*
  204. * drv_video_init
  205. * FUNCTION: initialize VCxK device
  206. */
  207. int drv_video_init(void)
  208. {
  209. #ifdef CONFIG_SPLASH_SCREEN
  210. unsigned long splash;
  211. #endif
  212. char *s;
  213. unsigned long csr;
  214. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  215. at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
  216. printf("Init Video as ");
  217. s = getenv("displaywidth");
  218. if (s != NULL)
  219. display_width = simple_strtoul(s, NULL, 10);
  220. else
  221. display_width = 256;
  222. s = getenv("displayheight");
  223. if (s != NULL)
  224. display_height = simple_strtoul(s, NULL, 10);
  225. else
  226. display_height = 256;
  227. printf("%ld x %ld pixel matrix\n", display_width, display_height);
  228. /* RWH = 2 | RWS =2 | TDF = 4 | NWS = 0x6 */
  229. csr = AT91_SMC_CSR_RWHOLD(2) | AT91_SMC_CSR_RWSETUP(2) |
  230. AT91_SMC_CSR_TDF(4) | AT91_SMC_CSR_NWS(6) |
  231. AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_16 |
  232. AT91_SMC_CSR_BAT_16 | AT91_SMC_CSR_WSEN;
  233. writel(csr, &mc->smc.csr[2]);
  234. writel(1 << ATMEL_ID_PIOB, &pmc->pcer);
  235. vcxk_init(display_width, display_height);
  236. #ifdef CONFIG_SPLASH_SCREEN
  237. s = getenv("splashimage");
  238. if (s != NULL) {
  239. splash = simple_strtoul(s, NULL, 16);
  240. printf("use splashimage: %lx\n", splash);
  241. video_display_bitmap(splash, 0, 0);
  242. }
  243. #endif
  244. return 0;
  245. }
  246. #endif
  247. #ifdef CONFIG_SOFT_I2C
  248. void i2c_init_board(void)
  249. {
  250. u32 pin;
  251. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  252. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  253. writel(1 << ATMEL_ID_PIOA, &pmc->pcer);
  254. pin = ATMEL_PMX_AA_TWD | ATMEL_PMX_AA_TWCK;
  255. writel(pin, &pio->pioa.idr);
  256. writel(pin, &pio->pioa.pudr);
  257. writel(pin, &pio->pioa.per);
  258. writel(pin, &pio->pioa.oer);
  259. writel(pin, &pio->pioa.sodr);
  260. }
  261. #endif
  262. /*--------------------------------------------------------------------------*/
  263. #ifdef CONFIG_STATUS_LED
  264. void __led_toggle(led_id_t mask)
  265. {
  266. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  267. if (readl(&pio->piod.odsr) & mask)
  268. writel(mask, &pio->piod.codr);
  269. else
  270. writel(mask, &pio->piod.codr);
  271. }
  272. void __led_init(led_id_t mask, int state)
  273. {
  274. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  275. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  276. writel(1 << ATMEL_ID_PIOD, &pmc->pcer); /* Enable PIOB clock */
  277. /* Disable peripherals on LEDs */
  278. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.per);
  279. /* Enable pins as outputs */
  280. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.oer);
  281. /* Turn all LEDs OFF */
  282. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.sodr);
  283. __led_set(mask, state);
  284. }
  285. void __led_set(led_id_t mask, int state)
  286. {
  287. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  288. if (state == STATUS_LED_ON)
  289. writel(mask, &pio->piod.codr);
  290. else
  291. writel(mask, &pio->piod.sodr);
  292. }
  293. #endif
  294. /*---------------------------------------------------------------------------*/
  295. int do_brightness(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  296. {
  297. int rcode = 0;
  298. ulong side;
  299. ulong bright;
  300. switch (argc) {
  301. case 3:
  302. side = simple_strtoul(argv[1], NULL, 10);
  303. bright = simple_strtoul(argv[2], NULL, 10);
  304. if ((side >= 0) && (side <= 3) &&
  305. (bright >= 0) && (bright <= 1000)) {
  306. vcxk_setbrightness(side, bright);
  307. rcode = 0;
  308. } else {
  309. printf("parameters out of range\n");
  310. printf("Usage:\n%s\n", cmdtp->usage);
  311. rcode = 1;
  312. }
  313. break;
  314. default:
  315. printf("Usage:\n%s\n", cmdtp->usage);
  316. rcode = 1;
  317. break;
  318. }
  319. return rcode;
  320. }
  321. /*---------------------------------------------------------------------------*/
  322. U_BOOT_CMD(
  323. bright, 3, 0, do_brightness,
  324. "bright - sets the display brightness\n",
  325. " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n"
  326. );
  327. /* EOF cpu9k2.c */