spr_misc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * (C) Copyright 2009
  3. * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <i2c.h>
  26. #include <net.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/hardware.h>
  29. #include <asm/arch/spr_emi.h>
  30. #include <asm/arch/spr_defs.h>
  31. #define CPU 0
  32. #define DDR 1
  33. #define SRAM_REL 0xD2801000
  34. DECLARE_GLOBAL_DATA_PTR;
  35. int dram_init(void)
  36. {
  37. /* Store complete RAM size and return */
  38. gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
  39. return 0;
  40. }
  41. void dram_init_banksize(void)
  42. {
  43. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  44. gd->bd->bi_dram[0].size = gd->ram_size;
  45. }
  46. int misc_init_r(void)
  47. {
  48. #if defined(CONFIG_CMD_NET)
  49. uchar mac_id[6];
  50. if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
  51. eth_setenv_enetaddr("ethaddr", mac_id);
  52. #endif
  53. setenv("verify", "n");
  54. #if defined(CONFIG_SPEAR_USBTTY)
  55. setenv("stdin", "usbtty");
  56. setenv("stdout", "usbtty");
  57. setenv("stderr", "usbtty");
  58. #endif
  59. return 0;
  60. }
  61. #ifdef CONFIG_SPEAR_EMI
  62. struct cust_emi_para {
  63. unsigned int tap;
  64. unsigned int tsdp;
  65. unsigned int tdpw;
  66. unsigned int tdpr;
  67. unsigned int tdcs;
  68. };
  69. /* EMI timing setting of m28w640hc of linux kernel */
  70. const struct cust_emi_para emi_timing_m28w640hc = {
  71. .tap = 0x10,
  72. .tsdp = 0x05,
  73. .tdpw = 0x0a,
  74. .tdpr = 0x0a,
  75. .tdcs = 0x05,
  76. };
  77. /* EMI timing setting of bootrom */
  78. const struct cust_emi_para emi_timing_bootrom = {
  79. .tap = 0xf,
  80. .tsdp = 0x0,
  81. .tdpw = 0xff,
  82. .tdpr = 0x111,
  83. .tdcs = 0x02,
  84. };
  85. void spear_emi_init(void)
  86. {
  87. const struct cust_emi_para *p = &emi_timing_m28w640hc;
  88. struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
  89. unsigned int cs;
  90. unsigned int val, tmp;
  91. val = readl(CONFIG_SPEAR_RASBASE);
  92. if (val & EMI_ACKMSK)
  93. tmp = 0x3f;
  94. else
  95. tmp = 0x0;
  96. writel(tmp, &emi_regs_p->ack);
  97. for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
  98. writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
  99. writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
  100. writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
  101. writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
  102. writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
  103. writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
  104. &emi_regs_p->bank_regs[cs].control);
  105. }
  106. }
  107. #endif
  108. int spear_board_init(ulong mach_type)
  109. {
  110. gd->bd->bi_arch_number = mach_type;
  111. /* adress of boot parameters */
  112. gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
  113. #ifdef CONFIG_SPEAR_EMI
  114. spear_emi_init();
  115. #endif
  116. return 0;
  117. }
  118. static int i2c_read_mac(uchar *buffer)
  119. {
  120. u8 buf[2];
  121. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  122. /* Check if mac in i2c memory is valid */
  123. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  124. /* Valid mac address is saved in i2c eeprom */
  125. i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
  126. return 0;
  127. }
  128. return -1;
  129. }
  130. static int write_mac(uchar *mac)
  131. {
  132. u8 buf[2];
  133. buf[0] = (u8)MAGIC_BYTE0;
  134. buf[1] = (u8)MAGIC_BYTE1;
  135. i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  136. buf[0] = (u8)~MAGIC_BYTE0;
  137. buf[1] = (u8)~MAGIC_BYTE1;
  138. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  139. /* check if valid MAC address is saved in I2C EEPROM or not? */
  140. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  141. i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
  142. puts("I2C EEPROM written with mac address \n");
  143. return 0;
  144. }
  145. puts("I2C EEPROM writing failed \n");
  146. return -1;
  147. }
  148. int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  149. {
  150. void (*sram_setfreq) (unsigned int, unsigned int);
  151. unsigned char mac[6];
  152. unsigned int reg, frequency;
  153. char *s, *e;
  154. char i2c_mac[20];
  155. if ((argc > 3) || (argc < 2))
  156. return cmd_usage(cmdtp);
  157. if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
  158. frequency = simple_strtoul(argv[2], NULL, 0);
  159. if (frequency > 333) {
  160. printf("Frequency is limited to 333MHz\n");
  161. return 1;
  162. }
  163. sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
  164. if (!strcmp(argv[1], "cpufreq")) {
  165. sram_setfreq(CPU, frequency);
  166. printf("CPU frequency changed to %u\n", frequency);
  167. } else {
  168. sram_setfreq(DDR, frequency);
  169. printf("DDR frequency changed to %u\n", frequency);
  170. }
  171. return 0;
  172. } else if (!strcmp(argv[1], "ethaddr")) {
  173. s = argv[2];
  174. for (reg = 0; reg < 6; ++reg) {
  175. mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
  176. if (s)
  177. s = (*e) ? e + 1 : e;
  178. }
  179. write_mac(mac);
  180. return 0;
  181. } else if (!strcmp(argv[1], "print")) {
  182. if (!i2c_read_mac(mac)) {
  183. sprintf(i2c_mac, "%pM", mac);
  184. printf("Ethaddr (from i2c mem) = %s\n", i2c_mac);
  185. } else {
  186. printf("Ethaddr (from i2c mem) = Not set\n");
  187. }
  188. return 0;
  189. }
  190. return cmd_usage(cmdtp);
  191. }
  192. U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
  193. "configure chip",
  194. "chip_config cpufreq/ddrfreq frequency\n"
  195. "chip_config print");