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 */ 909bb9aa0SMaxime Bizon #include <linux/module.h> 1009bb9aa0SMaxime Bizon #include <linux/phy.h> 1109bb9aa0SMaxime Bizon 1209bb9aa0SMaxime Bizon #define MII_BCM63XX_IR 0x1a /* interrupt register */ 1309bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */ 1409bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */ 1509bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */ 1609bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_LINK 0x0200 /* link changed */ 1709bb9aa0SMaxime Bizon #define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */ 1809bb9aa0SMaxime Bizon 1909bb9aa0SMaxime Bizon MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver"); 2009bb9aa0SMaxime Bizon MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>"); 2109bb9aa0SMaxime Bizon MODULE_LICENSE("GPL"); 2209bb9aa0SMaxime Bizon 2309bb9aa0SMaxime Bizon static int bcm63xx_config_init(struct phy_device *phydev) 2409bb9aa0SMaxime Bizon { 2509bb9aa0SMaxime Bizon int reg, err; 2609bb9aa0SMaxime Bizon 2709bb9aa0SMaxime Bizon reg = phy_read(phydev, MII_BCM63XX_IR); 2809bb9aa0SMaxime Bizon if (reg < 0) 2909bb9aa0SMaxime Bizon return reg; 3009bb9aa0SMaxime Bizon 3109bb9aa0SMaxime Bizon /* Mask interrupts globally. */ 3209bb9aa0SMaxime Bizon reg |= MII_BCM63XX_IR_GMASK; 3309bb9aa0SMaxime Bizon err = phy_write(phydev, MII_BCM63XX_IR, reg); 3409bb9aa0SMaxime Bizon if (err < 0) 3509bb9aa0SMaxime Bizon return err; 3609bb9aa0SMaxime Bizon 3709bb9aa0SMaxime Bizon /* Unmask events we are interested in */ 3809bb9aa0SMaxime Bizon reg = ~(MII_BCM63XX_IR_DUPLEX | 3909bb9aa0SMaxime Bizon MII_BCM63XX_IR_SPEED | 4009bb9aa0SMaxime Bizon MII_BCM63XX_IR_LINK) | 4109bb9aa0SMaxime Bizon MII_BCM63XX_IR_EN; 4209bb9aa0SMaxime Bizon err = phy_write(phydev, MII_BCM63XX_IR, reg); 4309bb9aa0SMaxime Bizon if (err < 0) 4409bb9aa0SMaxime Bizon return err; 4509bb9aa0SMaxime Bizon return 0; 4609bb9aa0SMaxime Bizon } 4709bb9aa0SMaxime Bizon 4809bb9aa0SMaxime Bizon static int bcm63xx_ack_interrupt(struct phy_device *phydev) 4909bb9aa0SMaxime Bizon { 5009bb9aa0SMaxime Bizon int reg; 5109bb9aa0SMaxime Bizon 5209bb9aa0SMaxime Bizon /* Clear pending interrupts. */ 5309bb9aa0SMaxime Bizon reg = phy_read(phydev, MII_BCM63XX_IR); 5409bb9aa0SMaxime Bizon if (reg < 0) 5509bb9aa0SMaxime Bizon return reg; 5609bb9aa0SMaxime Bizon 5709bb9aa0SMaxime Bizon return 0; 5809bb9aa0SMaxime Bizon } 5909bb9aa0SMaxime Bizon 6009bb9aa0SMaxime Bizon static int bcm63xx_config_intr(struct phy_device *phydev) 6109bb9aa0SMaxime Bizon { 6209bb9aa0SMaxime Bizon int reg, err; 6309bb9aa0SMaxime Bizon 6409bb9aa0SMaxime Bizon reg = phy_read(phydev, MII_BCM63XX_IR); 6509bb9aa0SMaxime Bizon if (reg < 0) 6609bb9aa0SMaxime Bizon return reg; 6709bb9aa0SMaxime Bizon 6809bb9aa0SMaxime Bizon if (phydev->interrupts == PHY_INTERRUPT_ENABLED) 6909bb9aa0SMaxime Bizon reg &= ~MII_BCM63XX_IR_GMASK; 7009bb9aa0SMaxime Bizon else 7109bb9aa0SMaxime Bizon reg |= MII_BCM63XX_IR_GMASK; 7209bb9aa0SMaxime Bizon 7309bb9aa0SMaxime Bizon err = phy_write(phydev, MII_BCM63XX_IR, reg); 7409bb9aa0SMaxime Bizon return err; 7509bb9aa0SMaxime Bizon } 7609bb9aa0SMaxime Bizon 7709bb9aa0SMaxime Bizon static struct phy_driver bcm63xx_1_driver = { 7809bb9aa0SMaxime Bizon .phy_id = 0x00406000, 7909bb9aa0SMaxime Bizon .phy_id_mask = 0xfffffc00, 8009bb9aa0SMaxime Bizon .name = "Broadcom BCM63XX (1)", 8109bb9aa0SMaxime Bizon /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */ 8209bb9aa0SMaxime Bizon .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 8309bb9aa0SMaxime Bizon .flags = PHY_HAS_INTERRUPT, 8409bb9aa0SMaxime Bizon .config_init = bcm63xx_config_init, 8509bb9aa0SMaxime Bizon .config_aneg = genphy_config_aneg, 8609bb9aa0SMaxime Bizon .read_status = genphy_read_status, 8709bb9aa0SMaxime Bizon .ack_interrupt = bcm63xx_ack_interrupt, 8809bb9aa0SMaxime Bizon .config_intr = bcm63xx_config_intr, 8909bb9aa0SMaxime Bizon .driver = { .owner = THIS_MODULE }, 9009bb9aa0SMaxime Bizon }; 9109bb9aa0SMaxime Bizon 9209bb9aa0SMaxime Bizon /* same phy as above, with just a different OUI */ 9309bb9aa0SMaxime Bizon static struct phy_driver bcm63xx_2_driver = { 9409bb9aa0SMaxime Bizon .phy_id = 0x002bdc00, 9509bb9aa0SMaxime Bizon .phy_id_mask = 0xfffffc00, 9609bb9aa0SMaxime Bizon .name = "Broadcom BCM63XX (2)", 9709bb9aa0SMaxime Bizon .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), 9809bb9aa0SMaxime Bizon .flags = PHY_HAS_INTERRUPT, 9909bb9aa0SMaxime Bizon .config_init = bcm63xx_config_init, 10009bb9aa0SMaxime Bizon .config_aneg = genphy_config_aneg, 10109bb9aa0SMaxime Bizon .read_status = genphy_read_status, 10209bb9aa0SMaxime Bizon .ack_interrupt = bcm63xx_ack_interrupt, 10309bb9aa0SMaxime Bizon .config_intr = bcm63xx_config_intr, 10409bb9aa0SMaxime Bizon .driver = { .owner = THIS_MODULE }, 10509bb9aa0SMaxime Bizon }; 10609bb9aa0SMaxime Bizon 10709bb9aa0SMaxime Bizon static int __init bcm63xx_phy_init(void) 10809bb9aa0SMaxime Bizon { 10909bb9aa0SMaxime Bizon int ret; 11009bb9aa0SMaxime Bizon 11109bb9aa0SMaxime Bizon ret = phy_driver_register(&bcm63xx_1_driver); 11209bb9aa0SMaxime Bizon if (ret) 11309bb9aa0SMaxime Bizon goto out_63xx_1; 11409bb9aa0SMaxime Bizon ret = phy_driver_register(&bcm63xx_2_driver); 11509bb9aa0SMaxime Bizon if (ret) 11609bb9aa0SMaxime Bizon goto out_63xx_2; 11709bb9aa0SMaxime Bizon return ret; 11809bb9aa0SMaxime Bizon 11909bb9aa0SMaxime Bizon out_63xx_2: 12009bb9aa0SMaxime Bizon phy_driver_unregister(&bcm63xx_1_driver); 12109bb9aa0SMaxime Bizon out_63xx_1: 12209bb9aa0SMaxime Bizon return ret; 12309bb9aa0SMaxime Bizon } 12409bb9aa0SMaxime Bizon 12509bb9aa0SMaxime Bizon static void __exit bcm63xx_phy_exit(void) 12609bb9aa0SMaxime Bizon { 12709bb9aa0SMaxime Bizon phy_driver_unregister(&bcm63xx_1_driver); 12809bb9aa0SMaxime Bizon phy_driver_unregister(&bcm63xx_2_driver); 12909bb9aa0SMaxime Bizon } 13009bb9aa0SMaxime Bizon 13109bb9aa0SMaxime Bizon module_init(bcm63xx_phy_init); 13209bb9aa0SMaxime Bizon module_exit(bcm63xx_phy_exit); 1334e4f10f6SDavid Woodhouse 1344e4f10f6SDavid Woodhouse static struct mdio_device_id bcm63xx_tbl[] = { 1354e4f10f6SDavid Woodhouse { 0x00406000, 0xfffffc00 }, 1364e4f10f6SDavid Woodhouse { 0x002bdc00, 0xfffffc00 }, 1374e4f10f6SDavid Woodhouse { } 1384e4f10f6SDavid Woodhouse }; 1394e4f10f6SDavid Woodhouse 1400de8655aSFlorian Fainelli MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl); 141