mergerbox.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. *
  4. * Copyright (C) 2011 Matrix Vision GmbH
  5. * Andre Schwarz <andre.schwarz@matrix-vision.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. */
  15. #include <common.h>
  16. #include <hwconfig.h>
  17. #include <i2c.h>
  18. #include <spi.h>
  19. #include <asm/io.h>
  20. #include <asm/fsl_mpc83xx_serdes.h>
  21. #include <fdt_support.h>
  22. #include <spd_sdram.h>
  23. #include "mergerbox.h"
  24. #include "fpga.h"
  25. #include "../common/mv_common.h"
  26. static void setup_serdes(void)
  27. {
  28. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  29. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  30. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
  31. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  32. }
  33. #if defined(CONFIG_SYS_DRAM_TEST)
  34. int testdram(void)
  35. {
  36. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  37. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  38. uint *p;
  39. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  40. CONFIG_SYS_MEMTEST_START, CONFIG_SYS_MEMTEST_END);
  41. printf("DRAM test phase 1:\n");
  42. for (p = pstart; p < pend; p++)
  43. *p = 0xaaaaaaaa;
  44. for (p = pstart; p < pend; p++) {
  45. if (*p != 0xaaaaaaaa) {
  46. printf("DRAM test fails at: %08x\n", (uint) p);
  47. return 1;
  48. }
  49. }
  50. printf("DRAM test phase 2:\n");
  51. for (p = pstart; p < pend; p++)
  52. *p = 0x55555555;
  53. for (p = pstart; p < pend; p++) {
  54. if (*p != 0x55555555) {
  55. printf("DRAM test fails at: %08x\n", (uint) p);
  56. return 1;
  57. }
  58. }
  59. printf("DRAM test passed.\n");
  60. return 0;
  61. }
  62. #endif
  63. phys_size_t initdram(int board_type)
  64. {
  65. u32 msize;
  66. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  67. volatile clk83xx_t *clk = (clk83xx_t *)&immr->clk;
  68. /* Enable PCI_CLK[0:1] */
  69. clk->occr |= 0xc0000000;
  70. udelay(2000);
  71. #if defined(CONFIG_SPD_EEPROM)
  72. msize = spd_sdram();
  73. #else
  74. immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  75. u32 msize_log2;
  76. msize = CONFIG_SYS_DDR_SIZE;
  77. msize_log2 = __ilog2(msize);
  78. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  79. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  80. im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
  81. udelay(50000);
  82. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
  83. udelay(1000);
  84. im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
  85. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  86. udelay(1000);
  87. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  88. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  89. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  90. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  91. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  92. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  93. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  94. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  95. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  96. __asm__ __volatile__("sync");
  97. udelay(1000);
  98. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  99. udelay(2000);
  100. #endif
  101. setup_serdes();
  102. return msize << 20;
  103. }
  104. int checkboard(void)
  105. {
  106. puts("Board: Matrix Vision MergerBox\n");
  107. return 0;
  108. }
  109. int misc_init_r(void)
  110. {
  111. u16 dim;
  112. int result;
  113. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  114. volatile gpio83xx_t *gpio = (gpio83xx_t *)&immr->gpio[1];
  115. unsigned char mac[6], mac_verify[6];
  116. char *s = getenv("reset_env");
  117. for (dim = 10; dim < 180; dim += 5) {
  118. mergerbox_tft_dim(dim);
  119. udelay(100000);
  120. }
  121. if (s)
  122. mv_reset_environment();
  123. i2c_read(SPD_EEPROM_ADDRESS, 0x80, 2, mac, sizeof(mac));
  124. /* check if Matrix Vision prefix present and export to env */
  125. if (mac[0] == 0x00 && mac[1] == 0x0c && mac[2] == 0x8d) {
  126. printf("valid MAC found in eeprom: %pM\n", mac);
  127. eth_setenv_enetaddr("ethaddr", mac);
  128. } else {
  129. printf("no valid MAC found in eeprom.\n");
  130. /* no: check the env */
  131. if (!eth_getenv_enetaddr("ethaddr", mac)) {
  132. printf("no valid MAC found in env either.\n");
  133. /* TODO: ask for valid MAC */
  134. } else {
  135. printf("valid MAC found in env: %pM\n", mac);
  136. printf("updating MAC in eeprom.\n");
  137. do {
  138. result = test_and_clear_bit(20, &gpio->dat);
  139. if (result)
  140. printf("unprotect EEPROM failed !\n");
  141. udelay(20000);
  142. } while(result);
  143. i2c_write(SPD_EEPROM_ADDRESS, 0x80, 2, mac, 6);
  144. udelay(20000);
  145. do {
  146. result = test_and_set_bit(20, &gpio->dat);
  147. if (result)
  148. printf("protect EEPROM failed !\n");
  149. udelay(20000);
  150. } while(result);
  151. printf("verify MAC %pM ... ", mac);
  152. i2c_read(SPD_EEPROM_ADDRESS, 0x80, 2, mac_verify, 6);
  153. if (!strncmp((char *)mac, (char *)mac_verify, 6))
  154. printf("ok.\n");
  155. else
  156. /* TODO: retry or do something useful */
  157. printf("FAILED (got %pM) !\n", mac_verify);
  158. }
  159. }
  160. return 0;
  161. }
  162. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  163. {
  164. return bus == 0 && cs == 0;
  165. }
  166. void spi_cs_activate(struct spi_slave *slave)
  167. {
  168. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  169. iopd->dat &= ~TFT_SPI_CPLD_CS;
  170. }
  171. void spi_cs_deactivate(struct spi_slave *slave)
  172. {
  173. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  174. iopd->dat |= TFT_SPI_CPLD_CS;
  175. }
  176. /* control backlight pwm (display brightness).
  177. * allow values 0-250 with 0 = turn off and 250 = max brightness
  178. */
  179. void mergerbox_tft_dim(u16 value)
  180. {
  181. struct spi_slave *slave;
  182. u16 din;
  183. u16 dout = 0;
  184. if (value > 0 && value < 250)
  185. dout = 0x4000 | value;
  186. slave = spi_setup_slave(0, 0, 1000000, SPI_MODE_0 | SPI_CS_HIGH);
  187. spi_claim_bus(slave);
  188. spi_xfer(slave, 16, &dout, &din, SPI_XFER_BEGIN | SPI_XFER_END);
  189. spi_release_bus(slave);
  190. spi_free_slave(slave);
  191. }
  192. void ft_board_setup(void *blob, bd_t *bd)
  193. {
  194. ft_cpu_setup(blob, bd);
  195. fdt_fixup_dr_usb(blob, bd);
  196. ft_pci_setup(blob, bd);
  197. }