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