spr_misc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. void 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. }
  34. int board_early_init_f()
  35. {
  36. #if defined(CONFIG_ST_SMI)
  37. smi_init();
  38. #endif
  39. return 0;
  40. }
  41. int misc_init_r(void)
  42. {
  43. #if defined(CONFIG_CMD_NET)
  44. uchar mac_id[6];
  45. if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
  46. eth_setenv_enetaddr("ethaddr", mac_id);
  47. #endif
  48. setenv("verify", "n");
  49. #if defined(CONFIG_SPEAR_USBTTY)
  50. setenv("stdin", "usbtty");
  51. setenv("stdout", "usbtty");
  52. setenv("stderr", "usbtty");
  53. #ifndef CONFIG_SYS_NO_DCACHE
  54. dcache_enable();
  55. #endif
  56. #endif
  57. return 0;
  58. }
  59. #ifdef CONFIG_SPEAR_EMI
  60. struct cust_emi_para {
  61. unsigned int tap;
  62. unsigned int tsdp;
  63. unsigned int tdpw;
  64. unsigned int tdpr;
  65. unsigned int tdcs;
  66. };
  67. /* EMI timing setting of m28w640hc of linux kernel */
  68. const struct cust_emi_para emi_timing_m28w640hc = {
  69. .tap = 0x10,
  70. .tsdp = 0x05,
  71. .tdpw = 0x0a,
  72. .tdpr = 0x0a,
  73. .tdcs = 0x05,
  74. };
  75. /* EMI timing setting of bootrom */
  76. const struct cust_emi_para emi_timing_bootrom = {
  77. .tap = 0xf,
  78. .tsdp = 0x0,
  79. .tdpw = 0xff,
  80. .tdpr = 0x111,
  81. .tdcs = 0x02,
  82. };
  83. void spear_emi_init(void)
  84. {
  85. const struct cust_emi_para *p = &emi_timing_m28w640hc;
  86. struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
  87. unsigned int cs;
  88. unsigned int val, tmp;
  89. val = readl(CONFIG_SPEAR_RASBASE);
  90. if (val & EMI_ACKMSK)
  91. tmp = 0x3f;
  92. else
  93. tmp = 0x0;
  94. writel(tmp, &emi_regs_p->ack);
  95. for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
  96. writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
  97. writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
  98. writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
  99. writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
  100. writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
  101. writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
  102. &emi_regs_p->bank_regs[cs].control);
  103. }
  104. }
  105. #endif
  106. int spear_board_init(ulong mach_type)
  107. {
  108. gd->bd->bi_arch_number = mach_type;
  109. /* adress of boot parameters */
  110. gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
  111. #ifdef CONFIG_SPEAR_EMI
  112. spear_emi_init();
  113. #endif
  114. return 0;
  115. }
  116. #if defined(CONFIG_CMD_NET)
  117. static int i2c_read_mac(uchar *buffer)
  118. {
  119. u8 buf[2];
  120. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  121. /* Check if mac in i2c memory is valid */
  122. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  123. /* Valid mac address is saved in i2c eeprom */
  124. i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
  125. return 0;
  126. }
  127. return -1;
  128. }
  129. static int write_mac(uchar *mac)
  130. {
  131. u8 buf[2];
  132. buf[0] = (u8)MAGIC_BYTE0;
  133. buf[1] = (u8)MAGIC_BYTE1;
  134. i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  135. buf[0] = (u8)~MAGIC_BYTE0;
  136. buf[1] = (u8)~MAGIC_BYTE1;
  137. i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
  138. /* check if valid MAC address is saved in I2C EEPROM or not? */
  139. if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
  140. i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
  141. puts("I2C EEPROM written with mac address \n");
  142. return 0;
  143. }
  144. puts("I2C EEPROM writing failed\n");
  145. return -1;
  146. }
  147. #endif
  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 int frequency;
  152. #if defined(CONFIG_CMD_NET)
  153. unsigned char mac[6];
  154. #endif
  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. #if defined(CONFIG_CMD_NET)
  173. } else if (!strcmp(argv[1], "ethaddr")) {
  174. u32 reg;
  175. char *e, *s = argv[2];
  176. for (reg = 0; reg < 6; ++reg) {
  177. mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
  178. if (s)
  179. s = (*e) ? e + 1 : e;
  180. }
  181. write_mac(mac);
  182. return 0;
  183. #endif
  184. } else if (!strcmp(argv[1], "print")) {
  185. #if defined(CONFIG_CMD_NET)
  186. if (!i2c_read_mac(mac)) {
  187. printf("Ethaddr (from i2c mem) = %pM\n", mac);
  188. } else {
  189. printf("Ethaddr (from i2c mem) = Not set\n");
  190. }
  191. #endif
  192. return 0;
  193. }
  194. return cmd_usage(cmdtp);
  195. }
  196. U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
  197. "configure chip",
  198. "chip_config cpufreq/ddrfreq frequency\n"
  199. #if defined(CONFIG_CMD_NET)
  200. "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
  201. #endif
  202. "chip_config print");