blob: 9eaf1524b28e847d2a8ca35fc5d1fb82164c5fd9 [file] [log] [blame]
/*
* (C) Copyright 2002
* Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/*
* SPI Read/Write Utilities
*/
#include <common.h>
#include <command.h>
#include <spi.h>
#if (CONFIG_COMMANDS & CFG_CMD_SPI)
#ifndef MAX_SPI_BYTES
# define MAX_SPI_BYTES 32 /* Maximum number of bytes we can handle */
#endif
static uchar dout[MAX_SPI_BYTES];
static uchar din[MAX_SPI_BYTES];
int do_spi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
int rcode = 0;
int i;
int cs;
int len;
if (argc < 3)
{
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
if (strcmp(argv[1],"read") == 0) {
cs = simple_strtoul(argv[2], NULL, 10);
if(argc == 4)
{
len = simple_strtoul(argv[3], NULL, 16);
}
else
{
printf ("Usage:\n%s\n", cmdtp->usage);
}
printf("Read cs %d: ",cs);
for(i = 0; i < len; i++)
{
c2k_spi_read(cs, &dout, 1);
printf("%02x ",dout[0]);
}
printf("\n");
}
else if (strcmp(argv[1],"write") == 0) {
cs = simple_strtoul(argv[2], NULL, 10);
printf("Write cs %d: ",cs);
for (i = 3; i < argc; i++)
{
din[0] = simple_strtoul(argv[i], NULL, 16);
c2k_spi_write(cs, &din, 1);
printf("%02x ",din[0]);
}
printf("\n");
}
else
{
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
}
/***************************************************/
U_BOOT_CMD(
spi, 32, 1, do_spi,
"spi - SPI utility commands\n",
"spi read chipselect len - Read len number of bytes from the SPI device \n"
"spi write chipselect byte0 <byte1> <byte2> ... - Write bytes to the SPI device\n"
);
#endif