On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún <[email protected]>

The pre-relocation board topology reading in board_fix_fdt() is
unstable: sometimes wrong data are read from the SPI bus.

This is due to wrong order of SPI bus configuration instructions: we
first need to set the pins to SPI mode, and only after that configure
the bus.

Also add a 1ms delay before enabling chip-select, so that the clock pin
is high for some time before reading the bus.

Signed-off-by: Marek Behún <[email protected]>

Reviewed-by: Stefan Roese <[email protected]>

Thanks,
Stefan

---
  board/CZ.NIC/turris_mox/turris_mox.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index 502f6fc010..809ce82d20 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -56,9 +56,11 @@ int board_fix_fdt(void *blob)
         * to read SPI by reading/writing SPI registers directly
         */
- writel(0x10df, ARMADA_37XX_SPI_CFG);
        /* put pin from GPIO to SPI mode */
        clrbits_le32(ARMADA_37XX_NB_GPIO_SEL, BIT(12));
+       /* configure cpol, cpha, prescale */
+       writel(0x10df, ARMADA_37XX_SPI_CFG);
+       mdelay(1);
        /* enable SPI CS1 */
        setbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));

Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]

Reply via email to