aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-omap2-mcspi.c
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-06-26 11:21:01 -0400
committerMark Brown <broonie@linaro.org>2013-06-26 11:21:01 -0400
commit1728ddb2ca726b150e7bf10cdd35b5c3fc5efcf3 (patch)
tree9abdf224254d340791f1d771c7304db4be96e19a /drivers/spi/spi-omap2-mcspi.c
parent13a621693ebc2276ea24850e62ba7f8a8fc6a617 (diff)
parent0b9e49e6704b81fd991827b0b60a0a6d56d06921 (diff)
Merge remote-tracking branch 'spi/topic/omap' into spi-next
Diffstat (limited to 'drivers/spi/spi-omap2-mcspi.c')
-rw-r--r--drivers/spi/spi-omap2-mcspi.c237
1 files changed, 187 insertions, 50 deletions
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 6246fb455774..e7742134451a 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -38,13 +38,15 @@
38#include <linux/pm_runtime.h> 38#include <linux/pm_runtime.h>
39#include <linux/of.h> 39#include <linux/of.h>
40#include <linux/of_device.h> 40#include <linux/of_device.h>
41#include <linux/pinctrl/consumer.h> 41#include <linux/gcd.h>
42 42
43#include <linux/spi/spi.h> 43#include <linux/spi/spi.h>
44 44
45#include <linux/platform_data/spi-omap2-mcspi.h> 45#include <linux/platform_data/spi-omap2-mcspi.h>
46 46
47#define OMAP2_MCSPI_MAX_FREQ 48000000 47#define OMAP2_MCSPI_MAX_FREQ 48000000
48#define OMAP2_MCSPI_MAX_FIFODEPTH 64
49#define OMAP2_MCSPI_MAX_FIFOWCNT 0xFFFF
48#define SPI_AUTOSUSPEND_TIMEOUT 2000 50#define SPI_AUTOSUSPEND_TIMEOUT 2000
49 51
50#define OMAP2_MCSPI_REVISION 0x00 52#define OMAP2_MCSPI_REVISION 0x00
@@ -54,6 +56,7 @@
54#define OMAP2_MCSPI_WAKEUPENABLE 0x20 56#define OMAP2_MCSPI_WAKEUPENABLE 0x20
55#define OMAP2_MCSPI_SYST 0x24 57#define OMAP2_MCSPI_SYST 0x24
56#define OMAP2_MCSPI_MODULCTRL 0x28 58#define OMAP2_MCSPI_MODULCTRL 0x28
59#define OMAP2_MCSPI_XFERLEVEL 0x7c
57 60
58/* per-channel banks, 0x14 bytes each, first is: */ 61/* per-channel banks, 0x14 bytes each, first is: */
59#define OMAP2_MCSPI_CHCONF0 0x2c 62#define OMAP2_MCSPI_CHCONF0 0x2c
@@ -63,6 +66,7 @@
63#define OMAP2_MCSPI_RX0 0x3c 66#define OMAP2_MCSPI_RX0 0x3c
64 67
65/* per-register bitmasks: */ 68/* per-register bitmasks: */
69#define OMAP2_MCSPI_IRQSTATUS_EOW BIT(17)
66 70
67#define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0) 71#define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0)
68#define OMAP2_MCSPI_MODULCTRL_MS BIT(2) 72#define OMAP2_MCSPI_MODULCTRL_MS BIT(2)
@@ -83,10 +87,13 @@
83#define OMAP2_MCSPI_CHCONF_IS BIT(18) 87#define OMAP2_MCSPI_CHCONF_IS BIT(18)
84#define OMAP2_MCSPI_CHCONF_TURBO BIT(19) 88#define OMAP2_MCSPI_CHCONF_TURBO BIT(19)
85#define OMAP2_MCSPI_CHCONF_FORCE BIT(20) 89#define OMAP2_MCSPI_CHCONF_FORCE BIT(20)
90#define OMAP2_MCSPI_CHCONF_FFET BIT(27)
91#define OMAP2_MCSPI_CHCONF_FFER BIT(28)
86 92
87#define OMAP2_MCSPI_CHSTAT_RXS BIT(0) 93#define OMAP2_MCSPI_CHSTAT_RXS BIT(0)
88#define OMAP2_MCSPI_CHSTAT_TXS BIT(1) 94#define OMAP2_MCSPI_CHSTAT_TXS BIT(1)
89#define OMAP2_MCSPI_CHSTAT_EOT BIT(2) 95#define OMAP2_MCSPI_CHSTAT_EOT BIT(2)
96#define OMAP2_MCSPI_CHSTAT_TXFFE BIT(3)
90 97
91#define OMAP2_MCSPI_CHCTRL_EN BIT(0) 98#define OMAP2_MCSPI_CHCTRL_EN BIT(0)
92 99
@@ -102,6 +109,9 @@ struct omap2_mcspi_dma {
102 109
103 struct completion dma_tx_completion; 110 struct completion dma_tx_completion;
104 struct completion dma_rx_completion; 111 struct completion dma_rx_completion;
112
113 char dma_rx_ch_name[14];
114 char dma_tx_ch_name[14];
105}; 115};
106 116
107/* use PIO for small transfers, avoiding DMA setup/teardown overhead and 117/* use PIO for small transfers, avoiding DMA setup/teardown overhead and
@@ -129,6 +139,7 @@ struct omap2_mcspi {
129 struct omap2_mcspi_dma *dma_channels; 139 struct omap2_mcspi_dma *dma_channels;
130 struct device *dev; 140 struct device *dev;
131 struct omap2_mcspi_regs ctx; 141 struct omap2_mcspi_regs ctx;
142 int fifo_depth;
132 unsigned int pin_dir:1; 143 unsigned int pin_dir:1;
133}; 144};
134 145
@@ -187,6 +198,16 @@ static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val)
187 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0); 198 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0);
188} 199}
189 200
201static inline int mcspi_bytes_per_word(int word_len)
202{
203 if (word_len <= 8)
204 return 1;
205 else if (word_len <= 16)
206 return 2;
207 else /* word_len <= 32 */
208 return 4;
209}
210
190static void omap2_mcspi_set_dma_req(const struct spi_device *spi, 211static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
191 int is_read, int enable) 212 int is_read, int enable)
192{ 213{
@@ -248,6 +269,58 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master)
248 ctx->modulctrl = l; 269 ctx->modulctrl = l;
249} 270}
250 271
272static void omap2_mcspi_set_fifo(const struct spi_device *spi,
273 struct spi_transfer *t, int enable)
274{
275 struct spi_master *master = spi->master;
276 struct omap2_mcspi_cs *cs = spi->controller_state;
277 struct omap2_mcspi *mcspi;
278 unsigned int wcnt;
279 int fifo_depth, bytes_per_word;
280 u32 chconf, xferlevel;
281
282 mcspi = spi_master_get_devdata(master);
283
284 chconf = mcspi_cached_chconf0(spi);
285 if (enable) {
286 bytes_per_word = mcspi_bytes_per_word(cs->word_len);
287 if (t->len % bytes_per_word != 0)
288 goto disable_fifo;
289
290 fifo_depth = gcd(t->len, OMAP2_MCSPI_MAX_FIFODEPTH);
291 if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0)
292 goto disable_fifo;
293
294 wcnt = t->len / bytes_per_word;
295 if (wcnt > OMAP2_MCSPI_MAX_FIFOWCNT)
296 goto disable_fifo;
297
298 xferlevel = wcnt << 16;
299 if (t->rx_buf != NULL) {
300 chconf |= OMAP2_MCSPI_CHCONF_FFER;
301 xferlevel |= (fifo_depth - 1) << 8;
302 } else {
303 chconf |= OMAP2_MCSPI_CHCONF_FFET;
304 xferlevel |= fifo_depth - 1;
305 }
306
307 mcspi_write_reg(master, OMAP2_MCSPI_XFERLEVEL, xferlevel);
308 mcspi_write_chconf0(spi, chconf);
309 mcspi->fifo_depth = fifo_depth;
310
311 return;
312 }
313
314disable_fifo:
315 if (t->rx_buf != NULL)
316 chconf &= ~OMAP2_MCSPI_CHCONF_FFER;
317 else
318 chconf &= ~OMAP2_MCSPI_CHCONF_FFET;
319
320 mcspi_write_chconf0(spi, chconf);
321 mcspi->fifo_depth = 0;
322}
323
251static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi) 324static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
252{ 325{
253 struct spi_master *spi_cntrl = mcspi->master; 326 struct spi_master *spi_cntrl = mcspi->master;
@@ -364,7 +437,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
364{ 437{
365 struct omap2_mcspi *mcspi; 438 struct omap2_mcspi *mcspi;
366 struct omap2_mcspi_dma *mcspi_dma; 439 struct omap2_mcspi_dma *mcspi_dma;
367 unsigned int count; 440 unsigned int count, dma_count;
368 u32 l; 441 u32 l;
369 int elements = 0; 442 int elements = 0;
370 int word_len, element_count; 443 int word_len, element_count;
@@ -372,6 +445,11 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
372 mcspi = spi_master_get_devdata(spi->master); 445 mcspi = spi_master_get_devdata(spi->master);
373 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 446 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
374 count = xfer->len; 447 count = xfer->len;
448 dma_count = xfer->len;
449
450 if (mcspi->fifo_depth == 0)
451 dma_count -= es;
452
375 word_len = cs->word_len; 453 word_len = cs->word_len;
376 l = mcspi_cached_chconf0(spi); 454 l = mcspi_cached_chconf0(spi);
377 455
@@ -385,16 +463,15 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
385 if (mcspi_dma->dma_rx) { 463 if (mcspi_dma->dma_rx) {
386 struct dma_async_tx_descriptor *tx; 464 struct dma_async_tx_descriptor *tx;
387 struct scatterlist sg; 465 struct scatterlist sg;
388 size_t len = xfer->len - es;
389 466
390 dmaengine_slave_config(mcspi_dma->dma_rx, &cfg); 467 dmaengine_slave_config(mcspi_dma->dma_rx, &cfg);
391 468
392 if (l & OMAP2_MCSPI_CHCONF_TURBO) 469 if ((l & OMAP2_MCSPI_CHCONF_TURBO) && mcspi->fifo_depth == 0)
393 len -= es; 470 dma_count -= es;
394 471
395 sg_init_table(&sg, 1); 472 sg_init_table(&sg, 1);
396 sg_dma_address(&sg) = xfer->rx_dma; 473 sg_dma_address(&sg) = xfer->rx_dma;
397 sg_dma_len(&sg) = len; 474 sg_dma_len(&sg) = dma_count;
398 475
399 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, 476 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1,
400 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | 477 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT |
@@ -414,6 +491,10 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
414 wait_for_completion(&mcspi_dma->dma_rx_completion); 491 wait_for_completion(&mcspi_dma->dma_rx_completion);
415 dma_unmap_single(mcspi->dev, xfer->rx_dma, count, 492 dma_unmap_single(mcspi->dev, xfer->rx_dma, count,
416 DMA_FROM_DEVICE); 493 DMA_FROM_DEVICE);
494
495 if (mcspi->fifo_depth > 0)
496 return count;
497
417 omap2_mcspi_set_enable(spi, 0); 498 omap2_mcspi_set_enable(spi, 0);
418 499
419 elements = element_count - 1; 500 elements = element_count - 1;
@@ -433,10 +514,9 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
433 else /* word_len <= 32 */ 514 else /* word_len <= 32 */
434 ((u32 *)xfer->rx_buf)[elements++] = w; 515 ((u32 *)xfer->rx_buf)[elements++] = w;
435 } else { 516 } else {
517 int bytes_per_word = mcspi_bytes_per_word(word_len);
436 dev_err(&spi->dev, "DMA RX penultimate word empty"); 518 dev_err(&spi->dev, "DMA RX penultimate word empty");
437 count -= (word_len <= 8) ? 2 : 519 count -= (bytes_per_word << 1);
438 (word_len <= 16) ? 4 :
439 /* word_len <= 32 */ 8;
440 omap2_mcspi_set_enable(spi, 1); 520 omap2_mcspi_set_enable(spi, 1);
441 return count; 521 return count;
442 } 522 }
@@ -454,9 +534,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
454 ((u32 *)xfer->rx_buf)[elements] = w; 534 ((u32 *)xfer->rx_buf)[elements] = w;
455 } else { 535 } else {
456 dev_err(&spi->dev, "DMA RX last word empty"); 536 dev_err(&spi->dev, "DMA RX last word empty");
457 count -= (word_len <= 8) ? 1 : 537 count -= mcspi_bytes_per_word(word_len);
458 (word_len <= 16) ? 2 :
459 /* word_len <= 32 */ 4;
460 } 538 }
461 omap2_mcspi_set_enable(spi, 1); 539 omap2_mcspi_set_enable(spi, 1);
462 return count; 540 return count;
@@ -475,7 +553,10 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
475 struct dma_slave_config cfg; 553 struct dma_slave_config cfg;
476 enum dma_slave_buswidth width; 554 enum dma_slave_buswidth width;
477 unsigned es; 555 unsigned es;
556 u32 burst;
478 void __iomem *chstat_reg; 557 void __iomem *chstat_reg;
558 void __iomem *irqstat_reg;
559 int wait_res;
479 560
480 mcspi = spi_master_get_devdata(spi->master); 561 mcspi = spi_master_get_devdata(spi->master);
481 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 562 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
@@ -493,19 +574,27 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
493 es = 4; 574 es = 4;
494 } 575 }
495 576
577 count = xfer->len;
578 burst = 1;
579
580 if (mcspi->fifo_depth > 0) {
581 if (count > mcspi->fifo_depth)
582 burst = mcspi->fifo_depth / es;
583 else
584 burst = count / es;
585 }
586
496 memset(&cfg, 0, sizeof(cfg)); 587 memset(&cfg, 0, sizeof(cfg));
497 cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0; 588 cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0;
498 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; 589 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
499 cfg.src_addr_width = width; 590 cfg.src_addr_width = width;
500 cfg.dst_addr_width = width; 591 cfg.dst_addr_width = width;
501 cfg.src_maxburst = 1; 592 cfg.src_maxburst = burst;
502 cfg.dst_maxburst = 1; 593 cfg.dst_maxburst = burst;
503 594
504 rx = xfer->rx_buf; 595 rx = xfer->rx_buf;
505 tx = xfer->tx_buf; 596 tx = xfer->tx_buf;
506 597
507 count = xfer->len;
508
509 if (tx != NULL) 598 if (tx != NULL)
510 omap2_mcspi_tx_dma(spi, xfer, cfg); 599 omap2_mcspi_tx_dma(spi, xfer, cfg);
511 600
@@ -513,18 +602,38 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
513 count = omap2_mcspi_rx_dma(spi, xfer, cfg, es); 602 count = omap2_mcspi_rx_dma(spi, xfer, cfg, es);
514 603
515 if (tx != NULL) { 604 if (tx != NULL) {
516 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
517 wait_for_completion(&mcspi_dma->dma_tx_completion); 605 wait_for_completion(&mcspi_dma->dma_tx_completion);
518 dma_unmap_single(mcspi->dev, xfer->tx_dma, xfer->len, 606 dma_unmap_single(mcspi->dev, xfer->tx_dma, xfer->len,
519 DMA_TO_DEVICE); 607 DMA_TO_DEVICE);
520 608
609 if (mcspi->fifo_depth > 0) {
610 irqstat_reg = mcspi->base + OMAP2_MCSPI_IRQSTATUS;
611
612 if (mcspi_wait_for_reg_bit(irqstat_reg,
613 OMAP2_MCSPI_IRQSTATUS_EOW) < 0)
614 dev_err(&spi->dev, "EOW timed out\n");
615
616 mcspi_write_reg(mcspi->master, OMAP2_MCSPI_IRQSTATUS,
617 OMAP2_MCSPI_IRQSTATUS_EOW);
618 }
619
521 /* for TX_ONLY mode, be sure all words have shifted out */ 620 /* for TX_ONLY mode, be sure all words have shifted out */
522 if (rx == NULL) { 621 if (rx == NULL) {
523 if (mcspi_wait_for_reg_bit(chstat_reg, 622 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
524 OMAP2_MCSPI_CHSTAT_TXS) < 0) 623 if (mcspi->fifo_depth > 0) {
525 dev_err(&spi->dev, "TXS timed out\n"); 624 wait_res = mcspi_wait_for_reg_bit(chstat_reg,
526 else if (mcspi_wait_for_reg_bit(chstat_reg, 625 OMAP2_MCSPI_CHSTAT_TXFFE);
527 OMAP2_MCSPI_CHSTAT_EOT) < 0) 626 if (wait_res < 0)
627 dev_err(&spi->dev, "TXFFE timed out\n");
628 } else {
629 wait_res = mcspi_wait_for_reg_bit(chstat_reg,
630 OMAP2_MCSPI_CHSTAT_TXS);
631 if (wait_res < 0)
632 dev_err(&spi->dev, "TXS timed out\n");
633 }
634 if (wait_res >= 0 &&
635 (mcspi_wait_for_reg_bit(chstat_reg,
636 OMAP2_MCSPI_CHSTAT_EOT) < 0))
528 dev_err(&spi->dev, "EOT timed out\n"); 637 dev_err(&spi->dev, "EOT timed out\n");
529 } 638 }
530 } 639 }
@@ -830,12 +939,20 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
830 dma_cap_zero(mask); 939 dma_cap_zero(mask);
831 dma_cap_set(DMA_SLAVE, mask); 940 dma_cap_set(DMA_SLAVE, mask);
832 sig = mcspi_dma->dma_rx_sync_dev; 941 sig = mcspi_dma->dma_rx_sync_dev;
833 mcspi_dma->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 942
943 mcspi_dma->dma_rx =
944 dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
945 &sig, &master->dev,
946 mcspi_dma->dma_rx_ch_name);
834 if (!mcspi_dma->dma_rx) 947 if (!mcspi_dma->dma_rx)
835 goto no_dma; 948 goto no_dma;
836 949
837 sig = mcspi_dma->dma_tx_sync_dev; 950 sig = mcspi_dma->dma_tx_sync_dev;
838 mcspi_dma->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 951 mcspi_dma->dma_tx =
952 dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
953 &sig, &master->dev,
954 mcspi_dma->dma_tx_ch_name);
955
839 if (!mcspi_dma->dma_tx) { 956 if (!mcspi_dma->dma_tx) {
840 dma_release_channel(mcspi_dma->dma_rx); 957 dma_release_channel(mcspi_dma->dma_rx);
841 mcspi_dma->dma_rx = NULL; 958 mcspi_dma->dma_rx = NULL;
@@ -945,7 +1062,7 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
945 cs = spi->controller_state; 1062 cs = spi->controller_state;
946 cd = spi->controller_data; 1063 cd = spi->controller_data;
947 1064
948 omap2_mcspi_set_enable(spi, 1); 1065 omap2_mcspi_set_enable(spi, 0);
949 list_for_each_entry(t, &m->transfers, transfer_list) { 1066 list_for_each_entry(t, &m->transfers, transfer_list) {
950 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) { 1067 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
951 status = -EINVAL; 1068 status = -EINVAL;
@@ -993,6 +1110,12 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
993 if (t->len) { 1110 if (t->len) {
994 unsigned count; 1111 unsigned count;
995 1112
1113 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
1114 (m->is_dma_mapped || t->len >= DMA_MIN_BYTES))
1115 omap2_mcspi_set_fifo(spi, t, 1);
1116
1117 omap2_mcspi_set_enable(spi, 1);
1118
996 /* RX_ONLY mode needs dummy data in TX reg */ 1119 /* RX_ONLY mode needs dummy data in TX reg */
997 if (t->tx_buf == NULL) 1120 if (t->tx_buf == NULL)
998 __raw_writel(0, cs->base 1121 __raw_writel(0, cs->base
@@ -1019,6 +1142,11 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
1019 omap2_mcspi_force_cs(spi, 0); 1142 omap2_mcspi_force_cs(spi, 0);
1020 cs_active = 0; 1143 cs_active = 0;
1021 } 1144 }
1145
1146 omap2_mcspi_set_enable(spi, 0);
1147
1148 if (mcspi->fifo_depth > 0)
1149 omap2_mcspi_set_fifo(spi, t, 0);
1022 } 1150 }
1023 /* Restore defaults if they were overriden */ 1151 /* Restore defaults if they were overriden */
1024 if (par_override) { 1152 if (par_override) {
@@ -1039,8 +1167,10 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
1039 1167
1040 omap2_mcspi_set_enable(spi, 0); 1168 omap2_mcspi_set_enable(spi, 0);
1041 1169
1042 m->status = status; 1170 if (mcspi->fifo_depth > 0 && t)
1171 omap2_mcspi_set_fifo(spi, t, 0);
1043 1172
1173 m->status = status;
1044} 1174}
1045 1175
1046static int omap2_mcspi_transfer_one_message(struct spi_master *master, 1176static int omap2_mcspi_transfer_one_message(struct spi_master *master,
@@ -1177,7 +1307,6 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
1177 static int bus_num = 1; 1307 static int bus_num = 1;
1178 struct device_node *node = pdev->dev.of_node; 1308 struct device_node *node = pdev->dev.of_node;
1179 const struct of_device_id *match; 1309 const struct of_device_id *match;
1180 struct pinctrl *pinctrl;
1181 1310
1182 master = spi_alloc_master(&pdev->dev, sizeof *mcspi); 1311 master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
1183 if (master == NULL) { 1312 if (master == NULL) {
@@ -1247,39 +1376,47 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
1247 goto free_master; 1376 goto free_master;
1248 1377
1249 for (i = 0; i < master->num_chipselect; i++) { 1378 for (i = 0; i < master->num_chipselect; i++) {
1250 char dma_ch_name[14]; 1379 char *dma_rx_ch_name = mcspi->dma_channels[i].dma_rx_ch_name;
1380 char *dma_tx_ch_name = mcspi->dma_channels[i].dma_tx_ch_name;
1251 struct resource *dma_res; 1381 struct resource *dma_res;
1252 1382
1253 sprintf(dma_ch_name, "rx%d", i); 1383 sprintf(dma_rx_ch_name, "rx%d", i);
1254 dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA, 1384 if (!pdev->dev.of_node) {
1255 dma_ch_name); 1385 dma_res =
1256 if (!dma_res) { 1386 platform_get_resource_byname(pdev,
1257 dev_dbg(&pdev->dev, "cannot get DMA RX channel\n"); 1387 IORESOURCE_DMA,
1258 status = -ENODEV; 1388 dma_rx_ch_name);
1259 break; 1389 if (!dma_res) {
1260 } 1390 dev_dbg(&pdev->dev,
1391 "cannot get DMA RX channel\n");
1392 status = -ENODEV;
1393 break;
1394 }
1261 1395
1262 mcspi->dma_channels[i].dma_rx_sync_dev = dma_res->start; 1396 mcspi->dma_channels[i].dma_rx_sync_dev =
1263 sprintf(dma_ch_name, "tx%d", i); 1397 dma_res->start;
1264 dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA,
1265 dma_ch_name);
1266 if (!dma_res) {
1267 dev_dbg(&pdev->dev, "cannot get DMA TX channel\n");
1268 status = -ENODEV;
1269 break;
1270 } 1398 }
1399 sprintf(dma_tx_ch_name, "tx%d", i);
1400 if (!pdev->dev.of_node) {
1401 dma_res =
1402 platform_get_resource_byname(pdev,
1403 IORESOURCE_DMA,
1404 dma_tx_ch_name);
1405 if (!dma_res) {
1406 dev_dbg(&pdev->dev,
1407 "cannot get DMA TX channel\n");
1408 status = -ENODEV;
1409 break;
1410 }
1271 1411
1272 mcspi->dma_channels[i].dma_tx_sync_dev = dma_res->start; 1412 mcspi->dma_channels[i].dma_tx_sync_dev =
1413 dma_res->start;
1414 }
1273 } 1415 }
1274 1416
1275 if (status < 0) 1417 if (status < 0)
1276 goto dma_chnl_free; 1418 goto dma_chnl_free;
1277 1419
1278 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
1279 if (IS_ERR(pinctrl))
1280 dev_warn(&pdev->dev,
1281 "pins are not configured from the driver\n");
1282
1283 pm_runtime_use_autosuspend(&pdev->dev); 1420 pm_runtime_use_autosuspend(&pdev->dev);
1284 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); 1421 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
1285 pm_runtime_enable(&pdev->dev); 1422 pm_runtime_enable(&pdev->dev);