title: How to make Linux spi write multi-bytes in one transfer?
body: <p>I am using a kit of TI's AM3354, which is quite similar to Beagle Bone Black. And I test it, found that it can only send 4-bytes at most for one transfer, which I mean the spi-cs signal asserted and deasserted. 
  But when I change the variable <code>bits</code> to be more than 32 like below, the running result shows error.
  My question is how to make spi send 64 bits or even more bits for each spi transfer?
  Thanks!</p>
  
  <pre><code># ./a.out
  open device: /dev/spidev2.0
  set spi mode: 0
  set bits per word: 40
  set max speed: 48000000 Hz (48 MHz)
  can't send spi message
  : Invalid argument
  Aborted
  
  
  # ./a.out
  open device: /dev/spidev2.0
  set spi mode: 0
  set bits per word: 64
  set max speed: 48000000 Hz (48 MHz)
  can't send spi message
  : Invalid argument
  Aborted
  </code></pre>
  
  <p>The test code is below:</p>
  
  <pre><code>/*
   * SPI testing utility (using spidev driver)
   *
   * Copyright (c) 2007  MontaVista Software, Inc.
   * Copyright (c) 2007  Anton Vorontsov &lt;avorontsov@ru.mvista.com&gt;
   *
   * 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.
   *
   * Cross-compile with cross-gcc -I/path/to/cross-kernel/include
   */
  
  #include &lt;stdint.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;getopt.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;linux/types.h&gt;
  #include &lt;linux/spi/spidev.h&gt;
  
  #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  
  static void pabort(const char *s)
  {
      perror(s);
      abort();
  }
  
  static const char *device = "/dev/spidev2.0";
  static uint8_t mode;
  static uint8_t bits = 64;
  static uint32_t speed = 48000000;
  static uint16_t delay;
  
  static void transfer(int fd)
  {
      int ret;
      uint8_t tx[] = {0x31, 0x32, 0x12, 0x89,
                      0x33, 0x34, 0x35, 0x36};
      uint8_t rx[ARRAY_SIZE(tx)] = {0, }; //the comma here doesn't matter, tested by Tom Xue
      struct spi_ioc_transfer tr = {
          .tx_buf = (unsigned long)tx,
          .rx_buf = (unsigned long)rx,
          .len = ARRAY_SIZE(tx),
          .delay_usecs = delay,
          .speed_hz = speed,
          .bits_per_word = bits,  //important, bits = 8 means byte transfer is possible
      };
  
      ret = ioctl(fd, SPI_IOC_MESSAGE(1), &amp;tr);
      if (ret &lt; 1)
          pabort("can't send spi message\n");
  
      printf("the received data is below:\n");
      for (ret = 0; ret &lt; ARRAY_SIZE(tx); ret++) {    //print the received data, by Tom Xue
          if (!(ret % 6))
              puts("");
          printf("%.2X ", rx[ret]);
      }
      puts("");
  }
  
  int main(int argc, char *argv[])
  {
      int ret = 0;
      int fd;
  
      fd = open(device, O_RDWR);
      if (fd &lt; 0)
          pabort("can't open device\n");
  
      /*
       * spi mode
       */
      ret = ioctl(fd, SPI_IOC_WR_MODE, &amp;mode);
      if (ret == -1)
          pabort("can't set spi mode\n");
  
      ret = ioctl(fd, SPI_IOC_RD_MODE, &amp;mode);
      if (ret == -1)
          pabort("can't get spi mode\n");
  
      /*
       * bits per word
       */
      ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &amp;bits);
      if (ret == -1)
          pabort("can't set bits per word\n");
  
      ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &amp;bits);
      if (ret == -1)
          pabort("can't get bits per word\n");
  
      /*
       * max speed hz
       */
      ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &amp;speed);
      if (ret == -1)
          pabort("can't set max speed hz\n");
  
      ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &amp;speed);
      if (ret == -1)
          pabort("can't get max speed hz\n");
  
      printf("open device: %s\n", device);
      printf("set spi mode: %d\n", mode);
      printf("set bits per word: %d\n", bits);
      printf("set max speed: %d Hz (%d MHz)\n", speed, speed/1000000);
  
      while(1){
          transfer(fd);
          sleep(1);
      }
  
      close(fd);
  
      return ret;
  }
  </code></pre>