net: fm: use get_nand_dev_by_index()
[oweals/u-boot.git] / drivers / net / fm / b4860.c
index 3b5defefa62e1c9b7614d7c733f06325ba8920cc..5aeeb872824826b4c5fb8a243487d604e1e6c453 100644 (file)
@@ -2,20 +2,7 @@
  * Copyright 2012 Freescale Semiconductor, Inc.
  *     Roy Zang <tie-fei.zang@freescale.com>
  *
- * 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 <phy.h>
@@ -23,6 +10,7 @@
 #include <asm/io.h>
 #include <asm/immap_85xx.h>
 #include <asm/fsl_serdes.h>
+#include <hwconfig.h>
 
 u32 port_to_devdisr[] = {
        [FM1_DTSEC1] = FSL_CORENET_DEVDISR2_DTSEC1_1,
@@ -50,17 +38,86 @@ void fman_disable_port(enum fm_port port)
        setbits_be32(&gur->devdisr2, port_to_devdisr[port]);
 }
 
+void fman_enable_port(enum fm_port port)
+{
+       ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+
+       clrbits_be32(&gur->devdisr2, port_to_devdisr[port]);
+}
+
 phy_interface_t fman_port_enet_if(enum fm_port port)
 {
+#if defined(CONFIG_TARGET_B4860QDS) || defined(CONFIG_TARGET_B4420QDS)
+       u32 serdes2_prtcl;
+       char buffer[HWCONFIG_BUFFER_SIZE];
+       char *buf = NULL;
+       ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+#endif
+
        if (is_device_disabled(port))
                return PHY_INTERFACE_MODE_NONE;
 
        /*B4860 has two 10Gig Mac*/
        if ((port == FM1_10GEC1 || port == FM1_10GEC2)  &&
            ((is_serdes_configured(XAUI_FM1_MAC9))      ||
-           (is_serdes_configured(XAUI_FM1_MAC10))))
+            #if (!defined(CONFIG_TARGET_B4860QDS) && \
+                 !defined(CONFIG_TARGET_B4R420QDS))
+            (is_serdes_configured(XFI_FM1_MAC9))       ||
+            (is_serdes_configured(XFI_FM1_MAC10))      ||
+            #endif
+            (is_serdes_configured(XAUI_FM1_MAC10))
+            ))
                return PHY_INTERFACE_MODE_XGMII;
 
+#if defined(CONFIG_TARGET_B4860QDS) || defined(CONFIG_TARGET_B4420QDS)
+       serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
+                       FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
+
+       if (serdes2_prtcl) {
+               serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
+               switch (serdes2_prtcl) {
+               case 0x80:
+               case 0x81:
+               case 0x82:
+               case 0x83:
+               case 0x84:
+               case 0x85:
+               case 0x86:
+               case 0x87:
+               case 0x88:
+               case 0x89:
+               case 0x8a:
+               case 0x8b:
+               case 0x8c:
+               case 0x8d:
+               case 0x8e:
+               case 0xb1:
+               case 0xb2:
+                       /*
+                        * Extract hwconfig from environment since environment
+                        * is not setup yet
+                        */
+                       getenv_f("hwconfig", buffer, sizeof(buffer));
+                       buf = buffer;
+
+                       /* check if XFI interface enable in hwconfig for 10g */
+                       if (hwconfig_subarg_cmp_f("fsl_b4860_serdes2",
+                                                 "sfp_amc", "sfp", buf)) {
+                               if ((port == FM1_10GEC1 ||
+                                    port == FM1_10GEC2) &&
+                                   ((is_serdes_configured(XFI_FM1_MAC9)) ||
+                                   (is_serdes_configured(XFI_FM1_MAC10))))
+                                       return PHY_INTERFACE_MODE_XGMII;
+                               else if ((port == FM1_DTSEC1) ||
+                                        (port == FM1_DTSEC2) ||
+                                        (port == FM1_DTSEC3) ||
+                                        (port == FM1_DTSEC4))
+                                       return PHY_INTERFACE_MODE_NONE;
+                       }
+               }
+       }
+#endif
+
        /* Fix me need to handle RGMII here first */
 
        switch (port) {