diff options
Diffstat (limited to 'drivers/net/phy')
-rw-r--r-- | drivers/net/phy/Kconfig | 9 | ||||
-rw-r--r-- | drivers/net/phy/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/phy/broadcom.c | 201 | ||||
-rw-r--r-- | drivers/net/phy/mdio-bitbang.c | 2 | ||||
-rw-r--r-- | drivers/net/phy/mdio-ofgpio.c | 205 |
5 files changed, 415 insertions, 3 deletions
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 6eb2d31d1e34..d55932acd887 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig | |||
@@ -53,7 +53,8 @@ config SMSC_PHY | |||
53 | config BROADCOM_PHY | 53 | config BROADCOM_PHY |
54 | tristate "Drivers for Broadcom PHYs" | 54 | tristate "Drivers for Broadcom PHYs" |
55 | ---help--- | 55 | ---help--- |
56 | Currently supports the BCM5411, BCM5421 and BCM5461 PHYs. | 56 | Currently supports the BCM5411, BCM5421, BCM5461, BCM5464, BCM5481 |
57 | and BCM5482 PHYs. | ||
57 | 58 | ||
58 | config ICPLUS_PHY | 59 | config ICPLUS_PHY |
59 | tristate "Drivers for ICPlus PHYs" | 60 | tristate "Drivers for ICPlus PHYs" |
@@ -83,4 +84,10 @@ config MDIO_BITBANG | |||
83 | 84 | ||
84 | If in doubt, say N. | 85 | If in doubt, say N. |
85 | 86 | ||
87 | config MDIO_OF_GPIO | ||
88 | tristate "Support for GPIO lib-based bitbanged MDIO buses" | ||
89 | depends on MDIO_BITBANG && OF_GPIO | ||
90 | ---help--- | ||
91 | Supports GPIO lib-based MDIO busses. | ||
92 | |||
86 | endif # PHYLIB | 93 | endif # PHYLIB |
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 5997d6ef702b..eee329fa6f53 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile | |||
@@ -15,3 +15,4 @@ obj-$(CONFIG_ICPLUS_PHY) += icplus.o | |||
15 | obj-$(CONFIG_REALTEK_PHY) += realtek.o | 15 | obj-$(CONFIG_REALTEK_PHY) += realtek.o |
16 | obj-$(CONFIG_FIXED_PHY) += fixed.o | 16 | obj-$(CONFIG_FIXED_PHY) += fixed.o |
17 | obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o | 17 | obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o |
18 | obj-$(CONFIG_MDIO_OF_GPIO) += mdio-ofgpio.o | ||
diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 60c5cfe96918..4b4dc98ad165 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c | |||
@@ -24,6 +24,12 @@ | |||
24 | #define MII_BCM54XX_ESR 0x11 /* BCM54xx extended status register */ | 24 | #define MII_BCM54XX_ESR 0x11 /* BCM54xx extended status register */ |
25 | #define MII_BCM54XX_ESR_IS 0x1000 /* Interrupt status */ | 25 | #define MII_BCM54XX_ESR_IS 0x1000 /* Interrupt status */ |
26 | 26 | ||
27 | #define MII_BCM54XX_EXP_DATA 0x15 /* Expansion register data */ | ||
28 | #define MII_BCM54XX_EXP_SEL 0x17 /* Expansion register select */ | ||
29 | #define MII_BCM54XX_EXP_SEL_SSD 0x0e00 /* Secondary SerDes select */ | ||
30 | #define MII_BCM54XX_EXP_SEL_ER 0x0f00 /* Expansion register select */ | ||
31 | |||
32 | #define MII_BCM54XX_AUX_CTL 0x18 /* Auxiliary control register */ | ||
27 | #define MII_BCM54XX_ISR 0x1a /* BCM54xx interrupt status register */ | 33 | #define MII_BCM54XX_ISR 0x1a /* BCM54xx interrupt status register */ |
28 | #define MII_BCM54XX_IMR 0x1b /* BCM54xx interrupt mask register */ | 34 | #define MII_BCM54XX_IMR 0x1b /* BCM54xx interrupt mask register */ |
29 | #define MII_BCM54XX_INT_CRCERR 0x0001 /* CRC error */ | 35 | #define MII_BCM54XX_INT_CRCERR 0x0001 /* CRC error */ |
@@ -42,10 +48,120 @@ | |||
42 | #define MII_BCM54XX_INT_MDIX 0x2000 /* MDIX status change */ | 48 | #define MII_BCM54XX_INT_MDIX 0x2000 /* MDIX status change */ |
43 | #define MII_BCM54XX_INT_PSERR 0x4000 /* Pair swap error */ | 49 | #define MII_BCM54XX_INT_PSERR 0x4000 /* Pair swap error */ |
44 | 50 | ||
51 | #define MII_BCM54XX_SHD 0x1c /* 0x1c shadow registers */ | ||
52 | #define MII_BCM54XX_SHD_WRITE 0x8000 | ||
53 | #define MII_BCM54XX_SHD_VAL(x) ((x & 0x1f) << 10) | ||
54 | #define MII_BCM54XX_SHD_DATA(x) ((x & 0x3ff) << 0) | ||
55 | |||
56 | /* | ||
57 | * Broadcom LED source encodings. These are used in BCM5461, BCM5481, | ||
58 | * BCM5482, and possibly some others. | ||
59 | */ | ||
60 | #define BCM_LED_SRC_LINKSPD1 0x0 | ||
61 | #define BCM_LED_SRC_LINKSPD2 0x1 | ||
62 | #define BCM_LED_SRC_XMITLED 0x2 | ||
63 | #define BCM_LED_SRC_ACTIVITYLED 0x3 | ||
64 | #define BCM_LED_SRC_FDXLED 0x4 | ||
65 | #define BCM_LED_SRC_SLAVE 0x5 | ||
66 | #define BCM_LED_SRC_INTR 0x6 | ||
67 | #define BCM_LED_SRC_QUALITY 0x7 | ||
68 | #define BCM_LED_SRC_RCVLED 0x8 | ||
69 | #define BCM_LED_SRC_MULTICOLOR1 0xa | ||
70 | #define BCM_LED_SRC_OPENSHORT 0xb | ||
71 | #define BCM_LED_SRC_OFF 0xe /* Tied high */ | ||
72 | #define BCM_LED_SRC_ON 0xf /* Tied low */ | ||
73 | |||
74 | /* | ||
75 | * BCM5482: Shadow registers | ||
76 | * Shadow values go into bits [14:10] of register 0x1c to select a shadow | ||
77 | * register to access. | ||
78 | */ | ||
79 | #define BCM5482_SHD_LEDS1 0x0d /* 01101: LED Selector 1 */ | ||
80 | /* LED3 / ~LINKSPD[2] selector */ | ||
81 | #define BCM5482_SHD_LEDS1_LED3(src) ((src & 0xf) << 4) | ||
82 | /* LED1 / ~LINKSPD[1] selector */ | ||
83 | #define BCM5482_SHD_LEDS1_LED1(src) ((src & 0xf) << 0) | ||
84 | #define BCM5482_SHD_SSD 0x14 /* 10100: Secondary SerDes control */ | ||
85 | #define BCM5482_SHD_SSD_LEDM 0x0008 /* SSD LED Mode enable */ | ||
86 | #define BCM5482_SHD_SSD_EN 0x0001 /* SSD enable */ | ||
87 | #define BCM5482_SHD_MODE 0x1f /* 11111: Mode Control Register */ | ||
88 | #define BCM5482_SHD_MODE_1000BX 0x0001 /* Enable 1000BASE-X registers */ | ||
89 | |||
90 | /* | ||
91 | * BCM5482: Secondary SerDes registers | ||
92 | */ | ||
93 | #define BCM5482_SSD_1000BX_CTL 0x00 /* 1000BASE-X Control */ | ||
94 | #define BCM5482_SSD_1000BX_CTL_PWRDOWN 0x0800 /* Power-down SSD */ | ||
95 | #define BCM5482_SSD_SGMII_SLAVE 0x15 /* SGMII Slave Register */ | ||
96 | #define BCM5482_SSD_SGMII_SLAVE_EN 0x0002 /* Slave mode enable */ | ||
97 | #define BCM5482_SSD_SGMII_SLAVE_AD 0x0001 /* Slave auto-detection */ | ||
98 | |||
99 | /* | ||
100 | * Device flags for PHYs that can be configured for different operating | ||
101 | * modes. | ||
102 | */ | ||
103 | #define PHY_BCM_FLAGS_VALID 0x80000000 | ||
104 | #define PHY_BCM_FLAGS_INTF_XAUI 0x00000020 | ||
105 | #define PHY_BCM_FLAGS_INTF_SGMII 0x00000010 | ||
106 | #define PHY_BCM_FLAGS_MODE_1000BX 0x00000002 | ||
107 | #define PHY_BCM_FLAGS_MODE_COPPER 0x00000001 | ||
108 | |||
45 | MODULE_DESCRIPTION("Broadcom PHY driver"); | 109 | MODULE_DESCRIPTION("Broadcom PHY driver"); |
46 | MODULE_AUTHOR("Maciej W. Rozycki"); | 110 | MODULE_AUTHOR("Maciej W. Rozycki"); |
47 | MODULE_LICENSE("GPL"); | 111 | MODULE_LICENSE("GPL"); |
48 | 112 | ||
113 | /* | ||
114 | * Indirect register access functions for the 1000BASE-T/100BASE-TX/10BASE-T | ||
115 | * 0x1c shadow registers. | ||
116 | */ | ||
117 | static int bcm54xx_shadow_read(struct phy_device *phydev, u16 shadow) | ||
118 | { | ||
119 | phy_write(phydev, MII_BCM54XX_SHD, MII_BCM54XX_SHD_VAL(shadow)); | ||
120 | return MII_BCM54XX_SHD_DATA(phy_read(phydev, MII_BCM54XX_SHD)); | ||
121 | } | ||
122 | |||
123 | static int bcm54xx_shadow_write(struct phy_device *phydev, u16 shadow, u16 val) | ||
124 | { | ||
125 | return phy_write(phydev, MII_BCM54XX_SHD, | ||
126 | MII_BCM54XX_SHD_WRITE | | ||
127 | MII_BCM54XX_SHD_VAL(shadow) | | ||
128 | MII_BCM54XX_SHD_DATA(val)); | ||
129 | } | ||
130 | |||
131 | /* | ||
132 | * Indirect register access functions for the Expansion Registers | ||
133 | * and Secondary SerDes registers (when sec_serdes=1). | ||
134 | */ | ||
135 | static int bcm54xx_exp_read(struct phy_device *phydev, | ||
136 | int sec_serdes, u8 regnum) | ||
137 | { | ||
138 | int val; | ||
139 | |||
140 | phy_write(phydev, MII_BCM54XX_EXP_SEL, | ||
141 | (sec_serdes ? MII_BCM54XX_EXP_SEL_SSD : | ||
142 | MII_BCM54XX_EXP_SEL_ER) | | ||
143 | regnum); | ||
144 | val = phy_read(phydev, MII_BCM54XX_EXP_DATA); | ||
145 | phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum); | ||
146 | |||
147 | return val; | ||
148 | } | ||
149 | |||
150 | static int bcm54xx_exp_write(struct phy_device *phydev, | ||
151 | int sec_serdes, u8 regnum, u16 val) | ||
152 | { | ||
153 | int ret; | ||
154 | |||
155 | phy_write(phydev, MII_BCM54XX_EXP_SEL, | ||
156 | (sec_serdes ? MII_BCM54XX_EXP_SEL_SSD : | ||
157 | MII_BCM54XX_EXP_SEL_ER) | | ||
158 | regnum); | ||
159 | ret = phy_write(phydev, MII_BCM54XX_EXP_DATA, val); | ||
160 | phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum); | ||
161 | |||
162 | return ret; | ||
163 | } | ||
164 | |||
49 | static int bcm54xx_config_init(struct phy_device *phydev) | 165 | static int bcm54xx_config_init(struct phy_device *phydev) |
50 | { | 166 | { |
51 | int reg, err; | 167 | int reg, err; |
@@ -70,6 +186,87 @@ static int bcm54xx_config_init(struct phy_device *phydev) | |||
70 | return 0; | 186 | return 0; |
71 | } | 187 | } |
72 | 188 | ||
189 | static int bcm5482_config_init(struct phy_device *phydev) | ||
190 | { | ||
191 | int err, reg; | ||
192 | |||
193 | err = bcm54xx_config_init(phydev); | ||
194 | |||
195 | if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) { | ||
196 | /* | ||
197 | * Enable secondary SerDes and its use as an LED source | ||
198 | */ | ||
199 | reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_SSD); | ||
200 | bcm54xx_shadow_write(phydev, BCM5482_SHD_SSD, | ||
201 | reg | | ||
202 | BCM5482_SHD_SSD_LEDM | | ||
203 | BCM5482_SHD_SSD_EN); | ||
204 | |||
205 | /* | ||
206 | * Enable SGMII slave mode and auto-detection | ||
207 | */ | ||
208 | reg = bcm54xx_exp_read(phydev, 1, BCM5482_SSD_SGMII_SLAVE); | ||
209 | bcm54xx_exp_write(phydev, 1, BCM5482_SSD_SGMII_SLAVE, | ||
210 | reg | | ||
211 | BCM5482_SSD_SGMII_SLAVE_EN | | ||
212 | BCM5482_SSD_SGMII_SLAVE_AD); | ||
213 | |||
214 | /* | ||
215 | * Disable secondary SerDes powerdown | ||
216 | */ | ||
217 | reg = bcm54xx_exp_read(phydev, 1, BCM5482_SSD_1000BX_CTL); | ||
218 | bcm54xx_exp_write(phydev, 1, BCM5482_SSD_1000BX_CTL, | ||
219 | reg & ~BCM5482_SSD_1000BX_CTL_PWRDOWN); | ||
220 | |||
221 | /* | ||
222 | * Select 1000BASE-X register set (primary SerDes) | ||
223 | */ | ||
224 | reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_MODE); | ||
225 | bcm54xx_shadow_write(phydev, BCM5482_SHD_MODE, | ||
226 | reg | BCM5482_SHD_MODE_1000BX); | ||
227 | |||
228 | /* | ||
229 | * LED1=ACTIVITYLED, LED3=LINKSPD[2] | ||
230 | * (Use LED1 as secondary SerDes ACTIVITY LED) | ||
231 | */ | ||
232 | bcm54xx_shadow_write(phydev, BCM5482_SHD_LEDS1, | ||
233 | BCM5482_SHD_LEDS1_LED1(BCM_LED_SRC_ACTIVITYLED) | | ||
234 | BCM5482_SHD_LEDS1_LED3(BCM_LED_SRC_LINKSPD2)); | ||
235 | |||
236 | /* | ||
237 | * Auto-negotiation doesn't seem to work quite right | ||
238 | * in this mode, so we disable it and force it to the | ||
239 | * right speed/duplex setting. Only 'link status' | ||
240 | * is important. | ||
241 | */ | ||
242 | phydev->autoneg = AUTONEG_DISABLE; | ||
243 | phydev->speed = SPEED_1000; | ||
244 | phydev->duplex = DUPLEX_FULL; | ||
245 | } | ||
246 | |||
247 | return err; | ||
248 | } | ||
249 | |||
250 | static int bcm5482_read_status(struct phy_device *phydev) | ||
251 | { | ||
252 | int err; | ||
253 | |||
254 | err = genphy_read_status(phydev); | ||
255 | |||
256 | if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) { | ||
257 | /* | ||
258 | * Only link status matters for 1000Base-X mode, so force | ||
259 | * 1000 Mbit/s full-duplex status | ||
260 | */ | ||
261 | if (phydev->link) { | ||
262 | phydev->speed = SPEED_1000; | ||
263 | phydev->duplex = DUPLEX_FULL; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | return err; | ||
268 | } | ||
269 | |||
73 | static int bcm54xx_ack_interrupt(struct phy_device *phydev) | 270 | static int bcm54xx_ack_interrupt(struct phy_device *phydev) |
74 | { | 271 | { |
75 | int reg; | 272 | int reg; |
@@ -210,9 +407,9 @@ static struct phy_driver bcm5482_driver = { | |||
210 | .name = "Broadcom BCM5482", | 407 | .name = "Broadcom BCM5482", |
211 | .features = PHY_GBIT_FEATURES, | 408 | .features = PHY_GBIT_FEATURES, |
212 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, | 409 | .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, |
213 | .config_init = bcm54xx_config_init, | 410 | .config_init = bcm5482_config_init, |
214 | .config_aneg = genphy_config_aneg, | 411 | .config_aneg = genphy_config_aneg, |
215 | .read_status = genphy_read_status, | 412 | .read_status = bcm5482_read_status, |
216 | .ack_interrupt = bcm54xx_ack_interrupt, | 413 | .ack_interrupt = bcm54xx_ack_interrupt, |
217 | .config_intr = bcm54xx_config_intr, | 414 | .config_intr = bcm54xx_config_intr, |
218 | .driver = { .owner = THIS_MODULE }, | 415 | .driver = { .owner = THIS_MODULE }, |
diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c index 2747b1f89ffe..c01b78013ddc 100644 --- a/drivers/net/phy/mdio-bitbang.c +++ b/drivers/net/phy/mdio-bitbang.c | |||
@@ -177,6 +177,7 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl) | |||
177 | 177 | ||
178 | return bus; | 178 | return bus; |
179 | } | 179 | } |
180 | EXPORT_SYMBOL(alloc_mdio_bitbang); | ||
180 | 181 | ||
181 | void free_mdio_bitbang(struct mii_bus *bus) | 182 | void free_mdio_bitbang(struct mii_bus *bus) |
182 | { | 183 | { |
@@ -185,5 +186,6 @@ void free_mdio_bitbang(struct mii_bus *bus) | |||
185 | module_put(ctrl->ops->owner); | 186 | module_put(ctrl->ops->owner); |
186 | kfree(bus); | 187 | kfree(bus); |
187 | } | 188 | } |
189 | EXPORT_SYMBOL(free_mdio_bitbang); | ||
188 | 190 | ||
189 | MODULE_LICENSE("GPL"); | 191 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/net/phy/mdio-ofgpio.c b/drivers/net/phy/mdio-ofgpio.c new file mode 100644 index 000000000000..7edfc0c34835 --- /dev/null +++ b/drivers/net/phy/mdio-ofgpio.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * OpenFirmware GPIO based MDIO bitbang driver. | ||
3 | * | ||
4 | * Copyright (c) 2008 CSE Semaphore Belgium. | ||
5 | * by Laurent Pinchart <laurentp@cse-semaphore.com> | ||
6 | * | ||
7 | * Based on earlier work by | ||
8 | * | ||
9 | * Copyright (c) 2003 Intracom S.A. | ||
10 | * by Pantelis Antoniou <panto@intracom.gr> | ||
11 | * | ||
12 | * 2005 (c) MontaVista Software, Inc. | ||
13 | * Vitaly Bordug <vbordug@ru.mvista.com> | ||
14 | * | ||
15 | * This file is licensed under the terms of the GNU General Public License | ||
16 | * version 2. This program is licensed "as is" without any warranty of any | ||
17 | * kind, whether express or implied. | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/mdio-bitbang.h> | ||
25 | #include <linux/of_gpio.h> | ||
26 | #include <linux/of_platform.h> | ||
27 | |||
28 | struct mdio_gpio_info { | ||
29 | struct mdiobb_ctrl ctrl; | ||
30 | int mdc, mdio; | ||
31 | }; | ||
32 | |||
33 | static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir) | ||
34 | { | ||
35 | struct mdio_gpio_info *bitbang = | ||
36 | container_of(ctrl, struct mdio_gpio_info, ctrl); | ||
37 | |||
38 | if (dir) | ||
39 | gpio_direction_output(bitbang->mdio, 1); | ||
40 | else | ||
41 | gpio_direction_input(bitbang->mdio); | ||
42 | } | ||
43 | |||
44 | static int mdio_read(struct mdiobb_ctrl *ctrl) | ||
45 | { | ||
46 | struct mdio_gpio_info *bitbang = | ||
47 | container_of(ctrl, struct mdio_gpio_info, ctrl); | ||
48 | |||
49 | return gpio_get_value(bitbang->mdio); | ||
50 | } | ||
51 | |||
52 | static void mdio(struct mdiobb_ctrl *ctrl, int what) | ||
53 | { | ||
54 | struct mdio_gpio_info *bitbang = | ||
55 | container_of(ctrl, struct mdio_gpio_info, ctrl); | ||
56 | |||
57 | gpio_set_value(bitbang->mdio, what); | ||
58 | } | ||
59 | |||
60 | static void mdc(struct mdiobb_ctrl *ctrl, int what) | ||
61 | { | ||
62 | struct mdio_gpio_info *bitbang = | ||
63 | container_of(ctrl, struct mdio_gpio_info, ctrl); | ||
64 | |||
65 | gpio_set_value(bitbang->mdc, what); | ||
66 | } | ||
67 | |||
68 | static struct mdiobb_ops mdio_gpio_ops = { | ||
69 | .owner = THIS_MODULE, | ||
70 | .set_mdc = mdc, | ||
71 | .set_mdio_dir = mdio_dir, | ||
72 | .set_mdio_data = mdio, | ||
73 | .get_mdio_data = mdio_read, | ||
74 | }; | ||
75 | |||
76 | static int __devinit mdio_ofgpio_bitbang_init(struct mii_bus *bus, | ||
77 | struct device_node *np) | ||
78 | { | ||
79 | struct mdio_gpio_info *bitbang = bus->priv; | ||
80 | |||
81 | bitbang->mdc = of_get_gpio(np, 0); | ||
82 | bitbang->mdio = of_get_gpio(np, 1); | ||
83 | |||
84 | if (bitbang->mdc < 0 || bitbang->mdio < 0) | ||
85 | return -ENODEV; | ||
86 | |||
87 | snprintf(bus->id, MII_BUS_ID_SIZE, "%x", bitbang->mdc); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static void __devinit add_phy(struct mii_bus *bus, struct device_node *np) | ||
92 | { | ||
93 | const u32 *data; | ||
94 | int len, id, irq; | ||
95 | |||
96 | data = of_get_property(np, "reg", &len); | ||
97 | if (!data || len != 4) | ||
98 | return; | ||
99 | |||
100 | id = *data; | ||
101 | bus->phy_mask &= ~(1 << id); | ||
102 | |||
103 | irq = of_irq_to_resource(np, 0, NULL); | ||
104 | if (irq != NO_IRQ) | ||
105 | bus->irq[id] = irq; | ||
106 | } | ||
107 | |||
108 | static int __devinit mdio_ofgpio_probe(struct of_device *ofdev, | ||
109 | const struct of_device_id *match) | ||
110 | { | ||
111 | struct device_node *np = NULL; | ||
112 | struct mii_bus *new_bus; | ||
113 | struct mdio_gpio_info *bitbang; | ||
114 | int ret = -ENOMEM; | ||
115 | int i; | ||
116 | |||
117 | bitbang = kzalloc(sizeof(struct mdio_gpio_info), GFP_KERNEL); | ||
118 | if (!bitbang) | ||
119 | goto out; | ||
120 | |||
121 | bitbang->ctrl.ops = &mdio_gpio_ops; | ||
122 | |||
123 | new_bus = alloc_mdio_bitbang(&bitbang->ctrl); | ||
124 | if (!new_bus) | ||
125 | goto out_free_priv; | ||
126 | |||
127 | new_bus->name = "GPIO Bitbanged MII", | ||
128 | |||
129 | ret = mdio_ofgpio_bitbang_init(new_bus, ofdev->node); | ||
130 | if (ret) | ||
131 | goto out_free_bus; | ||
132 | |||
133 | new_bus->phy_mask = ~0; | ||
134 | new_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); | ||
135 | if (!new_bus->irq) | ||
136 | goto out_free_bus; | ||
137 | |||
138 | for (i = 0; i < PHY_MAX_ADDR; i++) | ||
139 | new_bus->irq[i] = -1; | ||
140 | |||
141 | while ((np = of_get_next_child(ofdev->node, np))) | ||
142 | if (!strcmp(np->type, "ethernet-phy")) | ||
143 | add_phy(new_bus, np); | ||
144 | |||
145 | new_bus->dev = &ofdev->dev; | ||
146 | dev_set_drvdata(&ofdev->dev, new_bus); | ||
147 | |||
148 | ret = mdiobus_register(new_bus); | ||
149 | if (ret) | ||
150 | goto out_free_irqs; | ||
151 | |||
152 | return 0; | ||
153 | |||
154 | out_free_irqs: | ||
155 | dev_set_drvdata(&ofdev->dev, NULL); | ||
156 | kfree(new_bus->irq); | ||
157 | out_free_bus: | ||
158 | kfree(new_bus); | ||
159 | out_free_priv: | ||
160 | free_mdio_bitbang(new_bus); | ||
161 | out: | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | static int mdio_ofgpio_remove(struct of_device *ofdev) | ||
166 | { | ||
167 | struct mii_bus *bus = dev_get_drvdata(&ofdev->dev); | ||
168 | struct mdio_gpio_info *bitbang = bus->priv; | ||
169 | |||
170 | mdiobus_unregister(bus); | ||
171 | free_mdio_bitbang(bus); | ||
172 | dev_set_drvdata(&ofdev->dev, NULL); | ||
173 | kfree(bus->irq); | ||
174 | kfree(bitbang); | ||
175 | kfree(bus); | ||
176 | |||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static struct of_device_id mdio_ofgpio_match[] = { | ||
181 | { | ||
182 | .compatible = "virtual,mdio-gpio", | ||
183 | }, | ||
184 | {}, | ||
185 | }; | ||
186 | |||
187 | static struct of_platform_driver mdio_ofgpio_driver = { | ||
188 | .name = "mdio-gpio", | ||
189 | .match_table = mdio_ofgpio_match, | ||
190 | .probe = mdio_ofgpio_probe, | ||
191 | .remove = mdio_ofgpio_remove, | ||
192 | }; | ||
193 | |||
194 | static int mdio_ofgpio_init(void) | ||
195 | { | ||
196 | return of_register_platform_driver(&mdio_ofgpio_driver); | ||
197 | } | ||
198 | |||
199 | static void mdio_ofgpio_exit(void) | ||
200 | { | ||
201 | of_unregister_platform_driver(&mdio_ofgpio_driver); | ||
202 | } | ||
203 | |||
204 | module_init(mdio_ofgpio_init); | ||
205 | module_exit(mdio_ofgpio_exit); | ||