net: phy: broadcom: Add BCM Cygnus PHY
[oweals/u-boot.git] / drivers / net / phy / micrel.c
index aa9cbcfffc0465075ed7574e7ac76ffea908db48..49f444ac4c12c57993cb8139ce2fe946978e6d3e 100644 (file)
@@ -1,25 +1,11 @@
 /*
  * Micrel PHY drivers
  *
- * 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., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * Copyright 2010-2011 Freescale Semiconductor, Inc.
  * author Andy Fleming
  * (C) 2012 NetModule AG, David Andrey, added KSZ9031
- *
  */
 #include <config.h>
 #include <common.h>
@@ -36,11 +22,77 @@ static struct phy_driver KSZ804_driver = {
        .shutdown = &genphy_shutdown,
 };
 
+static struct phy_driver KSZ8081_driver = {
+       .name = "Micrel KSZ8081",
+       .uid = 0x221560,
+       .mask = 0xfffff0,
+       .features = PHY_BASIC_FEATURES,
+       .config = &genphy_config,
+       .startup = &genphy_startup,
+       .shutdown = &genphy_shutdown,
+};
+
+/**
+ * KSZ8895
+ */
+
+static unsigned short smireg_to_phy(unsigned short reg)
+{
+       return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
+}
+
+static unsigned short smireg_to_reg(unsigned short reg)
+{
+       return reg & 0x1F;
+}
+
+static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
+{
+       phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
+                                               smireg_to_reg(smireg), val);
+}
+
+#if 0
+static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
+{
+       return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
+                                       MDIO_DEVAD_NONE, smireg_to_reg(smireg));
+}
+#endif
+
+int ksz8895_config(struct phy_device *phydev)
+{
+       /* we are connected directly to the switch without
+        * dedicated PHY. SCONF1 == 001 */
+       phydev->link = 1;
+       phydev->duplex = DUPLEX_FULL;
+       phydev->speed = SPEED_100;
+
+       /* Force the switch to start */
+       ksz8895_write_smireg(phydev, 1, 1);
+
+       return 0;
+}
+
+static int ksz8895_startup(struct phy_device *phydev)
+{
+       return 0;
+}
+
+static struct phy_driver ksz8895_driver = {
+       .name = "Micrel KSZ8895/KSZ8864",
+       .uid  = 0x221450,
+       .mask = 0xffffe1,
+       .features = PHY_BASIC_FEATURES,
+       .config   = &ksz8895_config,
+       .startup  = &ksz8895_startup,
+       .shutdown = &genphy_shutdown,
+};
+
 #ifndef CONFIG_PHY_MICREL_KSZ9021
 /*
  * I can't believe Micrel used the exact same part number
- * for the KSZ9021
- * Shame Micrel, Shame!!!!!
+ * for the KSZ9021. Shame Micrel, Shame!
  */
 static struct phy_driver KS8721_driver = {
        .name = "Micrel KS8721BL",
@@ -54,7 +106,7 @@ static struct phy_driver KS8721_driver = {
 #endif
 
 
-/**
+/*
  * KSZ9021 - KSZ9031 common
  */
 
@@ -83,8 +135,8 @@ static int ksz90xx_startup(struct phy_device *phydev)
                phydev->speed = SPEED_10;
        return 0;
 }
-#ifdef CONFIG_PHY_MICREL_KSZ9021
 
+#ifdef CONFIG_PHY_MICREL_KSZ9021
 /*
  * KSZ9021
  */
@@ -114,6 +166,19 @@ int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
        return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
 }
 
+
+static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr,
+                             int regnum)
+{
+       return ksz9021_phy_extended_read(phydev, regnum);
+}
+
+static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr,
+                              int devaddr, int regnum, u16 val)
+{
+       return ksz9021_phy_extended_write(phydev, regnum, val);
+}
+
 /* Micrel ksz9021 */
 static int ksz9021_config(struct phy_device *phydev)
 {
@@ -145,6 +210,8 @@ static struct phy_driver ksz9021_driver = {
        .config = &ksz9021_config,
        .startup = &ksz90xx_startup,
        .shutdown = &genphy_shutdown,
+       .writeext = &ksz9021_phy_extwrite,
+       .readext = &ksz9021_phy_extread,
 };
 #endif
 
@@ -185,24 +252,43 @@ int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
        return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
 }
 
+static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr,
+                              int regnum)
+{
+       return ksz9031_phy_extended_read(phydev, devaddr, regnum,
+                                        MII_KSZ9031_MOD_DATA_NO_POST_INC);
+};
+
+static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr,
+                               int devaddr, int regnum, u16 val)
+{
+       return ksz9031_phy_extended_write(phydev, devaddr, regnum,
+                                        MII_KSZ9031_MOD_DATA_POST_INC_RW, val);
+};
+
+
 static struct phy_driver ksz9031_driver = {
        .name = "Micrel ksz9031",
        .uid  = 0x221620,
-       .mask = 0xfffffe,
+       .mask = 0xfffff0,
        .features = PHY_GBIT_FEATURES,
        .config   = &genphy_config,
        .startup  = &ksz90xx_startup,
        .shutdown = &genphy_shutdown,
+       .writeext = &ksz9031_phy_extwrite,
+       .readext = &ksz9031_phy_extread,
 };
 
 int phy_micrel_init(void)
 {
        phy_register(&KSZ804_driver);
+       phy_register(&KSZ8081_driver);
 #ifdef CONFIG_PHY_MICREL_KSZ9021
        phy_register(&ksz9021_driver);
 #else
        phy_register(&KS8721_driver);
 #endif
        phy_register(&ksz9031_driver);
+       phy_register(&ksz8895_driver);
        return 0;
 }