blob: daa57ce33c1690f4aff7d10fb8fa2f5a92e7a95d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming60ca78b2011-04-07 21:56:05 -05002/*
3 * Micrel PHY drivers
4 *
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
David Andreyf0d83c42013-02-06 22:18:37 +01007 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
Andy Fleming60ca78b2011-04-07 21:56:05 -05008 */
Troy Kisky80b6b092012-02-07 14:08:48 +00009#include <common.h>
Marek Vasut1005ce52015-12-05 17:41:58 +010010#include <dm.h>
11#include <errno.h>
12#include <fdtdec.h>
Troy Kisky80b6b092012-02-07 14:08:48 +000013#include <micrel.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050014#include <phy.h>
15
16static struct phy_driver KSZ804_driver = {
17 .name = "Micrel KSZ804",
18 .uid = 0x221510,
19 .mask = 0xfffff0,
20 .features = PHY_BASIC_FEATURES,
21 .config = &genphy_config,
22 .startup = &genphy_startup,
23 .shutdown = &genphy_shutdown,
24};
25
Alexandre Messier94bde102016-01-22 14:06:33 -050026#define MII_KSZPHY_OMSO 0x16
27#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
28
29static int ksz_genconfig_bcastoff(struct phy_device *phydev)
30{
31 int ret;
32
33 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
34 if (ret < 0)
35 return ret;
36
37 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
38 ret | KSZPHY_OMSO_B_CAST_OFF);
39 if (ret < 0)
40 return ret;
41
42 return genphy_config(phydev);
43}
44
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040045static struct phy_driver KSZ8031_driver = {
46 .name = "Micrel KSZ8021/KSZ8031",
47 .uid = 0x221550,
48 .mask = 0xfffff0,
49 .features = PHY_BASIC_FEATURES,
Alexandre Messier94bde102016-01-22 14:06:33 -050050 .config = &ksz_genconfig_bcastoff,
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040051 .startup = &genphy_startup,
52 .shutdown = &genphy_shutdown,
53};
54
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +020055/**
56 * KSZ8051
57 */
58#define MII_KSZ8051_PHY_OMSO 0x16
59#define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5)
60
61static int ksz8051_config(struct phy_device *phydev)
62{
63 unsigned val;
64
65 /* Disable NAND-tree */
66 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO);
67 val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON;
68 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val);
69
70 return genphy_config(phydev);
71}
72
73static struct phy_driver KSZ8051_driver = {
74 .name = "Micrel KSZ8051",
75 .uid = 0x221550,
76 .mask = 0xfffff0,
77 .features = PHY_BASIC_FEATURES,
78 .config = &ksz8051_config,
79 .startup = &genphy_startup,
80 .shutdown = &genphy_shutdown,
81};
82
Luca Elleroadeb9ea2015-03-24 11:32:24 +010083static struct phy_driver KSZ8081_driver = {
84 .name = "Micrel KSZ8081",
85 .uid = 0x221560,
86 .mask = 0xfffff0,
87 .features = PHY_BASIC_FEATURES,
Alexandre Messier94bde102016-01-22 14:06:33 -050088 .config = &ksz_genconfig_bcastoff,
Luca Elleroadeb9ea2015-03-24 11:32:24 +010089 .startup = &genphy_startup,
90 .shutdown = &genphy_shutdown,
91};
92
Philippe De Muyter2616b212014-02-19 17:21:59 +010093/**
94 * KSZ8895
95 */
96
97static unsigned short smireg_to_phy(unsigned short reg)
98{
99 return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
100}
101
102static unsigned short smireg_to_reg(unsigned short reg)
103{
104 return reg & 0x1F;
105}
106
107static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
108{
109 phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
110 smireg_to_reg(smireg), val);
111}
112
113#if 0
114static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
115{
116 return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
117 MDIO_DEVAD_NONE, smireg_to_reg(smireg));
118}
119#endif
120
121int ksz8895_config(struct phy_device *phydev)
122{
123 /* we are connected directly to the switch without
124 * dedicated PHY. SCONF1 == 001 */
125 phydev->link = 1;
126 phydev->duplex = DUPLEX_FULL;
127 phydev->speed = SPEED_100;
128
129 /* Force the switch to start */
130 ksz8895_write_smireg(phydev, 1, 1);
131
132 return 0;
133}
134
135static int ksz8895_startup(struct phy_device *phydev)
136{
137 return 0;
138}
139
140static struct phy_driver ksz8895_driver = {
141 .name = "Micrel KSZ8895/KSZ8864",
142 .uid = 0x221450,
143 .mask = 0xffffe1,
144 .features = PHY_BASIC_FEATURES,
145 .config = &ksz8895_config,
146 .startup = &ksz8895_startup,
147 .shutdown = &genphy_shutdown,
148};
149
James Byrnebc292c22019-03-06 12:48:27 +0000150/* Micrel used the exact same model number for the KSZ9021,
151 * so the revision number is used to distinguish them.
152 */
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000153static struct phy_driver KS8721_driver = {
154 .name = "Micrel KS8721BL",
James Byrnebc292c22019-03-06 12:48:27 +0000155 .uid = 0x221618,
156 .mask = 0xfffffc,
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000157 .features = PHY_BASIC_FEATURES,
158 .config = &genphy_config,
159 .startup = &genphy_startup,
160 .shutdown = &genphy_shutdown,
161};
David Andreyf0d83c42013-02-06 22:18:37 +0100162
Alexey Firago73823fa2016-05-26 16:28:44 +0300163int ksz886x_config(struct phy_device *phydev)
164{
165 /* we are connected directly to the switch without
166 * dedicated PHY. */
167 phydev->link = 1;
168 phydev->duplex = DUPLEX_FULL;
169 phydev->speed = SPEED_100;
170 return 0;
171}
172
173static int ksz886x_startup(struct phy_device *phydev)
174{
175 return 0;
176}
177
178static struct phy_driver ksz886x_driver = {
179 .name = "Micrel KSZ886x Switch",
180 .uid = 0x00221430,
181 .mask = 0xfffff0,
182 .features = PHY_BASIC_FEATURES,
183 .config = &ksz886x_config,
184 .startup = &ksz886x_startup,
185 .shutdown = &genphy_shutdown,
186};
187
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700188int phy_micrel_ksz8xxx_init(void)
Andy Fleming60ca78b2011-04-07 21:56:05 -0500189{
190 phy_register(&KSZ804_driver);
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -0400191 phy_register(&KSZ8031_driver);
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +0200192 phy_register(&KSZ8051_driver);
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100193 phy_register(&KSZ8081_driver);
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000194 phy_register(&KS8721_driver);
Philippe De Muyter2616b212014-02-19 17:21:59 +0100195 phy_register(&ksz8895_driver);
Alexey Firago73823fa2016-05-26 16:28:44 +0300196 phy_register(&ksz886x_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500197 return 0;
198}