Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Micrel PHY drivers |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 5 | * |
| 6 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
| 7 | * author Andy Fleming |
David Andrey | 62d7dba | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 8 | * (C) 2012 NetModule AG, David Andrey, added KSZ9031 |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 9 | */ |
Troy Kisky | 8682aba | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 10 | #include <config.h> |
| 11 | #include <common.h> |
Marek Vasut | 22854bd | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <errno.h> |
| 14 | #include <fdtdec.h> |
Troy Kisky | 8682aba | 2012-02-07 14:08:48 +0000 | [diff] [blame] | 15 | #include <micrel.h> |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 16 | #include <phy.h> |
| 17 | |
Marek Vasut | 22854bd | 2015-12-05 17:41:58 +0100 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 20 | static struct phy_driver KSZ804_driver = { |
| 21 | .name = "Micrel KSZ804", |
| 22 | .uid = 0x221510, |
| 23 | .mask = 0xfffff0, |
| 24 | .features = PHY_BASIC_FEATURES, |
| 25 | .config = &genphy_config, |
| 26 | .startup = &genphy_startup, |
| 27 | .shutdown = &genphy_shutdown, |
| 28 | }; |
| 29 | |
Alexandre Messier | 79e3efd | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 30 | #define MII_KSZPHY_OMSO 0x16 |
| 31 | #define KSZPHY_OMSO_B_CAST_OFF (1 << 9) |
| 32 | |
| 33 | static int ksz_genconfig_bcastoff(struct phy_device *phydev) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO); |
| 38 | if (ret < 0) |
| 39 | return ret; |
| 40 | |
| 41 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO, |
| 42 | ret | KSZPHY_OMSO_B_CAST_OFF); |
| 43 | if (ret < 0) |
| 44 | return ret; |
| 45 | |
| 46 | return genphy_config(phydev); |
| 47 | } |
| 48 | |
Sylvain Lemieux | 6617f87 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 49 | static struct phy_driver KSZ8031_driver = { |
| 50 | .name = "Micrel KSZ8021/KSZ8031", |
| 51 | .uid = 0x221550, |
| 52 | .mask = 0xfffff0, |
| 53 | .features = PHY_BASIC_FEATURES, |
Alexandre Messier | 79e3efd | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 54 | .config = &ksz_genconfig_bcastoff, |
Sylvain Lemieux | 6617f87 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 55 | .startup = &genphy_startup, |
| 56 | .shutdown = &genphy_shutdown, |
| 57 | }; |
| 58 | |
Sylvain Rochet | 4f48515 | 2015-10-07 22:54:22 +0200 | [diff] [blame] | 59 | /** |
| 60 | * KSZ8051 |
| 61 | */ |
| 62 | #define MII_KSZ8051_PHY_OMSO 0x16 |
| 63 | #define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5) |
| 64 | |
| 65 | static int ksz8051_config(struct phy_device *phydev) |
| 66 | { |
| 67 | unsigned val; |
| 68 | |
| 69 | /* Disable NAND-tree */ |
| 70 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO); |
| 71 | val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON; |
| 72 | phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val); |
| 73 | |
| 74 | return genphy_config(phydev); |
| 75 | } |
| 76 | |
| 77 | static struct phy_driver KSZ8051_driver = { |
| 78 | .name = "Micrel KSZ8051", |
| 79 | .uid = 0x221550, |
| 80 | .mask = 0xfffff0, |
| 81 | .features = PHY_BASIC_FEATURES, |
| 82 | .config = &ksz8051_config, |
| 83 | .startup = &genphy_startup, |
| 84 | .shutdown = &genphy_shutdown, |
| 85 | }; |
| 86 | |
Luca Ellero | c6a40f6 | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 87 | static struct phy_driver KSZ8081_driver = { |
| 88 | .name = "Micrel KSZ8081", |
| 89 | .uid = 0x221560, |
| 90 | .mask = 0xfffff0, |
| 91 | .features = PHY_BASIC_FEATURES, |
Alexandre Messier | 79e3efd | 2016-01-22 14:06:33 -0500 | [diff] [blame] | 92 | .config = &ksz_genconfig_bcastoff, |
Luca Ellero | c6a40f6 | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 93 | .startup = &genphy_startup, |
| 94 | .shutdown = &genphy_shutdown, |
| 95 | }; |
| 96 | |
Philippe De Muyter | b7a5b08 | 2014-02-19 17:21:59 +0100 | [diff] [blame] | 97 | /** |
| 98 | * KSZ8895 |
| 99 | */ |
| 100 | |
| 101 | static unsigned short smireg_to_phy(unsigned short reg) |
| 102 | { |
| 103 | return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5); |
| 104 | } |
| 105 | |
| 106 | static unsigned short smireg_to_reg(unsigned short reg) |
| 107 | { |
| 108 | return reg & 0x1F; |
| 109 | } |
| 110 | |
| 111 | static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val) |
| 112 | { |
| 113 | phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE, |
| 114 | smireg_to_reg(smireg), val); |
| 115 | } |
| 116 | |
| 117 | #if 0 |
| 118 | static int ksz8895_read_smireg(struct phy_device *phydev, int smireg) |
| 119 | { |
| 120 | return phydev->bus->read(phydev->bus, smireg_to_phy(smireg), |
| 121 | MDIO_DEVAD_NONE, smireg_to_reg(smireg)); |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | int ksz8895_config(struct phy_device *phydev) |
| 126 | { |
| 127 | /* we are connected directly to the switch without |
| 128 | * dedicated PHY. SCONF1 == 001 */ |
| 129 | phydev->link = 1; |
| 130 | phydev->duplex = DUPLEX_FULL; |
| 131 | phydev->speed = SPEED_100; |
| 132 | |
| 133 | /* Force the switch to start */ |
| 134 | ksz8895_write_smireg(phydev, 1, 1); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int ksz8895_startup(struct phy_device *phydev) |
| 140 | { |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static struct phy_driver ksz8895_driver = { |
| 145 | .name = "Micrel KSZ8895/KSZ8864", |
| 146 | .uid = 0x221450, |
| 147 | .mask = 0xffffe1, |
| 148 | .features = PHY_BASIC_FEATURES, |
| 149 | .config = &ksz8895_config, |
| 150 | .startup = &ksz8895_startup, |
| 151 | .shutdown = &genphy_shutdown, |
| 152 | }; |
| 153 | |
Alexandru Gagniuc | fbc120e | 2017-07-07 11:36:59 -0700 | [diff] [blame] | 154 | /* Micrel used the exact same part number for the KSZ9021. */ |
Vladimir Zapolskiy | fcc0c75 | 2011-12-06 02:47:57 +0000 | [diff] [blame] | 155 | static struct phy_driver KS8721_driver = { |
| 156 | .name = "Micrel KS8721BL", |
| 157 | .uid = 0x221610, |
| 158 | .mask = 0xfffff0, |
| 159 | .features = PHY_BASIC_FEATURES, |
| 160 | .config = &genphy_config, |
| 161 | .startup = &genphy_startup, |
| 162 | .shutdown = &genphy_shutdown, |
| 163 | }; |
David Andrey | 62d7dba | 2013-02-06 22:18:37 +0100 | [diff] [blame] | 164 | |
Alexey Firago | 7988774 | 2016-05-26 16:28:44 +0300 | [diff] [blame] | 165 | int ksz886x_config(struct phy_device *phydev) |
| 166 | { |
| 167 | /* we are connected directly to the switch without |
| 168 | * dedicated PHY. */ |
| 169 | phydev->link = 1; |
| 170 | phydev->duplex = DUPLEX_FULL; |
| 171 | phydev->speed = SPEED_100; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int ksz886x_startup(struct phy_device *phydev) |
| 176 | { |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static struct phy_driver ksz886x_driver = { |
| 181 | .name = "Micrel KSZ886x Switch", |
| 182 | .uid = 0x00221430, |
| 183 | .mask = 0xfffff0, |
| 184 | .features = PHY_BASIC_FEATURES, |
| 185 | .config = &ksz886x_config, |
| 186 | .startup = &ksz886x_startup, |
| 187 | .shutdown = &genphy_shutdown, |
| 188 | }; |
| 189 | |
Alexandru Gagniuc | d397f7c | 2017-07-07 11:36:57 -0700 | [diff] [blame] | 190 | int phy_micrel_ksz8xxx_init(void) |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 191 | { |
| 192 | phy_register(&KSZ804_driver); |
Sylvain Lemieux | 6617f87 | 2015-09-09 16:29:51 -0400 | [diff] [blame] | 193 | phy_register(&KSZ8031_driver); |
Sylvain Rochet | 4f48515 | 2015-10-07 22:54:22 +0200 | [diff] [blame] | 194 | phy_register(&KSZ8051_driver); |
Luca Ellero | c6a40f6 | 2015-03-24 11:32:24 +0100 | [diff] [blame] | 195 | phy_register(&KSZ8081_driver); |
Troy Kisky | cc5f552 | 2012-06-28 08:00:28 +0000 | [diff] [blame] | 196 | phy_register(&KS8721_driver); |
Philippe De Muyter | b7a5b08 | 2014-02-19 17:21:59 +0100 | [diff] [blame] | 197 | phy_register(&ksz8895_driver); |
Alexey Firago | 7988774 | 2016-05-26 16:28:44 +0300 | [diff] [blame] | 198 | phy_register(&ksz886x_driver); |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 199 | return 0; |
| 200 | } |