109bb9aa0SMaxime Bizon /* 209bb9aa0SMaxime Bizon * Driver for Broadcom 63xx SOCs integrated PHYs 309bb9aa0SMaxime Bizon * 409bb9aa0SMaxime Bizon * This program is free software; you can redistribute it and/or 509bb9aa0SMaxime Bizon * modify it under the terms of the GNU General Public License 609bb9aa0SMaxime Bizon * as published by the Free Software Foundation; either version 709bb9aa0SMaxime Bizon * 2 of the License, or (at your option) any later version. 809bb9aa0SMaxime Bizon */ 9a1cba561SArun Parameswaran #include "bcm-phy-lib.h" 1009bb9aa0SMaxime Bizon #include <linux/module.h> 1109bb9aa0SMaxime Bizon #include <linux/phy.h> 1209bb9aa0SMaxime Bizon 1309bb9aa0SMaxime Bizon #define MII_BCM63XX_IR 0x1a /* interrupt register */ 1409bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */ 1509bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */ 1609bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */ 1709bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_LINK 0x0200 /* link changed */ 1809bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */ 1909bb9aa0SMaxime Bizon 2009bb9aa0SMaxime Bizon MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver"); 2109bb9aa0SMaxime Bizon MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>"); 2209bb9aa0SMaxime Bizon MODULE_LICENSE("GPL"); 2309bb9aa0SMaxime Bizon 24cd33b3e0SDaniel Gonzalez Cabanelas static int bcm63xx_config_intr(struct phy_device *phydev) 25cd33b3e0SDaniel Gonzalez Cabanelas { 26cd33b3e0SDaniel Gonzalez Cabanelas int reg, err; 27cd33b3e0SDaniel Gonzalez Cabanelas 28cd33b3e0SDaniel Gonzalez Cabanelas reg = phy_read(phydev, MII_BCM63XX_IR); 29cd33b3e0SDaniel Gonzalez Cabanelas if (reg < 0) 30cd33b3e0SDaniel Gonzalez Cabanelas return reg; 31cd33b3e0SDaniel Gonzalez Cabanelas 32cd33b3e0SDaniel Gonzalez Cabanelas if (phydev->interrupts == PHY_INTERRUPT_ENABLED) 33cd33b3e0SDaniel Gonzalez Cabanelas reg &= ~MII_BCM63XX_IR_GMASK; 34cd33b3e0SDaniel Gonzalez Cabanelas else 35cd33b3e0SDaniel Gonzalez Cabanelas reg |= MII_BCM63XX_IR_GMASK; 36cd33b3e0SDaniel Gonzalez Cabanelas 37cd33b3e0SDaniel Gonzalez Cabanelas err = phy_write(phydev, MII_BCM63XX_IR, reg); 38cd33b3e0SDaniel Gonzalez Cabanelas return err; 39cd33b3e0SDaniel Gonzalez Cabanelas } 40cd33b3e0SDaniel Gonzalez Cabanelas 4109bb9aa0SMaxime Bizon static int bcm63xx_config_init(struct phy_device *phydev) 4209bb9aa0SMaxime Bizon { 4309bb9aa0SMaxime Bizon int reg, err; 4409bb9aa0SMaxime Bizon 4509bb9aa0SMaxime Bizon reg = phy_read(phydev, MII_BCM63XX_IR); 4609bb9aa0SMaxime Bizon if (reg < 0) 4709bb9aa0SMaxime Bizon return reg; 4809bb9aa0SMaxime Bizon 4909bb9aa0SMaxime Bizon /* Mask interrupts globally. */ 5009bb9aa0SMaxime Bizon reg |= MII_BCM63XX_IR_GMASK; 5109bb9aa0SMaxime Bizon err = phy_write(phydev, MII_BCM63XX_IR, reg); 5209bb9aa0SMaxime Bizon if (err < 0) 5309bb9aa0SMaxime Bizon return err; 5409bb9aa0SMaxime Bizon 5509bb9aa0SMaxime Bizon /* Unmask events we are interested in */ 5609bb9aa0SMaxime Bizon reg = ~(MII_BCM63XX_IR_DUPLEX | 5709bb9aa0SMaxime Bizon MII_BCM63XX_IR_SPEED | 5809bb9aa0SMaxime Bizon MII_BCM63XX_IR_LINK) | 5909bb9aa0SMaxime Bizon MII_BCM63XX_IR_EN; 60a25cc43eSSrinivas Kandagatla return phy_write(phydev, MII_BCM63XX_IR, reg); 6109bb9aa0SMaxime Bizon } 6209bb9aa0SMaxime Bizon 63d5bf9071SChristian Hohnstaedt static struct phy_driver bcm63xx_driver[] = { 64d5bf9071SChristian Hohnstaedt { 6509bb9aa0SMaxime Bizon .phy_id = 0x00406000, 6609bb9aa0SMaxime Bizon .phy_id_mask = 0xfffffc00, 6709bb9aa0SMaxime Bizon .name = "Broadcom BCM63XX (1)", 6809bb9aa0SMaxime Bizon /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */ 6909bb9aa0SMaxime Bizon .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 7050ab731eSFlorian Fainelli .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, 7109bb9aa0SMaxime Bizon .config_init = bcm63xx_config_init, 7209bb9aa0SMaxime Bizon .config_aneg = genphy_config_aneg, 7309bb9aa0SMaxime Bizon .read_status = genphy_read_status, 74a1cba561SArun Parameswaran .ack_interrupt = bcm_phy_ack_intr, 75cd33b3e0SDaniel Gonzalez Cabanelas .config_intr = bcm63xx_config_intr, 76d5bf9071SChristian Hohnstaedt }, { 7709bb9aa0SMaxime Bizon /* same phy as above, with just a different OUI */ 7809bb9aa0SMaxime Bizon .phy_id = 0x002bdc00, 7909bb9aa0SMaxime Bizon .phy_id_mask = 0xfffffc00, 8009bb9aa0SMaxime Bizon .name = "Broadcom BCM63XX (2)", 8109bb9aa0SMaxime Bizon .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 8250ab731eSFlorian Fainelli .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, 8309bb9aa0SMaxime Bizon .config_init = bcm63xx_config_init, 8409bb9aa0SMaxime Bizon .config_aneg = genphy_config_aneg, 8509bb9aa0SMaxime Bizon .read_status = genphy_read_status, 86a1cba561SArun Parameswaran .ack_interrupt = bcm_phy_ack_intr, 87cd33b3e0SDaniel Gonzalez Cabanelas .config_intr = bcm63xx_config_intr, 88d5bf9071SChristian Hohnstaedt } }; 8909bb9aa0SMaxime Bizon 9050fd7150SJohan Hovold module_phy_driver(bcm63xx_driver); 914e4f10f6SDavid Woodhouse 92cf93c945SUwe Kleine-König static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = { 934e4f10f6SDavid Woodhouse { 0x00406000, 0xfffffc00 }, 944e4f10f6SDavid Woodhouse { 0x002bdc00, 0xfffffc00 }, 954e4f10f6SDavid Woodhouse { } 964e4f10f6SDavid Woodhouse }; 974e4f10f6SDavid Woodhouse 980de8655aSFlorian Fainelli MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl); 99