Patchwork [U-Boot,05/14] spi: add common fdt SPI driver interface

login
register
mail settings
Submitter Allen Martin
Date Feb. 13, 2013, 3:23 a.m.
Message ID <1360725802-5518-6-git-send-email-amartin@nvidia.com>
Download mbox | patch
Permalink /patch/220053/
State Superseded
Delegated to: Tom Warren
Headers show

Comments

Allen Martin - Feb. 13, 2013, 3:23 a.m.
Add a common interface to fdt based SPI drivers.  Each driver is
represented by a table entry in fdt_spi_drivers[].  If there are
multiple SPI drivers in the table, the first driver to return success
from spi_init() will be registered as the SPI driver.

Signed-off-by: Allen Martin <amartin@nvidia.com>
---
 arch/arm/include/asm/arch-tegra20/tegra20_spi.h |   11 ++
 arch/arm/include/asm/arch-tegra30/tegra30_spi.h |   11 ++
 board/nvidia/common/board.c                     |    2 +-
 drivers/spi/Makefile                            |    1 +
 drivers/spi/fdt_spi.c                           |  172 +++++++++++++++++++++++
 drivers/spi/tegra20_spi.c                       |   41 ++----
 drivers/spi/tegra30_spi.c                       |   33 ++---
 include/configs/cardhu.h                        |    2 +-
 include/configs/tegra-common-post.h             |    4 +
 9 files changed, 228 insertions(+), 49 deletions(-)
 create mode 100644 drivers/spi/fdt_spi.c
Stephen Warren - Feb. 13, 2013, 10:40 p.m.
On 02/12/2013 08:23 PM, Allen Martin wrote:
> Add a common interface to fdt based SPI drivers.  Each driver is
> represented by a table entry in fdt_spi_drivers[].  If there are
> multiple SPI drivers in the table, the first driver to return success
> from spi_init() will be registered as the SPI driver.

I don't think there should be a global concept of "the" SPI driver;
instances of both SPI blocks exist on Tegra20, so they should be able to
co-exist, using the SFLASH driver for 1 SPI port, and the SLINK driver
for the other 4 ports.

How does this patch interact with any SPI-related device manager work?

