blob: 3411150ab9dbfcfd705c0238a070c6de29566378 [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
Alexandru Gagniuc6098a392017-07-07 11:36:59 -0700150/* Micrel used the exact same part number for the KSZ9021. */
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000151static struct phy_driver KS8721_driver = {
152 .name = "Micrel KS8721BL",
153 .uid = 0x221610,
154 .mask = 0xfffff0,
155 .features = PHY_BASIC_FEATURES,
156 .config = &genphy_config,
157 .startup = &genphy_startup,
158 .shutdown = &genphy_shutdown,
159};
David Andreyf0d83c42013-02-06 22:18:37 +0100160
Alexey Firago73823fa2016-05-26 16:28:44 +0300161int ksz886x_config(struct phy_device *phydev)
162{
163 /* we are connected directly to the switch without
164 * dedicated PHY. */
165 phydev->link = 1;
166 phydev->duplex = DUPLEX_FULL;
167 phydev->speed = SPEED_100;
168 return 0;
169}
170
171static int ksz886x_startup(struct phy_device *phydev)
172{
173 return 0;
174}
175
176static struct phy_driver ksz886x_driver = {
177 .name = "Micrel KSZ886x Switch",
178 .uid = 0x00221430,
179 .mask = 0xfffff0,
180 .features = PHY_BASIC_FEATURES,
181 .config = &ksz886x_config,
182 .startup = &ksz886x_startup,
183 .shutdown = &genphy_shutdown,
184};
185
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700186int phy_micrel_ksz8xxx_init(void)
Andy Fleming60ca78b2011-04-07 21:56:05 -0500187{
188 phy_register(&KSZ804_driver);
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -0400189 phy_register(&KSZ8031_driver);
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +0200190 phy_register(&KSZ8051_driver);
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100191 phy_register(&KSZ8081_driver);
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000192 phy_register(&KS8721_driver);
Philippe De Muyter2616b212014-02-19 17:21:59 +0100193 phy_register(&ksz8895_driver);
Alexey Firago73823fa2016-05-26 16:28:44 +0300194 phy_register(&ksz886x_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500195 return 0;
196}