blob: f9bb9256468b9f2be34e059f7ce7b686f4f7f261 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -07002/*
3 * TI PHY drivers
4 *
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -07005 */
6#include <common.h>
7#include <phy.h>
Dan Murphy83fbd0a2016-05-02 15:45:59 -05008#include <linux/compat.h>
9#include <malloc.h>
10
Dan Murphy83fbd0a2016-05-02 15:45:59 -050011#include <dm.h>
12#include <dt-bindings/net/ti-dp83867.h>
13
Edgar E. Iglesias8d3ce682015-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 Paladugu02c7be62016-03-25 12:53:43 +053020#define MII_DP83867_CFG2 0x14
21#define MII_DP83867_BISCR 0x16
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070022#define DP83867_CTRL 0x1f
23
24/* Extended Registers */
Murali Karicheri9b050762018-06-28 14:26:34 -050025#define DP83867_CFG4 0x0031
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070026#define DP83867_RGMIICTL 0x0032
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +020027#define DP83867_STRAP_STS1 0x006E
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020028#define DP83867_STRAP_STS2 0x006f
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070029#define DP83867_RGMIIDCTL 0x0086
Mugunthan V N5b6b18e2017-01-24 11:15:40 -060030#define DP83867_IO_MUX_CFG 0x0170
Edgar E. Iglesias8d3ce682015-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 Hagemannb3dd2ed2018-08-28 08:25:38 +020053/* STRAP_STS1 bits */
54#define DP83867_STRAP_STS1_RESERVED BIT(11)
55
Grygorii Strashko5b2742c2019-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. Iglesias8d3ce682015-09-25 23:46:08 -070063/* PHY CTRL bits */
64#define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +020065#define DP83867_PHYCR_RESERVED_MASK BIT(11)
Michal Simekf6459152015-10-19 10:43:30 +020066#define DP83867_MDI_CROSSOVER 5
67#define DP83867_MDI_CROSSOVER_AUTO 2
Siva Durga Prasad Paladugu02c7be62016-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. Iglesias8d3ce682015-09-25 23:46:08 -070072
73/* RGMIIDCTL bits */
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020074#define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070075#define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020076#define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070077
Siva Durga Prasad Paladugu02c7be62016-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 Murphy83fbd0a2016-05-02 15:45:59 -050086/* User setting - can be taken from DTS */
Dan Murphy83fbd0a2016-05-02 15:45:59 -050087#define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB
88
Mugunthan V N5b6b18e2017-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 Strashko1c35b572019-11-18 23:04:43 +020094#define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6)
Janine Hagemann1c2ba092018-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 N5b6b18e2017-01-24 11:15:40 -060098
Janine Hagemanned51bfc2018-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 Murphy83fbd0a2016-05-02 15:45:59 -0500108struct dp83867_private {
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200109 u32 rx_id_delay;
110 u32 tx_id_delay;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500111 int fifo_depth;
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600112 int io_impedance;
Murali Karicheri9b050762018-06-28 14:26:34 -0500113 bool rxctrl_strap_quirk;
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200114 int port_mirroring;
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200115 bool set_clk_output;
Trent Piephob0a86e52019-05-10 17:49:08 +0000116 unsigned int clk_output_sel;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500117};
118
Janine Hagemanned51bfc2018-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 Caionea8abcff2019-02-08 17:25:07 +0000125 val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
Janine Hagemanned51bfc2018-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 Caionea8abcff2019-02-08 17:25:07 +0000132 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200133
134 return 0;
135}
136
Dan Murphy83fbd0a2016-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 Strashko00e2c242018-07-05 12:02:49 -0500146 ofnode node;
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200147 int ret;
Janine Hagemann1c2ba092018-08-28 08:25:39 +0200148
Michal Simek8e102a82019-03-16 12:43:17 +0100149 node = phy_get_ofnode(phydev);
150 if (!ofnode_valid(node))
151 return -EINVAL;
152
Grygorii Strashko1c35b572019-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 Strashko00e2c242018-07-05 12:02:49 -0500169
Grygorii Strashko9df35052018-06-28 14:26:35 -0500170 if (ofnode_read_bool(node, "ti,max-output-impedance"))
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600171 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
Grygorii Strashko9df35052018-06-28 14:26:35 -0500172 else if (ofnode_read_bool(node, "ti,min-output-impedance"))
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600173 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
174 else
175 dp83867->io_impedance = -EINVAL;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500176
Grygorii Strashko9df35052018-06-28 14:26:35 -0500177 if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk"))
Murali Karicheri9b050762018-06-28 14:26:34 -0500178 dp83867->rxctrl_strap_quirk = true;
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200179
180 /* 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;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500190
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200191 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 Murphy83fbd0a2016-05-02 15:45:59 -0500228
Grygorii Strashko9df35052018-06-28 14:26:35 -0500229 dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth",
Trent Piepho19d7aee2019-05-09 19:41:51 +0000230 DEFAULT_FIFO_DEPTH);
Janine Hagemanned51bfc2018-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 Murphy83fbd0a2016-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 Strashko5b2742c2019-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 Murphy83fbd0a2016-05-02 15:45:59 -0500246 dp83867->fifo_depth = DEFAULT_FIFO_DEPTH;
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600247 dp83867->io_impedance = -EINVAL;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500248
249 return 0;
250}
251#endif
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700252
253static int dp83867_config(struct phy_device *phydev)
254{
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500255 struct dp83867_private *dp83867;
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530256 unsigned int val, delay, cfg2;
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200257 int ret, bs;
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700258
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200259 dp83867 = (struct dp83867_private *)phydev->priv;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500260
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200261 ret = dp83867_of_init(phydev);
262 if (ret)
263 return ret;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500264
Edgar E. Iglesias8d3ce682015-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 Karicheri9b050762018-06-28 14:26:34 -0500270 /* Mode 1 or 2 workaround */
271 if (dp83867->rxctrl_strap_quirk) {
Carlo Caionea8abcff2019-02-08 17:25:07 +0000272 val = phy_read_mmd(phydev, DP83867_DEVADDR,
273 DP83867_CFG4);
Murali Karicheri9b050762018-06-28 14:26:34 -0500274 val &= ~BIT(7);
Carlo Caionea8abcff2019-02-08 17:25:07 +0000275 phy_write_mmd(phydev, DP83867_DEVADDR,
276 DP83867_CFG4, val);
Murali Karicheri9b050762018-06-28 14:26:34 -0500277 }
278
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700279 if (phy_interface_is_rgmii(phydev)) {
280 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL,
Michal Simekf6459152015-10-19 10:43:30 +0200281 (DP83867_MDI_CROSSOVER_AUTO << DP83867_MDI_CROSSOVER) |
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500282 (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT));
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700283 if (ret)
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500284 goto err_out;
Janine Hagemannb3dd2ed2018-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
Carlo Caionea8abcff2019-02-08 17:25:07 +0000296 bs = phy_read_mmd(phydev, DP83867_DEVADDR,
297 DP83867_STRAP_STS1);
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200298 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL);
299 if (bs & DP83867_STRAP_STS1_RESERVED) {
300 val &= ~DP83867_PHYCR_RESERVED_MASK;
301 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL,
302 val);
303 }
304
Dan Murphy4f4e9622016-05-02 15:46:02 -0500305 } else if (phy_interface_is_sgmii(phydev)) {
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530306 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR,
307 (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000));
308
309 cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2);
310 cfg2 &= MII_DP83867_CFG2_MASK;
311 cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN |
312 MII_DP83867_CFG2_SGMII_AUTONEGEN |
313 MII_DP83867_CFG2_SPEEDOPT_ENH |
314 MII_DP83867_CFG2_SPEEDOPT_CNT |
315 MII_DP83867_CFG2_SPEEDOPT_INTLOW);
316 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2);
317
Carlo Caionea8abcff2019-02-08 17:25:07 +0000318 phy_write_mmd(phydev, DP83867_DEVADDR,
319 DP83867_RGMIICTL, 0x0);
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530320
321 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL,
322 DP83867_PHYCTRL_SGMIIEN |
323 (DP83867_MDI_CROSSOVER_MDIX <<
324 DP83867_MDI_CROSSOVER) |
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500325 (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) |
326 (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT));
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530327 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700328 }
329
Phil Edworthyc6119802016-12-09 10:46:02 +0000330 if (phy_interface_is_rgmii(phydev)) {
Carlo Caionea8abcff2019-02-08 17:25:07 +0000331 val = phy_read_mmd(phydev, DP83867_DEVADDR,
332 DP83867_RGMIICTL);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700333
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200334 val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN |
335 DP83867_RGMII_RX_CLK_DELAY_EN);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700336 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
337 val |= (DP83867_RGMII_TX_CLK_DELAY_EN |
338 DP83867_RGMII_RX_CLK_DELAY_EN);
339
340 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
341 val |= DP83867_RGMII_TX_CLK_DELAY_EN;
342
343 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
344 val |= DP83867_RGMII_RX_CLK_DELAY_EN;
345
Carlo Caionea8abcff2019-02-08 17:25:07 +0000346 phy_write_mmd(phydev, DP83867_DEVADDR,
347 DP83867_RGMIICTL, val);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700348
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500349 delay = (dp83867->rx_id_delay |
350 (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT));
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700351
Carlo Caionea8abcff2019-02-08 17:25:07 +0000352 phy_write_mmd(phydev, DP83867_DEVADDR,
353 DP83867_RGMIIDCTL, delay);
Grygorii Strashko38432512019-11-18 23:04:45 +0200354 }
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600355
Grygorii Strashko38432512019-11-18 23:04:45 +0200356 if (dp83867->io_impedance >= 0) {
357 val = phy_read_mmd(phydev,
358 DP83867_DEVADDR,
359 DP83867_IO_MUX_CFG);
360 val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
361 val |= dp83867->io_impedance &
362 DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
363 phy_write_mmd(phydev, DP83867_DEVADDR,
364 DP83867_IO_MUX_CFG, val);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700365 }
366
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200367 if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP)
368 dp83867_config_port_mirroring(phydev);
369
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200370 /* Clock output selection if muxing property is set */
371 if (dp83867->set_clk_output) {
372 val = phy_read_mmd(phydev, DP83867_DEVADDR,
373 DP83867_IO_MUX_CFG);
374
375 if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) {
376 val |= DP83867_IO_MUX_CFG_CLK_O_DISABLE;
377 } else {
378 val &= ~(DP83867_IO_MUX_CFG_CLK_O_SEL_MASK |
379 DP83867_IO_MUX_CFG_CLK_O_DISABLE);
380 val |= dp83867->clk_output_sel <<
381 DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT;
382 }
383 phy_write_mmd(phydev, DP83867_DEVADDR,
384 DP83867_IO_MUX_CFG, val);
385 }
386
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700387 genphy_config_aneg(phydev);
388 return 0;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500389
390err_out:
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500391 return ret;
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700392}
393
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200394static int dp83867_probe(struct phy_device *phydev)
395{
396 struct dp83867_private *dp83867;
397
398 dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL);
399 if (!dp83867)
400 return -ENOMEM;
401
402 phydev->priv = dp83867;
403 return 0;
404}
405
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700406static struct phy_driver DP83867_driver = {
407 .name = "TI DP83867",
408 .uid = 0x2000a231,
409 .mask = 0xfffffff0,
410 .features = PHY_GBIT_FEATURES,
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200411 .probe = dp83867_probe,
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700412 .config = &dp83867_config,
413 .startup = &genphy_startup,
414 .shutdown = &genphy_shutdown,
415};
416
417int phy_ti_init(void)
418{
419 phy_register(&DP83867_driver);
420 return 0;
421}