2
* atmel_df_pow2.c - convert Atmel Dataflashes to Power of 2 mode
4
* Copyright 2009 Analog Devices Inc.
6
* Licensed under the 2-clause BSD.
16
static int flash_cmd(struct spi_slave *slave, uchar cmd, uchar *buf, int len)
19
return spi_xfer(slave, 8 * len, buf, buf, SPI_XFER_BEGIN | SPI_XFER_END);
22
static int flash_status(struct spi_slave *slave)
25
if (flash_cmd(slave, CMD_STAT, buf, sizeof(buf)))
30
static int flash_set_pow2(struct spi_slave *slave)
39
ret = flash_cmd(slave, CMD_CFG, buf, sizeof(buf));
43
/* wait Tp, or 6 msec */
46
ret = flash_status(slave);
50
return ret & 0x1 ? 0 : 1;
53
static int flash_check(struct spi_slave *slave)
58
ret = flash_cmd(slave, CMD_ID, buf, sizeof(buf));
63
printf("atmel flash not found (id[0] = %#x)\n", buf[1]);
67
if ((buf[2] >> 5) != 0x1) {
68
printf("AT45 flash not found (id[0] = %#x)\n", buf[2]);
75
static char *getline(void)
77
static char buffer[100];
88
case '\r': /* Enter/Return key */
93
case 0x03: /* ^C - break */
97
case 0x08: /* ^H - backspace */
98
case 0x7F: /* DEL - backspace */
106
/* Ignore control characters */
109
/* Queue up all other characters */
117
int atmel_df_pow2(int argc, char *argv[])
119
/* Print the ABI version */
121
if (XF_VERSION != get_version()) {
122
printf("Expects ABI version %d\n", XF_VERSION);
123
printf("Actual U-Boot ABI version %lu\n", get_version());
124
printf("Can't run\n\n");
131
struct spi_slave *slave;
135
puts("\nenter the [BUS:]CS of the SPI flash: ");
144
bus = cs = simple_strtoul(line, &p, 10);
148
cs = simple_strtoul(p, &p, 10);
151
puts("invalid format, please try again\n");
157
printf("\ngoing to work with dataflash at %i:%i\n", bus, cs);
159
/* use a low speed -- it'll work with all devices, and
160
* speed here doesn't really matter.
162
slave = spi_setup_slave(bus, cs, 1000, SPI_MODE_3);
164
puts("unable to setup slave\n");
168
if (spi_claim_bus(slave)) {
169
spi_free_slave(slave);
173
if (flash_check(slave)) {
174
puts("no flash found\n");
178
status = flash_status(slave);
180
puts("unable to read status register\n");
184
puts("flash is already in power-of-2 mode!\n");
188
puts("are you sure you wish to set power-of-2 mode?\n");
189
puts("this operation is permanent and irreversible\n");
190
printf("enter YES to continue: ");
192
if (!line || strcmp(line, "YES"))
195
if (flash_set_pow2(slave)) {
196
puts("setting pow2 mode failed\n");
201
"Configuration should be updated now. You will have to\n"
202
"power cycle the part in order to finish the conversion.\n"
206
spi_release_bus(slave);
207
spi_free_slave(slave);