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
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
11 As fixed_phy_update_regs() no longer updates register state, rename
12 it to fixed_phy_update().
14 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
15 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
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(-)
22 --- a/drivers/net/phy/fixed_phy.c
23 +++ b/drivers/net/phy/fixed_phy.c
28 -#define MII_REGS_NUM 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 {
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),
45 -static void fixed_phy_update_regs(struct fixed_phy *fp)
46 +static void fixed_phy_update(struct fixed_phy *fp)
48 if (gpio_is_valid(fp->link_gpio))
49 fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
51 - swphy_update_regs(fp->regs, &fp->status);
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;
59 - if (reg_num >= MII_REGS_NUM)
62 - /* We do not support emulating Clause 45 over Clause 22 register reads
63 - * return an error instead of bogus data.
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,
79 - fixed_phy_update_regs(fp);
80 + fixed_phy_update(fp);
82 - return fp->regs[reg_num];
83 + return swphy_read_reg(reg_num, &fp->status);
87 @@ -144,7 +125,7 @@ int fixed_phy_update_state(struct phy_de
91 - fixed_phy_update_regs(fp);
92 + fixed_phy_update(fp);
96 @@ -169,8 +150,6 @@ int fixed_phy_add(unsigned int irq, int
100 - memset(fp->regs, 0xFF, sizeof(fp->regs[0]) * MII_REGS_NUM);
102 fmb->irqs[phy_addr] = irq;
105 @@ -184,7 +163,7 @@ int fixed_phy_add(unsigned int irq, int
109 - fixed_phy_update_regs(fp);
110 + fixed_phy_update(fp);
112 list_add_tail(&fp->node, &fmb->phys);
114 --- a/drivers/net/phy/swphy.c
115 +++ b/drivers/net/phy/swphy.c
120 +#define MII_REGS_NUM 29
125 @@ -110,14 +112,13 @@ int swphy_validate_state(const struct fi
126 EXPORT_SYMBOL_GPL(swphy_validate_state);
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
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.
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)
142 int speed_index, duplex_index;
143 u16 bmsr = BMSR_ANEGCAPABLE;
144 @@ -125,9 +126,12 @@ void swphy_update_regs(u16 *regs, const
148 + if (reg > MII_REGS_NUM)
151 speed_index = swphy_decode_speed(state->speed);
152 if (WARN_ON(speed_index < 0))
156 duplex_index = state->duplex ? SWMII_DUPLEX_FULL : SWMII_DUPLEX_HALF;
158 @@ -147,12 +151,29 @@ void swphy_update_regs(u16 *regs, const
159 lpa |= LPA_PAUSE_ASYM;
162 - regs[MII_PHYSID1] = 0;
163 - regs[MII_PHYSID2] = 0;
178 + * We do not support emulating Clause 45 over Clause 22 register
179 + * reads. Return an error instead of bogus data.
185 - regs[MII_BMSR] = bmsr;
186 - regs[MII_BMCR] = bmcr;
187 - regs[MII_LPA] = lpa;
188 - regs[MII_STAT1000] = lpagb;
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
198 struct fixed_phy_status;
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);