2 * (C) Copyright 2008-2009
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
6 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
31 #include <asm/ppc4xx_config.h>
34 static void print_configs(int cur_config_nr)
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)
48 static int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
52 int cur_config_nr = -1;
53 u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
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);
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);
65 printf("Error reading EEPROM at addr 0x%x\n",
66 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
71 * Search the current configuration
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)
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]);
91 printf("Available configurations (I2C address 0x%02x):\n",
92 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
93 print_configs(cur_config_nr);
97 for (i = 0; i < ppc4xx_config_count; i++) {
99 * Search for configuration name/label
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);
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);
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);
117 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
119 printf("Error updating EEPROM at addr 0x%x\n",
120 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
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"
133 printf("Configuration %s not found!\n", argv[1]);
134 print_configs(cur_config_nr);
139 chip_config, 2, 0, do_chip_config,
140 "program the I2C bootstrap EEPROM",