Re: [PATCH v4 1/3] spi: nxp_fspi: new driver for the FlexSPI controller

2020-01-06 Thread Michael Walle

Hi Jagan,

Am 2019-12-18 15:47, schrieb Jagan Teki:

On Wed, Dec 18, 2019 at 4:40 AM Michael Walle  wrote:


This is a port of the kernel's spi-nxp-fspi driver. It uses the new
spi-mem interface and does not expose the more generic spi-xfer
interface. The source was taken from the v5.3-rc3 tag.

The port was straightforward:
 - remove the interrupt handling and the completion by busy polling 
the

   controller
 - remove locks
 - move the setup of the memory windows into claim_bus()
 - move the setup of the speed into set_speed()
 - port the device tree bindings from the original fspi_probe() to
   ofdata_to_platdata()

There were only some style change fixes, no change in any logic. For
example, there are busy loops where the return code is not handled
correctly, eg. only prints a warning with WARN_ON(). This port
intentionally left most functions unchanged to ease future bugfixes.

This was tested on a custom LS1028A board. Because the LS1028A doesn't
have proper clock framework support, changing the clock speed was not
tested. This also means that it is not possible to change the SPI
speed on LS1028A for now (neither is it possible in the linux driver).

Signed-off-by: Michael Walle 
Reviewed-by: Jagan Teki 
Tested-by: Kuldeep Singh 


Applied to u-boot-spi/master


I can't find that one in your tree [1]. Did I miss something?

-michael

[1] https://gitlab.denx.de/u-boot/custodians/u-boot-spi/commits/master


Re: [PATCH v4 1/3] spi: nxp_fspi: new driver for the FlexSPI controller

2019-12-18 Thread Jagan Teki
On Wed, Dec 18, 2019 at 4:40 AM Michael Walle  wrote:
>
> This is a port of the kernel's spi-nxp-fspi driver. It uses the new
> spi-mem interface and does not expose the more generic spi-xfer
> interface. The source was taken from the v5.3-rc3 tag.
>
> The port was straightforward:
>  - remove the interrupt handling and the completion by busy polling the
>controller
>  - remove locks
>  - move the setup of the memory windows into claim_bus()
>  - move the setup of the speed into set_speed()
>  - port the device tree bindings from the original fspi_probe() to
>ofdata_to_platdata()
>
> There were only some style change fixes, no change in any logic. For
> example, there are busy loops where the return code is not handled
> correctly, eg. only prints a warning with WARN_ON(). This port
> intentionally left most functions unchanged to ease future bugfixes.
>
> This was tested on a custom LS1028A board. Because the LS1028A doesn't
> have proper clock framework support, changing the clock speed was not
> tested. This also means that it is not possible to change the SPI
> speed on LS1028A for now (neither is it possible in the linux driver).
>
> Signed-off-by: Michael Walle 
> Reviewed-by: Jagan Teki 
> Tested-by: Kuldeep Singh 

Applied to u-boot-spi/master


[PATCH v4 1/3] spi: nxp_fspi: new driver for the FlexSPI controller

2019-12-17 Thread Michael Walle
This is a port of the kernel's spi-nxp-fspi driver. It uses the new
spi-mem interface and does not expose the more generic spi-xfer
interface. The source was taken from the v5.3-rc3 tag.

The port was straightforward:
 - remove the interrupt handling and the completion by busy polling the
   controller
 - remove locks
 - move the setup of the memory windows into claim_bus()
 - move the setup of the speed into set_speed()
 - port the device tree bindings from the original fspi_probe() to
   ofdata_to_platdata()

There were only some style change fixes, no change in any logic. For
example, there are busy loops where the return code is not handled
correctly, eg. only prints a warning with WARN_ON(). This port
intentionally left most functions unchanged to ease future bugfixes.

This was tested on a custom LS1028A board. Because the LS1028A doesn't
have proper clock framework support, changing the clock speed was not
tested. This also means that it is not possible to change the SPI
speed on LS1028A for now (neither is it possible in the linux driver).

Signed-off-by: Michael Walle 
Reviewed-by: Jagan Teki 
Tested-by: Kuldeep Singh 
---
changes since v1:
 - fixed typo, thanks Jagan
