1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 * const argv[])
49{
50 int i;
51 int ret;
52 int cur_config_nr = -1;
53 u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
54
55
56
57
58
59 I2C_SET_BUS(0);
60
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);
65#else
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);
69#endif
70 if (ret) {
71 printf("Error reading EEPROM at addr 0x%x\n",
72 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
73 return -1;
74 }
75
76
77
78
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)
82 cur_config_nr = i;
83 }
84
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]);
92 }
93 printf("\n");
94 }
95
96 if (argc < 2) {
97 printf("Available configurations (I2C address 0x%02x):\n",
98 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
99 print_configs(cur_config_nr);
100 return 0;
101 }
102
103 for (i = 0; i < ppc4xx_config_count; i++) {
104
105
106
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);
111
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);
117#else
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);
122#endif
123 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
124 if (ret) {
125 printf("Error updating EEPROM at addr 0x%x\n",
126 CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
127 return -1;
128 }
129
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"
134 " take effect\n");
135 return 0;
136 }
137 }
138
139 printf("Configuration %s not found!\n", argv[1]);
140 print_configs(cur_config_nr);
141 return -1;
142}
143
144U_BOOT_CMD(
145 chip_config, 2, 0, do_chip_config,
146 "program the I2C bootstrap EEPROM",
147 "[config-label]"
148);
149