⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uec_phy.c

📁 from wangkj@yahoo.com 电路原理图和详细说明: amd.9966.org或者 arm.9966.org 都是原创,包括boot, loader,u-boot,linu
💻 C
📖 第 1 页 / 共 2 页
字号:
		if (status & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD))			mii_info->duplex = DUPLEX_FULL;		else			mii_info->duplex = DUPLEX_HALF;		if (status & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX))			mii_info->speed = SPEED_100;		else			mii_info->speed = SPEED_10;		mii_info->pause = 0;	}	/* On non-aneg, we assume what we put in BMCR is the speed,	 * though magic-aneg shouldn't prevent this case from occurring	 */	return 0;}static int marvell_read_status (struct uec_mii_info *mii_info){	u16 status;	int err;	/* Update the link, but return if there	 * was an error */	err = genmii_update_link (mii_info);	if (err)		return err;	/* If the link is up, read the speed and duplex */	/* If we aren't autonegotiating, assume speeds	 * are as set */	if (mii_info->autoneg && mii_info->link) {		int speed;		status = phy_read (mii_info, MII_M1011_PHY_SPEC_STATUS);		/* Get the duplexity */		if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)			mii_info->duplex = DUPLEX_FULL;		else			mii_info->duplex = DUPLEX_HALF;		/* Get the speed */		speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;		switch (speed) {		case MII_M1011_PHY_SPEC_STATUS_1000:			mii_info->speed = SPEED_1000;			break;		case MII_M1011_PHY_SPEC_STATUS_100:			mii_info->speed = SPEED_100;			break;		default:			mii_info->speed = SPEED_10;			break;		}		mii_info->pause = 0;	}	return 0;}static int marvell_ack_interrupt (struct uec_mii_info *mii_info){	/* Clear the interrupts by reading the reg */	phy_read (mii_info, MII_M1011_IEVENT);	return 0;}static int marvell_config_intr (struct uec_mii_info *mii_info){	if (mii_info->interrupts == MII_INTERRUPT_ENABLED)		phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);	else		phy_write (mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);	return 0;}static int dm9161_init (struct uec_mii_info *mii_info){	/* Reset the PHY */	phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) |		   PHY_BMCR_RESET);	/* PHY and MAC connect */	phy_write (mii_info, PHY_BMCR, phy_read (mii_info, PHY_BMCR) &		   ~PHY_BMCR_ISO);#ifdef CONFIG_RMII_MODE	phy_write (mii_info, MII_DM9161_SCR, MII_DM9161_SCR_RMII_INIT);#else	phy_write (mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT);#endif	config_genmii_advert (mii_info);	/* Start/restart aneg */	genmii_config_aneg (mii_info);	/* Delay to wait the aneg compeleted */	udelay (3000000);	return 0;}static int dm9161_config_aneg (struct uec_mii_info *mii_info){	return 0;}static int dm9161_read_status (struct uec_mii_info *mii_info){	u16 status;	int err;	/* Update the link, but return if there was an error */	err = genmii_update_link (mii_info);	if (err)		return err;	/* If the link is up, read the speed and duplex	   If we aren't autonegotiating assume speeds are as set */	if (mii_info->autoneg && mii_info->link) {		status = phy_read (mii_info, MII_DM9161_SCSR);		if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))			mii_info->speed = SPEED_100;		else			mii_info->speed = SPEED_10;		if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))			mii_info->duplex = DUPLEX_FULL;		else			mii_info->duplex = DUPLEX_HALF;	}	return 0;}static int dm9161_ack_interrupt (struct uec_mii_info *mii_info){	/* Clear the interrupt by reading the reg */	phy_read (mii_info, MII_DM9161_INTR);	return 0;}static int dm9161_config_intr (struct uec_mii_info *mii_info){	if (mii_info->interrupts == MII_INTERRUPT_ENABLED)		phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);	else		phy_write (mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);	return 0;}static void dm9161_close (struct uec_mii_info *mii_info){}static struct phy_info phy_info_dm9161 = {	.phy_id = 0x0181b880,	.phy_id_mask = 0x0ffffff0,	.name = "Davicom DM9161E",	.init = dm9161_init,	.config_aneg = dm9161_config_aneg,	.read_status = dm9161_read_status,	.close = dm9161_close,};static struct phy_info phy_info_dm9161a = {	.phy_id = 0x0181b8a0,	.phy_id_mask = 0x0ffffff0,	.name = "Davicom DM9161A",	.features = MII_BASIC_FEATURES,	.init = dm9161_init,	.config_aneg = dm9161_config_aneg,	.read_status = dm9161_read_status,	.ack_interrupt = dm9161_ack_interrupt,	.config_intr = dm9161_config_intr,	.close = dm9161_close,};static struct phy_info phy_info_marvell = {	.phy_id = 0x01410c00,	.phy_id_mask = 0xffffff00,	.name = "Marvell 88E11x1",	.features = MII_GBIT_FEATURES,	.config_aneg = &marvell_config_aneg,	.read_status = &marvell_read_status,	.ack_interrupt = &marvell_ack_interrupt,	.config_intr = &marvell_config_intr,};static struct phy_info phy_info_genmii = {	.phy_id = 0x00000000,	.phy_id_mask = 0x00000000,	.name = "Generic MII",	.features = MII_BASIC_FEATURES,	.config_aneg = genmii_config_aneg,	.read_status = genmii_read_status,};static struct phy_info *phy_info[] = {	&phy_info_dm9161,	&phy_info_dm9161a,	&phy_info_marvell,	&phy_info_genmii,	NULL};u16 phy_read (struct uec_mii_info *mii_info, u16 regnum){	return mii_info->mdio_read (mii_info->dev, mii_info->mii_id, regnum);}void phy_write (struct uec_mii_info *mii_info, u16 regnum, u16 val){	mii_info->mdio_write (mii_info->dev, mii_info->mii_id, regnum, val);}/* Use the PHY ID registers to determine what type of PHY is attached * to device dev.  return a struct phy_info structure describing that PHY */struct phy_info *get_phy_info (struct uec_mii_info *mii_info){	u16 phy_reg;	u32 phy_ID;	int i;	struct phy_info *theInfo = NULL;	/* Grab the bits from PHYIR1, and put them in the upper half */	phy_reg = phy_read (mii_info, PHY_PHYIDR1);	phy_ID = (phy_reg & 0xffff) << 16;	/* Grab the bits from PHYIR2, and put them in the lower half */	phy_reg = phy_read (mii_info, PHY_PHYIDR2);	phy_ID |= (phy_reg & 0xffff);	/* loop through all the known PHY types, and find one that */	/* matches the ID we read from the PHY. */	for (i = 0; phy_info[i]; i++)		if (phy_info[i]->phy_id ==		    (phy_ID & phy_info[i]->phy_id_mask)) {			theInfo = phy_info[i];			break;		}	/* This shouldn't happen, as we have generic PHY support */	if (theInfo == NULL) {		ugphy_info ("UEC: PHY id %x is not supported!", phy_ID);		return NULL;	} else {		ugphy_info ("UEC: PHY is %s (%x)", theInfo->name, phy_ID);	}	return theInfo;}void marvell_phy_interface_mode (struct eth_device *dev,				 enet_interface_e mode){	uec_private_t *uec = (uec_private_t *) dev->priv;	struct uec_mii_info *mii_info;	if (!uec->mii_info) {		printf ("%s: the PHY not intialized\n", __FUNCTION__);		return;	}	mii_info = uec->mii_info;	if (mode == ENET_100_RGMII) {		phy_write (mii_info, 0x00, 0x9140);		phy_write (mii_info, 0x1d, 0x001f);		phy_write (mii_info, 0x1e, 0x200c);		phy_write (mii_info, 0x1d, 0x0005);		phy_write (mii_info, 0x1e, 0x0000);		phy_write (mii_info, 0x1e, 0x0100);		phy_write (mii_info, 0x09, 0x0e00);		phy_write (mii_info, 0x04, 0x01e1);		phy_write (mii_info, 0x00, 0x9140);		phy_write (mii_info, 0x00, 0x1000);		udelay (100000);		phy_write (mii_info, 0x00, 0x2900);		phy_write (mii_info, 0x14, 0x0cd2);		phy_write (mii_info, 0x00, 0xa100);		phy_write (mii_info, 0x09, 0x0000);		phy_write (mii_info, 0x1b, 0x800b);		phy_write (mii_info, 0x04, 0x05e1);		phy_write (mii_info, 0x00, 0xa100);		phy_write (mii_info, 0x00, 0x2100);		udelay (1000000);	} else if (mode == ENET_10_RGMII) {		phy_write (mii_info, 0x14, 0x8e40);		phy_write (mii_info, 0x1b, 0x800b);		phy_write (mii_info, 0x14, 0x0c82);		phy_write (mii_info, 0x00, 0x8100);		udelay (1000000);	}}void change_phy_interface_mode (struct eth_device *dev, enet_interface_e mode){#ifdef CONFIG_PHY_MODE_NEED_CHANGE	marvell_phy_interface_mode (dev, mode);#endif}#endif /* CONFIG_QE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -