diff options
| author | Geert Uytterhoeven <geert+renesas@linux-m68k.org> | 2014-02-25 05:40:18 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@linaro.org> | 2014-02-26 23:51:29 -0500 |
| commit | c2e78c34ef0bf4fa860b5fffc99c769d6ddaf52d (patch) | |
| tree | 774f1048676e84b5c4d73394dd8f643ee706cd5c | |
| parent | dc64d39b54c1e9db97a6fb1ca52598c981728157 (diff) | |
spi: spidev_test: Add support for Dual/Quad SPI Transfers
Signed-off-by: Geert Uytterhoeven <geert+renesas@linux-m68k.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
| -rw-r--r-- | Documentation/spi/spidev_test.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index efd7385e907f..3a2f9d59edab 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c | |||
| @@ -30,7 +30,7 @@ static void pabort(const char *s) | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | static const char *device = "/dev/spidev1.1"; | 32 | static const char *device = "/dev/spidev1.1"; |
| 33 | static uint8_t mode; | 33 | static uint32_t mode; |
| 34 | static uint8_t bits = 8; | 34 | static uint8_t bits = 8; |
| 35 | static uint32_t speed = 500000; | 35 | static uint32_t speed = 500000; |
| 36 | static uint16_t delay; | 36 | static uint16_t delay; |
| @@ -57,6 +57,21 @@ static void transfer(int fd) | |||
| 57 | .bits_per_word = bits, | 57 | .bits_per_word = bits, |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | if (mode & SPI_TX_QUAD) | ||
| 61 | tr.tx_nbits = 4; | ||
| 62 | else if (mode & SPI_TX_DUAL) | ||
| 63 | tr.tx_nbits = 2; | ||
| 64 | if (mode & SPI_RX_QUAD) | ||
| 65 | tr.rx_nbits = 4; | ||
| 66 | else if (mode & SPI_RX_DUAL) | ||
| 67 | tr.rx_nbits = 2; | ||
| 68 | if (!(mode & SPI_LOOP)) { | ||
| 69 | if (mode & (SPI_TX_QUAD | SPI_TX_DUAL)) | ||
| 70 | tr.rx_buf = 0; | ||
| 71 | else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL)) | ||
| 72 | tr.tx_buf = 0; | ||
| 73 | } | ||
| 74 | |||
| 60 | ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); | 75 | ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); |
| 61 | if (ret < 1) | 76 | if (ret < 1) |
| 62 | pabort("can't send spi message"); | 77 | pabort("can't send spi message"); |
| @@ -83,7 +98,9 @@ static void print_usage(const char *prog) | |||
| 83 | " -C --cs-high chip select active high\n" | 98 | " -C --cs-high chip select active high\n" |
| 84 | " -3 --3wire SI/SO signals shared\n" | 99 | " -3 --3wire SI/SO signals shared\n" |
| 85 | " -N --no-cs no chip select\n" | 100 | " -N --no-cs no chip select\n" |
| 86 | " -R --ready slave pulls low to pause\n"); | 101 | " -R --ready slave pulls low to pause\n" |
| 102 | " -2 --dual dual transfer\n" | ||
| 103 | " -4 --quad quad transfer\n"); | ||
| 87 | exit(1); | 104 | exit(1); |
| 88 | } | 105 | } |
| 89 | 106 | ||
| @@ -103,11 +120,13 @@ static void parse_opts(int argc, char *argv[]) | |||
| 103 | { "3wire", 0, 0, '3' }, | 120 | { "3wire", 0, 0, '3' }, |
| 104 | { "no-cs", 0, 0, 'N' }, | 121 | { "no-cs", 0, 0, 'N' }, |
| 105 | { "ready", 0, 0, 'R' }, | 122 | { "ready", 0, 0, 'R' }, |
| 123 | { "dual", 0, 0, '2' }, | ||
| 124 | { "quad", 0, 0, '4' }, | ||
| 106 | { NULL, 0, 0, 0 }, | 125 | { NULL, 0, 0, 0 }, |
| 107 | }; | 126 | }; |
| 108 | int c; | 127 | int c; |
| 109 | 128 | ||
| 110 | c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR", lopts, NULL); | 129 | c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR24", lopts, NULL); |
| 111 | 130 | ||
| 112 | if (c == -1) | 131 | if (c == -1) |
| 113 | break; | 132 | break; |
| @@ -149,11 +168,23 @@ static void parse_opts(int argc, char *argv[]) | |||
| 149 | case 'R': | 168 | case 'R': |
| 150 | mode |= SPI_READY; | 169 | mode |= SPI_READY; |
| 151 | break; | 170 | break; |
| 171 | case '2': | ||
| 172 | mode |= SPI_TX_DUAL; | ||
| 173 | break; | ||
| 174 | case '4': | ||
| 175 | mode |= SPI_TX_QUAD; | ||
| 176 | break; | ||
| 152 | default: | 177 | default: |
| 153 | print_usage(argv[0]); | 178 | print_usage(argv[0]); |
| 154 | break; | 179 | break; |
| 155 | } | 180 | } |
| 156 | } | 181 | } |
| 182 | if (mode & SPI_LOOP) { | ||
| 183 | if (mode & SPI_TX_DUAL) | ||
| 184 | mode |= SPI_RX_DUAL; | ||
| 185 | if (mode & SPI_TX_QUAD) | ||
| 186 | mode |= SPI_RX_QUAD; | ||
| 187 | } | ||
| 157 | } | 188 | } |
| 158 | 189 | ||
| 159 | int main(int argc, char *argv[]) | 190 | int main(int argc, char *argv[]) |
| @@ -170,11 +201,11 @@ int main(int argc, char *argv[]) | |||
| 170 | /* | 201 | /* |
| 171 | * spi mode | 202 | * spi mode |
| 172 | */ | 203 | */ |
| 173 | ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); | 204 | ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode); |
| 174 | if (ret == -1) | 205 | if (ret == -1) |
| 175 | pabort("can't set spi mode"); | 206 | pabort("can't set spi mode"); |
| 176 | 207 | ||
| 177 | ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); | 208 | ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode); |
| 178 | if (ret == -1) | 209 | if (ret == -1) |
| 179 | pabort("can't get spi mode"); | 210 | pabort("can't get spi mode"); |
| 180 | 211 | ||
| @@ -200,7 +231,7 @@ int main(int argc, char *argv[]) | |||
| 200 | if (ret == -1) | 231 | if (ret == -1) |
| 201 | pabort("can't get max speed hz"); | 232 | pabort("can't get max speed hz"); |
| 202 | 233 | ||
| 203 | printf("spi mode: %d\n", mode); | 234 | printf("spi mode: 0x%x\n", mode); |
| 204 | printf("bits per word: %d\n", bits); | 235 | printf("bits per word: %d\n", bits); |
| 205 | printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); | 236 | printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); |
| 206 | 237 | ||
