]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - include/asm-ppc/4xx_pcie.h
ppc4xx: Dynamic configuration of 4xx PCIe mode as root or endpoint mode
[karo-tx-uboot.git] / include / asm-ppc / 4xx_pcie.h
index 17ac57b23bcd6a014de9eeb88de75926875b12c6..1830c6a8efd57fa80fbeb253859e7afca6f1fe86 100644 (file)
 #define U64_TO_U32_LOW(val)    ((u32)((val) & 0x00000000ffffffffULL))
 #define U64_TO_U32_HIGH(val)   ((u32)((val) >> 32))
 
+/*
+ * Prototypes
+ */
 int ppc4xx_init_pcie(void);
 int ppc4xx_init_pcie_rootport(int port);
 int ppc4xx_init_pcie_endport(int port);
@@ -251,6 +254,55 @@ void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
 int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
 int pcie_hose_scan(struct pci_controller *hose, int bus);
 
+/*
+ * Function to determine root port or endport from env variable.
+ */
+static inline int is_end_point(int port)
+{
+       static char s[10], *tk;
+
+       strcpy(s, getenv("pcie_mode"));
+       tk = strtok(s, ":");
+
+       switch (port) {
+       case 0:
+               if (tk != NULL) {
+                       if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
+                               return 1;
+                       else
+                               return 0;
+               }
+               else
+                       return 0;
+
+       case 1:
+               tk = strtok(NULL, ":");
+               if (tk != NULL) {
+                       if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
+                               return 1;
+                       else
+                               return 0;
+               }
+               else
+                       return 0;
+
+       case 2:
+               tk = strtok(NULL, ":");
+               if (tk != NULL)
+                       tk = strtok(NULL, ":");
+               if (tk != NULL) {
+                       if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
+                               return 1;
+                       else
+                               return 0;
+               }
+               else
+                       return 0;
+       }
+
+       return 0;
+}
+
 static inline void mdelay(int n)
 {
        u32 ms = n;