1d0507009SDavid J. Choi /* 2d0507009SDavid J. Choi * drivers/net/phy/micrel.c 3d0507009SDavid J. Choi * 4d0507009SDavid J. Choi * Driver for Micrel PHYs 5d0507009SDavid J. Choi * 6d0507009SDavid J. Choi * Author: David J. Choi 7d0507009SDavid J. Choi * 87ab59dc1SDavid J. Choi * Copyright (c) 2010-2013 Micrel, Inc. 9d0507009SDavid J. Choi * 10d0507009SDavid J. Choi * This program is free software; you can redistribute it and/or modify it 11d0507009SDavid J. Choi * under the terms of the GNU General Public License as published by the 12d0507009SDavid J. Choi * Free Software Foundation; either version 2 of the License, or (at your 13d0507009SDavid J. Choi * option) any later version. 14d0507009SDavid J. Choi * 157ab59dc1SDavid J. Choi * Support : Micrel Phys: 167ab59dc1SDavid J. Choi * Giga phys: ksz9021, ksz9031 177ab59dc1SDavid J. Choi * 100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041 187ab59dc1SDavid J. Choi * ksz8021, ksz8031, ksz8051, 197ab59dc1SDavid J. Choi * ksz8081, ksz8091, 207ab59dc1SDavid J. Choi * ksz8061, 217ab59dc1SDavid J. Choi * Switch : ksz8873, ksz886x 22d0507009SDavid J. Choi */ 23d0507009SDavid J. Choi 24d0507009SDavid J. Choi #include <linux/kernel.h> 25d0507009SDavid J. Choi #include <linux/module.h> 26d0507009SDavid J. Choi #include <linux/phy.h> 27d606ef3fSBaruch Siach #include <linux/micrel_phy.h> 28954c3967SSean Cross #include <linux/of.h> 291fadee0cSSascha Hauer #include <linux/clk.h> 30d0507009SDavid J. Choi 31212ea99aSMarek Vasut /* Operation Mode Strap Override */ 32212ea99aSMarek Vasut #define MII_KSZPHY_OMSO 0x16 3300aee095SJohan Hovold #define KSZPHY_OMSO_B_CAST_OFF BIT(9) 3400aee095SJohan Hovold #define KSZPHY_OMSO_RMII_OVERRIDE BIT(1) 3500aee095SJohan Hovold #define KSZPHY_OMSO_MII_OVERRIDE BIT(0) 36212ea99aSMarek Vasut 3751f932c4SChoi, David /* general Interrupt control/status reg in vendor specific block. */ 3851f932c4SChoi, David #define MII_KSZPHY_INTCS 0x1B 3900aee095SJohan Hovold #define KSZPHY_INTCS_JABBER BIT(15) 4000aee095SJohan Hovold #define KSZPHY_INTCS_RECEIVE_ERR BIT(14) 4100aee095SJohan Hovold #define KSZPHY_INTCS_PAGE_RECEIVE BIT(13) 4200aee095SJohan Hovold #define KSZPHY_INTCS_PARELLEL BIT(12) 4300aee095SJohan Hovold #define KSZPHY_INTCS_LINK_PARTNER_ACK BIT(11) 4400aee095SJohan Hovold #define KSZPHY_INTCS_LINK_DOWN BIT(10) 4500aee095SJohan Hovold #define KSZPHY_INTCS_REMOTE_FAULT BIT(9) 4600aee095SJohan Hovold #define KSZPHY_INTCS_LINK_UP BIT(8) 4751f932c4SChoi, David #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\ 4851f932c4SChoi, David KSZPHY_INTCS_LINK_DOWN) 4951f932c4SChoi, David 505a16778eSJohan Hovold /* PHY Control 1 */ 515a16778eSJohan Hovold #define MII_KSZPHY_CTRL_1 0x1e 525a16778eSJohan Hovold 535a16778eSJohan Hovold /* PHY Control 2 / PHY Control (if no PHY Control 1) */ 545a16778eSJohan Hovold #define MII_KSZPHY_CTRL_2 0x1f 555a16778eSJohan Hovold #define MII_KSZPHY_CTRL MII_KSZPHY_CTRL_2 5651f932c4SChoi, David /* bitmap of PHY register to set interrupt mode */ 5700aee095SJohan Hovold #define KSZPHY_CTRL_INT_ACTIVE_HIGH BIT(9) 5863f44b2bSJohan Hovold #define KSZPHY_RMII_REF_CLK_SEL BIT(7) 5951f932c4SChoi, David 60954c3967SSean Cross /* Write/read to/from extended registers */ 61954c3967SSean Cross #define MII_KSZPHY_EXTREG 0x0b 62954c3967SSean Cross #define KSZPHY_EXTREG_WRITE 0x8000 63954c3967SSean Cross 64954c3967SSean Cross #define MII_KSZPHY_EXTREG_WRITE 0x0c 65954c3967SSean Cross #define MII_KSZPHY_EXTREG_READ 0x0d 66954c3967SSean Cross 67954c3967SSean Cross /* Extended registers */ 68954c3967SSean Cross #define MII_KSZPHY_CLK_CONTROL_PAD_SKEW 0x104 69954c3967SSean Cross #define MII_KSZPHY_RX_DATA_PAD_SKEW 0x105 70954c3967SSean Cross #define MII_KSZPHY_TX_DATA_PAD_SKEW 0x106 71954c3967SSean Cross 72954c3967SSean Cross #define PS_TO_REG 200 73954c3967SSean Cross 74e6a423a8SJohan Hovold struct kszphy_type { 75e6a423a8SJohan Hovold u32 led_mode_reg; 76*c6f9575cSJohan Hovold u16 interrupt_level_mask; 770f95903eSJohan Hovold bool has_broadcast_disable; 7863f44b2bSJohan Hovold bool has_rmii_ref_clk_sel; 79e6a423a8SJohan Hovold }; 80e6a423a8SJohan Hovold 81e6a423a8SJohan Hovold struct kszphy_priv { 82e6a423a8SJohan Hovold const struct kszphy_type *type; 83e7a792e9SJohan Hovold int led_mode; 8463f44b2bSJohan Hovold bool rmii_ref_clk_sel; 8563f44b2bSJohan Hovold bool rmii_ref_clk_sel_val; 86e6a423a8SJohan Hovold }; 87e6a423a8SJohan Hovold 88e6a423a8SJohan Hovold static const struct kszphy_type ksz8021_type = { 89e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 9063f44b2bSJohan Hovold .has_rmii_ref_clk_sel = true, 91e6a423a8SJohan Hovold }; 92e6a423a8SJohan Hovold 93e6a423a8SJohan Hovold static const struct kszphy_type ksz8041_type = { 94e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_1, 95e6a423a8SJohan Hovold }; 96e6a423a8SJohan Hovold 97e6a423a8SJohan Hovold static const struct kszphy_type ksz8051_type = { 98e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 99e6a423a8SJohan Hovold }; 100e6a423a8SJohan Hovold 101e6a423a8SJohan Hovold static const struct kszphy_type ksz8081_type = { 102e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 1030f95903eSJohan Hovold .has_broadcast_disable = true, 10486dc1342SJohan Hovold .has_rmii_ref_clk_sel = true, 105e6a423a8SJohan Hovold }; 106e6a423a8SJohan Hovold 107*c6f9575cSJohan Hovold static const struct kszphy_type ks8737_type = { 108*c6f9575cSJohan Hovold .interrupt_level_mask = BIT(14), 109*c6f9575cSJohan Hovold }; 110*c6f9575cSJohan Hovold 111*c6f9575cSJohan Hovold static const struct kszphy_type ksz9021_type = { 112*c6f9575cSJohan Hovold .interrupt_level_mask = BIT(14), 113*c6f9575cSJohan Hovold }; 114*c6f9575cSJohan Hovold 115954c3967SSean Cross static int kszphy_extended_write(struct phy_device *phydev, 116954c3967SSean Cross u32 regnum, u16 val) 117954c3967SSean Cross { 118954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); 119954c3967SSean Cross return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); 120954c3967SSean Cross } 121954c3967SSean Cross 122954c3967SSean Cross static int kszphy_extended_read(struct phy_device *phydev, 123954c3967SSean Cross u32 regnum) 124954c3967SSean Cross { 125954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, regnum); 126954c3967SSean Cross return phy_read(phydev, MII_KSZPHY_EXTREG_READ); 127954c3967SSean Cross } 128954c3967SSean Cross 12951f932c4SChoi, David static int kszphy_ack_interrupt(struct phy_device *phydev) 13051f932c4SChoi, David { 13151f932c4SChoi, David /* bit[7..0] int status, which is a read and clear register. */ 13251f932c4SChoi, David int rc; 13351f932c4SChoi, David 13451f932c4SChoi, David rc = phy_read(phydev, MII_KSZPHY_INTCS); 13551f932c4SChoi, David 13651f932c4SChoi, David return (rc < 0) ? rc : 0; 13751f932c4SChoi, David } 13851f932c4SChoi, David 13951f932c4SChoi, David static int kszphy_config_intr(struct phy_device *phydev) 14051f932c4SChoi, David { 141*c6f9575cSJohan Hovold const struct kszphy_type *type = phydev->drv->driver_data; 142*c6f9575cSJohan Hovold int temp; 143*c6f9575cSJohan Hovold u16 mask; 144*c6f9575cSJohan Hovold 145*c6f9575cSJohan Hovold if (type && type->interrupt_level_mask) 146*c6f9575cSJohan Hovold mask = type->interrupt_level_mask; 147*c6f9575cSJohan Hovold else 148*c6f9575cSJohan Hovold mask = KSZPHY_CTRL_INT_ACTIVE_HIGH; 14951f932c4SChoi, David 15051f932c4SChoi, David /* set the interrupt pin active low */ 15151f932c4SChoi, David temp = phy_read(phydev, MII_KSZPHY_CTRL); 1525bb8fc0dSJohan Hovold if (temp < 0) 1535bb8fc0dSJohan Hovold return temp; 154*c6f9575cSJohan Hovold temp &= ~mask; 15551f932c4SChoi, David phy_write(phydev, MII_KSZPHY_CTRL, temp); 15651f932c4SChoi, David 157*c6f9575cSJohan Hovold /* enable / disable interrupts */ 158*c6f9575cSJohan Hovold if (phydev->interrupts == PHY_INTERRUPT_ENABLED) 159*c6f9575cSJohan Hovold temp = KSZPHY_INTCS_ALL; 160*c6f9575cSJohan Hovold else 161*c6f9575cSJohan Hovold temp = 0; 16251f932c4SChoi, David 163*c6f9575cSJohan Hovold return phy_write(phydev, MII_KSZPHY_INTCS, temp); 16451f932c4SChoi, David } 165d0507009SDavid J. Choi 16663f44b2bSJohan Hovold static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val) 16763f44b2bSJohan Hovold { 16863f44b2bSJohan Hovold int ctrl; 16963f44b2bSJohan Hovold 17063f44b2bSJohan Hovold ctrl = phy_read(phydev, MII_KSZPHY_CTRL); 17163f44b2bSJohan Hovold if (ctrl < 0) 17263f44b2bSJohan Hovold return ctrl; 17363f44b2bSJohan Hovold 17463f44b2bSJohan Hovold if (val) 17563f44b2bSJohan Hovold ctrl |= KSZPHY_RMII_REF_CLK_SEL; 17663f44b2bSJohan Hovold else 17763f44b2bSJohan Hovold ctrl &= ~KSZPHY_RMII_REF_CLK_SEL; 17863f44b2bSJohan Hovold 17963f44b2bSJohan Hovold return phy_write(phydev, MII_KSZPHY_CTRL, ctrl); 18063f44b2bSJohan Hovold } 18163f44b2bSJohan Hovold 182e7a792e9SJohan Hovold static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val) 18320d8435aSBen Dooks { 1845a16778eSJohan Hovold int rc, temp, shift; 1858620546cSJohan Hovold 1865a16778eSJohan Hovold switch (reg) { 1875a16778eSJohan Hovold case MII_KSZPHY_CTRL_1: 1885a16778eSJohan Hovold shift = 14; 1895a16778eSJohan Hovold break; 1905a16778eSJohan Hovold case MII_KSZPHY_CTRL_2: 1915a16778eSJohan Hovold shift = 4; 1925a16778eSJohan Hovold break; 1935a16778eSJohan Hovold default: 1945a16778eSJohan Hovold return -EINVAL; 1955a16778eSJohan Hovold } 1965a16778eSJohan Hovold 19720d8435aSBen Dooks temp = phy_read(phydev, reg); 198b7035860SJohan Hovold if (temp < 0) { 199b7035860SJohan Hovold rc = temp; 200b7035860SJohan Hovold goto out; 201b7035860SJohan Hovold } 20220d8435aSBen Dooks 20328bdc499SSergei Shtylyov temp &= ~(3 << shift); 20420d8435aSBen Dooks temp |= val << shift; 20520d8435aSBen Dooks rc = phy_write(phydev, reg, temp); 206b7035860SJohan Hovold out: 207b7035860SJohan Hovold if (rc < 0) 208b7035860SJohan Hovold dev_err(&phydev->dev, "failed to set led mode\n"); 20920d8435aSBen Dooks 210b7035860SJohan Hovold return rc; 21120d8435aSBen Dooks } 21220d8435aSBen Dooks 213bde15129SJohan Hovold /* Disable PHY address 0 as the broadcast address, so that it can be used as a 214bde15129SJohan Hovold * unique (non-broadcast) address on a shared bus. 215bde15129SJohan Hovold */ 216bde15129SJohan Hovold static int kszphy_broadcast_disable(struct phy_device *phydev) 217bde15129SJohan Hovold { 218bde15129SJohan Hovold int ret; 219bde15129SJohan Hovold 220bde15129SJohan Hovold ret = phy_read(phydev, MII_KSZPHY_OMSO); 221bde15129SJohan Hovold if (ret < 0) 222bde15129SJohan Hovold goto out; 223bde15129SJohan Hovold 224bde15129SJohan Hovold ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF); 225bde15129SJohan Hovold out: 226bde15129SJohan Hovold if (ret) 227bde15129SJohan Hovold dev_err(&phydev->dev, "failed to disable broadcast address\n"); 228bde15129SJohan Hovold 229bde15129SJohan Hovold return ret; 230bde15129SJohan Hovold } 231bde15129SJohan Hovold 232d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev) 233d0507009SDavid J. Choi { 234e6a423a8SJohan Hovold struct kszphy_priv *priv = phydev->priv; 235e6a423a8SJohan Hovold const struct kszphy_type *type; 23663f44b2bSJohan Hovold int ret; 237d0507009SDavid J. Choi 238e6a423a8SJohan Hovold if (!priv) 239e6a423a8SJohan Hovold return 0; 240e6a423a8SJohan Hovold 241e6a423a8SJohan Hovold type = priv->type; 242e6a423a8SJohan Hovold 2430f95903eSJohan Hovold if (type->has_broadcast_disable) 2440f95903eSJohan Hovold kszphy_broadcast_disable(phydev); 2450f95903eSJohan Hovold 24663f44b2bSJohan Hovold if (priv->rmii_ref_clk_sel) { 24763f44b2bSJohan Hovold ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val); 24863f44b2bSJohan Hovold if (ret) { 24963f44b2bSJohan Hovold dev_err(&phydev->dev, "failed to set rmii reference clock\n"); 25063f44b2bSJohan Hovold return ret; 25163f44b2bSJohan Hovold } 25263f44b2bSJohan Hovold } 25363f44b2bSJohan Hovold 254e7a792e9SJohan Hovold if (priv->led_mode >= 0) 255e7a792e9SJohan Hovold kszphy_setup_led(phydev, type->led_mode_reg, priv->led_mode); 256e6a423a8SJohan Hovold 257e6a423a8SJohan Hovold return 0; 25820d8435aSBen Dooks } 25920d8435aSBen Dooks 260212ea99aSMarek Vasut static int ksz8021_config_init(struct phy_device *phydev) 261212ea99aSMarek Vasut { 26220d8435aSBen Dooks int rc; 26320d8435aSBen Dooks 26463f44b2bSJohan Hovold rc = kszphy_config_init(phydev); 26563f44b2bSJohan Hovold if (rc) 266b838b4acSBruno Thomsen return rc; 267bde15129SJohan Hovold 268bde15129SJohan Hovold rc = kszphy_broadcast_disable(phydev); 269bde15129SJohan Hovold 270b6bb4dfcSHector Palacios return rc < 0 ? rc : 0; 271212ea99aSMarek Vasut } 272212ea99aSMarek Vasut 273954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev, 274954c3967SSean Cross struct device_node *of_node, u16 reg, 275954c3967SSean Cross char *field1, char *field2, 276954c3967SSean Cross char *field3, char *field4) 277954c3967SSean Cross { 278954c3967SSean Cross int val1 = -1; 279954c3967SSean Cross int val2 = -2; 280954c3967SSean Cross int val3 = -3; 281954c3967SSean Cross int val4 = -4; 282954c3967SSean Cross int newval; 283954c3967SSean Cross int matches = 0; 284954c3967SSean Cross 285954c3967SSean Cross if (!of_property_read_u32(of_node, field1, &val1)) 286954c3967SSean Cross matches++; 287954c3967SSean Cross 288954c3967SSean Cross if (!of_property_read_u32(of_node, field2, &val2)) 289954c3967SSean Cross matches++; 290954c3967SSean Cross 291954c3967SSean Cross if (!of_property_read_u32(of_node, field3, &val3)) 292954c3967SSean Cross matches++; 293954c3967SSean Cross 294954c3967SSean Cross if (!of_property_read_u32(of_node, field4, &val4)) 295954c3967SSean Cross matches++; 296954c3967SSean Cross 297954c3967SSean Cross if (!matches) 298954c3967SSean Cross return 0; 299954c3967SSean Cross 300954c3967SSean Cross if (matches < 4) 301954c3967SSean Cross newval = kszphy_extended_read(phydev, reg); 302954c3967SSean Cross else 303954c3967SSean Cross newval = 0; 304954c3967SSean Cross 305954c3967SSean Cross if (val1 != -1) 306954c3967SSean Cross newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0); 307954c3967SSean Cross 3086a119745SHubert Chaumette if (val2 != -2) 309954c3967SSean Cross newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4); 310954c3967SSean Cross 3116a119745SHubert Chaumette if (val3 != -3) 312954c3967SSean Cross newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8); 313954c3967SSean Cross 3146a119745SHubert Chaumette if (val4 != -4) 315954c3967SSean Cross newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12); 316954c3967SSean Cross 317954c3967SSean Cross return kszphy_extended_write(phydev, reg, newval); 318954c3967SSean Cross } 319954c3967SSean Cross 320954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev) 321954c3967SSean Cross { 322954c3967SSean Cross struct device *dev = &phydev->dev; 323954c3967SSean Cross struct device_node *of_node = dev->of_node; 324954c3967SSean Cross 325954c3967SSean Cross if (!of_node && dev->parent->of_node) 326954c3967SSean Cross of_node = dev->parent->of_node; 327954c3967SSean Cross 328954c3967SSean Cross if (of_node) { 329954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 330954c3967SSean Cross MII_KSZPHY_CLK_CONTROL_PAD_SKEW, 331954c3967SSean Cross "txen-skew-ps", "txc-skew-ps", 332954c3967SSean Cross "rxdv-skew-ps", "rxc-skew-ps"); 333954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 334954c3967SSean Cross MII_KSZPHY_RX_DATA_PAD_SKEW, 335954c3967SSean Cross "rxd0-skew-ps", "rxd1-skew-ps", 336954c3967SSean Cross "rxd2-skew-ps", "rxd3-skew-ps"); 337954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 338954c3967SSean Cross MII_KSZPHY_TX_DATA_PAD_SKEW, 339954c3967SSean Cross "txd0-skew-ps", "txd1-skew-ps", 340954c3967SSean Cross "txd2-skew-ps", "txd3-skew-ps"); 341954c3967SSean Cross } 342954c3967SSean Cross return 0; 343954c3967SSean Cross } 344954c3967SSean Cross 3456e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG 0x0d 3466e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG 0x0e 3476e4b8273SHubert Chaumette #define OP_DATA 1 3486e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG 60 3496e4b8273SHubert Chaumette 3506e4b8273SHubert Chaumette /* Extended registers */ 3516e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW 4 3526e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW 5 3536e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW 6 3546e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW 8 3556e4b8273SHubert Chaumette 3566e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev, 3576e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum, u16 val) 3586e4b8273SHubert Chaumette { 3596e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 3606e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 3616e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 3626e4b8273SHubert Chaumette return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val); 3636e4b8273SHubert Chaumette } 3646e4b8273SHubert Chaumette 3656e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev, 3666e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum) 3676e4b8273SHubert Chaumette { 3686e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 3696e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 3706e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 3716e4b8273SHubert Chaumette return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG); 3726e4b8273SHubert Chaumette } 3736e4b8273SHubert Chaumette 3746e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev, 3756e4b8273SHubert Chaumette struct device_node *of_node, 3766e4b8273SHubert Chaumette u16 reg, size_t field_sz, 3776e4b8273SHubert Chaumette char *field[], u8 numfields) 3786e4b8273SHubert Chaumette { 3796e4b8273SHubert Chaumette int val[4] = {-1, -2, -3, -4}; 3806e4b8273SHubert Chaumette int matches = 0; 3816e4b8273SHubert Chaumette u16 mask; 3826e4b8273SHubert Chaumette u16 maxval; 3836e4b8273SHubert Chaumette u16 newval; 3846e4b8273SHubert Chaumette int i; 3856e4b8273SHubert Chaumette 3866e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 3876e4b8273SHubert Chaumette if (!of_property_read_u32(of_node, field[i], val + i)) 3886e4b8273SHubert Chaumette matches++; 3896e4b8273SHubert Chaumette 3906e4b8273SHubert Chaumette if (!matches) 3916e4b8273SHubert Chaumette return 0; 3926e4b8273SHubert Chaumette 3936e4b8273SHubert Chaumette if (matches < numfields) 3946e4b8273SHubert Chaumette newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg); 3956e4b8273SHubert Chaumette else 3966e4b8273SHubert Chaumette newval = 0; 3976e4b8273SHubert Chaumette 3986e4b8273SHubert Chaumette maxval = (field_sz == 4) ? 0xf : 0x1f; 3996e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 4006e4b8273SHubert Chaumette if (val[i] != -(i + 1)) { 4016e4b8273SHubert Chaumette mask = 0xffff; 4026e4b8273SHubert Chaumette mask ^= maxval << (field_sz * i); 4036e4b8273SHubert Chaumette newval = (newval & mask) | 4046e4b8273SHubert Chaumette (((val[i] / KSZ9031_PS_TO_REG) & maxval) 4056e4b8273SHubert Chaumette << (field_sz * i)); 4066e4b8273SHubert Chaumette } 4076e4b8273SHubert Chaumette 4086e4b8273SHubert Chaumette return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval); 4096e4b8273SHubert Chaumette } 4106e4b8273SHubert Chaumette 4116e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev) 4126e4b8273SHubert Chaumette { 4136e4b8273SHubert Chaumette struct device *dev = &phydev->dev; 4146e4b8273SHubert Chaumette struct device_node *of_node = dev->of_node; 4156e4b8273SHubert Chaumette char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"}; 4166e4b8273SHubert Chaumette char *rx_data_skews[4] = { 4176e4b8273SHubert Chaumette "rxd0-skew-ps", "rxd1-skew-ps", 4186e4b8273SHubert Chaumette "rxd2-skew-ps", "rxd3-skew-ps" 4196e4b8273SHubert Chaumette }; 4206e4b8273SHubert Chaumette char *tx_data_skews[4] = { 4216e4b8273SHubert Chaumette "txd0-skew-ps", "txd1-skew-ps", 4226e4b8273SHubert Chaumette "txd2-skew-ps", "txd3-skew-ps" 4236e4b8273SHubert Chaumette }; 4246e4b8273SHubert Chaumette char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"}; 4256e4b8273SHubert Chaumette 4266e4b8273SHubert Chaumette if (!of_node && dev->parent->of_node) 4276e4b8273SHubert Chaumette of_node = dev->parent->of_node; 4286e4b8273SHubert Chaumette 4296e4b8273SHubert Chaumette if (of_node) { 4306e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4316e4b8273SHubert Chaumette MII_KSZ9031RN_CLK_PAD_SKEW, 5, 4326e4b8273SHubert Chaumette clk_skews, 2); 4336e4b8273SHubert Chaumette 4346e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4356e4b8273SHubert Chaumette MII_KSZ9031RN_CONTROL_PAD_SKEW, 4, 4366e4b8273SHubert Chaumette control_skews, 2); 4376e4b8273SHubert Chaumette 4386e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4396e4b8273SHubert Chaumette MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4, 4406e4b8273SHubert Chaumette rx_data_skews, 4); 4416e4b8273SHubert Chaumette 4426e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4436e4b8273SHubert Chaumette MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 4446e4b8273SHubert Chaumette tx_data_skews, 4); 4456e4b8273SHubert Chaumette } 4466e4b8273SHubert Chaumette return 0; 4476e4b8273SHubert Chaumette } 4486e4b8273SHubert Chaumette 44993272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 45000aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX BIT(6) 45100aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED BIT(4) 45232d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev) 45393272e07SJean-Christophe PLAGNIOL-VILLARD { 45493272e07SJean-Christophe PLAGNIOL-VILLARD int regval; 45593272e07SJean-Christophe PLAGNIOL-VILLARD 45693272e07SJean-Christophe PLAGNIOL-VILLARD /* dummy read */ 45793272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 45893272e07SJean-Christophe PLAGNIOL-VILLARD 45993272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 46093272e07SJean-Christophe PLAGNIOL-VILLARD 46193272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX) 46293272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_HALF; 46393272e07SJean-Christophe PLAGNIOL-VILLARD else 46493272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_FULL; 46593272e07SJean-Christophe PLAGNIOL-VILLARD 46693272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED) 46793272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_10; 46893272e07SJean-Christophe PLAGNIOL-VILLARD else 46993272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_100; 47093272e07SJean-Christophe PLAGNIOL-VILLARD 47193272e07SJean-Christophe PLAGNIOL-VILLARD phydev->link = 1; 47293272e07SJean-Christophe PLAGNIOL-VILLARD phydev->pause = phydev->asym_pause = 0; 47393272e07SJean-Christophe PLAGNIOL-VILLARD 47493272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 47593272e07SJean-Christophe PLAGNIOL-VILLARD } 47693272e07SJean-Christophe PLAGNIOL-VILLARD 47793272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev) 47893272e07SJean-Christophe PLAGNIOL-VILLARD { 47993272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 48093272e07SJean-Christophe PLAGNIOL-VILLARD } 48193272e07SJean-Christophe PLAGNIOL-VILLARD 48219936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the 48319936942SVince Bridgers * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE 48419936942SVince Bridgers * MMD extended PHY registers. 48519936942SVince Bridgers */ 48619936942SVince Bridgers static int 48719936942SVince Bridgers ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 48819936942SVince Bridgers int regnum) 48919936942SVince Bridgers { 49019936942SVince Bridgers return -1; 49119936942SVince Bridgers } 49219936942SVince Bridgers 49319936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support 49419936942SVince Bridgers * standard IEEE MMD extended PHY registers. 49519936942SVince Bridgers */ 49619936942SVince Bridgers static void 49719936942SVince Bridgers ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 49819936942SVince Bridgers int regnum, u32 val) 49919936942SVince Bridgers { 50019936942SVince Bridgers } 50119936942SVince Bridgers 502e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev) 503e6a423a8SJohan Hovold { 504e6a423a8SJohan Hovold const struct kszphy_type *type = phydev->drv->driver_data; 505e7a792e9SJohan Hovold struct device_node *np = phydev->dev.of_node; 506e6a423a8SJohan Hovold struct kszphy_priv *priv; 50763f44b2bSJohan Hovold struct clk *clk; 508e7a792e9SJohan Hovold int ret; 509e6a423a8SJohan Hovold 510e6a423a8SJohan Hovold priv = devm_kzalloc(&phydev->dev, sizeof(*priv), GFP_KERNEL); 511e6a423a8SJohan Hovold if (!priv) 512e6a423a8SJohan Hovold return -ENOMEM; 513e6a423a8SJohan Hovold 514e6a423a8SJohan Hovold phydev->priv = priv; 515e6a423a8SJohan Hovold 516e6a423a8SJohan Hovold priv->type = type; 517e6a423a8SJohan Hovold 518e7a792e9SJohan Hovold if (type->led_mode_reg) { 519e7a792e9SJohan Hovold ret = of_property_read_u32(np, "micrel,led-mode", 520e7a792e9SJohan Hovold &priv->led_mode); 521e7a792e9SJohan Hovold if (ret) 522e7a792e9SJohan Hovold priv->led_mode = -1; 523e7a792e9SJohan Hovold 524e7a792e9SJohan Hovold if (priv->led_mode > 3) { 525e7a792e9SJohan Hovold dev_err(&phydev->dev, "invalid led mode: 0x%02x\n", 526e7a792e9SJohan Hovold priv->led_mode); 527e7a792e9SJohan Hovold priv->led_mode = -1; 528e7a792e9SJohan Hovold } 529e7a792e9SJohan Hovold } else { 530e7a792e9SJohan Hovold priv->led_mode = -1; 531e7a792e9SJohan Hovold } 532e7a792e9SJohan Hovold 5331fadee0cSSascha Hauer clk = devm_clk_get(&phydev->dev, "rmii-ref"); 5341fadee0cSSascha Hauer if (!IS_ERR(clk)) { 5351fadee0cSSascha Hauer unsigned long rate = clk_get_rate(clk); 53686dc1342SJohan Hovold bool rmii_ref_clk_sel_25_mhz; 5371fadee0cSSascha Hauer 53863f44b2bSJohan Hovold priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; 53986dc1342SJohan Hovold rmii_ref_clk_sel_25_mhz = of_property_read_bool(np, 54086dc1342SJohan Hovold "micrel,rmii-reference-clock-select-25-mhz"); 54163f44b2bSJohan Hovold 5421fadee0cSSascha Hauer if (rate > 24500000 && rate < 25500000) { 54386dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz; 5441fadee0cSSascha Hauer } else if (rate > 49500000 && rate < 50500000) { 54586dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz; 5461fadee0cSSascha Hauer } else { 5471fadee0cSSascha Hauer dev_err(&phydev->dev, "Clock rate out of range: %ld\n", rate); 5481fadee0cSSascha Hauer return -EINVAL; 5491fadee0cSSascha Hauer } 5501fadee0cSSascha Hauer } 5511fadee0cSSascha Hauer 55263f44b2bSJohan Hovold /* Support legacy board-file configuration */ 55363f44b2bSJohan Hovold if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) { 55463f44b2bSJohan Hovold priv->rmii_ref_clk_sel = true; 55563f44b2bSJohan Hovold priv->rmii_ref_clk_sel_val = true; 55663f44b2bSJohan Hovold } 55763f44b2bSJohan Hovold 55863f44b2bSJohan Hovold return 0; 5591fadee0cSSascha Hauer } 5601fadee0cSSascha Hauer 561d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = { 562d5bf9071SChristian Hohnstaedt { 56351f932c4SChoi, David .phy_id = PHY_ID_KS8737, 564d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 56551f932c4SChoi, David .name = "Micrel KS8737", 56651f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 56751f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 568*c6f9575cSJohan Hovold .driver_data = &ks8737_type, 569d0507009SDavid J. Choi .config_init = kszphy_config_init, 570d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 571d0507009SDavid J. Choi .read_status = genphy_read_status, 57251f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 573*c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 5741a5465f5SPatrice Vilchez .suspend = genphy_suspend, 5751a5465f5SPatrice Vilchez .resume = genphy_resume, 576d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 577d5bf9071SChristian Hohnstaedt }, { 578212ea99aSMarek Vasut .phy_id = PHY_ID_KSZ8021, 579212ea99aSMarek Vasut .phy_id_mask = 0x00ffffff, 5807ab59dc1SDavid J. Choi .name = "Micrel KSZ8021 or KSZ8031", 581212ea99aSMarek Vasut .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 582212ea99aSMarek Vasut SUPPORTED_Asym_Pause), 583212ea99aSMarek Vasut .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 584e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 58563f44b2bSJohan Hovold .probe = kszphy_probe, 586212ea99aSMarek Vasut .config_init = ksz8021_config_init, 587212ea99aSMarek Vasut .config_aneg = genphy_config_aneg, 588212ea99aSMarek Vasut .read_status = genphy_read_status, 589212ea99aSMarek Vasut .ack_interrupt = kszphy_ack_interrupt, 590212ea99aSMarek Vasut .config_intr = kszphy_config_intr, 5911a5465f5SPatrice Vilchez .suspend = genphy_suspend, 5921a5465f5SPatrice Vilchez .resume = genphy_resume, 593212ea99aSMarek Vasut .driver = { .owner = THIS_MODULE,}, 594212ea99aSMarek Vasut }, { 595b818d1a7SHector Palacios .phy_id = PHY_ID_KSZ8031, 596b818d1a7SHector Palacios .phy_id_mask = 0x00ffffff, 597b818d1a7SHector Palacios .name = "Micrel KSZ8031", 598b818d1a7SHector Palacios .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 599b818d1a7SHector Palacios SUPPORTED_Asym_Pause), 600b818d1a7SHector Palacios .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 601e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 60263f44b2bSJohan Hovold .probe = kszphy_probe, 603b818d1a7SHector Palacios .config_init = ksz8021_config_init, 604b818d1a7SHector Palacios .config_aneg = genphy_config_aneg, 605b818d1a7SHector Palacios .read_status = genphy_read_status, 606b818d1a7SHector Palacios .ack_interrupt = kszphy_ack_interrupt, 607b818d1a7SHector Palacios .config_intr = kszphy_config_intr, 6081a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6091a5465f5SPatrice Vilchez .resume = genphy_resume, 610b818d1a7SHector Palacios .driver = { .owner = THIS_MODULE,}, 611b818d1a7SHector Palacios }, { 612510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8041, 613d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 614510d573fSMarek Vasut .name = "Micrel KSZ8041", 61551f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 61651f932c4SChoi, David | SUPPORTED_Asym_Pause), 61751f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 618e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 619e6a423a8SJohan Hovold .probe = kszphy_probe, 620e6a423a8SJohan Hovold .config_init = kszphy_config_init, 621d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 622d0507009SDavid J. Choi .read_status = genphy_read_status, 62351f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 62451f932c4SChoi, David .config_intr = kszphy_config_intr, 6251a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6261a5465f5SPatrice Vilchez .resume = genphy_resume, 62751f932c4SChoi, David .driver = { .owner = THIS_MODULE,}, 628d5bf9071SChristian Hohnstaedt }, { 6294bd7b512SSergei Shtylyov .phy_id = PHY_ID_KSZ8041RNLI, 6304bd7b512SSergei Shtylyov .phy_id_mask = 0x00fffff0, 6314bd7b512SSergei Shtylyov .name = "Micrel KSZ8041RNLI", 6324bd7b512SSergei Shtylyov .features = PHY_BASIC_FEATURES | 6334bd7b512SSergei Shtylyov SUPPORTED_Pause | SUPPORTED_Asym_Pause, 6344bd7b512SSergei Shtylyov .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 635e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 636e6a423a8SJohan Hovold .probe = kszphy_probe, 637e6a423a8SJohan Hovold .config_init = kszphy_config_init, 6384bd7b512SSergei Shtylyov .config_aneg = genphy_config_aneg, 6394bd7b512SSergei Shtylyov .read_status = genphy_read_status, 6404bd7b512SSergei Shtylyov .ack_interrupt = kszphy_ack_interrupt, 6414bd7b512SSergei Shtylyov .config_intr = kszphy_config_intr, 6424bd7b512SSergei Shtylyov .suspend = genphy_suspend, 6434bd7b512SSergei Shtylyov .resume = genphy_resume, 6444bd7b512SSergei Shtylyov .driver = { .owner = THIS_MODULE,}, 6454bd7b512SSergei Shtylyov }, { 646510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8051, 64751f932c4SChoi, David .phy_id_mask = 0x00fffff0, 648510d573fSMarek Vasut .name = "Micrel KSZ8051", 64951f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 65051f932c4SChoi, David | SUPPORTED_Asym_Pause), 65151f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 652e6a423a8SJohan Hovold .driver_data = &ksz8051_type, 653e6a423a8SJohan Hovold .probe = kszphy_probe, 65463f44b2bSJohan Hovold .config_init = kszphy_config_init, 65551f932c4SChoi, David .config_aneg = genphy_config_aneg, 65651f932c4SChoi, David .read_status = genphy_read_status, 65751f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 65851f932c4SChoi, David .config_intr = kszphy_config_intr, 6591a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6601a5465f5SPatrice Vilchez .resume = genphy_resume, 66151f932c4SChoi, David .driver = { .owner = THIS_MODULE,}, 662d5bf9071SChristian Hohnstaedt }, { 663510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8001, 664510d573fSMarek Vasut .name = "Micrel KSZ8001 or KS8721", 66548d7d0adSJason Wang .phy_id_mask = 0x00ffffff, 66651f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 66751f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 668e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 669e6a423a8SJohan Hovold .probe = kszphy_probe, 670e6a423a8SJohan Hovold .config_init = kszphy_config_init, 67151f932c4SChoi, David .config_aneg = genphy_config_aneg, 67251f932c4SChoi, David .read_status = genphy_read_status, 67351f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 67451f932c4SChoi, David .config_intr = kszphy_config_intr, 6751a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6761a5465f5SPatrice Vilchez .resume = genphy_resume, 677d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 678d5bf9071SChristian Hohnstaedt }, { 6797ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8081, 6807ab59dc1SDavid J. Choi .name = "Micrel KSZ8081 or KSZ8091", 6817ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 6827ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 6837ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 684e6a423a8SJohan Hovold .driver_data = &ksz8081_type, 685e6a423a8SJohan Hovold .probe = kszphy_probe, 6860f95903eSJohan Hovold .config_init = kszphy_config_init, 6877ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 6887ab59dc1SDavid J. Choi .read_status = genphy_read_status, 6897ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 6907ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 6911a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6921a5465f5SPatrice Vilchez .resume = genphy_resume, 6937ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 6947ab59dc1SDavid J. Choi }, { 6957ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8061, 6967ab59dc1SDavid J. Choi .name = "Micrel KSZ8061", 6977ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 6987ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 6997ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 7007ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 7017ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7027ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7037ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 7047ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 7051a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7061a5465f5SPatrice Vilchez .resume = genphy_resume, 7077ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 7087ab59dc1SDavid J. Choi }, { 709d0507009SDavid J. Choi .phy_id = PHY_ID_KSZ9021, 71048d7d0adSJason Wang .phy_id_mask = 0x000ffffe, 711d0507009SDavid J. Choi .name = "Micrel KSZ9021 Gigabit PHY", 71232fcafbcSVlastimil Kosar .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 71351f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 714*c6f9575cSJohan Hovold .driver_data = &ksz9021_type, 715954c3967SSean Cross .config_init = ksz9021_config_init, 716d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 717d0507009SDavid J. Choi .read_status = genphy_read_status, 71851f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 719*c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 7201a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7211a5465f5SPatrice Vilchez .resume = genphy_resume, 72219936942SVince Bridgers .read_mmd_indirect = ksz9021_rd_mmd_phyreg, 72319936942SVince Bridgers .write_mmd_indirect = ksz9021_wr_mmd_phyreg, 724d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 72593272e07SJean-Christophe PLAGNIOL-VILLARD }, { 7267ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ9031, 7277ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 7287ab59dc1SDavid J. Choi .name = "Micrel KSZ9031 Gigabit PHY", 72995e8b103SMike Looijmans .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 7307ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 731*c6f9575cSJohan Hovold .driver_data = &ksz9021_type, 7326e4b8273SHubert Chaumette .config_init = ksz9031_config_init, 7337ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7347ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7357ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 736*c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 7371a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7381a5465f5SPatrice Vilchez .resume = genphy_resume, 7397ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 7407ab59dc1SDavid J. Choi }, { 74193272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id = PHY_ID_KSZ8873MLL, 74293272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id_mask = 0x00fffff0, 74393272e07SJean-Christophe PLAGNIOL-VILLARD .name = "Micrel KSZ8873MLL Switch", 74493272e07SJean-Christophe PLAGNIOL-VILLARD .features = (SUPPORTED_Pause | SUPPORTED_Asym_Pause), 74593272e07SJean-Christophe PLAGNIOL-VILLARD .flags = PHY_HAS_MAGICANEG, 74693272e07SJean-Christophe PLAGNIOL-VILLARD .config_init = kszphy_config_init, 74793272e07SJean-Christophe PLAGNIOL-VILLARD .config_aneg = ksz8873mll_config_aneg, 74893272e07SJean-Christophe PLAGNIOL-VILLARD .read_status = ksz8873mll_read_status, 7491a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7501a5465f5SPatrice Vilchez .resume = genphy_resume, 75193272e07SJean-Christophe PLAGNIOL-VILLARD .driver = { .owner = THIS_MODULE, }, 7527ab59dc1SDavid J. Choi }, { 7537ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ886X, 7547ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 7557ab59dc1SDavid J. Choi .name = "Micrel KSZ886X Switch", 7567ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 7577ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 7587ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 7597ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7607ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7611a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7621a5465f5SPatrice Vilchez .resume = genphy_resume, 7637ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 764d5bf9071SChristian Hohnstaedt } }; 765d0507009SDavid J. Choi 76650fd7150SJohan Hovold module_phy_driver(ksphy_driver); 767d0507009SDavid J. Choi 768d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver"); 769d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi"); 770d0507009SDavid J. Choi MODULE_LICENSE("GPL"); 77152a60ed2SDavid S. Miller 772cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = { 77348d7d0adSJason Wang { PHY_ID_KSZ9021, 0x000ffffe }, 7747ab59dc1SDavid J. Choi { PHY_ID_KSZ9031, 0x00fffff0 }, 775510d573fSMarek Vasut { PHY_ID_KSZ8001, 0x00ffffff }, 77651f932c4SChoi, David { PHY_ID_KS8737, 0x00fffff0 }, 777212ea99aSMarek Vasut { PHY_ID_KSZ8021, 0x00ffffff }, 778b818d1a7SHector Palacios { PHY_ID_KSZ8031, 0x00ffffff }, 779510d573fSMarek Vasut { PHY_ID_KSZ8041, 0x00fffff0 }, 780510d573fSMarek Vasut { PHY_ID_KSZ8051, 0x00fffff0 }, 7817ab59dc1SDavid J. Choi { PHY_ID_KSZ8061, 0x00fffff0 }, 7827ab59dc1SDavid J. Choi { PHY_ID_KSZ8081, 0x00fffff0 }, 78393272e07SJean-Christophe PLAGNIOL-VILLARD { PHY_ID_KSZ8873MLL, 0x00fffff0 }, 7847ab59dc1SDavid J. Choi { PHY_ID_KSZ886X, 0x00fffff0 }, 78552a60ed2SDavid S. Miller { } 78652a60ed2SDavid S. Miller }; 78752a60ed2SDavid S. Miller 78852a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl); 789