Re: [U-Boot] [PATCH 13/14] tegra114: add SPI driver

2013-02-14 Thread Simon Glass
Hi Allen,

On Wed, Feb 13, 2013 at 2:59 PM, Stephen Warren swar...@wwwdotorg.org wrote:
 On 02/12/2013 08:23 PM, Allen Martin wrote:
 Subject: tegra114: add SPI driver

 This really touches the SPI sub-system more than Tegra, and the Tegra
 subsystem is just (and all of) Tegra not Tegra114-specific, so I'd
 re-title this:

 spi: tegra: add Tegra114 SPI driver

 similar s/tegra114:/tegra:/ in other patch subjects, many of which
 probably should be ARM: tegra: 

This driver seems to add a lot of duplication. What prevents using
common code? Is it the register layout, differences in algorithm or
something else?

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 13/14] tegra114: add SPI driver

2013-02-14 Thread Allen Martin
On Thu, Feb 14, 2013 at 06:32:06AM -0800, Simon Glass wrote:
 Hi Allen,
 
 On Wed, Feb 13, 2013 at 2:59 PM, Stephen Warren swar...@wwwdotorg.org wrote:
  On 02/12/2013 08:23 PM, Allen Martin wrote:
  Subject: tegra114: add SPI driver
 
  This really touches the SPI sub-system more than Tegra, and the Tegra
  subsystem is just (and all of) Tegra not Tegra114-specific, so I'd
  re-title this:
 
  spi: tegra: add Tegra114 SPI driver
 
  similar s/tegra114:/tegra:/ in other patch subjects, many of which
  probably should be ARM: tegra: 
 
 This driver seems to add a lot of duplication. What prevents using
 common code? Is it the register layout, differences in algorithm or
 something else?

Yes, unfortunately there really are three different SPI controller
hardware blocks.  There's sflash which is a tegra20 only block,
slink which is present in tegra20 and tegra30, and tegra114 has a
new SPI controller which is functionally equivalent to slink, but the
register interface is different.

The programming model is quite similar, but not exactly the same
between each.  For example, the same function may be one register
write on one chip and two or more register writes on another.  It
could be possible to hide some of those differences in macros or
inline functions, but I'm not sure if that's more or less messy.

-Allen
-- 
nvpublic
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 13/14] tegra114: add SPI driver

2013-02-13 Thread Stephen Warren
On 02/12/2013 08:23 PM, Allen Martin wrote:
 Subject: tegra114: add SPI driver

This really touches the SPI sub-system more than Tegra, and the Tegra
subsystem is just (and all of) Tegra not Tegra114-specific, so I'd
re-title this:

spi: tegra: add Tegra114 SPI driver

similar s/tegra114:/tegra:/ in other patch subjects, many of which
probably should be ARM: tegra: 
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 13/14] tegra114: add SPI driver

2013-02-12 Thread Allen Martin
Add driver for tegra114 SPI controller.  This controller is not
compatible with either the tegra20 or tegra30 controllers, so it
requires a new driver.

Signed-off-by: Allen Martin amar...@nvidia.com
---
 arch/arm/include/asm/arch-tegra114/tegra114_spi.h |   91 ++
 drivers/spi/Makefile  |1 +
 drivers/spi/fdt_spi.c |   15 +
 drivers/spi/tegra114_spi.c|  355 +
 include/configs/tegra-common-post.h   |2 +-
 5 files changed, 463 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/include/asm/arch-tegra114/tegra114_spi.h
 create mode 100644 drivers/spi/tegra114_spi.c

diff --git a/arch/arm/include/asm/arch-tegra114/tegra114_spi.h 
b/arch/arm/include/asm/arch-tegra114/tegra114_spi.h
new file mode 100644
index 000..bfbfa21
--- /dev/null
+++ b/arch/arm/include/asm/arch-tegra114/tegra114_spi.h
@@ -0,0 +1,91 @@
+/*
+ * NVIDIA Tegra SPI controller
+ *
+ * Copyright 2010-2013 NVIDIA Corporation
+ *
+ * This software may be used and distributed according to the
+ * terms of the GNU Public License, Version 2, incorporated
+ * herein by reference.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ *
+ * 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
+ */
+
+#ifndef _TEGRA114_SPI_H_
+#define _TEGRA114_SPI_H_
+
+#include asm/types.h
+
+/* COMMAND1 */
+#define SPI_CMD1_GO(1  31)
+#define SPI_CMD1_M_S   (1  30)
+#define SPI_CMD1_MODE_MASK 0x3
+#define SPI_CMD1_MODE_SHIFT28
+#define SPI_CMD1_CS_SEL_MASK   0x3
+#define SPI_CMD1_CS_SEL_SHIFT  26
+#define SPI_CMD1_CS_POL_INACTIVE3  (1  25)
+#define SPI_CMD1_CS_POL_INACTIVE2  (1  24)
+#define SPI_CMD1_CS_POL_INACTIVE1  (1  23)
+#define SPI_CMD1_CS_POL_INACTIVE0  (1  22)
+#define SPI_CMD1_CS_SW_HW  (1  21)
+#define SPI_CMD1_CS_SW_VAL (1  20)
+#define SPI_CMD1_IDLE_SDA_MASK 0x3
+#define SPI_CMD1_IDLE_SDA_SHIFT18
+#define SPI_CMD1_BIDIR (1  17)
+#define SPI_CMD1_LSBI_FE   (1  16)
+#define SPI_CMD1_LSBY_FE   (1  15)
+#define SPI_CMD1_BOTH_EN_BIT   (1  14)
+#define SPI_CMD1_BOTH_EN_BYTE  (1  13)
+#define SPI_CMD1_RX_EN (1  12)
+#define SPI_CMD1_TX_EN (1  11)
+#define SPI_CMD1_PACKED(1  5)
+#define SPI_CMD1_BIT_LEN_MASK  0x1F
+#define SPI_CMD1_BIT_LEN_SHIFT 0
+
+/* COMMAND2 */
+#define SPI_CMD2_TX_CLK_TAP_DELAY  (1  6)
+#define SPI_CMD2_TX_CLK_TAP_DELAY_MASK (0x3F  6)
+#define SPI_CMD2_RX_CLK_TAP_DELAY  (1  0)
+#define SPI_CMD2_RX_CLK_TAP_DELAY_MASK (0x3F  0)
+
+/* TRANSFER STATUS */
+#define SPI_XFER_STS_RDY   (1  30)
+
+/* FIFO STATUS */
+#define SPI_FIFO_STS_CS_INACTIVE   (1  31)
+#define SPI_FIFO_STS_FRAME_END (1  30)
+#define SPI_FIFO_STS_RX_FIFO_FLUSH (1  15)
+#define SPI_FIFO_STS_TX_FIFO_FLUSH (1  14)
+#define SPI_FIFO_STS_ERR   (1  8)
+#define SPI_FIFO_STS_TX_FIFO_OVF   (1  7)
+#define SPI_FIFO_STS_TX_FIFO_UNR   (1  6)
+#define SPI_FIFO_STS_RX_FIFO_OVF   (1  5)
+#define SPI_FIFO_STS_RX_FIFO_UNR   (1  4)
+#define SPI_FIFO_STS_TX_FIFO_FULL  (1  3)
+#define SPI_FIFO_STS_TX_FIFO_EMPTY (1  2)
+#define SPI_FIFO_STS_RX_FIFO_FULL  (1  1)
+#define SPI_FIFO_STS_RX_FIFO_EMPTY (1  0)
+
+int tegra114_spi_init(int *node_list, int count);
+int tegra114_spi_cs_is_valid(unsigned int bus, unsigned int cs);
+struct spi_slave *tegra114_spi_setup_slave(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int mode);
+void tegra114_spi_free_slave(struct spi_slave *slave);
+int tegra114_spi_claim_bus(struct spi_slave *slave);
+void tegra114_spi_cs_activate(struct spi_slave *slave);
+void tegra114_spi_cs_deactivate(struct spi_slave *slave);
+int tegra114_spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+const void *data_out, void *data_in, unsigned long flags);
+
+#endif /* _TEGRA114_SPI_H_ */
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 5551d01..275b70f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -48,6 +48,7 @@ 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) +=