]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - board/enbw/enbw_cmc/enbw_cmc.c
Merge remote-tracking branch 'u-boot-samsung/master'
[karo-tx-uboot.git] / board / enbw / enbw_cmc / enbw_cmc.c
index 67d5d4d6e5f0e35b627f5c1b8a1b2fb1e2f9aa7f..53b83621473239e2ce5739c7c00ce38099696768 100644 (file)
  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <asm/arch/da850_lowlevel.h>
 #include <asm/arch/davinci_misc.h>
-#include <asm/arch/emif_defs.h>
+#include <asm/ti-common/davinci_nand.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/pinmux_defs.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/sdmmc_defs.h>
 #include <asm/arch/timer_defs.h>
+#include <asm/davinci_rtc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -451,25 +440,15 @@ static char *enbw_cmc_getvalue(char *ptr, int *value)
        return ptr;
 }
 
-static int enbw_cmc_config_switch(unsigned long addr)
+static struct spi_slave *enbw_cmc_init_spi(void)
 {
        struct spi_slave *spi;
-       char *ptr = (char *)addr;
-       int value, reg;
        int ret;
-       int bus, cs, max_hz, spi_mode;
 
-       debug("configure switch with file on addr: 0x%lx\n", addr);
-
-       bus = 0;
-       cs = 0;
-       max_hz = 1000000;
-       spi_mode = 0;
-
-       spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
+       spi = spi_setup_slave(0, 0, 1000000, 0);
        if (!spi) {
                printf("Failed to set up slave\n");
-               return -EINVAL;
+               return NULL;
        }
 
        ret = spi_claim_bus(spi);
@@ -480,25 +459,45 @@ static int enbw_cmc_config_switch(unsigned long addr)
 
        ret = enbw_cmc_switch_read_ident(spi);
        if (ret)
-               goto err_claim_bus;
+               goto err_read;
+
+       return spi;
+err_read:
+       spi_release_bus(spi);
+err_claim_bus:
+       spi_free_slave(spi);
+       return NULL;
+}
+
+static int enbw_cmc_config_switch(unsigned long addr)
+{
+       struct spi_slave *spi;
+       char *ptr = (char *)addr;
+       int value, reg;
+       int ret = 0;
+
+       debug("configure switch with file on addr: 0x%lx\n", addr);
+
+       spi = enbw_cmc_init_spi();
+       if (!spi)
+               return -EINVAL;
 
-       ptr = (char *)addr;
        while (ptr != NULL) {
                ptr = enbw_cmc_getvalue(ptr, &reg);
                if (ptr != NULL) {
                        ptr = enbw_cmc_getvalue(ptr, &value);
                        if ((ptr != NULL) && (value >= 0))
-                               if (enbw_cmc_switch_write(spi, reg, value))
-                                       goto err_read;
+                               if (enbw_cmc_switch_write(spi, reg, value)) {
+                                       /* error writing to switch */
+                                       ptr = NULL;
+                                       ret = -EINVAL;
+                               }
                }
        }
-       return 0;
 
-err_read:
        spi_release_bus(spi);
-err_claim_bus:
        spi_free_slave(spi);
-       return -EINVAL;
+       return ret;
 }
 
 static int do_switch(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
@@ -524,8 +523,10 @@ U_BOOT_CMD(switch, 3, 1, do_switch,
  */
 int board_eth_init(bd_t *bis)
 {
+       struct spi_slave *spi;
        const char *s;
-       size_t len;
+       size_t len = 0;
+       int config = 1;
 
        davinci_emac_mii_mode_sel(0);
 
@@ -534,25 +535,49 @@ int board_eth_init(bd_t *bis)
        if (len) {
                unsigned long addr = simple_strtoul(s, NULL, 16);
 
-               enbw_cmc_config_switch(addr);
+               config = enbw_cmc_config_switch(addr);
        }
 
+       if (config) {
+               /*
+                * no valid config file -> do we have some args in
+                * hwconfig ?
+                */
+               if ((hwconfig_subarg("switch", "lan", &len)) ||
+                   (hwconfig_subarg("switch", "lmn", &len))) {
+                       /* If so start switch */
+                       spi = enbw_cmc_init_spi();
+                       if (spi) {
+                               if (enbw_cmc_switch_write(spi, 1, 0))
+                                       config = 0;
+                               udelay(10000);
+                               if (enbw_cmc_switch_write(spi, 1, 1))
+                                       config = 0;
+                               spi_release_bus(spi);
+                               spi_free_slave(spi);
+                       }
+               } else {
+                       config = 0;
+               }
+       }
        if (!davinci_emac_initialize()) {
                printf("Error: Ethernet init failed!\n");
                return -1;
        }
 
-       if (hwconfig_subarg_cmp("switch", "lan", "on"))
-               /* Switch port lan on */
-               enbw_cmc_switch(1, 1);
-       else
-               enbw_cmc_switch(1, 0);
+       if (config) {
+               if (hwconfig_subarg_cmp("switch", "lan", "on"))
+                       /* Switch port lan on */
+                       enbw_cmc_switch(1, 1);
+               else
+                       enbw_cmc_switch(1, 0);
 
-       if (hwconfig_subarg_cmp("switch", "pwl", "on"))
-               /* Switch port pwl on */
-               enbw_cmc_switch(2, 1);
-       else
-               enbw_cmc_switch(2, 0);
+               if (hwconfig_subarg_cmp("switch", "lmn", "on"))
+                       /* Switch port pwl on */
+                       enbw_cmc_switch(2, 1);
+               else
+                       enbw_cmc_switch(2, 0);
+       }
 
        return 0;
 }