Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 10 | #include <env.h> |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 11 | #include <i2c.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 12 | #include <init.h> |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 13 | #include <net.h> |
Amit Virdi | 47462dd | 2012-05-07 13:06:49 +0530 | [diff] [blame] | 14 | #include <linux/mtd/st_smi.h> |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/hardware.h> |
Vipin KUMAR | 9ab7f85 | 2010-01-15 19:15:51 +0530 | [diff] [blame] | 17 | #include <asm/arch/spr_emi.h> |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 18 | #include <asm/arch/spr_defs.h> |
| 19 | |
| 20 | #define CPU 0 |
| 21 | #define DDR 1 |
| 22 | #define SRAM_REL 0xD2801000 |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 25 | |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 26 | #if defined(CONFIG_CMD_NET) |
| 27 | static int i2c_read_mac(uchar *buffer); |
| 28 | #endif |
| 29 | |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 30 | int dram_init(void) |
| 31 | { |
Amit Virdi | 29b7a83 | 2012-05-07 13:06:39 +0530 | [diff] [blame] | 32 | /* Store complete RAM size and return */ |
Shiraz Hashim | 6bef6c8 | 2011-06-11 21:32:57 +0000 | [diff] [blame] | 33 | gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 34 | |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 35 | return 0; |
| 36 | } |
| 37 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 38 | int dram_init_banksize(void) |
Shiraz Hashim | 6bef6c8 | 2011-06-11 21:32:57 +0000 | [diff] [blame] | 39 | { |
| 40 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 41 | gd->bd->bi_dram[0].size = gd->ram_size; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 42 | |
| 43 | return 0; |
Shiraz Hashim | 6bef6c8 | 2011-06-11 21:32:57 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Amit Virdi | 47462dd | 2012-05-07 13:06:49 +0530 | [diff] [blame] | 46 | int board_early_init_f() |
| 47 | { |
| 48 | #if defined(CONFIG_ST_SMI) |
| 49 | smi_init(); |
| 50 | #endif |
| 51 | return 0; |
| 52 | } |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 53 | int misc_init_r(void) |
| 54 | { |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 55 | #if defined(CONFIG_CMD_NET) |
| 56 | uchar mac_id[6]; |
| 57 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 58 | if (!eth_env_get_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 59 | eth_env_set_enetaddr("ethaddr", mac_id); |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 60 | #endif |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 61 | env_set("verify", "n"); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 62 | |
| 63 | #if defined(CONFIG_SPEAR_USBTTY) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 64 | env_set("stdin", "usbtty"); |
| 65 | env_set("stdout", "usbtty"); |
| 66 | env_set("stderr", "usbtty"); |
Shiraz Hashim | e35e287 | 2012-05-07 13:06:53 +0530 | [diff] [blame] | 67 | |
| 68 | #ifndef CONFIG_SYS_NO_DCACHE |
| 69 | dcache_enable(); |
| 70 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 71 | #endif |
| 72 | return 0; |
| 73 | } |
| 74 | |
Vipin KUMAR | 9ab7f85 | 2010-01-15 19:15:51 +0530 | [diff] [blame] | 75 | #ifdef CONFIG_SPEAR_EMI |
| 76 | struct cust_emi_para { |
| 77 | unsigned int tap; |
| 78 | unsigned int tsdp; |
| 79 | unsigned int tdpw; |
| 80 | unsigned int tdpr; |
| 81 | unsigned int tdcs; |
| 82 | }; |
| 83 | |
| 84 | /* EMI timing setting of m28w640hc of linux kernel */ |
| 85 | const struct cust_emi_para emi_timing_m28w640hc = { |
| 86 | .tap = 0x10, |
| 87 | .tsdp = 0x05, |
| 88 | .tdpw = 0x0a, |
| 89 | .tdpr = 0x0a, |
| 90 | .tdcs = 0x05, |
| 91 | }; |
| 92 | |
| 93 | /* EMI timing setting of bootrom */ |
| 94 | const struct cust_emi_para emi_timing_bootrom = { |
| 95 | .tap = 0xf, |
| 96 | .tsdp = 0x0, |
| 97 | .tdpw = 0xff, |
| 98 | .tdpr = 0x111, |
| 99 | .tdcs = 0x02, |
| 100 | }; |
| 101 | |
| 102 | void spear_emi_init(void) |
| 103 | { |
| 104 | const struct cust_emi_para *p = &emi_timing_m28w640hc; |
| 105 | struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE; |
| 106 | unsigned int cs; |
| 107 | unsigned int val, tmp; |
| 108 | |
| 109 | val = readl(CONFIG_SPEAR_RASBASE); |
| 110 | |
| 111 | if (val & EMI_ACKMSK) |
| 112 | tmp = 0x3f; |
| 113 | else |
| 114 | tmp = 0x0; |
| 115 | |
| 116 | writel(tmp, &emi_regs_p->ack); |
| 117 | |
| 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); |
| 126 | } |
| 127 | } |
| 128 | #endif |
| 129 | |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 130 | int spear_board_init(ulong mach_type) |
| 131 | { |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 132 | gd->bd->bi_arch_number = mach_type; |
| 133 | |
| 134 | /* adress of boot parameters */ |
| 135 | gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR; |
| 136 | |
Vipin KUMAR | 9ab7f85 | 2010-01-15 19:15:51 +0530 | [diff] [blame] | 137 | #ifdef CONFIG_SPEAR_EMI |
| 138 | spear_emi_init(); |
| 139 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 143 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 144 | static int i2c_read_mac(uchar *buffer) |
| 145 | { |
| 146 | u8 buf[2]; |
| 147 | |
| 148 | i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN); |
| 149 | |
| 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); |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | return -1; |
| 158 | } |
| 159 | |
| 160 | static int write_mac(uchar *mac) |
| 161 | { |
| 162 | u8 buf[2]; |
| 163 | |
| 164 | buf[0] = (u8)MAGIC_BYTE0; |
| 165 | buf[1] = (u8)MAGIC_BYTE1; |
| 166 | i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN); |
| 167 | |
| 168 | buf[0] = (u8)~MAGIC_BYTE0; |
| 169 | buf[1] = (u8)~MAGIC_BYTE1; |
| 170 | |
| 171 | i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN); |
| 172 | |
| 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"); |
| 177 | return 0; |
| 178 | } |
| 179 | |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 180 | puts("I2C EEPROM writing failed\n"); |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 181 | return -1; |
| 182 | } |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 183 | #endif |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 184 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 185 | int do_chip_config(struct cmd_tbl *cmdtp, int flag, int argc, |
| 186 | char *const argv[]) |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 187 | { |
| 188 | void (*sram_setfreq) (unsigned int, unsigned int); |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 189 | unsigned int frequency; |
| 190 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 191 | unsigned char mac[6]; |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 192 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 193 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 194 | if ((argc > 3) || (argc < 2)) |
| 195 | return cmd_usage(cmdtp); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 196 | |
| 197 | if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) { |
| 198 | |
| 199 | frequency = simple_strtoul(argv[2], NULL, 0); |
| 200 | |
| 201 | if (frequency > 333) { |
| 202 | printf("Frequency is limited to 333MHz\n"); |
| 203 | return 1; |
| 204 | } |
| 205 | |
| 206 | sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz); |
| 207 | |
| 208 | if (!strcmp(argv[1], "cpufreq")) { |
| 209 | sram_setfreq(CPU, frequency); |
| 210 | printf("CPU frequency changed to %u\n", frequency); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 211 | } else { |
| 212 | sram_setfreq(DDR, frequency); |
| 213 | printf("DDR frequency changed to %u\n", frequency); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | return 0; |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 217 | |
| 218 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 219 | } else if (!strcmp(argv[1], "ethaddr")) { |
| 220 | |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 221 | u32 reg; |
| 222 | char *e, *s = argv[2]; |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 223 | for (reg = 0; reg < 6; ++reg) { |
| 224 | mac[reg] = s ? simple_strtoul(s, &e, 16) : 0; |
| 225 | if (s) |
| 226 | s = (*e) ? e + 1 : e; |
| 227 | } |
| 228 | write_mac(mac); |
| 229 | |
| 230 | return 0; |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 231 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 232 | } else if (!strcmp(argv[1], "print")) { |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 233 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 234 | if (!i2c_read_mac(mac)) { |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 235 | printf("Ethaddr (from i2c mem) = %pM\n", mac); |
Vipin KUMAR | f8c7278 | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 236 | } else { |
| 237 | printf("Ethaddr (from i2c mem) = Not set\n"); |
| 238 | } |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 239 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 243 | return cmd_usage(cmdtp); |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | U_BOOT_CMD(chip_config, 3, 1, do_chip_config, |
| 247 | "configure chip", |
| 248 | "chip_config cpufreq/ddrfreq frequency\n" |
Vipin KUMAR | f6b5678 | 2012-05-07 13:06:41 +0530 | [diff] [blame] | 249 | #if defined(CONFIG_CMD_NET) |
| 250 | "chip_config ethaddr XX:XX:XX:XX:XX:XX\n" |
| 251 | #endif |
Vipin KUMAR | 7cc4c46 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 252 | "chip_config print"); |