Vipin KUMAR | 566c9c1 | 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> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/arch/hardware.h> |
Vipin KUMAR | 4bfacad | 2010-01-15 19:15:51 +0530 | [diff] [blame] | 30 | #include <asm/arch/spr_emi.h> |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 31 | #include <asm/arch/spr_defs.h> |
| 32 | |
| 33 | #define CPU 0 |
| 34 | #define DDR 1 |
| 35 | #define SRAM_REL 0xD2801000 |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 38 | |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 39 | #if defined(CONFIG_CMD_NET) |
| 40 | static int i2c_read_mac(uchar *buffer); |
| 41 | #endif |
| 42 | |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 43 | int dram_init(void) |
| 44 | { |
Amit Virdi | 5cca72f | 2012-05-07 13:06:39 +0530 | [diff] [blame] | 45 | /* Store complete RAM size and return */ |
Shiraz Hashim | a39fcfb | 2011-06-11 21:32:57 +0000 | [diff] [blame] | 46 | gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE); |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 47 | |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
Shiraz Hashim | a39fcfb | 2011-06-11 21:32:57 +0000 | [diff] [blame] | 51 | void dram_init_banksize(void) |
| 52 | { |
| 53 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 54 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 55 | } |
| 56 | |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 57 | int misc_init_r(void) |
| 58 | { |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 59 | #if defined(CONFIG_CMD_NET) |
| 60 | uchar mac_id[6]; |
| 61 | |
| 62 | if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id)) |
| 63 | eth_setenv_enetaddr("ethaddr", mac_id); |
| 64 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 65 | setenv("verify", "n"); |
| 66 | |
| 67 | #if defined(CONFIG_SPEAR_USBTTY) |
| 68 | setenv("stdin", "usbtty"); |
| 69 | setenv("stdout", "usbtty"); |
| 70 | setenv("stderr", "usbtty"); |
| 71 | #endif |
| 72 | return 0; |
| 73 | } |
| 74 | |
Vipin KUMAR | 4bfacad | 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 | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 130 | int spear_board_init(ulong mach_type) |
| 131 | { |
Vipin KUMAR | 566c9c1 | 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 | 4bfacad | 2010-01-15 19:15:51 +0530 | [diff] [blame] | 137 | #ifdef CONFIG_SPEAR_EMI |
| 138 | spear_emi_init(); |
| 139 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 143 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f92994f | 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 | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 180 | puts("I2C EEPROM writing failed\n"); |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 181 | return -1; |
| 182 | } |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 183 | #endif |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 184 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 185 | int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 186 | { |
| 187 | void (*sram_setfreq) (unsigned int, unsigned int); |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 188 | unsigned int frequency; |
| 189 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 190 | unsigned char mac[6]; |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 191 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 192 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 193 | if ((argc > 3) || (argc < 2)) |
| 194 | return cmd_usage(cmdtp); |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 195 | |
| 196 | if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) { |
| 197 | |
| 198 | frequency = simple_strtoul(argv[2], NULL, 0); |
| 199 | |
| 200 | if (frequency > 333) { |
| 201 | printf("Frequency is limited to 333MHz\n"); |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz); |
| 206 | |
| 207 | if (!strcmp(argv[1], "cpufreq")) { |
| 208 | sram_setfreq(CPU, frequency); |
| 209 | printf("CPU frequency changed to %u\n", frequency); |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 210 | } else { |
| 211 | sram_setfreq(DDR, frequency); |
| 212 | printf("DDR frequency changed to %u\n", frequency); |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | return 0; |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 216 | |
| 217 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 218 | } else if (!strcmp(argv[1], "ethaddr")) { |
| 219 | |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 220 | u32 reg; |
| 221 | char *e, *s = argv[2]; |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 222 | for (reg = 0; reg < 6; ++reg) { |
| 223 | mac[reg] = s ? simple_strtoul(s, &e, 16) : 0; |
| 224 | if (s) |
| 225 | s = (*e) ? e + 1 : e; |
| 226 | } |
| 227 | write_mac(mac); |
| 228 | |
| 229 | return 0; |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 230 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 231 | } else if (!strcmp(argv[1], "print")) { |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 232 | #if defined(CONFIG_CMD_NET) |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 233 | if (!i2c_read_mac(mac)) { |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 234 | printf("Ethaddr (from i2c mem) = %pM\n", mac); |
Vipin KUMAR | f92994f | 2010-01-15 19:15:49 +0530 | [diff] [blame] | 235 | } else { |
| 236 | printf("Ethaddr (from i2c mem) = Not set\n"); |
| 237 | } |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 238 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 242 | return cmd_usage(cmdtp); |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | U_BOOT_CMD(chip_config, 3, 1, do_chip_config, |
| 246 | "configure chip", |
| 247 | "chip_config cpufreq/ddrfreq frequency\n" |
Vipin KUMAR | 8026b1e | 2012-05-07 13:06:41 +0530 | [diff] [blame^] | 248 | #if defined(CONFIG_CMD_NET) |
| 249 | "chip_config ethaddr XX:XX:XX:XX:XX:XX\n" |
| 250 | #endif |
Vipin KUMAR | 566c9c1 | 2010-01-15 19:15:48 +0530 | [diff] [blame] | 251 | "chip_config print"); |