spr_misc.c 5.2 KB

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