~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/spi/omap2_mcspi.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
298
298
        unsigned int            count, c;
299
299
        unsigned long           base, tx_reg, rx_reg;
300
300
        int                     word_len, data_type, element_count;
301
 
        int                     elements;
 
301
        int                     elements = 0;
302
302
        u32                     l;
303
303
        u8                      * rx;
304
304
        const u8                * tx;
467
467
        rx_reg          = base + OMAP2_MCSPI_RX0;
468
468
        chstat_reg      = base + OMAP2_MCSPI_CHSTAT0;
469
469
 
 
470
        if (c < (word_len>>3))
 
471
                return 0;
 
472
 
470
473
        if (word_len <= 8) {
471
474
                u8              *rx;
472
475
                const u8        *tx;
561
564
                                dev_vdbg(&spi->dev, "read-%d %04x\n",
562
565
                                                word_len, *(rx - 1));
563
566
                        }
564
 
                } while (c);
 
567
                } while (c >= 2);
565
568
        } else if (word_len <= 32) {
566
569
                u32             *rx;
567
570
                const u32       *tx;
608
611
                                dev_vdbg(&spi->dev, "read-%d %08x\n",
609
612
                                                word_len, *(rx - 1));
610
613
                        }
611
 
                } while (c);
 
614
                } while (c >= 4);
612
615
        }
613
616
 
614
617
        /* for TX_ONLY mode, be sure all words have shifted out */
631
634
        return count - c;
632
635
}
633
636
 
 
637
static u32 omap2_mcspi_calc_divisor(u32 speed_hz)
 
638
{
 
639
        u32 div;
 
640
 
 
641
        for (div = 0; div < 15; div++)
 
642
                if (speed_hz >= (OMAP2_MCSPI_MAX_FREQ >> div))
 
643
                        return div;
 
644
 
 
645
        return 15;
 
646
}
 
647
 
634
648
/* called only when no transfer is active to this device */
635
649
static int omap2_mcspi_setup_transfer(struct spi_device *spi,
636
650
                struct spi_transfer *t)
653
667
        if (t && t->speed_hz)
654
668
                speed_hz = t->speed_hz;
655
669
 
656
 
        if (speed_hz) {
657
 
                while (div <= 15 && (OMAP2_MCSPI_MAX_FREQ / (1 << div))
658
 
                                        > speed_hz)
659
 
                        div++;
660
 
        } else
661
 
                div = 15;
 
670
        speed_hz = min_t(u32, speed_hz, OMAP2_MCSPI_MAX_FREQ);
 
671
        div = omap2_mcspi_calc_divisor(speed_hz);
662
672
 
663
673
        l = mcspi_cached_chconf0(spi);
664
674
 
695
705
        mcspi_write_chconf0(spi, l);
696
706
 
697
707
        dev_dbg(&spi->dev, "setup: speed %d, sample %s edge, clk %s\n",
698
 
                        OMAP2_MCSPI_MAX_FREQ / (1 << div),
 
708
                        OMAP2_MCSPI_MAX_FREQ >> div,
699
709
                        (spi->mode & SPI_CPHA) ? "trailing" : "leading",
700
710
                        (spi->mode & SPI_CPOL) ? "inverted" : "normal");
701
711
 
996
1006
                                        t->bits_per_word);
997
1007
                        return -EINVAL;
998
1008
                }
999
 
                if (t->speed_hz && t->speed_hz < OMAP2_MCSPI_MAX_FREQ/(1<<16)) {
1000
 
                        dev_dbg(&spi->dev, "%d Hz max exceeds %d\n",
1001
 
                                        t->speed_hz,
1002
 
                                        OMAP2_MCSPI_MAX_FREQ/(1<<16));
 
1009
                if (t->speed_hz && t->speed_hz < (OMAP2_MCSPI_MAX_FREQ >> 15)) {
 
1010
                        dev_dbg(&spi->dev, "speed_hz %d below minimum %d Hz\n",
 
1011
                                t->speed_hz,
 
1012
                                OMAP2_MCSPI_MAX_FREQ >> 15);
1003
1013
                        return -EINVAL;
1004
1014
                }
1005
1015