5 * SPDX-License-Identifier: GPL-2.0+
10 #include <environment.h>
13 #include <linux/mtd/st_smi.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/spr_emi.h>
17 #include <asm/arch/spr_defs.h>
21 #define SRAM_REL 0xD2801000
23 DECLARE_GLOBAL_DATA_PTR;
25 #if defined(CONFIG_CMD_NET)
26 static int i2c_read_mac(uchar *buffer);
31 /* Store complete RAM size and return */
32 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
37 int dram_init_banksize(void)
39 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
40 gd->bd->bi_dram[0].size = gd->ram_size;
45 int board_early_init_f()
47 #if defined(CONFIG_ST_SMI)
54 #if defined(CONFIG_CMD_NET)
57 if (!eth_env_get_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
58 eth_env_set_enetaddr("ethaddr", mac_id);
60 env_set("verify", "n");
62 #if defined(CONFIG_SPEAR_USBTTY)
63 env_set("stdin", "usbtty");
64 env_set("stdout", "usbtty");
65 env_set("stderr", "usbtty");
67 #ifndef CONFIG_SYS_NO_DCACHE
74 #ifdef CONFIG_SPEAR_EMI
75 struct cust_emi_para {
83 /* EMI timing setting of m28w640hc of linux kernel */
84 const struct cust_emi_para emi_timing_m28w640hc = {
92 /* EMI timing setting of bootrom */
93 const struct cust_emi_para emi_timing_bootrom = {
101 void spear_emi_init(void)
103 const struct cust_emi_para *p = &emi_timing_m28w640hc;
104 struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
106 unsigned int val, tmp;
108 val = readl(CONFIG_SPEAR_RASBASE);
110 if (val & EMI_ACKMSK)
115 writel(tmp, &emi_regs_p->ack);
117 for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
118 writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
119 writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
120 writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
121 writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
122 writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
123 writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
124 &emi_regs_p->bank_regs[cs].control);
129 int spear_board_init(ulong mach_type)
131 gd->bd->bi_arch_number = mach_type;
133 /* adress of boot parameters */
134 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
136 #ifdef CONFIG_SPEAR_EMI
142 #if defined(CONFIG_CMD_NET)
143 static int i2c_read_mac(uchar *buffer)
147 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
149 /* Check if mac in i2c memory is valid */
150 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
151 /* Valid mac address is saved in i2c eeprom */
152 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
159 static int write_mac(uchar *mac)
163 buf[0] = (u8)MAGIC_BYTE0;
164 buf[1] = (u8)MAGIC_BYTE1;
165 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
167 buf[0] = (u8)~MAGIC_BYTE0;
168 buf[1] = (u8)~MAGIC_BYTE1;
170 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
172 /* check if valid MAC address is saved in I2C EEPROM or not? */
173 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
174 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
175 puts("I2C EEPROM written with mac address \n");
179 puts("I2C EEPROM writing failed\n");
184 int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
186 void (*sram_setfreq) (unsigned int, unsigned int);
187 unsigned int frequency;
188 #if defined(CONFIG_CMD_NET)
189 unsigned char mac[6];
192 if ((argc > 3) || (argc < 2))
193 return cmd_usage(cmdtp);
195 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
197 frequency = simple_strtoul(argv[2], NULL, 0);
199 if (frequency > 333) {
200 printf("Frequency is limited to 333MHz\n");
204 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
206 if (!strcmp(argv[1], "cpufreq")) {
207 sram_setfreq(CPU, frequency);
208 printf("CPU frequency changed to %u\n", frequency);
210 sram_setfreq(DDR, frequency);
211 printf("DDR frequency changed to %u\n", frequency);
216 #if defined(CONFIG_CMD_NET)
217 } else if (!strcmp(argv[1], "ethaddr")) {
220 char *e, *s = argv[2];
221 for (reg = 0; reg < 6; ++reg) {
222 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
224 s = (*e) ? e + 1 : e;
230 } else if (!strcmp(argv[1], "print")) {
231 #if defined(CONFIG_CMD_NET)
232 if (!i2c_read_mac(mac)) {
233 printf("Ethaddr (from i2c mem) = %pM\n", mac);
235 printf("Ethaddr (from i2c mem) = Not set\n");
241 return cmd_usage(cmdtp);
244 U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
246 "chip_config cpufreq/ddrfreq frequency\n"
247 #if defined(CONFIG_CMD_NET)
248 "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
250 "chip_config print");