cpux9k2.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. /* Enable Ctrlc */
  54. console_init_f();
  55. /* Correct IRDA resistor problem / Set PA23_TXD in Output */
  56. writel(ATMEL_PMX_AA_TXD2, &pio->pioa.oer);
  57. gd->bd->bi_arch_number = MACH_TYPE_EB_CPUX9K2;
  58. /* adress of boot parameters */
  59. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  60. #ifdef CONFIG_STATUS_LED
  61. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  62. #endif
  63. #ifdef CONFIG_CMD_NAND
  64. cpux9k2_nand_hw_init();
  65. #endif
  66. return 0;
  67. }
  68. int board_early_init_f(void)
  69. {
  70. at91_seriald_hw_init();
  71. return 0;
  72. }
  73. #ifdef CONFIG_MISC_INIT_R
  74. int misc_init_r(void)
  75. {
  76. uchar mac[8];
  77. uchar tm;
  78. uchar midx;
  79. uchar macn6, macn7;
  80. if (getenv("ethaddr") == NULL) {
  81. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x00,
  82. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  83. (uchar *) &mac, sizeof(mac)) != 0) {
  84. puts("Error reading MAC from EEPROM\n");
  85. } else {
  86. tm = 0;
  87. macn6 = 0;
  88. macn7 = 0xFF;
  89. for (midx = 0; midx < 6; midx++) {
  90. if ((mac[midx] != 0) && (mac[midx] != 0xFF))
  91. tm++;
  92. macn6 += mac[midx];
  93. macn7 ^= mac[midx];
  94. }
  95. if ((macn6 != mac[6]) || (macn7 != mac[7]))
  96. tm = 0;
  97. if (tm)
  98. eth_setenv_enetaddr("ethaddr", mac);
  99. else
  100. puts("Error: invalid MAC at EEPROM\n");
  101. }
  102. }
  103. gd->jt[XF_do_reset] = (void *) do_reset;
  104. #ifdef CONFIG_STATUS_LED
  105. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  106. #endif
  107. return 0;
  108. }
  109. #endif
  110. #ifdef CONFIG_RESET_PHY_R
  111. void reset_phy(void)
  112. {
  113. udelay(10000);
  114. eth_init(gd->bd);
  115. }
  116. #endif
  117. /*
  118. * DRAM initialisations
  119. */
  120. int dram_init(void)
  121. {
  122. gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
  123. CONFIG_SYS_SDRAM_SIZE);
  124. return 0;
  125. }
  126. /*
  127. * Ethernet initialisations
  128. */
  129. #ifdef CONFIG_DRIVER_AT91EMAC
  130. int board_eth_init(bd_t *bis)
  131. {
  132. int rc = 0;
  133. rc = at91emac_register(bis, (u32) ATMEL_BASE_EMAC);
  134. return rc;
  135. }
  136. #endif
  137. /*
  138. * Disk On Chip (NAND) Millenium initialization.
  139. * The NAND lives in the CS2* space
  140. */
  141. #if defined(CONFIG_CMD_NAND)
  142. #define MASK_ALE (1 << 22) /* our ALE is AD22 */
  143. #define MASK_CLE (1 << 21) /* our CLE is AD21 */
  144. void cpux9k2_nand_hw_init(void)
  145. {
  146. unsigned long csr;
  147. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  148. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  149. at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
  150. /* Setup Smart Media, fitst enable the address range of CS3 */
  151. writel(readl(&mc->ebi.csa) | AT91_EBI_CSA_CS3A, &mc->ebi.csa);
  152. /* RWH = 1 | RWS = 0 | TDF = 1 | NWS = 3 */
  153. csr = AT91_SMC_CSR_RWHOLD(1) | AT91_SMC_CSR_TDF(1) |
  154. AT91_SMC_CSR_NWS(3) |
  155. AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_8 |
  156. AT91_SMC_CSR_WSEN;
  157. writel(csr, &mc->smc.csr[3]);
  158. writel(ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE, &pio->pioc.asr);
  159. writel(ATMEL_PMX_CA_BFCK | ATMEL_PMX_CA_SMOE | ATMEL_PMX_CA_SMWE,
  160. &pio->pioc.pdr);
  161. /* Configure PC2 as input (signal Nand READY ) */
  162. writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.per);
  163. writel(ATMEL_PMX_CA_BFAVD, &pio->pioc.odr); /* disable output */
  164. writel(ATMEL_PMX_CA_BFCK, &pio->pioc.codr);
  165. /* PIOC clock enabling */
  166. writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
  167. }
  168. static void board_nand_hwcontrol(struct mtd_info *mtd,
  169. int cmd, unsigned int ctrl)
  170. {
  171. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  172. struct nand_chip *this = mtd->priv;
  173. ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
  174. if (ctrl & NAND_CTRL_CHANGE) {
  175. IO_ADDR_W &= ~(MASK_ALE | MASK_CLE);
  176. if (ctrl & NAND_CLE)
  177. IO_ADDR_W |= MASK_CLE;
  178. if (ctrl & NAND_ALE)
  179. IO_ADDR_W |= MASK_ALE;
  180. if ((ctrl & NAND_NCE))
  181. writel(1, &pio->pioc.codr);
  182. else
  183. writel(1, &pio->pioc.sodr);
  184. this->IO_ADDR_W = (void *) IO_ADDR_W;
  185. }
  186. if (cmd != NAND_CMD_NONE)
  187. writeb(cmd, this->IO_ADDR_W);
  188. }
  189. static int board_nand_dev_ready(struct mtd_info *mtd)
  190. {
  191. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  192. return ((readl(&pio->pioc.pdsr) & (1 << 2)) != 0);
  193. }
  194. int board_nand_init(struct nand_chip *nand)
  195. {
  196. cpux9k2_nand_hw_init();
  197. nand->ecc.mode = NAND_ECC_SOFT;
  198. nand->cmd_ctrl = board_nand_hwcontrol;
  199. nand->dev_ready = board_nand_dev_ready;
  200. nand->chip_delay = 20;
  201. return 0;
  202. }
  203. #endif
  204. #if defined(CONFIG_VIDEO)
  205. /*
  206. * drv_video_init
  207. * FUNCTION: initialize VCxK device
  208. */
  209. int drv_video_init(void)
  210. {
  211. #ifdef CONFIG_SPLASH_SCREEN
  212. unsigned long splash;
  213. #endif
  214. char *s;
  215. unsigned long csr;
  216. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  217. at91_mc_t *mc = (at91_mc_t *) ATMEL_BASE_MC;
  218. printf("Init Video as ");
  219. s = getenv("displaywidth");
  220. if (s != NULL)
  221. display_width = simple_strtoul(s, NULL, 10);
  222. else
  223. display_width = 256;
  224. s = getenv("displayheight");
  225. if (s != NULL)
  226. display_height = simple_strtoul(s, NULL, 10);
  227. else
  228. display_height = 256;
  229. printf("%ld x %ld pixel matrix\n", display_width, display_height);
  230. /* RWH = 7 | RWS =7 | TDF = 15 | NWS = 0x7F */
  231. csr = AT91_SMC_CSR_RWHOLD(7) | AT91_SMC_CSR_RWSETUP(7) |
  232. AT91_SMC_CSR_TDF(15) | AT91_SMC_CSR_NWS(127) |
  233. AT91_SMC_CSR_ACSS_STANDARD | AT91_SMC_CSR_DBW_16 |
  234. AT91_SMC_CSR_BAT_16 | AT91_SMC_CSR_WSEN;
  235. writel(csr, &mc->smc.csr[2]);
  236. writel(1 << ATMEL_ID_PIOB, &pmc->pcer);
  237. vcxk_init(display_width, display_height);
  238. #ifdef CONFIG_SPLASH_SCREEN
  239. s = getenv("splashimage");
  240. if (s != NULL) {
  241. splash = simple_strtoul(s, NULL, 16);
  242. printf("use splashimage: %lx\n", splash);
  243. video_display_bitmap(splash, 0, 0);
  244. }
  245. #endif
  246. return 0;
  247. }
  248. #endif
  249. #ifdef CONFIG_SOFT_I2C
  250. void i2c_init_board(void)
  251. {
  252. u32 pin;
  253. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  254. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  255. writel(1 << ATMEL_ID_PIOA, &pmc->pcer);
  256. pin = ATMEL_PMX_AA_TWD | ATMEL_PMX_AA_TWCK;
  257. writel(pin, &pio->pioa.idr);
  258. writel(pin, &pio->pioa.pudr);
  259. writel(pin, &pio->pioa.per);
  260. writel(pin, &pio->pioa.oer);
  261. writel(pin, &pio->pioa.sodr);
  262. }
  263. #endif
  264. /*--------------------------------------------------------------------------*/
  265. #ifdef CONFIG_STATUS_LED
  266. void __led_toggle(led_id_t mask)
  267. {
  268. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  269. if (readl(&pio->piod.odsr) & mask)
  270. writel(mask, &pio->piod.codr);
  271. else
  272. writel(mask, &pio->piod.codr);
  273. }
  274. void __led_init(led_id_t mask, int state)
  275. {
  276. at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
  277. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  278. writel(1 << ATMEL_ID_PIOD, &pmc->pcer); /* Enable PIOB clock */
  279. /* Disable peripherals on LEDs */
  280. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.per);
  281. /* Enable pins as outputs */
  282. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.oer);
  283. /* Turn all LEDs OFF */
  284. writel(STATUS_LED_BIT | STATUS_LED_BIT1, &pio->piod.sodr);
  285. __led_set(mask, state);
  286. }
  287. void __led_set(led_id_t mask, int state)
  288. {
  289. at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
  290. if (state == STATUS_LED_ON)
  291. writel(mask, &pio->piod.codr);
  292. else
  293. writel(mask, &pio->piod.sodr);
  294. }
  295. #endif
  296. /*---------------------------------------------------------------------------*/
  297. int do_brightness(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  298. {
  299. int rcode = 0;
  300. ulong side;
  301. ulong bright;
  302. switch (argc) {
  303. case 3:
  304. side = simple_strtoul(argv[1], NULL, 10);
  305. bright = simple_strtoul(argv[2], NULL, 10);
  306. if ((side >= 0) && (side <= 3) &&
  307. (bright >= 0) && (bright <= 1000)) {
  308. vcxk_setbrightness(side, bright);
  309. rcode = 0;
  310. } else {
  311. printf("parameters out of range\n");
  312. printf("Usage:\n%s\n", cmdtp->usage);
  313. rcode = 1;
  314. }
  315. break;
  316. default:
  317. printf("Usage:\n%s\n", cmdtp->usage);
  318. rcode = 1;
  319. break;
  320. }
  321. return rcode;
  322. }
  323. /*---------------------------------------------------------------------------*/
  324. U_BOOT_CMD(
  325. bright, 3, 0, do_brightness,
  326. "bright - sets the display brightness\n",
  327. " <side> <0..1000>\n side: 0/3=both; 1=first; 2=second\n"
  328. );
  329. /* EOF cpu9k2.c */