]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/spi/mxs_spi.c
SPI: mxc_spi: delay initialisation until claim bus
[karo-tx-uboot.git] / drivers / spi / mxs_spi.c
index aa999f9a945583a740e75af2e831b56d7406dab4..2b9f395a97821568dc12c5e28feaaf42b42ffd50 100644 (file)
@@ -4,20 +4,7 @@
  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  * on behalf of DENX Software Engineering GmbH
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * NOTE: This driver only supports the SPI-controller chipselects,
  *       GPIO driven chipselects are not supported.
@@ -31,7 +18,7 @@
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/sys_proto.h>
-#include <asm/arch/dma.h>
+#include <asm/imx-common/dma.h>
 
 #define        MXS_SPI_MAX_TIMEOUT     1000000
 #define        MXS_SPI_PORT_OFFSET     0x2000
@@ -69,8 +56,6 @@ 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;
-       struct mxs_ssp_regs *ssp_regs;
-       int reg;
 
        if (!spi_cs_is_valid(bus, cs)) {
                printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
@@ -87,13 +72,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        mxs_slave->max_khz = max_hz / 1000;
        mxs_slave->mode = mode;
        mxs_slave->regs = mxs_ssp_regs_by_bus(bus);
-       ssp_regs = mxs_slave->regs;
-
-       reg = readl(&ssp_regs->hw_ssp_ctrl0);
-       reg &= ~(MXS_SSP_CHIPSELECT_MASK);
-       reg |= cs << MXS_SSP_CHIPSELECT_SHIFT;
 
-       writel(reg, &ssp_regs->hw_ssp_ctrl0);
        return &mxs_slave->slave;
 
 err_init:
@@ -115,7 +94,9 @@ int spi_claim_bus(struct spi_slave *slave)
 
        mxs_reset_block(&ssp_regs->hw_ssp_ctrl0_reg);
 
-       writel(SSP_CTRL0_BUS_WIDTH_ONE_BIT, &ssp_regs->hw_ssp_ctrl0);
+       writel((slave->cs << MXS_SSP_CHIPSELECT_SHIFT) |
+              SSP_CTRL0_BUS_WIDTH_ONE_BIT,
+              &ssp_regs->hw_ssp_ctrl0);
 
        reg = SSP_CTRL1_SSP_MODE_SPI | SSP_CTRL1_WORD_LENGTH_EIGHT_BITS;
        reg |= (mxs_slave->mode & SPI_CPOL) ? SSP_CTRL1_POLARITY : 0;