blob: a43793cd4274040fc75014c861a5614d6632ad1e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Edgar E. Iglesias721aed72015-09-25 23:46:08 -07002/*
3 * TI PHY drivers
4 *
Edgar E. Iglesias721aed72015-09-25 23:46:08 -07005 */
6#include <common.h>
7#include <phy.h>
Dan Murphy085445c2016-05-02 15:45:59 -05008#include <linux/compat.h>
9#include <malloc.h>
10
Dan Murphy085445c2016-05-02 15:45:59 -050011#include <dm.h>
12#include <dt-bindings/net/ti-dp83867.h>
13
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070014
15/* TI DP83867 */
16#define DP83867_DEVADDR 0x1f
17
18#define MII_DP83867_PHYCTRL 0x10
19#define MII_DP83867_MICR 0x12
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +053020#define MII_DP83867_CFG2 0x14
21#define MII_DP83867_BISCR 0x16
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070022#define DP83867_CTRL 0x1f
23
24/* Extended Registers */
Murali Karicheri63d31922018-06-28 14:26:34 -050025#define DP83867_CFG4 0x0031
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070026#define DP83867_RGMIICTL 0x0032
Janine Hagemannbe71a742018-08-28 08:25:38 +020027#define DP83867_STRAP_STS1 0x006E
Grygorii Strashko20f7ea42019-11-18 23:04:44 +020028#define DP83867_STRAP_STS2 0x006f
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070029#define DP83867_RGMIIDCTL 0x0086
Mugunthan V N64631702017-01-24 11:15:40 -060030#define DP83867_IO_MUX_CFG 0x0170
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070031
32#define DP83867_SW_RESET BIT(15)
33#define DP83867_SW_RESTART BIT(14)
34
35/* MICR Interrupt bits */
36#define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15)
37#define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14)
38#define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13)
39#define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12)
40#define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11)
41#define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10)
42#define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8)
43#define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4)
44#define MII_DP83867_MICR_WOL_INT_EN BIT(3)
45#define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2)
46#define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1)
47#define MII_DP83867_MICR_JABBER_INT_EN BIT(0)
48
49/* RGMIICTL bits */
50#define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1)
51#define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0)
52
Janine Hagemannbe71a742018-08-28 08:25:38 +020053/* STRAP_STS1 bits */
54#define DP83867_STRAP_STS1_RESERVED BIT(11)
55
Grygorii Strashko20f7ea42019-11-18 23:04:44 +020056/* STRAP_STS2 bits */
57#define DP83867_STRAP_STS2_CLK_SKEW_TX_MASK GENMASK(6, 4)
58#define DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT 4
59#define DP83867_STRAP_STS2_CLK_SKEW_RX_MASK GENMASK(2, 0)
60#define DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT 0
61#define DP83867_STRAP_STS2_CLK_SKEW_NONE BIT(2)
62
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070063/* PHY CTRL bits */
64#define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14
Grygorii Strashko37d62652019-11-18 23:04:46 +020065#define DP83867_PHYCR_FIFO_DEPTH_MASK GENMASK(15, 14)
Janine Hagemannbe71a742018-08-28 08:25:38 +020066#define DP83867_PHYCR_RESERVED_MASK BIT(11)
Michal Simek01790632015-10-19 10:43:30 +020067#define DP83867_MDI_CROSSOVER 5
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +053068#define DP83867_MDI_CROSSOVER_MDIX 2
69#define DP83867_PHYCTRL_SGMIIEN 0x0800
70#define DP83867_PHYCTRL_RXFIFO_SHIFT 12
71#define DP83867_PHYCTRL_TXFIFO_SHIFT 14
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070072
73/* RGMIIDCTL bits */
Grygorii Strashko20f7ea42019-11-18 23:04:44 +020074#define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070075#define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4
Grygorii Strashko20f7ea42019-11-18 23:04:44 +020076#define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias721aed72015-09-25 23:46:08 -070077
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +053078/* CFG2 bits */
79#define MII_DP83867_CFG2_SPEEDOPT_10EN 0x0040
80#define MII_DP83867_CFG2_SGMII_AUTONEGEN 0x0080
81#define MII_DP83867_CFG2_SPEEDOPT_ENH 0x0100
82#define MII_DP83867_CFG2_SPEEDOPT_CNT 0x0800
83#define MII_DP83867_CFG2_SPEEDOPT_INTLOW 0x2000
84#define MII_DP83867_CFG2_MASK 0x003F
85
Dan Murphy085445c2016-05-02 15:45:59 -050086/* User setting - can be taken from DTS */
Dan Murphy085445c2016-05-02 15:45:59 -050087#define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB
88
Mugunthan V N64631702017-01-24 11:15:40 -060089/* IO_MUX_CFG bits */
90#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f
91
92#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0
93#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f
Grygorii Strashkob3b9b122019-11-18 23:04:43 +020094#define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6)
Janine Hagemann0f347a02018-08-28 08:25:39 +020095#define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8
96#define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK \
97 GENMASK(0x1f, DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT)
Mugunthan V N64631702017-01-24 11:15:40 -060098
Janine Hagemannfba725f2018-08-28 08:25:37 +020099/* CFG4 bits */
100#define DP83867_CFG4_PORT_MIRROR_EN BIT(0)
101
102enum {
103 DP83867_PORT_MIRRORING_KEEP,
104 DP83867_PORT_MIRRORING_EN,
105 DP83867_PORT_MIRRORING_DIS,
106};
107
Dan Murphy085445c2016-05-02 15:45:59 -0500108struct dp83867_private {
Grygorii Strashko20f7ea42019-11-18 23:04:44 +0200109 u32 rx_id_delay;
110 u32 tx_id_delay;
Dan Murphy085445c2016-05-02 15:45:59 -0500111 int fifo_depth;
Mugunthan V N64631702017-01-24 11:15:40 -0600112 int io_impedance;
Murali Karicheri63d31922018-06-28 14:26:34 -0500113 bool rxctrl_strap_quirk;
Janine Hagemannfba725f2018-08-28 08:25:37 +0200114 int port_mirroring;
Grygorii Strashkob3b9b122019-11-18 23:04:43 +0200115 bool set_clk_output;
Trent Piepho2529dea2019-05-10 17:49:08 +0000116 unsigned int clk_output_sel;
Dan Murphy085445c2016-05-02 15:45:59 -0500117};
118
Janine Hagemannfba725f2018-08-28 08:25:37 +0200119static int dp83867_config_port_mirroring(struct phy_device *phydev)
120{
121 struct dp83867_private *dp83867 =
122 (struct dp83867_private *)phydev->priv;
123 u16 val;
124
Carlo Caione4c29dc12019-02-08 17:25:07 +0000125 val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
Janine Hagemannfba725f2018-08-28 08:25:37 +0200126
127 if (dp83867->port_mirroring == DP83867_PORT_MIRRORING_EN)
128 val |= DP83867_CFG4_PORT_MIRROR_EN;
129 else
130 val &= ~DP83867_CFG4_PORT_MIRROR_EN;
131
Carlo Caione4c29dc12019-02-08 17:25:07 +0000132 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
Janine Hagemannfba725f2018-08-28 08:25:37 +0200133
134 return 0;
135}
136
Dan Murphy085445c2016-05-02 15:45:59 -0500137#if defined(CONFIG_DM_ETH)
138/**
139 * dp83867_data_init - Convenience function for setting PHY specific data
140 *
141 * @phydev: the phy_device struct
142 */
143static int dp83867_of_init(struct phy_device *phydev)
144{
145 struct dp83867_private *dp83867 = phydev->priv;
Grygorii Strashkob8d7ec72018-07-05 12:02:49 -0500146 ofnode node;
Grygorii Strashkob3b9b122019-11-18 23:04:43 +0200147 int ret;
Janine Hagemann0f347a02018-08-28 08:25:39 +0200148
Michal Simek6845b362019-03-16 12:43:17 +0100149 node = phy_get_ofnode(phydev);
150 if (!ofnode_valid(node))
151 return -EINVAL;
152
Grygorii Strashkob3b9b122019-11-18 23:04:43 +0200153 /* Optional configuration */
154 ret = ofnode_read_u32(node, "ti,clk-output-sel",
155 &dp83867->clk_output_sel);
156 /* If not set, keep default */
157 if (!ret) {
158 dp83867->set_clk_output = true;
159 /* Valid values are 0 to DP83867_CLK_O_SEL_REF_CLK or
160 * DP83867_CLK_O_SEL_OFF.
161 */
162 if (dp83867->clk_output_sel > DP83867_CLK_O_SEL_REF_CLK &&
163 dp83867->clk_output_sel != DP83867_CLK_O_SEL_OFF) {
164 pr_debug("ti,clk-output-sel value %u out of range\n",
165 dp83867->clk_output_sel);
166 return -EINVAL;
167 }
168 }
Grygorii Strashkob8d7ec72018-07-05 12:02:49 -0500169
Grygorii Strashko3ab75cf2018-06-28 14:26:35 -0500170 if (ofnode_read_bool(node, "ti,max-output-impedance"))
Mugunthan V N64631702017-01-24 11:15:40 -0600171 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
Grygorii Strashko3ab75cf2018-06-28 14:26:35 -0500172 else if (ofnode_read_bool(node, "ti,min-output-impedance"))
Mugunthan V N64631702017-01-24 11:15:40 -0600173 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
174 else
175 dp83867->io_impedance = -EINVAL;
Dan Murphy085445c2016-05-02 15:45:59 -0500176
Grygorii Strashko3ab75cf2018-06-28 14:26:35 -0500177 if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk"))
Murali Karicheri63d31922018-06-28 14:26:34 -0500178 dp83867->rxctrl_strap_quirk = true;
Dan Murphy085445c2016-05-02 15:45:59 -0500179
Grygorii Strashko20f7ea42019-11-18 23:04:44 +0200180 /* Existing behavior was to use default pin strapping delay in rgmii
181 * mode, but rgmii should have meant no delay. Warn existing users.
182 */
183 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
184 u16 val = phy_read_mmd(phydev, DP83867_DEVADDR,
185 DP83867_STRAP_STS2);
186 u16 txskew = (val & DP83867_STRAP_STS2_CLK_SKEW_TX_MASK) >>
187 DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT;
188 u16 rxskew = (val & DP83867_STRAP_STS2_CLK_SKEW_RX_MASK) >>
189 DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT;
190
191 if (txskew != DP83867_STRAP_STS2_CLK_SKEW_NONE ||
192 rxskew != DP83867_STRAP_STS2_CLK_SKEW_NONE)
193 pr_warn("PHY has delays via pin strapping, but phy-mode = 'rgmii'\n"
194 "Should be 'rgmii-id' to use internal delays\n");
195 }
196
197 /* RX delay *must* be specified if internal delay of RX is used. */
198 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
199 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
200 ret = ofnode_read_u32(node, "ti,rx-internal-delay",
201 &dp83867->rx_id_delay);
202 if (ret) {
203 pr_debug("ti,rx-internal-delay must be specified\n");
204 return ret;
205 }
206 if (dp83867->rx_id_delay > DP83867_RGMII_RX_CLK_DELAY_MAX) {
207 pr_debug("ti,rx-internal-delay value of %u out of range\n",
208 dp83867->rx_id_delay);
209 return -EINVAL;
210 }
211 }
212
213 /* TX delay *must* be specified if internal delay of RX is used. */
214 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
215 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
216 ret = ofnode_read_u32(node, "ti,tx-internal-delay",
217 &dp83867->tx_id_delay);
218 if (ret) {
219 debug("ti,tx-internal-delay must be specified\n");
220 return ret;
221 }
222 if (dp83867->tx_id_delay > DP83867_RGMII_TX_CLK_DELAY_MAX) {
223 pr_debug("ti,tx-internal-delay value of %u out of range\n",
224 dp83867->tx_id_delay);
225 return -EINVAL;
226 }
227 }
Dan Murphy085445c2016-05-02 15:45:59 -0500228
Grygorii Strashko3ab75cf2018-06-28 14:26:35 -0500229 dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth",
Trent Piephoc2df9b42019-05-09 19:41:51 +0000230 DEFAULT_FIFO_DEPTH);
Janine Hagemannfba725f2018-08-28 08:25:37 +0200231 if (ofnode_read_bool(node, "enet-phy-lane-swap"))
232 dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN;
233
234 if (ofnode_read_bool(node, "enet-phy-lane-no-swap"))
235 dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS;
236
Dan Murphy085445c2016-05-02 15:45:59 -0500237 return 0;
238}
239#else
240static int dp83867_of_init(struct phy_device *phydev)
241{
242 struct dp83867_private *dp83867 = phydev->priv;
243
Grygorii Strashko20f7ea42019-11-18 23:04:44 +0200244 dp83867->rx_id_delay = DP83867_RGMIIDCTL_2_25_NS;
245 dp83867->tx_id_delay = DP83867_RGMIIDCTL_2_75_NS;
Dan Murphy085445c2016-05-02 15:45:59 -0500246 dp83867->fifo_depth = DEFAULT_FIFO_DEPTH;
Mugunthan V N64631702017-01-24 11:15:40 -0600247 dp83867->io_impedance = -EINVAL;
Dan Murphy085445c2016-05-02 15:45:59 -0500248
249 return 0;
250}
251#endif
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700252
253static int dp83867_config(struct phy_device *phydev)
254{
Dan Murphy085445c2016-05-02 15:45:59 -0500255 struct dp83867_private *dp83867;
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +0530256 unsigned int val, delay, cfg2;
Janine Hagemannbe71a742018-08-28 08:25:38 +0200257 int ret, bs;
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700258
Grygorii Strashkoee622f02019-11-18 23:04:41 +0200259 dp83867 = (struct dp83867_private *)phydev->priv;
Dan Murphy085445c2016-05-02 15:45:59 -0500260
Grygorii Strashkoee622f02019-11-18 23:04:41 +0200261 ret = dp83867_of_init(phydev);
262 if (ret)
263 return ret;
Dan Murphy085445c2016-05-02 15:45:59 -0500264
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700265 /* Restart the PHY. */
266 val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL);
267 phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL,
268 val | DP83867_SW_RESTART);
269
Murali Karicheri63d31922018-06-28 14:26:34 -0500270 /* Mode 1 or 2 workaround */
271 if (dp83867->rxctrl_strap_quirk) {
Carlo Caione4c29dc12019-02-08 17:25:07 +0000272 val = phy_read_mmd(phydev, DP83867_DEVADDR,
273 DP83867_CFG4);
Murali Karicheri63d31922018-06-28 14:26:34 -0500274 val &= ~BIT(7);
Carlo Caione4c29dc12019-02-08 17:25:07 +0000275 phy_write_mmd(phydev, DP83867_DEVADDR,
276 DP83867_CFG4, val);
Murali Karicheri63d31922018-06-28 14:26:34 -0500277 }
278
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700279 if (phy_interface_is_rgmii(phydev)) {
Grygorii Strashko37d62652019-11-18 23:04:46 +0200280 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL);
281 if (val < 0)
Dan Murphy085445c2016-05-02 15:45:59 -0500282 goto err_out;
Grygorii Strashko37d62652019-11-18 23:04:46 +0200283 val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK;
284 val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT);
Janine Hagemannbe71a742018-08-28 08:25:38 +0200285
286 /* The code below checks if "port mirroring" N/A MODE4 has been
287 * enabled during power on bootstrap.
288 *
289 * Such N/A mode enabled by mistake can put PHY IC in some
290 * internal testing mode and disable RGMII transmission.
291 *
292 * In this particular case one needs to check STRAP_STS1
293 * register's bit 11 (marked as RESERVED).
294 */
295
Grygorii Strashko37d62652019-11-18 23:04:46 +0200296 bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS1);
297 if (bs & DP83867_STRAP_STS1_RESERVED)
Janine Hagemannbe71a742018-08-28 08:25:38 +0200298 val &= ~DP83867_PHYCR_RESERVED_MASK;
Janine Hagemannbe71a742018-08-28 08:25:38 +0200299
Grygorii Strashko37d62652019-11-18 23:04:46 +0200300 ret = phy_write(phydev, MDIO_DEVAD_NONE,
301 MII_DP83867_PHYCTRL, val);
302
303 val = phy_read_mmd(phydev, DP83867_DEVADDR,
304 DP83867_RGMIICTL);
305
306 val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN |
307 DP83867_RGMII_RX_CLK_DELAY_EN);
308 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
309 val |= (DP83867_RGMII_TX_CLK_DELAY_EN |
310 DP83867_RGMII_RX_CLK_DELAY_EN);
311
312 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
313 val |= DP83867_RGMII_TX_CLK_DELAY_EN;
314
315 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
316 val |= DP83867_RGMII_RX_CLK_DELAY_EN;
317
318 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL, val);
319
320 delay = (dp83867->rx_id_delay |
321 (dp83867->tx_id_delay <<
322 DP83867_RGMII_TX_CLK_DELAY_SHIFT));
323
324 phy_write_mmd(phydev, DP83867_DEVADDR,
325 DP83867_RGMIIDCTL, delay);
326 }
327
328 if (phy_interface_is_sgmii(phydev)) {
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +0530329 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR,
330 (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000));
331
332 cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2);
333 cfg2 &= MII_DP83867_CFG2_MASK;
334 cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN |
335 MII_DP83867_CFG2_SGMII_AUTONEGEN |
336 MII_DP83867_CFG2_SPEEDOPT_ENH |
337 MII_DP83867_CFG2_SPEEDOPT_CNT |
338 MII_DP83867_CFG2_SPEEDOPT_INTLOW);
339 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2);
340
Carlo Caione4c29dc12019-02-08 17:25:07 +0000341 phy_write_mmd(phydev, DP83867_DEVADDR,
342 DP83867_RGMIICTL, 0x0);
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +0530343
344 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL,
345 DP83867_PHYCTRL_SGMIIEN |
346 (DP83867_MDI_CROSSOVER_MDIX <<
347 DP83867_MDI_CROSSOVER) |
Dan Murphy085445c2016-05-02 15:45:59 -0500348 (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) |
349 (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT));
Siva Durga Prasad Paladugu85b949f2016-03-25 12:53:43 +0530350 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0);
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700351 }
352
Grygorii Strashko253a5ff2019-11-18 23:04:45 +0200353 if (dp83867->io_impedance >= 0) {
354 val = phy_read_mmd(phydev,
355 DP83867_DEVADDR,
356 DP83867_IO_MUX_CFG);
357 val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
358 val |= dp83867->io_impedance &
359 DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
360 phy_write_mmd(phydev, DP83867_DEVADDR,
361 DP83867_IO_MUX_CFG, val);
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700362 }
363
Janine Hagemannfba725f2018-08-28 08:25:37 +0200364 if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP)
365 dp83867_config_port_mirroring(phydev);
366
Grygorii Strashkob3b9b122019-11-18 23:04:43 +0200367 /* Clock output selection if muxing property is set */
368 if (dp83867->set_clk_output) {
369 val = phy_read_mmd(phydev, DP83867_DEVADDR,
370 DP83867_IO_MUX_CFG);
371
372 if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) {
373 val |= DP83867_IO_MUX_CFG_CLK_O_DISABLE;
374 } else {
375 val &= ~(DP83867_IO_MUX_CFG_CLK_O_SEL_MASK |
376 DP83867_IO_MUX_CFG_CLK_O_DISABLE);
377 val |= dp83867->clk_output_sel <<
378 DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT;
379 }
380 phy_write_mmd(phydev, DP83867_DEVADDR,
381 DP83867_IO_MUX_CFG, val);
382 }
383
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700384 genphy_config_aneg(phydev);
385 return 0;
Dan Murphy085445c2016-05-02 15:45:59 -0500386
387err_out:
Dan Murphy085445c2016-05-02 15:45:59 -0500388 return ret;
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700389}
390
Grygorii Strashkoee622f02019-11-18 23:04:41 +0200391static int dp83867_probe(struct phy_device *phydev)
392{
393 struct dp83867_private *dp83867;
394
395 dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL);
396 if (!dp83867)
397 return -ENOMEM;
398
399 phydev->priv = dp83867;
400 return 0;
401}
402
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700403static struct phy_driver DP83867_driver = {
404 .name = "TI DP83867",
405 .uid = 0x2000a231,
406 .mask = 0xfffffff0,
407 .features = PHY_GBIT_FEATURES,
Grygorii Strashkoee622f02019-11-18 23:04:41 +0200408 .probe = dp83867_probe,
Edgar E. Iglesias721aed72015-09-25 23:46:08 -0700409 .config = &dp83867_config,
410 .startup = &genphy_startup,
411 .shutdown = &genphy_shutdown,
412};
413
414int phy_ti_init(void)
415{
416 phy_register(&DP83867_driver);
417 return 0;
418}