]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
spi: mxs: Introduce spi_cs_is_valid()
authorFabio Estevam <fabio.estevam@freescale.com>
Mon, 23 Apr 2012 08:30:49 +0000 (08:30 +0000)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Tue, 15 May 2012 06:31:35 +0000 (08:31 +0200)
Introduce spi_cs_is_valid() for validating spi bus and chip select numbers.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Marek Vasut <marex@denx.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>
drivers/spi/mxs_spi.c

index 4e6f14ee0722d102b2db33cdcb67ff1c02a1c272..e7237e720a40ca785922f4eb0182aedbc68d2a98 100644 (file)
@@ -51,14 +51,23 @@ void spi_init(void)
 {
 }
 
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+       /* MXS SPI: 4 ports and 3 chip selects maximum */
+       if (bus > 3 || cs > 2)
+               return 0;
+       else
+               return 1;
+}
+
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                                  unsigned int max_hz, unsigned int mode)
 {
        struct mxs_spi_slave *mxs_slave;
        uint32_t addr;
 
-       if (bus > 3) {
-               printf("MXS SPI: Max bus number is 3\n");
+       if (!spi_cs_is_valid(bus, cs)) {
+               printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
                return NULL;
        }