3 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <asm/arch/hardware.h>
30 #include <asm/arch/spr_emi.h>
31 #include <asm/arch/spr_xloader_table.h>
32 #include <asm/arch/spr_defs.h>
36 #define SRAM_REL 0xD2801000
38 DECLARE_GLOBAL_DATA_PTR;
39 static struct chip_data chip_data;
43 /* Store complete RAM size and return */
44 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
49 void dram_init_banksize(void)
51 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
52 gd->bd->bi_dram[0].size = gd->ram_size;
57 #if defined(CONFIG_CMD_NET)
60 if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
61 eth_setenv_enetaddr("ethaddr", mac_id);
63 setenv("verify", "n");
65 #if defined(CONFIG_SPEAR_USBTTY)
66 setenv("stdin", "usbtty");
67 setenv("stdout", "usbtty");
68 setenv("stderr", "usbtty");
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 struct xloader_table *xloader_tb =
131 (struct xloader_table *)XLOADER_TABLE_ADDRESS;
132 struct xloader_table_1_2 *table_1_2;
133 struct chip_data *chip = &chip_data;
135 gd->bd->bi_arch_number = mach_type;
137 /* adress of boot parameters */
138 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
140 /* CPU is initialized to work at 333MHz in Xloader */
143 if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) {
144 table_1_2 = &xloader_tb->table.table_1_2;
145 memcpy(chip->version, table_1_2->version,
146 sizeof(chip->version));
149 #ifdef CONFIG_SPEAR_EMI
155 static int i2c_read_mac(uchar *buffer)
159 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
161 /* Check if mac in i2c memory is valid */
162 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
163 /* Valid mac address is saved in i2c eeprom */
164 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
171 static int write_mac(uchar *mac)
175 buf[0] = (u8)MAGIC_BYTE0;
176 buf[1] = (u8)MAGIC_BYTE1;
177 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
179 buf[0] = (u8)~MAGIC_BYTE0;
180 buf[1] = (u8)~MAGIC_BYTE1;
182 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
184 /* check if valid MAC address is saved in I2C EEPROM or not? */
185 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
186 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
187 puts("I2C EEPROM written with mac address \n");
191 puts("I2C EEPROM writing failed \n");
195 int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
197 void (*sram_setfreq) (unsigned int, unsigned int);
198 struct chip_data *chip = &chip_data;
199 unsigned char mac[6];
200 unsigned int reg, frequency;
204 if ((argc > 3) || (argc < 2))
205 return cmd_usage(cmdtp);
207 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
209 frequency = simple_strtoul(argv[2], NULL, 0);
211 if (frequency > 333) {
212 printf("Frequency is limited to 333MHz\n");
216 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
218 if (!strcmp(argv[1], "cpufreq")) {
219 sram_setfreq(CPU, frequency);
220 printf("CPU frequency changed to %u\n", frequency);
222 chip->cpufreq = frequency;
224 sram_setfreq(DDR, frequency);
225 printf("DDR frequency changed to %u\n", frequency);
227 chip->dramfreq = frequency;
231 } else if (!strcmp(argv[1], "ethaddr")) {
234 for (reg = 0; reg < 6; ++reg) {
235 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
237 s = (*e) ? e + 1 : e;
242 } else if (!strcmp(argv[1], "print")) {
244 if (chip->cpufreq == -1)
245 printf("CPU Freq = Not Known\n");
247 printf("CPU Freq = %d MHz\n", chip->cpufreq);
249 if (chip->dramfreq == -1)
250 printf("DDR Freq = Not Known\n");
252 printf("DDR Freq = %d MHz\n", chip->dramfreq);
254 if (chip->dramtype == DDRMOBILE)
255 printf("DDR Type = MOBILE\n");
256 else if (chip->dramtype == DDR2)
257 printf("DDR Type = DDR2\n");
259 printf("DDR Type = Not Known\n");
261 if (!i2c_read_mac(mac)) {
262 sprintf(i2c_mac, "%pM", mac);
263 printf("Ethaddr (from i2c mem) = %s\n", i2c_mac);
265 printf("Ethaddr (from i2c mem) = Not set\n");
268 printf("Xloader Rev = %s\n", chip->version);
273 return cmd_usage(cmdtp);
276 U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
278 "chip_config cpufreq/ddrfreq frequency\n"
279 "chip_config print");