Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Broadcom 63xx SOCs integrated PHYs |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 9 | #include "bcm-phy-lib.h" |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/phy.h> |
| 12 | |
| 13 | #define MII_BCM63XX_IR 0x1a /* interrupt register */ |
| 14 | #define MII_BCM63XX_IR_EN 0x4000 /* global interrupt enable */ |
| 15 | #define MII_BCM63XX_IR_DUPLEX 0x0800 /* duplex changed */ |
| 16 | #define MII_BCM63XX_IR_SPEED 0x0400 /* speed changed */ |
| 17 | #define MII_BCM63XX_IR_LINK 0x0200 /* link changed */ |
| 18 | #define MII_BCM63XX_IR_GMASK 0x0100 /* global interrupt mask */ |
| 19 | |
| 20 | MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver"); |
| 21 | MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
Daniel Gonzalez Cabanelas | cd33b3e | 2017-01-17 16:26:55 -0800 | [diff] [blame] | 24 | static int bcm63xx_config_intr(struct phy_device *phydev) |
| 25 | { |
| 26 | int reg, err; |
| 27 | |
| 28 | reg = phy_read(phydev, MII_BCM63XX_IR); |
| 29 | if (reg < 0) |
| 30 | return reg; |
| 31 | |
| 32 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
| 33 | reg &= ~MII_BCM63XX_IR_GMASK; |
| 34 | else |
| 35 | reg |= MII_BCM63XX_IR_GMASK; |
| 36 | |
| 37 | err = phy_write(phydev, MII_BCM63XX_IR, reg); |
| 38 | return err; |
| 39 | } |
| 40 | |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 41 | static int bcm63xx_config_init(struct phy_device *phydev) |
| 42 | { |
| 43 | int reg, err; |
| 44 | |
| 45 | reg = phy_read(phydev, MII_BCM63XX_IR); |
| 46 | if (reg < 0) |
| 47 | return reg; |
| 48 | |
| 49 | /* Mask interrupts globally. */ |
| 50 | reg |= MII_BCM63XX_IR_GMASK; |
| 51 | err = phy_write(phydev, MII_BCM63XX_IR, reg); |
| 52 | if (err < 0) |
| 53 | return err; |
| 54 | |
| 55 | /* Unmask events we are interested in */ |
| 56 | reg = ~(MII_BCM63XX_IR_DUPLEX | |
| 57 | MII_BCM63XX_IR_SPEED | |
| 58 | MII_BCM63XX_IR_LINK) | |
| 59 | MII_BCM63XX_IR_EN; |
Srinivas Kandagatla | a25cc43 | 2012-04-02 06:24:55 +0000 | [diff] [blame] | 60 | return phy_write(phydev, MII_BCM63XX_IR, reg); |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 63 | static struct phy_driver bcm63xx_driver[] = { |
| 64 | { |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 65 | .phy_id = 0x00406000, |
| 66 | .phy_id_mask = 0xfffffc00, |
| 67 | .name = "Broadcom BCM63XX (1)", |
| 68 | /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */ |
| 69 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), |
Florian Fainelli | 50ab731 | 2013-05-23 01:11:13 +0000 | [diff] [blame] | 70 | .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 71 | .config_init = bcm63xx_config_init, |
| 72 | .config_aneg = genphy_config_aneg, |
| 73 | .read_status = genphy_read_status, |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 74 | .ack_interrupt = bcm_phy_ack_intr, |
Daniel Gonzalez Cabanelas | cd33b3e | 2017-01-17 16:26:55 -0800 | [diff] [blame] | 75 | .config_intr = bcm63xx_config_intr, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 76 | }, { |
| 77 | /* same phy as above, with just a different OUI */ |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 78 | .phy_id = 0x002bdc00, |
| 79 | .phy_id_mask = 0xfffffc00, |
| 80 | .name = "Broadcom BCM63XX (2)", |
| 81 | .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), |
Florian Fainelli | 50ab731 | 2013-05-23 01:11:13 +0000 | [diff] [blame] | 82 | .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 83 | .config_init = bcm63xx_config_init, |
| 84 | .config_aneg = genphy_config_aneg, |
| 85 | .read_status = genphy_read_status, |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 86 | .ack_interrupt = bcm_phy_ack_intr, |
Daniel Gonzalez Cabanelas | cd33b3e | 2017-01-17 16:26:55 -0800 | [diff] [blame] | 87 | .config_intr = bcm63xx_config_intr, |
Christian Hohnstaedt | d5bf907 | 2012-07-04 05:44:34 +0000 | [diff] [blame] | 88 | } }; |
Maxime Bizon | 09bb9aa | 2009-07-01 01:29:36 +0000 | [diff] [blame] | 89 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 90 | module_phy_driver(bcm63xx_driver); |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 91 | |
Uwe Kleine-König | cf93c94 | 2010-10-03 23:43:32 +0000 | [diff] [blame] | 92 | static struct mdio_device_id __maybe_unused bcm63xx_tbl[] = { |
David Woodhouse | 4e4f10f | 2010-04-02 01:05:56 +0000 | [diff] [blame] | 93 | { 0x00406000, 0xfffffc00 }, |
| 94 | { 0x002bdc00, 0xfffffc00 }, |
| 95 | { } |
| 96 | }; |
| 97 | |
Florian Fainelli | 0de8655 | 2010-04-09 01:04:45 +0000 | [diff] [blame] | 98 | MODULE_DEVICE_TABLE(mdio, bcm63xx_tbl); |