1 From 4d5621372f6e7ddbfd5879602f82073987bcc722 Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@arm.linux.org.uk>
3 Date: Sun, 20 Sep 2015 09:57:10 +0100
4 Subject: [PATCH 709/744] phy: move fixed_phy MII register generation to a
7 Move the fixed_phy MII register generation to a library to allow other
8 software phy implementations to use this code.
10 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
11 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
13 drivers/net/phy/Kconfig | 4 ++
14 drivers/net/phy/Makefile | 3 +-
15 drivers/net/phy/fixed_phy.c | 95 ++-------------------------------
16 drivers/net/phy/swphy.c | 126 ++++++++++++++++++++++++++++++++++++++++++++
17 drivers/net/phy/swphy.h | 8 +++
18 5 files changed, 143 insertions(+), 93 deletions(-)
19 create mode 100644 drivers/net/phy/swphy.c
20 create mode 100644 drivers/net/phy/swphy.h
22 --- a/drivers/net/phy/Kconfig
23 +++ b/drivers/net/phy/Kconfig
24 @@ -26,6 +26,9 @@ config SWCONFIG_LEDS
25 bool "Switch LED trigger support"
26 depends on (SWCONFIG && LEDS_TRIGGERS)
31 comment "MII PHY device drivers"
34 @@ -205,6 +208,7 @@ config RTL8306_PHY
36 tristate "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
40 Adds the platform "fixed" MDIO Bus to cover the boards that use
41 PHYs that are not connected to the real MDIO bus.
42 --- a/drivers/net/phy/Makefile
43 +++ b/drivers/net/phy/Makefile
45 # Makefile for Linux PHY drivers
47 -libphy-objs := phy.o phy_device.o mdio_bus.o
48 +libphy-y := phy.o phy_device.o mdio_bus.o
49 +libphy-$(CONFIG_SWPHY) += swphy.o
51 obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
53 --- a/drivers/net/phy/fixed_phy.c
54 +++ b/drivers/net/phy/fixed_phy.c
57 #include <linux/gpio.h>
61 #define MII_REGS_NUM 29
63 struct fixed_mdio_bus {
64 @@ -49,101 +51,10 @@ static struct fixed_mdio_bus platform_fm
66 static int fixed_phy_update_regs(struct fixed_phy *fp)
68 - u16 bmsr = BMSR_ANEGCAPABLE;
73 if (gpio_is_valid(fp->link_gpio))
74 fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
76 - if (fp->status.duplex) {
77 - switch (fp->status.speed) {
79 - bmsr |= BMSR_ESTATEN;
82 - bmsr |= BMSR_100FULL;
85 - bmsr |= BMSR_10FULL;
91 - switch (fp->status.speed) {
93 - bmsr |= BMSR_ESTATEN;
96 - bmsr |= BMSR_100HALF;
99 - bmsr |= BMSR_10HALF;
106 - if (fp->status.link) {
107 - bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
109 - if (fp->status.duplex) {
110 - bmcr |= BMCR_FULLDPLX;
112 - switch (fp->status.speed) {
114 - bmcr |= BMCR_SPEED1000;
115 - lpagb |= LPA_1000FULL;
118 - bmcr |= BMCR_SPEED100;
119 - lpa |= LPA_100FULL;
125 - pr_warn("fixed phy: unknown speed\n");
129 - switch (fp->status.speed) {
131 - bmcr |= BMCR_SPEED1000;
132 - lpagb |= LPA_1000HALF;
135 - bmcr |= BMCR_SPEED100;
136 - lpa |= LPA_100HALF;
142 - pr_warn("fixed phy: unknown speed\n");
147 - if (fp->status.pause)
148 - lpa |= LPA_PAUSE_CAP;
150 - if (fp->status.asym_pause)
151 - lpa |= LPA_PAUSE_ASYM;
154 - fp->regs[MII_PHYSID1] = 0;
155 - fp->regs[MII_PHYSID2] = 0;
157 - fp->regs[MII_BMSR] = bmsr;
158 - fp->regs[MII_BMCR] = bmcr;
159 - fp->regs[MII_LPA] = lpa;
160 - fp->regs[MII_STAT1000] = lpagb;
163 + return swphy_update_regs(fp->regs, &fp->status);
166 static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
168 +++ b/drivers/net/phy/swphy.c
171 + * Software PHY emulation
173 + * Code taken from fixed_phy.c by Russell King <rmk+kernel@arm.linux.org.uk>
175 + * Author: Vitaly Bordug <vbordug@ru.mvista.com>
176 + * Anton Vorontsov <avorontsov@ru.mvista.com>
178 + * Copyright (c) 2006-2007 MontaVista Software, Inc.
180 + * This program is free software; you can redistribute it and/or modify it
181 + * under the terms of the GNU General Public License as published by the
182 + * Free Software Foundation; either version 2 of the License, or (at your
183 + * option) any later version.
185 +#include <linux/export.h>
186 +#include <linux/mii.h>
187 +#include <linux/phy.h>
188 +#include <linux/phy_fixed.h>
193 + * swphy_update_regs - update MII register array with fixed phy state
194 + * @regs: array of 32 registers to update
195 + * @state: fixed phy status
197 + * Update the array of MII registers with the fixed phy link, speed,
198 + * duplex and pause mode settings.
200 +int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state)
202 + u16 bmsr = BMSR_ANEGCAPABLE;
207 + if (state->duplex) {
208 + switch (state->speed) {
210 + bmsr |= BMSR_ESTATEN;
213 + bmsr |= BMSR_100FULL;
216 + bmsr |= BMSR_10FULL;
222 + switch (state->speed) {
224 + bmsr |= BMSR_ESTATEN;
227 + bmsr |= BMSR_100HALF;
230 + bmsr |= BMSR_10HALF;
238 + bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
240 + if (state->duplex) {
241 + bmcr |= BMCR_FULLDPLX;
243 + switch (state->speed) {
245 + bmcr |= BMCR_SPEED1000;
246 + lpagb |= LPA_1000FULL;
249 + bmcr |= BMCR_SPEED100;
250 + lpa |= LPA_100FULL;
256 + pr_warn("swphy: unknown speed\n");
260 + switch (state->speed) {
262 + bmcr |= BMCR_SPEED1000;
263 + lpagb |= LPA_1000HALF;
266 + bmcr |= BMCR_SPEED100;
267 + lpa |= LPA_100HALF;
273 + pr_warn("swphy: unknown speed\n");
279 + lpa |= LPA_PAUSE_CAP;
281 + if (state->asym_pause)
282 + lpa |= LPA_PAUSE_ASYM;
285 + regs[MII_PHYSID1] = 0;
286 + regs[MII_PHYSID2] = 0;
288 + regs[MII_BMSR] = bmsr;
289 + regs[MII_BMCR] = bmcr;
290 + regs[MII_LPA] = lpa;
291 + regs[MII_STAT1000] = lpagb;
295 +EXPORT_SYMBOL_GPL(swphy_update_regs);
297 +++ b/drivers/net/phy/swphy.h
302 +struct fixed_phy_status;
304 +int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state);