]> git.sur5r.net Git - u-boot/blobdiff - drivers/spi/tegra20_sflash.c
dw_mmc: cleanups
[u-boot] / drivers / spi / tegra20_sflash.c
index bb1e57d5e80040beebfba7792dc559171a9f5dc8..b5d561be34108dade5a7450391ff9824461d03c9 100644 (file)
@@ -3,23 +3,7 @@
  * With help from the mpc8xxx SPI driver
  * With more help from omap3_spi SPI driver
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * 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+
  */
 
 #include <common.h>
@@ -101,7 +85,7 @@ static inline struct tegra_spi_slave *to_tegra_spi(struct spi_slave *slave)
        return container_of(slave, struct tegra_spi_slave, slave);
 }
 
-int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+int tegra20_spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
        /* Tegra20 SPI-Flash - only 1 device ('bus/cs') */
        if (bus != 0 || cs != 0)
@@ -110,8 +94,8 @@ int spi_cs_is_valid(unsigned int bus, unsigned int cs)
                return 1;
 }
 
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
-               unsigned int max_hz, unsigned int mode)
+struct spi_slave *tegra20_spi_setup_slave(unsigned int bus, unsigned int cs,
+                                 unsigned int max_hz, unsigned int mode)
 {
        struct tegra_spi_slave *spi;
 
@@ -127,13 +111,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                return NULL;
        }
 
-       spi = malloc(sizeof(struct tegra_spi_slave));
+       spi = spi_alloc_slave(struct tegra_spi_slave, bus, cs);
        if (!spi) {
                printf("SPI error: malloc of SPI structure failed\n");
                return NULL;
        }
-       spi->slave.bus = bus;
-       spi->slave.cs = cs;
        spi->ctrl = &spi_ctrls[bus];
        if (!spi->ctrl) {
                printf("SPI error: could not find controller for bus %d\n",
@@ -151,25 +133,20 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        return &spi->slave;
 }
 
-void spi_free_slave(struct spi_slave *slave)
+void tegra20_spi_free_slave(struct spi_slave *slave)
 {
        struct tegra_spi_slave *spi = to_tegra_spi(slave);
 
        free(spi);
 }
 
-void spi_init(void)
+int tegra20_spi_init(int *node_list, int count)
 {
        struct tegra_spi_ctrl *ctrl;
        int i;
        int node = 0;
-       int count;
-       int node_list[1];
+       int found = 0;
 
-       count = fdtdec_find_aliases_for_id(gd->fdt_blob, "spi",
-                                          COMPAT_NVIDIA_TEGRA20_SFLASH,
-                                          node_list,
-                                          1);
        for (i = 0; i < count; i++) {
                ctrl = &spi_ctrls[i];
                node = node_list[i];
@@ -193,13 +170,15 @@ void spi_init(void)
                        continue;
                }
                ctrl->valid = 1;
+               found = 1;
 
                debug("%s: found controller at %p, freq = %u, periph_id = %d\n",
                      __func__, ctrl->regs, ctrl->freq, ctrl->periph_id);
        }
+       return !found;
 }
 
-int spi_claim_bus(struct spi_slave *slave)
+int tegra20_spi_claim_bus(struct spi_slave *slave)
 {
        struct tegra_spi_slave *spi = to_tegra_spi(slave);
        struct spi_regs *regs = spi->ctrl->regs;
@@ -213,7 +192,7 @@ int spi_claim_bus(struct spi_slave *slave)
        reg = SPI_STAT_RDY | SPI_STAT_RXF_FLUSH | SPI_STAT_TXF_FLUSH | \
                SPI_STAT_RXF_UNR | SPI_STAT_TXF_OVF;
        writel(reg, &regs->status);
-       debug("spi_init: STATUS = %08x\n", readl(&regs->status));
+       debug("%s: STATUS = %08x\n", __func__, readl(&regs->status));
 
        /*
         * Use sw-controlled CS, so we can clock in data after ReadID, etc.
@@ -223,30 +202,20 @@ int spi_claim_bus(struct spi_slave *slave)
                reg |= 1 << SPI_CMD_ACTIVE_SCLK_SHIFT;
        clrsetbits_le32(&regs->command, SPI_CMD_ACTIVE_SCLK_MASK |
                SPI_CMD_ACTIVE_SDA_MASK, SPI_CMD_CS_SOFT | reg);
-       debug("spi_init: COMMAND = %08x\n", readl(&regs->command));
+       debug("%s: COMMAND = %08x\n", __func__, readl(&regs->command));
 
        /*
         * SPI pins on Tegra20 are muxed - change pinmux later due to UART
         * issue.
         */
-       pinmux_set_func(PINGRP_GMD, PMUX_FUNC_SFLASH);
-       pinmux_tristate_disable(PINGRP_LSPI);
-       pinmux_set_func(PINGRP_GMC, PMUX_FUNC_SFLASH);
+       pinmux_set_func(PMUX_PINGRP_GMD, PMUX_FUNC_SFLASH);
+       pinmux_tristate_disable(PMUX_PINGRP_LSPI);
+       pinmux_set_func(PMUX_PINGRP_GMC, PMUX_FUNC_SFLASH);
 
        return 0;
 }
 
-void spi_release_bus(struct spi_slave *slave)
-{
-       /*
-        * We can't release UART_DISABLE and set pinmux to UART4 here since
-        * some code (e,g, spi_flash_probe) uses printf() while the SPI
-        * bus is held. That is arguably bad, but it has the advantage of
-        * already being in the source tree.
-        */
-}
-
-void spi_cs_activate(struct spi_slave *slave)
+void tegra20_spi_cs_activate(struct spi_slave *slave)
 {
        struct tegra_spi_slave *spi = to_tegra_spi(slave);
        struct spi_regs *regs = spi->ctrl->regs;
@@ -255,7 +224,7 @@ void spi_cs_activate(struct spi_slave *slave)
        setbits_le32(&regs->command, SPI_CMD_CS_VAL);
 }
 
-void spi_cs_deactivate(struct spi_slave *slave)
+void tegra20_spi_cs_deactivate(struct spi_slave *slave)
 {
        struct tegra_spi_slave *spi = to_tegra_spi(slave);
        struct spi_regs *regs = spi->ctrl->regs;
@@ -264,7 +233,7 @@ void spi_cs_deactivate(struct spi_slave *slave)
        clrbits_le32(&regs->command, SPI_CMD_CS_VAL);
 }
 
-int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+int tegra20_spi_xfer(struct spi_slave *slave, unsigned int bitlen,
                const void *data_out, void *data_in, unsigned long flags)
 {
        struct tegra_spi_slave *spi = to_tegra_spi(slave);