+static int do_spi_xfer(int bus, int cs)
+{
+ struct spi_slave *slave;
+ int rcode = 0;
+
+ slave = spi_setup_slave(bus, cs, 1000000, mode);
+ if (!slave) {
+ printf("Invalid device %d:%d\n", bus, cs);
+ return -EINVAL;
+ }
+
+ spi_claim_bus(slave);
+ if (spi_xfer(slave, bitlen, dout, din,
+ SPI_XFER_BEGIN | SPI_XFER_END) != 0) {
+ printf("Error during SPI transaction\n");
+ rcode = -EIO;
+ } else {
+ int j;
+
+ for (j = 0; j < ((bitlen + 7) / 8); j++)
+ printf("%02X", din[j]);
+ printf("\n");
+ }
+ spi_release_bus(slave);
+ spi_free_slave(slave);
+
+ return rcode;
+}
+