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. 9ee0dc2fbSJohan Hovold * Copyright (c) 2014 Johan Hovold <johan@kernel.org> 10d0507009SDavid J. Choi * 11d0507009SDavid J. Choi * This program is free software; you can redistribute it and/or modify it 12d0507009SDavid J. Choi * under the terms of the GNU General Public License as published by the 13d0507009SDavid J. Choi * Free Software Foundation; either version 2 of the License, or (at your 14d0507009SDavid J. Choi * option) any later version. 15d0507009SDavid J. Choi * 167ab59dc1SDavid J. Choi * Support : Micrel Phys: 177ab59dc1SDavid J. Choi * Giga phys: ksz9021, ksz9031 187ab59dc1SDavid J. Choi * 100/10 Phys : ksz8001, ksz8721, ksz8737, ksz8041 197ab59dc1SDavid J. Choi * ksz8021, ksz8031, ksz8051, 207ab59dc1SDavid J. Choi * ksz8081, ksz8091, 217ab59dc1SDavid J. Choi * ksz8061, 227ab59dc1SDavid J. Choi * Switch : ksz8873, ksz886x 23d0507009SDavid J. Choi */ 24d0507009SDavid J. Choi 25d0507009SDavid J. Choi #include <linux/kernel.h> 26d0507009SDavid J. Choi #include <linux/module.h> 27d0507009SDavid J. Choi #include <linux/phy.h> 28d606ef3fSBaruch Siach #include <linux/micrel_phy.h> 29954c3967SSean Cross #include <linux/of.h> 301fadee0cSSascha Hauer #include <linux/clk.h> 31d0507009SDavid J. Choi 32212ea99aSMarek Vasut /* Operation Mode Strap Override */ 33212ea99aSMarek Vasut #define MII_KSZPHY_OMSO 0x16 3400aee095SJohan Hovold #define KSZPHY_OMSO_B_CAST_OFF BIT(9) 352b0ba96cSSylvain Rochet #define KSZPHY_OMSO_NAND_TREE_ON BIT(5) 3600aee095SJohan Hovold #define KSZPHY_OMSO_RMII_OVERRIDE BIT(1) 3700aee095SJohan Hovold #define KSZPHY_OMSO_MII_OVERRIDE BIT(0) 38212ea99aSMarek Vasut 3951f932c4SChoi, David /* general Interrupt control/status reg in vendor specific block. */ 4051f932c4SChoi, David #define MII_KSZPHY_INTCS 0x1B 4100aee095SJohan Hovold #define KSZPHY_INTCS_JABBER BIT(15) 4200aee095SJohan Hovold #define KSZPHY_INTCS_RECEIVE_ERR BIT(14) 4300aee095SJohan Hovold #define KSZPHY_INTCS_PAGE_RECEIVE BIT(13) 4400aee095SJohan Hovold #define KSZPHY_INTCS_PARELLEL BIT(12) 4500aee095SJohan Hovold #define KSZPHY_INTCS_LINK_PARTNER_ACK BIT(11) 4600aee095SJohan Hovold #define KSZPHY_INTCS_LINK_DOWN BIT(10) 4700aee095SJohan Hovold #define KSZPHY_INTCS_REMOTE_FAULT BIT(9) 4800aee095SJohan Hovold #define KSZPHY_INTCS_LINK_UP BIT(8) 4951f932c4SChoi, David #define KSZPHY_INTCS_ALL (KSZPHY_INTCS_LINK_UP |\ 5051f932c4SChoi, David KSZPHY_INTCS_LINK_DOWN) 5151f932c4SChoi, David 525a16778eSJohan Hovold /* PHY Control 1 */ 535a16778eSJohan Hovold #define MII_KSZPHY_CTRL_1 0x1e 545a16778eSJohan Hovold 555a16778eSJohan Hovold /* PHY Control 2 / PHY Control (if no PHY Control 1) */ 565a16778eSJohan Hovold #define MII_KSZPHY_CTRL_2 0x1f 575a16778eSJohan Hovold #define MII_KSZPHY_CTRL MII_KSZPHY_CTRL_2 5851f932c4SChoi, David /* bitmap of PHY register to set interrupt mode */ 5900aee095SJohan Hovold #define KSZPHY_CTRL_INT_ACTIVE_HIGH BIT(9) 6063f44b2bSJohan Hovold #define KSZPHY_RMII_REF_CLK_SEL BIT(7) 6151f932c4SChoi, David 62954c3967SSean Cross /* Write/read to/from extended registers */ 63954c3967SSean Cross #define MII_KSZPHY_EXTREG 0x0b 64954c3967SSean Cross #define KSZPHY_EXTREG_WRITE 0x8000 65954c3967SSean Cross 66954c3967SSean Cross #define MII_KSZPHY_EXTREG_WRITE 0x0c 67954c3967SSean Cross #define MII_KSZPHY_EXTREG_READ 0x0d 68954c3967SSean Cross 69954c3967SSean Cross /* Extended registers */ 70954c3967SSean Cross #define MII_KSZPHY_CLK_CONTROL_PAD_SKEW 0x104 71954c3967SSean Cross #define MII_KSZPHY_RX_DATA_PAD_SKEW 0x105 72954c3967SSean Cross #define MII_KSZPHY_TX_DATA_PAD_SKEW 0x106 73954c3967SSean Cross 74954c3967SSean Cross #define PS_TO_REG 200 75954c3967SSean Cross 762b2427d0SAndrew Lunn struct kszphy_hw_stat { 772b2427d0SAndrew Lunn const char *string; 782b2427d0SAndrew Lunn u8 reg; 792b2427d0SAndrew Lunn u8 bits; 802b2427d0SAndrew Lunn }; 812b2427d0SAndrew Lunn 822b2427d0SAndrew Lunn static struct kszphy_hw_stat kszphy_hw_stats[] = { 832b2427d0SAndrew Lunn { "phy_receive_errors", 21, 16}, 842b2427d0SAndrew Lunn { "phy_idle_errors", 10, 8 }, 852b2427d0SAndrew Lunn }; 862b2427d0SAndrew Lunn 87e6a423a8SJohan Hovold struct kszphy_type { 88e6a423a8SJohan Hovold u32 led_mode_reg; 89c6f9575cSJohan Hovold u16 interrupt_level_mask; 900f95903eSJohan Hovold bool has_broadcast_disable; 912b0ba96cSSylvain Rochet bool has_nand_tree_disable; 9263f44b2bSJohan Hovold bool has_rmii_ref_clk_sel; 93e6a423a8SJohan Hovold }; 94e6a423a8SJohan Hovold 95e6a423a8SJohan Hovold struct kszphy_priv { 96e6a423a8SJohan Hovold const struct kszphy_type *type; 97e7a792e9SJohan Hovold int led_mode; 9863f44b2bSJohan Hovold bool rmii_ref_clk_sel; 9963f44b2bSJohan Hovold bool rmii_ref_clk_sel_val; 1002b2427d0SAndrew Lunn u64 stats[ARRAY_SIZE(kszphy_hw_stats)]; 101e6a423a8SJohan Hovold }; 102e6a423a8SJohan Hovold 103e6a423a8SJohan Hovold static const struct kszphy_type ksz8021_type = { 104e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 105d0e1df9cSJohan Hovold .has_broadcast_disable = true, 1062b0ba96cSSylvain Rochet .has_nand_tree_disable = true, 10763f44b2bSJohan Hovold .has_rmii_ref_clk_sel = true, 108e6a423a8SJohan Hovold }; 109e6a423a8SJohan Hovold 110e6a423a8SJohan Hovold static const struct kszphy_type ksz8041_type = { 111e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_1, 112e6a423a8SJohan Hovold }; 113e6a423a8SJohan Hovold 114e6a423a8SJohan Hovold static const struct kszphy_type ksz8051_type = { 115e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 1162b0ba96cSSylvain Rochet .has_nand_tree_disable = true, 117e6a423a8SJohan Hovold }; 118e6a423a8SJohan Hovold 119e6a423a8SJohan Hovold static const struct kszphy_type ksz8081_type = { 120e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 1210f95903eSJohan Hovold .has_broadcast_disable = true, 1222b0ba96cSSylvain Rochet .has_nand_tree_disable = true, 12386dc1342SJohan Hovold .has_rmii_ref_clk_sel = true, 124e6a423a8SJohan Hovold }; 125e6a423a8SJohan Hovold 126c6f9575cSJohan Hovold static const struct kszphy_type ks8737_type = { 127c6f9575cSJohan Hovold .interrupt_level_mask = BIT(14), 128c6f9575cSJohan Hovold }; 129c6f9575cSJohan Hovold 130c6f9575cSJohan Hovold static const struct kszphy_type ksz9021_type = { 131c6f9575cSJohan Hovold .interrupt_level_mask = BIT(14), 132c6f9575cSJohan Hovold }; 133c6f9575cSJohan Hovold 134954c3967SSean Cross static int kszphy_extended_write(struct phy_device *phydev, 135954c3967SSean Cross u32 regnum, u16 val) 136954c3967SSean Cross { 137954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); 138954c3967SSean Cross return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); 139954c3967SSean Cross } 140954c3967SSean Cross 141954c3967SSean Cross static int kszphy_extended_read(struct phy_device *phydev, 142954c3967SSean Cross u32 regnum) 143954c3967SSean Cross { 144954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, regnum); 145954c3967SSean Cross return phy_read(phydev, MII_KSZPHY_EXTREG_READ); 146954c3967SSean Cross } 147954c3967SSean Cross 14851f932c4SChoi, David static int kszphy_ack_interrupt(struct phy_device *phydev) 14951f932c4SChoi, David { 15051f932c4SChoi, David /* bit[7..0] int status, which is a read and clear register. */ 15151f932c4SChoi, David int rc; 15251f932c4SChoi, David 15351f932c4SChoi, David rc = phy_read(phydev, MII_KSZPHY_INTCS); 15451f932c4SChoi, David 15551f932c4SChoi, David return (rc < 0) ? rc : 0; 15651f932c4SChoi, David } 15751f932c4SChoi, David 15851f932c4SChoi, David static int kszphy_config_intr(struct phy_device *phydev) 15951f932c4SChoi, David { 160c6f9575cSJohan Hovold const struct kszphy_type *type = phydev->drv->driver_data; 161c6f9575cSJohan Hovold int temp; 162c6f9575cSJohan Hovold u16 mask; 163c6f9575cSJohan Hovold 164c6f9575cSJohan Hovold if (type && type->interrupt_level_mask) 165c6f9575cSJohan Hovold mask = type->interrupt_level_mask; 166c6f9575cSJohan Hovold else 167c6f9575cSJohan Hovold mask = KSZPHY_CTRL_INT_ACTIVE_HIGH; 16851f932c4SChoi, David 16951f932c4SChoi, David /* set the interrupt pin active low */ 17051f932c4SChoi, David temp = phy_read(phydev, MII_KSZPHY_CTRL); 1715bb8fc0dSJohan Hovold if (temp < 0) 1725bb8fc0dSJohan Hovold return temp; 173c6f9575cSJohan Hovold temp &= ~mask; 17451f932c4SChoi, David phy_write(phydev, MII_KSZPHY_CTRL, temp); 17551f932c4SChoi, David 176c6f9575cSJohan Hovold /* enable / disable interrupts */ 177c6f9575cSJohan Hovold if (phydev->interrupts == PHY_INTERRUPT_ENABLED) 178c6f9575cSJohan Hovold temp = KSZPHY_INTCS_ALL; 179c6f9575cSJohan Hovold else 180c6f9575cSJohan Hovold temp = 0; 18151f932c4SChoi, David 182c6f9575cSJohan Hovold return phy_write(phydev, MII_KSZPHY_INTCS, temp); 18351f932c4SChoi, David } 184d0507009SDavid J. Choi 18563f44b2bSJohan Hovold static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val) 18663f44b2bSJohan Hovold { 18763f44b2bSJohan Hovold int ctrl; 18863f44b2bSJohan Hovold 18963f44b2bSJohan Hovold ctrl = phy_read(phydev, MII_KSZPHY_CTRL); 19063f44b2bSJohan Hovold if (ctrl < 0) 19163f44b2bSJohan Hovold return ctrl; 19263f44b2bSJohan Hovold 19363f44b2bSJohan Hovold if (val) 19463f44b2bSJohan Hovold ctrl |= KSZPHY_RMII_REF_CLK_SEL; 19563f44b2bSJohan Hovold else 19663f44b2bSJohan Hovold ctrl &= ~KSZPHY_RMII_REF_CLK_SEL; 19763f44b2bSJohan Hovold 19863f44b2bSJohan Hovold return phy_write(phydev, MII_KSZPHY_CTRL, ctrl); 19963f44b2bSJohan Hovold } 20063f44b2bSJohan Hovold 201e7a792e9SJohan Hovold static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val) 20220d8435aSBen Dooks { 2035a16778eSJohan Hovold int rc, temp, shift; 2048620546cSJohan Hovold 2055a16778eSJohan Hovold switch (reg) { 2065a16778eSJohan Hovold case MII_KSZPHY_CTRL_1: 2075a16778eSJohan Hovold shift = 14; 2085a16778eSJohan Hovold break; 2095a16778eSJohan Hovold case MII_KSZPHY_CTRL_2: 2105a16778eSJohan Hovold shift = 4; 2115a16778eSJohan Hovold break; 2125a16778eSJohan Hovold default: 2135a16778eSJohan Hovold return -EINVAL; 2145a16778eSJohan Hovold } 2155a16778eSJohan Hovold 21620d8435aSBen Dooks temp = phy_read(phydev, reg); 217b7035860SJohan Hovold if (temp < 0) { 218b7035860SJohan Hovold rc = temp; 219b7035860SJohan Hovold goto out; 220b7035860SJohan Hovold } 22120d8435aSBen Dooks 22228bdc499SSergei Shtylyov temp &= ~(3 << shift); 22320d8435aSBen Dooks temp |= val << shift; 22420d8435aSBen Dooks rc = phy_write(phydev, reg, temp); 225b7035860SJohan Hovold out: 226b7035860SJohan Hovold if (rc < 0) 22772ba48beSAndrew Lunn phydev_err(phydev, "failed to set led mode\n"); 22820d8435aSBen Dooks 229b7035860SJohan Hovold return rc; 23020d8435aSBen Dooks } 23120d8435aSBen Dooks 232bde15129SJohan Hovold /* Disable PHY address 0 as the broadcast address, so that it can be used as a 233bde15129SJohan Hovold * unique (non-broadcast) address on a shared bus. 234bde15129SJohan Hovold */ 235bde15129SJohan Hovold static int kszphy_broadcast_disable(struct phy_device *phydev) 236bde15129SJohan Hovold { 237bde15129SJohan Hovold int ret; 238bde15129SJohan Hovold 239bde15129SJohan Hovold ret = phy_read(phydev, MII_KSZPHY_OMSO); 240bde15129SJohan Hovold if (ret < 0) 241bde15129SJohan Hovold goto out; 242bde15129SJohan Hovold 243bde15129SJohan Hovold ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF); 244bde15129SJohan Hovold out: 245bde15129SJohan Hovold if (ret) 24672ba48beSAndrew Lunn phydev_err(phydev, "failed to disable broadcast address\n"); 247bde15129SJohan Hovold 248bde15129SJohan Hovold return ret; 249bde15129SJohan Hovold } 250bde15129SJohan Hovold 2512b0ba96cSSylvain Rochet static int kszphy_nand_tree_disable(struct phy_device *phydev) 2522b0ba96cSSylvain Rochet { 2532b0ba96cSSylvain Rochet int ret; 2542b0ba96cSSylvain Rochet 2552b0ba96cSSylvain Rochet ret = phy_read(phydev, MII_KSZPHY_OMSO); 2562b0ba96cSSylvain Rochet if (ret < 0) 2572b0ba96cSSylvain Rochet goto out; 2582b0ba96cSSylvain Rochet 2592b0ba96cSSylvain Rochet if (!(ret & KSZPHY_OMSO_NAND_TREE_ON)) 2602b0ba96cSSylvain Rochet return 0; 2612b0ba96cSSylvain Rochet 2622b0ba96cSSylvain Rochet ret = phy_write(phydev, MII_KSZPHY_OMSO, 2632b0ba96cSSylvain Rochet ret & ~KSZPHY_OMSO_NAND_TREE_ON); 2642b0ba96cSSylvain Rochet out: 2652b0ba96cSSylvain Rochet if (ret) 26672ba48beSAndrew Lunn phydev_err(phydev, "failed to disable NAND tree mode\n"); 2672b0ba96cSSylvain Rochet 2682b0ba96cSSylvain Rochet return ret; 2692b0ba96cSSylvain Rochet } 2702b0ba96cSSylvain Rochet 271d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev) 272d0507009SDavid J. Choi { 273e6a423a8SJohan Hovold struct kszphy_priv *priv = phydev->priv; 274e6a423a8SJohan Hovold const struct kszphy_type *type; 27563f44b2bSJohan Hovold int ret; 276d0507009SDavid J. Choi 277e6a423a8SJohan Hovold if (!priv) 278e6a423a8SJohan Hovold return 0; 279e6a423a8SJohan Hovold 280e6a423a8SJohan Hovold type = priv->type; 281e6a423a8SJohan Hovold 2820f95903eSJohan Hovold if (type->has_broadcast_disable) 2830f95903eSJohan Hovold kszphy_broadcast_disable(phydev); 2840f95903eSJohan Hovold 2852b0ba96cSSylvain Rochet if (type->has_nand_tree_disable) 2862b0ba96cSSylvain Rochet kszphy_nand_tree_disable(phydev); 2872b0ba96cSSylvain Rochet 28863f44b2bSJohan Hovold if (priv->rmii_ref_clk_sel) { 28963f44b2bSJohan Hovold ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val); 29063f44b2bSJohan Hovold if (ret) { 29172ba48beSAndrew Lunn phydev_err(phydev, 29272ba48beSAndrew Lunn "failed to set rmii reference clock\n"); 29363f44b2bSJohan Hovold return ret; 29463f44b2bSJohan Hovold } 29563f44b2bSJohan Hovold } 29663f44b2bSJohan Hovold 297e7a792e9SJohan Hovold if (priv->led_mode >= 0) 298e7a792e9SJohan Hovold kszphy_setup_led(phydev, type->led_mode_reg, priv->led_mode); 299e6a423a8SJohan Hovold 300e6a423a8SJohan Hovold return 0; 30120d8435aSBen Dooks } 30220d8435aSBen Dooks 303954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev, 3043c9a9f7fSJaeden Amero const struct device_node *of_node, 3053c9a9f7fSJaeden Amero u16 reg, 3063c9a9f7fSJaeden Amero const char *field1, const char *field2, 3073c9a9f7fSJaeden Amero const char *field3, const char *field4) 308954c3967SSean Cross { 309954c3967SSean Cross int val1 = -1; 310954c3967SSean Cross int val2 = -2; 311954c3967SSean Cross int val3 = -3; 312954c3967SSean Cross int val4 = -4; 313954c3967SSean Cross int newval; 314954c3967SSean Cross int matches = 0; 315954c3967SSean Cross 316954c3967SSean Cross if (!of_property_read_u32(of_node, field1, &val1)) 317954c3967SSean Cross matches++; 318954c3967SSean Cross 319954c3967SSean Cross if (!of_property_read_u32(of_node, field2, &val2)) 320954c3967SSean Cross matches++; 321954c3967SSean Cross 322954c3967SSean Cross if (!of_property_read_u32(of_node, field3, &val3)) 323954c3967SSean Cross matches++; 324954c3967SSean Cross 325954c3967SSean Cross if (!of_property_read_u32(of_node, field4, &val4)) 326954c3967SSean Cross matches++; 327954c3967SSean Cross 328954c3967SSean Cross if (!matches) 329954c3967SSean Cross return 0; 330954c3967SSean Cross 331954c3967SSean Cross if (matches < 4) 332954c3967SSean Cross newval = kszphy_extended_read(phydev, reg); 333954c3967SSean Cross else 334954c3967SSean Cross newval = 0; 335954c3967SSean Cross 336954c3967SSean Cross if (val1 != -1) 337954c3967SSean Cross newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0); 338954c3967SSean Cross 3396a119745SHubert Chaumette if (val2 != -2) 340954c3967SSean Cross newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4); 341954c3967SSean Cross 3426a119745SHubert Chaumette if (val3 != -3) 343954c3967SSean Cross newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8); 344954c3967SSean Cross 3456a119745SHubert Chaumette if (val4 != -4) 346954c3967SSean Cross newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12); 347954c3967SSean Cross 348954c3967SSean Cross return kszphy_extended_write(phydev, reg, newval); 349954c3967SSean Cross } 350954c3967SSean Cross 351954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev) 352954c3967SSean Cross { 353e5a03bfdSAndrew Lunn const struct device *dev = &phydev->mdio.dev; 3543c9a9f7fSJaeden Amero const struct device_node *of_node = dev->of_node; 355651df218SAndrew Lunn const struct device *dev_walker; 356954c3967SSean Cross 357651df218SAndrew Lunn /* The Micrel driver has a deprecated option to place phy OF 358651df218SAndrew Lunn * properties in the MAC node. Walk up the tree of devices to 359651df218SAndrew Lunn * find a device with an OF node. 360651df218SAndrew Lunn */ 361e5a03bfdSAndrew Lunn dev_walker = &phydev->mdio.dev; 362651df218SAndrew Lunn do { 363651df218SAndrew Lunn of_node = dev_walker->of_node; 364651df218SAndrew Lunn dev_walker = dev_walker->parent; 365651df218SAndrew Lunn 366651df218SAndrew Lunn } while (!of_node && dev_walker); 367954c3967SSean Cross 368954c3967SSean Cross if (of_node) { 369954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 370954c3967SSean Cross MII_KSZPHY_CLK_CONTROL_PAD_SKEW, 371954c3967SSean Cross "txen-skew-ps", "txc-skew-ps", 372954c3967SSean Cross "rxdv-skew-ps", "rxc-skew-ps"); 373954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 374954c3967SSean Cross MII_KSZPHY_RX_DATA_PAD_SKEW, 375954c3967SSean Cross "rxd0-skew-ps", "rxd1-skew-ps", 376954c3967SSean Cross "rxd2-skew-ps", "rxd3-skew-ps"); 377954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 378954c3967SSean Cross MII_KSZPHY_TX_DATA_PAD_SKEW, 379954c3967SSean Cross "txd0-skew-ps", "txd1-skew-ps", 380954c3967SSean Cross "txd2-skew-ps", "txd3-skew-ps"); 381954c3967SSean Cross } 382954c3967SSean Cross return 0; 383954c3967SSean Cross } 384954c3967SSean Cross 3856e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG 0x0d 3866e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG 0x0e 3876e4b8273SHubert Chaumette #define OP_DATA 1 3886e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG 60 3896e4b8273SHubert Chaumette 3906e4b8273SHubert Chaumette /* Extended registers */ 3916270e1aeSJaeden Amero /* MMD Address 0x0 */ 3926270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_LO 3 3936270e1aeSJaeden Amero #define MII_KSZ9031RN_FLP_BURST_TX_HI 4 3946270e1aeSJaeden Amero 395ae6c97bbSJaeden Amero /* MMD Address 0x2 */ 3966e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW 4 3976e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW 5 3986e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW 6 3996e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW 8 4006e4b8273SHubert Chaumette 4016e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev, 4026e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum, u16 val) 4036e4b8273SHubert Chaumette { 4046e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 4056e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 4066e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 4076e4b8273SHubert Chaumette return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val); 4086e4b8273SHubert Chaumette } 4096e4b8273SHubert Chaumette 4106e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev, 4116e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum) 4126e4b8273SHubert Chaumette { 4136e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 4146e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 4156e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 4166e4b8273SHubert Chaumette return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG); 4176e4b8273SHubert Chaumette } 4186e4b8273SHubert Chaumette 4196e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev, 4203c9a9f7fSJaeden Amero const struct device_node *of_node, 4216e4b8273SHubert Chaumette u16 reg, size_t field_sz, 4223c9a9f7fSJaeden Amero const char *field[], u8 numfields) 4236e4b8273SHubert Chaumette { 4246e4b8273SHubert Chaumette int val[4] = {-1, -2, -3, -4}; 4256e4b8273SHubert Chaumette int matches = 0; 4266e4b8273SHubert Chaumette u16 mask; 4276e4b8273SHubert Chaumette u16 maxval; 4286e4b8273SHubert Chaumette u16 newval; 4296e4b8273SHubert Chaumette int i; 4306e4b8273SHubert Chaumette 4316e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 4326e4b8273SHubert Chaumette if (!of_property_read_u32(of_node, field[i], val + i)) 4336e4b8273SHubert Chaumette matches++; 4346e4b8273SHubert Chaumette 4356e4b8273SHubert Chaumette if (!matches) 4366e4b8273SHubert Chaumette return 0; 4376e4b8273SHubert Chaumette 4386e4b8273SHubert Chaumette if (matches < numfields) 4396e4b8273SHubert Chaumette newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg); 4406e4b8273SHubert Chaumette else 4416e4b8273SHubert Chaumette newval = 0; 4426e4b8273SHubert Chaumette 4436e4b8273SHubert Chaumette maxval = (field_sz == 4) ? 0xf : 0x1f; 4446e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 4456e4b8273SHubert Chaumette if (val[i] != -(i + 1)) { 4466e4b8273SHubert Chaumette mask = 0xffff; 4476e4b8273SHubert Chaumette mask ^= maxval << (field_sz * i); 4486e4b8273SHubert Chaumette newval = (newval & mask) | 4496e4b8273SHubert Chaumette (((val[i] / KSZ9031_PS_TO_REG) & maxval) 4506e4b8273SHubert Chaumette << (field_sz * i)); 4516e4b8273SHubert Chaumette } 4526e4b8273SHubert Chaumette 4536e4b8273SHubert Chaumette return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval); 4546e4b8273SHubert Chaumette } 4556e4b8273SHubert Chaumette 4566270e1aeSJaeden Amero static int ksz9031_center_flp_timing(struct phy_device *phydev) 4576270e1aeSJaeden Amero { 4586270e1aeSJaeden Amero int result; 4596270e1aeSJaeden Amero 4606270e1aeSJaeden Amero /* Center KSZ9031RNX FLP timing at 16ms. */ 4616270e1aeSJaeden Amero result = ksz9031_extended_write(phydev, OP_DATA, 0, 4626270e1aeSJaeden Amero MII_KSZ9031RN_FLP_BURST_TX_HI, 0x0006); 4636270e1aeSJaeden Amero result = ksz9031_extended_write(phydev, OP_DATA, 0, 4646270e1aeSJaeden Amero MII_KSZ9031RN_FLP_BURST_TX_LO, 0x1A80); 4656270e1aeSJaeden Amero 4666270e1aeSJaeden Amero if (result) 4676270e1aeSJaeden Amero return result; 4686270e1aeSJaeden Amero 4696270e1aeSJaeden Amero return genphy_restart_aneg(phydev); 4706270e1aeSJaeden Amero } 4716270e1aeSJaeden Amero 4726e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev) 4736e4b8273SHubert Chaumette { 474e5a03bfdSAndrew Lunn const struct device *dev = &phydev->mdio.dev; 4753c9a9f7fSJaeden Amero const struct device_node *of_node = dev->of_node; 4763c9a9f7fSJaeden Amero static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"}; 4773c9a9f7fSJaeden Amero static const char *rx_data_skews[4] = { 4786e4b8273SHubert Chaumette "rxd0-skew-ps", "rxd1-skew-ps", 4796e4b8273SHubert Chaumette "rxd2-skew-ps", "rxd3-skew-ps" 4806e4b8273SHubert Chaumette }; 4813c9a9f7fSJaeden Amero static const char *tx_data_skews[4] = { 4826e4b8273SHubert Chaumette "txd0-skew-ps", "txd1-skew-ps", 4836e4b8273SHubert Chaumette "txd2-skew-ps", "txd3-skew-ps" 4846e4b8273SHubert Chaumette }; 4853c9a9f7fSJaeden Amero static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"}; 486b4c19f71SRoosen Henri const struct device *dev_walker; 4876e4b8273SHubert Chaumette 488b4c19f71SRoosen Henri /* The Micrel driver has a deprecated option to place phy OF 489b4c19f71SRoosen Henri * properties in the MAC node. Walk up the tree of devices to 490b4c19f71SRoosen Henri * find a device with an OF node. 491b4c19f71SRoosen Henri */ 4929d367eddSDavid S. Miller dev_walker = &phydev->mdio.dev; 493b4c19f71SRoosen Henri do { 494b4c19f71SRoosen Henri of_node = dev_walker->of_node; 495b4c19f71SRoosen Henri dev_walker = dev_walker->parent; 496b4c19f71SRoosen Henri } while (!of_node && dev_walker); 4976e4b8273SHubert Chaumette 4986e4b8273SHubert Chaumette if (of_node) { 4996e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 5006e4b8273SHubert Chaumette MII_KSZ9031RN_CLK_PAD_SKEW, 5, 5016e4b8273SHubert Chaumette clk_skews, 2); 5026e4b8273SHubert Chaumette 5036e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 5046e4b8273SHubert Chaumette MII_KSZ9031RN_CONTROL_PAD_SKEW, 4, 5056e4b8273SHubert Chaumette control_skews, 2); 5066e4b8273SHubert Chaumette 5076e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 5086e4b8273SHubert Chaumette MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4, 5096e4b8273SHubert Chaumette rx_data_skews, 4); 5106e4b8273SHubert Chaumette 5116e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 5126e4b8273SHubert Chaumette MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 5136e4b8273SHubert Chaumette tx_data_skews, 4); 5146e4b8273SHubert Chaumette } 5156270e1aeSJaeden Amero 5166270e1aeSJaeden Amero return ksz9031_center_flp_timing(phydev); 5176e4b8273SHubert Chaumette } 5186e4b8273SHubert Chaumette 51993272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 52000aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX BIT(6) 52100aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED BIT(4) 52232d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev) 52393272e07SJean-Christophe PLAGNIOL-VILLARD { 52493272e07SJean-Christophe PLAGNIOL-VILLARD int regval; 52593272e07SJean-Christophe PLAGNIOL-VILLARD 52693272e07SJean-Christophe PLAGNIOL-VILLARD /* dummy read */ 52793272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 52893272e07SJean-Christophe PLAGNIOL-VILLARD 52993272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 53093272e07SJean-Christophe PLAGNIOL-VILLARD 53193272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX) 53293272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_HALF; 53393272e07SJean-Christophe PLAGNIOL-VILLARD else 53493272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_FULL; 53593272e07SJean-Christophe PLAGNIOL-VILLARD 53693272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED) 53793272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_10; 53893272e07SJean-Christophe PLAGNIOL-VILLARD else 53993272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_100; 54093272e07SJean-Christophe PLAGNIOL-VILLARD 54193272e07SJean-Christophe PLAGNIOL-VILLARD phydev->link = 1; 54293272e07SJean-Christophe PLAGNIOL-VILLARD phydev->pause = phydev->asym_pause = 0; 54393272e07SJean-Christophe PLAGNIOL-VILLARD 54493272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 54593272e07SJean-Christophe PLAGNIOL-VILLARD } 54693272e07SJean-Christophe PLAGNIOL-VILLARD 547d2fd719bSNathan Sullivan static int ksz9031_read_status(struct phy_device *phydev) 548d2fd719bSNathan Sullivan { 549d2fd719bSNathan Sullivan int err; 550d2fd719bSNathan Sullivan int regval; 551d2fd719bSNathan Sullivan 552d2fd719bSNathan Sullivan err = genphy_read_status(phydev); 553d2fd719bSNathan Sullivan if (err) 554d2fd719bSNathan Sullivan return err; 555d2fd719bSNathan Sullivan 556d2fd719bSNathan Sullivan /* Make sure the PHY is not broken. Read idle error count, 557d2fd719bSNathan Sullivan * and reset the PHY if it is maxed out. 558d2fd719bSNathan Sullivan */ 559d2fd719bSNathan Sullivan regval = phy_read(phydev, MII_STAT1000); 560d2fd719bSNathan Sullivan if ((regval & 0xFF) == 0xFF) { 561d2fd719bSNathan Sullivan phy_init_hw(phydev); 562d2fd719bSNathan Sullivan phydev->link = 0; 563d2fd719bSNathan Sullivan } 564d2fd719bSNathan Sullivan 565d2fd719bSNathan Sullivan return 0; 566d2fd719bSNathan Sullivan } 567d2fd719bSNathan Sullivan 56893272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev) 56993272e07SJean-Christophe PLAGNIOL-VILLARD { 57093272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 57193272e07SJean-Christophe PLAGNIOL-VILLARD } 57293272e07SJean-Christophe PLAGNIOL-VILLARD 57319936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the 57419936942SVince Bridgers * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE 57519936942SVince Bridgers * MMD extended PHY registers. 57619936942SVince Bridgers */ 57719936942SVince Bridgers static int 57819936942SVince Bridgers ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 57919936942SVince Bridgers int regnum) 58019936942SVince Bridgers { 58119936942SVince Bridgers return -1; 58219936942SVince Bridgers } 58319936942SVince Bridgers 58419936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support 58519936942SVince Bridgers * standard IEEE MMD extended PHY registers. 58619936942SVince Bridgers */ 58719936942SVince Bridgers static void 58819936942SVince Bridgers ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 58919936942SVince Bridgers int regnum, u32 val) 59019936942SVince Bridgers { 59119936942SVince Bridgers } 59219936942SVince Bridgers 5932b2427d0SAndrew Lunn static int kszphy_get_sset_count(struct phy_device *phydev) 5942b2427d0SAndrew Lunn { 5952b2427d0SAndrew Lunn return ARRAY_SIZE(kszphy_hw_stats); 5962b2427d0SAndrew Lunn } 5972b2427d0SAndrew Lunn 5982b2427d0SAndrew Lunn static void kszphy_get_strings(struct phy_device *phydev, u8 *data) 5992b2427d0SAndrew Lunn { 6002b2427d0SAndrew Lunn int i; 6012b2427d0SAndrew Lunn 6022b2427d0SAndrew Lunn for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) { 6032b2427d0SAndrew Lunn memcpy(data + i * ETH_GSTRING_LEN, 6042b2427d0SAndrew Lunn kszphy_hw_stats[i].string, ETH_GSTRING_LEN); 6052b2427d0SAndrew Lunn } 6062b2427d0SAndrew Lunn } 6072b2427d0SAndrew Lunn 6082b2427d0SAndrew Lunn #ifndef UINT64_MAX 6092b2427d0SAndrew Lunn #define UINT64_MAX (u64)(~((u64)0)) 6102b2427d0SAndrew Lunn #endif 6112b2427d0SAndrew Lunn static u64 kszphy_get_stat(struct phy_device *phydev, int i) 6122b2427d0SAndrew Lunn { 6132b2427d0SAndrew Lunn struct kszphy_hw_stat stat = kszphy_hw_stats[i]; 6142b2427d0SAndrew Lunn struct kszphy_priv *priv = phydev->priv; 615*321b4d4bSAndrew Lunn int val; 616*321b4d4bSAndrew Lunn u64 ret; 6172b2427d0SAndrew Lunn 6182b2427d0SAndrew Lunn val = phy_read(phydev, stat.reg); 6192b2427d0SAndrew Lunn if (val < 0) { 620*321b4d4bSAndrew Lunn ret = UINT64_MAX; 6212b2427d0SAndrew Lunn } else { 6222b2427d0SAndrew Lunn val = val & ((1 << stat.bits) - 1); 6232b2427d0SAndrew Lunn priv->stats[i] += val; 624*321b4d4bSAndrew Lunn ret = priv->stats[i]; 6252b2427d0SAndrew Lunn } 6262b2427d0SAndrew Lunn 627*321b4d4bSAndrew Lunn return ret; 6282b2427d0SAndrew Lunn } 6292b2427d0SAndrew Lunn 6302b2427d0SAndrew Lunn static void kszphy_get_stats(struct phy_device *phydev, 6312b2427d0SAndrew Lunn struct ethtool_stats *stats, u64 *data) 6322b2427d0SAndrew Lunn { 6332b2427d0SAndrew Lunn int i; 6342b2427d0SAndrew Lunn 6352b2427d0SAndrew Lunn for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) 6362b2427d0SAndrew Lunn data[i] = kszphy_get_stat(phydev, i); 6372b2427d0SAndrew Lunn } 6382b2427d0SAndrew Lunn 639e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev) 640e6a423a8SJohan Hovold { 641e6a423a8SJohan Hovold const struct kszphy_type *type = phydev->drv->driver_data; 642e5a03bfdSAndrew Lunn const struct device_node *np = phydev->mdio.dev.of_node; 643e6a423a8SJohan Hovold struct kszphy_priv *priv; 64463f44b2bSJohan Hovold struct clk *clk; 645e7a792e9SJohan Hovold int ret; 646e6a423a8SJohan Hovold 647e5a03bfdSAndrew Lunn priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); 648e6a423a8SJohan Hovold if (!priv) 649e6a423a8SJohan Hovold return -ENOMEM; 650e6a423a8SJohan Hovold 651e6a423a8SJohan Hovold phydev->priv = priv; 652e6a423a8SJohan Hovold 653e6a423a8SJohan Hovold priv->type = type; 654e6a423a8SJohan Hovold 655e7a792e9SJohan Hovold if (type->led_mode_reg) { 656e7a792e9SJohan Hovold ret = of_property_read_u32(np, "micrel,led-mode", 657e7a792e9SJohan Hovold &priv->led_mode); 658e7a792e9SJohan Hovold if (ret) 659e7a792e9SJohan Hovold priv->led_mode = -1; 660e7a792e9SJohan Hovold 661e7a792e9SJohan Hovold if (priv->led_mode > 3) { 66272ba48beSAndrew Lunn phydev_err(phydev, "invalid led mode: 0x%02x\n", 663e7a792e9SJohan Hovold priv->led_mode); 664e7a792e9SJohan Hovold priv->led_mode = -1; 665e7a792e9SJohan Hovold } 666e7a792e9SJohan Hovold } else { 667e7a792e9SJohan Hovold priv->led_mode = -1; 668e7a792e9SJohan Hovold } 669e7a792e9SJohan Hovold 670e5a03bfdSAndrew Lunn clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref"); 671bced8701SNiklas Cassel /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */ 672bced8701SNiklas Cassel if (!IS_ERR_OR_NULL(clk)) { 6731fadee0cSSascha Hauer unsigned long rate = clk_get_rate(clk); 67486dc1342SJohan Hovold bool rmii_ref_clk_sel_25_mhz; 6751fadee0cSSascha Hauer 67663f44b2bSJohan Hovold priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; 67786dc1342SJohan Hovold rmii_ref_clk_sel_25_mhz = of_property_read_bool(np, 67886dc1342SJohan Hovold "micrel,rmii-reference-clock-select-25-mhz"); 67963f44b2bSJohan Hovold 6801fadee0cSSascha Hauer if (rate > 24500000 && rate < 25500000) { 68186dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz; 6821fadee0cSSascha Hauer } else if (rate > 49500000 && rate < 50500000) { 68386dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz; 6841fadee0cSSascha Hauer } else { 68572ba48beSAndrew Lunn phydev_err(phydev, "Clock rate out of range: %ld\n", 68672ba48beSAndrew Lunn rate); 6871fadee0cSSascha Hauer return -EINVAL; 6881fadee0cSSascha Hauer } 6891fadee0cSSascha Hauer } 6901fadee0cSSascha Hauer 69163f44b2bSJohan Hovold /* Support legacy board-file configuration */ 69263f44b2bSJohan Hovold if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) { 69363f44b2bSJohan Hovold priv->rmii_ref_clk_sel = true; 69463f44b2bSJohan Hovold priv->rmii_ref_clk_sel_val = true; 69563f44b2bSJohan Hovold } 69663f44b2bSJohan Hovold 69763f44b2bSJohan Hovold return 0; 6981fadee0cSSascha Hauer } 6991fadee0cSSascha Hauer 700d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = { 701d5bf9071SChristian Hohnstaedt { 70251f932c4SChoi, David .phy_id = PHY_ID_KS8737, 703d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 70451f932c4SChoi, David .name = "Micrel KS8737", 70551f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 70651f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 707c6f9575cSJohan Hovold .driver_data = &ks8737_type, 708d0507009SDavid J. Choi .config_init = kszphy_config_init, 709d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 710d0507009SDavid J. Choi .read_status = genphy_read_status, 71151f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 712c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 7132b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 7142b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 7152b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 7161a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7171a5465f5SPatrice Vilchez .resume = genphy_resume, 718d5bf9071SChristian Hohnstaedt }, { 719212ea99aSMarek Vasut .phy_id = PHY_ID_KSZ8021, 720212ea99aSMarek Vasut .phy_id_mask = 0x00ffffff, 7217ab59dc1SDavid J. Choi .name = "Micrel KSZ8021 or KSZ8031", 722212ea99aSMarek Vasut .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 723212ea99aSMarek Vasut SUPPORTED_Asym_Pause), 724212ea99aSMarek Vasut .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 725e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 72663f44b2bSJohan Hovold .probe = kszphy_probe, 727d0e1df9cSJohan Hovold .config_init = kszphy_config_init, 728212ea99aSMarek Vasut .config_aneg = genphy_config_aneg, 729212ea99aSMarek Vasut .read_status = genphy_read_status, 730212ea99aSMarek Vasut .ack_interrupt = kszphy_ack_interrupt, 731212ea99aSMarek Vasut .config_intr = kszphy_config_intr, 7322b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 7332b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 7342b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 7351a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7361a5465f5SPatrice Vilchez .resume = genphy_resume, 737212ea99aSMarek Vasut }, { 738b818d1a7SHector Palacios .phy_id = PHY_ID_KSZ8031, 739b818d1a7SHector Palacios .phy_id_mask = 0x00ffffff, 740b818d1a7SHector Palacios .name = "Micrel KSZ8031", 741b818d1a7SHector Palacios .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 742b818d1a7SHector Palacios SUPPORTED_Asym_Pause), 743b818d1a7SHector Palacios .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 744e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 74563f44b2bSJohan Hovold .probe = kszphy_probe, 746d0e1df9cSJohan Hovold .config_init = kszphy_config_init, 747b818d1a7SHector Palacios .config_aneg = genphy_config_aneg, 748b818d1a7SHector Palacios .read_status = genphy_read_status, 749b818d1a7SHector Palacios .ack_interrupt = kszphy_ack_interrupt, 750b818d1a7SHector Palacios .config_intr = kszphy_config_intr, 7512b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 7522b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 7532b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 7541a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7551a5465f5SPatrice Vilchez .resume = genphy_resume, 756b818d1a7SHector Palacios }, { 757510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8041, 758d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 759510d573fSMarek Vasut .name = "Micrel KSZ8041", 76051f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 76151f932c4SChoi, David | SUPPORTED_Asym_Pause), 76251f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 763e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 764e6a423a8SJohan Hovold .probe = kszphy_probe, 765e6a423a8SJohan Hovold .config_init = kszphy_config_init, 766d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 767d0507009SDavid J. Choi .read_status = genphy_read_status, 76851f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 76951f932c4SChoi, David .config_intr = kszphy_config_intr, 7702b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 7712b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 7722b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 7731a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7741a5465f5SPatrice Vilchez .resume = genphy_resume, 775d5bf9071SChristian Hohnstaedt }, { 7764bd7b512SSergei Shtylyov .phy_id = PHY_ID_KSZ8041RNLI, 7774bd7b512SSergei Shtylyov .phy_id_mask = 0x00fffff0, 7784bd7b512SSergei Shtylyov .name = "Micrel KSZ8041RNLI", 7794bd7b512SSergei Shtylyov .features = PHY_BASIC_FEATURES | 7804bd7b512SSergei Shtylyov SUPPORTED_Pause | SUPPORTED_Asym_Pause, 7814bd7b512SSergei Shtylyov .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 782e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 783e6a423a8SJohan Hovold .probe = kszphy_probe, 784e6a423a8SJohan Hovold .config_init = kszphy_config_init, 7854bd7b512SSergei Shtylyov .config_aneg = genphy_config_aneg, 7864bd7b512SSergei Shtylyov .read_status = genphy_read_status, 7874bd7b512SSergei Shtylyov .ack_interrupt = kszphy_ack_interrupt, 7884bd7b512SSergei Shtylyov .config_intr = kszphy_config_intr, 7892b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 7902b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 7912b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 7924bd7b512SSergei Shtylyov .suspend = genphy_suspend, 7934bd7b512SSergei Shtylyov .resume = genphy_resume, 7944bd7b512SSergei Shtylyov }, { 795510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8051, 79651f932c4SChoi, David .phy_id_mask = 0x00fffff0, 797510d573fSMarek Vasut .name = "Micrel KSZ8051", 79851f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 79951f932c4SChoi, David | SUPPORTED_Asym_Pause), 80051f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 801e6a423a8SJohan Hovold .driver_data = &ksz8051_type, 802e6a423a8SJohan Hovold .probe = kszphy_probe, 80363f44b2bSJohan Hovold .config_init = kszphy_config_init, 80451f932c4SChoi, David .config_aneg = genphy_config_aneg, 80551f932c4SChoi, David .read_status = genphy_read_status, 80651f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 80751f932c4SChoi, David .config_intr = kszphy_config_intr, 8082b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8092b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8102b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8111a5465f5SPatrice Vilchez .suspend = genphy_suspend, 8121a5465f5SPatrice Vilchez .resume = genphy_resume, 813d5bf9071SChristian Hohnstaedt }, { 814510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8001, 815510d573fSMarek Vasut .name = "Micrel KSZ8001 or KS8721", 81648d7d0adSJason Wang .phy_id_mask = 0x00ffffff, 81751f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 81851f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 819e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 820e6a423a8SJohan Hovold .probe = kszphy_probe, 821e6a423a8SJohan Hovold .config_init = kszphy_config_init, 82251f932c4SChoi, David .config_aneg = genphy_config_aneg, 82351f932c4SChoi, David .read_status = genphy_read_status, 82451f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 82551f932c4SChoi, David .config_intr = kszphy_config_intr, 8262b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8272b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8282b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8291a5465f5SPatrice Vilchez .suspend = genphy_suspend, 8301a5465f5SPatrice Vilchez .resume = genphy_resume, 831d5bf9071SChristian Hohnstaedt }, { 8327ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8081, 8337ab59dc1SDavid J. Choi .name = "Micrel KSZ8081 or KSZ8091", 8347ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 8357ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 8367ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 837e6a423a8SJohan Hovold .driver_data = &ksz8081_type, 838e6a423a8SJohan Hovold .probe = kszphy_probe, 8390f95903eSJohan Hovold .config_init = kszphy_config_init, 8407ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 8417ab59dc1SDavid J. Choi .read_status = genphy_read_status, 8427ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 8437ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 8442b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8452b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8462b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8471a5465f5SPatrice Vilchez .suspend = genphy_suspend, 8481a5465f5SPatrice Vilchez .resume = genphy_resume, 8497ab59dc1SDavid J. Choi }, { 8507ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8061, 8517ab59dc1SDavid J. Choi .name = "Micrel KSZ8061", 8527ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 8537ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 8547ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 8557ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 8567ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 8577ab59dc1SDavid J. Choi .read_status = genphy_read_status, 8587ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 8597ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 8602b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8612b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8622b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8631a5465f5SPatrice Vilchez .suspend = genphy_suspend, 8641a5465f5SPatrice Vilchez .resume = genphy_resume, 8657ab59dc1SDavid J. Choi }, { 866d0507009SDavid J. Choi .phy_id = PHY_ID_KSZ9021, 86748d7d0adSJason Wang .phy_id_mask = 0x000ffffe, 868d0507009SDavid J. Choi .name = "Micrel KSZ9021 Gigabit PHY", 86932fcafbcSVlastimil Kosar .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 87051f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 871c6f9575cSJohan Hovold .driver_data = &ksz9021_type, 872954c3967SSean Cross .config_init = ksz9021_config_init, 873d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 874d0507009SDavid J. Choi .read_status = genphy_read_status, 87551f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 876c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 8772b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8782b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8792b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8801a5465f5SPatrice Vilchez .suspend = genphy_suspend, 8811a5465f5SPatrice Vilchez .resume = genphy_resume, 88219936942SVince Bridgers .read_mmd_indirect = ksz9021_rd_mmd_phyreg, 88319936942SVince Bridgers .write_mmd_indirect = ksz9021_wr_mmd_phyreg, 88493272e07SJean-Christophe PLAGNIOL-VILLARD }, { 8857ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ9031, 8867ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 8877ab59dc1SDavid J. Choi .name = "Micrel KSZ9031 Gigabit PHY", 88895e8b103SMike Looijmans .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 8897ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 890c6f9575cSJohan Hovold .driver_data = &ksz9021_type, 8916e4b8273SHubert Chaumette .config_init = ksz9031_config_init, 8927ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 893d2fd719bSNathan Sullivan .read_status = ksz9031_read_status, 8947ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 895c6f9575cSJohan Hovold .config_intr = kszphy_config_intr, 8962b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 8972b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 8982b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 8991a5465f5SPatrice Vilchez .suspend = genphy_suspend, 9001a5465f5SPatrice Vilchez .resume = genphy_resume, 9017ab59dc1SDavid J. Choi }, { 90293272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id = PHY_ID_KSZ8873MLL, 90393272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id_mask = 0x00fffff0, 90493272e07SJean-Christophe PLAGNIOL-VILLARD .name = "Micrel KSZ8873MLL Switch", 90593272e07SJean-Christophe PLAGNIOL-VILLARD .features = (SUPPORTED_Pause | SUPPORTED_Asym_Pause), 90693272e07SJean-Christophe PLAGNIOL-VILLARD .flags = PHY_HAS_MAGICANEG, 90793272e07SJean-Christophe PLAGNIOL-VILLARD .config_init = kszphy_config_init, 90893272e07SJean-Christophe PLAGNIOL-VILLARD .config_aneg = ksz8873mll_config_aneg, 90993272e07SJean-Christophe PLAGNIOL-VILLARD .read_status = ksz8873mll_read_status, 9102b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 9112b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 9122b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 9131a5465f5SPatrice Vilchez .suspend = genphy_suspend, 9141a5465f5SPatrice Vilchez .resume = genphy_resume, 9157ab59dc1SDavid J. Choi }, { 9167ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ886X, 9177ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 9187ab59dc1SDavid J. Choi .name = "Micrel KSZ886X Switch", 9197ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 9207ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 9217ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 9227ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 9237ab59dc1SDavid J. Choi .read_status = genphy_read_status, 9242b2427d0SAndrew Lunn .get_sset_count = kszphy_get_sset_count, 9252b2427d0SAndrew Lunn .get_strings = kszphy_get_strings, 9262b2427d0SAndrew Lunn .get_stats = kszphy_get_stats, 9271a5465f5SPatrice Vilchez .suspend = genphy_suspend, 9281a5465f5SPatrice Vilchez .resume = genphy_resume, 929d5bf9071SChristian Hohnstaedt } }; 930d0507009SDavid J. Choi 93150fd7150SJohan Hovold module_phy_driver(ksphy_driver); 932d0507009SDavid J. Choi 933d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver"); 934d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi"); 935d0507009SDavid J. Choi MODULE_LICENSE("GPL"); 93652a60ed2SDavid S. Miller 937cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = { 93848d7d0adSJason Wang { PHY_ID_KSZ9021, 0x000ffffe }, 9397ab59dc1SDavid J. Choi { PHY_ID_KSZ9031, 0x00fffff0 }, 940510d573fSMarek Vasut { PHY_ID_KSZ8001, 0x00ffffff }, 94151f932c4SChoi, David { PHY_ID_KS8737, 0x00fffff0 }, 942212ea99aSMarek Vasut { PHY_ID_KSZ8021, 0x00ffffff }, 943b818d1a7SHector Palacios { PHY_ID_KSZ8031, 0x00ffffff }, 944510d573fSMarek Vasut { PHY_ID_KSZ8041, 0x00fffff0 }, 945510d573fSMarek Vasut { PHY_ID_KSZ8051, 0x00fffff0 }, 9467ab59dc1SDavid J. Choi { PHY_ID_KSZ8061, 0x00fffff0 }, 9477ab59dc1SDavid J. Choi { PHY_ID_KSZ8081, 0x00fffff0 }, 94893272e07SJean-Christophe PLAGNIOL-VILLARD { PHY_ID_KSZ8873MLL, 0x00fffff0 }, 9497ab59dc1SDavid J. Choi { PHY_ID_KSZ886X, 0x00fffff0 }, 95052a60ed2SDavid S. Miller { } 95152a60ed2SDavid S. Miller }; 95252a60ed2SDavid S. Miller 95352a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl); 954