3 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/mtd/st_smi.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/spr_emi.h>
16 #include <asm/arch/spr_defs.h>
20 #define SRAM_REL 0xD2801000
22 DECLARE_GLOBAL_DATA_PTR;
24 #if defined(CONFIG_CMD_NET)
25 static int i2c_read_mac(uchar *buffer);
30 /* Store complete RAM size and return */
31 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
36 int dram_init_banksize(void)
38 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
39 gd->bd->bi_dram[0].size = gd->ram_size;
44 int board_early_init_f()
46 #if defined(CONFIG_ST_SMI)
53 #if defined(CONFIG_CMD_NET)
56 if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
57 eth_setenv_enetaddr("ethaddr", mac_id);
59 setenv("verify", "n");
61 #if defined(CONFIG_SPEAR_USBTTY)
62 setenv("stdin", "usbtty");
63 setenv("stdout", "usbtty");
64 setenv("stderr", "usbtty");
66 #ifndef CONFIG_SYS_NO_DCACHE
73 #ifdef CONFIG_SPEAR_EMI
74 struct cust_emi_para {
82 /* EMI timing setting of m28w640hc of linux kernel */
83 const struct cust_emi_para emi_timing_m28w640hc = {
91 /* EMI timing setting of bootrom */
92 const struct cust_emi_para emi_timing_bootrom = {
100 void spear_emi_init(void)
102 const struct cust_emi_para *p = &emi_timing_m28w640hc;
103 struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
105 unsigned int val, tmp;
107 val = readl(CONFIG_SPEAR_RASBASE);
109 if (val & EMI_ACKMSK)
114 writel(tmp, &emi_regs_p->ack);
116 for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
117 writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
118 writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
119 writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
120 writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
121 writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
122 writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
123 &emi_regs_p->bank_regs[cs].control);
128 int spear_board_init(ulong mach_type)
130 gd->bd->bi_arch_number = mach_type;
132 /* adress of boot parameters */
133 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
135 #ifdef CONFIG_SPEAR_EMI
141 #if defined(CONFIG_CMD_NET)
142 static int i2c_read_mac(uchar *buffer)
146 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
148 /* Check if mac in i2c memory is valid */
149 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
150 /* Valid mac address is saved in i2c eeprom */
151 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
158 static int write_mac(uchar *mac)
162 buf[0] = (u8)MAGIC_BYTE0;
163 buf[1] = (u8)MAGIC_BYTE1;
164 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
166 buf[0] = (u8)~MAGIC_BYTE0;
167 buf[1] = (u8)~MAGIC_BYTE1;
169 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
171 /* check if valid MAC address is saved in I2C EEPROM or not? */
172 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
173 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
174 puts("I2C EEPROM written with mac address \n");
178 puts("I2C EEPROM writing failed\n");
183 int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
185 void (*sram_setfreq) (unsigned int, unsigned int);
186 unsigned int frequency;
187 #if defined(CONFIG_CMD_NET)
188 unsigned char mac[6];
191 if ((argc > 3) || (argc < 2))
192 return cmd_usage(cmdtp);
194 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
196 frequency = simple_strtoul(argv[2], NULL, 0);
198 if (frequency > 333) {
199 printf("Frequency is limited to 333MHz\n");
203 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
205 if (!strcmp(argv[1], "cpufreq")) {
206 sram_setfreq(CPU, frequency);
207 printf("CPU frequency changed to %u\n", frequency);
209 sram_setfreq(DDR, frequency);
210 printf("DDR frequency changed to %u\n", frequency);
215 #if defined(CONFIG_CMD_NET)
216 } else if (!strcmp(argv[1], "ethaddr")) {
219 char *e, *s = argv[2];
220 for (reg = 0; reg < 6; ++reg) {
221 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
223 s = (*e) ? e + 1 : e;
229 } else if (!strcmp(argv[1], "print")) {
230 #if defined(CONFIG_CMD_NET)
231 if (!i2c_read_mac(mac)) {
232 printf("Ethaddr (from i2c mem) = %pM\n", mac);
234 printf("Ethaddr (from i2c mem) = Not set\n");
240 return cmd_usage(cmdtp);
243 U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
245 "chip_config cpufreq/ddrfreq frequency\n"
246 #if defined(CONFIG_CMD_NET)
247 "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
249 "chip_config print");