AR8216: make ARL age time configurable
[openwrt.git] / target / linux / generic / files / drivers / net / phy / b53 / b53_phy_fixup.c
1 /*
2  * B53 PHY Fixup call
3  *
4  * Copyright (C) 2013 Jonas Gorski <jogo@openwrt.org>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/phy.h>
22
23 #define B53_PSEUDO_PHY  0x1e /* Register Access Pseudo PHY */
24
25 #define B53_BRCM_OUI_1  0x0143bc00
26 #define B53_BRCM_OUI_2  0x03625c00
27 #define B53_BRCM_OUI_3  0x00406000
28
29 static int b53_phy_fixup(struct phy_device *dev)
30 {
31         u32 phy_id;
32         struct mii_bus *bus = dev->bus;
33
34         if (dev->addr != B53_PSEUDO_PHY)
35                 return 0;
36
37         /* read the first port's id */
38         phy_id = mdiobus_read(bus, 0, 2) << 16;
39         phy_id |= mdiobus_read(bus, 0, 3);
40
41         if ((phy_id & 0xfffffc00) == B53_BRCM_OUI_1 ||
42             (phy_id & 0xfffffc00) == B53_BRCM_OUI_2 ||
43             (phy_id & 0xfffffc00) == B53_BRCM_OUI_3) {
44                 dev->phy_id = phy_id;
45         }
46
47         return 0;
48 }
49
50 int __init b53_phy_fixup_register(void)
51 {
52         return phy_register_fixup_for_id(PHY_ANY_ID, b53_phy_fixup);
53 }
54
55 subsys_initcall(b53_phy_fixup_register);