changes since v2:
 - none
changes since v3:
 - move original copyright to the top

 drivers/spi/Kconfig|   7 +
 drivers/spi/Makefile   |   1 +
 drivers/spi/nxp_fspi.c | 996 +
 3 files changed, 1004 insertions(+)
 create mode 100644 drivers/spi/nxp_fspi.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 8588866489..d8d34fc021 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -192,6 +192,13 @@ config MVEBU_A3700_SPI
  used to access the SPI NOR flash on platforms embedding this
  Marvell IP core.
 
+config NXP_FSPI
+   bool "NXP FlexSPI driver"
+   depends on SPI_MEM
+   help
+ Enable the NXP FlexSPI (FSPI) driver. This driver can be used to
+ access the SPI NOR flash on platforms embedding this NXP IP core.
+
 config PIC32_SPI
bool "Microchip PIC32 SPI driver"
depends on MACH_PIC32
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index ae4f2958f8..52462e19a3 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_MSCC_BB_SPI) += mscc_bb_spi.o
 obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o
 obj-$(CONFIG_MXC_SPI) += mxc_spi.o
 obj-$(CONFIG_MXS_SPI) += mxs_spi.o
+obj-$(CONFIG_NXP_FSPI) += nxp_fspi.o
 obj-$(CONFIG_ATCSPI200_SPI) += atcspi200_spi.o
 obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 obj-$(CONFIG_PIC32_SPI) += pic32_spi.o
diff --git a/drivers/spi/nxp_fspi.c b/drivers/spi/nxp_fspi.c
new file mode 100644
index 00..a2fab7ad0a
--- /dev/null
+++ b/drivers/spi/nxp_fspi.c
@@ -0,0 +1,996 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * NXP FlexSPI(FSPI) controller driver.
+ *
+ * Copyright (c) 2019 Michael Walle 
+ * Copyright (c) 2019 NXP
+ *
+ * This driver was originally ported from the linux kernel v5.4-rc3, which had
+ * the following notes:
+ *
+ * FlexSPI is a flexsible SPI host controller which supports two SPI
+ * channels and up to 4 external devices. Each channel supports
+ * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
+ * data lines).
+ *
+ * FlexSPI controller is driven by the LUT(Look-up Table) registers
+ * LUT registers are a look-up-table for sequences of instructions.
+ * A valid sequence consists of four LUT registers.
+ * Maximum 32 LUT sequences can be programmed simultaneously.
+ *
+ * LUTs are being created at run-time based on the commands passed
+ * from the spi-mem framework, thus using single LUT index.
+ *
+ * Software triggered Flash read/write access by IP Bus.
+ *
+ * Memory mapped read access by AHB Bus.
+ *
+ * Based on SPI MEM interface and spi-fsl-qspi.c driver.
+ *
+ * Author:
+ * Yogesh Narayan Gaur 
+ * Boris Brezillon 
+ * Frieder Schrempf 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * The driver only uses one single LUT entry, that is updated on
+ * each call of exec_op(). Index 0 is preset at boot with a basic
+ * read operation, so let's use the last entry (31).
+ */
+#defineSEQID_LUT   31
+
+/* Registers used by the driver */
+#define FSPI_MCR0  0x00
+#define FSPI_MCR0_AHB_TIMEOUT(x)   ((x) << 24)
+#define FSPI_MCR0_IP_TIMEOUT(x)((x) << 16)
+#define FSPI_MCR0_LEARN_EN BIT(15)
+#define FSPI_MCR0_SCRFRUN_EN   BIT(14)
+#define FSPI_MCR0_OCTCOMB_EN   BIT(13)
+#define FSPI_MCR0_DOZE_EN  BIT(12)
+#define FSPI_MCR0_HSEN BIT(11)
+#define FSPI_MCR0_SERCLKDIVBIT(8)
+#define FSPI_MCR0_ATDF_EN  BIT(7)
+#define FSPI_MCR0_ARDF_EN  BIT(6)
+#define FSPI_MCR0_RXCLKSRC(x)  ((x) << 4)
+#define FSPI_MCR0_END_CFG(x)   ((x) << 2)
+#define FSPI_