> +void spi_init(void)
> +{
> +	int i;
> +	int num_drivers = sizeof(fdt_spi_drivers) /
> +		sizeof(struct fdt_spi_driver);

U-Boot doesn't have an ARSIZE/ARRAY_SIZE macro?

> diff --git a/include/configs/cardhu.h b/include/configs/cardhu.h

>  /* SPI */
>  #define CONFIG_TEGRA30_SPI
> -#define CONFIG_TEGRA_SLINK_CTRLS       6
> +#define CONFIG_TEGRA30_SPI_CTRLS       6

Should that be in one of the other patches?
Allen Martin - Feb. 14, 2013, 8:07 p.m.
On Wed, Feb 13, 2013 at 02:40:29PM -0800, Stephen Warren wrote:
> On 02/12/2013 08:23 PM, Allen Martin wrote:
> > Add a common interface to fdt based SPI drivers.  Each driver is
> > represented by a table entry in fdt_spi_drivers[].  If there are
> > multiple SPI drivers in the table, the first driver to return success
> > from spi_init() will be registered as the SPI driver.
> 
> I don't think there should be a global concept of "the" SPI driver;
> instances of both SPI blocks exist on Tegra20, so they should be able to
> co-exist, using the SFLASH driver for 1 SPI port, and the SLINK driver
> for the other 4 ports.

I agree, but that's probably beyond the scope of this series, as
that's a more global problem.  Other drivers call directly into the
SPI driver by use of well known function names, so that would need to
be abstracted to fix.

> 
> How does this patch interact with any SPI-related device manager work?

I'm not sure what device manager is in the context of u-boot.  Is that
the same as the unified driver model that's being documented in
doc/driver-model?  If so I think this fits in really well with that.
The "struct ops" described there is almost identical to the callbacks
I added in "struct fdt_spi_driver" 

> 
> > +void spi_init(void)
> > +{
> > +	int i;
> > +	int num_drivers = sizeof(fdt_spi_drivers) /
> > +		sizeof(struct fdt_spi_driver);
> 
> U-Boot doesn't have an ARSIZE/ARRAY_SIZE macro?

Will fix.

> 
> > diff --git a/include/configs/cardhu.h b/include/configs/cardhu.h
> 
> >  /* SPI */
> >  #define CONFIG_TEGRA30_SPI
> > -#define CONFIG_TEGRA_SLINK_CTRLS       6
> > +#define CONFIG_TEGRA30_SPI_CTRLS       6
> 
> Should that be in one of the other patches?

Yes, probably the renaming patch if we decide to keep it.
Stephen Warren - Feb. 14, 2013, 8:21 p.m.
On 02/14/2013 01:07 PM, Allen Martin wrote:
> On Wed, Feb 13, 2013 at 02:40:29PM -0800, Stephen Warren wrote:
>> On 02/12/2013 08:23 PM, Allen Martin wrote:
>>> Add a common interface to fdt based SPI drivers.  Each driver is
>>> represented by a table entry in fdt_spi_drivers[].  If there are
>>> multiple SPI drivers in the table, the first driver to return success
>>> from spi_init() will be registered as the SPI driver.
>>
>> I don't think there should be a global concept of "the" SPI driver;
>> instances of both SPI blocks exist on Tegra20, so they should be able to
>> co-exist, using the SFLASH driver for 1 SPI port, and the SLINK driver
>> for the other 4 ports.
> 
> I agree, but that's probably beyond the scope of this series, as
> that's a more global problem.  Other drivers call directly into the
> SPI driver by use of well known function names, so that would need to
> be abstracted to fix.

It should be simple to fix; you already have a table of all known
(DT-based) SPI drivers; simply iterate over all entries in the table
always, rather than stopping when you hit the first one. Also, don't
store /a/ pointer to the driver, but store a pointer per instance. I
think the modifications to your patch series to solve this shouldn't be
large at all.

>> How does this patch interact with any SPI-related device manager work?
> 
> I'm not sure what device manager is in the context of u-boot.  Is that
> the same as the unified driver model that's being documented in
> doc/driver-model?

Yes.

> If so I think this fits in really well with that.
> The "struct ops" described there is almost identical to the callbacks
> I added in "struct fdt_spi_driver" 

The code certainly looks like a move in the right direction. I was
thinking more along the lines of: Is anyone actively working on this
right now, so your patches will conflict.
Allen Martin - Feb. 14, 2013, 9:42 p.m.
On Thu, Feb 14, 2013 at 12:21:34PM -0800, Stephen Warren wrote:
> On 02/14/2013 01:07 PM, Allen Martin wrote:
> > On Wed, Feb 13, 2013 at 02:40:29PM -0800, Stephen Warren wrote:
> >> On 02/12/2013 08:23 PM, Allen Martin wrote:
> >>> Add a common interface to fdt based SPI drivers.  Each driver is
> >>> represented by a table entry in fdt_spi_drivers[].  If there are
> >>> multiple SPI drivers in the table, the first driver to return success
> >>> from spi_init() will be registered as the SPI driver.
> >>
> >> I don't think there should be a global concept of "the" SPI driver;
> >> instances of both SPI blocks exist on Tegra20, so they should be able to
> >> co-exist, using the SFLASH driver for 1 SPI port, and the SLINK driver
> >> for the other 4 ports.
> > 
> > I agree, but that's probably beyond the scope of this series, as
> > that's a more global problem.  Other drivers call directly into the
> > SPI driver by use of well known function names, so that would need to
> > be abstracted to fix.
> 
> It should be simple to fix; you already have a table of all known
> (DT-based) SPI drivers; simply iterate over all entries in the table
> always, rather than stopping when you hit the first one. Also, don't
> store /a/ pointer to the driver, but store a pointer per instance. I
> think the modifications to your patch series to solve this shouldn't be
> large at all.
> 

I don't think it will be that easy.  The different drivers would have
to coordinate on bus numbering, or there would have to be a new
"adapter number" addressing to differentiate the drivers, which would
be hard to do without impacting all the other non-fdt drivers as well.


> >> How does this patch interact with any SPI-related device manager work?
> > 
> > I'm not sure what device manager is in the context of u-boot.  Is that
> > the same as the unified driver model that's being documented in
> > doc/driver-model?
> 
> Yes.
> 
> > If so I think this fits in really well with that.
> > The "struct ops" described there is almost identical to the callbacks
> > I added in "struct fdt_spi_driver" 
> 
> The code certainly looks like a move in the right direction. I was
> thinking more along the lines of: Is anyone actively working on this
> right now, so your patches will conflict.

I haven't seen any, but I haven't been looking out for those patches
either, I'll look through the list archives and see if anyting turns
up. 

-Allen

Patch

diff --git a/arch/arm/include/asm/arch-tegra20/tegra20_spi.h b/arch/arm/include/asm/arch-tegra20/tegra20_spi.h
index 6789881..b272fc5 100644
--- a/arch/arm/include/asm/arch-tegra20/tegra20_spi.h
+++ b/arch/arm/include/asm/arch-tegra20/tegra20_spi.h
@@ -59,4 +59,15 @@ 
 #define SPI_STAT_SEL_TXRX_N		(1 << 16)
 #define SPI_STAT_CUR_BLKCNT		(1 << 15)
 
+int tegra20_spi_cs_is_valid(unsigned int bus, unsigned int cs);
+struct spi_slave *tegra20_spi_setup_slave(unsigned int bus, unsigned int cs,
+				  unsigned int max_hz, unsigned int mode);
+void tegra20_spi_free_slave(struct spi_slave *slave);
+int tegra20_spi_init(int *node_list, int count);
+int tegra20_spi_claim_bus(struct spi_slave *slave);
+void tegra20_spi_cs_activate(struct spi_slave *slave);
+void tegra20_spi_cs_deactivate(struct spi_slave *slave);
+int tegra20_spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+	     const void *data_out, void *data_in, unsigned long flags);
+
 #endif	/* _TEGRA20_SPI_H_ */
diff --git a/arch/arm/include/asm/arch-tegra30/tegra30_spi.h b/arch/arm/include/asm/arch-tegra30/tegra30_spi.h
index 87a8169..234a468 100644
--- a/arch/arm/include/asm/arch-tegra30/tegra30_spi.h
+++ b/arch/arm/include/asm/arch-tegra30/tegra30_spi.h
@@ -63,4 +63,15 @@ 
 #define SLINK_STAT2_RXF_FULL_CNT	(1 << 16)
 #define SLINK_STAT2_TXF_FULL_CNT	(1 << 0)
 
+int tegra30_spi_init(int *node_list, int count);
+int tegra30_spi_cs_is_valid(unsigned int bus, unsigned int cs);
+struct spi_slave *tegra30_spi_setup_slave(unsigned int bus, unsigned int cs,
+				  unsigned int max_hz, unsigned int mode);
+void tegra30_spi_free_slave(struct spi_slave *slave);
+int tegra30_spi_claim_bus(struct spi_slave *slave);
+void tegra30_spi_cs_activate(struct spi_slave *slave);
+void tegra30_spi_cs_deactivate(struct spi_slave *slave);
+int tegra30_spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+		     const void *data_out, void *data_in, unsigned long flags);
+
 #endif	/* _TEGRA30_SPI_H_ */
