arm: mvebu: turris_mox: Fix early SPI communication
authorMarek Behún <marek.behun@nic.cz>
Wed, 8 Apr 2020 10:02:03 +0000 (12:02 +0200)
committerStefan Roese <sr@denx.de>
Tue, 14 Apr 2020 11:16:42 +0000 (13:16 +0200)
The SPI clock signal changes value when the SPI configuration register
is configured. This can sometimes lead to the device misinterpreting
the enablement of the SPI controller as actual clock tick.
This can be solved by first setting the SPI CS1 pin from GPIO to SPI mode,
and only after that writing the SPI configuration register.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
board/CZ.NIC/turris_mox/turris_mox.c

index 377191baefbe22544f5c0e3b654447fa6348044e..0b13d1d1902a82c364efc7c34a7d4f15df787072 100644 (file)
@@ -67,9 +67,11 @@ int board_fix_fdt(void *blob)
         * to read SPI by reading/writing SPI registers directly
         */
 
-       writel(0x563fa, ARMADA_37XX_NB_GPIO_SEL);
        writel(0x10df, ARMADA_37XX_SPI_CFG);
-       writel(0x2005b, ARMADA_37XX_SPI_CTRL);
+       /* put pin from GPIO to SPI mode */
+       clrbits_le32(ARMADA_37XX_NB_GPIO_SEL, BIT(12));
+       /* enable SPI CS1 */
+       setbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));
 
        while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2))
                udelay(1);
@@ -89,7 +91,8 @@ int board_fix_fdt(void *blob)
 
        size = i;
 
-       writel(0x5b, ARMADA_37XX_SPI_CTRL);
+       /* disable SPI CS1 */
+       clrbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));
 
        if (size > 1 && (topology[1] == MOX_MODULE_PCI ||
                         topology[1] == MOX_MODULE_USB3 ||