arm64: Switch to 4.9 kernel
[openwrt/openwrt.git] / target / linux / mvebu / patches-4.4 / 123-phy-generate-swphy-registers-on-the-fly.patch
1 From e0f33a88243329da1aa5a90fe10ab25c9fb0a091 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@arm.linux.org.uk>
3 Date: Sun, 20 Sep 2015 11:28:39 +0100
4 Subject: [PATCH 712/744] phy: generate swphy registers on the fly
5
6 Generate software phy registers as and when requested, rather than
7 duplicating the state in fixed_phy. This allows us to eliminate
8 the duplicate storage of of the same data, which is only different
9 in format.
10
11 As fixed_phy_update_regs() no longer updates register state, rename
12 it to fixed_phy_update().
13
14 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
15 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
16 ---
17 drivers/net/phy/fixed_phy.c | 31 +++++-------------------------
18 drivers/net/phy/swphy.c | 47 ++++++++++++++++++++++++++++++++-------------
19 drivers/net/phy/swphy.h | 2 +-
20 3 files changed, 40 insertions(+), 40 deletions(-)
21
22 --- a/drivers/net/phy/fixed_phy.c
23 +++ b/drivers/net/phy/fixed_phy.c
24 @@ -26,8 +26,6 @@
25
26 #include "swphy.h"
27
28 -#define MII_REGS_NUM 29
29 -
30 struct fixed_mdio_bus {
31 int irqs[PHY_MAX_ADDR];
32 struct mii_bus *mii_bus;
33 @@ -36,7 +34,6 @@ struct fixed_mdio_bus {
34
35 struct fixed_phy {
36 int addr;
37 - u16 regs[MII_REGS_NUM];
38 struct phy_device *phydev;
39 struct fixed_phy_status status;
40 int (*link_update)(struct net_device *, struct fixed_phy_status *);
41 @@ -49,12 +46,10 @@ static struct fixed_mdio_bus platform_fm
42 .phys = LIST_HEAD_INIT(platform_fmb.phys),
43 };
44
45 -static void fixed_phy_update_regs(struct fixed_phy *fp)
46 +static void fixed_phy_update(struct fixed_phy *fp)
47 {
48 if (gpio_is_valid(fp->link_gpio))
49 fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
50 -
51 - swphy_update_regs(fp->regs, &fp->status);
52 }
53
54 static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
55 @@ -62,29 +57,15 @@ static int fixed_mdio_read(struct mii_bu
56 struct fixed_mdio_bus *fmb = bus->priv;
57 struct fixed_phy *fp;
58
59 - if (reg_num >= MII_REGS_NUM)
60 - return -1;
61 -
62 - /* We do not support emulating Clause 45 over Clause 22 register reads
63 - * return an error instead of bogus data.
64 - */
65 - switch (reg_num) {
66 - case MII_MMD_CTRL:
67 - case MII_MMD_DATA:
68 - return -1;
69 - default:
70 - break;
71 - }
72 -
73 list_for_each_entry(fp, &fmb->phys, node) {
74 if (fp->addr == phy_addr) {
75 /* Issue callback if user registered it. */
76 if (fp->link_update) {
77 fp->link_update(fp->phydev->attached_dev,
78 &fp->status);
79 - fixed_phy_update_regs(fp);
80 + fixed_phy_update(fp);
81 }
82 - return fp->regs[reg_num];
83 + return swphy_read_reg(reg_num, &fp->status);
84 }
85 }
86
87 @@ -144,7 +125,7 @@ int fixed_phy_update_state(struct phy_de
88 _UPD(pause);
89 _UPD(asym_pause);
90 #undef _UPD
91 - fixed_phy_update_regs(fp);
92 + fixed_phy_update(fp);
93 return 0;
94 }
95 }
96 @@ -169,8 +150,6 @@ int fixed_phy_add(unsigned int irq, int
97 if (!fp)
98 return -ENOMEM;
99
100 - memset(fp->regs, 0xFF, sizeof(fp->regs[0]) * MII_REGS_NUM);
101 -
102 fmb->irqs[phy_addr] = irq;
103
104 fp->addr = phy_addr;
105 @@ -184,7 +163,7 @@ int fixed_phy_add(unsigned int irq, int
106 goto err_regs;
107 }
108
109 - fixed_phy_update_regs(fp);
110 + fixed_phy_update(fp);
111
112 list_add_tail(&fp->node, &fmb->phys);
113
114 --- a/drivers/net/phy/swphy.c
115 +++ b/drivers/net/phy/swphy.c
116 @@ -20,6 +20,8 @@
117
118 #include "swphy.h"
119
120 +#define MII_REGS_NUM 29
121 +
122 struct swmii_regs {
123 u16 bmcr;
124 u16 bmsr;
125 @@ -110,14 +112,13 @@ int swphy_validate_state(const struct fi
126 EXPORT_SYMBOL_GPL(swphy_validate_state);
127
128 /**
129 - * swphy_update_regs - update MII register array with fixed phy state
130 - * @regs: array of 32 registers to update
131 + * swphy_read_reg - return a MII register from the fixed phy state
132 + * @reg: MII register
133 * @state: fixed phy status
134 *
135 - * Update the array of MII registers with the fixed phy link, speed,
136 - * duplex and pause mode settings.
137 + * Return the MII @reg register generated from the fixed phy state @state.
138 */
139 -void swphy_update_regs(u16 *regs, const struct fixed_phy_status *state)
140 +int swphy_read_reg(int reg, const struct fixed_phy_status *state)
141 {
142 int speed_index, duplex_index;
143 u16 bmsr = BMSR_ANEGCAPABLE;
144 @@ -125,9 +126,12 @@ void swphy_update_regs(u16 *regs, const
145 u16 lpagb = 0;
146 u16 lpa = 0;
147
148 + if (reg > MII_REGS_NUM)
149 + return -1;
150 +
151 speed_index = swphy_decode_speed(state->speed);
152 if (WARN_ON(speed_index < 0))
153 - return;
154 + return 0;
155
156 duplex_index = state->duplex ? SWMII_DUPLEX_FULL : SWMII_DUPLEX_HALF;
157
158 @@ -147,12 +151,29 @@ void swphy_update_regs(u16 *regs, const
159 lpa |= LPA_PAUSE_ASYM;
160 }
161
162 - regs[MII_PHYSID1] = 0;
163 - regs[MII_PHYSID2] = 0;
164 + switch (reg) {
165 + case MII_BMCR:
166 + return bmcr;
167 + case MII_BMSR:
168 + return bmsr;
169 + case MII_PHYSID1:
170 + case MII_PHYSID2:
171 + return 0;
172 + case MII_LPA:
173 + return lpa;
174 + case MII_STAT1000:
175 + return lpagb;
176 +
177 + /*
178 + * We do not support emulating Clause 45 over Clause 22 register
179 + * reads. Return an error instead of bogus data.
180 + */
181 + case MII_MMD_CTRL:
182 + case MII_MMD_DATA:
183 + return -1;
184
185 - regs[MII_BMSR] = bmsr;
186 - regs[MII_BMCR] = bmcr;
187 - regs[MII_LPA] = lpa;
188 - regs[MII_STAT1000] = lpagb;
189 + default:
190 + return 0xffff;
191 + }
192 }
193 -EXPORT_SYMBOL_GPL(swphy_update_regs);
194 +EXPORT_SYMBOL_GPL(swphy_read_reg);
195 --- a/drivers/net/phy/swphy.h
196 +++ b/drivers/net/phy/swphy.h
197 @@ -4,6 +4,6 @@
198 struct fixed_phy_status;
199
200 int swphy_validate_state(const struct fixed_phy_status *state);
201 -void swphy_update_regs(u16 *regs, const struct fixed_phy_status *state);
202 +int swphy_read_reg(int reg, const struct fixed_phy_status *state);
203
204 #endif