spr_misc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 <linux/mtd/st_smi.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/hardware.h>
  30. #include <asm/arch/spr_emi.h>
  31. #include <asm/arch/spr_defs.h>
  32. #define CPU 0
  33. #define DDR 1
  34. #define SRAM_REL 0xD2801000
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #if defined(CONFIG_CMD_NET)
  37. static int i2c_read_mac(uchar *buffer);
  38. #endif
  39. int dram_init(void)
  40. {
  41. /* Store complete RAM size and return */
  42. gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
  43. return 0;
  44. }
  45. void dram_init_banksize(void)
  46. {
  47. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  48. gd->bd->bi_dram[0].size = gd->ram_size;
  49. }
  50. int board_early_init_f()
  51. {
  52. #if defined(CONFIG_ST_SMI)
  53. smi_init();
  54. #endif
  55. return 0;
  56. }
  57. int misc_init_r(void)
  58. {
  59. #if defined(CONFIG_CMD_NET)
  60. uchar mac_id[6];
  61. if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
  62. eth_setenv_enetaddr("ethaddr", mac_id);
  63. #endif
  64. setenv("verify", "n");
  65. #if defined(CONFIG_SPEAR_USBTTY)
  66. setenv("stdin", "usbtty");
  67. setenv("stdout", "usbtty");
  68. setenv("stderr", "usbtty");
  69. #ifndef CONFIG_SYS_NO_DCACHE
  70. dcache_enable();
  71. #endif
  72. #endif
  73. return 0;
  74. }
  75. #ifdef CONFIG_SPEAR_EMI
  76. struct cust_emi_para {
  77. unsigned int tap;
  78. unsigned int tsdp;
  79. unsigned int tdpw;
  80. unsigned int tdpr;
  81. unsigned int tdcs;
  82. };
  83. /* EMI timing setting of m28w640hc of linux kernel */
  84. const struct cust_emi_para emi_timing_m28w640hc = {
  85. .tap = 0x10,
  86. .tsdp = 0x05,
  87. .tdpw = 0x0a,
  88. .tdpr = 0x0a,
  89. .tdcs = 0x05,
  90. };
  91. /* EMI timing setting of bootrom */
  92. const struct cust_emi_para emi_timing_bootrom = {
  93. .tap = 0xf,
  94. .tsdp = 0x0,
  95. .tdpw = 0xff,
  96. .tdpr = 0x111,
  97. .tdcs = 0x02,
  98. };
  99. void spear_emi_init(void)
  100. {
  101. const struct cust_emi_para *p = &emi_timing_m28w640hc;
  102. struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
  103. unsigned int cs;
  104. unsigned int val, tmp;
  105. val = readl(CONFIG_SPEAR_RASBASE);
  106. if (val & EMI_ACKMSK)
  107. tmp = 0x3f;
  108. else
  109. tmp = 0x0;
  110. writel(tmp, &emi_regs_p->ack);
  111. for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
  112. writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
  113. writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
  114. writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
  115. writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
  116. writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
  117. writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
  118. &emi_regs_p->bank_regs[cs].control);
  119. }
  120. }
  121. #endif
  122. int spear_board_init(ulong mach_type)
  123. {
  124. gd->bd->bi_arch_number = mach_type;
  125. /* adress of boot parameters */
  126. gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
  127. #ifdef CONFIG_SPEAR_EMI
  128. spear_emi_init();
  129. #endif
  130. return 0;
  131. }
  132. #if defined(CONFIG_CMD_NET)
  133. static int i2c_read_mac(uchar *buffer)
  134. {
  135. u8 buf[2];
  136. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  137. /* Check if mac in i2c memory is valid */
  138. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  139. /* Valid mac address is saved in i2c eeprom */
  140. i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
  141. return 0;
  142. }
  143. return -1;
  144. }
  145. static int write_mac(uchar *mac)
  146. {
  147. u8 buf[2];
  148. buf[0] = (u8)MAGIC_BYTE0;
  149. buf[1] = (u8)MAGIC_BYTE1;
  150. i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  151. buf[0] = (u8)~MAGIC_BYTE0;
  152. buf[1] = (u8)~MAGIC_BYTE1;
  153. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  154. /* check if valid MAC address is saved in I2C EEPROM or not? */
  155. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  156. i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
  157. puts("I2C EEPROM written with mac address \n");
  158. return 0;
  159. }
  160. puts("I2C EEPROM writing failed\n");
  161. return -1;
  162. }
  163. #endif
  164. int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  165. {
  166. void (*sram_setfreq) (unsigned int, unsigned int);
  167. unsigned int frequency;
  168. #if defined(CONFIG_CMD_NET)
  169. unsigned char mac[6];
  170. #endif
  171. if ((argc > 3) || (argc < 2))
  172. return cmd_usage(cmdtp);
  173. if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
  174. frequency = simple_strtoul(argv[2], NULL, 0);
  175. if (frequency > 333) {
  176. printf("Frequency is limited to 333MHz\n");
  177. return 1;
  178. }
  179. sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
  180. if (!strcmp(argv[1], "cpufreq")) {
  181. sram_setfreq(CPU, frequency);
  182. printf("CPU frequency changed to %u\n", frequency);
  183. } else {
  184. sram_setfreq(DDR, frequency);
  185. printf("DDR frequency changed to %u\n", frequency);
  186. }
  187. return 0;
  188. #if defined(CONFIG_CMD_NET)
  189. } else if (!strcmp(argv[1], "ethaddr")) {
  190. u32 reg;
  191. char *e, *s = argv[2];
  192. for (reg = 0; reg < 6; ++reg) {
  193. mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
  194. if (s)
  195. s = (*e) ? e + 1 : e;
  196. }
  197. write_mac(mac);
  198. return 0;
  199. #endif
  200. } else if (!strcmp(argv[1], "print")) {
  201. #if defined(CONFIG_CMD_NET)
  202. if (!i2c_read_mac(mac)) {
  203. printf("Ethaddr (from i2c mem) = %pM\n", mac);
  204. } else {
  205. printf("Ethaddr (from i2c mem) = Not set\n");
  206. }
  207. #endif
  208. return 0;
  209. }
  210. return cmd_usage(cmdtp);
  211. }
  212. U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
  213. "configure chip",
  214. "chip_config cpufreq/ddrfreq frequency\n"
  215. #if defined(CONFIG_CMD_NET)
  216. "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
  217. #endif
  218. "chip_config print");