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_xloader_table.h>
31 #include <asm/arch/spr_defs.h>
35 #define SRAM_REL 0xD2801000
37 DECLARE_GLOBAL_DATA_PTR;
38 static struct chip_data chip_data;
42 struct xloader_table *xloader_tb =
43 (struct xloader_table *)XLOADER_TABLE_ADDRESS;
44 struct xloader_table_1_1 *table_1_1;
45 struct xloader_table_1_2 *table_1_2;
46 struct chip_data *chip = &chip_data;
48 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
49 gd->bd->bi_dram[0].size = get_ram_size(PHYS_SDRAM_1,
50 PHYS_SDRAM_1_MAXSIZE);
52 if (XLOADER_TABLE_VERSION_1_1 == xloader_tb->table_version) {
53 table_1_1 = &xloader_tb->table.table_1_1;
54 chip->dramfreq = table_1_1->ddrfreq;
55 chip->dramtype = table_1_1->ddrtype;
57 } else if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) {
58 table_1_2 = &xloader_tb->table.table_1_2;
59 chip->dramfreq = table_1_2->ddrfreq;
60 chip->dramtype = table_1_2->ddrtype;
70 #if defined(CONFIG_CMD_NET)
73 if (!eth_getenv_enetaddr("ethaddr", mac_id) && !i2c_read_mac(mac_id))
74 eth_setenv_enetaddr("ethaddr", mac_id);
76 setenv("verify", "n");
78 #if defined(CONFIG_SPEAR_USBTTY)
79 setenv("stdin", "usbtty");
80 setenv("stdout", "usbtty");
81 setenv("stderr", "usbtty");
86 int spear_board_init(ulong mach_type)
88 struct xloader_table *xloader_tb =
89 (struct xloader_table *)XLOADER_TABLE_ADDRESS;
90 struct xloader_table_1_2 *table_1_2;
91 struct chip_data *chip = &chip_data;
93 gd->bd->bi_arch_number = mach_type;
95 /* adress of boot parameters */
96 gd->bd->bi_boot_params = CONFIG_BOOT_PARAMS_ADDR;
98 /* CPU is initialized to work at 333MHz in Xloader */
101 if (XLOADER_TABLE_VERSION_1_2 == xloader_tb->table_version) {
102 table_1_2 = &xloader_tb->table.table_1_2;
103 memcpy(chip->version, table_1_2->version,
104 sizeof(chip->version));
110 static int i2c_read_mac(uchar *buffer)
114 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
116 /* Check if mac in i2c memory is valid */
117 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
118 /* Valid mac address is saved in i2c eeprom */
119 i2c_read(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, buffer, MAC_LEN);
126 static int write_mac(uchar *mac)
130 buf[0] = (u8)MAGIC_BYTE0;
131 buf[1] = (u8)MAGIC_BYTE1;
132 i2c_write(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
134 buf[0] = (u8)~MAGIC_BYTE0;
135 buf[1] = (u8)~MAGIC_BYTE1;
137 i2c_read(CONFIG_I2C_CHIPADDRESS, MAGIC_OFF, 1, buf, MAGIC_LEN);
139 /* check if valid MAC address is saved in I2C EEPROM or not? */
140 if ((buf[0] == MAGIC_BYTE0) && (buf[1] == MAGIC_BYTE1)) {
141 i2c_write(CONFIG_I2C_CHIPADDRESS, MAC_OFF, 1, mac, MAC_LEN);
142 puts("I2C EEPROM written with mac address \n");
146 puts("I2C EEPROM writing failed \n");
150 int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
152 void (*sram_setfreq) (unsigned int, unsigned int);
153 struct chip_data *chip = &chip_data;
154 unsigned char mac[6];
155 unsigned int reg, frequency;
159 if ((argc > 3) || (argc < 2)) {
164 if ((!strcmp(argv[1], "cpufreq")) || (!strcmp(argv[1], "ddrfreq"))) {
166 frequency = simple_strtoul(argv[2], NULL, 0);
168 if (frequency > 333) {
169 printf("Frequency is limited to 333MHz\n");
173 sram_setfreq = memcpy((void *)SRAM_REL, setfreq, setfreq_sz);
175 if (!strcmp(argv[1], "cpufreq")) {
176 sram_setfreq(CPU, frequency);
177 printf("CPU frequency changed to %u\n", frequency);
179 chip->cpufreq = frequency;
181 sram_setfreq(DDR, frequency);
182 printf("DDR frequency changed to %u\n", frequency);
184 chip->dramfreq = frequency;
188 } else if (!strcmp(argv[1], "ethaddr")) {
191 for (reg = 0; reg < 6; ++reg) {
192 mac[reg] = s ? simple_strtoul(s, &e, 16) : 0;
194 s = (*e) ? e + 1 : e;
199 } else if (!strcmp(argv[1], "print")) {
201 if (chip->cpufreq == -1)
202 printf("CPU Freq = Not Known\n");
204 printf("CPU Freq = %d MHz\n", chip->cpufreq);
206 if (chip->dramfreq == -1)
207 printf("DDR Freq = Not Known\n");
209 printf("DDR Freq = %d MHz\n", chip->dramfreq);
211 if (chip->dramtype == DDRMOBILE)
212 printf("DDR Type = MOBILE\n");
213 else if (chip->dramtype == DDR2)
214 printf("DDR Type = DDR2\n");
216 printf("DDR Type = Not Known\n");
218 if (!i2c_read_mac(mac)) {
219 sprintf(i2c_mac, "%pM", mac);
220 printf("Ethaddr (from i2c mem) = %s\n", i2c_mac);
222 printf("Ethaddr (from i2c mem) = Not set\n");
225 printf("Xloader Rev = %s\n", chip->version);
234 U_BOOT_CMD(chip_config, 3, 1, do_chip_config,
236 "chip_config cpufreq/ddrfreq frequency\n"
237 "chip_config print");