diff options
Diffstat (limited to 'drivers/net/phy')
-rw-r--r-- | drivers/net/phy/cicada.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/davicom.c | 2 | ||||
-rw-r--r-- | drivers/net/phy/dp83640.c | 36 | ||||
-rw-r--r-- | drivers/net/phy/icplus.c | 2 | ||||
-rw-r--r-- | drivers/net/phy/lxt.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/marvell.c | 22 | ||||
-rw-r--r-- | drivers/net/phy/mdio-gpio.c | 1 | ||||
-rw-r--r-- | drivers/net/phy/mdio-moxart.c | 1 | ||||
-rw-r--r-- | drivers/net/phy/mdio-mux-gpio.c | 1 | ||||
-rw-r--r-- | drivers/net/phy/mdio-mux-mmioreg.c | 1 | ||||
-rw-r--r-- | drivers/net/phy/mdio-octeon.c | 1 | ||||
-rw-r--r-- | drivers/net/phy/mdio-sun4i.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 36 | ||||
-rw-r--r-- | drivers/net/phy/micrel.c | 4 | ||||
-rw-r--r-- | drivers/net/phy/phy.c | 440 | ||||
-rw-r--r-- | drivers/net/phy/phy_device.c | 466 | ||||
-rw-r--r-- | drivers/net/phy/spi_ks8995.c | 7 |
17 files changed, 564 insertions, 468 deletions
diff --git a/drivers/net/phy/cicada.c b/drivers/net/phy/cicada.c index 313a0377f68f..b57ce0cc9657 100644 --- a/drivers/net/phy/cicada.c +++ b/drivers/net/phy/cicada.c | |||
@@ -92,8 +92,8 @@ static int cis820x_config_intr(struct phy_device *phydev) | |||
92 | { | 92 | { |
93 | int err; | 93 | int err; |
94 | 94 | ||
95 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | 95 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
96 | err = phy_write(phydev, MII_CIS8201_IMASK, | 96 | err = phy_write(phydev, MII_CIS8201_IMASK, |
97 | MII_CIS8201_IMASK_MASK); | 97 | MII_CIS8201_IMASK_MASK); |
98 | else | 98 | else |
99 | err = phy_write(phydev, MII_CIS8201_IMASK, 0); | 99 | err = phy_write(phydev, MII_CIS8201_IMASK, 0); |
diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c index 383e8338ad86..d2c08f625a41 100644 --- a/drivers/net/phy/davicom.c +++ b/drivers/net/phy/davicom.c | |||
@@ -72,7 +72,7 @@ static int dm9161_config_intr(struct phy_device *phydev) | |||
72 | if (temp < 0) | 72 | if (temp < 0) |
73 | return temp; | 73 | return temp; |
74 | 74 | ||
75 | if(PHY_INTERRUPT_ENABLED == phydev->interrupts ) | 75 | if (PHY_INTERRUPT_ENABLED == phydev->interrupts) |
76 | temp &= ~(MII_DM9161_INTR_STOP); | 76 | temp &= ~(MII_DM9161_INTR_STOP); |
77 | else | 77 | else |
78 | temp |= MII_DM9161_INTR_STOP; | 78 | temp |= MII_DM9161_INTR_STOP; |
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c index 7490b6c866e6..98e7cbf720a5 100644 --- a/drivers/net/phy/dp83640.c +++ b/drivers/net/phy/dp83640.c | |||
@@ -437,7 +437,10 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp, | |||
437 | if (on) { | 437 | if (on) { |
438 | gpio_num = gpio_tab[EXTTS0_GPIO + index]; | 438 | gpio_num = gpio_tab[EXTTS0_GPIO + index]; |
439 | evnt |= (gpio_num & EVNT_GPIO_MASK) << EVNT_GPIO_SHIFT; | 439 | evnt |= (gpio_num & EVNT_GPIO_MASK) << EVNT_GPIO_SHIFT; |
440 | evnt |= EVNT_RISE; | 440 | if (rq->extts.flags & PTP_FALLING_EDGE) |
441 | evnt |= EVNT_FALL; | ||
442 | else | ||
443 | evnt |= EVNT_RISE; | ||
441 | } | 444 | } |
442 | ext_write(0, phydev, PAGE5, PTP_EVNT, evnt); | 445 | ext_write(0, phydev, PAGE5, PTP_EVNT, evnt); |
443 | return 0; | 446 | return 0; |
@@ -851,8 +854,8 @@ static int match(struct sk_buff *skb, unsigned int type, struct rxts *rxts) | |||
851 | 854 | ||
852 | seqid = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID); | 855 | seqid = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID); |
853 | 856 | ||
854 | return (rxts->msgtype == (*msgtype & 0xf) && | 857 | return rxts->msgtype == (*msgtype & 0xf) && |
855 | rxts->seqid == ntohs(*seqid)); | 858 | rxts->seqid == ntohs(*seqid); |
856 | } | 859 | } |
857 | 860 | ||
858 | static void dp83640_free_clocks(void) | 861 | static void dp83640_free_clocks(void) |
@@ -1003,11 +1006,6 @@ static int dp83640_probe(struct phy_device *phydev) | |||
1003 | } else | 1006 | } else |
1004 | list_add_tail(&dp83640->list, &clock->phylist); | 1007 | list_add_tail(&dp83640->list, &clock->phylist); |
1005 | 1008 | ||
1006 | if (clock->chosen && !list_empty(&clock->phylist)) | ||
1007 | recalibrate(clock); | ||
1008 | else | ||
1009 | enable_broadcast(dp83640->phydev, clock->page, 1); | ||
1010 | |||
1011 | dp83640_clock_put(clock); | 1009 | dp83640_clock_put(clock); |
1012 | return 0; | 1010 | return 0; |
1013 | 1011 | ||
@@ -1058,6 +1056,21 @@ static void dp83640_remove(struct phy_device *phydev) | |||
1058 | kfree(dp83640); | 1056 | kfree(dp83640); |
1059 | } | 1057 | } |
1060 | 1058 | ||
1059 | static int dp83640_config_init(struct phy_device *phydev) | ||
1060 | { | ||
1061 | struct dp83640_private *dp83640 = phydev->priv; | ||
1062 | struct dp83640_clock *clock = dp83640->clock; | ||
1063 | |||
1064 | if (clock->chosen && !list_empty(&clock->phylist)) | ||
1065 | recalibrate(clock); | ||
1066 | else | ||
1067 | enable_broadcast(phydev, clock->page, 1); | ||
1068 | |||
1069 | enable_status_frames(phydev, true); | ||
1070 | ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE); | ||
1071 | return 0; | ||
1072 | } | ||
1073 | |||
1061 | static int dp83640_ack_interrupt(struct phy_device *phydev) | 1074 | static int dp83640_ack_interrupt(struct phy_device *phydev) |
1062 | { | 1075 | { |
1063 | int err = phy_read(phydev, MII_DP83640_MISR); | 1076 | int err = phy_read(phydev, MII_DP83640_MISR); |
@@ -1195,11 +1208,6 @@ static int dp83640_hwtstamp(struct phy_device *phydev, struct ifreq *ifr) | |||
1195 | 1208 | ||
1196 | mutex_lock(&dp83640->clock->extreg_lock); | 1209 | mutex_lock(&dp83640->clock->extreg_lock); |
1197 | 1210 | ||
1198 | if (dp83640->hwts_tx_en || dp83640->hwts_rx_en) { | ||
1199 | enable_status_frames(phydev, true); | ||
1200 | ext_write(0, phydev, PAGE4, PTP_CTL, PTP_ENABLE); | ||
1201 | } | ||
1202 | |||
1203 | ext_write(0, phydev, PAGE5, PTP_TXCFG0, txcfg0); | 1211 | ext_write(0, phydev, PAGE5, PTP_TXCFG0, txcfg0); |
1204 | ext_write(0, phydev, PAGE5, PTP_RXCFG0, rxcfg0); | 1212 | ext_write(0, phydev, PAGE5, PTP_RXCFG0, rxcfg0); |
1205 | 1213 | ||
@@ -1281,6 +1289,7 @@ static void dp83640_txtstamp(struct phy_device *phydev, | |||
1281 | } | 1289 | } |
1282 | /* fall through */ | 1290 | /* fall through */ |
1283 | case HWTSTAMP_TX_ON: | 1291 | case HWTSTAMP_TX_ON: |
1292 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | ||
1284 | skb_queue_tail(&dp83640->tx_queue, skb); | 1293 | skb_queue_tail(&dp83640->tx_queue, skb); |
1285 | schedule_work(&dp83640->ts_work); | 1294 | schedule_work(&dp83640->ts_work); |
1286 | break; | 1295 | break; |
@@ -1330,6 +1339,7 @@ static struct phy_driver dp83640_driver = { | |||
1330 | .flags = PHY_HAS_INTERRUPT, | 1339 | .flags = PHY_HAS_INTERRUPT, |
1331 | .probe = dp83640_probe, | 1340 | .probe = dp83640_probe, |
1332 | .remove = dp83640_remove, | 1341 | .remove = dp83640_remove, |
1342 | .config_init = dp83640_config_init, | ||
1333 | .config_aneg = genphy_config_aneg, | 1343 | .config_aneg = genphy_config_aneg, |
1334 | .read_status = genphy_read_status, | 1344 | .read_status = genphy_read_status, |
1335 | .ack_interrupt = dp83640_ack_interrupt, | 1345 | .ack_interrupt = dp83640_ack_interrupt, |
diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c index b5ddd5077a80..97bf58bf4939 100644 --- a/drivers/net/phy/icplus.c +++ b/drivers/net/phy/icplus.c | |||
@@ -48,7 +48,7 @@ MODULE_LICENSE("GPL"); | |||
48 | static int ip175c_config_init(struct phy_device *phydev) | 48 | static int ip175c_config_init(struct phy_device *phydev) |
49 | { | 49 | { |
50 | int err, i; | 50 | int err, i; |
51 | static int full_reset_performed = 0; | 51 | static int full_reset_performed; |
52 | 52 | ||
53 | if (full_reset_performed == 0) { | 53 | if (full_reset_performed == 0) { |
54 | 54 | ||
diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c index ff2e45e9cb54..9108f3191701 100644 --- a/drivers/net/phy/lxt.c +++ b/drivers/net/phy/lxt.c | |||
@@ -82,7 +82,7 @@ static int lxt970_config_intr(struct phy_device *phydev) | |||
82 | { | 82 | { |
83 | int err; | 83 | int err; |
84 | 84 | ||
85 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | 85 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
86 | err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN); | 86 | err = phy_write(phydev, MII_LXT970_IER, MII_LXT970_IER_IEN); |
87 | else | 87 | else |
88 | err = phy_write(phydev, MII_LXT970_IER, 0); | 88 | err = phy_write(phydev, MII_LXT970_IER, 0); |
@@ -114,7 +114,7 @@ static int lxt971_config_intr(struct phy_device *phydev) | |||
114 | { | 114 | { |
115 | int err; | 115 | int err; |
116 | 116 | ||
117 | if(phydev->interrupts == PHY_INTERRUPT_ENABLED) | 117 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) |
118 | err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN); | 118 | err = phy_write(phydev, MII_LXT971_IER, MII_LXT971_IER_IEN); |
119 | else | 119 | else |
120 | err = phy_write(phydev, MII_LXT971_IER, 0); | 120 | err = phy_write(phydev, MII_LXT971_IER, 0); |
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 2e3c778ea9bf..bd37e45c89c0 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c | |||
@@ -894,6 +894,8 @@ static struct phy_driver marvell_drivers[] = { | |||
894 | .read_status = &genphy_read_status, | 894 | .read_status = &genphy_read_status, |
895 | .ack_interrupt = &marvell_ack_interrupt, | 895 | .ack_interrupt = &marvell_ack_interrupt, |
896 | .config_intr = &marvell_config_intr, | 896 | .config_intr = &marvell_config_intr, |
897 | .resume = &genphy_resume, | ||
898 | .suspend = &genphy_suspend, | ||
897 | .driver = { .owner = THIS_MODULE }, | 899 | .driver = { .owner = THIS_MODULE }, |
898 | }, | 900 | }, |
899 | { | 901 | { |
@@ -907,6 +909,8 @@ static struct phy_driver marvell_drivers[] = { | |||
907 | .read_status = &genphy_read_status, | 909 | .read_status = &genphy_read_status, |
908 | .ack_interrupt = &marvell_ack_interrupt, | 910 | .ack_interrupt = &marvell_ack_interrupt, |
909 | .config_intr = &marvell_config_intr, | 911 | .config_intr = &marvell_config_intr, |
912 | .resume = &genphy_resume, | ||
913 | .suspend = &genphy_suspend, | ||
910 | .driver = { .owner = THIS_MODULE }, | 914 | .driver = { .owner = THIS_MODULE }, |
911 | }, | 915 | }, |
912 | { | 916 | { |
@@ -920,6 +924,8 @@ static struct phy_driver marvell_drivers[] = { | |||
920 | .read_status = &marvell_read_status, | 924 | .read_status = &marvell_read_status, |
921 | .ack_interrupt = &marvell_ack_interrupt, | 925 | .ack_interrupt = &marvell_ack_interrupt, |
922 | .config_intr = &marvell_config_intr, | 926 | .config_intr = &marvell_config_intr, |
927 | .resume = &genphy_resume, | ||
928 | .suspend = &genphy_suspend, | ||
923 | .driver = { .owner = THIS_MODULE }, | 929 | .driver = { .owner = THIS_MODULE }, |
924 | }, | 930 | }, |
925 | { | 931 | { |
@@ -933,6 +939,8 @@ static struct phy_driver marvell_drivers[] = { | |||
933 | .read_status = &genphy_read_status, | 939 | .read_status = &genphy_read_status, |
934 | .ack_interrupt = &marvell_ack_interrupt, | 940 | .ack_interrupt = &marvell_ack_interrupt, |
935 | .config_intr = &marvell_config_intr, | 941 | .config_intr = &marvell_config_intr, |
942 | .resume = &genphy_resume, | ||
943 | .suspend = &genphy_suspend, | ||
936 | .driver = {.owner = THIS_MODULE,}, | 944 | .driver = {.owner = THIS_MODULE,}, |
937 | }, | 945 | }, |
938 | { | 946 | { |
@@ -946,6 +954,8 @@ static struct phy_driver marvell_drivers[] = { | |||
946 | .ack_interrupt = &marvell_ack_interrupt, | 954 | .ack_interrupt = &marvell_ack_interrupt, |
947 | .config_intr = &marvell_config_intr, | 955 | .config_intr = &marvell_config_intr, |
948 | .did_interrupt = &m88e1121_did_interrupt, | 956 | .did_interrupt = &m88e1121_did_interrupt, |
957 | .resume = &genphy_resume, | ||
958 | .suspend = &genphy_suspend, | ||
949 | .driver = { .owner = THIS_MODULE }, | 959 | .driver = { .owner = THIS_MODULE }, |
950 | }, | 960 | }, |
951 | { | 961 | { |
@@ -961,6 +971,8 @@ static struct phy_driver marvell_drivers[] = { | |||
961 | .did_interrupt = &m88e1121_did_interrupt, | 971 | .did_interrupt = &m88e1121_did_interrupt, |
962 | .get_wol = &m88e1318_get_wol, | 972 | .get_wol = &m88e1318_get_wol, |
963 | .set_wol = &m88e1318_set_wol, | 973 | .set_wol = &m88e1318_set_wol, |
974 | .resume = &genphy_resume, | ||
975 | .suspend = &genphy_suspend, | ||
964 | .driver = { .owner = THIS_MODULE }, | 976 | .driver = { .owner = THIS_MODULE }, |
965 | }, | 977 | }, |
966 | { | 978 | { |
@@ -974,6 +986,8 @@ static struct phy_driver marvell_drivers[] = { | |||
974 | .read_status = &genphy_read_status, | 986 | .read_status = &genphy_read_status, |
975 | .ack_interrupt = &marvell_ack_interrupt, | 987 | .ack_interrupt = &marvell_ack_interrupt, |
976 | .config_intr = &marvell_config_intr, | 988 | .config_intr = &marvell_config_intr, |
989 | .resume = &genphy_resume, | ||
990 | .suspend = &genphy_suspend, | ||
977 | .driver = { .owner = THIS_MODULE }, | 991 | .driver = { .owner = THIS_MODULE }, |
978 | }, | 992 | }, |
979 | { | 993 | { |
@@ -987,6 +1001,8 @@ static struct phy_driver marvell_drivers[] = { | |||
987 | .read_status = &genphy_read_status, | 1001 | .read_status = &genphy_read_status, |
988 | .ack_interrupt = &marvell_ack_interrupt, | 1002 | .ack_interrupt = &marvell_ack_interrupt, |
989 | .config_intr = &marvell_config_intr, | 1003 | .config_intr = &marvell_config_intr, |
1004 | .resume = &genphy_resume, | ||
1005 | .suspend = &genphy_suspend, | ||
990 | .driver = { .owner = THIS_MODULE }, | 1006 | .driver = { .owner = THIS_MODULE }, |
991 | }, | 1007 | }, |
992 | { | 1008 | { |
@@ -1000,6 +1016,8 @@ static struct phy_driver marvell_drivers[] = { | |||
1000 | .read_status = &genphy_read_status, | 1016 | .read_status = &genphy_read_status, |
1001 | .ack_interrupt = &marvell_ack_interrupt, | 1017 | .ack_interrupt = &marvell_ack_interrupt, |
1002 | .config_intr = &marvell_config_intr, | 1018 | .config_intr = &marvell_config_intr, |
1019 | .resume = &genphy_resume, | ||
1020 | .suspend = &genphy_suspend, | ||
1003 | .driver = { .owner = THIS_MODULE }, | 1021 | .driver = { .owner = THIS_MODULE }, |
1004 | }, | 1022 | }, |
1005 | { | 1023 | { |
@@ -1013,6 +1031,8 @@ static struct phy_driver marvell_drivers[] = { | |||
1013 | .read_status = &genphy_read_status, | 1031 | .read_status = &genphy_read_status, |
1014 | .ack_interrupt = &marvell_ack_interrupt, | 1032 | .ack_interrupt = &marvell_ack_interrupt, |
1015 | .config_intr = &marvell_config_intr, | 1033 | .config_intr = &marvell_config_intr, |
1034 | .resume = &genphy_resume, | ||
1035 | .suspend = &genphy_suspend, | ||
1016 | .driver = { .owner = THIS_MODULE }, | 1036 | .driver = { .owner = THIS_MODULE }, |
1017 | }, | 1037 | }, |
1018 | { | 1038 | { |
@@ -1026,6 +1046,8 @@ static struct phy_driver marvell_drivers[] = { | |||
1026 | .ack_interrupt = &marvell_ack_interrupt, | 1046 | .ack_interrupt = &marvell_ack_interrupt, |
1027 | .config_intr = &marvell_config_intr, | 1047 | .config_intr = &marvell_config_intr, |
1028 | .did_interrupt = &m88e1121_did_interrupt, | 1048 | .did_interrupt = &m88e1121_did_interrupt, |
1049 | .resume = &genphy_resume, | ||
1050 | .suspend = &genphy_suspend, | ||
1029 | .driver = { .owner = THIS_MODULE }, | 1051 | .driver = { .owner = THIS_MODULE }, |
1030 | }, | 1052 | }, |
1031 | }; | 1053 | }; |
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c index 8004acbef2c9..e701433bf52f 100644 --- a/drivers/net/phy/mdio-gpio.c +++ b/drivers/net/phy/mdio-gpio.c | |||
@@ -22,7 +22,6 @@ | |||
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
27 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
28 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
diff --git a/drivers/net/phy/mdio-moxart.c b/drivers/net/phy/mdio-moxart.c index a5741cb0304e..f1fc51f655d9 100644 --- a/drivers/net/phy/mdio-moxart.c +++ b/drivers/net/phy/mdio-moxart.c | |||
@@ -8,7 +8,6 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
11 | #include <linux/init.h> | ||
12 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 12 | #include <linux/module.h> |
14 | #include <linux/mutex.h> | 13 | #include <linux/mutex.h> |
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index d2dd9e473e2c..096695163491 100644 --- a/drivers/net/phy/mdio-mux-gpio.c +++ b/drivers/net/phy/mdio-mux-gpio.c | |||
@@ -10,7 +10,6 @@ | |||
10 | #include <linux/device.h> | 10 | #include <linux/device.h> |
11 | #include <linux/of_mdio.h> | 11 | #include <linux/of_mdio.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/init.h> | ||
14 | #include <linux/phy.h> | 13 | #include <linux/phy.h> |
15 | #include <linux/mdio-mux.h> | 14 | #include <linux/mdio-mux.h> |
16 | #include <linux/of_gpio.h> | 15 | #include <linux/of_gpio.h> |
diff --git a/drivers/net/phy/mdio-mux-mmioreg.c b/drivers/net/phy/mdio-mux-mmioreg.c index f8e305d8da76..1656785ff339 100644 --- a/drivers/net/phy/mdio-mux-mmioreg.c +++ b/drivers/net/phy/mdio-mux-mmioreg.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/of_address.h> | 15 | #include <linux/of_address.h> |
16 | #include <linux/of_mdio.h> | 16 | #include <linux/of_mdio.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/phy.h> | 18 | #include <linux/phy.h> |
20 | #include <linux/mdio-mux.h> | 19 | #include <linux/mdio-mux.h> |
21 | 20 | ||
diff --git a/drivers/net/phy/mdio-octeon.c b/drivers/net/phy/mdio-octeon.c index 6aee02ed97ac..a51ed92fbada 100644 --- a/drivers/net/phy/mdio-octeon.c +++ b/drivers/net/phy/mdio-octeon.c | |||
@@ -10,7 +10,6 @@ | |||
10 | #include <linux/of_mdio.h> | 10 | #include <linux/of_mdio.h> |
11 | #include <linux/delay.h> | 11 | #include <linux/delay.h> |
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/init.h> | ||
14 | #include <linux/gfp.h> | 13 | #include <linux/gfp.h> |
15 | #include <linux/phy.h> | 14 | #include <linux/phy.h> |
16 | #include <linux/io.h> | 15 | #include <linux/io.h> |
diff --git a/drivers/net/phy/mdio-sun4i.c b/drivers/net/phy/mdio-sun4i.c index 18969b3ad8bb..9367acc84fbb 100644 --- a/drivers/net/phy/mdio-sun4i.c +++ b/drivers/net/phy/mdio-sun4i.c | |||
@@ -13,7 +13,6 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
18 | #include <linux/module.h> | 17 | #include <linux/module.h> |
19 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
@@ -171,6 +170,9 @@ static int sun4i_mdio_remove(struct platform_device *pdev) | |||
171 | } | 170 | } |
172 | 171 | ||
173 | static const struct of_device_id sun4i_mdio_dt_ids[] = { | 172 | static const struct of_device_id sun4i_mdio_dt_ids[] = { |
173 | { .compatible = "allwinner,sun4i-a10-mdio" }, | ||
174 | |||
175 | /* Deprecated */ | ||
174 | { .compatible = "allwinner,sun4i-mdio" }, | 176 | { .compatible = "allwinner,sun4i-mdio" }, |
175 | { } | 177 | { } |
176 | }; | 178 | }; |
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 56178761ce93..71e49000fbf3 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -1,7 +1,4 @@ | |||
1 | /* | 1 | /* MDIO Bus interface |
2 | * drivers/net/phy/mdio_bus.c | ||
3 | * | ||
4 | * MDIO Bus interface | ||
5 | * | 2 | * |
6 | * Author: Andy Fleming | 3 | * Author: Andy Fleming |
7 | * | 4 | * |
@@ -36,10 +33,10 @@ | |||
36 | #include <linux/mii.h> | 33 | #include <linux/mii.h> |
37 | #include <linux/ethtool.h> | 34 | #include <linux/ethtool.h> |
38 | #include <linux/phy.h> | 35 | #include <linux/phy.h> |
36 | #include <linux/io.h> | ||
37 | #include <linux/uaccess.h> | ||
39 | 38 | ||
40 | #include <asm/io.h> | ||
41 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
42 | #include <asm/uaccess.h> | ||
43 | 40 | ||
44 | /** | 41 | /** |
45 | * mdiobus_alloc_size - allocate a mii_bus structure | 42 | * mdiobus_alloc_size - allocate a mii_bus structure |
@@ -139,8 +136,7 @@ int mdiobus_register(struct mii_bus *bus) | |||
139 | int i, err; | 136 | int i, err; |
140 | 137 | ||
141 | if (NULL == bus || NULL == bus->name || | 138 | if (NULL == bus || NULL == bus->name || |
142 | NULL == bus->read || | 139 | NULL == bus->read || NULL == bus->write) |
143 | NULL == bus->write) | ||
144 | return -EINVAL; | 140 | return -EINVAL; |
145 | 141 | ||
146 | BUG_ON(bus->state != MDIOBUS_ALLOCATED && | 142 | BUG_ON(bus->state != MDIOBUS_ALLOCATED && |
@@ -154,6 +150,7 @@ int mdiobus_register(struct mii_bus *bus) | |||
154 | err = device_register(&bus->dev); | 150 | err = device_register(&bus->dev); |
155 | if (err) { | 151 | if (err) { |
156 | pr_err("mii_bus %s failed to register\n", bus->id); | 152 | pr_err("mii_bus %s failed to register\n", bus->id); |
153 | put_device(&bus->dev); | ||
157 | return -EINVAL; | 154 | return -EINVAL; |
158 | } | 155 | } |
159 | 156 | ||
@@ -214,9 +211,7 @@ EXPORT_SYMBOL(mdiobus_unregister); | |||
214 | */ | 211 | */ |
215 | void mdiobus_free(struct mii_bus *bus) | 212 | void mdiobus_free(struct mii_bus *bus) |
216 | { | 213 | { |
217 | /* | 214 | /* For compatibility with error handling in drivers. */ |
218 | * For compatibility with error handling in drivers. | ||
219 | */ | ||
220 | if (bus->state == MDIOBUS_ALLOCATED) { | 215 | if (bus->state == MDIOBUS_ALLOCATED) { |
221 | kfree(bus); | 216 | kfree(bus); |
222 | return; | 217 | return; |
@@ -316,8 +311,8 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv) | |||
316 | if (phydrv->match_phy_device) | 311 | if (phydrv->match_phy_device) |
317 | return phydrv->match_phy_device(phydev); | 312 | return phydrv->match_phy_device(phydev); |
318 | 313 | ||
319 | return ((phydrv->phy_id & phydrv->phy_id_mask) == | 314 | return (phydrv->phy_id & phydrv->phy_id_mask) == |
320 | (phydev->phy_id & phydrv->phy_id_mask)); | 315 | (phydev->phy_id & phydrv->phy_id_mask); |
321 | } | 316 | } |
322 | 317 | ||
323 | #ifdef CONFIG_PM | 318 | #ifdef CONFIG_PM |
@@ -335,15 +330,13 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev) | |||
335 | if (!netdev) | 330 | if (!netdev) |
336 | return true; | 331 | return true; |
337 | 332 | ||
338 | /* | 333 | /* Don't suspend PHY if the attched netdev parent may wakeup. |
339 | * Don't suspend PHY if the attched netdev parent may wakeup. | ||
340 | * The parent may point to a PCI device, as in tg3 driver. | 334 | * The parent may point to a PCI device, as in tg3 driver. |
341 | */ | 335 | */ |
342 | if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) | 336 | if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) |
343 | return false; | 337 | return false; |
344 | 338 | ||
345 | /* | 339 | /* Also don't suspend PHY if the netdev itself may wakeup. This |
346 | * Also don't suspend PHY if the netdev itself may wakeup. This | ||
347 | * is the case for devices w/o underlaying pwr. mgmt. aware bus, | 340 | * is the case for devices w/o underlaying pwr. mgmt. aware bus, |
348 | * e.g. SoC devices. | 341 | * e.g. SoC devices. |
349 | */ | 342 | */ |
@@ -358,8 +351,7 @@ static int mdio_bus_suspend(struct device *dev) | |||
358 | struct phy_driver *phydrv = to_phy_driver(dev->driver); | 351 | struct phy_driver *phydrv = to_phy_driver(dev->driver); |
359 | struct phy_device *phydev = to_phy_device(dev); | 352 | struct phy_device *phydev = to_phy_device(dev); |
360 | 353 | ||
361 | /* | 354 | /* We must stop the state machine manually, otherwise it stops out of |
362 | * We must stop the state machine manually, otherwise it stops out of | ||
363 | * control, possibly with the phydev->lock held. Upon resume, netdev | 355 | * control, possibly with the phydev->lock held. Upon resume, netdev |
364 | * may call phy routines that try to grab the same lock, and that may | 356 | * may call phy routines that try to grab the same lock, and that may |
365 | * lead to a deadlock. | 357 | * lead to a deadlock. |
@@ -388,7 +380,7 @@ static int mdio_bus_resume(struct device *dev) | |||
388 | 380 | ||
389 | no_resume: | 381 | no_resume: |
390 | if (phydev->attached_dev && phydev->adjust_link) | 382 | if (phydev->attached_dev && phydev->adjust_link) |
391 | phy_start_machine(phydev, NULL); | 383 | phy_start_machine(phydev); |
392 | 384 | ||
393 | return 0; | 385 | return 0; |
394 | } | 386 | } |
@@ -410,12 +402,12 @@ static int mdio_bus_restore(struct device *dev) | |||
410 | phydev->link = 0; | 402 | phydev->link = 0; |
411 | phydev->state = PHY_UP; | 403 | phydev->state = PHY_UP; |
412 | 404 | ||
413 | phy_start_machine(phydev, NULL); | 405 | phy_start_machine(phydev); |
414 | 406 | ||
415 | return 0; | 407 | return 0; |
416 | } | 408 | } |
417 | 409 | ||
418 | static struct dev_pm_ops mdio_bus_pm_ops = { | 410 | static const struct dev_pm_ops mdio_bus_pm_ops = { |
419 | .suspend = mdio_bus_suspend, | 411 | .suspend = mdio_bus_suspend, |
420 | .resume = mdio_bus_resume, | 412 | .resume = mdio_bus_resume, |
421 | .freeze = mdio_bus_suspend, | 413 | .freeze = mdio_bus_suspend, |
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 26fa05a472b4..5a8993b0cafc 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c | |||
@@ -81,14 +81,14 @@ static int ksz_config_flags(struct phy_device *phydev) | |||
81 | } | 81 | } |
82 | 82 | ||
83 | static int kszphy_extended_write(struct phy_device *phydev, | 83 | static int kszphy_extended_write(struct phy_device *phydev, |
84 | u32 regnum, u16 val) | 84 | u32 regnum, u16 val) |
85 | { | 85 | { |
86 | phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); | 86 | phy_write(phydev, MII_KSZPHY_EXTREG, KSZPHY_EXTREG_WRITE | regnum); |
87 | return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); | 87 | return phy_write(phydev, MII_KSZPHY_EXTREG_WRITE, val); |
88 | } | 88 | } |
89 | 89 | ||
90 | static int kszphy_extended_read(struct phy_device *phydev, | 90 | static int kszphy_extended_read(struct phy_device *phydev, |
91 | u32 regnum) | 91 | u32 regnum) |
92 | { | 92 | { |
93 | phy_write(phydev, MII_KSZPHY_EXTREG, regnum); | 93 | phy_write(phydev, MII_KSZPHY_EXTREG, regnum); |
94 | return phy_read(phydev, MII_KSZPHY_EXTREG_READ); | 94 | return phy_read(phydev, MII_KSZPHY_EXTREG_READ); |
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 98434b84f041..76d96b9ebcdb 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c | |||
@@ -1,7 +1,4 @@ | |||
1 | /* | 1 | /* Framework for configuring and reading PHY devices |
2 | * drivers/net/phy/phy.c | ||
3 | * | ||
4 | * Framework for configuring and reading PHY devices | ||
5 | * Based on code in sungem_phy.c and gianfar_phy.c | 2 | * Based on code in sungem_phy.c and gianfar_phy.c |
6 | * | 3 | * |
7 | * Author: Andy Fleming | 4 | * Author: Andy Fleming |
@@ -23,7 +20,6 @@ | |||
23 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
24 | #include <linux/unistd.h> | 21 | #include <linux/unistd.h> |
25 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
26 | #include <linux/init.h> | ||
27 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
28 | #include <linux/netdevice.h> | 24 | #include <linux/netdevice.h> |
29 | #include <linux/etherdevice.h> | 25 | #include <linux/etherdevice.h> |
@@ -36,11 +32,11 @@ | |||
36 | #include <linux/timer.h> | 32 | #include <linux/timer.h> |
37 | #include <linux/workqueue.h> | 33 | #include <linux/workqueue.h> |
38 | #include <linux/mdio.h> | 34 | #include <linux/mdio.h> |
39 | 35 | #include <linux/io.h> | |
36 | #include <linux/uaccess.h> | ||
40 | #include <linux/atomic.h> | 37 | #include <linux/atomic.h> |
41 | #include <asm/io.h> | 38 | |
42 | #include <asm/irq.h> | 39 | #include <asm/irq.h> |
43 | #include <asm/uaccess.h> | ||
44 | 40 | ||
45 | /** | 41 | /** |
46 | * phy_print_status - Convenience function to print out the current phy status | 42 | * phy_print_status - Convenience function to print out the current phy status |
@@ -48,13 +44,14 @@ | |||
48 | */ | 44 | */ |
49 | void phy_print_status(struct phy_device *phydev) | 45 | void phy_print_status(struct phy_device *phydev) |
50 | { | 46 | { |
51 | if (phydev->link) | 47 | if (phydev->link) { |
52 | pr_info("%s - Link is Up - %d/%s\n", | 48 | pr_info("%s - Link is Up - %d/%s\n", |
53 | dev_name(&phydev->dev), | 49 | dev_name(&phydev->dev), |
54 | phydev->speed, | 50 | phydev->speed, |
55 | DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); | 51 | DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); |
56 | else | 52 | } else { |
57 | pr_info("%s - Link is Down\n", dev_name(&phydev->dev)); | 53 | pr_info("%s - Link is Down\n", dev_name(&phydev->dev)); |
54 | } | ||
58 | } | 55 | } |
59 | EXPORT_SYMBOL(phy_print_status); | 56 | EXPORT_SYMBOL(phy_print_status); |
60 | 57 | ||
@@ -69,12 +66,10 @@ EXPORT_SYMBOL(phy_print_status); | |||
69 | */ | 66 | */ |
70 | static int phy_clear_interrupt(struct phy_device *phydev) | 67 | static int phy_clear_interrupt(struct phy_device *phydev) |
71 | { | 68 | { |
72 | int err = 0; | ||
73 | |||
74 | if (phydev->drv->ack_interrupt) | 69 | if (phydev->drv->ack_interrupt) |
75 | err = phydev->drv->ack_interrupt(phydev); | 70 | return phydev->drv->ack_interrupt(phydev); |
76 | 71 | ||
77 | return err; | 72 | return 0; |
78 | } | 73 | } |
79 | 74 | ||
80 | /** | 75 | /** |
@@ -86,13 +81,11 @@ static int phy_clear_interrupt(struct phy_device *phydev) | |||
86 | */ | 81 | */ |
87 | static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) | 82 | static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) |
88 | { | 83 | { |
89 | int err = 0; | ||
90 | |||
91 | phydev->interrupts = interrupts; | 84 | phydev->interrupts = interrupts; |
92 | if (phydev->drv->config_intr) | 85 | if (phydev->drv->config_intr) |
93 | err = phydev->drv->config_intr(phydev); | 86 | return phydev->drv->config_intr(phydev); |
94 | 87 | ||
95 | return err; | 88 | return 0; |
96 | } | 89 | } |
97 | 90 | ||
98 | 91 | ||
@@ -106,15 +99,14 @@ static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts) | |||
106 | */ | 99 | */ |
107 | static inline int phy_aneg_done(struct phy_device *phydev) | 100 | static inline int phy_aneg_done(struct phy_device *phydev) |
108 | { | 101 | { |
109 | int retval; | 102 | int retval = phy_read(phydev, MII_BMSR); |
110 | |||
111 | retval = phy_read(phydev, MII_BMSR); | ||
112 | 103 | ||
113 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); | 104 | return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE); |
114 | } | 105 | } |
115 | 106 | ||
116 | /* A structure for mapping a particular speed and duplex | 107 | /* A structure for mapping a particular speed and duplex |
117 | * combination to a particular SUPPORTED and ADVERTISED value */ | 108 | * combination to a particular SUPPORTED and ADVERTISED value |
109 | */ | ||
118 | struct phy_setting { | 110 | struct phy_setting { |
119 | int speed; | 111 | int speed; |
120 | int duplex; | 112 | int duplex; |
@@ -172,13 +164,12 @@ static const struct phy_setting settings[] = { | |||
172 | * of that setting. Returns the index of the last setting if | 164 | * of that setting. Returns the index of the last setting if |
173 | * none of the others match. | 165 | * none of the others match. |
174 | */ | 166 | */ |
175 | static inline int phy_find_setting(int speed, int duplex) | 167 | static inline unsigned int phy_find_setting(int speed, int duplex) |
176 | { | 168 | { |
177 | int idx = 0; | 169 | unsigned int idx = 0; |
178 | 170 | ||
179 | while (idx < ARRAY_SIZE(settings) && | 171 | while (idx < ARRAY_SIZE(settings) && |
180 | (settings[idx].speed != speed || | 172 | (settings[idx].speed != speed || settings[idx].duplex != duplex)) |
181 | settings[idx].duplex != duplex)) | ||
182 | idx++; | 173 | idx++; |
183 | 174 | ||
184 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; | 175 | return idx < MAX_NUM_SETTINGS ? idx : MAX_NUM_SETTINGS - 1; |
@@ -194,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex) | |||
194 | * the mask in features. Returns the index of the last setting | 185 | * the mask in features. Returns the index of the last setting |
195 | * if nothing else matches. | 186 | * if nothing else matches. |
196 | */ | 187 | */ |
197 | static inline int phy_find_valid(int idx, u32 features) | 188 | static inline unsigned int phy_find_valid(unsigned int idx, u32 features) |
198 | { | 189 | { |
199 | while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) | 190 | while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) |
200 | idx++; | 191 | idx++; |
@@ -213,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features) | |||
213 | static void phy_sanitize_settings(struct phy_device *phydev) | 204 | static void phy_sanitize_settings(struct phy_device *phydev) |
214 | { | 205 | { |
215 | u32 features = phydev->supported; | 206 | u32 features = phydev->supported; |
216 | int idx; | 207 | unsigned int idx; |
217 | 208 | ||
218 | /* Sanitize settings based on PHY capabilities */ | 209 | /* Sanitize settings based on PHY capabilities */ |
219 | if ((features & SUPPORTED_Autoneg) == 0) | 210 | if ((features & SUPPORTED_Autoneg) == 0) |
@@ -245,8 +236,7 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) | |||
245 | if (cmd->phy_address != phydev->addr) | 236 | if (cmd->phy_address != phydev->addr) |
246 | return -EINVAL; | 237 | return -EINVAL; |
247 | 238 | ||
248 | /* We make sure that we don't pass unsupported | 239 | /* We make sure that we don't pass unsupported values in to the PHY */ |
249 | * values in to the PHY */ | ||
250 | cmd->advertising &= phydev->supported; | 240 | cmd->advertising &= phydev->supported; |
251 | 241 | ||
252 | /* Verify the settings we care about. */ | 242 | /* Verify the settings we care about. */ |
@@ -289,6 +279,7 @@ int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) | |||
289 | cmd->supported = phydev->supported; | 279 | cmd->supported = phydev->supported; |
290 | 280 | ||
291 | cmd->advertising = phydev->advertising; | 281 | cmd->advertising = phydev->advertising; |
282 | cmd->lp_advertising = phydev->lp_advertising; | ||
292 | 283 | ||
293 | ethtool_cmd_speed_set(cmd, phydev->speed); | 284 | ethtool_cmd_speed_set(cmd, phydev->speed); |
294 | cmd->duplex = phydev->duplex; | 285 | cmd->duplex = phydev->duplex; |
@@ -312,8 +303,7 @@ EXPORT_SYMBOL(phy_ethtool_gset); | |||
312 | * PHYCONTROL layer. It changes registers without regard to | 303 | * PHYCONTROL layer. It changes registers without regard to |
313 | * current state. Use at own risk. | 304 | * current state. Use at own risk. |
314 | */ | 305 | */ |
315 | int phy_mii_ioctl(struct phy_device *phydev, | 306 | int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) |
316 | struct ifreq *ifr, int cmd) | ||
317 | { | 307 | { |
318 | struct mii_ioctl_data *mii_data = if_mii(ifr); | 308 | struct mii_ioctl_data *mii_data = if_mii(ifr); |
319 | u16 val = mii_data->val_in; | 309 | u16 val = mii_data->val_in; |
@@ -326,25 +316,24 @@ int phy_mii_ioctl(struct phy_device *phydev, | |||
326 | case SIOCGMIIREG: | 316 | case SIOCGMIIREG: |
327 | mii_data->val_out = mdiobus_read(phydev->bus, mii_data->phy_id, | 317 | mii_data->val_out = mdiobus_read(phydev->bus, mii_data->phy_id, |
328 | mii_data->reg_num); | 318 | mii_data->reg_num); |
329 | break; | 319 | return 0; |
330 | 320 | ||
331 | case SIOCSMIIREG: | 321 | case SIOCSMIIREG: |
332 | if (mii_data->phy_id == phydev->addr) { | 322 | if (mii_data->phy_id == phydev->addr) { |
333 | switch(mii_data->reg_num) { | 323 | switch (mii_data->reg_num) { |
334 | case MII_BMCR: | 324 | case MII_BMCR: |
335 | if ((val & (BMCR_RESET|BMCR_ANENABLE)) == 0) | 325 | if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) |
336 | phydev->autoneg = AUTONEG_DISABLE; | 326 | phydev->autoneg = AUTONEG_DISABLE; |
337 | else | 327 | else |
338 | phydev->autoneg = AUTONEG_ENABLE; | 328 | phydev->autoneg = AUTONEG_ENABLE; |
339 | if ((!phydev->autoneg) && (val & BMCR_FULLDPLX)) | 329 | if (!phydev->autoneg && (val & BMCR_FULLDPLX)) |
340 | phydev->duplex = DUPLEX_FULL; | 330 | phydev->duplex = DUPLEX_FULL; |
341 | else | 331 | else |
342 | phydev->duplex = DUPLEX_HALF; | 332 | phydev->duplex = DUPLEX_HALF; |
343 | if ((!phydev->autoneg) && | 333 | if (!phydev->autoneg && (val & BMCR_SPEED1000)) |
344 | (val & BMCR_SPEED1000)) | ||
345 | phydev->speed = SPEED_1000; | 334 | phydev->speed = SPEED_1000; |
346 | else if ((!phydev->autoneg) && | 335 | else if (!phydev->autoneg && |
347 | (val & BMCR_SPEED100)) | 336 | (val & BMCR_SPEED100)) |
348 | phydev->speed = SPEED_100; | 337 | phydev->speed = SPEED_100; |
349 | break; | 338 | break; |
350 | case MII_ADVERTISE: | 339 | case MII_ADVERTISE: |
@@ -360,12 +349,9 @@ int phy_mii_ioctl(struct phy_device *phydev, | |||
360 | mii_data->reg_num, val); | 349 | mii_data->reg_num, val); |
361 | 350 | ||
362 | if (mii_data->reg_num == MII_BMCR && | 351 | if (mii_data->reg_num == MII_BMCR && |
363 | val & BMCR_RESET && | 352 | val & BMCR_RESET) |
364 | phydev->drv->config_init) { | 353 | return phy_init_hw(phydev); |
365 | phy_scan_fixups(phydev); | 354 | return 0; |
366 | phydev->drv->config_init(phydev); | ||
367 | } | ||
368 | break; | ||
369 | 355 | ||
370 | case SIOCSHWTSTAMP: | 356 | case SIOCSHWTSTAMP: |
371 | if (phydev->drv->hwtstamp) | 357 | if (phydev->drv->hwtstamp) |
@@ -375,8 +361,6 @@ int phy_mii_ioctl(struct phy_device *phydev, | |||
375 | default: | 361 | default: |
376 | return -EOPNOTSUPP; | 362 | return -EOPNOTSUPP; |
377 | } | 363 | } |
378 | |||
379 | return 0; | ||
380 | } | 364 | } |
381 | EXPORT_SYMBOL(phy_mii_ioctl); | 365 | EXPORT_SYMBOL(phy_mii_ioctl); |
382 | 366 | ||
@@ -399,7 +383,6 @@ int phy_start_aneg(struct phy_device *phydev) | |||
399 | phy_sanitize_settings(phydev); | 383 | phy_sanitize_settings(phydev); |
400 | 384 | ||
401 | err = phydev->drv->config_aneg(phydev); | 385 | err = phydev->drv->config_aneg(phydev); |
402 | |||
403 | if (err < 0) | 386 | if (err < 0) |
404 | goto out_unlock; | 387 | goto out_unlock; |
405 | 388 | ||
@@ -419,25 +402,18 @@ out_unlock: | |||
419 | } | 402 | } |
420 | EXPORT_SYMBOL(phy_start_aneg); | 403 | EXPORT_SYMBOL(phy_start_aneg); |
421 | 404 | ||
422 | |||
423 | /** | 405 | /** |
424 | * phy_start_machine - start PHY state machine tracking | 406 | * phy_start_machine - start PHY state machine tracking |
425 | * @phydev: the phy_device struct | 407 | * @phydev: the phy_device struct |
426 | * @handler: callback function for state change notifications | ||
427 | * | 408 | * |
428 | * Description: The PHY infrastructure can run a state machine | 409 | * Description: The PHY infrastructure can run a state machine |
429 | * which tracks whether the PHY is starting up, negotiating, | 410 | * which tracks whether the PHY is starting up, negotiating, |
430 | * etc. This function starts the timer which tracks the state | 411 | * etc. This function starts the timer which tracks the state |
431 | * of the PHY. If you want to be notified when the state changes, | 412 | * of the PHY. If you want to maintain your own state machine, |
432 | * pass in the callback @handler, otherwise, pass NULL. If you | 413 | * do not call this function. |
433 | * want to maintain your own state machine, do not call this | ||
434 | * function. | ||
435 | */ | 414 | */ |
436 | void phy_start_machine(struct phy_device *phydev, | 415 | void phy_start_machine(struct phy_device *phydev) |
437 | void (*handler)(struct net_device *)) | ||
438 | { | 416 | { |
439 | phydev->adjust_state = handler; | ||
440 | |||
441 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, HZ); | 417 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, HZ); |
442 | } | 418 | } |
443 | 419 | ||
@@ -457,8 +433,6 @@ void phy_stop_machine(struct phy_device *phydev) | |||
457 | if (phydev->state > PHY_UP) | 433 | if (phydev->state > PHY_UP) |
458 | phydev->state = PHY_UP; | 434 | phydev->state = PHY_UP; |
459 | mutex_unlock(&phydev->lock); | 435 | mutex_unlock(&phydev->lock); |
460 | |||
461 | phydev->adjust_state = NULL; | ||
462 | } | 436 | } |
463 | 437 | ||
464 | /** | 438 | /** |
@@ -495,7 +469,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) | |||
495 | /* The MDIO bus is not allowed to be written in interrupt | 469 | /* The MDIO bus is not allowed to be written in interrupt |
496 | * context, so we need to disable the irq here. A work | 470 | * context, so we need to disable the irq here. A work |
497 | * queue will write the PHY to disable and clear the | 471 | * queue will write the PHY to disable and clear the |
498 | * interrupt, and then reenable the irq line. */ | 472 | * interrupt, and then reenable the irq line. |
473 | */ | ||
499 | disable_irq_nosync(irq); | 474 | disable_irq_nosync(irq); |
500 | atomic_inc(&phydev->irq_disable); | 475 | atomic_inc(&phydev->irq_disable); |
501 | 476 | ||
@@ -510,16 +485,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat) | |||
510 | */ | 485 | */ |
511 | static int phy_enable_interrupts(struct phy_device *phydev) | 486 | static int phy_enable_interrupts(struct phy_device *phydev) |
512 | { | 487 | { |
513 | int err; | 488 | int err = phy_clear_interrupt(phydev); |
514 | |||
515 | err = phy_clear_interrupt(phydev); | ||
516 | 489 | ||
517 | if (err < 0) | 490 | if (err < 0) |
518 | return err; | 491 | return err; |
519 | 492 | ||
520 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | 493 | return phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); |
521 | |||
522 | return err; | ||
523 | } | 494 | } |
524 | 495 | ||
525 | /** | 496 | /** |
@@ -532,13 +503,11 @@ static int phy_disable_interrupts(struct phy_device *phydev) | |||
532 | 503 | ||
533 | /* Disable PHY interrupts */ | 504 | /* Disable PHY interrupts */ |
534 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); | 505 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); |
535 | |||
536 | if (err) | 506 | if (err) |
537 | goto phy_err; | 507 | goto phy_err; |
538 | 508 | ||
539 | /* Clear the interrupt */ | 509 | /* Clear the interrupt */ |
540 | err = phy_clear_interrupt(phydev); | 510 | err = phy_clear_interrupt(phydev); |
541 | |||
542 | if (err) | 511 | if (err) |
543 | goto phy_err; | 512 | goto phy_err; |
544 | 513 | ||
@@ -562,8 +531,6 @@ phy_err: | |||
562 | */ | 531 | */ |
563 | int phy_start_interrupts(struct phy_device *phydev) | 532 | int phy_start_interrupts(struct phy_device *phydev) |
564 | { | 533 | { |
565 | int err = 0; | ||
566 | |||
567 | atomic_set(&phydev->irq_disable, 0); | 534 | atomic_set(&phydev->irq_disable, 0); |
568 | if (request_irq(phydev->irq, phy_interrupt, 0, "phy_interrupt", | 535 | if (request_irq(phydev->irq, phy_interrupt, 0, "phy_interrupt", |
569 | phydev) < 0) { | 536 | phydev) < 0) { |
@@ -573,9 +540,7 @@ int phy_start_interrupts(struct phy_device *phydev) | |||
573 | return 0; | 540 | return 0; |
574 | } | 541 | } |
575 | 542 | ||
576 | err = phy_enable_interrupts(phydev); | 543 | return phy_enable_interrupts(phydev); |
577 | |||
578 | return err; | ||
579 | } | 544 | } |
580 | EXPORT_SYMBOL(phy_start_interrupts); | 545 | EXPORT_SYMBOL(phy_start_interrupts); |
581 | 546 | ||
@@ -585,24 +550,20 @@ EXPORT_SYMBOL(phy_start_interrupts); | |||
585 | */ | 550 | */ |
586 | int phy_stop_interrupts(struct phy_device *phydev) | 551 | int phy_stop_interrupts(struct phy_device *phydev) |
587 | { | 552 | { |
588 | int err; | 553 | int err = phy_disable_interrupts(phydev); |
589 | |||
590 | err = phy_disable_interrupts(phydev); | ||
591 | 554 | ||
592 | if (err) | 555 | if (err) |
593 | phy_error(phydev); | 556 | phy_error(phydev); |
594 | 557 | ||
595 | free_irq(phydev->irq, phydev); | 558 | free_irq(phydev->irq, phydev); |
596 | 559 | ||
597 | /* | 560 | /* Cannot call flush_scheduled_work() here as desired because |
598 | * Cannot call flush_scheduled_work() here as desired because | ||
599 | * of rtnl_lock(), but we do not really care about what would | 561 | * of rtnl_lock(), but we do not really care about what would |
600 | * be done, except from enable_irq(), so cancel any work | 562 | * be done, except from enable_irq(), so cancel any work |
601 | * possibly pending and take care of the matter below. | 563 | * possibly pending and take care of the matter below. |
602 | */ | 564 | */ |
603 | cancel_work_sync(&phydev->phy_queue); | 565 | cancel_work_sync(&phydev->phy_queue); |
604 | /* | 566 | /* If work indeed has been cancelled, disable_irq() will have |
605 | * If work indeed has been cancelled, disable_irq() will have | ||
606 | * been left unbalanced from phy_interrupt() and enable_irq() | 567 | * been left unbalanced from phy_interrupt() and enable_irq() |
607 | * has to be called so that other devices on the line work. | 568 | * has to be called so that other devices on the line work. |
608 | */ | 569 | */ |
@@ -613,14 +574,12 @@ int phy_stop_interrupts(struct phy_device *phydev) | |||
613 | } | 574 | } |
614 | EXPORT_SYMBOL(phy_stop_interrupts); | 575 | EXPORT_SYMBOL(phy_stop_interrupts); |
615 | 576 | ||
616 | |||
617 | /** | 577 | /** |
618 | * phy_change - Scheduled by the phy_interrupt/timer to handle PHY changes | 578 | * phy_change - Scheduled by the phy_interrupt/timer to handle PHY changes |
619 | * @work: work_struct that describes the work to be done | 579 | * @work: work_struct that describes the work to be done |
620 | */ | 580 | */ |
621 | void phy_change(struct work_struct *work) | 581 | void phy_change(struct work_struct *work) |
622 | { | 582 | { |
623 | int err; | ||
624 | struct phy_device *phydev = | 583 | struct phy_device *phydev = |
625 | container_of(work, struct phy_device, phy_queue); | 584 | container_of(work, struct phy_device, phy_queue); |
626 | 585 | ||
@@ -628,9 +587,7 @@ void phy_change(struct work_struct *work) | |||
628 | !phydev->drv->did_interrupt(phydev)) | 587 | !phydev->drv->did_interrupt(phydev)) |
629 | goto ignore; | 588 | goto ignore; |
630 | 589 | ||
631 | err = phy_disable_interrupts(phydev); | 590 | if (phy_disable_interrupts(phydev)) |
632 | |||
633 | if (err) | ||
634 | goto phy_err; | 591 | goto phy_err; |
635 | 592 | ||
636 | mutex_lock(&phydev->lock); | 593 | mutex_lock(&phydev->lock); |
@@ -642,16 +599,13 @@ void phy_change(struct work_struct *work) | |||
642 | enable_irq(phydev->irq); | 599 | enable_irq(phydev->irq); |
643 | 600 | ||
644 | /* Reenable interrupts */ | 601 | /* Reenable interrupts */ |
645 | if (PHY_HALTED != phydev->state) | 602 | if (PHY_HALTED != phydev->state && |
646 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); | 603 | phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED)) |
647 | |||
648 | if (err) | ||
649 | goto irq_enable_err; | 604 | goto irq_enable_err; |
650 | 605 | ||
651 | /* reschedule state queue work to run as soon as possible */ | 606 | /* reschedule state queue work to run as soon as possible */ |
652 | cancel_delayed_work_sync(&phydev->state_queue); | 607 | cancel_delayed_work_sync(&phydev->state_queue); |
653 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 0); | 608 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, 0); |
654 | |||
655 | return; | 609 | return; |
656 | 610 | ||
657 | ignore: | 611 | ignore: |
@@ -690,13 +644,12 @@ void phy_stop(struct phy_device *phydev) | |||
690 | out_unlock: | 644 | out_unlock: |
691 | mutex_unlock(&phydev->lock); | 645 | mutex_unlock(&phydev->lock); |
692 | 646 | ||
693 | /* | 647 | /* Cannot call flush_scheduled_work() here as desired because |
694 | * Cannot call flush_scheduled_work() here as desired because | ||
695 | * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change() | 648 | * of rtnl_lock(), but PHY_HALTED shall guarantee phy_change() |
696 | * will not reenable interrupts. | 649 | * will not reenable interrupts. |
697 | */ | 650 | */ |
698 | } | 651 | } |
699 | 652 | EXPORT_SYMBOL(phy_stop); | |
700 | 653 | ||
701 | /** | 654 | /** |
702 | * phy_start - start or restart a PHY device | 655 | * phy_start - start or restart a PHY device |
@@ -713,20 +666,19 @@ void phy_start(struct phy_device *phydev) | |||
713 | mutex_lock(&phydev->lock); | 666 | mutex_lock(&phydev->lock); |
714 | 667 | ||
715 | switch (phydev->state) { | 668 | switch (phydev->state) { |
716 | case PHY_STARTING: | 669 | case PHY_STARTING: |
717 | phydev->state = PHY_PENDING; | 670 | phydev->state = PHY_PENDING; |
718 | break; | 671 | break; |
719 | case PHY_READY: | 672 | case PHY_READY: |
720 | phydev->state = PHY_UP; | 673 | phydev->state = PHY_UP; |
721 | break; | 674 | break; |
722 | case PHY_HALTED: | 675 | case PHY_HALTED: |
723 | phydev->state = PHY_RESUMING; | 676 | phydev->state = PHY_RESUMING; |
724 | default: | 677 | default: |
725 | break; | 678 | break; |
726 | } | 679 | } |
727 | mutex_unlock(&phydev->lock); | 680 | mutex_unlock(&phydev->lock); |
728 | } | 681 | } |
729 | EXPORT_SYMBOL(phy_stop); | ||
730 | EXPORT_SYMBOL(phy_start); | 682 | EXPORT_SYMBOL(phy_start); |
731 | 683 | ||
732 | /** | 684 | /** |
@@ -738,160 +690,132 @@ void phy_state_machine(struct work_struct *work) | |||
738 | struct delayed_work *dwork = to_delayed_work(work); | 690 | struct delayed_work *dwork = to_delayed_work(work); |
739 | struct phy_device *phydev = | 691 | struct phy_device *phydev = |
740 | container_of(dwork, struct phy_device, state_queue); | 692 | container_of(dwork, struct phy_device, state_queue); |
741 | int needs_aneg = 0; | 693 | int needs_aneg = 0, do_suspend = 0; |
742 | int err = 0; | 694 | int err = 0; |
743 | 695 | ||
744 | mutex_lock(&phydev->lock); | 696 | mutex_lock(&phydev->lock); |
745 | 697 | ||
746 | if (phydev->adjust_state) | 698 | switch (phydev->state) { |
747 | phydev->adjust_state(phydev->attached_dev); | 699 | case PHY_DOWN: |
700 | case PHY_STARTING: | ||
701 | case PHY_READY: | ||
702 | case PHY_PENDING: | ||
703 | break; | ||
704 | case PHY_UP: | ||
705 | needs_aneg = 1; | ||
748 | 706 | ||
749 | switch(phydev->state) { | 707 | phydev->link_timeout = PHY_AN_TIMEOUT; |
750 | case PHY_DOWN: | ||
751 | case PHY_STARTING: | ||
752 | case PHY_READY: | ||
753 | case PHY_PENDING: | ||
754 | break; | ||
755 | case PHY_UP: | ||
756 | needs_aneg = 1; | ||
757 | 708 | ||
758 | phydev->link_timeout = PHY_AN_TIMEOUT; | 709 | break; |
710 | case PHY_AN: | ||
711 | err = phy_read_status(phydev); | ||
712 | if (err < 0) | ||
713 | break; | ||
759 | 714 | ||
715 | /* If the link is down, give up on negotiation for now */ | ||
716 | if (!phydev->link) { | ||
717 | phydev->state = PHY_NOLINK; | ||
718 | netif_carrier_off(phydev->attached_dev); | ||
719 | phydev->adjust_link(phydev->attached_dev); | ||
760 | break; | 720 | break; |
761 | case PHY_AN: | 721 | } |
762 | err = phy_read_status(phydev); | ||
763 | 722 | ||
764 | if (err < 0) | 723 | /* Check if negotiation is done. Break if there's an error */ |
765 | break; | 724 | err = phy_aneg_done(phydev); |
725 | if (err < 0) | ||
726 | break; | ||
766 | 727 | ||
767 | /* If the link is down, give up on | 728 | /* If AN is done, we're running */ |
768 | * negotiation for now */ | 729 | if (err > 0) { |
769 | if (!phydev->link) { | 730 | phydev->state = PHY_RUNNING; |
770 | phydev->state = PHY_NOLINK; | 731 | netif_carrier_on(phydev->attached_dev); |
771 | netif_carrier_off(phydev->attached_dev); | 732 | phydev->adjust_link(phydev->attached_dev); |
772 | phydev->adjust_link(phydev->attached_dev); | ||
773 | break; | ||
774 | } | ||
775 | 733 | ||
776 | /* Check if negotiation is done. Break | 734 | } else if (0 == phydev->link_timeout--) { |
777 | * if there's an error */ | 735 | needs_aneg = 1; |
778 | err = phy_aneg_done(phydev); | 736 | /* If we have the magic_aneg bit, we try again */ |
779 | if (err < 0) | 737 | if (phydev->drv->flags & PHY_HAS_MAGICANEG) |
780 | break; | 738 | break; |
781 | 739 | } | |
782 | /* If AN is done, we're running */ | 740 | break; |
783 | if (err > 0) { | 741 | case PHY_NOLINK: |
784 | phydev->state = PHY_RUNNING; | 742 | err = phy_read_status(phydev); |
785 | netif_carrier_on(phydev->attached_dev); | 743 | if (err) |
786 | phydev->adjust_link(phydev->attached_dev); | ||
787 | |||
788 | } else if (0 == phydev->link_timeout--) { | ||
789 | needs_aneg = 1; | ||
790 | /* If we have the magic_aneg bit, | ||
791 | * we try again */ | ||
792 | if (phydev->drv->flags & PHY_HAS_MAGICANEG) | ||
793 | break; | ||
794 | } | ||
795 | break; | 744 | break; |
796 | case PHY_NOLINK: | ||
797 | err = phy_read_status(phydev); | ||
798 | |||
799 | if (err) | ||
800 | break; | ||
801 | 745 | ||
802 | if (phydev->link) { | 746 | if (phydev->link) { |
803 | phydev->state = PHY_RUNNING; | 747 | phydev->state = PHY_RUNNING; |
804 | netif_carrier_on(phydev->attached_dev); | 748 | netif_carrier_on(phydev->attached_dev); |
805 | phydev->adjust_link(phydev->attached_dev); | 749 | phydev->adjust_link(phydev->attached_dev); |
806 | } | 750 | } |
751 | break; | ||
752 | case PHY_FORCING: | ||
753 | err = genphy_update_link(phydev); | ||
754 | if (err) | ||
807 | break; | 755 | break; |
808 | case PHY_FORCING: | ||
809 | err = genphy_update_link(phydev); | ||
810 | |||
811 | if (err) | ||
812 | break; | ||
813 | 756 | ||
814 | if (phydev->link) { | 757 | if (phydev->link) { |
815 | phydev->state = PHY_RUNNING; | 758 | phydev->state = PHY_RUNNING; |
816 | netif_carrier_on(phydev->attached_dev); | 759 | netif_carrier_on(phydev->attached_dev); |
817 | } else { | 760 | } else { |
818 | if (0 == phydev->link_timeout--) | 761 | if (0 == phydev->link_timeout--) |
819 | needs_aneg = 1; | 762 | needs_aneg = 1; |
820 | } | 763 | } |
821 | 764 | ||
822 | phydev->adjust_link(phydev->attached_dev); | 765 | phydev->adjust_link(phydev->attached_dev); |
823 | break; | 766 | break; |
824 | case PHY_RUNNING: | 767 | case PHY_RUNNING: |
825 | /* Only register a CHANGE if we are | 768 | /* Only register a CHANGE if we are |
826 | * polling or ignoring interrupts | 769 | * polling or ignoring interrupts |
827 | */ | 770 | */ |
828 | if (!phy_interrupt_is_valid(phydev)) | 771 | if (!phy_interrupt_is_valid(phydev)) |
829 | phydev->state = PHY_CHANGELINK; | 772 | phydev->state = PHY_CHANGELINK; |
773 | break; | ||
774 | case PHY_CHANGELINK: | ||
775 | err = phy_read_status(phydev); | ||
776 | if (err) | ||
830 | break; | 777 | break; |
831 | case PHY_CHANGELINK: | ||
832 | err = phy_read_status(phydev); | ||
833 | 778 | ||
834 | if (err) | 779 | if (phydev->link) { |
835 | break; | 780 | phydev->state = PHY_RUNNING; |
781 | netif_carrier_on(phydev->attached_dev); | ||
782 | } else { | ||
783 | phydev->state = PHY_NOLINK; | ||
784 | netif_carrier_off(phydev->attached_dev); | ||
785 | } | ||
836 | 786 | ||
837 | if (phydev->link) { | 787 | phydev->adjust_link(phydev->attached_dev); |
838 | phydev->state = PHY_RUNNING; | ||
839 | netif_carrier_on(phydev->attached_dev); | ||
840 | } else { | ||
841 | phydev->state = PHY_NOLINK; | ||
842 | netif_carrier_off(phydev->attached_dev); | ||
843 | } | ||
844 | 788 | ||
789 | if (phy_interrupt_is_valid(phydev)) | ||
790 | err = phy_config_interrupt(phydev, | ||
791 | PHY_INTERRUPT_ENABLED); | ||
792 | break; | ||
793 | case PHY_HALTED: | ||
794 | if (phydev->link) { | ||
795 | phydev->link = 0; | ||
796 | netif_carrier_off(phydev->attached_dev); | ||
845 | phydev->adjust_link(phydev->attached_dev); | 797 | phydev->adjust_link(phydev->attached_dev); |
846 | 798 | do_suspend = 1; | |
847 | if (phy_interrupt_is_valid(phydev)) | 799 | } |
848 | err = phy_config_interrupt(phydev, | 800 | break; |
849 | PHY_INTERRUPT_ENABLED); | 801 | case PHY_RESUMING: |
850 | break; | 802 | err = phy_clear_interrupt(phydev); |
851 | case PHY_HALTED: | 803 | if (err) |
852 | if (phydev->link) { | ||
853 | phydev->link = 0; | ||
854 | netif_carrier_off(phydev->attached_dev); | ||
855 | phydev->adjust_link(phydev->attached_dev); | ||
856 | } | ||
857 | break; | 804 | break; |
858 | case PHY_RESUMING: | ||
859 | |||
860 | err = phy_clear_interrupt(phydev); | ||
861 | 805 | ||
862 | if (err) | 806 | err = phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); |
863 | break; | 807 | if (err) |
864 | 808 | break; | |
865 | err = phy_config_interrupt(phydev, | ||
866 | PHY_INTERRUPT_ENABLED); | ||
867 | 809 | ||
868 | if (err) | 810 | if (AUTONEG_ENABLE == phydev->autoneg) { |
811 | err = phy_aneg_done(phydev); | ||
812 | if (err < 0) | ||
869 | break; | 813 | break; |
870 | 814 | ||
871 | if (AUTONEG_ENABLE == phydev->autoneg) { | 815 | /* err > 0 if AN is done. |
872 | err = phy_aneg_done(phydev); | 816 | * Otherwise, it's 0, and we're still waiting for AN |
873 | if (err < 0) | 817 | */ |
874 | break; | 818 | if (err > 0) { |
875 | |||
876 | /* err > 0 if AN is done. | ||
877 | * Otherwise, it's 0, and we're | ||
878 | * still waiting for AN */ | ||
879 | if (err > 0) { | ||
880 | err = phy_read_status(phydev); | ||
881 | if (err) | ||
882 | break; | ||
883 | |||
884 | if (phydev->link) { | ||
885 | phydev->state = PHY_RUNNING; | ||
886 | netif_carrier_on(phydev->attached_dev); | ||
887 | } else | ||
888 | phydev->state = PHY_NOLINK; | ||
889 | phydev->adjust_link(phydev->attached_dev); | ||
890 | } else { | ||
891 | phydev->state = PHY_AN; | ||
892 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
893 | } | ||
894 | } else { | ||
895 | err = phy_read_status(phydev); | 819 | err = phy_read_status(phydev); |
896 | if (err) | 820 | if (err) |
897 | break; | 821 | break; |
@@ -899,11 +823,28 @@ void phy_state_machine(struct work_struct *work) | |||
899 | if (phydev->link) { | 823 | if (phydev->link) { |
900 | phydev->state = PHY_RUNNING; | 824 | phydev->state = PHY_RUNNING; |
901 | netif_carrier_on(phydev->attached_dev); | 825 | netif_carrier_on(phydev->attached_dev); |
902 | } else | 826 | } else { |
903 | phydev->state = PHY_NOLINK; | 827 | phydev->state = PHY_NOLINK; |
828 | } | ||
904 | phydev->adjust_link(phydev->attached_dev); | 829 | phydev->adjust_link(phydev->attached_dev); |
830 | } else { | ||
831 | phydev->state = PHY_AN; | ||
832 | phydev->link_timeout = PHY_AN_TIMEOUT; | ||
905 | } | 833 | } |
906 | break; | 834 | } else { |
835 | err = phy_read_status(phydev); | ||
836 | if (err) | ||
837 | break; | ||
838 | |||
839 | if (phydev->link) { | ||
840 | phydev->state = PHY_RUNNING; | ||
841 | netif_carrier_on(phydev->attached_dev); | ||
842 | } else { | ||
843 | phydev->state = PHY_NOLINK; | ||
844 | } | ||
845 | phydev->adjust_link(phydev->attached_dev); | ||
846 | } | ||
847 | break; | ||
907 | } | 848 | } |
908 | 849 | ||
909 | mutex_unlock(&phydev->lock); | 850 | mutex_unlock(&phydev->lock); |
@@ -911,11 +852,14 @@ void phy_state_machine(struct work_struct *work) | |||
911 | if (needs_aneg) | 852 | if (needs_aneg) |
912 | err = phy_start_aneg(phydev); | 853 | err = phy_start_aneg(phydev); |
913 | 854 | ||
855 | if (do_suspend) | ||
856 | phy_suspend(phydev); | ||
857 | |||
914 | if (err < 0) | 858 | if (err < 0) |
915 | phy_error(phydev); | 859 | phy_error(phydev); |
916 | 860 | ||
917 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, | 861 | queue_delayed_work(system_power_efficient_wq, &phydev->state_queue, |
918 | PHY_STATE_TIME * HZ); | 862 | PHY_STATE_TIME * HZ); |
919 | } | 863 | } |
920 | 864 | ||
921 | void phy_mac_interrupt(struct phy_device *phydev, int new_link) | 865 | void phy_mac_interrupt(struct phy_device *phydev, int new_link) |
@@ -957,14 +901,10 @@ static inline void mmd_phy_indirect(struct mii_bus *bus, int prtad, int devad, | |||
957 | static int phy_read_mmd_indirect(struct mii_bus *bus, int prtad, int devad, | 901 | static int phy_read_mmd_indirect(struct mii_bus *bus, int prtad, int devad, |
958 | int addr) | 902 | int addr) |
959 | { | 903 | { |
960 | u32 ret; | ||
961 | |||
962 | mmd_phy_indirect(bus, prtad, devad, addr); | 904 | mmd_phy_indirect(bus, prtad, devad, addr); |
963 | 905 | ||
964 | /* Read the content of the MMD's selected register */ | 906 | /* Read the content of the MMD's selected register */ |
965 | ret = bus->read(bus, addr, MII_MMD_DATA); | 907 | return bus->read(bus, addr, MII_MMD_DATA); |
966 | |||
967 | return ret; | ||
968 | } | 908 | } |
969 | 909 | ||
970 | /** | 910 | /** |
@@ -1004,8 +944,6 @@ static void phy_write_mmd_indirect(struct mii_bus *bus, int prtad, int devad, | |||
1004 | */ | 944 | */ |
1005 | int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) | 945 | int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) |
1006 | { | 946 | { |
1007 | int ret = -EPROTONOSUPPORT; | ||
1008 | |||
1009 | /* According to 802.3az,the EEE is supported only in full duplex-mode. | 947 | /* According to 802.3az,the EEE is supported only in full duplex-mode. |
1010 | * Also EEE feature is active when core is operating with MII, GMII | 948 | * Also EEE feature is active when core is operating with MII, GMII |
1011 | * or RGMII. | 949 | * or RGMII. |
@@ -1016,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) | |||
1016 | (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { | 954 | (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { |
1017 | int eee_lp, eee_cap, eee_adv; | 955 | int eee_lp, eee_cap, eee_adv; |
1018 | u32 lp, cap, adv; | 956 | u32 lp, cap, adv; |
1019 | int idx, status; | 957 | int status; |
958 | unsigned int idx; | ||
1020 | 959 | ||
1021 | /* Read phy status to properly get the right settings */ | 960 | /* Read phy status to properly get the right settings */ |
1022 | status = phy_read_status(phydev); | 961 | status = phy_read_status(phydev); |
@@ -1031,7 +970,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) | |||
1031 | 970 | ||
1032 | cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap); | 971 | cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap); |
1033 | if (!cap) | 972 | if (!cap) |
1034 | goto eee_exit; | 973 | return -EPROTONOSUPPORT; |
1035 | 974 | ||
1036 | /* Check which link settings negotiated and verify it in | 975 | /* Check which link settings negotiated and verify it in |
1037 | * the EEE advertising registers. | 976 | * the EEE advertising registers. |
@@ -1050,7 +989,7 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) | |||
1050 | lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp); | 989 | lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp); |
1051 | idx = phy_find_setting(phydev->speed, phydev->duplex); | 990 | idx = phy_find_setting(phydev->speed, phydev->duplex); |
1052 | if (!(lp & adv & settings[idx].setting)) | 991 | if (!(lp & adv & settings[idx].setting)) |
1053 | goto eee_exit; | 992 | return -EPROTONOSUPPORT; |
1054 | 993 | ||
1055 | if (clk_stop_enable) { | 994 | if (clk_stop_enable) { |
1056 | /* Configure the PHY to stop receiving xMII | 995 | /* Configure the PHY to stop receiving xMII |
@@ -1067,11 +1006,10 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) | |||
1067 | MDIO_MMD_PCS, phydev->addr, val); | 1006 | MDIO_MMD_PCS, phydev->addr, val); |
1068 | } | 1007 | } |
1069 | 1008 | ||
1070 | ret = 0; /* EEE supported */ | 1009 | return 0; /* EEE supported */ |
1071 | } | 1010 | } |
1072 | 1011 | ||
1073 | eee_exit: | 1012 | return -EPROTONOSUPPORT; |
1074 | return ret; | ||
1075 | } | 1013 | } |
1076 | EXPORT_SYMBOL(phy_init_eee); | 1014 | EXPORT_SYMBOL(phy_init_eee); |
1077 | 1015 | ||
@@ -1086,7 +1024,6 @@ int phy_get_eee_err(struct phy_device *phydev) | |||
1086 | { | 1024 | { |
1087 | return phy_read_mmd_indirect(phydev->bus, MDIO_PCS_EEE_WK_ERR, | 1025 | return phy_read_mmd_indirect(phydev->bus, MDIO_PCS_EEE_WK_ERR, |
1088 | MDIO_MMD_PCS, phydev->addr); | 1026 | MDIO_MMD_PCS, phydev->addr); |
1089 | |||
1090 | } | 1027 | } |
1091 | EXPORT_SYMBOL(phy_get_eee_err); | 1028 | EXPORT_SYMBOL(phy_get_eee_err); |
1092 | 1029 | ||
@@ -1136,9 +1073,8 @@ EXPORT_SYMBOL(phy_ethtool_get_eee); | |||
1136 | */ | 1073 | */ |
1137 | int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) | 1074 | int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) |
1138 | { | 1075 | { |
1139 | int val; | 1076 | int val = ethtool_adv_to_mmd_eee_adv_t(data->advertised); |
1140 | 1077 | ||
1141 | val = ethtool_adv_to_mmd_eee_adv_t(data->advertised); | ||
1142 | phy_write_mmd_indirect(phydev->bus, MDIO_AN_EEE_ADV, MDIO_MMD_AN, | 1078 | phy_write_mmd_indirect(phydev->bus, MDIO_AN_EEE_ADV, MDIO_MMD_AN, |
1143 | phydev->addr, val); | 1079 | phydev->addr, val); |
1144 | 1080 | ||
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index d6447b3f7409..2f6989b1e0dc 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c | |||
@@ -1,7 +1,4 @@ | |||
1 | /* | 1 | /* Framework for finding and configuring PHYs. |
2 | * drivers/net/phy/phy_device.c | ||
3 | * | ||
4 | * Framework for finding and configuring PHYs. | ||
5 | * Also contains generic PHY driver | 2 | * Also contains generic PHY driver |
6 | * | 3 | * |
7 | * Author: Andy Fleming | 4 | * Author: Andy Fleming |
@@ -33,10 +30,11 @@ | |||
33 | #include <linux/mii.h> | 30 | #include <linux/mii.h> |
34 | #include <linux/ethtool.h> | 31 | #include <linux/ethtool.h> |
35 | #include <linux/phy.h> | 32 | #include <linux/phy.h> |
33 | #include <linux/mdio.h> | ||
34 | #include <linux/io.h> | ||
35 | #include <linux/uaccess.h> | ||
36 | 36 | ||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | 37 | #include <asm/irq.h> |
39 | #include <asm/uaccess.h> | ||
40 | 38 | ||
41 | MODULE_DESCRIPTION("PHY library"); | 39 | MODULE_DESCRIPTION("PHY library"); |
42 | MODULE_AUTHOR("Andy Fleming"); | 40 | MODULE_AUTHOR("Andy Fleming"); |
@@ -53,31 +51,31 @@ static void phy_device_release(struct device *dev) | |||
53 | kfree(to_phy_device(dev)); | 51 | kfree(to_phy_device(dev)); |
54 | } | 52 | } |
55 | 53 | ||
56 | static struct phy_driver genphy_driver; | 54 | enum genphy_driver { |
57 | extern int mdio_bus_init(void); | 55 | GENPHY_DRV_1G, |
58 | extern void mdio_bus_exit(void); | 56 | GENPHY_DRV_10G, |
57 | GENPHY_DRV_MAX | ||
58 | }; | ||
59 | |||
60 | static struct phy_driver genphy_driver[GENPHY_DRV_MAX]; | ||
59 | 61 | ||
60 | static LIST_HEAD(phy_fixup_list); | 62 | static LIST_HEAD(phy_fixup_list); |
61 | static DEFINE_MUTEX(phy_fixup_lock); | 63 | static DEFINE_MUTEX(phy_fixup_lock); |
62 | 64 | ||
63 | static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | 65 | /** |
64 | u32 flags, phy_interface_t interface); | 66 | * phy_register_fixup - creates a new phy_fixup and adds it to the list |
65 | |||
66 | /* | ||
67 | * Creates a new phy_fixup and adds it to the list | ||
68 | * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID) | 67 | * @bus_id: A string which matches phydev->dev.bus_id (or PHY_ANY_ID) |
69 | * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) | 68 | * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY) |
70 | * It can also be PHY_ANY_UID | 69 | * It can also be PHY_ANY_UID |
71 | * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before | 70 | * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before |
72 | * comparison | 71 | * comparison |
73 | * @run: The actual code to be run when a matching PHY is found | 72 | * @run: The actual code to be run when a matching PHY is found |
74 | */ | 73 | */ |
75 | int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, | 74 | int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask, |
76 | int (*run)(struct phy_device *)) | 75 | int (*run)(struct phy_device *)) |
77 | { | 76 | { |
78 | struct phy_fixup *fixup; | 77 | struct phy_fixup *fixup = kzalloc(sizeof(*fixup), GFP_KERNEL); |
79 | 78 | ||
80 | fixup = kzalloc(sizeof(struct phy_fixup), GFP_KERNEL); | ||
81 | if (!fixup) | 79 | if (!fixup) |
82 | return -ENOMEM; | 80 | return -ENOMEM; |
83 | 81 | ||
@@ -96,7 +94,7 @@ EXPORT_SYMBOL(phy_register_fixup); | |||
96 | 94 | ||
97 | /* Registers a fixup to be run on any PHY with the UID in phy_uid */ | 95 | /* Registers a fixup to be run on any PHY with the UID in phy_uid */ |
98 | int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, | 96 | int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, |
99 | int (*run)(struct phy_device *)) | 97 | int (*run)(struct phy_device *)) |
100 | { | 98 | { |
101 | return phy_register_fixup(PHY_ANY_ID, phy_uid, phy_uid_mask, run); | 99 | return phy_register_fixup(PHY_ANY_ID, phy_uid, phy_uid_mask, run); |
102 | } | 100 | } |
@@ -104,14 +102,13 @@ EXPORT_SYMBOL(phy_register_fixup_for_uid); | |||
104 | 102 | ||
105 | /* Registers a fixup to be run on the PHY with id string bus_id */ | 103 | /* Registers a fixup to be run on the PHY with id string bus_id */ |
106 | int phy_register_fixup_for_id(const char *bus_id, | 104 | int phy_register_fixup_for_id(const char *bus_id, |
107 | int (*run)(struct phy_device *)) | 105 | int (*run)(struct phy_device *)) |
108 | { | 106 | { |
109 | return phy_register_fixup(bus_id, PHY_ANY_UID, 0xffffffff, run); | 107 | return phy_register_fixup(bus_id, PHY_ANY_UID, 0xffffffff, run); |
110 | } | 108 | } |
111 | EXPORT_SYMBOL(phy_register_fixup_for_id); | 109 | EXPORT_SYMBOL(phy_register_fixup_for_id); |
112 | 110 | ||
113 | /* | 111 | /* Returns 1 if fixup matches phydev in bus_id and phy_uid. |
114 | * Returns 1 if fixup matches phydev in bus_id and phy_uid. | ||
115 | * Fixups can be set to match any in one or more fields. | 112 | * Fixups can be set to match any in one or more fields. |
116 | */ | 113 | */ |
117 | static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) | 114 | static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) |
@@ -121,7 +118,7 @@ static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) | |||
121 | return 0; | 118 | return 0; |
122 | 119 | ||
123 | if ((fixup->phy_uid & fixup->phy_uid_mask) != | 120 | if ((fixup->phy_uid & fixup->phy_uid_mask) != |
124 | (phydev->phy_id & fixup->phy_uid_mask)) | 121 | (phydev->phy_id & fixup->phy_uid_mask)) |
125 | if (fixup->phy_uid != PHY_ANY_UID) | 122 | if (fixup->phy_uid != PHY_ANY_UID) |
126 | return 0; | 123 | return 0; |
127 | 124 | ||
@@ -129,16 +126,14 @@ static int phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *fixup) | |||
129 | } | 126 | } |
130 | 127 | ||
131 | /* Runs any matching fixups for this phydev */ | 128 | /* Runs any matching fixups for this phydev */ |
132 | int phy_scan_fixups(struct phy_device *phydev) | 129 | static int phy_scan_fixups(struct phy_device *phydev) |
133 | { | 130 | { |
134 | struct phy_fixup *fixup; | 131 | struct phy_fixup *fixup; |
135 | 132 | ||
136 | mutex_lock(&phy_fixup_lock); | 133 | mutex_lock(&phy_fixup_lock); |
137 | list_for_each_entry(fixup, &phy_fixup_list, list) { | 134 | list_for_each_entry(fixup, &phy_fixup_list, list) { |
138 | if (phy_needs_fixup(phydev, fixup)) { | 135 | if (phy_needs_fixup(phydev, fixup)) { |
139 | int err; | 136 | int err = fixup->run(phydev); |
140 | |||
141 | err = fixup->run(phydev); | ||
142 | 137 | ||
143 | if (err < 0) { | 138 | if (err < 0) { |
144 | mutex_unlock(&phy_fixup_lock); | 139 | mutex_unlock(&phy_fixup_lock); |
@@ -150,25 +145,24 @@ int phy_scan_fixups(struct phy_device *phydev) | |||
150 | 145 | ||
151 | return 0; | 146 | return 0; |
152 | } | 147 | } |
153 | EXPORT_SYMBOL(phy_scan_fixups); | ||
154 | 148 | ||
155 | struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, | 149 | struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, |
156 | bool is_c45, struct phy_c45_device_ids *c45_ids) | 150 | bool is_c45, |
151 | struct phy_c45_device_ids *c45_ids) | ||
157 | { | 152 | { |
158 | struct phy_device *dev; | 153 | struct phy_device *dev; |
159 | 154 | ||
160 | /* We allocate the device, and initialize the | 155 | /* We allocate the device, and initialize the default values */ |
161 | * default values */ | ||
162 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 156 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
163 | |||
164 | if (NULL == dev) | 157 | if (NULL == dev) |
165 | return (struct phy_device*) PTR_ERR((void*)-ENOMEM); | 158 | return (struct phy_device *)PTR_ERR((void *)-ENOMEM); |
166 | 159 | ||
167 | dev->dev.release = phy_device_release; | 160 | dev->dev.release = phy_device_release; |
168 | 161 | ||
169 | dev->speed = 0; | 162 | dev->speed = 0; |
170 | dev->duplex = -1; | 163 | dev->duplex = -1; |
171 | dev->pause = dev->asym_pause = 0; | 164 | dev->pause = 0; |
165 | dev->asym_pause = 0; | ||
172 | dev->link = 1; | 166 | dev->link = 1; |
173 | dev->interface = PHY_INTERFACE_MODE_GMII; | 167 | dev->interface = PHY_INTERFACE_MODE_GMII; |
174 | 168 | ||
@@ -192,14 +186,15 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, | |||
192 | INIT_WORK(&dev->phy_queue, phy_change); | 186 | INIT_WORK(&dev->phy_queue, phy_change); |
193 | 187 | ||
194 | /* Request the appropriate module unconditionally; don't | 188 | /* Request the appropriate module unconditionally; don't |
195 | bother trying to do so only if it isn't already loaded, | 189 | * bother trying to do so only if it isn't already loaded, |
196 | because that gets complicated. A hotplug event would have | 190 | * because that gets complicated. A hotplug event would have |
197 | done an unconditional modprobe anyway. | 191 | * done an unconditional modprobe anyway. |
198 | We don't do normal hotplug because it won't work for MDIO | 192 | * We don't do normal hotplug because it won't work for MDIO |
199 | -- because it relies on the device staying around for long | 193 | * -- because it relies on the device staying around for long |
200 | enough for the driver to get loaded. With MDIO, the NIC | 194 | * enough for the driver to get loaded. With MDIO, the NIC |
201 | driver will get bored and give up as soon as it finds that | 195 | * driver will get bored and give up as soon as it finds that |
202 | there's no driver _already_ loaded. */ | 196 | * there's no driver _already_ loaded. |
197 | */ | ||
203 | request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, MDIO_ID_ARGS(phy_id)); | 198 | request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, MDIO_ID_ARGS(phy_id)); |
204 | 199 | ||
205 | device_initialize(&dev->dev); | 200 | device_initialize(&dev->dev); |
@@ -299,10 +294,8 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, | |||
299 | if (is_c45) | 294 | if (is_c45) |
300 | return get_phy_c45_ids(bus, addr, phy_id, c45_ids); | 295 | return get_phy_c45_ids(bus, addr, phy_id, c45_ids); |
301 | 296 | ||
302 | /* Grab the bits from PHYIR1, and put them | 297 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
303 | * in the upper half */ | ||
304 | phy_reg = mdiobus_read(bus, addr, MII_PHYSID1); | 298 | phy_reg = mdiobus_read(bus, addr, MII_PHYSID1); |
305 | |||
306 | if (phy_reg < 0) | 299 | if (phy_reg < 0) |
307 | return -EIO; | 300 | return -EIO; |
308 | 301 | ||
@@ -310,7 +303,6 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, | |||
310 | 303 | ||
311 | /* Grab the bits from PHYIR2, and put them in the lower half */ | 304 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
312 | phy_reg = mdiobus_read(bus, addr, MII_PHYSID2); | 305 | phy_reg = mdiobus_read(bus, addr, MII_PHYSID2); |
313 | |||
314 | if (phy_reg < 0) | 306 | if (phy_reg < 0) |
315 | return -EIO; | 307 | return -EIO; |
316 | 308 | ||
@@ -320,7 +312,8 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, | |||
320 | } | 312 | } |
321 | 313 | ||
322 | /** | 314 | /** |
323 | * get_phy_device - reads the specified PHY device and returns its @phy_device struct | 315 | * get_phy_device - reads the specified PHY device and returns its @phy_device |
316 | * struct | ||
324 | * @bus: the target MII bus | 317 | * @bus: the target MII bus |
325 | * @addr: PHY address on the MII bus | 318 | * @addr: PHY address on the MII bus |
326 | * @is_c45: If true the PHY uses the 802.3 clause 45 protocol | 319 | * @is_c45: If true the PHY uses the 802.3 clause 45 protocol |
@@ -331,7 +324,6 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, | |||
331 | struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) | 324 | struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) |
332 | { | 325 | { |
333 | struct phy_c45_device_ids c45_ids = {0}; | 326 | struct phy_c45_device_ids c45_ids = {0}; |
334 | struct phy_device *dev = NULL; | ||
335 | u32 phy_id = 0; | 327 | u32 phy_id = 0; |
336 | int r; | 328 | int r; |
337 | 329 | ||
@@ -343,9 +335,7 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) | |||
343 | if ((phy_id & 0x1fffffff) == 0x1fffffff) | 335 | if ((phy_id & 0x1fffffff) == 0x1fffffff) |
344 | return NULL; | 336 | return NULL; |
345 | 337 | ||
346 | dev = phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); | 338 | return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); |
347 | |||
348 | return dev; | ||
349 | } | 339 | } |
350 | EXPORT_SYMBOL(get_phy_device); | 340 | EXPORT_SYMBOL(get_phy_device); |
351 | 341 | ||
@@ -357,14 +347,17 @@ int phy_device_register(struct phy_device *phydev) | |||
357 | { | 347 | { |
358 | int err; | 348 | int err; |
359 | 349 | ||
360 | /* Don't register a phy if one is already registered at this | 350 | /* Don't register a phy if one is already registered at this address */ |
361 | * address */ | ||
362 | if (phydev->bus->phy_map[phydev->addr]) | 351 | if (phydev->bus->phy_map[phydev->addr]) |
363 | return -EINVAL; | 352 | return -EINVAL; |
364 | phydev->bus->phy_map[phydev->addr] = phydev; | 353 | phydev->bus->phy_map[phydev->addr] = phydev; |
365 | 354 | ||
366 | /* Run all of the fixups for this PHY */ | 355 | /* Run all of the fixups for this PHY */ |
367 | phy_scan_fixups(phydev); | 356 | err = phy_init_hw(phydev); |
357 | if (err) { | ||
358 | pr_err("PHY %d failed to initialize\n", phydev->addr); | ||
359 | goto out; | ||
360 | } | ||
368 | 361 | ||
369 | err = device_add(&phydev->dev); | 362 | err = device_add(&phydev->dev); |
370 | if (err) { | 363 | if (err) { |
@@ -409,7 +402,7 @@ EXPORT_SYMBOL(phy_find_first); | |||
409 | * this function. | 402 | * this function. |
410 | */ | 403 | */ |
411 | static void phy_prepare_link(struct phy_device *phydev, | 404 | static void phy_prepare_link(struct phy_device *phydev, |
412 | void (*handler)(struct net_device *)) | 405 | void (*handler)(struct net_device *)) |
413 | { | 406 | { |
414 | phydev->adjust_link = handler; | 407 | phydev->adjust_link = handler; |
415 | } | 408 | } |
@@ -432,7 +425,7 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev, | |||
432 | return rc; | 425 | return rc; |
433 | 426 | ||
434 | phy_prepare_link(phydev, handler); | 427 | phy_prepare_link(phydev, handler); |
435 | phy_start_machine(phydev, NULL); | 428 | phy_start_machine(phydev); |
436 | if (phydev->irq > 0) | 429 | if (phydev->irq > 0) |
437 | phy_start_interrupts(phydev); | 430 | phy_start_interrupts(phydev); |
438 | 431 | ||
@@ -455,16 +448,17 @@ EXPORT_SYMBOL(phy_connect_direct); | |||
455 | * choose to call only the subset of functions which provide | 448 | * choose to call only the subset of functions which provide |
456 | * the desired functionality. | 449 | * the desired functionality. |
457 | */ | 450 | */ |
458 | struct phy_device * phy_connect(struct net_device *dev, const char *bus_id, | 451 | struct phy_device *phy_connect(struct net_device *dev, const char *bus_id, |
459 | void (*handler)(struct net_device *), | 452 | void (*handler)(struct net_device *), |
460 | phy_interface_t interface) | 453 | phy_interface_t interface) |
461 | { | 454 | { |
462 | struct phy_device *phydev; | 455 | struct phy_device *phydev; |
463 | struct device *d; | 456 | struct device *d; |
464 | int rc; | 457 | int rc; |
465 | 458 | ||
466 | /* Search the list of PHY devices on the mdio bus for the | 459 | /* Search the list of PHY devices on the mdio bus for the |
467 | * PHY with the requested name */ | 460 | * PHY with the requested name |
461 | */ | ||
468 | d = bus_find_device_by_name(&mdio_bus_type, NULL, bus_id); | 462 | d = bus_find_device_by_name(&mdio_bus_type, NULL, bus_id); |
469 | if (!d) { | 463 | if (!d) { |
470 | pr_err("PHY %s not found\n", bus_id); | 464 | pr_err("PHY %s not found\n", bus_id); |
@@ -481,7 +475,8 @@ struct phy_device * phy_connect(struct net_device *dev, const char *bus_id, | |||
481 | EXPORT_SYMBOL(phy_connect); | 475 | EXPORT_SYMBOL(phy_connect); |
482 | 476 | ||
483 | /** | 477 | /** |
484 | * phy_disconnect - disable interrupts, stop state machine, and detach a PHY device | 478 | * phy_disconnect - disable interrupts, stop state machine, and detach a PHY |
479 | * device | ||
485 | * @phydev: target phy_device struct | 480 | * @phydev: target phy_device struct |
486 | */ | 481 | */ |
487 | void phy_disconnect(struct phy_device *phydev) | 482 | void phy_disconnect(struct phy_device *phydev) |
@@ -490,13 +485,53 @@ void phy_disconnect(struct phy_device *phydev) | |||
490 | phy_stop_interrupts(phydev); | 485 | phy_stop_interrupts(phydev); |
491 | 486 | ||
492 | phy_stop_machine(phydev); | 487 | phy_stop_machine(phydev); |
493 | 488 | ||
494 | phydev->adjust_link = NULL; | 489 | phydev->adjust_link = NULL; |
495 | 490 | ||
496 | phy_detach(phydev); | 491 | phy_detach(phydev); |
497 | } | 492 | } |
498 | EXPORT_SYMBOL(phy_disconnect); | 493 | EXPORT_SYMBOL(phy_disconnect); |
499 | 494 | ||
495 | /** | ||
496 | * phy_poll_reset - Safely wait until a PHY reset has properly completed | ||
497 | * @phydev: The PHY device to poll | ||
498 | * | ||
499 | * Description: According to IEEE 802.3, Section 2, Subsection 22.2.4.1.1, as | ||
500 | * published in 2008, a PHY reset may take up to 0.5 seconds. The MII BMCR | ||
501 | * register must be polled until the BMCR_RESET bit clears. | ||
502 | * | ||
503 | * Furthermore, any attempts to write to PHY registers may have no effect | ||
504 | * or even generate MDIO bus errors until this is complete. | ||
505 | * | ||
506 | * Some PHYs (such as the Marvell 88E1111) don't entirely conform to the | ||
507 | * standard and do not fully reset after the BMCR_RESET bit is set, and may | ||
508 | * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an | ||
509 | * effort to support such broken PHYs, this function is separate from the | ||
510 | * standard phy_init_hw() which will zero all the other bits in the BMCR | ||
511 | * and reapply all driver-specific and board-specific fixups. | ||
512 | */ | ||
513 | static int phy_poll_reset(struct phy_device *phydev) | ||
514 | { | ||
515 | /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */ | ||
516 | unsigned int retries = 12; | ||
517 | int ret; | ||
518 | |||
519 | do { | ||
520 | msleep(50); | ||
521 | ret = phy_read(phydev, MII_BMCR); | ||
522 | if (ret < 0) | ||
523 | return ret; | ||
524 | } while (ret & BMCR_RESET && --retries); | ||
525 | if (ret & BMCR_RESET) | ||
526 | return -ETIMEDOUT; | ||
527 | |||
528 | /* Some chips (smsc911x) may still need up to another 1ms after the | ||
529 | * BMCR_RESET bit is cleared before they are usable. | ||
530 | */ | ||
531 | msleep(1); | ||
532 | return 0; | ||
533 | } | ||
534 | |||
500 | int phy_init_hw(struct phy_device *phydev) | 535 | int phy_init_hw(struct phy_device *phydev) |
501 | { | 536 | { |
502 | int ret; | 537 | int ret; |
@@ -504,12 +539,21 @@ int phy_init_hw(struct phy_device *phydev) | |||
504 | if (!phydev->drv || !phydev->drv->config_init) | 539 | if (!phydev->drv || !phydev->drv->config_init) |
505 | return 0; | 540 | return 0; |
506 | 541 | ||
542 | ret = phy_write(phydev, MII_BMCR, BMCR_RESET); | ||
543 | if (ret < 0) | ||
544 | return ret; | ||
545 | |||
546 | ret = phy_poll_reset(phydev); | ||
547 | if (ret < 0) | ||
548 | return ret; | ||
549 | |||
507 | ret = phy_scan_fixups(phydev); | 550 | ret = phy_scan_fixups(phydev); |
508 | if (ret < 0) | 551 | if (ret < 0) |
509 | return ret; | 552 | return ret; |
510 | 553 | ||
511 | return phydev->drv->config_init(phydev); | 554 | return phydev->drv->config_init(phydev); |
512 | } | 555 | } |
556 | EXPORT_SYMBOL(phy_init_hw); | ||
513 | 557 | ||
514 | /** | 558 | /** |
515 | * phy_attach_direct - attach a network device to a given PHY device pointer | 559 | * phy_attach_direct - attach a network device to a given PHY device pointer |
@@ -520,26 +564,25 @@ int phy_init_hw(struct phy_device *phydev) | |||
520 | * | 564 | * |
521 | * Description: Called by drivers to attach to a particular PHY | 565 | * Description: Called by drivers to attach to a particular PHY |
522 | * device. The phy_device is found, and properly hooked up | 566 | * device. The phy_device is found, and properly hooked up |
523 | * to the phy_driver. If no driver is attached, then the | 567 | * to the phy_driver. If no driver is attached, then a |
524 | * genphy_driver is used. The phy_device is given a ptr to | 568 | * generic driver is used. The phy_device is given a ptr to |
525 | * the attaching device, and given a callback for link status | 569 | * the attaching device, and given a callback for link status |
526 | * change. The phy_device is returned to the attaching driver. | 570 | * change. The phy_device is returned to the attaching driver. |
527 | */ | 571 | */ |
528 | static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | 572 | int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, |
529 | u32 flags, phy_interface_t interface) | 573 | u32 flags, phy_interface_t interface) |
530 | { | 574 | { |
531 | struct device *d = &phydev->dev; | 575 | struct device *d = &phydev->dev; |
532 | int err; | 576 | int err; |
533 | 577 | ||
534 | /* Assume that if there is no driver, that it doesn't | 578 | /* Assume that if there is no driver, that it doesn't |
535 | * exist, and we should use the genphy driver. */ | 579 | * exist, and we should use the genphy driver. |
580 | */ | ||
536 | if (NULL == d->driver) { | 581 | if (NULL == d->driver) { |
537 | if (phydev->is_c45) { | 582 | if (phydev->is_c45) |
538 | pr_err("No driver for phy %x\n", phydev->phy_id); | 583 | d->driver = &genphy_driver[GENPHY_DRV_10G].driver; |
539 | return -ENODEV; | 584 | else |
540 | } | 585 | d->driver = &genphy_driver[GENPHY_DRV_1G].driver; |
541 | |||
542 | d->driver = &genphy_driver.driver; | ||
543 | 586 | ||
544 | err = d->driver->probe(d); | 587 | err = d->driver->probe(d); |
545 | if (err >= 0) | 588 | if (err >= 0) |
@@ -565,13 +608,17 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | |||
565 | 608 | ||
566 | /* Do initial configuration here, now that | 609 | /* Do initial configuration here, now that |
567 | * we have certain key parameters | 610 | * we have certain key parameters |
568 | * (dev_flags and interface) */ | 611 | * (dev_flags and interface) |
612 | */ | ||
569 | err = phy_init_hw(phydev); | 613 | err = phy_init_hw(phydev); |
570 | if (err) | 614 | if (err) |
571 | phy_detach(phydev); | 615 | phy_detach(phydev); |
572 | 616 | ||
617 | phy_resume(phydev); | ||
618 | |||
573 | return err; | 619 | return err; |
574 | } | 620 | } |
621 | EXPORT_SYMBOL(phy_attach_direct); | ||
575 | 622 | ||
576 | /** | 623 | /** |
577 | * phy_attach - attach a network device to a particular PHY device | 624 | * phy_attach - attach a network device to a particular PHY device |
@@ -582,8 +629,8 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, | |||
582 | * Description: Same as phy_attach_direct() except that a PHY bus_id | 629 | * Description: Same as phy_attach_direct() except that a PHY bus_id |
583 | * string is passed instead of a pointer to a struct phy_device. | 630 | * string is passed instead of a pointer to a struct phy_device. |
584 | */ | 631 | */ |
585 | struct phy_device *phy_attach(struct net_device *dev, | 632 | struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, |
586 | const char *bus_id, phy_interface_t interface) | 633 | phy_interface_t interface) |
587 | { | 634 | { |
588 | struct bus_type *bus = &mdio_bus_type; | 635 | struct bus_type *bus = &mdio_bus_type; |
589 | struct phy_device *phydev; | 636 | struct phy_device *phydev; |
@@ -591,7 +638,8 @@ struct phy_device *phy_attach(struct net_device *dev, | |||
591 | int rc; | 638 | int rc; |
592 | 639 | ||
593 | /* Search the list of PHY devices on the mdio bus for the | 640 | /* Search the list of PHY devices on the mdio bus for the |
594 | * PHY with the requested name */ | 641 | * PHY with the requested name |
642 | */ | ||
595 | d = bus_find_device_by_name(bus, NULL, bus_id); | 643 | d = bus_find_device_by_name(bus, NULL, bus_id); |
596 | if (!d) { | 644 | if (!d) { |
597 | pr_err("PHY %s not found\n", bus_id); | 645 | pr_err("PHY %s not found\n", bus_id); |
@@ -613,18 +661,48 @@ EXPORT_SYMBOL(phy_attach); | |||
613 | */ | 661 | */ |
614 | void phy_detach(struct phy_device *phydev) | 662 | void phy_detach(struct phy_device *phydev) |
615 | { | 663 | { |
664 | int i; | ||
616 | phydev->attached_dev->phydev = NULL; | 665 | phydev->attached_dev->phydev = NULL; |
617 | phydev->attached_dev = NULL; | 666 | phydev->attached_dev = NULL; |
667 | phy_suspend(phydev); | ||
618 | 668 | ||
619 | /* If the device had no specific driver before (i.e. - it | 669 | /* If the device had no specific driver before (i.e. - it |
620 | * was using the generic driver), we unbind the device | 670 | * was using the generic driver), we unbind the device |
621 | * from the generic driver so that there's a chance a | 671 | * from the generic driver so that there's a chance a |
622 | * real driver could be loaded */ | 672 | * real driver could be loaded |
623 | if (phydev->dev.driver == &genphy_driver.driver) | 673 | */ |
624 | device_release_driver(&phydev->dev); | 674 | for (i = 0; i < ARRAY_SIZE(genphy_driver); i++) { |
675 | if (phydev->dev.driver == &genphy_driver[i].driver) { | ||
676 | device_release_driver(&phydev->dev); | ||
677 | break; | ||
678 | } | ||
679 | } | ||
625 | } | 680 | } |
626 | EXPORT_SYMBOL(phy_detach); | 681 | EXPORT_SYMBOL(phy_detach); |
627 | 682 | ||
683 | int phy_suspend(struct phy_device *phydev) | ||
684 | { | ||
685 | struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver); | ||
686 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; | ||
687 | |||
688 | /* If the device has WOL enabled, we cannot suspend the PHY */ | ||
689 | phy_ethtool_get_wol(phydev, &wol); | ||
690 | if (wol.wolopts) | ||
691 | return -EBUSY; | ||
692 | |||
693 | if (phydrv->suspend) | ||
694 | return phydrv->suspend(phydev); | ||
695 | return 0; | ||
696 | } | ||
697 | |||
698 | int phy_resume(struct phy_device *phydev) | ||
699 | { | ||
700 | struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver); | ||
701 | |||
702 | if (phydrv->resume) | ||
703 | return phydrv->resume(phydev); | ||
704 | return 0; | ||
705 | } | ||
628 | 706 | ||
629 | /* Generic PHY support and helper functions */ | 707 | /* Generic PHY support and helper functions */ |
630 | 708 | ||
@@ -640,20 +718,19 @@ EXPORT_SYMBOL(phy_detach); | |||
640 | static int genphy_config_advert(struct phy_device *phydev) | 718 | static int genphy_config_advert(struct phy_device *phydev) |
641 | { | 719 | { |
642 | u32 advertise; | 720 | u32 advertise; |
643 | int oldadv, adv; | 721 | int oldadv, adv, bmsr; |
644 | int err, changed = 0; | 722 | int err, changed = 0; |
645 | 723 | ||
646 | /* Only allow advertising what | 724 | /* Only allow advertising what this PHY supports */ |
647 | * this PHY supports */ | ||
648 | phydev->advertising &= phydev->supported; | 725 | phydev->advertising &= phydev->supported; |
649 | advertise = phydev->advertising; | 726 | advertise = phydev->advertising; |
650 | 727 | ||
651 | /* Setup standard advertisement */ | 728 | /* Setup standard advertisement */ |
652 | oldadv = adv = phy_read(phydev, MII_ADVERTISE); | 729 | adv = phy_read(phydev, MII_ADVERTISE); |
653 | |||
654 | if (adv < 0) | 730 | if (adv < 0) |
655 | return adv; | 731 | return adv; |
656 | 732 | ||
733 | oldadv = adv; | ||
657 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | | 734 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | |
658 | ADVERTISE_PAUSE_ASYM); | 735 | ADVERTISE_PAUSE_ASYM); |
659 | adv |= ethtool_adv_to_mii_adv_t(advertise); | 736 | adv |= ethtool_adv_to_mii_adv_t(advertise); |
@@ -666,26 +743,36 @@ static int genphy_config_advert(struct phy_device *phydev) | |||
666 | changed = 1; | 743 | changed = 1; |
667 | } | 744 | } |
668 | 745 | ||
669 | /* Configure gigabit if it's supported */ | 746 | bmsr = phy_read(phydev, MII_BMSR); |
670 | if (phydev->supported & (SUPPORTED_1000baseT_Half | | 747 | if (bmsr < 0) |
671 | SUPPORTED_1000baseT_Full)) { | 748 | return bmsr; |
672 | oldadv = adv = phy_read(phydev, MII_CTRL1000); | ||
673 | 749 | ||
674 | if (adv < 0) | 750 | /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all |
675 | return adv; | 751 | * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a |
752 | * logical 1. | ||
753 | */ | ||
754 | if (!(bmsr & BMSR_ESTATEN)) | ||
755 | return changed; | ||
676 | 756 | ||
677 | adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); | 757 | /* Configure gigabit if it's supported */ |
678 | adv |= ethtool_adv_to_mii_ctrl1000_t(advertise); | 758 | adv = phy_read(phydev, MII_CTRL1000); |
759 | if (adv < 0) | ||
760 | return adv; | ||
679 | 761 | ||
680 | if (adv != oldadv) { | 762 | oldadv = adv; |
681 | err = phy_write(phydev, MII_CTRL1000, adv); | 763 | adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
682 | 764 | ||
683 | if (err < 0) | 765 | if (phydev->supported & (SUPPORTED_1000baseT_Half | |
684 | return err; | 766 | SUPPORTED_1000baseT_Full)) { |
767 | adv |= ethtool_adv_to_mii_ctrl1000_t(advertise); | ||
768 | if (adv != oldadv) | ||
685 | changed = 1; | 769 | changed = 1; |
686 | } | ||
687 | } | 770 | } |
688 | 771 | ||
772 | err = phy_write(phydev, MII_CTRL1000, adv); | ||
773 | if (err < 0) | ||
774 | return err; | ||
775 | |||
689 | return changed; | 776 | return changed; |
690 | } | 777 | } |
691 | 778 | ||
@@ -699,10 +786,10 @@ static int genphy_config_advert(struct phy_device *phydev) | |||
699 | */ | 786 | */ |
700 | int genphy_setup_forced(struct phy_device *phydev) | 787 | int genphy_setup_forced(struct phy_device *phydev) |
701 | { | 788 | { |
702 | int err; | ||
703 | int ctl = 0; | 789 | int ctl = 0; |
704 | 790 | ||
705 | phydev->pause = phydev->asym_pause = 0; | 791 | phydev->pause = 0; |
792 | phydev->asym_pause = 0; | ||
706 | 793 | ||
707 | if (SPEED_1000 == phydev->speed) | 794 | if (SPEED_1000 == phydev->speed) |
708 | ctl |= BMCR_SPEED1000; | 795 | ctl |= BMCR_SPEED1000; |
@@ -711,10 +798,8 @@ int genphy_setup_forced(struct phy_device *phydev) | |||
711 | 798 | ||
712 | if (DUPLEX_FULL == phydev->duplex) | 799 | if (DUPLEX_FULL == phydev->duplex) |
713 | ctl |= BMCR_FULLDPLX; | 800 | ctl |= BMCR_FULLDPLX; |
714 | |||
715 | err = phy_write(phydev, MII_BMCR, ctl); | ||
716 | 801 | ||
717 | return err; | 802 | return phy_write(phydev, MII_BMCR, ctl); |
718 | } | 803 | } |
719 | EXPORT_SYMBOL(genphy_setup_forced); | 804 | EXPORT_SYMBOL(genphy_setup_forced); |
720 | 805 | ||
@@ -724,25 +809,20 @@ EXPORT_SYMBOL(genphy_setup_forced); | |||
724 | */ | 809 | */ |
725 | int genphy_restart_aneg(struct phy_device *phydev) | 810 | int genphy_restart_aneg(struct phy_device *phydev) |
726 | { | 811 | { |
727 | int ctl; | 812 | int ctl = phy_read(phydev, MII_BMCR); |
728 | |||
729 | ctl = phy_read(phydev, MII_BMCR); | ||
730 | 813 | ||
731 | if (ctl < 0) | 814 | if (ctl < 0) |
732 | return ctl; | 815 | return ctl; |
733 | 816 | ||
734 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); | 817 | ctl |= BMCR_ANENABLE | BMCR_ANRESTART; |
735 | 818 | ||
736 | /* Don't isolate the PHY if we're negotiating */ | 819 | /* Don't isolate the PHY if we're negotiating */ |
737 | ctl &= ~(BMCR_ISOLATE); | 820 | ctl &= ~BMCR_ISOLATE; |
738 | 821 | ||
739 | ctl = phy_write(phydev, MII_BMCR, ctl); | 822 | return phy_write(phydev, MII_BMCR, ctl); |
740 | |||
741 | return ctl; | ||
742 | } | 823 | } |
743 | EXPORT_SYMBOL(genphy_restart_aneg); | 824 | EXPORT_SYMBOL(genphy_restart_aneg); |
744 | 825 | ||
745 | |||
746 | /** | 826 | /** |
747 | * genphy_config_aneg - restart auto-negotiation or write BMCR | 827 | * genphy_config_aneg - restart auto-negotiation or write BMCR |
748 | * @phydev: target phy_device struct | 828 | * @phydev: target phy_device struct |
@@ -759,13 +839,12 @@ int genphy_config_aneg(struct phy_device *phydev) | |||
759 | return genphy_setup_forced(phydev); | 839 | return genphy_setup_forced(phydev); |
760 | 840 | ||
761 | result = genphy_config_advert(phydev); | 841 | result = genphy_config_advert(phydev); |
762 | |||
763 | if (result < 0) /* error */ | 842 | if (result < 0) /* error */ |
764 | return result; | 843 | return result; |
765 | |||
766 | if (result == 0) { | 844 | if (result == 0) { |
767 | /* Advertisement hasn't changed, but maybe aneg was never on to | 845 | /* Advertisement hasn't changed, but maybe aneg was never on to |
768 | * begin with? Or maybe phy was isolated? */ | 846 | * begin with? Or maybe phy was isolated? |
847 | */ | ||
769 | int ctl = phy_read(phydev, MII_BMCR); | 848 | int ctl = phy_read(phydev, MII_BMCR); |
770 | 849 | ||
771 | if (ctl < 0) | 850 | if (ctl < 0) |
@@ -776,7 +855,8 @@ int genphy_config_aneg(struct phy_device *phydev) | |||
776 | } | 855 | } |
777 | 856 | ||
778 | /* Only restart aneg if we are advertising something different | 857 | /* Only restart aneg if we are advertising something different |
779 | * than we were before. */ | 858 | * than we were before. |
859 | */ | ||
780 | if (result > 0) | 860 | if (result > 0) |
781 | result = genphy_restart_aneg(phydev); | 861 | result = genphy_restart_aneg(phydev); |
782 | 862 | ||
@@ -784,6 +864,11 @@ int genphy_config_aneg(struct phy_device *phydev) | |||
784 | } | 864 | } |
785 | EXPORT_SYMBOL(genphy_config_aneg); | 865 | EXPORT_SYMBOL(genphy_config_aneg); |
786 | 866 | ||
867 | static int gen10g_config_aneg(struct phy_device *phydev) | ||
868 | { | ||
869 | return 0; | ||
870 | } | ||
871 | |||
787 | /** | 872 | /** |
788 | * genphy_update_link - update link status in @phydev | 873 | * genphy_update_link - update link status in @phydev |
789 | * @phydev: target phy_device struct | 874 | * @phydev: target phy_device struct |
@@ -798,13 +883,11 @@ int genphy_update_link(struct phy_device *phydev) | |||
798 | 883 | ||
799 | /* Do a fake read */ | 884 | /* Do a fake read */ |
800 | status = phy_read(phydev, MII_BMSR); | 885 | status = phy_read(phydev, MII_BMSR); |
801 | |||
802 | if (status < 0) | 886 | if (status < 0) |
803 | return status; | 887 | return status; |
804 | 888 | ||
805 | /* Read link and autonegotiation status */ | 889 | /* Read link and autonegotiation status */ |
806 | status = phy_read(phydev, MII_BMSR); | 890 | status = phy_read(phydev, MII_BMSR); |
807 | |||
808 | if (status < 0) | 891 | if (status < 0) |
809 | return status; | 892 | return status; |
810 | 893 | ||
@@ -832,65 +915,70 @@ int genphy_read_status(struct phy_device *phydev) | |||
832 | int err; | 915 | int err; |
833 | int lpa; | 916 | int lpa; |
834 | int lpagb = 0; | 917 | int lpagb = 0; |
918 | int common_adv; | ||
919 | int common_adv_gb = 0; | ||
835 | 920 | ||
836 | /* Update the link, but return if there | 921 | /* Update the link, but return if there was an error */ |
837 | * was an error */ | ||
838 | err = genphy_update_link(phydev); | 922 | err = genphy_update_link(phydev); |
839 | if (err) | 923 | if (err) |
840 | return err; | 924 | return err; |
841 | 925 | ||
926 | phydev->lp_advertising = 0; | ||
927 | |||
842 | if (AUTONEG_ENABLE == phydev->autoneg) { | 928 | if (AUTONEG_ENABLE == phydev->autoneg) { |
843 | if (phydev->supported & (SUPPORTED_1000baseT_Half | 929 | if (phydev->supported & (SUPPORTED_1000baseT_Half |
844 | | SUPPORTED_1000baseT_Full)) { | 930 | | SUPPORTED_1000baseT_Full)) { |
845 | lpagb = phy_read(phydev, MII_STAT1000); | 931 | lpagb = phy_read(phydev, MII_STAT1000); |
846 | |||
847 | if (lpagb < 0) | 932 | if (lpagb < 0) |
848 | return lpagb; | 933 | return lpagb; |
849 | 934 | ||
850 | adv = phy_read(phydev, MII_CTRL1000); | 935 | adv = phy_read(phydev, MII_CTRL1000); |
851 | |||
852 | if (adv < 0) | 936 | if (adv < 0) |
853 | return adv; | 937 | return adv; |
854 | 938 | ||
855 | lpagb &= adv << 2; | 939 | phydev->lp_advertising = |
940 | mii_stat1000_to_ethtool_lpa_t(lpagb); | ||
941 | common_adv_gb = lpagb & adv << 2; | ||
856 | } | 942 | } |
857 | 943 | ||
858 | lpa = phy_read(phydev, MII_LPA); | 944 | lpa = phy_read(phydev, MII_LPA); |
859 | |||
860 | if (lpa < 0) | 945 | if (lpa < 0) |
861 | return lpa; | 946 | return lpa; |
862 | 947 | ||
863 | adv = phy_read(phydev, MII_ADVERTISE); | 948 | phydev->lp_advertising |= mii_lpa_to_ethtool_lpa_t(lpa); |
864 | 949 | ||
950 | adv = phy_read(phydev, MII_ADVERTISE); | ||
865 | if (adv < 0) | 951 | if (adv < 0) |
866 | return adv; | 952 | return adv; |
867 | 953 | ||
868 | lpa &= adv; | 954 | common_adv = lpa & adv; |
869 | 955 | ||
870 | phydev->speed = SPEED_10; | 956 | phydev->speed = SPEED_10; |
871 | phydev->duplex = DUPLEX_HALF; | 957 | phydev->duplex = DUPLEX_HALF; |
872 | phydev->pause = phydev->asym_pause = 0; | 958 | phydev->pause = 0; |
959 | phydev->asym_pause = 0; | ||
873 | 960 | ||
874 | if (lpagb & (LPA_1000FULL | LPA_1000HALF)) { | 961 | if (common_adv_gb & (LPA_1000FULL | LPA_1000HALF)) { |
875 | phydev->speed = SPEED_1000; | 962 | phydev->speed = SPEED_1000; |
876 | 963 | ||
877 | if (lpagb & LPA_1000FULL) | 964 | if (common_adv_gb & LPA_1000FULL) |
878 | phydev->duplex = DUPLEX_FULL; | 965 | phydev->duplex = DUPLEX_FULL; |
879 | } else if (lpa & (LPA_100FULL | LPA_100HALF)) { | 966 | } else if (common_adv & (LPA_100FULL | LPA_100HALF)) { |
880 | phydev->speed = SPEED_100; | 967 | phydev->speed = SPEED_100; |
881 | 968 | ||
882 | if (lpa & LPA_100FULL) | 969 | if (common_adv & LPA_100FULL) |
883 | phydev->duplex = DUPLEX_FULL; | 970 | phydev->duplex = DUPLEX_FULL; |
884 | } else | 971 | } else |
885 | if (lpa & LPA_10FULL) | 972 | if (common_adv & LPA_10FULL) |
886 | phydev->duplex = DUPLEX_FULL; | 973 | phydev->duplex = DUPLEX_FULL; |
887 | 974 | ||
888 | if (phydev->duplex == DUPLEX_FULL){ | 975 | if (phydev->duplex == DUPLEX_FULL) { |
889 | phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; | 976 | phydev->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; |
890 | phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; | 977 | phydev->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; |
891 | } | 978 | } |
892 | } else { | 979 | } else { |
893 | int bmcr = phy_read(phydev, MII_BMCR); | 980 | int bmcr = phy_read(phydev, MII_BMCR); |
981 | |||
894 | if (bmcr < 0) | 982 | if (bmcr < 0) |
895 | return bmcr; | 983 | return bmcr; |
896 | 984 | ||
@@ -906,27 +994,55 @@ int genphy_read_status(struct phy_device *phydev) | |||
906 | else | 994 | else |
907 | phydev->speed = SPEED_10; | 995 | phydev->speed = SPEED_10; |
908 | 996 | ||
909 | phydev->pause = phydev->asym_pause = 0; | 997 | phydev->pause = 0; |
998 | phydev->asym_pause = 0; | ||
910 | } | 999 | } |
911 | 1000 | ||
912 | return 0; | 1001 | return 0; |
913 | } | 1002 | } |
914 | EXPORT_SYMBOL(genphy_read_status); | 1003 | EXPORT_SYMBOL(genphy_read_status); |
915 | 1004 | ||
1005 | static int gen10g_read_status(struct phy_device *phydev) | ||
1006 | { | ||
1007 | int devad, reg; | ||
1008 | u32 mmd_mask = phydev->c45_ids.devices_in_package; | ||
1009 | |||
1010 | phydev->link = 1; | ||
1011 | |||
1012 | /* For now just lie and say it's 10G all the time */ | ||
1013 | phydev->speed = SPEED_10000; | ||
1014 | phydev->duplex = DUPLEX_FULL; | ||
1015 | |||
1016 | for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) { | ||
1017 | if (!(mmd_mask & 1)) | ||
1018 | continue; | ||
1019 | |||
1020 | /* Read twice because link state is latched and a | ||
1021 | * read moves the current state into the register | ||
1022 | */ | ||
1023 | phy_read_mmd(phydev, devad, MDIO_STAT1); | ||
1024 | reg = phy_read_mmd(phydev, devad, MDIO_STAT1); | ||
1025 | if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS)) | ||
1026 | phydev->link = 0; | ||
1027 | } | ||
1028 | |||
1029 | return 0; | ||
1030 | } | ||
1031 | |||
916 | static int genphy_config_init(struct phy_device *phydev) | 1032 | static int genphy_config_init(struct phy_device *phydev) |
917 | { | 1033 | { |
918 | int val; | 1034 | int val; |
919 | u32 features; | 1035 | u32 features; |
920 | 1036 | ||
921 | /* For now, I'll claim that the generic driver supports | 1037 | /* For now, I'll claim that the generic driver supports |
922 | * all possible port types */ | 1038 | * all possible port types |
1039 | */ | ||
923 | features = (SUPPORTED_TP | SUPPORTED_MII | 1040 | features = (SUPPORTED_TP | SUPPORTED_MII |
924 | | SUPPORTED_AUI | SUPPORTED_FIBRE | | 1041 | | SUPPORTED_AUI | SUPPORTED_FIBRE | |
925 | SUPPORTED_BNC); | 1042 | SUPPORTED_BNC); |
926 | 1043 | ||
927 | /* Do we support autonegotiation? */ | 1044 | /* Do we support autonegotiation? */ |
928 | val = phy_read(phydev, MII_BMSR); | 1045 | val = phy_read(phydev, MII_BMSR); |
929 | |||
930 | if (val < 0) | 1046 | if (val < 0) |
931 | return val; | 1047 | return val; |
932 | 1048 | ||
@@ -944,7 +1060,6 @@ static int genphy_config_init(struct phy_device *phydev) | |||
944 | 1060 | ||
945 | if (val & BMSR_ESTATEN) { | 1061 | if (val & BMSR_ESTATEN) { |
946 | val = phy_read(phydev, MII_ESTATUS); | 1062 | val = phy_read(phydev, MII_ESTATUS); |
947 | |||
948 | if (val < 0) | 1063 | if (val < 0) |
949 | return val; | 1064 | return val; |
950 | 1065 | ||
@@ -959,6 +1074,16 @@ static int genphy_config_init(struct phy_device *phydev) | |||
959 | 1074 | ||
960 | return 0; | 1075 | return 0; |
961 | } | 1076 | } |
1077 | |||
1078 | static int gen10g_config_init(struct phy_device *phydev) | ||
1079 | { | ||
1080 | /* Temporarily just say we support everything */ | ||
1081 | phydev->supported = SUPPORTED_10000baseT_Full; | ||
1082 | phydev->advertising = SUPPORTED_10000baseT_Full; | ||
1083 | |||
1084 | return 0; | ||
1085 | } | ||
1086 | |||
962 | int genphy_suspend(struct phy_device *phydev) | 1087 | int genphy_suspend(struct phy_device *phydev) |
963 | { | 1088 | { |
964 | int value; | 1089 | int value; |
@@ -966,7 +1091,7 @@ int genphy_suspend(struct phy_device *phydev) | |||
966 | mutex_lock(&phydev->lock); | 1091 | mutex_lock(&phydev->lock); |
967 | 1092 | ||
968 | value = phy_read(phydev, MII_BMCR); | 1093 | value = phy_read(phydev, MII_BMCR); |
969 | phy_write(phydev, MII_BMCR, (value | BMCR_PDOWN)); | 1094 | phy_write(phydev, MII_BMCR, value | BMCR_PDOWN); |
970 | 1095 | ||
971 | mutex_unlock(&phydev->lock); | 1096 | mutex_unlock(&phydev->lock); |
972 | 1097 | ||
@@ -974,6 +1099,11 @@ int genphy_suspend(struct phy_device *phydev) | |||
974 | } | 1099 | } |
975 | EXPORT_SYMBOL(genphy_suspend); | 1100 | EXPORT_SYMBOL(genphy_suspend); |
976 | 1101 | ||
1102 | static int gen10g_suspend(struct phy_device *phydev) | ||
1103 | { | ||
1104 | return 0; | ||
1105 | } | ||
1106 | |||
977 | int genphy_resume(struct phy_device *phydev) | 1107 | int genphy_resume(struct phy_device *phydev) |
978 | { | 1108 | { |
979 | int value; | 1109 | int value; |
@@ -981,7 +1111,7 @@ int genphy_resume(struct phy_device *phydev) | |||
981 | mutex_lock(&phydev->lock); | 1111 | mutex_lock(&phydev->lock); |
982 | 1112 | ||
983 | value = phy_read(phydev, MII_BMCR); | 1113 | value = phy_read(phydev, MII_BMCR); |
984 | phy_write(phydev, MII_BMCR, (value & ~BMCR_PDOWN)); | 1114 | phy_write(phydev, MII_BMCR, value & ~BMCR_PDOWN); |
985 | 1115 | ||
986 | mutex_unlock(&phydev->lock); | 1116 | mutex_unlock(&phydev->lock); |
987 | 1117 | ||
@@ -989,6 +1119,11 @@ int genphy_resume(struct phy_device *phydev) | |||
989 | } | 1119 | } |
990 | EXPORT_SYMBOL(genphy_resume); | 1120 | EXPORT_SYMBOL(genphy_resume); |
991 | 1121 | ||
1122 | static int gen10g_resume(struct phy_device *phydev) | ||
1123 | { | ||
1124 | return 0; | ||
1125 | } | ||
1126 | |||
992 | /** | 1127 | /** |
993 | * phy_probe - probe and init a PHY device | 1128 | * phy_probe - probe and init a PHY device |
994 | * @dev: device to probe and init | 1129 | * @dev: device to probe and init |
@@ -999,22 +1134,18 @@ EXPORT_SYMBOL(genphy_resume); | |||
999 | */ | 1134 | */ |
1000 | static int phy_probe(struct device *dev) | 1135 | static int phy_probe(struct device *dev) |
1001 | { | 1136 | { |
1002 | struct phy_device *phydev; | 1137 | struct phy_device *phydev = to_phy_device(dev); |
1003 | struct phy_driver *phydrv; | 1138 | struct device_driver *drv = phydev->dev.driver; |
1004 | struct device_driver *drv; | 1139 | struct phy_driver *phydrv = to_phy_driver(drv); |
1005 | int err = 0; | 1140 | int err = 0; |
1006 | 1141 | ||
1007 | phydev = to_phy_device(dev); | ||
1008 | |||
1009 | drv = phydev->dev.driver; | ||
1010 | phydrv = to_phy_driver(drv); | ||
1011 | phydev->drv = phydrv; | 1142 | phydev->drv = phydrv; |
1012 | 1143 | ||
1013 | /* Disable the interrupt if the PHY doesn't support it | 1144 | /* Disable the interrupt if the PHY doesn't support it |
1014 | * but the interrupt is still a valid one | 1145 | * but the interrupt is still a valid one |
1015 | */ | 1146 | */ |
1016 | if (!(phydrv->flags & PHY_HAS_INTERRUPT) && | 1147 | if (!(phydrv->flags & PHY_HAS_INTERRUPT) && |
1017 | phy_interrupt_is_valid(phydev)) | 1148 | phy_interrupt_is_valid(phydev)) |
1018 | phydev->irq = PHY_POLL; | 1149 | phydev->irq = PHY_POLL; |
1019 | 1150 | ||
1020 | if (phydrv->flags & PHY_IS_INTERNAL) | 1151 | if (phydrv->flags & PHY_IS_INTERNAL) |
@@ -1024,7 +1155,8 @@ static int phy_probe(struct device *dev) | |||
1024 | 1155 | ||
1025 | /* Start out supporting everything. Eventually, | 1156 | /* Start out supporting everything. Eventually, |
1026 | * a controller will attach, and may modify one | 1157 | * a controller will attach, and may modify one |
1027 | * or both of these values */ | 1158 | * or both of these values |
1159 | */ | ||
1028 | phydev->supported = phydrv->features; | 1160 | phydev->supported = phydrv->features; |
1029 | phydev->advertising = phydrv->features; | 1161 | phydev->advertising = phydrv->features; |
1030 | 1162 | ||
@@ -1037,14 +1169,11 @@ static int phy_probe(struct device *dev) | |||
1037 | mutex_unlock(&phydev->lock); | 1169 | mutex_unlock(&phydev->lock); |
1038 | 1170 | ||
1039 | return err; | 1171 | return err; |
1040 | |||
1041 | } | 1172 | } |
1042 | 1173 | ||
1043 | static int phy_remove(struct device *dev) | 1174 | static int phy_remove(struct device *dev) |
1044 | { | 1175 | { |
1045 | struct phy_device *phydev; | 1176 | struct phy_device *phydev = to_phy_device(dev); |
1046 | |||
1047 | phydev = to_phy_device(dev); | ||
1048 | 1177 | ||
1049 | mutex_lock(&phydev->lock); | 1178 | mutex_lock(&phydev->lock); |
1050 | phydev->state = PHY_DOWN; | 1179 | phydev->state = PHY_DOWN; |
@@ -1071,7 +1200,6 @@ int phy_driver_register(struct phy_driver *new_driver) | |||
1071 | new_driver->driver.remove = phy_remove; | 1200 | new_driver->driver.remove = phy_remove; |
1072 | 1201 | ||
1073 | retval = driver_register(&new_driver->driver); | 1202 | retval = driver_register(&new_driver->driver); |
1074 | |||
1075 | if (retval) { | 1203 | if (retval) { |
1076 | pr_err("%s: Error %d in registering driver\n", | 1204 | pr_err("%s: Error %d in registering driver\n", |
1077 | new_driver->name, retval); | 1205 | new_driver->name, retval); |
@@ -1110,13 +1238,14 @@ EXPORT_SYMBOL(phy_driver_unregister); | |||
1110 | void phy_drivers_unregister(struct phy_driver *drv, int n) | 1238 | void phy_drivers_unregister(struct phy_driver *drv, int n) |
1111 | { | 1239 | { |
1112 | int i; | 1240 | int i; |
1113 | for (i = 0; i < n; i++) { | 1241 | |
1242 | for (i = 0; i < n; i++) | ||
1114 | phy_driver_unregister(drv + i); | 1243 | phy_driver_unregister(drv + i); |
1115 | } | ||
1116 | } | 1244 | } |
1117 | EXPORT_SYMBOL(phy_drivers_unregister); | 1245 | EXPORT_SYMBOL(phy_drivers_unregister); |
1118 | 1246 | ||
1119 | static struct phy_driver genphy_driver = { | 1247 | static struct phy_driver genphy_driver[] = { |
1248 | { | ||
1120 | .phy_id = 0xffffffff, | 1249 | .phy_id = 0xffffffff, |
1121 | .phy_id_mask = 0xffffffff, | 1250 | .phy_id_mask = 0xffffffff, |
1122 | .name = "Generic PHY", | 1251 | .name = "Generic PHY", |
@@ -1126,8 +1255,19 @@ static struct phy_driver genphy_driver = { | |||
1126 | .read_status = genphy_read_status, | 1255 | .read_status = genphy_read_status, |
1127 | .suspend = genphy_suspend, | 1256 | .suspend = genphy_suspend, |
1128 | .resume = genphy_resume, | 1257 | .resume = genphy_resume, |
1129 | .driver = {.owner= THIS_MODULE, }, | 1258 | .driver = { .owner = THIS_MODULE, }, |
1130 | }; | 1259 | }, { |
1260 | .phy_id = 0xffffffff, | ||
1261 | .phy_id_mask = 0xffffffff, | ||
1262 | .name = "Generic 10G PHY", | ||
1263 | .config_init = gen10g_config_init, | ||
1264 | .features = 0, | ||
1265 | .config_aneg = gen10g_config_aneg, | ||
1266 | .read_status = gen10g_read_status, | ||
1267 | .suspend = gen10g_suspend, | ||
1268 | .resume = gen10g_resume, | ||
1269 | .driver = {.owner = THIS_MODULE, }, | ||
1270 | } }; | ||
1131 | 1271 | ||
1132 | static int __init phy_init(void) | 1272 | static int __init phy_init(void) |
1133 | { | 1273 | { |
@@ -1137,7 +1277,8 @@ static int __init phy_init(void) | |||
1137 | if (rc) | 1277 | if (rc) |
1138 | return rc; | 1278 | return rc; |
1139 | 1279 | ||
1140 | rc = phy_driver_register(&genphy_driver); | 1280 | rc = phy_drivers_register(genphy_driver, |
1281 | ARRAY_SIZE(genphy_driver)); | ||
1141 | if (rc) | 1282 | if (rc) |
1142 | mdio_bus_exit(); | 1283 | mdio_bus_exit(); |
1143 | 1284 | ||
@@ -1146,7 +1287,8 @@ static int __init phy_init(void) | |||
1146 | 1287 | ||
1147 | static void __exit phy_exit(void) | 1288 | static void __exit phy_exit(void) |
1148 | { | 1289 | { |
1149 | phy_driver_unregister(&genphy_driver); | 1290 | phy_drivers_unregister(genphy_driver, |
1291 | ARRAY_SIZE(genphy_driver)); | ||
1150 | mdio_bus_exit(); | 1292 | mdio_bus_exit(); |
1151 | } | 1293 | } |
1152 | 1294 | ||
diff --git a/drivers/net/phy/spi_ks8995.c b/drivers/net/phy/spi_ks8995.c index f3bea1346021..4cf5fb922e59 100644 --- a/drivers/net/phy/spi_ks8995.c +++ b/drivers/net/phy/spi_ks8995.c | |||
@@ -15,7 +15,6 @@ | |||
15 | 15 | ||
16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
20 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
21 | #include <linux/device.h> | 20 | #include <linux/device.h> |
@@ -171,14 +170,14 @@ static int ks8995_write(struct ks8995_switch *ks, char *buf, | |||
171 | 170 | ||
172 | static inline int ks8995_read_reg(struct ks8995_switch *ks, u8 addr, u8 *buf) | 171 | static inline int ks8995_read_reg(struct ks8995_switch *ks, u8 addr, u8 *buf) |
173 | { | 172 | { |
174 | return (ks8995_read(ks, buf, addr, 1) != 1); | 173 | return ks8995_read(ks, buf, addr, 1) != 1; |
175 | } | 174 | } |
176 | 175 | ||
177 | static inline int ks8995_write_reg(struct ks8995_switch *ks, u8 addr, u8 val) | 176 | static inline int ks8995_write_reg(struct ks8995_switch *ks, u8 addr, u8 val) |
178 | { | 177 | { |
179 | char buf = val; | 178 | char buf = val; |
180 | 179 | ||
181 | return (ks8995_write(ks, &buf, addr, 1) != 1); | 180 | return ks8995_write(ks, &buf, addr, 1) != 1; |
182 | } | 181 | } |
183 | 182 | ||
184 | /* ------------------------------------------------------------------------ */ | 183 | /* ------------------------------------------------------------------------ */ |
@@ -325,7 +324,6 @@ static int ks8995_probe(struct spi_device *spi) | |||
325 | return 0; | 324 | return 0; |
326 | 325 | ||
327 | err_drvdata: | 326 | err_drvdata: |
328 | spi_set_drvdata(spi, NULL); | ||
329 | kfree(ks); | 327 | kfree(ks); |
330 | return err; | 328 | return err; |
331 | } | 329 | } |
@@ -337,7 +335,6 @@ static int ks8995_remove(struct spi_device *spi) | |||
337 | ks8995 = spi_get_drvdata(spi); | 335 | ks8995 = spi_get_drvdata(spi); |
338 | sysfs_remove_bin_file(&spi->dev.kobj, &ks8995_registers_attr); | 336 | sysfs_remove_bin_file(&spi->dev.kobj, &ks8995_registers_attr); |
339 | 337 | ||
340 | spi_set_drvdata(spi, NULL); | ||
341 | kfree(ks8995); | 338 | kfree(ks8995); |
342 | 339 | ||
343 | return 0; | 340 | return 0; |