mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-17 20:51:39 +00:00
davinci: enbw_cmc: change switch init behaviour
change the behaviour of switch initialization: - rename "pwl" to "lan" in hwconfig parameter "lan" = port 1 with phy addr 2 "lmn" = port 2 with phy addr 3 - if we have a valid switch config file in flash, do not evaluate the settings in the hwconfig "lan" or "lmn" subcommand. - if we have no valid switch config file in flash, start the switch with default values, if we have a "lan" or a "lmn" hwconfig subcommand. If no "lan" or "lmn" is found in hwconfig, do nothing with the switch. Signed-off-by: Heiko Schocher <hs@denx.de>
This commit is contained in:
parent
6995a28937
commit
1bb0946b5c
1 changed files with 69 additions and 33 deletions
|
@ -451,25 +451,15 @@ static char *enbw_cmc_getvalue(char *ptr, int *value)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int enbw_cmc_config_switch(unsigned long addr)
|
static struct spi_slave *enbw_cmc_init_spi(void)
|
||||||
{
|
{
|
||||||
struct spi_slave *spi;
|
struct spi_slave *spi;
|
||||||
char *ptr = (char *)addr;
|
|
||||||
int value, reg;
|
|
||||||
int ret;
|
int ret;
|
||||||
int bus, cs, max_hz, spi_mode;
|
|
||||||
|
|
||||||
debug("configure switch with file on addr: 0x%lx\n", addr);
|
spi = spi_setup_slave(0, 0, 1000000, 0);
|
||||||
|
|
||||||
bus = 0;
|
|
||||||
cs = 0;
|
|
||||||
max_hz = 1000000;
|
|
||||||
spi_mode = 0;
|
|
||||||
|
|
||||||
spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
|
|
||||||
if (!spi) {
|
if (!spi) {
|
||||||
printf("Failed to set up slave\n");
|
printf("Failed to set up slave\n");
|
||||||
return -EINVAL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = spi_claim_bus(spi);
|
ret = spi_claim_bus(spi);
|
||||||
|
@ -480,25 +470,45 @@ static int enbw_cmc_config_switch(unsigned long addr)
|
||||||
|
|
||||||
ret = enbw_cmc_switch_read_ident(spi);
|
ret = enbw_cmc_switch_read_ident(spi);
|
||||||
if (ret)
|
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) {
|
while (ptr != NULL) {
|
||||||
ptr = enbw_cmc_getvalue(ptr, ®);
|
ptr = enbw_cmc_getvalue(ptr, ®);
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
ptr = enbw_cmc_getvalue(ptr, &value);
|
ptr = enbw_cmc_getvalue(ptr, &value);
|
||||||
if ((ptr != NULL) && (value >= 0))
|
if ((ptr != NULL) && (value >= 0))
|
||||||
if (enbw_cmc_switch_write(spi, reg, value))
|
if (enbw_cmc_switch_write(spi, reg, value)) {
|
||||||
goto err_read;
|
/* error writing to switch */
|
||||||
|
ptr = NULL;
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_read:
|
|
||||||
spi_release_bus(spi);
|
spi_release_bus(spi);
|
||||||
err_claim_bus:
|
|
||||||
spi_free_slave(spi);
|
spi_free_slave(spi);
|
||||||
return -EINVAL;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_switch(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
static int do_switch(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
|
||||||
|
@ -524,8 +534,10 @@ U_BOOT_CMD(switch, 3, 1, do_switch,
|
||||||
*/
|
*/
|
||||||
int board_eth_init(bd_t *bis)
|
int board_eth_init(bd_t *bis)
|
||||||
{
|
{
|
||||||
|
struct spi_slave *spi;
|
||||||
const char *s;
|
const char *s;
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
|
int config = 1;
|
||||||
|
|
||||||
davinci_emac_mii_mode_sel(0);
|
davinci_emac_mii_mode_sel(0);
|
||||||
|
|
||||||
|
@ -534,25 +546,49 @@ int board_eth_init(bd_t *bis)
|
||||||
if (len) {
|
if (len) {
|
||||||
unsigned long addr = simple_strtoul(s, NULL, 16);
|
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()) {
|
if (!davinci_emac_initialize()) {
|
||||||
printf("Error: Ethernet init failed!\n");
|
printf("Error: Ethernet init failed!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hwconfig_subarg_cmp("switch", "lan", "on"))
|
if (config) {
|
||||||
/* Switch port lan on */
|
if (hwconfig_subarg_cmp("switch", "lan", "on"))
|
||||||
enbw_cmc_switch(1, 1);
|
/* Switch port lan on */
|
||||||
else
|
enbw_cmc_switch(1, 1);
|
||||||
enbw_cmc_switch(1, 0);
|
else
|
||||||
|
enbw_cmc_switch(1, 0);
|
||||||
|
|
||||||
if (hwconfig_subarg_cmp("switch", "pwl", "on"))
|
if (hwconfig_subarg_cmp("switch", "lmn", "on"))
|
||||||
/* Switch port pwl on */
|
/* Switch port pwl on */
|
||||||
enbw_cmc_switch(2, 1);
|
enbw_cmc_switch(2, 1);
|
||||||
else
|
else
|
||||||
enbw_cmc_switch(2, 0);
|
enbw_cmc_switch(2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue