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) 5800aee095SJohan Hovold #define KSZ9021_CTRL_INT_ACTIVE_HIGH BIT(14) 5900aee095SJohan Hovold #define KS8737_CTRL_INT_ACTIVE_HIGH BIT(14) 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 76e6a423a8SJohan Hovold struct kszphy_type { 77e6a423a8SJohan Hovold u32 led_mode_reg; 780f95903eSJohan Hovold bool has_broadcast_disable; 7963f44b2bSJohan Hovold bool has_rmii_ref_clk_sel; 80e6a423a8SJohan Hovold }; 81e6a423a8SJohan Hovold 82e6a423a8SJohan Hovold struct kszphy_priv { 83e6a423a8SJohan Hovold const struct kszphy_type *type; 84e7a792e9SJohan Hovold int led_mode; 8563f44b2bSJohan Hovold bool rmii_ref_clk_sel; 8663f44b2bSJohan Hovold bool rmii_ref_clk_sel_val; 87e6a423a8SJohan Hovold }; 88e6a423a8SJohan Hovold 89e6a423a8SJohan Hovold static const struct kszphy_type ksz8021_type = { 90e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 9163f44b2bSJohan Hovold .has_rmii_ref_clk_sel = true, 92e6a423a8SJohan Hovold }; 93e6a423a8SJohan Hovold 94e6a423a8SJohan Hovold static const struct kszphy_type ksz8041_type = { 95e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_1, 96e6a423a8SJohan Hovold }; 97e6a423a8SJohan Hovold 98e6a423a8SJohan Hovold static const struct kszphy_type ksz8051_type = { 99e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 100e6a423a8SJohan Hovold }; 101e6a423a8SJohan Hovold 102e6a423a8SJohan Hovold static const struct kszphy_type ksz8081_type = { 103e6a423a8SJohan Hovold .led_mode_reg = MII_KSZPHY_CTRL_2, 1040f95903eSJohan Hovold .has_broadcast_disable = true, 105*86dc1342SJohan Hovold .has_rmii_ref_clk_sel = true, 106e6a423a8SJohan Hovold }; 107e6a423a8SJohan Hovold 108954c3967SSean Cross static int kszphy_extended_write(struct phy_device *phydev, 109954c3967SSean Cross u32 regnum, u16 val) 110954c3967SSean Cross { 111954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); 112954c3967SSean Cross return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); 113954c3967SSean Cross } 114954c3967SSean Cross 115954c3967SSean Cross static int kszphy_extended_read(struct phy_device *phydev, 116954c3967SSean Cross u32 regnum) 117954c3967SSean Cross { 118954c3967SSean Cross phy_write(phydev, MII_KSZPHY_EXTREG, regnum); 119954c3967SSean Cross return phy_read(phydev, MII_KSZPHY_EXTREG_READ); 120954c3967SSean Cross } 121954c3967SSean Cross 12251f932c4SChoi, David static int kszphy_ack_interrupt(struct phy_device *phydev) 12351f932c4SChoi, David { 12451f932c4SChoi, David /* bit[7..0] int status, which is a read and clear register. */ 12551f932c4SChoi, David int rc; 12651f932c4SChoi, David 12751f932c4SChoi, David rc = phy_read(phydev, MII_KSZPHY_INTCS); 12851f932c4SChoi, David 12951f932c4SChoi, David return (rc < 0) ? rc : 0; 13051f932c4SChoi, David } 13151f932c4SChoi, David 13251f932c4SChoi, David static int kszphy_set_interrupt(struct phy_device *phydev) 13351f932c4SChoi, David { 13451f932c4SChoi, David int temp; 13551f932c4SChoi, David temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ? 13651f932c4SChoi, David KSZPHY_INTCS_ALL : 0; 13751f932c4SChoi, David return phy_write(phydev, MII_KSZPHY_INTCS, temp); 13851f932c4SChoi, David } 13951f932c4SChoi, David 14051f932c4SChoi, David static int kszphy_config_intr(struct phy_device *phydev) 14151f932c4SChoi, David { 14251f932c4SChoi, David int temp, rc; 14351f932c4SChoi, David 14451f932c4SChoi, David /* set the interrupt pin active low */ 14551f932c4SChoi, David temp = phy_read(phydev, MII_KSZPHY_CTRL); 1465bb8fc0dSJohan Hovold if (temp < 0) 1475bb8fc0dSJohan Hovold return temp; 14851f932c4SChoi, David temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH; 14951f932c4SChoi, David phy_write(phydev, MII_KSZPHY_CTRL, temp); 15051f932c4SChoi, David rc = kszphy_set_interrupt(phydev); 15151f932c4SChoi, David return rc < 0 ? rc : 0; 15251f932c4SChoi, David } 15351f932c4SChoi, David 15451f932c4SChoi, David static int ksz9021_config_intr(struct phy_device *phydev) 15551f932c4SChoi, David { 15651f932c4SChoi, David int temp, rc; 15751f932c4SChoi, David 15851f932c4SChoi, David /* set the interrupt pin active low */ 15951f932c4SChoi, David temp = phy_read(phydev, MII_KSZPHY_CTRL); 1605bb8fc0dSJohan Hovold if (temp < 0) 1615bb8fc0dSJohan Hovold return temp; 16251f932c4SChoi, David temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH; 16351f932c4SChoi, David phy_write(phydev, MII_KSZPHY_CTRL, temp); 16451f932c4SChoi, David rc = kszphy_set_interrupt(phydev); 16551f932c4SChoi, David return rc < 0 ? rc : 0; 16651f932c4SChoi, David } 16751f932c4SChoi, David 16851f932c4SChoi, David static int ks8737_config_intr(struct phy_device *phydev) 16951f932c4SChoi, David { 17051f932c4SChoi, David int temp, rc; 17151f932c4SChoi, David 17251f932c4SChoi, David /* set the interrupt pin active low */ 17351f932c4SChoi, David temp = phy_read(phydev, MII_KSZPHY_CTRL); 1745bb8fc0dSJohan Hovold if (temp < 0) 1755bb8fc0dSJohan Hovold return temp; 17651f932c4SChoi, David temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH; 17751f932c4SChoi, David phy_write(phydev, MII_KSZPHY_CTRL, temp); 17851f932c4SChoi, David rc = kszphy_set_interrupt(phydev); 17951f932c4SChoi, David return rc < 0 ? rc : 0; 18051f932c4SChoi, David } 181d0507009SDavid J. Choi 18263f44b2bSJohan Hovold static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val) 18363f44b2bSJohan Hovold { 18463f44b2bSJohan Hovold int ctrl; 18563f44b2bSJohan Hovold 18663f44b2bSJohan Hovold ctrl = phy_read(phydev, MII_KSZPHY_CTRL); 18763f44b2bSJohan Hovold if (ctrl < 0) 18863f44b2bSJohan Hovold return ctrl; 18963f44b2bSJohan Hovold 19063f44b2bSJohan Hovold if (val) 19163f44b2bSJohan Hovold ctrl |= KSZPHY_RMII_REF_CLK_SEL; 19263f44b2bSJohan Hovold else 19363f44b2bSJohan Hovold ctrl &= ~KSZPHY_RMII_REF_CLK_SEL; 19463f44b2bSJohan Hovold 19563f44b2bSJohan Hovold return phy_write(phydev, MII_KSZPHY_CTRL, ctrl); 19663f44b2bSJohan Hovold } 19763f44b2bSJohan Hovold 198e7a792e9SJohan Hovold static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val) 19920d8435aSBen Dooks { 2005a16778eSJohan Hovold int rc, temp, shift; 2018620546cSJohan Hovold 2025a16778eSJohan Hovold switch (reg) { 2035a16778eSJohan Hovold case MII_KSZPHY_CTRL_1: 2045a16778eSJohan Hovold shift = 14; 2055a16778eSJohan Hovold break; 2065a16778eSJohan Hovold case MII_KSZPHY_CTRL_2: 2075a16778eSJohan Hovold shift = 4; 2085a16778eSJohan Hovold break; 2095a16778eSJohan Hovold default: 2105a16778eSJohan Hovold return -EINVAL; 2115a16778eSJohan Hovold } 2125a16778eSJohan Hovold 21320d8435aSBen Dooks temp = phy_read(phydev, reg); 214b7035860SJohan Hovold if (temp < 0) { 215b7035860SJohan Hovold rc = temp; 216b7035860SJohan Hovold goto out; 217b7035860SJohan Hovold } 21820d8435aSBen Dooks 21928bdc499SSergei Shtylyov temp &= ~(3 << shift); 22020d8435aSBen Dooks temp |= val << shift; 22120d8435aSBen Dooks rc = phy_write(phydev, reg, temp); 222b7035860SJohan Hovold out: 223b7035860SJohan Hovold if (rc < 0) 224b7035860SJohan Hovold dev_err(&phydev->dev, "failed to set led mode\n"); 22520d8435aSBen Dooks 226b7035860SJohan Hovold return rc; 22720d8435aSBen Dooks } 22820d8435aSBen Dooks 229bde15129SJohan Hovold /* Disable PHY address 0 as the broadcast address, so that it can be used as a 230bde15129SJohan Hovold * unique (non-broadcast) address on a shared bus. 231bde15129SJohan Hovold */ 232bde15129SJohan Hovold static int kszphy_broadcast_disable(struct phy_device *phydev) 233bde15129SJohan Hovold { 234bde15129SJohan Hovold int ret; 235bde15129SJohan Hovold 236bde15129SJohan Hovold ret = phy_read(phydev, MII_KSZPHY_OMSO); 237bde15129SJohan Hovold if (ret < 0) 238bde15129SJohan Hovold goto out; 239bde15129SJohan Hovold 240bde15129SJohan Hovold ret = phy_write(phydev, MII_KSZPHY_OMSO, ret | KSZPHY_OMSO_B_CAST_OFF); 241bde15129SJohan Hovold out: 242bde15129SJohan Hovold if (ret) 243bde15129SJohan Hovold dev_err(&phydev->dev, "failed to disable broadcast address\n"); 244bde15129SJohan Hovold 245bde15129SJohan Hovold return ret; 246bde15129SJohan Hovold } 247bde15129SJohan Hovold 248d0507009SDavid J. Choi static int kszphy_config_init(struct phy_device *phydev) 249d0507009SDavid J. Choi { 250e6a423a8SJohan Hovold struct kszphy_priv *priv = phydev->priv; 251e6a423a8SJohan Hovold const struct kszphy_type *type; 25263f44b2bSJohan Hovold int ret; 253d0507009SDavid J. Choi 254e6a423a8SJohan Hovold if (!priv) 255e6a423a8SJohan Hovold return 0; 256e6a423a8SJohan Hovold 257e6a423a8SJohan Hovold type = priv->type; 258e6a423a8SJohan Hovold 2590f95903eSJohan Hovold if (type->has_broadcast_disable) 2600f95903eSJohan Hovold kszphy_broadcast_disable(phydev); 2610f95903eSJohan Hovold 26263f44b2bSJohan Hovold if (priv->rmii_ref_clk_sel) { 26363f44b2bSJohan Hovold ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val); 26463f44b2bSJohan Hovold if (ret) { 26563f44b2bSJohan Hovold dev_err(&phydev->dev, "failed to set rmii reference clock\n"); 26663f44b2bSJohan Hovold return ret; 26763f44b2bSJohan Hovold } 26863f44b2bSJohan Hovold } 26963f44b2bSJohan Hovold 270e7a792e9SJohan Hovold if (priv->led_mode >= 0) 271e7a792e9SJohan Hovold kszphy_setup_led(phydev, type->led_mode_reg, priv->led_mode); 272e6a423a8SJohan Hovold 273e6a423a8SJohan Hovold return 0; 27420d8435aSBen Dooks } 27520d8435aSBen Dooks 276212ea99aSMarek Vasut static int ksz8021_config_init(struct phy_device *phydev) 277212ea99aSMarek Vasut { 27820d8435aSBen Dooks int rc; 27920d8435aSBen Dooks 28063f44b2bSJohan Hovold rc = kszphy_config_init(phydev); 28163f44b2bSJohan Hovold if (rc) 282b838b4acSBruno Thomsen return rc; 283bde15129SJohan Hovold 284bde15129SJohan Hovold rc = kszphy_broadcast_disable(phydev); 285bde15129SJohan Hovold 286b6bb4dfcSHector Palacios return rc < 0 ? rc : 0; 287212ea99aSMarek Vasut } 288212ea99aSMarek Vasut 289954c3967SSean Cross static int ksz9021_load_values_from_of(struct phy_device *phydev, 290954c3967SSean Cross struct device_node *of_node, u16 reg, 291954c3967SSean Cross char *field1, char *field2, 292954c3967SSean Cross char *field3, char *field4) 293954c3967SSean Cross { 294954c3967SSean Cross int val1 = -1; 295954c3967SSean Cross int val2 = -2; 296954c3967SSean Cross int val3 = -3; 297954c3967SSean Cross int val4 = -4; 298954c3967SSean Cross int newval; 299954c3967SSean Cross int matches = 0; 300954c3967SSean Cross 301954c3967SSean Cross if (!of_property_read_u32(of_node, field1, &val1)) 302954c3967SSean Cross matches++; 303954c3967SSean Cross 304954c3967SSean Cross if (!of_property_read_u32(of_node, field2, &val2)) 305954c3967SSean Cross matches++; 306954c3967SSean Cross 307954c3967SSean Cross if (!of_property_read_u32(of_node, field3, &val3)) 308954c3967SSean Cross matches++; 309954c3967SSean Cross 310954c3967SSean Cross if (!of_property_read_u32(of_node, field4, &val4)) 311954c3967SSean Cross matches++; 312954c3967SSean Cross 313954c3967SSean Cross if (!matches) 314954c3967SSean Cross return 0; 315954c3967SSean Cross 316954c3967SSean Cross if (matches < 4) 317954c3967SSean Cross newval = kszphy_extended_read(phydev, reg); 318954c3967SSean Cross else 319954c3967SSean Cross newval = 0; 320954c3967SSean Cross 321954c3967SSean Cross if (val1 != -1) 322954c3967SSean Cross newval = ((newval & 0xfff0) | ((val1 / PS_TO_REG) & 0xf) << 0); 323954c3967SSean Cross 3246a119745SHubert Chaumette if (val2 != -2) 325954c3967SSean Cross newval = ((newval & 0xff0f) | ((val2 / PS_TO_REG) & 0xf) << 4); 326954c3967SSean Cross 3276a119745SHubert Chaumette if (val3 != -3) 328954c3967SSean Cross newval = ((newval & 0xf0ff) | ((val3 / PS_TO_REG) & 0xf) << 8); 329954c3967SSean Cross 3306a119745SHubert Chaumette if (val4 != -4) 331954c3967SSean Cross newval = ((newval & 0x0fff) | ((val4 / PS_TO_REG) & 0xf) << 12); 332954c3967SSean Cross 333954c3967SSean Cross return kszphy_extended_write(phydev, reg, newval); 334954c3967SSean Cross } 335954c3967SSean Cross 336954c3967SSean Cross static int ksz9021_config_init(struct phy_device *phydev) 337954c3967SSean Cross { 338954c3967SSean Cross struct device *dev = &phydev->dev; 339954c3967SSean Cross struct device_node *of_node = dev->of_node; 340954c3967SSean Cross 341954c3967SSean Cross if (!of_node && dev->parent->of_node) 342954c3967SSean Cross of_node = dev->parent->of_node; 343954c3967SSean Cross 344954c3967SSean Cross if (of_node) { 345954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 346954c3967SSean Cross MII_KSZPHY_CLK_CONTROL_PAD_SKEW, 347954c3967SSean Cross "txen-skew-ps", "txc-skew-ps", 348954c3967SSean Cross "rxdv-skew-ps", "rxc-skew-ps"); 349954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 350954c3967SSean Cross MII_KSZPHY_RX_DATA_PAD_SKEW, 351954c3967SSean Cross "rxd0-skew-ps", "rxd1-skew-ps", 352954c3967SSean Cross "rxd2-skew-ps", "rxd3-skew-ps"); 353954c3967SSean Cross ksz9021_load_values_from_of(phydev, of_node, 354954c3967SSean Cross MII_KSZPHY_TX_DATA_PAD_SKEW, 355954c3967SSean Cross "txd0-skew-ps", "txd1-skew-ps", 356954c3967SSean Cross "txd2-skew-ps", "txd3-skew-ps"); 357954c3967SSean Cross } 358954c3967SSean Cross return 0; 359954c3967SSean Cross } 360954c3967SSean Cross 3616e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_CTRL_REG 0x0d 3626e4b8273SHubert Chaumette #define MII_KSZ9031RN_MMD_REGDATA_REG 0x0e 3636e4b8273SHubert Chaumette #define OP_DATA 1 3646e4b8273SHubert Chaumette #define KSZ9031_PS_TO_REG 60 3656e4b8273SHubert Chaumette 3666e4b8273SHubert Chaumette /* Extended registers */ 3676e4b8273SHubert Chaumette #define MII_KSZ9031RN_CONTROL_PAD_SKEW 4 3686e4b8273SHubert Chaumette #define MII_KSZ9031RN_RX_DATA_PAD_SKEW 5 3696e4b8273SHubert Chaumette #define MII_KSZ9031RN_TX_DATA_PAD_SKEW 6 3706e4b8273SHubert Chaumette #define MII_KSZ9031RN_CLK_PAD_SKEW 8 3716e4b8273SHubert Chaumette 3726e4b8273SHubert Chaumette static int ksz9031_extended_write(struct phy_device *phydev, 3736e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum, u16 val) 3746e4b8273SHubert Chaumette { 3756e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 3766e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 3776e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 3786e4b8273SHubert Chaumette return phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, val); 3796e4b8273SHubert Chaumette } 3806e4b8273SHubert Chaumette 3816e4b8273SHubert Chaumette static int ksz9031_extended_read(struct phy_device *phydev, 3826e4b8273SHubert Chaumette u8 mode, u32 dev_addr, u32 regnum) 3836e4b8273SHubert Chaumette { 3846e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, dev_addr); 3856e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_REGDATA_REG, regnum); 3866e4b8273SHubert Chaumette phy_write(phydev, MII_KSZ9031RN_MMD_CTRL_REG, (mode << 14) | dev_addr); 3876e4b8273SHubert Chaumette return phy_read(phydev, MII_KSZ9031RN_MMD_REGDATA_REG); 3886e4b8273SHubert Chaumette } 3896e4b8273SHubert Chaumette 3906e4b8273SHubert Chaumette static int ksz9031_of_load_skew_values(struct phy_device *phydev, 3916e4b8273SHubert Chaumette struct device_node *of_node, 3926e4b8273SHubert Chaumette u16 reg, size_t field_sz, 3936e4b8273SHubert Chaumette char *field[], u8 numfields) 3946e4b8273SHubert Chaumette { 3956e4b8273SHubert Chaumette int val[4] = {-1, -2, -3, -4}; 3966e4b8273SHubert Chaumette int matches = 0; 3976e4b8273SHubert Chaumette u16 mask; 3986e4b8273SHubert Chaumette u16 maxval; 3996e4b8273SHubert Chaumette u16 newval; 4006e4b8273SHubert Chaumette int i; 4016e4b8273SHubert Chaumette 4026e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 4036e4b8273SHubert Chaumette if (!of_property_read_u32(of_node, field[i], val + i)) 4046e4b8273SHubert Chaumette matches++; 4056e4b8273SHubert Chaumette 4066e4b8273SHubert Chaumette if (!matches) 4076e4b8273SHubert Chaumette return 0; 4086e4b8273SHubert Chaumette 4096e4b8273SHubert Chaumette if (matches < numfields) 4106e4b8273SHubert Chaumette newval = ksz9031_extended_read(phydev, OP_DATA, 2, reg); 4116e4b8273SHubert Chaumette else 4126e4b8273SHubert Chaumette newval = 0; 4136e4b8273SHubert Chaumette 4146e4b8273SHubert Chaumette maxval = (field_sz == 4) ? 0xf : 0x1f; 4156e4b8273SHubert Chaumette for (i = 0; i < numfields; i++) 4166e4b8273SHubert Chaumette if (val[i] != -(i + 1)) { 4176e4b8273SHubert Chaumette mask = 0xffff; 4186e4b8273SHubert Chaumette mask ^= maxval << (field_sz * i); 4196e4b8273SHubert Chaumette newval = (newval & mask) | 4206e4b8273SHubert Chaumette (((val[i] / KSZ9031_PS_TO_REG) & maxval) 4216e4b8273SHubert Chaumette << (field_sz * i)); 4226e4b8273SHubert Chaumette } 4236e4b8273SHubert Chaumette 4246e4b8273SHubert Chaumette return ksz9031_extended_write(phydev, OP_DATA, 2, reg, newval); 4256e4b8273SHubert Chaumette } 4266e4b8273SHubert Chaumette 4276e4b8273SHubert Chaumette static int ksz9031_config_init(struct phy_device *phydev) 4286e4b8273SHubert Chaumette { 4296e4b8273SHubert Chaumette struct device *dev = &phydev->dev; 4306e4b8273SHubert Chaumette struct device_node *of_node = dev->of_node; 4316e4b8273SHubert Chaumette char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"}; 4326e4b8273SHubert Chaumette char *rx_data_skews[4] = { 4336e4b8273SHubert Chaumette "rxd0-skew-ps", "rxd1-skew-ps", 4346e4b8273SHubert Chaumette "rxd2-skew-ps", "rxd3-skew-ps" 4356e4b8273SHubert Chaumette }; 4366e4b8273SHubert Chaumette char *tx_data_skews[4] = { 4376e4b8273SHubert Chaumette "txd0-skew-ps", "txd1-skew-ps", 4386e4b8273SHubert Chaumette "txd2-skew-ps", "txd3-skew-ps" 4396e4b8273SHubert Chaumette }; 4406e4b8273SHubert Chaumette char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"}; 4416e4b8273SHubert Chaumette 4426e4b8273SHubert Chaumette if (!of_node && dev->parent->of_node) 4436e4b8273SHubert Chaumette of_node = dev->parent->of_node; 4446e4b8273SHubert Chaumette 4456e4b8273SHubert Chaumette if (of_node) { 4466e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4476e4b8273SHubert Chaumette MII_KSZ9031RN_CLK_PAD_SKEW, 5, 4486e4b8273SHubert Chaumette clk_skews, 2); 4496e4b8273SHubert Chaumette 4506e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4516e4b8273SHubert Chaumette MII_KSZ9031RN_CONTROL_PAD_SKEW, 4, 4526e4b8273SHubert Chaumette control_skews, 2); 4536e4b8273SHubert Chaumette 4546e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4556e4b8273SHubert Chaumette MII_KSZ9031RN_RX_DATA_PAD_SKEW, 4, 4566e4b8273SHubert Chaumette rx_data_skews, 4); 4576e4b8273SHubert Chaumette 4586e4b8273SHubert Chaumette ksz9031_of_load_skew_values(phydev, of_node, 4596e4b8273SHubert Chaumette MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, 4606e4b8273SHubert Chaumette tx_data_skews, 4); 4616e4b8273SHubert Chaumette } 4626e4b8273SHubert Chaumette return 0; 4636e4b8273SHubert Chaumette } 4646e4b8273SHubert Chaumette 46593272e07SJean-Christophe PLAGNIOL-VILLARD #define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 46600aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX BIT(6) 46700aee095SJohan Hovold #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED BIT(4) 46832d73b14SJingoo Han static int ksz8873mll_read_status(struct phy_device *phydev) 46993272e07SJean-Christophe PLAGNIOL-VILLARD { 47093272e07SJean-Christophe PLAGNIOL-VILLARD int regval; 47193272e07SJean-Christophe PLAGNIOL-VILLARD 47293272e07SJean-Christophe PLAGNIOL-VILLARD /* dummy read */ 47393272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 47493272e07SJean-Christophe PLAGNIOL-VILLARD 47593272e07SJean-Christophe PLAGNIOL-VILLARD regval = phy_read(phydev, KSZ8873MLL_GLOBAL_CONTROL_4); 47693272e07SJean-Christophe PLAGNIOL-VILLARD 47793272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX) 47893272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_HALF; 47993272e07SJean-Christophe PLAGNIOL-VILLARD else 48093272e07SJean-Christophe PLAGNIOL-VILLARD phydev->duplex = DUPLEX_FULL; 48193272e07SJean-Christophe PLAGNIOL-VILLARD 48293272e07SJean-Christophe PLAGNIOL-VILLARD if (regval & KSZ8873MLL_GLOBAL_CONTROL_4_SPEED) 48393272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_10; 48493272e07SJean-Christophe PLAGNIOL-VILLARD else 48593272e07SJean-Christophe PLAGNIOL-VILLARD phydev->speed = SPEED_100; 48693272e07SJean-Christophe PLAGNIOL-VILLARD 48793272e07SJean-Christophe PLAGNIOL-VILLARD phydev->link = 1; 48893272e07SJean-Christophe PLAGNIOL-VILLARD phydev->pause = phydev->asym_pause = 0; 48993272e07SJean-Christophe PLAGNIOL-VILLARD 49093272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 49193272e07SJean-Christophe PLAGNIOL-VILLARD } 49293272e07SJean-Christophe PLAGNIOL-VILLARD 49393272e07SJean-Christophe PLAGNIOL-VILLARD static int ksz8873mll_config_aneg(struct phy_device *phydev) 49493272e07SJean-Christophe PLAGNIOL-VILLARD { 49593272e07SJean-Christophe PLAGNIOL-VILLARD return 0; 49693272e07SJean-Christophe PLAGNIOL-VILLARD } 49793272e07SJean-Christophe PLAGNIOL-VILLARD 49819936942SVince Bridgers /* This routine returns -1 as an indication to the caller that the 49919936942SVince Bridgers * Micrel ksz9021 10/100/1000 PHY does not support standard IEEE 50019936942SVince Bridgers * MMD extended PHY registers. 50119936942SVince Bridgers */ 50219936942SVince Bridgers static int 50319936942SVince Bridgers ksz9021_rd_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 50419936942SVince Bridgers int regnum) 50519936942SVince Bridgers { 50619936942SVince Bridgers return -1; 50719936942SVince Bridgers } 50819936942SVince Bridgers 50919936942SVince Bridgers /* This routine does nothing since the Micrel ksz9021 does not support 51019936942SVince Bridgers * standard IEEE MMD extended PHY registers. 51119936942SVince Bridgers */ 51219936942SVince Bridgers static void 51319936942SVince Bridgers ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, 51419936942SVince Bridgers int regnum, u32 val) 51519936942SVince Bridgers { 51619936942SVince Bridgers } 51719936942SVince Bridgers 518e6a423a8SJohan Hovold static int kszphy_probe(struct phy_device *phydev) 519e6a423a8SJohan Hovold { 520e6a423a8SJohan Hovold const struct kszphy_type *type = phydev->drv->driver_data; 521e7a792e9SJohan Hovold struct device_node *np = phydev->dev.of_node; 522e6a423a8SJohan Hovold struct kszphy_priv *priv; 52363f44b2bSJohan Hovold struct clk *clk; 524e7a792e9SJohan Hovold int ret; 525e6a423a8SJohan Hovold 526e6a423a8SJohan Hovold priv = devm_kzalloc(&phydev->dev, sizeof(*priv), GFP_KERNEL); 527e6a423a8SJohan Hovold if (!priv) 528e6a423a8SJohan Hovold return -ENOMEM; 529e6a423a8SJohan Hovold 530e6a423a8SJohan Hovold phydev->priv = priv; 531e6a423a8SJohan Hovold 532e6a423a8SJohan Hovold priv->type = type; 533e6a423a8SJohan Hovold 534e7a792e9SJohan Hovold if (type->led_mode_reg) { 535e7a792e9SJohan Hovold ret = of_property_read_u32(np, "micrel,led-mode", 536e7a792e9SJohan Hovold &priv->led_mode); 537e7a792e9SJohan Hovold if (ret) 538e7a792e9SJohan Hovold priv->led_mode = -1; 539e7a792e9SJohan Hovold 540e7a792e9SJohan Hovold if (priv->led_mode > 3) { 541e7a792e9SJohan Hovold dev_err(&phydev->dev, "invalid led mode: 0x%02x\n", 542e7a792e9SJohan Hovold priv->led_mode); 543e7a792e9SJohan Hovold priv->led_mode = -1; 544e7a792e9SJohan Hovold } 545e7a792e9SJohan Hovold } else { 546e7a792e9SJohan Hovold priv->led_mode = -1; 547e7a792e9SJohan Hovold } 548e7a792e9SJohan Hovold 5491fadee0cSSascha Hauer clk = devm_clk_get(&phydev->dev, "rmii-ref"); 5501fadee0cSSascha Hauer if (!IS_ERR(clk)) { 5511fadee0cSSascha Hauer unsigned long rate = clk_get_rate(clk); 552*86dc1342SJohan Hovold bool rmii_ref_clk_sel_25_mhz; 5531fadee0cSSascha Hauer 55463f44b2bSJohan Hovold priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; 555*86dc1342SJohan Hovold rmii_ref_clk_sel_25_mhz = of_property_read_bool(np, 556*86dc1342SJohan Hovold "micrel,rmii-reference-clock-select-25-mhz"); 55763f44b2bSJohan Hovold 5581fadee0cSSascha Hauer if (rate > 24500000 && rate < 25500000) { 559*86dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz; 5601fadee0cSSascha Hauer } else if (rate > 49500000 && rate < 50500000) { 561*86dc1342SJohan Hovold priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz; 5621fadee0cSSascha Hauer } else { 5631fadee0cSSascha Hauer dev_err(&phydev->dev, "Clock rate out of range: %ld\n", rate); 5641fadee0cSSascha Hauer return -EINVAL; 5651fadee0cSSascha Hauer } 5661fadee0cSSascha Hauer } 5671fadee0cSSascha Hauer 56863f44b2bSJohan Hovold /* Support legacy board-file configuration */ 56963f44b2bSJohan Hovold if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) { 57063f44b2bSJohan Hovold priv->rmii_ref_clk_sel = true; 57163f44b2bSJohan Hovold priv->rmii_ref_clk_sel_val = true; 57263f44b2bSJohan Hovold } 57363f44b2bSJohan Hovold 57463f44b2bSJohan Hovold return 0; 5751fadee0cSSascha Hauer } 5761fadee0cSSascha Hauer 577d5bf9071SChristian Hohnstaedt static struct phy_driver ksphy_driver[] = { 578d5bf9071SChristian Hohnstaedt { 57951f932c4SChoi, David .phy_id = PHY_ID_KS8737, 580d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 58151f932c4SChoi, David .name = "Micrel KS8737", 58251f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 58351f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 584d0507009SDavid J. Choi .config_init = kszphy_config_init, 585d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 586d0507009SDavid J. Choi .read_status = genphy_read_status, 58751f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 58851f932c4SChoi, David .config_intr = ks8737_config_intr, 5891a5465f5SPatrice Vilchez .suspend = genphy_suspend, 5901a5465f5SPatrice Vilchez .resume = genphy_resume, 591d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 592d5bf9071SChristian Hohnstaedt }, { 593212ea99aSMarek Vasut .phy_id = PHY_ID_KSZ8021, 594212ea99aSMarek Vasut .phy_id_mask = 0x00ffffff, 5957ab59dc1SDavid J. Choi .name = "Micrel KSZ8021 or KSZ8031", 596212ea99aSMarek Vasut .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 597212ea99aSMarek Vasut SUPPORTED_Asym_Pause), 598212ea99aSMarek Vasut .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 599e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 60063f44b2bSJohan Hovold .probe = kszphy_probe, 601212ea99aSMarek Vasut .config_init = ksz8021_config_init, 602212ea99aSMarek Vasut .config_aneg = genphy_config_aneg, 603212ea99aSMarek Vasut .read_status = genphy_read_status, 604212ea99aSMarek Vasut .ack_interrupt = kszphy_ack_interrupt, 605212ea99aSMarek Vasut .config_intr = kszphy_config_intr, 6061a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6071a5465f5SPatrice Vilchez .resume = genphy_resume, 608212ea99aSMarek Vasut .driver = { .owner = THIS_MODULE,}, 609212ea99aSMarek Vasut }, { 610b818d1a7SHector Palacios .phy_id = PHY_ID_KSZ8031, 611b818d1a7SHector Palacios .phy_id_mask = 0x00ffffff, 612b818d1a7SHector Palacios .name = "Micrel KSZ8031", 613b818d1a7SHector Palacios .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause | 614b818d1a7SHector Palacios SUPPORTED_Asym_Pause), 615b818d1a7SHector Palacios .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 616e6a423a8SJohan Hovold .driver_data = &ksz8021_type, 61763f44b2bSJohan Hovold .probe = kszphy_probe, 618b818d1a7SHector Palacios .config_init = ksz8021_config_init, 619b818d1a7SHector Palacios .config_aneg = genphy_config_aneg, 620b818d1a7SHector Palacios .read_status = genphy_read_status, 621b818d1a7SHector Palacios .ack_interrupt = kszphy_ack_interrupt, 622b818d1a7SHector Palacios .config_intr = kszphy_config_intr, 6231a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6241a5465f5SPatrice Vilchez .resume = genphy_resume, 625b818d1a7SHector Palacios .driver = { .owner = THIS_MODULE,}, 626b818d1a7SHector Palacios }, { 627510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8041, 628d0507009SDavid J. Choi .phy_id_mask = 0x00fffff0, 629510d573fSMarek Vasut .name = "Micrel KSZ8041", 63051f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 63151f932c4SChoi, David | SUPPORTED_Asym_Pause), 63251f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 633e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 634e6a423a8SJohan Hovold .probe = kszphy_probe, 635e6a423a8SJohan Hovold .config_init = kszphy_config_init, 636d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 637d0507009SDavid J. Choi .read_status = genphy_read_status, 63851f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 63951f932c4SChoi, David .config_intr = kszphy_config_intr, 6401a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6411a5465f5SPatrice Vilchez .resume = genphy_resume, 64251f932c4SChoi, David .driver = { .owner = THIS_MODULE,}, 643d5bf9071SChristian Hohnstaedt }, { 6444bd7b512SSergei Shtylyov .phy_id = PHY_ID_KSZ8041RNLI, 6454bd7b512SSergei Shtylyov .phy_id_mask = 0x00fffff0, 6464bd7b512SSergei Shtylyov .name = "Micrel KSZ8041RNLI", 6474bd7b512SSergei Shtylyov .features = PHY_BASIC_FEATURES | 6484bd7b512SSergei Shtylyov SUPPORTED_Pause | SUPPORTED_Asym_Pause, 6494bd7b512SSergei Shtylyov .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 650e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 651e6a423a8SJohan Hovold .probe = kszphy_probe, 652e6a423a8SJohan Hovold .config_init = kszphy_config_init, 6534bd7b512SSergei Shtylyov .config_aneg = genphy_config_aneg, 6544bd7b512SSergei Shtylyov .read_status = genphy_read_status, 6554bd7b512SSergei Shtylyov .ack_interrupt = kszphy_ack_interrupt, 6564bd7b512SSergei Shtylyov .config_intr = kszphy_config_intr, 6574bd7b512SSergei Shtylyov .suspend = genphy_suspend, 6584bd7b512SSergei Shtylyov .resume = genphy_resume, 6594bd7b512SSergei Shtylyov .driver = { .owner = THIS_MODULE,}, 6604bd7b512SSergei Shtylyov }, { 661510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8051, 66251f932c4SChoi, David .phy_id_mask = 0x00fffff0, 663510d573fSMarek Vasut .name = "Micrel KSZ8051", 66451f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause 66551f932c4SChoi, David | SUPPORTED_Asym_Pause), 66651f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 667e6a423a8SJohan Hovold .driver_data = &ksz8051_type, 668e6a423a8SJohan Hovold .probe = kszphy_probe, 66963f44b2bSJohan Hovold .config_init = kszphy_config_init, 67051f932c4SChoi, David .config_aneg = genphy_config_aneg, 67151f932c4SChoi, David .read_status = genphy_read_status, 67251f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 67351f932c4SChoi, David .config_intr = kszphy_config_intr, 6741a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6751a5465f5SPatrice Vilchez .resume = genphy_resume, 67651f932c4SChoi, David .driver = { .owner = THIS_MODULE,}, 677d5bf9071SChristian Hohnstaedt }, { 678510d573fSMarek Vasut .phy_id = PHY_ID_KSZ8001, 679510d573fSMarek Vasut .name = "Micrel KSZ8001 or KS8721", 68048d7d0adSJason Wang .phy_id_mask = 0x00ffffff, 68151f932c4SChoi, David .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 68251f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 683e6a423a8SJohan Hovold .driver_data = &ksz8041_type, 684e6a423a8SJohan Hovold .probe = kszphy_probe, 685e6a423a8SJohan Hovold .config_init = kszphy_config_init, 68651f932c4SChoi, David .config_aneg = genphy_config_aneg, 68751f932c4SChoi, David .read_status = genphy_read_status, 68851f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 68951f932c4SChoi, David .config_intr = kszphy_config_intr, 6901a5465f5SPatrice Vilchez .suspend = genphy_suspend, 6911a5465f5SPatrice Vilchez .resume = genphy_resume, 692d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 693d5bf9071SChristian Hohnstaedt }, { 6947ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8081, 6957ab59dc1SDavid J. Choi .name = "Micrel KSZ8081 or KSZ8091", 6967ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 6977ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 6987ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 699e6a423a8SJohan Hovold .driver_data = &ksz8081_type, 700e6a423a8SJohan Hovold .probe = kszphy_probe, 7010f95903eSJohan Hovold .config_init = kszphy_config_init, 7027ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7037ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7047ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 7057ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 7061a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7071a5465f5SPatrice Vilchez .resume = genphy_resume, 7087ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 7097ab59dc1SDavid J. Choi }, { 7107ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ8061, 7117ab59dc1SDavid J. Choi .name = "Micrel KSZ8061", 7127ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 7137ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 7147ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 7157ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 7167ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7177ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7187ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 7197ab59dc1SDavid J. Choi .config_intr = kszphy_config_intr, 7201a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7211a5465f5SPatrice Vilchez .resume = genphy_resume, 7227ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE,}, 7237ab59dc1SDavid J. Choi }, { 724d0507009SDavid J. Choi .phy_id = PHY_ID_KSZ9021, 72548d7d0adSJason Wang .phy_id_mask = 0x000ffffe, 726d0507009SDavid J. Choi .name = "Micrel KSZ9021 Gigabit PHY", 72732fcafbcSVlastimil Kosar .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 72851f932c4SChoi, David .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 729954c3967SSean Cross .config_init = ksz9021_config_init, 730d0507009SDavid J. Choi .config_aneg = genphy_config_aneg, 731d0507009SDavid J. Choi .read_status = genphy_read_status, 73251f932c4SChoi, David .ack_interrupt = kszphy_ack_interrupt, 73351f932c4SChoi, David .config_intr = ksz9021_config_intr, 7341a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7351a5465f5SPatrice Vilchez .resume = genphy_resume, 73619936942SVince Bridgers .read_mmd_indirect = ksz9021_rd_mmd_phyreg, 73719936942SVince Bridgers .write_mmd_indirect = ksz9021_wr_mmd_phyreg, 738d0507009SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 73993272e07SJean-Christophe PLAGNIOL-VILLARD }, { 7407ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ9031, 7417ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 7427ab59dc1SDavid J. Choi .name = "Micrel KSZ9031 Gigabit PHY", 74395e8b103SMike Looijmans .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), 7447ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 7456e4b8273SHubert Chaumette .config_init = ksz9031_config_init, 7467ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7477ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7487ab59dc1SDavid J. Choi .ack_interrupt = kszphy_ack_interrupt, 7497ab59dc1SDavid J. Choi .config_intr = ksz9021_config_intr, 7501a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7511a5465f5SPatrice Vilchez .resume = genphy_resume, 7527ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 7537ab59dc1SDavid J. Choi }, { 75493272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id = PHY_ID_KSZ8873MLL, 75593272e07SJean-Christophe PLAGNIOL-VILLARD .phy_id_mask = 0x00fffff0, 75693272e07SJean-Christophe PLAGNIOL-VILLARD .name = "Micrel KSZ8873MLL Switch", 75793272e07SJean-Christophe PLAGNIOL-VILLARD .features = (SUPPORTED_Pause | SUPPORTED_Asym_Pause), 75893272e07SJean-Christophe PLAGNIOL-VILLARD .flags = PHY_HAS_MAGICANEG, 75993272e07SJean-Christophe PLAGNIOL-VILLARD .config_init = kszphy_config_init, 76093272e07SJean-Christophe PLAGNIOL-VILLARD .config_aneg = ksz8873mll_config_aneg, 76193272e07SJean-Christophe PLAGNIOL-VILLARD .read_status = ksz8873mll_read_status, 7621a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7631a5465f5SPatrice Vilchez .resume = genphy_resume, 76493272e07SJean-Christophe PLAGNIOL-VILLARD .driver = { .owner = THIS_MODULE, }, 7657ab59dc1SDavid J. Choi }, { 7667ab59dc1SDavid J. Choi .phy_id = PHY_ID_KSZ886X, 7677ab59dc1SDavid J. Choi .phy_id_mask = 0x00fffff0, 7687ab59dc1SDavid J. Choi .name = "Micrel KSZ886X Switch", 7697ab59dc1SDavid J. Choi .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 7707ab59dc1SDavid J. Choi .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 7717ab59dc1SDavid J. Choi .config_init = kszphy_config_init, 7727ab59dc1SDavid J. Choi .config_aneg = genphy_config_aneg, 7737ab59dc1SDavid J. Choi .read_status = genphy_read_status, 7741a5465f5SPatrice Vilchez .suspend = genphy_suspend, 7751a5465f5SPatrice Vilchez .resume = genphy_resume, 7767ab59dc1SDavid J. Choi .driver = { .owner = THIS_MODULE, }, 777d5bf9071SChristian Hohnstaedt } }; 778d0507009SDavid J. Choi 77950fd7150SJohan Hovold module_phy_driver(ksphy_driver); 780d0507009SDavid J. Choi 781d0507009SDavid J. Choi MODULE_DESCRIPTION("Micrel PHY driver"); 782d0507009SDavid J. Choi MODULE_AUTHOR("David J. Choi"); 783d0507009SDavid J. Choi MODULE_LICENSE("GPL"); 78452a60ed2SDavid S. Miller 785cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused micrel_tbl[] = { 78648d7d0adSJason Wang { PHY_ID_KSZ9021, 0x000ffffe }, 7877ab59dc1SDavid J. Choi { PHY_ID_KSZ9031, 0x00fffff0 }, 788510d573fSMarek Vasut { PHY_ID_KSZ8001, 0x00ffffff }, 78951f932c4SChoi, David { PHY_ID_KS8737, 0x00fffff0 }, 790212ea99aSMarek Vasut { PHY_ID_KSZ8021, 0x00ffffff }, 791b818d1a7SHector Palacios { PHY_ID_KSZ8031, 0x00ffffff }, 792510d573fSMarek Vasut { PHY_ID_KSZ8041, 0x00fffff0 }, 793510d573fSMarek Vasut { PHY_ID_KSZ8051, 0x00fffff0 }, 7947ab59dc1SDavid J. Choi { PHY_ID_KSZ8061, 0x00fffff0 }, 7957ab59dc1SDavid J. Choi { PHY_ID_KSZ8081, 0x00fffff0 }, 79693272e07SJean-Christophe PLAGNIOL-VILLARD { PHY_ID_KSZ8873MLL, 0x00fffff0 }, 7977ab59dc1SDavid J. Choi { PHY_ID_KSZ886X, 0x00fffff0 }, 79852a60ed2SDavid S. Miller { } 79952a60ed2SDavid S. Miller }; 80052a60ed2SDavid S. Miller 80152a60ed2SDavid S. Miller MODULE_DEVICE_TABLE(mdio, micrel_tbl); 802