blob: 043c72a05d3496b5ee19d6a013965b66c7743f20 [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>
Amit Virdi0b7ff3f2012-05-07 13:06:49 +053028#include <linux/mtd/st_smi.h>
Vipin KUMAR566c9c12010-01-15 19:15:48 +053029#include <asm/io.h>
30#include <asm/arch/hardware.h>
Vipin KUMAR4bfacad2010-01-15 19:15:51 +053031#include <asm/arch/spr_emi.h>
Vipin KUMAR566c9c12010-01-15 19:15:48 +053032#include <asm/arch/spr_defs.h>
33
34#define CPU 0
35#define DDR 1
36#define SRAM_REL 0xD2801000
37
38DECLARE_GLOBAL_DATA_PTR;
Vipin KUMAR566c9c12010-01-15 19:15:48 +053039
Vipin KUMAR8026b1e2012-05-07 13:06:41 +053040#if defined(CONFIG_CMD_NET)
41static int i2c_read_mac(uchar *buffer);
42#endif
43
Vipin KUMAR566c9c12010-01-15 19:15:48 +053044int dram_init(void)
45{
Amit Virdi5cca72f2012-05-07 13:06:39 +053046 /* Store complete RAM size and return */
Shiraz Hashima39fcfb2011-06-11 21:32:57 +000047 gd->ram_size = get_ram_size(PHYS_SDRAM_1, PHYS_SDRAM_1_MAXSIZE);
Vipin KUMAR566c9c12010-01-15 19:15:48 +053048
Vipin KUMAR566c9c12010-01-15 19:15:48 +053049 return 0;
50}
51
Shiraz Hashima39fcfb2011-06-11 21:32:57 +000052void 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 Virdi0b7ff3f2012-05-07 13:06:49 +053058int board_early_init_f()
59{
60#if defined(CONFIG_ST_SMI)
61 smi_init();
62#endif
63 return 0;
64}
Vipin KUMAR566c9c12010-01-15 19:15:48 +053065int misc_init_r(void)
66{
Vipin KUMARf92994f2010-01-15 19:15:49 +053067#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 KUMAR566c9c12010-01-15 19:15:48 +053073 setenv("verify", "n");
74
75#if defined(CONFIG_SPEAR_USBTTY)
76 setenv("stdin", "usbtty");
77 setenv("stdout", "usbtty");
78 setenv("stderr", "usbtty");
79#endif
80 return 0;
81}
82
Vipin KUMAR4bfacad2010-01-15 19:15:51 +053083#ifdef CONFIG_SPEAR_EMI
84struct cust_emi_para {
85 unsigned int tap;
86 unsigned int tsdp;
87 unsigned int tdpw;
88 unsigned int tdpr;
89 unsigned int tdcs;
90};
91
92/* EMI timing setting of m28w640hc of linux kernel */
93const struct cust_emi_para emi_timing_m28w640hc = {
94 .tap = 0x10,
95 .tsdp = 0x05,
96 .tdpw = 0x0a,
97 .tdpr = 0x0a,
98 .tdcs = 0x05,
99};
100
101/* EMI timing setting of bootrom */
102const struct cust_emi_para emi_timing_bootrom = {
103 .tap = 0xf,
104 .tsdp = 0x0,
105 .tdpw = 0xff,
106 .tdpr = 0x111,
107 .tdcs = 0x02,
108};
109
110void spear_emi_init(void)
111{
112 const struct cust_emi_para *p = &emi_timing_m28w640hc;
113 struct emi_regs *emi_regs_p = (struct emi_regs *)CONFIG_SPEAR_EMIBASE;
114 unsigned int cs;
115 unsigned int val, tmp;
116
117 val = readl(CONFIG_SPEAR_RASBASE);
118
119 if (val & EMI_ACKMSK)
120 tmp = 0x3f;
121 else
122 tmp = 0x0;
123
124 writel(tmp, &emi_regs_p->ack);
125
126 for (cs = 0; cs < CONFIG_SYS_MAX_FLASH_BANKS; cs++) {
127 writel(p->tap, &emi_regs_p->bank_regs[cs].tap);
128 writel(p->tsdp, &emi_regs_p->bank_regs[cs].tsdp);
129 writel(p->tdpw, &emi_regs_p->bank_regs[cs].tdpw);
130 writel(p->tdpr, &emi_regs_p->bank_regs[cs].tdpr);
131 writel(p->tdcs, &emi_regs_p->bank_regs[cs].tdcs);
132 writel(EMI_CNTL_ENBBYTERW | ((val & 0x18) >> 3),
133 &emi_regs_p->bank_regs[cs].control);
134 }
135}
136#endif
137
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530138int spear_board_init(ulong mach_type)
139{
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530140 gd->bd->bi_arch_number = mach_type;
141
142 /* adress of boot parameters */
143 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
144
Vipin KUMAR4bfacad2010-01-15 19:15:51 +0530145#ifdef CONFIG_SPEAR_EMI
146 spear_emi_init();
147#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530148 return 0;
149}
150
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530151#if defined(CONFIG_CMD_NET)
Vipin KUMARf92994f2010-01-15 19:15:49 +0530152static int i2c_read_mac(uchar *buffer)
153{
154 u8 buf[2];
155
156 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
157
158 /* Check if mac in i2c memory is valid */
159 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
160 /* Valid mac address is saved in i2c eeprom */
161 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
162 return 0;
163 }
164
165 return -1;
166}
167
168static int write_mac(uchar *mac)
169{
170 u8 buf[2];
171
172 buf[0] = (u8)MAGIC_BYTE0;
173 buf[1] = (u8)MAGIC_BYTE1;
174 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
175
176 buf[0] = (u8)~MAGIC_BYTE0;
177 buf[1] = (u8)~MAGIC_BYTE1;
178
179 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
180
181 /* check if valid MAC address is saved in I2C EEPROM or not? */
182 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
183 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
184 puts("I2C EEPROM written with mac address \n");
185 return 0;
186 }
187
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530188 puts("I2C EEPROM writing failed\n");
Vipin KUMARf92994f2010-01-15 19:15:49 +0530189 return -1;
190}
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530191#endif
Vipin KUMARf92994f2010-01-15 19:15:49 +0530192
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200193int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530194{
195 void (*sram_setfreq) (unsigned int, unsigned int);
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530196 unsigned int frequency;
197#if defined(CONFIG_CMD_NET)
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530198 unsigned char mac[6];
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530199#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530200
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200201 if ((argc > 3) || (argc < 2))
202 return cmd_usage(cmdtp);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530203
204 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
205
206 frequency = simple_strtoul(argv[2], NULL, 0);
207
208 if (frequency > 333) {
209 printf("Frequency is limited to 333MHz\n");
210 return 1;
211 }
212
213 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
214
215 if (!strcmp(argv[1], "cpufreq")) {
216 sram_setfreq(CPU, frequency);
217 printf("CPU frequency changed to %u\n", frequency);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530218 } else {
219 sram_setfreq(DDR, frequency);
220 printf("DDR frequency changed to %u\n", frequency);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530221 }
222
223 return 0;
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530224
225#if defined(CONFIG_CMD_NET)
Vipin KUMARf92994f2010-01-15 19:15:49 +0530226 } else if (!strcmp(argv[1], "ethaddr")) {
227
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530228 u32 reg;
229 char *e, *s = argv[2];
Vipin KUMARf92994f2010-01-15 19:15:49 +0530230 for (reg = 0; reg < 6; ++reg) {
231 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
232 if (s)
233 s = (*e) ? e + 1 : e;
234 }
235 write_mac(mac);
236
237 return 0;
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530238#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530239 } else if (!strcmp(argv[1], "print")) {
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530240#if defined(CONFIG_CMD_NET)
Vipin KUMARf92994f2010-01-15 19:15:49 +0530241 if (!i2c_read_mac(mac)) {
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530242 printf("Ethaddr (from i2c mem) = %pM\n", mac);
Vipin KUMARf92994f2010-01-15 19:15:49 +0530243 } else {
244 printf("Ethaddr (from i2c mem) = Not set\n");
245 }
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530246#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530247 return 0;
248 }
249
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200250 return cmd_usage(cmdtp);
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530251}
252
253U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
254 "configure chip",
255 "chip_config cpufreq/ddrfreq frequency\n"
Vipin KUMAR8026b1e2012-05-07 13:06:41 +0530256#if defined(CONFIG_CMD_NET)
257 "chip_config ethaddr XX:XX:XX:XX:XX:XX\n"
258#endif
Vipin KUMAR566c9c12010-01-15 19:15:48 +0530259 "chip_config print");