]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/spi/omap3_spi.c
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / drivers / spi / omap3_spi.c
index 344d5b8a7e2dc5d9006793e00d40343dec18be44..80a4e4776c83d17314b54060e758d980d91975b8 100644 (file)
@@ -80,12 +80,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                                  unsigned int max_hz, unsigned int mode)
 {
        struct omap3_spi_slave  *ds;
-
-       ds = malloc(sizeof(struct omap3_spi_slave));
-       if (!ds) {
-               printf("SPI error: malloc of SPI structure failed\n");
-               return NULL;
-       }
+       struct mcspi *regs;
 
        /*
         * OMAP3 McSPI (MultiChannel SPI) has 4 busses (modules)
@@ -98,21 +93,21 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
        switch (bus) {
        case 0:
-               ds->regs = (struct mcspi *)OMAP3_MCSPI1_BASE;
+               regs = (struct mcspi *)OMAP3_MCSPI1_BASE;
                break;
 #ifdef OMAP3_MCSPI2_BASE
        case 1:
-               ds->regs = (struct mcspi *)OMAP3_MCSPI2_BASE;
+               regs = (struct mcspi *)OMAP3_MCSPI2_BASE;
                break;
 #endif
 #ifdef OMAP3_MCSPI3_BASE 
        case 2:
-               ds->regs = (struct mcspi *)OMAP3_MCSPI3_BASE;
+               regs = (struct mcspi *)OMAP3_MCSPI3_BASE;
                break;
 #endif
 #ifdef OMAP3_MCSPI4_BASE
        case 3:
-               ds->regs = (struct mcspi *)OMAP3_MCSPI4_BASE;
+               regs = (struct mcspi *)OMAP3_MCSPI4_BASE;
                break;
 #endif
        default:
@@ -120,7 +115,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                        Supported busses 0 - 3\n", bus);
                return NULL;
        }
-       ds->slave.bus = bus;
 
        if (((bus == 0) && (cs > 3)) ||
                        ((bus == 1) && (cs > 1)) ||
@@ -130,19 +124,26 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                        on bus %i\n", cs, bus);
                return NULL;
        }
-       ds->slave.cs = cs;
 
        if (max_hz > OMAP3_MCSPI_MAX_FREQ) {
                printf("SPI error: unsupported frequency %i Hz. \
                        Max frequency is 48 Mhz\n", max_hz);
                return NULL;
        }
-       ds->freq = max_hz;
 
        if (mode > SPI_MODE_3) {
                printf("SPI error: unsupported SPI mode %i\n", mode);
                return NULL;
        }
+
+       ds = spi_alloc_slave(struct omap3_spi_slave, bus, cs);
+       if (!ds) {
+               printf("SPI error: malloc of SPI structure failed\n");
+               return NULL;
+       }
+
+       ds->regs = regs;
+       ds->freq = max_hz;
        ds->mode = mode;
 
        return &ds->slave;