]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/amcc/acadia/cmd_acadia.c
cmd_usage(): simplify return code handling
[people/ms/u-boot.git] / board / amcc / acadia / cmd_acadia.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_267_nor[] = {
30 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x00,
31 0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00
33 };
34
35 static u8 boot_267_nand[] = {
36 0xd0, 0x38, 0xc3, 0x50, 0x13, 0x88, 0x8e, 0x00,
37 0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00
39 };
40
41 static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
42 {
43 u8 chip;
44 u8 *buf;
45 int cpu_freq;
46
47 if (argc < 3)
48 return cmd_usage(cmdtp);
49
50 cpu_freq = simple_strtol(argv[1], NULL, 10);
51 if (cpu_freq != 267) {
52 printf("Unsupported cpu-frequency - only 267 supported\n");
53 return 1;
54 }
55
56 /* use 0x50 as I2C EEPROM address for now */
57 chip = 0x50;
58
59 if ((strcmp(argv[2], "nor") != 0) &&
60 (strcmp(argv[2], "nand") != 0)) {
61 printf("Unsupported boot-device - only nor|nand support\n");
62 return 1;
63 }
64
65 if (strcmp(argv[2], "nand") == 0) {
66 switch (cpu_freq) {
67 case 267:
68 buf = boot_267_nand;
69 break;
70 default:
71 break;
72 }
73 } else {
74 switch (cpu_freq) {
75 case 267:
76 buf = boot_267_nor;
77 break;
78 default:
79 break;
80 }
81 }
82
83 if (i2c_write(chip, 0, 1, buf, 16) != 0)
84 printf("Error writing to EEPROM at address 0x%x\n", chip);
85 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
86 if (i2c_write(chip, 0x10, 1, buf+16, 4) != 0)
87 printf("Error2 writing to EEPROM at address 0x%x\n", chip);
88
89 printf("Done\n");
90 printf("Please power-cycle the board for the changes to take effect\n");
91
92 return 0;
93 }
94
95 U_BOOT_CMD(
96 bootstrap, 3, 0, do_bootstrap,
97 "program the I2C bootstrap EEPROM",
98 "<cpu-freq> <nor|nand> - program the I2C bootstrap EEPROM"
99 );