cpux9k2.c 9.0 KB

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