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