aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjiada wang <jiada_wang@mentor.com>2017-09-05 01:12:32 -0400
committerMark Brown <broonie@kernel.org>2017-09-19 11:01:43 -0400
commit71abd29057cb17b6b9532421821dc443427399ed (patch)
treea95746fc7dc1c10a78b48746095f4aa90ee05b66
parent2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff)
spi: imx: Add support for SPI Slave mode
Previously i.MX SPI controller only works in Master mode. This patch adds support to i.MX51, i.MX53 and i.MX6 ECSPI controller to work also in Slave mode. Currently SPI Slave mode support patch has the following limitations: 1. The stale data in RXFIFO will be dropped when the Slave does any new transfer. 2. One transfer can be finished only after all transfer->len data been transferred to master device 3. Slave device only accepts transfer->len data. Any data longer than this from master device will be dropped. Any data shorter than this from master will cause SPI to stuck due to mentioned HW limitation 2. 4. Only PIO transfer is supported in Slave mode. 5. Dynamic burst size adjust isn't supported in Slave mode. Following HW limitation applies: 1. ECSPI has a HW issue when works in Slave mode, after 64 words written to TXFIFO, even TXFIFO becomes empty, ECSPI_TXDATA keeps shift out the last word data, so we have to disable ECSPI when in slave mode after the transfer completes 2. Due to Freescale errata ERR003775 "eCSPI: Burst completion by Chip Select (SS) signal in Slave mode is not functional" burst size must be set exactly to the size of the transfer. This limit SPI transaction with maximum 2^12 bits. This errata affects i.MX53 and i.MX6 ECSPI controllers. Signed-off-by: Jiada Wang <jiada_wang@mentor.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-imx.c227
1 files changed, 196 insertions, 31 deletions
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index babb15f07995..fe35aaea323b 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -53,10 +53,13 @@
53/* generic defines to abstract from the different register layouts */ 53/* generic defines to abstract from the different register layouts */
54#define MXC_INT_RR (1 << 0) /* Receive data ready interrupt */ 54#define MXC_INT_RR (1 << 0) /* Receive data ready interrupt */
55#define MXC_INT_TE (1 << 1) /* Transmit FIFO empty interrupt */ 55#define MXC_INT_TE (1 << 1) /* Transmit FIFO empty interrupt */
56#define MXC_INT_RDR BIT(4) /* Receive date threshold interrupt */
56 57
57/* The maximum bytes that a sdma BD can transfer.*/ 58/* The maximum bytes that a sdma BD can transfer.*/
58#define MAX_SDMA_BD_BYTES (1 << 15) 59#define MAX_SDMA_BD_BYTES (1 << 15)
59#define MX51_ECSPI_CTRL_MAX_BURST 512 60#define MX51_ECSPI_CTRL_MAX_BURST 512
61/* The maximum bytes that IMX53_ECSPI can transfer in slave mode.*/
62#define MX53_MAX_TRANSFER_BYTES 512
60 63
61enum spi_imx_devtype { 64enum spi_imx_devtype {
62 IMX1_CSPI, 65 IMX1_CSPI,
@@ -76,7 +79,9 @@ struct spi_imx_devtype_data {
76 void (*trigger)(struct spi_imx_data *); 79 void (*trigger)(struct spi_imx_data *);
77 int (*rx_available)(struct spi_imx_data *); 80 int (*rx_available)(struct spi_imx_data *);
78 void (*reset)(struct spi_imx_data *); 81 void (*reset)(struct spi_imx_data *);
82 void (*disable)(struct spi_imx_data *);
79 bool has_dmamode; 83 bool has_dmamode;
84 bool has_slavemode;
80 unsigned int fifo_size; 85 unsigned int fifo_size;
81 bool dynamic_burst; 86 bool dynamic_burst;
82 enum spi_imx_devtype devtype; 87 enum spi_imx_devtype devtype;
@@ -108,6 +113,11 @@ struct spi_imx_data {
108 unsigned int dynamic_burst, read_u32; 113 unsigned int dynamic_burst, read_u32;
109 unsigned int word_mask; 114 unsigned int word_mask;
110 115
116 /* Slave mode */
117 bool slave_mode;
118 bool slave_aborted;
119 unsigned int slave_burst;
120
111 /* DMA */ 121 /* DMA */
112 bool usedma; 122 bool usedma;
113 u32 wml; 123 u32 wml;
@@ -221,6 +231,9 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
221 if (!master->dma_rx) 231 if (!master->dma_rx)
222 return false; 232 return false;
223 233
234 if (spi_imx->slave_mode)
235 return false;
236
224 bytes_per_word = spi_imx_bytes_per_word(transfer->bits_per_word); 237 bytes_per_word = spi_imx_bytes_per_word(transfer->bits_per_word);
225 238
226 if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4) 239 if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4)
@@ -262,6 +275,7 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi,
262#define MX51_ECSPI_INT 0x10 275#define MX51_ECSPI_INT 0x10
263#define MX51_ECSPI_INT_TEEN (1 << 0) 276#define MX51_ECSPI_INT_TEEN (1 << 0)
264#define MX51_ECSPI_INT_RREN (1 << 3) 277#define MX51_ECSPI_INT_RREN (1 << 3)
278#define MX51_ECSPI_INT_RDREN (1 << 4)
265 279
266#define MX51_ECSPI_DMA 0x14 280#define MX51_ECSPI_DMA 0x14
267#define MX51_ECSPI_DMA_TX_WML(wml) ((wml) & 0x3f) 281#define MX51_ECSPI_DMA_TX_WML(wml) ((wml) & 0x3f)
@@ -378,6 +392,44 @@ static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx)
378 spi_imx_buf_tx_u16(spi_imx); 392 spi_imx_buf_tx_u16(spi_imx);
379} 393}
380 394
395static void mx53_ecspi_rx_slave(struct spi_imx_data *spi_imx)
396{
397 u32 val = be32_to_cpu(readl(spi_imx->base + MXC_CSPIRXDATA));
398
399 if (spi_imx->rx_buf) {
400 int n_bytes = spi_imx->slave_burst % sizeof(val);
401
402 if (!n_bytes)
403 n_bytes = sizeof(val);
404
405 memcpy(spi_imx->rx_buf,
406 ((u8 *)&val) + sizeof(val) - n_bytes, n_bytes);
407
408 spi_imx->rx_buf += n_bytes;
409 spi_imx->slave_burst -= n_bytes;
410 }
411}
412
413static void mx53_ecspi_tx_slave(struct spi_imx_data *spi_imx)
414{
415 u32 val = 0;
416 int n_bytes = spi_imx->count % sizeof(val);
417
418 if (!n_bytes)
419 n_bytes = sizeof(val);
420
421 if (spi_imx->tx_buf) {
422 memcpy(((u8 *)&val) + sizeof(val) - n_bytes,
423 spi_imx->tx_buf, n_bytes);
424 val = cpu_to_be32(val);
425 spi_imx->tx_buf += n_bytes;
426 }
427
428 spi_imx->count -= n_bytes;
429
430 writel(val, spi_imx->base + MXC_CSPITXDATA);
431}
432
381/* MX51 eCSPI */ 433/* MX51 eCSPI */
382static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx, 434static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx,
383 unsigned int fspi, unsigned int *fres) 435 unsigned int fspi, unsigned int *fres)
@@ -427,6 +479,9 @@ static void mx51_ecspi_intctrl(struct spi_imx_data *spi_imx, int enable)
427 if (enable & MXC_INT_RR) 479 if (enable & MXC_INT_RR)
428 val |= MX51_ECSPI_INT_RREN; 480 val |= MX51_ECSPI_INT_RREN;
429 481
482 if (enable & MXC_INT_RDR)
483 val |= MX51_ECSPI_INT_RDREN;
484
430 writel(val, spi_imx->base + MX51_ECSPI_INT); 485 writel(val, spi_imx->base + MX51_ECSPI_INT);
431} 486}
432 487
@@ -439,6 +494,15 @@ static void mx51_ecspi_trigger(struct spi_imx_data *spi_imx)
439 writel(reg, spi_imx->base + MX51_ECSPI_CTRL); 494 writel(reg, spi_imx->base + MX51_ECSPI_CTRL);
440} 495}
441 496
497static void mx51_ecspi_disable(struct spi_imx_data *spi_imx)
498{
499 u32 ctrl;
500
501 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL);
502 ctrl &= ~MX51_ECSPI_CTRL_ENABLE;
503 writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
504}
505
442static int mx51_ecspi_config(struct spi_device *spi) 506static int mx51_ecspi_config(struct spi_device *spi)
443{ 507{
444 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); 508 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
@@ -446,14 +510,11 @@ static int mx51_ecspi_config(struct spi_device *spi)
446 u32 clk = spi_imx->speed_hz, delay, reg; 510 u32 clk = spi_imx->speed_hz, delay, reg;
447 u32 cfg = readl(spi_imx->base + MX51_ECSPI_CONFIG); 511 u32 cfg = readl(spi_imx->base + MX51_ECSPI_CONFIG);
448 512
449 /* 513 /* set Master or Slave mode */
450 * The hardware seems to have a race condition when changing modes. The 514 if (spi_imx->slave_mode)
451 * current assumption is that the selection of the channel arrives 515 ctrl &= ~MX51_ECSPI_CTRL_MODE_MASK;
452 * earlier in the hardware than the mode bits when they are written at 516 else
453 * the same time. 517 ctrl |= MX51_ECSPI_CTRL_MODE_MASK;
454 * So set master mode for all channels as we do not support slave mode.
455 */
456 ctrl |= MX51_ECSPI_CTRL_MODE_MASK;
457 518
458 /* 519 /*
459 * Enable SPI_RDY handling (falling edge/level triggered). 520 * Enable SPI_RDY handling (falling edge/level triggered).
@@ -468,9 +529,22 @@ static int mx51_ecspi_config(struct spi_device *spi)
468 /* set chip select to use */ 529 /* set chip select to use */
469 ctrl |= MX51_ECSPI_CTRL_CS(spi->chip_select); 530 ctrl |= MX51_ECSPI_CTRL_CS(spi->chip_select);
470 531
471 ctrl |= (spi_imx->bits_per_word - 1) << MX51_ECSPI_CTRL_BL_OFFSET; 532 if (spi_imx->slave_mode && is_imx53_ecspi(spi_imx))
533 ctrl |= (spi_imx->slave_burst * 8 - 1)
534 << MX51_ECSPI_CTRL_BL_OFFSET;
535 else
536 ctrl |= (spi_imx->bits_per_word - 1)
537 << MX51_ECSPI_CTRL_BL_OFFSET;
472 538
473 cfg |= MX51_ECSPI_CONFIG_SBBCTRL(spi->chip_select); 539 /*
540 * eCSPI burst completion by Chip Select signal in Slave mode
541 * is not functional for imx53 Soc, config SPI burst completed when
542 * BURST_LENGTH + 1 bits are received
543 */
544 if (spi_imx->slave_mode && is_imx53_ecspi(spi_imx))
545 cfg &= ~MX51_ECSPI_CONFIG_SBBCTRL(spi->chip_select);
546 else
547 cfg |= MX51_ECSPI_CONFIG_SBBCTRL(spi->chip_select);
474 548
475 if (spi->mode & SPI_CPHA) 549 if (spi->mode & SPI_CPHA)
476 cfg |= MX51_ECSPI_CONFIG_SCLKPHA(spi->chip_select); 550 cfg |= MX51_ECSPI_CONFIG_SCLKPHA(spi->chip_select);
@@ -805,6 +879,7 @@ static struct spi_imx_devtype_data imx1_cspi_devtype_data = {
805 .fifo_size = 8, 879 .fifo_size = 8,
806 .has_dmamode = false, 880 .has_dmamode = false,
807 .dynamic_burst = false, 881 .dynamic_burst = false,
882 .has_slavemode = false,
808 .devtype = IMX1_CSPI, 883 .devtype = IMX1_CSPI,
809}; 884};
810 885
@@ -817,6 +892,7 @@ static struct spi_imx_devtype_data imx21_cspi_devtype_data = {
817 .fifo_size = 8, 892 .fifo_size = 8,
818 .has_dmamode = false, 893 .has_dmamode = false,
819 .dynamic_burst = false, 894 .dynamic_burst = false,
895 .has_slavemode = false,
820 .devtype = IMX21_CSPI, 896 .devtype = IMX21_CSPI,
821}; 897};
822 898
@@ -830,6 +906,7 @@ static struct spi_imx_devtype_data imx27_cspi_devtype_data = {
830 .fifo_size = 8, 906 .fifo_size = 8,
831 .has_dmamode = false, 907 .has_dmamode = false,
832 .dynamic_burst = false, 908 .dynamic_burst = false,
909 .has_slavemode = false,
833 .devtype = IMX27_CSPI, 910 .devtype = IMX27_CSPI,
834}; 911};
835 912
@@ -842,6 +919,7 @@ static struct spi_imx_devtype_data imx31_cspi_devtype_data = {
842 .fifo_size = 8, 919 .fifo_size = 8,
843 .has_dmamode = false, 920 .has_dmamode = false,
844 .dynamic_burst = false, 921 .dynamic_burst = false,
922 .has_slavemode = false,
845 .devtype = IMX31_CSPI, 923 .devtype = IMX31_CSPI,
846}; 924};
847 925
@@ -855,6 +933,7 @@ static struct spi_imx_devtype_data imx35_cspi_devtype_data = {
855 .fifo_size = 8, 933 .fifo_size = 8,
856 .has_dmamode = true, 934 .has_dmamode = true,
857 .dynamic_burst = false, 935 .dynamic_burst = false,
936 .has_slavemode = false,
858 .devtype = IMX35_CSPI, 937 .devtype = IMX35_CSPI,
859}; 938};
860 939
@@ -867,6 +946,8 @@ static struct spi_imx_devtype_data imx51_ecspi_devtype_data = {
867 .fifo_size = 64, 946 .fifo_size = 64,
868 .has_dmamode = true, 947 .has_dmamode = true,
869 .dynamic_burst = true, 948 .dynamic_burst = true,
949 .has_slavemode = true,
950 .disable = mx51_ecspi_disable,
870 .devtype = IMX51_ECSPI, 951 .devtype = IMX51_ECSPI,
871}; 952};
872 953
@@ -878,6 +959,8 @@ static struct spi_imx_devtype_data imx53_ecspi_devtype_data = {
878 .reset = mx51_ecspi_reset, 959 .reset = mx51_ecspi_reset,
879 .fifo_size = 64, 960 .fifo_size = 64,
880 .has_dmamode = true, 961 .has_dmamode = true,
962 .has_slavemode = true,
963 .disable = mx51_ecspi_disable,
881 .devtype = IMX53_ECSPI, 964 .devtype = IMX53_ECSPI,
882}; 965};
883 966
@@ -945,14 +1028,16 @@ static void spi_imx_push(struct spi_imx_data *spi_imx)
945 spi_imx->txfifo++; 1028 spi_imx->txfifo++;
946 } 1029 }
947 1030
948 spi_imx->devtype_data->trigger(spi_imx); 1031 if (!spi_imx->slave_mode)
1032 spi_imx->devtype_data->trigger(spi_imx);
949} 1033}
950 1034
951static irqreturn_t spi_imx_isr(int irq, void *dev_id) 1035static irqreturn_t spi_imx_isr(int irq, void *dev_id)
952{ 1036{
953 struct spi_imx_data *spi_imx = dev_id; 1037 struct spi_imx_data *spi_imx = dev_id;
954 1038
955 while (spi_imx->devtype_data->rx_available(spi_imx)) { 1039 while (spi_imx->txfifo &&
1040 spi_imx->devtype_data->rx_available(spi_imx)) {
956 spi_imx->rx(spi_imx); 1041 spi_imx->rx(spi_imx);
957 spi_imx->txfifo--; 1042 spi_imx->txfifo--;
958 } 1043 }
@@ -1034,7 +1119,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
1034 spi_imx->speed_hz = t->speed_hz; 1119 spi_imx->speed_hz = t->speed_hz;
1035 1120
1036 /* Initialize the functions for transfer */ 1121 /* Initialize the functions for transfer */
1037 if (spi_imx->devtype_data->dynamic_burst) { 1122 if (spi_imx->devtype_data->dynamic_burst && !spi_imx->slave_mode) {
1038 u32 mask; 1123 u32 mask;
1039 1124
1040 spi_imx->dynamic_burst = 0; 1125 spi_imx->dynamic_burst = 0;
@@ -1078,6 +1163,12 @@ static int spi_imx_setupxfer(struct spi_device *spi,
1078 return ret; 1163 return ret;
1079 } 1164 }
1080 1165
1166 if (is_imx53_ecspi(spi_imx) && spi_imx->slave_mode) {
1167 spi_imx->rx = mx53_ecspi_rx_slave;
1168 spi_imx->tx = mx53_ecspi_tx_slave;
1169 spi_imx->slave_burst = t->len;
1170 }
1171
1081 spi_imx->devtype_data->config(spi); 1172 spi_imx->devtype_data->config(spi);
1082 1173
1083 return 0; 1174 return 0;
@@ -1262,11 +1353,61 @@ static int spi_imx_pio_transfer(struct spi_device *spi,
1262 return transfer->len; 1353 return transfer->len;
1263} 1354}
1264 1355
1356static int spi_imx_pio_transfer_slave(struct spi_device *spi,
1357 struct spi_transfer *transfer)
1358{
1359 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
1360 int ret = transfer->len;
1361
1362 if (is_imx53_ecspi(spi_imx) &&
1363 transfer->len > MX53_MAX_TRANSFER_BYTES) {
1364 dev_err(&spi->dev, "Transaction too big, max size is %d bytes\n",
1365 MX53_MAX_TRANSFER_BYTES);
1366 return -EMSGSIZE;
1367 }
1368
1369 spi_imx->tx_buf = transfer->tx_buf;
1370 spi_imx->rx_buf = transfer->rx_buf;
1371 spi_imx->count = transfer->len;
1372 spi_imx->txfifo = 0;
1373
1374 reinit_completion(&spi_imx->xfer_done);
1375 spi_imx->slave_aborted = false;
1376
1377 spi_imx_push(spi_imx);
1378
1379 spi_imx->devtype_data->intctrl(spi_imx, MXC_INT_TE | MXC_INT_RDR);
1380
1381 if (wait_for_completion_interruptible(&spi_imx->xfer_done) ||
1382 spi_imx->slave_aborted) {
1383 dev_dbg(&spi->dev, "interrupted\n");
1384 ret = -EINTR;
1385 }
1386
1387 /* ecspi has a HW issue when works in Slave mode,
1388 * after 64 words writtern to TXFIFO, even TXFIFO becomes empty,
1389 * ECSPI_TXDATA keeps shift out the last word data,
1390 * so we have to disable ECSPI when in slave mode after the
1391 * transfer completes
1392 */
1393 if (spi_imx->devtype_data->disable)
1394 spi_imx->devtype_data->disable(spi_imx);
1395
1396 return ret;
1397}
1398
1265static int spi_imx_transfer(struct spi_device *spi, 1399static int spi_imx_transfer(struct spi_device *spi,
1266 struct spi_transfer *transfer) 1400 struct spi_transfer *transfer)
1267{ 1401{
1268 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); 1402 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
1269 1403
1404 /* flush rxfifo before transfer */
1405 while (spi_imx->devtype_data->rx_available(spi_imx))
1406 spi_imx->rx(spi_imx);
1407
1408 if (spi_imx->slave_mode)
1409 return spi_imx_pio_transfer_slave(spi, transfer);
1410
1270 if (spi_imx->usedma) 1411 if (spi_imx->usedma)
1271 return spi_imx_dma_transfer(spi_imx, transfer); 1412 return spi_imx_dma_transfer(spi_imx, transfer);
1272 else 1413 else
@@ -1323,6 +1464,16 @@ spi_imx_unprepare_message(struct spi_master *master, struct spi_message *msg)
1323 return 0; 1464 return 0;
1324} 1465}
1325 1466
1467static int spi_imx_slave_abort(struct spi_master *master)
1468{
1469 struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
1470
1471 spi_imx->slave_aborted = true;
1472 complete(&spi_imx->xfer_done);
1473
1474 return 0;
1475}
1476
1326static int spi_imx_probe(struct platform_device *pdev) 1477static int spi_imx_probe(struct platform_device *pdev)
1327{ 1478{
1328 struct device_node *np = pdev->dev.of_node; 1479 struct device_node *np = pdev->dev.of_node;
@@ -1334,13 +1485,23 @@ static int spi_imx_probe(struct platform_device *pdev)
1334 struct spi_imx_data *spi_imx; 1485 struct spi_imx_data *spi_imx;
1335 struct resource *res; 1486 struct resource *res;
1336 int i, ret, irq, spi_drctl; 1487 int i, ret, irq, spi_drctl;
1488 const struct spi_imx_devtype_data *devtype_data = of_id ? of_id->data :
1489 (struct spi_imx_devtype_data *)pdev->id_entry->driver_data;
1490 bool slave_mode;
1337 1491
1338 if (!np && !mxc_platform_info) { 1492 if (!np && !mxc_platform_info) {
1339 dev_err(&pdev->dev, "can't get the platform data\n"); 1493 dev_err(&pdev->dev, "can't get the platform data\n");
1340 return -EINVAL; 1494 return -EINVAL;
1341 } 1495 }
1342 1496
1343 master = spi_alloc_master(&pdev->dev, sizeof(struct spi_imx_data)); 1497 slave_mode = devtype_data->has_slavemode &&
1498 of_property_read_bool(np, "spi-slave");
1499 if (slave_mode)
1500 master = spi_alloc_slave(&pdev->dev,
1501 sizeof(struct spi_imx_data));
1502 else
1503 master = spi_alloc_master(&pdev->dev,
1504 sizeof(struct spi_imx_data));
1344 if (!master) 1505 if (!master)
1345 return -ENOMEM; 1506 return -ENOMEM;
1346 1507
@@ -1358,9 +1519,9 @@ static int spi_imx_probe(struct platform_device *pdev)
1358 spi_imx = spi_master_get_devdata(master); 1519 spi_imx = spi_master_get_devdata(master);
1359 spi_imx->bitbang.master = master; 1520 spi_imx->bitbang.master = master;
1360 spi_imx->dev = &pdev->dev; 1521 spi_imx->dev = &pdev->dev;
1522 spi_imx->slave_mode = slave_mode;
1361 1523
1362 spi_imx->devtype_data = of_id ? of_id->data : 1524 spi_imx->devtype_data = devtype_data;
1363 (struct spi_imx_devtype_data *)pdev->id_entry->driver_data;
1364 1525
1365 if (mxc_platform_info) { 1526 if (mxc_platform_info) {
1366 master->num_chipselect = mxc_platform_info->num_chipselect; 1527 master->num_chipselect = mxc_platform_info->num_chipselect;
@@ -1380,6 +1541,7 @@ static int spi_imx_probe(struct platform_device *pdev)
1380 spi_imx->bitbang.master->cleanup = spi_imx_cleanup; 1541 spi_imx->bitbang.master->cleanup = spi_imx_cleanup;
1381 spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; 1542 spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message;
1382 spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; 1543 spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message;
1544 spi_imx->bitbang.master->slave_abort = spi_imx_slave_abort;
1383 spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ 1545 spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
1384 | SPI_NO_CS; 1546 | SPI_NO_CS;
1385 if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx) || 1547 if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx) ||
@@ -1457,23 +1619,26 @@ static int spi_imx_probe(struct platform_device *pdev)
1457 goto out_clk_put; 1619 goto out_clk_put;
1458 } 1620 }
1459 1621
1460 if (!master->cs_gpios) { 1622 if (!spi_imx->slave_mode) {
1461 dev_err(&pdev->dev, "No CS GPIOs available\n"); 1623 if (!master->cs_gpios) {
1462 ret = -EINVAL; 1624 dev_err(&pdev->dev, "No CS GPIOs available\n");
1463 goto out_clk_put; 1625 ret = -EINVAL;
1464 }
1465
1466 for (i = 0; i < master->num_chipselect; i++) {
1467 if (!gpio_is_valid(master->cs_gpios[i]))
1468 continue;
1469
1470 ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i],
1471 DRIVER_NAME);
1472 if (ret) {
1473 dev_err(&pdev->dev, "Can't get CS GPIO %i\n",
1474 master->cs_gpios[i]);
1475 goto out_clk_put; 1626 goto out_clk_put;
1476 } 1627 }
1628
1629 for (i = 0; i < master->num_chipselect; i++) {
1630 if (!gpio_is_valid(master->cs_gpios[i]))
1631 continue;
1632
1633 ret = devm_gpio_request(&pdev->dev,
1634 master->cs_gpios[i],
1635 DRIVER_NAME);
1636 if (ret) {
1637 dev_err(&pdev->dev, "Can't get CS GPIO %i\n",
1638 master->cs_gpios[i]);
1639 goto out_clk_put;
1640 }
1641 }
1477 } 1642 }
1478 1643
1479 dev_info(&pdev->dev, "probed\n"); 1644 dev_info(&pdev->dev, "probed\n");