Example #1
0
File: ag934x.c Project: jhbsz/102
static int ag7240_check_link(ag7240_mac_t *mac)
{
    u32 link, duplex, speed, fdx;

    ag7240_phy_link(mac->mac_unit, &link);
    ag7240_phy_duplex(mac->mac_unit, &duplex);
    ag7240_phy_speed(mac->mac_unit, &speed);

    mac->link = link;
#ifdef SUPPORT_PLC
    if(strcmp(mac->dev->name, "eth0") == 0) {
        printf("ag7240_check_link: %s link forced down\n",mac->dev->name);
        return 0;
    }
#endif

    if(!mac->link) {
        printf("%s link down\n",mac->dev->name);
        return 0;
    }

    switch (speed)
    {
    case _1000BASET:
        ag7240_set_mac_if(mac, 1);
        ag7240_reg_rmw_set(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));
        if (is_ar7242() && (mac->mac_unit == 0)) {
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x1c000000);
        }
#ifdef CONFIG_F1E_PHY
        if (is_wasp() && (mac->mac_unit == 0)) {
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x0e000000);
        }
#elif CONFIG_VIR_PHY
        if (is_wasp() && (mac->mac_unit == 0)) {
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x82000000);
            ar7240_reg_wr(AG7240_ETH_CFG,0x000c0001);
        }
#else
        if (is_wasp() && (mac->mac_unit == 0) && !is_f2e()) {
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x06000000);
        }
#endif
        if (is_wasp() && mac->mac_unit == 0 && is_f1e() ) {
            ar7240_reg_rmw_set(AG7240_ETH_CFG,AG7240_ETH_CFG_RXD_DELAY);
            ar7240_reg_rmw_set(AG7240_ETH_CFG,AG7240_ETH_CFG_RDV_DELAY);
        }

        break;

    case _100BASET:
        ag7240_set_mac_if(mac, 0);
        ag7240_set_mac_speed(mac, 1);
        ag7240_reg_rmw_clear(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));
        if ((is_ar7242() || is_wasp()) && (mac->mac_unit == 0) && !is_f2e())
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x0101);

        if (is_wasp() && mac->mac_unit == 0 && is_f1e()) {
            ar7240_reg_rmw_clear(AG7240_ETH_CFG,AG7240_ETH_CFG_RXD_DELAY);
            ar7240_reg_rmw_clear(AG7240_ETH_CFG,AG7240_ETH_CFG_RDV_DELAY);
        }
        break;

    case _10BASET:
        ag7240_set_mac_if(mac, 0);
        ag7240_set_mac_speed(mac, 0);
        ag7240_reg_rmw_clear(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));

        if ((is_ar7242() || is_wasp()) && (mac->mac_unit == 0) && !is_f2e())
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x1616);

        if (is_wasp() && mac->mac_unit == 0 && is_f1e()) {
            ar7240_reg_rmw_clear(AG7240_ETH_CFG,AG7240_ETH_CFG_RXD_DELAY);
            ar7240_reg_rmw_clear(AG7240_ETH_CFG,AG7240_ETH_CFG_RDV_DELAY);
            ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x1313);
        }
        if (is_f2e()) {
            ar7240_reg_rmw_clear(AG7240_ETH_CFG, AG7240_ETH_CFG_RMII_HISPD_GE0);
        }
        break;

    default:
        printf("Invalid speed detected\n");
        return 0;
    }

    if (mac->link && (duplex == mac->duplex) && (speed == mac->speed))
        return 1;

    mac->duplex = duplex;
    mac->speed = speed;

    printf("dup %d speed %d\n", duplex, speed);

    ag7240_set_mac_duplex(mac,duplex);

    return 1;
}
Example #2
0
static int ag7240_check_link(ag7240_mac_t *mac) {
	int link = 0, duplex = 0, speed = 0;
	char *s;

	s = getenv("stdin");

	ag7240_phy_link(mac->mac_unit, &link);
	ag7240_phy_duplex(mac->mac_unit, &duplex);
	ag7240_phy_speed(mac->mac_unit, &speed);

	mac->link = link;

	if (!mac->link) {
		if((s != NULL) && (strcmp(s, "nc") != 0)){
			printf("Link down: %s\n", mac->dev->name);
		}
		return 0;
	}

	switch (speed) {
	case _1000BASET:
		ag7240_set_mac_if(mac, 1);
		ag7240_reg_rmw_set(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));
		if (is_ar7242() && (mac->mac_unit == 0)) {
			ar7240_reg_wr(AR7242_ETH_XMII_CONFIG, 0x1c000000);
		}
#ifdef CONFIG_F1E_PHY
		if (is_wasp() && (mac->mac_unit == 0)) {
			ar7240_reg_wr(AR7242_ETH_XMII_CONFIG,0x0e000000);
		}
#else      
		if (is_wasp() && (mac->mac_unit == 0)) {
			ar7240_reg_wr(AR7242_ETH_XMII_CONFIG, 0x06000000);
		}
#endif
		break;

	case _100BASET:
		ag7240_set_mac_if(mac, 0);
		ag7240_set_mac_speed(mac, 1);
		ag7240_reg_rmw_clear(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));
		if ((is_ar7242() || is_wasp()) && (mac->mac_unit == 0)){
			ar7240_reg_wr(AR7242_ETH_XMII_CONFIG, 0x0101);
		}
		break;

	case _10BASET:
		ag7240_set_mac_if(mac, 0);
		ag7240_set_mac_speed(mac, 0);
		ag7240_reg_rmw_clear(mac, AG7240_MAC_FIFO_CFG_5, (1 << 19));
		if ((is_ar7242() || is_wasp()) && (mac->mac_unit == 0)){
			ar7240_reg_wr(AR7242_ETH_XMII_CONFIG, 0x1616);
		}
		break;

	default:
		if((s != NULL) && (strcmp(s, "nc") != 0)){
			printf("## Error: invalid speed detected\n");
		}
		return 0;
	}

	if (mac->link && (duplex == mac->duplex) && (speed == mac->speed)){
		return 1;
	}

	mac->duplex = duplex;
	mac->speed = speed;

	if((s != NULL) && (strcmp(s, "nc") != 0)){
		printf("Ethernet mode (duplex/speed): %d/%d Mbps\n", duplex, speed);
	}

	ag7240_set_mac_duplex(mac, duplex);

	return 1;
}