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
];
56 * First switch to correct I2C bus. This is I2C bus 0
57 * for all currently available 4xx derivats.
61 #ifdef CONFIG_CMD_EEPROM
62 ret
= eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
63 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
64 cur_config
, CONFIG_4xx_CONFIG_BLOCKSIZE
);
66 ret
= i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
67 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
68 1, cur_config
, CONFIG_4xx_CONFIG_BLOCKSIZE
);
71 printf("Error reading EEPROM at addr 0x%x\n",
72 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
77 * Search the current configuration
79 for (i
= 0; i
< ppc4xx_config_count
; i
++) {
80 if (memcmp(cur_config
, ppc4xx_config_val
[i
].val
,
81 CONFIG_4xx_CONFIG_BLOCKSIZE
) == 0)
85 if (cur_config_nr
== -1) {
86 printf("Warning: The I2C bootstrap values don't match any"
87 " of the available options!\n");
88 printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
89 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
90 for (i
= 0; i
< CONFIG_4xx_CONFIG_BLOCKSIZE
; i
++) {
91 printf("%02x ", cur_config
[i
]);
97 printf("Available configurations (I2C address 0x%02x):\n",
98 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
99 print_configs(cur_config_nr
);
103 for (i
= 0; i
< ppc4xx_config_count
; i
++) {
105 * Search for configuration name/label
107 if (strcmp(argv
[1], ppc4xx_config_val
[i
].label
) == 0) {
108 printf("Using configuration:\n%-16s - %s\n",
109 ppc4xx_config_val
[i
].label
,
110 ppc4xx_config_val
[i
].description
);
112 #ifdef CONFIG_CMD_EEPROM
113 ret
= eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
114 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
115 ppc4xx_config_val
[i
].val
,
116 CONFIG_4xx_CONFIG_BLOCKSIZE
);
118 ret
= i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
119 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
120 1, ppc4xx_config_val
[i
].val
,
121 CONFIG_4xx_CONFIG_BLOCKSIZE
);
123 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
* 1000);
125 printf("Error updating EEPROM at addr 0x%x\n",
126 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
130 printf("done (dump via 'i2c md %x 0.1 %x')\n",
131 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
132 CONFIG_4xx_CONFIG_BLOCKSIZE
);
133 printf("Reset the board for the changes to"
139 printf("Configuration %s not found!\n", argv
[1]);
140 print_configs(cur_config_nr
);
145 chip_config
, 2, 0, do_chip_config
,
146 "program the I2C bootstrap EEPROM",