Kconfig: Add CONFIG_SATA to enable SATA
[oweals/u-boot.git] / arch / powerpc / cpu / mpc85xx / portals.c
index b59ef69f1f6c5aa123aae4ae80191fd926047461..3777c6faa166142685e0364e4e23c82d010b3346 100644 (file)
@@ -1,23 +1,7 @@
 /*
  * Copyright 2008-2011 Freescale Semiconductor, Inc.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/fsl_portals.h>
 #include <asm/fsl_liodn.h>
 
-static ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
-static ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
+#define MAX_BPORTALS (CONFIG_SYS_BMAN_CINH_SIZE / CONFIG_SYS_BMAN_SP_CINH_SIZE)
+#define MAX_QPORTALS (CONFIG_SYS_QMAN_CINH_SIZE / CONFIG_SYS_QMAN_SP_CINH_SIZE)
+static void inhibit_portals(void __iomem *addr, int max_portals,
+                       int arch_max_portals, int portal_cinh_size)
+{
+       uint32_t val;
+       int i;
+
+       /* arch_max_portals is the maximum based on memory size. This includes
+        * the reserved memory in the SoC.  max_portals the number of physical
+        * portals in the SoC */
+       if (max_portals > arch_max_portals) {
+               printf("ERROR: portal config error\n");
+               max_portals = arch_max_portals;
+       }
+
+       for (i = 0; i < max_portals; i++) {
+               out_be32(addr, -1);
+               val = in_be32(addr);
+               if (!val) {
+                       printf("ERROR: Stopped after %d portals\n", i);
+                       goto done;
+               }
+               addr += portal_cinh_size;
+       }
+#ifdef DEBUG
+       printf("Cleared %d portals\n", i);
+#endif
+done:
+
+       return;
+}
 
 void setup_portals(void)
 {
+       ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
+       void __iomem *bpaddr = (void *)CONFIG_SYS_BMAN_CINH_BASE +
+                               CONFIG_SYS_BMAN_SWP_ISDR_REG;
+       void __iomem *qpaddr = (void *)CONFIG_SYS_QMAN_CINH_BASE +
+                               CONFIG_SYS_QMAN_SWP_ISDR_REG;
 #ifdef CONFIG_FSL_CORENET
        int i;
 
@@ -56,6 +75,12 @@ void setup_portals(void)
        out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32));
 #endif
        out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS);
+
+       /* Change default state of BMan ISDR portals to all 1s */
+       inhibit_portals(bpaddr, CONFIG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS,
+                       CONFIG_SYS_BMAN_SP_CINH_SIZE);
+       inhibit_portals(qpaddr, CONFIG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS,
+                       CONFIG_SYS_QMAN_SP_CINH_SIZE);
 }
 
 /* Update portal containter to match LAW setup of portal in phy map */
@@ -130,24 +155,32 @@ static int fdt_qportal(void *blob, int off, int id, char *name,
 
        childoff = fdt_subnode_offset(blob, off, name);
        if (create) {
-               if (childoff <= 0)
-                       childoff = fdt_add_subnode(blob, off, name);
+               char handle[64], *p;
 
-               if (childoff > 0) {
-                       char handle[64], *p;
+               strncpy(handle, name, sizeof(handle));
+               p = strchr(handle, '@');
+               if (!strncmp(name, "fman", 4)) {
+                       *p = *(p + 1);
+                       p++;
+               }
+               *p = '\0';
 
-                       strncpy(handle, name, sizeof(handle));
-                       p = strchr(handle, '@');
-                       if (!strncmp(name, "fman", 4)) {
-                               *p = *(p + 1);
-                               p++;
-                       }
-                       *p = '\0';
+               dev_off = fdt_path_offset(blob, handle);
+               /* skip this node if alias is not found */
+               if (dev_off == -FDT_ERR_BADPATH)
+                       return 0;
+               if (dev_off < 0)
+                       return dev_off;
+
+               if (childoff <= 0)
+                       childoff = fdt_add_subnode(blob, off, name);
 
-                       dev_off = fdt_path_offset(blob, handle);
-                       if (dev_off < 0)
-                               return dev_off;
+               /* need to update the dev_off after adding a subnode */
+               dev_off = fdt_path_offset(blob, handle);
+               if (dev_off < 0)
+                       return dev_off;
 
+               if (childoff > 0) {
                        dev_handle = fdt_get_phandle(blob, dev_off);
                        if (dev_handle <= 0) {
                                dev_handle = fdt_alloc_phandle(blob);
@@ -166,6 +199,20 @@ static int fdt_qportal(void *blob, int off, int id, char *name,
                        num = get_dpaa_liodn(dev, &liodns[0], id);
                        ret = fdt_setprop(blob, childoff, "fsl,liodn",
                                          &liodns[0], sizeof(u32) * num);
+                       if (!strncmp(name, "pme", 3)) {
+                               u32 pme_rev1, pme_rev2;
+                               ccsr_pme_t *pme_regs =
+                                       (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR;
+
+                               pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1);
+                               pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2);
+                               ret = fdt_setprop(blob, childoff,
+                                       "fsl,pme-rev1", &pme_rev1, sizeof(u32));
+                               if (ret < 0)
+                                       return ret;
+                               ret = fdt_setprop(blob, childoff,
+                                       "fsl,pme-rev2", &pme_rev2, sizeof(u32));
+                       }
 #endif
                } else {
                        return childoff;
@@ -183,6 +230,7 @@ void fdt_fixup_qportals(void *blob)
        int off, err;
        unsigned int maj, min;
        unsigned int ip_cfg;
+       ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR;
        u32 rev_1 = in_be32(&qman->ip_rev_1);
        u32 rev_2 = in_be32(&qman->ip_rev_2);
        char compat[64];
@@ -201,8 +249,13 @@ void fdt_fixup_qportals(void *blob)
 #ifdef CONFIG_FSL_CORENET
                u32 liodns[2];
 #endif
-               const int *ci = fdt_getprop(blob, off, "cell-index", NULL);
-               int i = *ci;
+               const int *ci = fdt_getprop(blob, off, "cell-index", &err);
+               int i;
+
+               if (!ci)
+                       goto err;
+
+               i = *ci;
 #ifdef CONFIG_SYS_DPAA_FMAN
                int j;
 #endif
@@ -272,6 +325,7 @@ void fdt_fixup_bportals(void *blob)
        int off, err;
        unsigned int maj, min;
        unsigned int ip_cfg;
+       ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR;
        u32 rev_1 = in_be32(&bman->ip_rev_1);
        u32 rev_2 = in_be32(&bman->ip_rev_2);
        char compat[64];