blob: 98a0c83e68b13b63ba217b222c60852bcb99584b [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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050016
17static struct phy_driver KSZ804_driver = {
18 .name = "Micrel KSZ804",
19 .uid = 0x221510,
20 .mask = 0xfffff0,
21 .features = PHY_BASIC_FEATURES,
22 .config = &genphy_config,
23 .startup = &genphy_startup,
24 .shutdown = &genphy_shutdown,
25};
26
Alexandre Messier94bde102016-01-22 14:06:33 -050027#define MII_KSZPHY_OMSO 0x16
Nicolas Ferre45d262d2019-10-23 10:46:44 +000028#define KSZPHY_OMSO_FACTORY_TEST BIT(15)
Alexandre Messier94bde102016-01-22 14:06:33 -050029#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
30
31static int ksz_genconfig_bcastoff(struct phy_device *phydev)
32{
33 int ret;
34
35 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
36 if (ret < 0)
37 return ret;
38
39 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
40 ret | KSZPHY_OMSO_B_CAST_OFF);
41 if (ret < 0)
42 return ret;
43
44 return genphy_config(phydev);
45}
46
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040047static struct phy_driver KSZ8031_driver = {
48 .name = "Micrel KSZ8021/KSZ8031",
49 .uid = 0x221550,
50 .mask = 0xfffff0,
51 .features = PHY_BASIC_FEATURES,
Alexandre Messier94bde102016-01-22 14:06:33 -050052 .config = &ksz_genconfig_bcastoff,
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040053 .startup = &genphy_startup,
54 .shutdown = &genphy_shutdown,
55};
56
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +020057/**
58 * KSZ8051
59 */
60#define MII_KSZ8051_PHY_OMSO 0x16
61#define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5)
62
63static int ksz8051_config(struct phy_device *phydev)
64{
65 unsigned val;
66
67 /* Disable NAND-tree */
68 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO);
69 val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON;
70 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val);
71
72 return genphy_config(phydev);
73}
74
75static struct phy_driver KSZ8051_driver = {
76 .name = "Micrel KSZ8051",
77 .uid = 0x221550,
78 .mask = 0xfffff0,
79 .features = PHY_BASIC_FEATURES,
80 .config = &ksz8051_config,
81 .startup = &genphy_startup,
82 .shutdown = &genphy_shutdown,
83};
84
Nicolas Ferre45d262d2019-10-23 10:46:44 +000085static int ksz8081_config(struct phy_device *phydev)
86{
87 int ret;
88
89 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
90 if (ret < 0)
91 return ret;
92
93 ret &= ~KSZPHY_OMSO_FACTORY_TEST;
94
95 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
96 ret | KSZPHY_OMSO_B_CAST_OFF);
97 if (ret < 0)
98 return ret;
99
100 return genphy_config(phydev);
101}
102
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100103static struct phy_driver KSZ8081_driver = {
104 .name = "Micrel KSZ8081",
105 .uid = 0x221560,
106 .mask = 0xfffff0,
107 .features = PHY_BASIC_FEATURES,
Nicolas Ferre45d262d2019-10-23 10:46:44 +0000108 .config = &ksz8081_config,
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100109 .startup = &genphy_startup,
110 .shutdown = &genphy_shutdown,
111};
112
Philippe De Muyter2616b212014-02-19 17:21:59 +0100113/**
114 * KSZ8895
115 */
116
117static unsigned short smireg_to_phy(unsigned short reg)
118{
119 return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
120}
121
122static unsigned short smireg_to_reg(unsigned short reg)
123{
124 return reg & 0x1F;
125}
126
127static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
128{
129 phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
130 smireg_to_reg(smireg), val);
131}
132
133#if 0
134static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
135{
136 return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
137 MDIO_DEVAD_NONE, smireg_to_reg(smireg));
138}
139#endif
140
141int ksz8895_config(struct phy_device *phydev)
142{
143 /* we are connected directly to the switch without
144 * dedicated PHY. SCONF1 == 001 */
145 phydev->link = 1;
146 phydev->duplex = DUPLEX_FULL;
147 phydev->speed = SPEED_100;
148
149 /* Force the switch to start */
150 ksz8895_write_smireg(phydev, 1, 1);
151
152 return 0;
153}
154
155static int ksz8895_startup(struct phy_device *phydev)
156{
157 return 0;
158}
159
160static struct phy_driver ksz8895_driver = {
161 .name = "Micrel KSZ8895/KSZ8864",
162 .uid = 0x221450,
163 .mask = 0xffffe1,
164 .features = PHY_BASIC_FEATURES,
165 .config = &ksz8895_config,
166 .startup = &ksz8895_startup,
167 .shutdown = &genphy_shutdown,
168};
169
James Byrnebc292c22019-03-06 12:48:27 +0000170/* Micrel used the exact same model number for the KSZ9021,
171 * so the revision number is used to distinguish them.
172 */
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000173static struct phy_driver KS8721_driver = {
174 .name = "Micrel KS8721BL",
James Byrnebc292c22019-03-06 12:48:27 +0000175 .uid = 0x221618,
176 .mask = 0xfffffc,
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000177 .features = PHY_BASIC_FEATURES,
178 .config = &genphy_config,
179 .startup = &genphy_startup,
180 .shutdown = &genphy_shutdown,
181};
David Andreyf0d83c42013-02-06 22:18:37 +0100182
Alexey Firago73823fa2016-05-26 16:28:44 +0300183int ksz886x_config(struct phy_device *phydev)
184{
185 /* we are connected directly to the switch without
186 * dedicated PHY. */
187 phydev->link = 1;
188 phydev->duplex = DUPLEX_FULL;
189 phydev->speed = SPEED_100;
190 return 0;
191}
192
193static int ksz886x_startup(struct phy_device *phydev)
194{
195 return 0;
196}
197
198static struct phy_driver ksz886x_driver = {
199 .name = "Micrel KSZ886x Switch",
200 .uid = 0x00221430,
201 .mask = 0xfffff0,
202 .features = PHY_BASIC_FEATURES,
203 .config = &ksz886x_config,
204 .startup = &ksz886x_startup,
205 .shutdown = &genphy_shutdown,
206};
207
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700208int phy_micrel_ksz8xxx_init(void)
Andy Fleming60ca78b2011-04-07 21:56:05 -0500209{
210 phy_register(&KSZ804_driver);
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -0400211 phy_register(&KSZ8031_driver);
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +0200212 phy_register(&KSZ8051_driver);
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100213 phy_register(&KSZ8081_driver);
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000214 phy_register(&KS8721_driver);
Philippe De Muyter2616b212014-02-19 17:21:59 +0100215 phy_register(&ksz8895_driver);
Alexey Firago73823fa2016-05-26 16:28:44 +0300216 phy_register(&ksz886x_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500217 return 0;
218}