Skip to content

Commit

Permalink
FEAT: add phy driver for yt8511
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnyGuo-MYiR committed Dec 3, 2021
1 parent dc31636 commit f2a2487
Show file tree
Hide file tree
Showing 8 changed files with 2,336 additions and 0 deletions.
Expand Up @@ -1066,6 +1066,7 @@ CONFIG_PHYLIB=y
# CONFIG_VITESSE_PHY is not set
CONFIG_SMSC_PHY=y
CONFIG_AT803X_PHY=y
CONFIG_MOTORCOMM_PHY=y
# CONFIG_BROADCOM_PHY is not set
# CONFIG_ICPLUS_PHY is not set
# CONFIG_REALTEK_PHY is not set
Expand Down
1 change: 1 addition & 0 deletions arch/arm/configs/myd_am335x_defconfig
Expand Up @@ -1081,6 +1081,7 @@ CONFIG_PHYLIB=y
# CONFIG_VITESSE_PHY is not set
CONFIG_SMSC_PHY=y
CONFIG_AT803X_PHY=y
CONFIG_MOTORCOMM_PHY=y
# CONFIG_BROADCOM_PHY is not set
# CONFIG_ICPLUS_PHY is not set
# CONFIG_REALTEK_PHY is not set
Expand Down
15 changes: 15 additions & 0 deletions drivers/net/phy/Kconfig
Expand Up @@ -97,6 +97,21 @@ config MICREL_PHY
---help---
Supports the KSZ9021, VSC8201, KS8001 PHYs.

config DP83848_PHY
tristate "Driver for Texas Instruments DP83848 PHY"
---help---
Supports the DP83848 PHY.

config DP83867_PHY
tristate "Drivers for Texas Instruments DP83867 Gigabit PHY"
---help---
Currently supports the DP83867 PHY.

config MOTORCOMM_PHY
tristate "Motorcomm PHYs"
---help---
Supports the YT8511 PHYs.

config FIXED_PHY
bool "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
depends on PHYLIB=y
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/phy/Makefile
Expand Up @@ -20,7 +20,10 @@ obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o
obj-$(CONFIG_MDIO_GPIO) += mdio-gpio.o
obj-$(CONFIG_NATIONAL_PHY) += national.o
obj-$(CONFIG_DP83640_PHY) += dp83640.o
obj-$(CONFIG_DP83848_PHY) += dp83848.o
obj-$(CONFIG_DP83867_PHY) += dp83867.o
obj-$(CONFIG_STE10XP) += ste10Xp.o
obj-$(CONFIG_MICREL_PHY) += micrel.o
obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
obj-$(CONFIG_AT803X_PHY) += at803x.o
obj-$(CONFIG_MOTORCOMM_PHY) += motorcomm.o
168 changes: 168 additions & 0 deletions drivers/net/phy/motorcomm.c
@@ -0,0 +1,168 @@
/*
* drivers/net/phy/motorcomm.c
*
* Driver for Motorcomm PHYs
*
* Author: Leilei Zhao <leilei.zhao@motorcomm.com>
*
* Copyright (c) 2019 Motorcomm, Inc.
*
* 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.
*
* Support : Motorcomm Phys:
* Giga phys: yt8511, yt8521
* 100/10 Phys : yt8512, yt8512b, yt8510
* Automotive 100Mb Phys : yt8010
* Automotive 100/10 hyper range Phys: yt8510
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/phy.h>
#include <linux/motorcomm_phy.h>
#include <linux/of.h>
#include <linux/clk.h>
#include <linux/version.h>
/*for wol, 20210604*/
#include <linux/netdevice.h>

#include "yt8614-phy.h"

/**** configuration section begin ***********/

/* if system depends on ethernet packet to restore from sleep, please define this macro to 1
* otherwise, define it to 0.
*/
#define SYS_WAKEUP_BASED_ON_ETH_PKT 0

/* to enable system WOL of phy, please define this macro to 1
* otherwise, define it to 0.
*/
#define YTPHY_ENABLE_WOL 0

/* some GMAC need clock input from PHY, for eg., 125M, please enable this macro
* by degault, it is set to 0
* NOTE: this macro will need macro SYS_WAKEUP_BASED_ON_ETH_PKT to set to 1
*/
#define GMAC_CLOCK_INPUT_NEEDED 0


#define YT8521_PHY_MODE_FIBER 1 //fiber mode only
#define YT8521_PHY_MODE_UTP 2 //utp mode only
#define YT8521_PHY_MODE_POLL 3 //fiber and utp, poll mode

/* please make choice according to system design
* for Fiber only system, please define YT8521_PHY_MODE_CURR 1
* for UTP only system, please define YT8521_PHY_MODE_CURR 2
* for combo system, please define YT8521_PHY_MODE_CURR 3
*/
#define YT8521_PHY_MODE_CURR 3

/**** configuration section end ***********/


/* no need to change below */

#if (YTPHY_ENABLE_WOL)
#undef SYS_WAKEUP_BASED_ON_ETH_PKT
#define SYS_WAKEUP_BASED_ON_ETH_PKT 1
#endif

static int ytphy_read_ext(struct phy_device *phydev, u32 regnum)
{
int ret;
int val;

ret = phy_write(phydev, REG_DEBUG_ADDR_OFFSET, regnum);
if (ret < 0)
return ret;

val = phy_read(phydev, REG_DEBUG_DATA);

return val;
}

static int ytphy_write_ext(struct phy_device *phydev, u32 regnum, u16 val)
{
int ret;

ret = phy_write(phydev, REG_DEBUG_ADDR_OFFSET, regnum);
if (ret < 0)
return ret;

ret = phy_write(phydev, REG_DEBUG_DATA, val);

return ret;
}

static int yt8511_config_init(struct phy_device *phydev)
{
int ret;
int val;

ret = genphy_config_init(phydev);
if(ret < 0){
return ret;
}

// if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {

/* disable auto sleep */
val = ytphy_read_ext(phydev, 0x27);
val &= (~BIT(15));

ret = ytphy_write_ext(phydev, 0x27, val);

/* enable RXC clock when no wire plug */
val = ytphy_read_ext(phydev, 0xc);

/* ext reg 0xc b[7:4]
Tx Delay time = 150ps * N - 250ps
*/
val |= (0xf << 4);
val |= 0x1;
ret = ytphy_write_ext(phydev, 0xc, val);
// printk("yt8511_config_en_txdelay..phy txdelay, val=%#08x\n",val);
// }
return ret;
}
static struct phy_driver ytphy_drvs[] = {
{
.phy_id = PHY_ID_YT8511,
.name = "YT8511 Gigabit Ethernet",
.phy_id_mask = MOTORCOMM_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.flags = PHY_HAS_INTERRUPT,
.config_aneg = genphy_config_aneg,
.config_init = yt8511_config_init,
.read_status = genphy_read_status,
.suspend = genphy_suspend,
.resume = genphy_resume,
}
};

module_phy_driver(ytphy_drvs);

MODULE_DESCRIPTION("Motorcomm PHY driver");
MODULE_AUTHOR("Leilei Zhao");
MODULE_LICENSE("GPL");

static struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
{ PHY_ID_YT8010, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8510, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8511, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8512, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8512B, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8521, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8531S, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8531, MOTORCOMM_PHY_ID_MASK },
{ PHY_ID_YT8618, MOTORCOMM_MPHY_ID_MASK },
{ PHY_ID_YT8614, MOTORCOMM_MPHY_ID_MASK_8614 },
{ }
};

MODULE_DEVICE_TABLE(mdio, motorcomm_tbl);

0 comments on commit f2a2487

Please sign in to comment.