2 * (C) Copyright 2008-2009
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
6 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/ppc4xx_config.h>
17 static void print_configs(int cur_config_nr
)
21 for (i
= 0; i
< ppc4xx_config_count
; i
++) {
22 printf("%-16s - %s", ppc4xx_config_val
[i
].label
,
23 ppc4xx_config_val
[i
].description
);
24 if (i
== cur_config_nr
)
31 static int do_chip_config(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
35 int cur_config_nr
= -1;
36 u8 cur_config
[CONFIG_4xx_CONFIG_BLOCKSIZE
];
39 * First switch to correct I2C bus. This is I2C bus 0
40 * for all currently available 4xx derivats.
44 #ifdef CONFIG_CMD_EEPROM
45 ret
= eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
46 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
47 cur_config
, CONFIG_4xx_CONFIG_BLOCKSIZE
);
49 ret
= i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
50 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
51 1, cur_config
, CONFIG_4xx_CONFIG_BLOCKSIZE
);
54 printf("Error reading EEPROM at addr 0x%x\n",
55 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
60 * Search the current configuration
62 for (i
= 0; i
< ppc4xx_config_count
; i
++) {
63 if (memcmp(cur_config
, ppc4xx_config_val
[i
].val
,
64 CONFIG_4xx_CONFIG_BLOCKSIZE
) == 0)
68 if (cur_config_nr
== -1) {
69 printf("Warning: The I2C bootstrap values don't match any"
70 " of the available options!\n");
71 printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
72 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
73 for (i
= 0; i
< CONFIG_4xx_CONFIG_BLOCKSIZE
; i
++) {
74 printf("%02x ", cur_config
[i
]);
80 printf("Available configurations (I2C address 0x%02x):\n",
81 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
82 print_configs(cur_config_nr
);
86 for (i
= 0; i
< ppc4xx_config_count
; i
++) {
88 * Search for configuration name/label
90 if (strcmp(argv
[1], ppc4xx_config_val
[i
].label
) == 0) {
91 printf("Using configuration:\n%-16s - %s\n",
92 ppc4xx_config_val
[i
].label
,
93 ppc4xx_config_val
[i
].description
);
95 #ifdef CONFIG_CMD_EEPROM
96 ret
= eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
97 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
98 ppc4xx_config_val
[i
].val
,
99 CONFIG_4xx_CONFIG_BLOCKSIZE
);
101 ret
= i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
102 CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET
,
103 1, ppc4xx_config_val
[i
].val
,
104 CONFIG_4xx_CONFIG_BLOCKSIZE
);
106 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
* 1000);
108 printf("Error updating EEPROM at addr 0x%x\n",
109 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
);
113 printf("done (dump via 'i2c md %x 0.1 %x')\n",
114 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR
,
115 CONFIG_4xx_CONFIG_BLOCKSIZE
);
116 printf("Reset the board for the changes to"
122 printf("Configuration %s not found!\n", argv
[1]);
123 print_configs(cur_config_nr
);
128 chip_config
, 2, 0, do_chip_config
,
129 "program the I2C bootstrap EEPROM",