0ccafc1c0072f85d5702aed02dbe7a760e99345f
[15.05/openwrt.git] / target / linux / brcm63xx / patches-2.6.27 / 010-add_integrated_ethernet_phy_support.patch
1 From 7eefcb968019804e024c8243e28afb1eebd674a2 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Sun, 21 Sep 2008 02:20:53 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add integrated ethernet PHY support for phylib.
5
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
7 ---
8  drivers/net/phy/Kconfig   |    6 ++
9  drivers/net/phy/Makefile  |    1 +
10  drivers/net/phy/bcm63xx.c |  132 +++++++++++++++++++++++++++++++++++++++++++++
11  3 files changed, 139 insertions(+), 0 deletions(-)
12  create mode 100644 drivers/net/phy/bcm63xx.c
13
14 diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
15 index d55932a..a5d2c2d 100644
16 --- a/drivers/net/phy/Kconfig
17 +++ b/drivers/net/phy/Kconfig
18 @@ -56,6 +56,12 @@ config BROADCOM_PHY
19           Currently supports the BCM5411, BCM5421, BCM5461, BCM5464, BCM5481
20           and BCM5482 PHYs.
21  
22 +config BCM63XX_PHY
23 +       tristate "Drivers for Broadcom 63xx SOCs internal PHY"
24 +       depends on BCM63XX
25 +       ---help---
26 +         Currently supports the 6348 and 6358 PHYs.
27 +
28  config ICPLUS_PHY
29         tristate "Drivers for ICPlus PHYs"
30         ---help---
31 diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
32 index eee329f..0d43f58 100644
33 --- a/drivers/net/phy/Makefile
34 +++ b/drivers/net/phy/Makefile
35 @@ -11,6 +11,7 @@ obj-$(CONFIG_QSEMI_PHY)               += qsemi.o
36  obj-$(CONFIG_SMSC_PHY)         += smsc.o
37  obj-$(CONFIG_VITESSE_PHY)      += vitesse.o
38  obj-$(CONFIG_BROADCOM_PHY)     += broadcom.o
39 +obj-$(CONFIG_BCM63XX_PHY)      += bcm63xx.o
40  obj-$(CONFIG_ICPLUS_PHY)       += icplus.o
41  obj-$(CONFIG_REALTEK_PHY)      += realtek.o
42  obj-$(CONFIG_FIXED_PHY)                += fixed.o
43 diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c
44 new file mode 100644
45 index 0000000..4fed95e
46 --- /dev/null
47 +++ b/drivers/net/phy/bcm63xx.c
48 @@ -0,0 +1,132 @@
49 +/*
50 + *     Driver for Broadcom 63xx SOCs integrated PHYs
51 + *
52 + *     This program is free software; you can redistribute it and/or
53 + *     modify it under the terms of the GNU General Public License
54 + *     as published by the Free Software Foundation; either version
55 + *     2 of the License, or (at your option) any later version.
56 + */
57 +#include <linux/module.h>
58 +#include <linux/phy.h>
59 +
60 +#define MII_BCM63XX_IR         0x1a    /* interrupt register */
61 +#define MII_BCM63XX_IR_EN      0x4000  /* global interrupt enable */
62 +#define MII_BCM63XX_IR_DUPLEX  0x0800  /* duplex changed */
63 +#define MII_BCM63XX_IR_SPEED   0x0400  /* speed changed */
64 +#define MII_BCM63XX_IR_LINK    0x0200  /* link changed */
65 +#define MII_BCM63XX_IR_GMASK   0x0100  /* global interrupt mask */
66 +
67 +MODULE_DESCRIPTION("Broadcom 63xx internal PHY driver");
68 +MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
69 +MODULE_LICENSE("GPL");
70 +
71 +static int bcm63xx_config_init(struct phy_device *phydev)
72 +{
73 +       int reg, err;
74 +
75 +       reg = phy_read(phydev, MII_BCM63XX_IR);
76 +       if (reg < 0)
77 +               return reg;
78 +
79 +       /* Mask interrupts globally.  */
80 +       reg |= MII_BCM63XX_IR_GMASK;
81 +       err = phy_write(phydev, MII_BCM63XX_IR, reg);
82 +       if (err < 0)
83 +               return err;
84 +
85 +       /* Unmask events we are interested in  */
86 +       reg = ~(MII_BCM63XX_IR_DUPLEX |
87 +               MII_BCM63XX_IR_SPEED |
88 +               MII_BCM63XX_IR_LINK) |
89 +               MII_BCM63XX_IR_EN;
90 +       err = phy_write(phydev, MII_BCM63XX_IR, reg);
91 +       if (err < 0)
92 +               return err;
93 +       return 0;
94 +}
95 +
96 +static int bcm63xx_ack_interrupt(struct phy_device *phydev)
97 +{
98 +       int reg;
99 +
100 +       /* Clear pending interrupts.  */
101 +       reg = phy_read(phydev, MII_BCM63XX_IR);
102 +       if (reg < 0)
103 +               return reg;
104 +
105 +       return 0;
106 +}
107 +
108 +static int bcm63xx_config_intr(struct phy_device *phydev)
109 +{
110 +       int reg, err;
111 +
112 +       reg = phy_read(phydev, MII_BCM63XX_IR);
113 +       if (reg < 0)
114 +               return reg;
115 +
116 +       if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
117 +               reg &= ~MII_BCM63XX_IR_GMASK;
118 +       else
119 +               reg |= MII_BCM63XX_IR_GMASK;
120 +
121 +       err = phy_write(phydev, MII_BCM63XX_IR, reg);
122 +       return err;
123 +}
124 +
125 +static struct phy_driver bcm63xx_1_driver = {
126 +       .phy_id         = 0x00406000,
127 +       .phy_id_mask    = 0xfffffc00,
128 +       .name           = "Broadcom BCM63XX (1)",
129 +       /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */
130 +       .features       = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
131 +       .flags          = PHY_HAS_INTERRUPT,
132 +       .config_init    = bcm63xx_config_init,
133 +       .config_aneg    = genphy_config_aneg,
134 +       .read_status    = genphy_read_status,
135 +       .ack_interrupt  = bcm63xx_ack_interrupt,
136 +       .config_intr    = bcm63xx_config_intr,
137 +       .driver         = { .owner = THIS_MODULE },
138 +};
139 +
140 +/* same phy as above, with just a different OUI */
141 +static struct phy_driver bcm63xx_2_driver = {
142 +       .phy_id         = 0x002bdc00,
143 +       .phy_id_mask    = 0xfffffc00,
144 +       .name           = "Broadcom BCM63XX (2)",
145 +       .features       = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
146 +       .flags          = PHY_HAS_INTERRUPT,
147 +       .config_init    = bcm63xx_config_init,
148 +       .config_aneg    = genphy_config_aneg,
149 +       .read_status    = genphy_read_status,
150 +       .ack_interrupt  = bcm63xx_ack_interrupt,
151 +       .config_intr    = bcm63xx_config_intr,
152 +       .driver         = { .owner = THIS_MODULE },
153 +};
154 +
155 +static int __init bcm63xx_phy_init(void)
156 +{
157 +       int ret;
158 +
159 +       ret = phy_driver_register(&bcm63xx_1_driver);
160 +       if (ret)
161 +               goto out_63xx_1;
162 +       ret = phy_driver_register(&bcm63xx_2_driver);
163 +       if (ret)
164 +               goto out_63xx_2;
165 +       return ret;
166 +
167 +out_63xx_2:
168 +       phy_driver_unregister(&bcm63xx_1_driver);
169 +out_63xx_1:
170 +       return ret;
171 +}
172 +
173 +static void __exit bcm63xx_phy_exit(void)
174 +{
175 +       phy_driver_unregister(&bcm63xx_1_driver);
176 +       phy_driver_unregister(&bcm63xx_2_driver);
177 +}
178 +
179 +module_init(bcm63xx_phy_init);
180 +module_exit(bcm63xx_phy_exit);
181 -- 
182 1.5.4.3
183