blob: be96c1504e69a755ebd5d1e984000b20c3a56524 [file] [log] [blame]
Vipin KUMAR566c9c12010-01-15 19:15:48 +05301/*
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 KUMAR4bfacad2010-01-15 19:15:51 +053030#include <asm/arch/spr_emi.h>
Vipin KUMAR566c9c12010-01-15 19:15:48 +053031#include <asm/arch/spr_defs.h>
32
33#define CPU 0
34#define DDR 1
35#define SRAM_REL 0xD2801000
36
37DECLARE_GLOBAL_DATA_PTR;
Vipin KUMAR566c9c12010-01-15 19:15:48 +053038
39int dram_init(void)
40{
Amit Virdi5cca72f2012-05-07 13:06:39 +053041 /* Store complete RAM size and return */
Shiraz Hashima39fcfb2011-06-11 21:32:57 +000042 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
Vipin KUMAR566c9c12010-01-15 19:15:48 +053043
Vipin KUMAR566c9c12010-01-15 19:15:48 +053044 return 0;
45}
46
Shiraz Hashima39fcfb2011-06-11 21:32:57 +000047void dram_init_banksize(void)
48{
49 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
50 gd->bd->bi_dram[0].size = gd->ram_size;
51}
52
Vipin KUMAR566c9c12010-01-15 19:15:48 +053053int misc_init_r(void)
54{
Vipin KUMARf92994f2010-01-15 19:15:49 +053055#if defined(CONFIG_CMD_NET)
56 uchar mac_id[6];
57
58 if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
59 eth_setenv_enetaddr("ethaddr", mac_id);
60#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +053061 setenv("verify", "n");
62
63#if defined(CONFIG_SPEAR_USBTTY)
64 setenv("stdin", "usbtty");
65 setenv("stdout", "usbtty");
66 setenv("stderr", "usbtty");
67#endif
68 return 0;
69}
70
Vipin KUMAR4bfacad2010-01-15 19:15:51 +053071#ifdef CONFIG_SPEAR_EMI
72struct 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 */
81const 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 */
90const struct cust_emi_para emi_timing_bootrom = {
91 .tap = 0xf,
92 .tsdp = 0x0,
93 .tdpw = 0xff,
94 .tdpr = 0x111,
95 .tdcs = 0x02,
96};
97
98void 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 KUMAR566c9c12010-01-15 19:15:48 +0530126int spear_board_init(ulong mach_type)
127{
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530128 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 KUMAR4bfacad2010-01-15 19:15:51 +0530133#ifdef CONFIG_SPEAR_EMI
134 spear_emi_init();
135#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530136 return 0;
137}
138
Vipin KUMARf92994f2010-01-15 19:15:49 +0530139static int i2c_read_mac(uchar *buffer)
140{
141 u8 buf[2];
142
143 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
144
145 /* Check if mac in i2c memory is valid */
146 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
147 /* Valid mac address is saved in i2c eeprom */
148 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
149 return 0;
150 }
151
152 return -1;
153}
154
155static int write_mac(uchar *mac)
156{
157 u8 buf[2];
158
159 buf[0] = (u8)MAGIC_BYTE0;
160 buf[1] = (u8)MAGIC_BYTE1;
161 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
162
163 buf[0] = (u8)~MAGIC_BYTE0;
164 buf[1] = (u8)~MAGIC_BYTE1;
165
166 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
167
168 /* check if valid MAC address is saved in I2C EEPROM or not? */
169 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
170 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
171 puts("I2C EEPROM written with mac address \n");
172 return 0;
173 }
174
175 puts("I2C EEPROM writing failed \n");
176 return -1;
177}
178
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200179int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530180{
181 void (*sram_setfreq) (unsigned int, unsigned int);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530182 unsigned char mac[6];
Vipin KUMARf92994f2010-01-15 19:15:49 +0530183 unsigned int reg, frequency;
184 char *s, *e;
185 char i2c_mac[20];
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530186
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200187 if ((argc > 3) || (argc < 2))
188 return cmd_usage(cmdtp);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530189
190 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
191
192 frequency = simple_strtoul(argv[2], NULL, 0);
193
194 if (frequency > 333) {
195 printf("Frequency is limited to 333MHz\n");
196 return 1;
197 }
198
199 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
200
201 if (!strcmp(argv[1], "cpufreq")) {
202 sram_setfreq(CPU, frequency);
203 printf("CPU frequency changed to %u\n", frequency);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530204 } else {
205 sram_setfreq(DDR, frequency);
206 printf("DDR frequency changed to %u\n", frequency);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530207 }
208
209 return 0;
Vipin KUMARf92994f2010-01-15 19:15:49 +0530210 } else if (!strcmp(argv[1], "ethaddr")) {
211
212 s = argv[2];
213 for (reg = 0; reg < 6; ++reg) {
214 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
215 if (s)
216 s = (*e) ? e + 1 : e;
217 }
218 write_mac(mac);
219
220 return 0;
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530221 } else if (!strcmp(argv[1], "print")) {
Vipin KUMARf92994f2010-01-15 19:15:49 +0530222 if (!i2c_read_mac(mac)) {
223 sprintf(i2c_mac, "%pM", mac);
224 printf("Ethaddr (from i2c mem) = %s\n", i2c_mac);
225 } else {
226 printf("Ethaddr (from i2c mem) = Not set\n");
227 }
228
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530229 return 0;
230 }
231
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200232 return cmd_usage(cmdtp);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530233}
234
235U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
236 "configure chip",
237 "chip_config cpufreq/ddrfreq frequency\n"
238 "chip_config print");