Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / powerpc / cpu / mpc85xx / mpc8536_serdes.c
index ec96e81ed5ecf5c5c35b00e3dd5b8be485230724..111692f15d1830134e28be8f4f56d472020032ef 100644 (file)
@@ -1,28 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2008,2010 Freescale Semiconductor, Inc.
  *     Dave Liu <daveliu@freescale.com>
- *
- * 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
  */
 
 #include <config.h>
 #include <common.h>
+#include <log.h>
 #include <asm/io.h>
 #include <asm/immap_85xx.h>
 #include <asm/fsl_serdes.h>
@@ -87,11 +71,19 @@ static u8 serdes2_cfg_tbl[][SRDS2_MAX_LANES] = {
 
 int is_serdes_configured(enum srds_prtcl device)
 {
-       int ret = (1 << device) & serdes1_prtcl_map;
+       int ret;
+
+       if (!(serdes1_prtcl_map & (1 << NONE)))
+               fsl_serdes_init();
+
+       ret = (1 << device) & serdes1_prtcl_map;
 
        if (ret)
                return ret;
 
+       if (!(serdes2_prtcl_map & (1 << NONE)))
+               fsl_serdes_init();
+
        return (1 << device) & serdes2_prtcl_map;
 }
 
@@ -104,6 +96,10 @@ void fsl_serdes_init(void)
        u32 tmp;
        int lane;
 
+       if (serdes1_prtcl_map & (1 << NONE) &&
+           serdes2_prtcl_map & (1 << NONE))
+               return;
+
        srds1_io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
                                MPC85xx_PORDEVSR_IO_SEL_SHIFT;
 
@@ -237,6 +233,9 @@ void fsl_serdes_init(void)
                serdes1_prtcl_map |= (1 << lane_prtcl);
        }
 
+       /* Set the first bit to indicate serdes has been initialized */
+       serdes1_prtcl_map |= (1 << NONE);
+
        if (srds2_io_sel >= ARRAY_SIZE(serdes2_cfg_tbl)) {
                printf("Invalid PORDEVSR[SRDS2_IO_SEL] = %d\n", srds2_io_sel);
                return;
@@ -246,4 +245,7 @@ void fsl_serdes_init(void)
                enum srds_prtcl lane_prtcl = serdes2_cfg_tbl[srds2_io_sel][lane];
                serdes2_prtcl_map |= (1 << lane_prtcl);
        }
+
+       /* Set the first bit to indicate serdes has been initialized */
+       serdes2_prtcl_map |= (1 << NONE);
 }