diff --git a/board/nvidia/common/board.c b/board/nvidia/common/board.c
index 18e6420..30e71a6 100644
--- a/board/nvidia/common/board.c
+++ b/board/nvidia/common/board.c
@@ -131,7 +131,7 @@  int board_init(void)
 #ifdef CONFIG_SPI_UART_SWITCH
 	gpio_config_uart();
 #endif
-#if defined(CONFIG_TEGRA20_SPI) || defined(CONFIG_TEGRA30_SPI)
+#ifdef CONFIG_FDT_SPI
 	pin_mux_spi();
 	spi_init();
 #endif
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index e9fccb5..5551d01 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -45,6 +45,7 @@  COBJS-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o
 COBJS-$(CONFIG_SH_SPI) += sh_spi.o
 COBJS-$(CONFIG_FSL_ESPI) += fsl_espi.o
+COBJS-$(CONFIG_FDT_SPI) += fdt_spi.o
 COBJS-$(CONFIG_TEGRA20_SPI) += tegra20_spi.o
 COBJS-$(CONFIG_TEGRA30_SPI) += tegra30_spi.o
 COBJS-$(CONFIG_XILINX_SPI) += xilinx_spi.o
diff --git a/drivers/spi/fdt_spi.c b/drivers/spi/fdt_spi.c
new file mode 100644
index 0000000..1a3937a
--- /dev/null
+++ b/drivers/spi/fdt_spi.c
@@ -0,0 +1,172 @@ 
+/*
+ * Common fdt based SPI driver front end
+ *
+ * Copyright (c) 2013 NVIDIA Corporation
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+#include <asm/arch/clock.h>
+#include <asm/arch-tegra/clk_rst.h>
+#include <asm/arch-tegra20/tegra20_spi.h>
+#include <asm/arch-tegra30/tegra30_spi.h>
+#include <spi.h>
+#include <fdtdec.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct fdt_spi_driver {
+	int compat;
+	int max_ctrls;
+	int (*init)(int *node_list, int count);
+	int (*claim_bus)(struct spi_slave *slave);
+	int (*release_bus)(struct spi_slave *slave);
+	int (*cs_is_valid)(unsigned int bus, unsigned int cs);
+	struct spi_slave *(*setup_slave)(unsigned int bus, unsigned int cs,
+					unsigned int max_hz, unsigned int mode);
+	void (*free_slave)(struct spi_slave *slave);
+	void (*cs_activate)(struct spi_slave *slave);
+	void (*cs_deactivate)(struct spi_slave *slave);
+	int (*xfer)(struct spi_slave *slave, unsigned int bitlen,
+		    const void *data_out, void *data_in, unsigned long flags);
+};
+
+static struct fdt_spi_driver fdt_spi_drivers[] = {
+#ifdef CONFIG_TEGRA20_SPI
+	{
+		.compat		= COMPAT_NVIDIA_TEGRA20_SFLASH,
+		.max_ctrls	= 1,
+		.init		= tegra20_spi_init,
+		.claim_bus	= tegra20_spi_claim_bus,
+		.cs_is_valid	= tegra20_spi_cs_is_valid,
+		.setup_slave	= tegra20_spi_setup_slave,
+		.free_slave	= tegra20_spi_free_slave,
+		.cs_activate	= tegra20_spi_cs_activate,
+		.cs_deactivate	= tegra20_spi_cs_deactivate,
+		.xfer		= tegra20_spi_xfer,
+	},
+#endif
+#ifdef CONFIG_TEGRA30_SPI
+	{
+		.compat		= COMPAT_NVIDIA_TEGRA20_SLINK,
+		.max_ctrls	= CONFIG_TEGRA30_SPI_CTRLS,
+		.init		= tegra30_spi_init,
+		.claim_bus	= tegra30_spi_claim_bus,
+		.cs_is_valid	= tegra30_spi_cs_is_valid,
+		.setup_slave	= tegra30_spi_setup_slave,
+		.free_slave	= tegra30_spi_free_slave,
+		.cs_activate	= tegra30_spi_cs_activate,
+		.cs_deactivate	= tegra30_spi_cs_deactivate,
+		.xfer		= tegra30_spi_xfer,
+	},
+#endif
+};
+
+static struct fdt_spi_driver *driver;
+
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+	if (!driver)
+		return 0;
+	else if (!driver->cs_is_valid)
+		return 1;
+	else
+		return driver->cs_is_valid(bus, cs);
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+		unsigned int max_hz, unsigned int mode)
+{
+	if (!driver || !driver->setup_slave)
+		return NULL;
+
+	return driver->setup_slave(bus, cs, max_hz, mode);
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+	if (driver && driver->free_slave)
+		return driver->free_slave(slave);
+}
+
+static int spi_init_driver(struct fdt_spi_driver *driver)
+{
+	int count;
+	int node_list[driver->max_ctrls];
+
+	count = fdtdec_find_aliases_for_id(gd->fdt_blob, "spi",
+					   driver->compat,
+					   node_list,
+					   driver->max_ctrls);
+	return driver->init(node_list, count);
+}
+
+void spi_init(void)
+{
+	int i;
+	int num_drivers = sizeof(fdt_spi_drivers) /
+		sizeof(struct fdt_spi_driver);
+	for (i = 0; i < num_drivers; i++) {
+		driver = &fdt_spi_drivers[i];
+		if (!spi_init_driver(driver))
+			break;
+	}
+	if (i == num_drivers)
+		driver = NULL;
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+	if (!driver)
+		return 1;
+	if (!driver->claim_bus)
+		return 0;
+
+	return driver->claim_bus(slave);
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+	if (driver && driver->release_bus)
+		driver->release_bus(slave);
+}
+
+void spi_cs_activate(struct spi_slave *slave)
+{
+	if (driver && driver->cs_activate)
+		driver->cs_activate(slave);
+}
+
+void spi_cs_deactivate(struct spi_slave *slave)
+{
+	if (driver && driver->cs_deactivate)
+		driver->cs_deactivate(slave);
+}
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+	     const void *data_out, void *data_in, unsigned long flags)
+{
+	if (!driver || !driver->xfer)
+		return -1;
+
+	return driver->xfer(slave, bitlen, data_out, data_in, flags);
+}
diff --git a/drivers/spi/tegra20_spi.c b/drivers/spi/tegra20_spi.c
index f3985f2..df481cb 100644
--- a/drivers/spi/tegra20_spi.c
+++ b/drivers/spi/tegra20_spi.c
@@ -76,7 +76,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)
@@ -85,8 +85,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;
 
@@ -126,25 +126,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];
@@ -168,13 +163,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;
@@ -188,7 +185,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.
@@ -198,7 +195,7 @@  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
@@ -219,17 +216,7 @@  int spi_claim_bus(struct spi_slave *slave)
 	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;
@@ -242,7 +229,7 @@  void spi_cs_activate(struct spi_slave *slave)
 	corrupt_delay();		/* Let UART settle */
 }
 
