Merge commit 'upstream/master'
[platform/kernel/u-boot.git] / board / amcc / sequoia / cmd_sequoia.c
1 /*
2  * (C) Copyright 2007
3  * Stefan Roese, DENX Software Engineering, sr@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  *
23  */
24
25 #include <common.h>
26 #include <command.h>
27 #include <i2c.h>
28
29 static u8 boot_533_nor[] = {
30         0x87, 0x78, 0x82, 0x52, 0x09, 0x57, 0xa0, 0x30,
31         0x40, 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
32 };
33
34 static u8 boot_533_nand[] = {
35         0x87, 0x78, 0x82, 0x52, 0x09, 0x57, 0xd0, 0x10,
36         0xa0, 0x68, 0x23, 0x58, 0x0d, 0x05, 0x00, 0x00
37 };
38
39 static u8 boot_667_nor[] = {
40         0x87, 0x78, 0xa2, 0x52, 0x09, 0xd7, 0xa0, 0x30,
41         0x40, 0x08, 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
42 };
43
44 static u8 boot_667_nand[] = {
45         0x87, 0x78, 0xa2, 0x52, 0x09, 0xd7, 0xd0, 0x10,
46         0xa0, 0x68, 0x23, 0x58, 0x0d, 0x05, 0x00, 0x00
47 };
48
49 static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50 {
51         u8 chip;
52         u8 *buf;
53         int cpu_freq;
54
55         if (argc < 3) {
56                 printf("Usage:\n%s\n", cmdtp->usage);
57                 return 1;
58         }
59
60         cpu_freq = simple_strtol(argv[1], NULL, 10);
61         if (!((cpu_freq == 533) || (cpu_freq == 667))) {
62                 printf("Unsupported cpu-frequency - only 533 and 667 supported\n");
63                 return 1;
64         }
65
66         /* use 0x52 as I2C EEPROM address for now */
67         chip = 0x52;
68
69         if ((strcmp(argv[2], "nor") != 0) &&
70             (strcmp(argv[2], "nand") != 0)) {
71                 printf("Unsupported boot-device - only nor|nand support\n");
72                 return 1;
73         }
74
75         if (strcmp(argv[2], "nand") == 0) {
76                 switch (cpu_freq) {
77                 default:
78                 case 533:
79                         buf = boot_533_nand;
80                         break;
81                 case 667:
82                         buf = boot_667_nand;
83                         break;
84                 }
85         } else {
86                 switch (cpu_freq) {
87                 default:
88                 case 533:
89                         buf = boot_533_nor;
90                         break;
91                 case 667:
92                         buf = boot_667_nor;
93                         break;
94                 }
95         }
96
97         if (i2c_write(chip, 0, 1, buf, 16) != 0)
98                 printf("Error writing to EEPROM at address 0x%x\n", chip);
99         udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
100
101         printf("Done\n");
102         printf("Please power-cycle the board for the changes to take effect\n");
103
104         return 0;
105 }
106
107 U_BOOT_CMD(
108         bootstrap,      3,      0,      do_bootstrap,
109         "bootstrap - program the I2C bootstrap EEPROM\n",
110         "<cpu-freq> <nor|nand> - program the I2C bootstrap EEPROM\n"
111         );