board: turris_mox: Fixup U-Boot's device tree if PCIe connected
authorMarek BehĂșn <marek.behun@nic.cz>
Tue, 21 Aug 2018 10:22:09 +0000 (12:22 +0200)
committerStefan Roese <sr@denx.de>
Wed, 19 Sep 2018 07:00:39 +0000 (09:00 +0200)
If PCIe Mox module is connected we want to have PCIe node enabled
in U-Boot's device tree.

Signed-off-by: Marek Behun <marek.behun@nic.cz>
Signed-off-by: Stefan Roese <sr@denx.de>
arch/arm/dts/armada-3720-turris-mox.dts
board/CZ.NIC/turris_mox/turris_mox.c
configs/turris_mox_defconfig

index a72735ac0172316aa3584af328d5ff18dde270e8..7babc166799d89aa50386e4e57208f1514801f7f 100644 (file)
        vbus-supply = <&reg_usb3_vbus>;
        status = "okay";
 };
+
+&pcie0 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pcie_pins>;
+       reset-gpio = <&gpiosb 3 GPIO_ACTIVE_HIGH>;
+       status = "disabled";
+};
index b6a0ca462641bf87084c6234e39a376895daed84..c4622a49c2e47759d6aa0ff22a15793ba99012eb 100644 (file)
@@ -4,17 +4,99 @@
  */
 
 #include <common.h>
+#include <asm/io.h>
 #include <dm.h>
 #include <clk.h>
 #include <spi.h>
 #include <linux/string.h>
+#include <linux/libfdt.h>
+#include <fdt_support.h>
 
 #ifdef CONFIG_WDT_ARMADA_37XX
 #include <wdt.h>
 #endif
 
+#define MAX_MOX_MODULES                10
+
+#define MOX_MODULE_SFP         0x1
+#define MOX_MODULE_PCI         0x2
+#define MOX_MODULE_TOPAZ       0x3
+#define MOX_MODULE_PERIDOT     0x4
+#define MOX_MODULE_USB3                0x5
+#define MOX_MODULE_PASSPCI     0x6
+
+#define ARMADA_37XX_NB_GPIO_SEL        0xd0013830
+#define ARMADA_37XX_SPI_CTRL   0xd0010600
+#define ARMADA_37XX_SPI_CFG    0xd0010604
+#define ARMADA_37XX_SPI_DOUT   0xd0010608
+#define ARMADA_37XX_SPI_DIN    0xd001060c
+
+#define PCIE_PATH      "/soc/pcie@d0070000"
+
 DECLARE_GLOBAL_DATA_PTR;
 
+#if defined(CONFIG_OF_BOARD_FIXUP)
+int board_fix_fdt(void *blob)
+{
+       u8 topology[MAX_MOX_MODULES];
+       int i, size, node;
+       bool enable;
+
+       /*
+        * SPI driver is not loaded in driver model yet, but we have to find out
+        * if pcie should be enabled in U-Boot's device tree. Therefore we have
+        * 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);
+
+       while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2))
+               udelay(1);
+
+       for (i = 0; i < MAX_MOX_MODULES; ++i) {
+               writel(0x0, ARMADA_37XX_SPI_DOUT);
+
+               while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2))
+                       udelay(1);
+
+               topology[i] = readl(ARMADA_37XX_SPI_DIN) & 0xff;
+               if (topology[i] == 0xff)
+                       break;
+
+               topology[i] &= 0xf;
+       }
+
+       size = i;
+
+       writel(0x5b, ARMADA_37XX_SPI_CTRL);
+
+       if (size > 1 && (topology[1] == MOX_MODULE_PCI ||
+                        topology[1] == MOX_MODULE_USB3 ||
+                        topology[1] == MOX_MODULE_PASSPCI))
+               enable = true;
+       else
+               enable = false;
+
+       node = fdt_path_offset(blob, PCIE_PATH);
+
+       if (node < 0) {
+               printf("Cannot find PCIe node in U-Boot's device tree!\n");
+               return 0;
+       }
+
+       if (fdt_setprop_string(blob, node, "status",
+                              enable ? "okay" : "disabled") < 0) {
+               printf("Cannot %s PCIe in U-Boot's device tree!\n",
+                      enable ? "enable" : "disable");
+               return 0;
+       }
+
+       return 0;
+}
+#endif
+
 #ifdef CONFIG_WDT_ARMADA_37XX
 static struct udevice *watchdog_dev;
 
index fb13b7ef7af23614b88a13afa5fcd0f501d39efe..6463abcd3d44a992d15bd02fb022bdd1b4a84c0f 100644 (file)
@@ -13,6 +13,7 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_ARCH_EARLY_INIT_R=y
+CONFIG_OF_BOARD_FIXUP=y
 CONFIG_CMD_CLK=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_I2C=y