-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;
@@ -255,7 +242,7 @@  void spi_cs_deactivate(struct spi_slave *slave)
 	corrupt_delay();		/* Let SPI settle */
 }
 
-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);
diff --git a/drivers/spi/tegra30_spi.c b/drivers/spi/tegra30_spi.c
index 8f3dc8f..e94848d 100644
--- a/drivers/spi/tegra30_spi.c
+++ b/drivers/spi/tegra30_spi.c
@@ -64,22 +64,22 @@  struct tegra_spi_slave {
 	struct tegra_spi_ctrl *ctrl;
 };
 
-static struct tegra_spi_ctrl spi_ctrls[CONFIG_TEGRA_SLINK_CTRLS];
+static struct tegra_spi_ctrl spi_ctrls[CONFIG_TEGRA30_SPI_CTRLS];
 
 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 tegra30_spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
-	if (bus >= CONFIG_TEGRA_SLINK_CTRLS || cs > 3 || !spi_ctrls[bus].valid)
+	if (bus >= CONFIG_TEGRA30_SPI_CTRLS || cs > 3 || !spi_ctrls[bus].valid)
 		return 0;
 	else
 		return 1;
 }
 
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+struct spi_slave *tegra30_spi_setup_slave(unsigned int bus, unsigned int cs,
 		unsigned int max_hz, unsigned int mode)
 {
 	struct tegra_spi_slave *spi;
@@ -123,25 +123,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 tegra30_spi_free_slave(struct spi_slave *slave)
 {
 	struct tegra_spi_slave *spi = to_tegra_spi(slave);
 
 	free(spi);
 }
 
-void spi_init(void)
+int tegra30_spi_init(int *node_list, int count)
 {
 	struct tegra_spi_ctrl *ctrl;
 	int i;
 	int node = 0;
-	int count;
-	int node_list[CONFIG_TEGRA_SLINK_CTRLS];
+	int found = 0;
 
-	count = fdtdec_find_aliases_for_id(gd->fdt_blob, "spi",
-					   COMPAT_NVIDIA_TEGRA20_SLINK,
-					   node_list,
-					   CONFIG_TEGRA_SLINK_CTRLS);
 	for (i = 0; i < count; i++) {
 		ctrl = &spi_ctrls[i];
 		node = node_list[i];
@@ -165,13 +160,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 tegra30_spi_claim_bus(struct spi_slave *slave)
 {
 	struct tegra_spi_slave *spi = to_tegra_spi(slave);
 	struct spi_regs *regs = spi->ctrl->regs;
@@ -196,11 +193,7 @@  int spi_claim_bus(struct spi_slave *slave)
 	return 0;
 }
 
-void spi_release_bus(struct spi_slave *slave)
-{
-}
-
-void spi_cs_activate(struct spi_slave *slave)
+void tegra30_spi_cs_activate(struct spi_slave *slave)
 {
 	struct tegra_spi_slave *spi = to_tegra_spi(slave);
 	struct spi_regs *regs = spi->ctrl->regs;
@@ -209,7 +202,7 @@  void spi_cs_activate(struct spi_slave *slave)
 	setbits_le32(&regs->command, SLINK_CMD_CS_VAL);
 }
 
-void spi_cs_deactivate(struct spi_slave *slave)
+void tegra30_spi_cs_deactivate(struct spi_slave *slave)
 {
 	struct tegra_spi_slave *spi = to_tegra_spi(slave);
 	struct spi_regs *regs = spi->ctrl->regs;
@@ -218,7 +211,7 @@  void spi_cs_deactivate(struct spi_slave *slave)
 	clrbits_le32(&regs->command, SLINK_CMD_CS_VAL);
 }
 
-int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+int tegra30_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);
diff --git a/include/configs/cardhu.h b/include/configs/cardhu.h
index e7274f8..247bbaa 100644
--- a/include/configs/cardhu.h
+++ b/include/configs/cardhu.h
@@ -51,7 +51,7 @@ 
 
 /* SPI */
 #define CONFIG_TEGRA30_SPI
-#define CONFIG_TEGRA_SLINK_CTRLS       6
+#define CONFIG_TEGRA30_SPI_CTRLS       6
 #define CONFIG_SPI_FLASH
 #define CONFIG_SPI_FLASH_WINBOND
 #define CONFIG_SF_DEFAULT_MODE         SPI_MODE_0
diff --git a/include/configs/tegra-common-post.h b/include/configs/tegra-common-post.h
index f2a70b1..9e8b407 100644
--- a/include/configs/tegra-common-post.h
+++ b/include/configs/tegra-common-post.h
@@ -150,6 +150,10 @@ 
 	MEM_LAYOUT_ENV_SETTINGS \
 	BOOTCMDS_COMMON
 
+#if defined(CONFIG_TEGRA20_SPI) || defined(CONFIG_TEGRA30_SPI)
+#define CONFIG_FDT_SPI
+#endif
+
 /* overrides for SPL build here */
 #ifdef CONFIG_SPL_BUILD