3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 * SPI Read/Write Utilities
33 #if (CONFIG_COMMANDS & CFG_CMD_SPI)
35 #define MAX_SPI_BYTES 32 /* max number of bytes we can handle */
38 * External table of chip select functions (see the appropriate board
39 * support for the actual definition of the table).
41 extern spi_chipsel_type spi_chipsel[];
45 * Values from last command.
49 static uchar dout[MAX_SPI_BYTES];
50 static uchar din[MAX_SPI_BYTES];
56 * spi {dev} {num_bits} {dout}
57 * {dev} is the device number for controlling chip select (see TBD)
58 * {num_bits} is the number of bits to send & receive (base 10)
59 * {dout} is a hexadecimal string of data to send
60 * The command prints out the hexadecimal string received via SPI.
63 int do_spi (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
71 * We use the last specified parameters, unless new ones are
75 if ((flag & CMD_FLAG_REPEAT) == 0)
78 device = simple_strtoul(argv[1], NULL, 10);
80 bitlen = simple_strtoul(argv[2], NULL, 10);
83 for(j = 0; *cp; j++, cp++) {
86 tmp -= ('A' - '0') - 10;
90 printf("Conversion error on %c, bailing out.\n", *cp);
94 dout[j / 2] = (tmp << 4);
100 printf("spi_chipsel[%d] = %08X\n", device, (uint)spi_chipsel[device]);
101 if(spi_xfer(spi_chipsel[device], bitlen, dout, din) != 0) {
102 printf("Error with the SPI transaction.\n");
106 for(j = 0; j < ((bitlen + 7) / 8); j++) {
107 printf("%02X", *cp++);
115 #endif /* CFG_CMD_SPI */