]>
Commit | Line | Data |
---|---|---|
34e45ad9 AD |
1 | /* |
2 | * Driver for the Texas Instruments DP83848 PHY | |
3 | * | |
2f67864b | 4 | * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/ |
34e45ad9 AD |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | */ | |
15 | ||
16 | #include <linux/module.h> | |
17 | #include <linux/phy.h> | |
18 | ||
68336293 AD |
19 | #define TI_DP83848C_PHY_ID 0x20005ca0 |
20 | #define NS_DP83848C_PHY_ID 0x20005c90 | |
34e45ad9 AD |
21 | |
22 | /* Registers */ | |
23 | #define DP83848_MICR 0x11 | |
24 | #define DP83848_MISR 0x12 | |
25 | ||
26 | /* MICR Register Fields */ | |
27 | #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */ | |
28 | #define DP83848_MICR_INTEN BIT(1) /* Interrupt Enable */ | |
29 | ||
30 | /* MISR Register Fields */ | |
31 | #define DP83848_MISR_RHF_INT_EN BIT(0) /* Receive Error Counter */ | |
32 | #define DP83848_MISR_FHF_INT_EN BIT(1) /* False Carrier Counter */ | |
33 | #define DP83848_MISR_ANC_INT_EN BIT(2) /* Auto-negotiation complete */ | |
34 | #define DP83848_MISR_DUP_INT_EN BIT(3) /* Duplex Status */ | |
35 | #define DP83848_MISR_SPD_INT_EN BIT(4) /* Speed status */ | |
36 | #define DP83848_MISR_LINK_INT_EN BIT(5) /* Link status */ | |
37 | #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */ | |
38 | #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */ | |
39 | ||
cf13be5a AD |
40 | #define DP83848_INT_EN_MASK \ |
41 | (DP83848_MISR_ANC_INT_EN | \ | |
42 | DP83848_MISR_DUP_INT_EN | \ | |
43 | DP83848_MISR_SPD_INT_EN | \ | |
44 | DP83848_MISR_LINK_INT_EN) | |
45 | ||
34e45ad9 AD |
46 | static int dp83848_ack_interrupt(struct phy_device *phydev) |
47 | { | |
48 | int err = phy_read(phydev, DP83848_MISR); | |
49 | ||
50 | return err < 0 ? err : 0; | |
51 | } | |
52 | ||
53 | static int dp83848_config_intr(struct phy_device *phydev) | |
54 | { | |
cf13be5a AD |
55 | int control, ret; |
56 | ||
57 | control = phy_read(phydev, DP83848_MICR); | |
58 | if (control < 0) | |
59 | return control; | |
34e45ad9 AD |
60 | |
61 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { | |
cf13be5a AD |
62 | control |= DP83848_MICR_INT_OE; |
63 | control |= DP83848_MICR_INTEN; | |
34e45ad9 | 64 | |
cf13be5a AD |
65 | ret = phy_write(phydev, DP83848_MISR, DP83848_INT_EN_MASK); |
66 | if (ret < 0) | |
67 | return ret; | |
68 | } else { | |
69 | control &= ~DP83848_MICR_INTEN; | |
34e45ad9 AD |
70 | } |
71 | ||
cf13be5a | 72 | return phy_write(phydev, DP83848_MICR, control); |
34e45ad9 AD |
73 | } |
74 | ||
75 | static struct mdio_device_id __maybe_unused dp83848_tbl[] = { | |
68336293 AD |
76 | { TI_DP83848C_PHY_ID, 0xfffffff0 }, |
77 | { NS_DP83848C_PHY_ID, 0xfffffff0 }, | |
34e45ad9 AD |
78 | { } |
79 | }; | |
80 | MODULE_DEVICE_TABLE(mdio, dp83848_tbl); | |
81 | ||
2f67864b AD |
82 | #define DP83848_PHY_DRIVER(_id, _name) \ |
83 | { \ | |
84 | .phy_id = _id, \ | |
85 | .phy_id_mask = 0xfffffff0, \ | |
86 | .name = _name, \ | |
87 | .features = PHY_BASIC_FEATURES, \ | |
88 | .flags = PHY_HAS_INTERRUPT, \ | |
89 | \ | |
90 | .soft_reset = genphy_soft_reset, \ | |
91 | .config_init = genphy_config_init, \ | |
92 | .suspend = genphy_suspend, \ | |
93 | .resume = genphy_resume, \ | |
94 | .config_aneg = genphy_config_aneg, \ | |
95 | .read_status = genphy_read_status, \ | |
96 | \ | |
97 | /* IRQ related */ \ | |
98 | .ack_interrupt = dp83848_ack_interrupt, \ | |
99 | .config_intr = dp83848_config_intr, \ | |
100 | } | |
34e45ad9 | 101 | |
2f67864b | 102 | static struct phy_driver dp83848_driver[] = { |
68336293 AD |
103 | DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY"), |
104 | DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY"), | |
34e45ad9 AD |
105 | }; |
106 | module_phy_driver(dp83848_driver); | |
107 | ||
108 | MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver"); | |
109 | MODULE_AUTHOR("Andrew F. Davis <afd@ti.com"); | |
110 | MODULE_LICENSE("GPL"); |