1 // SPDX-License-Identifier: GPL-2.0+
4 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
14 #include <linux/mtd/st_smi.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/spr_emi.h>
18 #include <asm/arch/spr_defs.h>
22 #define SRAM_REL 0xD2801000
24 DECLARE_GLOBAL_DATA_PTR;
26 #if defined(CONFIG_CMD_NET)
27 static int i2c_read_mac(uchar *buffer);
32 /* Store complete RAM size and return */
33 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
38 int dram_init_banksize(void)
40 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
41 gd->bd->bi_dram[0].size = gd->ram_size;
46 int board_early_init_f()
48 #if defined(CONFIG_ST_SMI)
55 #if defined(CONFIG_CMD_NET)
58 if (!eth_env_get_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
59 eth_env_set_enetaddr("ethaddr", mac_id);
61 env_set("verify", "n");
63 #if defined(CONFIG_SPEAR_USBTTY)
64 env_set("stdin", "usbtty");
65 env_set("stdout", "usbtty");
66 env_set("stderr", "usbtty");
68 #ifndef CONFIG_SYS_NO_DCACHE
75 #ifdef CONFIG_SPEAR_EMI
76 struct cust_emi_para {
84 /* EMI timing setting of m28w640hc of linux kernel */
85 const struct cust_emi_para emi_timing_m28w640hc = {
93 /* EMI timing setting of bootrom */
94 const struct cust_emi_para emi_timing_bootrom = {
102 void spear_emi_init(void)
104 const struct cust_emi_para *p = &emi_timing_m28w640hc;
105 struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
107 unsigned int val, tmp;
109 val = readl(CONFIG_SPEAR_RASBASE);
111 if (val & EMI_ACKMSK)
116 writel(tmp, &emi_regs_p->ack);
118 for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
119 writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
120 writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
121 writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
122 writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
123 writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
124 writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
125 &emi_regs_p->bank_regs[cs].control);
130 int spear_board_init(ulong mach_type)
132 gd->bd->bi_arch_number = mach_type;
134 /* adress of boot parameters */
135 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
137 #ifdef CONFIG_SPEAR_EMI
143 #if defined(CONFIG_CMD_NET)
144 static int i2c_read_mac(uchar *buffer)
148 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
150 /* Check if mac in i2c memory is valid */
151 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
152 /* Valid mac address is saved in i2c eeprom */
153 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
160 static int write_mac(uchar *mac)
164 buf[0] = (u8)MAGIC_BYTE0;
165 buf[1] = (u8)MAGIC_BYTE1;
166 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
168 buf[0] = (u8)~MAGIC_BYTE0;
169 buf[1] = (u8)~MAGIC_BYTE1;
171 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
173 /* check if valid MAC address is saved in I2C EEPROM or not? */
174 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
175 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
176 puts("I2C EEPROM written with mac address \n");
180 puts("I2C EEPROM writing failed\n");
185 int do_chip_config(struct cmd_tbl *cmdtp, int flag, int argc,
188 void (*sram_setfreq) (unsigned int, unsigned int);
189 unsigned int frequency;
190 #if defined(CONFIG_CMD_NET)
191 unsigned char mac[6];
194 if ((argc > 3) || (argc < 2))
195 return cmd_usage(cmdtp);
197 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
199 frequency = simple_strtoul(argv[2], NULL, 0);
201 if (frequency > 333) {
202 printf("Frequency is limited to 333MHz\n");
206 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
208 if (!strcmp(argv[1], "cpufreq")) {
209 sram_setfreq(CPU, frequency);
210 printf("CPU frequency changed to %u\n", frequency);
212 sram_setfreq(DDR, frequency);
213 printf("DDR frequency changed to %u\n", frequency);
218 #if defined(CONFIG_CMD_NET)
219 } else if (!strcmp(argv[1], "ethaddr")) {
222 char *e, *s = argv[2];
223 for (reg = 0; reg < 6; ++reg) {
224 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
226 s = (*e) ? e + 1 : e;
232 } else if (!strcmp(argv[1], "print")) {
233 #if defined(CONFIG_CMD_NET)
234 if (!i2c_read_mac(mac)) {
235 printf("Ethaddr (from i2c mem) = %pM\n", mac);
237 printf("Ethaddr (from i2c mem) = Not set\n");
243 return cmd_usage(cmdtp);
246 U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
248 "chip_config cpufreq/ddrfreq frequency\n"
249 #if defined(CONFIG_CMD_NET)
250 "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
252 "chip_config print");