spr_misc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * (C) Copyright 2009
  3. * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <i2c.h>
  10. #include <net.h>
  11. #include <linux/mtd/st_smi.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/spr_emi.h>
  15. #include <asm/arch/spr_defs.h>
  16. #define CPU 0
  17. #define DDR 1
  18. #define SRAM_REL 0xD2801000
  19. DECLARE_GLOBAL_DATA_PTR;
  20. #if defined(CONFIG_CMD_NET)
  21. static int i2c_read_mac(uchar *buffer);
  22. #endif
  23. int dram_init(void)
  24. {
  25. /* Store complete RAM size and return */
  26. gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
  27. return 0;
  28. }
  29. int dram_init_banksize(void)
  30. {
  31. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  32. gd->bd->bi_dram[0].size = gd->ram_size;
  33. return 0;
  34. }
  35. int board_early_init_f()
  36. {
  37. #if defined(CONFIG_ST_SMI)
  38. smi_init();
  39. #endif
  40. return 0;
  41. }
  42. int misc_init_r(void)
  43. {
  44. #if defined(CONFIG_CMD_NET)
  45. uchar mac_id[6];
  46. if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
  47. eth_setenv_enetaddr("ethaddr", mac_id);
  48. #endif
  49. setenv("verify", "n");
  50. #if defined(CONFIG_SPEAR_USBTTY)
  51. setenv("stdin", "usbtty");
  52. setenv("stdout", "usbtty");
  53. setenv("stderr", "usbtty");
  54. #ifndef CONFIG_SYS_NO_DCACHE
  55. dcache_enable();
  56. #endif
  57. #endif
  58. return 0;
  59. }
  60. #ifdef CONFIG_SPEAR_EMI
  61. struct cust_emi_para {
  62. unsigned int tap;
  63. unsigned int tsdp;
  64. unsigned int tdpw;
  65. unsigned int tdpr;
  66. unsigned int tdcs;
  67. };
  68. /* EMI timing setting of m28w640hc of linux kernel */
  69. const struct cust_emi_para emi_timing_m28w640hc = {
  70. .tap = 0x10,
  71. .tsdp = 0x05,
  72. .tdpw = 0x0a,
  73. .tdpr = 0x0a,
  74. .tdcs = 0x05,
  75. };
  76. /* EMI timing setting of bootrom */
  77. const struct cust_emi_para emi_timing_bootrom = {
  78. .tap = 0xf,
  79. .tsdp = 0x0,
  80. .tdpw = 0xff,
  81. .tdpr = 0x111,
  82. .tdcs = 0x02,
  83. };
  84. void spear_emi_init(void)
  85. {
  86. const struct cust_emi_para *p = &emi_timing_m28w640hc;
  87. struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
  88. unsigned int cs;
  89. unsigned int val, tmp;
  90. val = readl(CONFIG_SPEAR_RASBASE);
  91. if (val & EMI_ACKMSK)
  92. tmp = 0x3f;
  93. else
  94. tmp = 0x0;
  95. writel(tmp, &emi_regs_p->ack);
  96. for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
  97. writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
  98. writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
  99. writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
  100. writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
  101. writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
  102. writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
  103. &emi_regs_p->bank_regs[cs].control);
  104. }
  105. }
  106. #endif
  107. int spear_board_init(ulong mach_type)
  108. {
  109. gd->bd->bi_arch_number = mach_type;
  110. /* adress of boot parameters */
  111. gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
  112. #ifdef CONFIG_SPEAR_EMI
  113. spear_emi_init();
  114. #endif
  115. return 0;
  116. }
  117. #if defined(CONFIG_CMD_NET)
  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. #endif
  149. int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  150. {
  151. void (*sram_setfreq) (unsigned int, unsigned int);
  152. unsigned int frequency;
  153. #if defined(CONFIG_CMD_NET)
  154. unsigned char mac[6];
  155. #endif
  156. if ((argc > 3) || (argc < 2))
  157. return cmd_usage(cmdtp);
  158. if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
  159. frequency = simple_strtoul(argv[2], NULL, 0);
  160. if (frequency > 333) {
  161. printf("Frequency is limited to 333MHz\n");
  162. return 1;
  163. }
  164. sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
  165. if (!strcmp(argv[1], "cpufreq")) {
  166. sram_setfreq(CPU, frequency);
  167. printf("CPU frequency changed to %u\n", frequency);
  168. } else {
  169. sram_setfreq(DDR, frequency);
  170. printf("DDR frequency changed to %u\n", frequency);
  171. }
  172. return 0;
  173. #if defined(CONFIG_CMD_NET)
  174. } else if (!strcmp(argv[1], "ethaddr")) {
  175. u32 reg;
  176. char *e, *s = argv[2];
  177. for (reg = 0; reg < 6; ++reg) {
  178. mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
  179. if (s)
  180. s = (*e) ? e + 1 : e;
  181. }
  182. write_mac(mac);
  183. return 0;
  184. #endif
  185. } else if (!strcmp(argv[1], "print")) {
  186. #if defined(CONFIG_CMD_NET)
  187. if (!i2c_read_mac(mac)) {
  188. printf("Ethaddr (from i2c mem) = %pM\n", mac);
  189. } else {
  190. printf("Ethaddr (from i2c mem) = Not set\n");
  191. }
  192. #endif
  193. return 0;
  194. }
  195. return cmd_usage(cmdtp);
  196. }
  197. U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
  198. "configure chip",
  199. "chip_config cpufreq/ddrfreq frequency\n"
  200. #if defined(CONFIG_CMD_NET)
  201. "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
  202. #endif
  203. "chip_config print");