blob: d360d5beecee6ef914da32cc2e37f1d15ac1d9f6 [file] [log] [blame]
Stefan Roese87c0b722009-07-20 06:57:27 +02001/*
2 * (C) Copyright 2008-2009
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * (C) Copyright 2009
6 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 *
26 */
27
28#include <common.h>
29#include <command.h>
30#include <i2c.h>
31#include <asm/ppc4xx_config.h>
32#include <asm/io.h>
33
34static void print_configs(int cur_config_nr)
35{
36 int i;
37
38 for (i = 0; i < ppc4xx_config_count; i++) {
39 printf("%-16s - %s", ppc4xx_config_val[i].label,
40 ppc4xx_config_val[i].description);
41 if (i == cur_config_nr)
42 printf(" ***");
43 printf("\n");
44 }
45
46}
47
48static int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
49{
50 int i;
51 int ret;
52 int cur_config_nr = -1;
53 u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
54
55#ifdef CONFIG_CMD_EEPROM
56 ret = eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
57 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
58 cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
59#else
60 ret = i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
61 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
62 1, cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
63#endif
64 if (ret) {
65 printf("Error reading EEPROM at addr 0x%x\n",
66 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
67 return -1;
68 }
69
70 /*
71 * Search the current configuration
72 */
73 for (i = 0; i < ppc4xx_config_count; i++) {
74 if (memcmp(cur_config, ppc4xx_config_val[i].val,
75 CONFIG_4xx_CONFIG_BLOCKSIZE) == 0)
76 cur_config_nr = i;
77 }
78
79 if (cur_config_nr == -1) {
80 printf("Warning: The I2C bootstrap values don't match any"
81 " of the available options!\n");
82 printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
83 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
84 for (i = 0; i < CONFIG_4xx_CONFIG_BLOCKSIZE; i++) {
85 printf("%02x ", cur_config[i]);
86 }
87 printf("\n");
88 }
89
90 if (argc < 2) {
91 printf("Available configurations (I2C address 0x%02x):\n",
92 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
93 print_configs(cur_config_nr);
94 return 0;
95 }
96
97 for (i = 0; i < ppc4xx_config_count; i++) {
98 /*
99 * Search for configuration name/label
100 */
101 if (strcmp(argv[1], ppc4xx_config_val[i].label) == 0) {
102 printf("Using configuration:\n%-16s - %s\n",
103 ppc4xx_config_val[i].label,
104 ppc4xx_config_val[i].description);
105
106#ifdef CONFIG_CMD_EEPROM
107 ret = eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
108 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
109 ppc4xx_config_val[i].val,
110 CONFIG_4xx_CONFIG_BLOCKSIZE);
111#else
112 ret = i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
113 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
114 1, ppc4xx_config_val[i].val,
115 CONFIG_4xx_CONFIG_BLOCKSIZE);
116#endif
117 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
118 if (ret) {
119 printf("Error updating EEPROM at addr 0x%x\n",
120 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
121 return -1;
122 }
123
124 printf("done (dump via 'i2c md %x 0.1 %x')\n",
125 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
126 CONFIG_4xx_CONFIG_BLOCKSIZE);
127 printf("Reset the board for the changes to"
128 " take effect\n");
129 return 0;
130 }
131 }
132
133 printf("Configuration %s not found!\n", argv[1]);
134 print_configs(cur_config_nr);
135 return -1;
136}
137
138U_BOOT_CMD(
139 chip_config, 2, 0, do_chip_config,
140 "program the I2C bootstrap EEPROM",
141 "[config-label]"
142);