Add Broadcom PHY support
Subsystems (4)
PATCH 1/1 Add Broadcom PHY support
[PATCH] Add Broadcom PHY support
This patch adds a driver to support the bcm5421s and bcm5461s PHY
Kernel version: linux-2.6.18-rc6
drivers/net/phy/broadcom.c new file +129 -0
@@ -0,0 +1,129 @@ +/* +* drivers/net/phy/broadcom.c, Driver for Broadcom PHYs +* +* Copyright (c) 2006 Wind River Systems, Inc. +* Written by Amy Fong +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +*/ + +#include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/errno.h> +#include <linux/unistd.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> +#include <linux/spinlock.h> +#include <linux/mm.h> +#include <linux/module.h> +#include <linux/mii.h> +#include <linux/ethtool.h> +#include <linux/phy.h> + +#include <asm/io.h> +#include <asm/irq.h> +#include <asm/uaccess.h> + +/* BCM5421S control register */ +#define MII_BCM5421S_CONTROL 0x00 +#define MII_BCM5421S_CONTROL_RESET 0x00008000 +#define MII_BCM5421S_CONTROL_INIT 0x00001140 +#define MII_BCM5421S_ANEN 0x00001000 +#define MII_BCM5421S_CR 0x00 +#define MII_BCM5421S_CR_RST 0x00008000 +#define MII_BCM5421S_CR_INIT 0x00001000 +#define MII_BCM5421S_STATUS 0x1 +#define MII_BCM5421S_STATUS_AN_DONE 0x00000020 +#define MII_BCM5421S_STATUS_LINK 0x0004 +#define MII_BCM5421S_PHYIR1 0x2 +#define MII_BCM5421S_PHYIR2 0x3 +#define MII_BCM5421S_ANLPBPA 0x5 +#define MII_BCM5421S_ANLPBPA_HALF 0x00000040 +#define MII_BCM5421S_ANLPBPA_FULL 0x00000020 +#define MII_BCM5421S_ANEX 0x6 +#define MII_BCM5421S_ANEX_NP 0x00000004 +#define MII_BCM5421S_ANEX_PRX 0x00000002 + +MODULE_DESCRIPTION ("Broadcom PHY driver" ); +MODULE_AUTHOR ("Amy Fong" ); +MODULE_LICENSE ("GPL" ); + +static int bcm5421s_config_aneg (struct phy_device *phydev) +{ +int err; + +/* Write the appropriate value to the PHY reg */ +if (phydev->supported & SUPPORTED_1000baseT_Full) + err =phy_write (phydev,MII_BCM5421S_CONTROL ,MII_BCM5421S_CONTROL_INIT ); +else + err =phy_write (phydev,MII_BCM5421S_CONTROL ,MII_BCM5421S_CR_INIT ); + +if (err <0 )return err; + +/* doesn't have phy interrupt */ + phydev->interrupts =PHY_INTERRUPT_DISABLED ; + +return 0 ; +} + +static struct phy_driver bcm5421s_driver = { + .phy_id =0x002060e1 , + .phy_id_mask =0x00ffffff , + .name ="Broadcom BCM5421S" , + .features =PHY_GBIT_FEATURES , + .config_aneg = bcm5421s_config_aneg, + .read_status = genphy_read_status, + .driver = { .owner =THIS_MODULE ,}, +}; + +/* Glossy description on Broadcom's site seems to hint that the 5461 +should be a drop-in for the 5421.... */ +static struct phy_driver bcm5461s_driver = { + .phy_id =0x002060c1 , + .phy_id_mask =0x00ffffff , + .name ="Broadcom BCM5461S" , + .features =PHY_GBIT_FEATURES , + .config_aneg = bcm5421s_config_aneg, + .read_status = genphy_read_status, + .driver = { .owner =THIS_MODULE ,}, +}; + +static int __init broadcom_init (void ) +{ +int ret; + + ret =phy_driver_register (&bcm5421s_driver); +if (!ret) { + ret =phy_driver_register (&bcm5461s_driver); +if (ret)phy_driver_unregister (&bcm5421s_driver); + } +return ret; +} + +static void __exit broadcom_exit(void) +{ +phy_driver_unregister (&bcm5421s_driver); +phy_driver_unregister (&bcm5461s_driver); +} + +module_init (broadcom_init); +module_exit (broadcom_exit);
drivers/net/phy/Kconfig +6 -0
@@ -56,6 +56,12 @@ ---help--- Currently supports the LAN83C185 PHY +config BROADCOM_PHY + tristate "Drivers for Broadcom PHYs" + depends on PHYLIB + ---help--- + Currently supports bcm5421s and bcm5461s + config FIXED_PHY tristate "Drivers for PHY emulation on fixed speed/link" depends on PHYLIB
drivers/net/phy/Makefile +1 -0
@@ -10,4 +10,5 @@ obj-$(CONFIG_QSEMI_PHY) += qsemi.o obj-$(CONFIG_SMSC_PHY) += smsc.o obj-$(CONFIG_VITESSE_PHY) += vitesse.o +obj-$(CONFIG_BROADCOM_PHY) += broadcom.o obj-$(CONFIG_FIXED_PHY) += fixed.o
Quoted 7 lines · Amy Fong
[PATCH] Add Broadcom PHY support
This patch adds a driver to support the bcm5421s and bcm5461s PHY
Kernel version: linux-2.6.18-rc6
Signed-off-by Amy Fong <[email protected]>
And... where are the users of this phy driver?
Jeff
[ Charset ISO-8859-1 unsupported, converting... ]
Quoted 5 lines
Quoted 4 lines · Amy Fong
[PATCH] Add Broadcom PHY support
This patch adds a driver to support the bcm5421s and bcm5461s PHY
Quoted 8 lines
Quoted 3 lines
Kernel version: linux-2.6.18-rc6
Signed-off-by Amy Fong <[email protected]>And... where are the users of this phy driver?
Jeff
This phy driver is used by the WRS's sbc8560 (bcm5421s) and sbc843x (bcm5461s) via the gianfar driver.
Amy
Quoted 1 line · Amy Fong
Quoted 1 line
And... where are the users of this phy driver?
[...]
Quoted 2 lines
This phy driver is used by the WRS's sbc8560 (bcm5421s) and sbc843x (bcm5461s) via the gianfar driver.
And sb1250-mac.c would be happy to use it too.
Maciej
Quoted 7 lines · Maciej W. Rozycki
Quoted 1 line · Amy Fong
Quoted 1 line
And... where are the users of this phy driver?
[...]
Quoted 1 line
This phy driver is used by the WRS's sbc8560 (bcm5421s) and sbc843x (bcm5461s) via the gianfar driver.
And
sb1250-mac.cwould be happy to use it too.
"would be happy to" != "is using". I don't want to add a phy driver until there are already active users in the kernel.
Jeff
Quoted 4 lines · Jeff Garzik
Quoted 1 line
And
sb1250-mac.cwould be happy to use it too."would be happy to" != "is using". I don't want to add a phy driver until
there are already active users in the kernel.
Fair enough, but Amy may be looking forward to seeing yet another piece
of code using the new driver. ;-)
Maciej
Quoted 7 lines · Amy Fong
[PATCH] Add Broadcom PHY support
This patch adds a driver to support the bcm5421s and bcm5461s PHY
Kernel version: linux-2.6.18-rc6
Signed-off-by Amy Fong
Some 5421's need special initialisation (see drivers/net/sungem_phy.c), might be worth having them there too. I was also wondering... for spidernet, we need to enable the fiber mode on the PHY. Does phylib has an API for that ?
I'd like to look into moving sungem and spidernet over to phylib.
Ben.
Quoted 9 lines · Amy Fong
Quoted 7 lines
[PATCH] Add Broadcom PHY support
This patch adds a driver to support the bcm5421s and bcm5461s PHY
Kernel version: linux-2.6.18-rc6
Signed-off-by Amy Fong
Quoted 8 lines
Some 5421's need special initialisation (see
drivers/net/sungem_phy.c), might be worth having them there too. I was also wondering... for spidernet, we need to enable the fiber mode on the PHY. Does phylib has an API for that ?I'd like to look into moving sungem and spidernet over to phylib.
Ben.
I believe that this fiber enabling can be done by defining config_init in the phy_driver struct.
struct phy_driver {
<snip>
/* Called to initialize the PHY, * including after a reset */ int (*config_init)(struct phy_device *phydev);
<snip>
};
ie.
static struct phy_driver bcm5421s_driver = {
<snip>
.config_init = bcm5421s_phy_config,
<snip>
};
int bcm5421s_phy_config(struct phy_device *phydev) {
...
/* enable fiber mode here... */
...
}
Amy
Quoted 10 lines
I believe that this fiber enabling can be done by defining
config_initin thephy_driverstruct.struct
phy_driver{
<snip>/* Called to initialize the PHY, * including after a reset */ int (*config_init)(struct phy_device *phydev);<snip>
};
Well... I don't know for sure... thing is, enabling the fiber mode is a rather platform specific thing. So it's the MAC driver that knows wether it wants it on a PHY and should call into the driver.
It's difficult to abstract all possible PHY config options tho... some MACs might want to enable low power, some don't because they have issues with it, that sort of thing, though.
Not sure what the best solution is at this point... Maybe an ascii string to pass the PHY driver is the most flexible, though a bit yucky, or we try to have a list of all the possible configuration options in phy.h and people just add new ones that they need as they add support for them...
Sounds grossly like an in-kernel ioctl tho...
Ben.
Quoted 19 lines · Benjamin Herrenschmidt
Quoted 10 lines
I believe that this fiber enabling can be done by defining
config_initin thephy_driverstruct.struct
phy_driver{
<snip>/* Called to initialize the PHY, * including after a reset */ int (*config_init)(struct phy_device *phydev);<snip>
};Well... I don't know for sure... thing is, enabling the fiber mode is a rather platform specific thing. So it's the MAC driver that knows wether it wants it on a PHY and should call into the driver.
It's difficult to abstract all possible PHY config options tho... some MACs might want to enable low power, some don't because they have issues with it, that sort of thing, though.
Quoted 7 lines
Not sure what the best solution is at this point... Maybe an ascii string to pass the PHY driver is the most flexible, though a bit yucky, or we try to have a list of all the possible configuration options in
phy.hand people just add new ones that they need as they add support for them...Sounds grossly like an in-kernel ioctl tho...
Each phy_device structure now has a dev_flags field that can be modified by the controller's code upon connecting. The PHY driver can then check that field for PHY-specific, platform-specific interactions. For instance, on the newer CDS, there's a Marvell PHY which requires configurable resistance changes to work in RGMII mode. So there's a flag for that. Basically, each PHY driver specifies its own flags, and the platform code is currently responsible for setting those flags appropriately. A string might be more flexible, but I'm operating on the hope that there shouldn't be too many of these.
For Fiber mode, or other such changes, we might want to add another field, like the interface field, to describe standard external interfaces. The call to phy_connect() is beginning to get a bit long, though.
Andy