Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751556AbdG0KqP (ORCPT ); Thu, 27 Jul 2017 06:46:15 -0400 Received: from aibo.runbox.com ([91.220.196.211]:35064 "EHLO aibo.runbox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750965AbdG0KqN (ORCPT ); Thu, 27 Jul 2017 06:46:13 -0400 Subject: Re: [PATCH net-next v2 04/10] net: dsa: lan9303: Added adjust_link() method To: Andrew Lunn Cc: corbet@lwn.net, vivien.didelot@savoirfairelinux.com, f.fainelli@gmail.com, davem@davemloft.net, kernel@pengutronix.de, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org References: <20170725161553.30147-1-privat@egil-hjelmeland.no> <20170725161553.30147-5-privat@egil-hjelmeland.no> <20170726170928.GP12049@lunn.ch> From: Egil Hjelmeland Message-ID: Date: Thu, 27 Jul 2017 12:45:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170726170928.GP12049@lunn.ch> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2308 Lines: 86 On 26. juli 2017 19:09, Andrew Lunn wrote: > On Tue, Jul 25, 2017 at 06:15:47PM +0200, Egil Hjelmeland wrote: >> This makes the driver react to device tree "fixed-link" declaration >> on CPU port. >> >> - turn off autonegotiation >> - force speed 10 or 100 mb/s >> - force duplex mode >> >> Signed-off-by: Egil Hjelmeland >> --- >> drivers/net/dsa/lan9303-core.c | 33 +++++++++++++++++++++++++++++++++ >> 1 file changed, 33 insertions(+) >> >> diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c >> index 0806a0684d55..be6d78f45a5f 100644 >> --- a/drivers/net/dsa/lan9303-core.c >> +++ b/drivers/net/dsa/lan9303-core.c >> @@ -17,6 +17,7 @@ >> #include >> #include >> #include >> +#include >> >> #include "lan9303.h" >> >> @@ -746,6 +747,37 @@ static int lan9303_phy_write(struct dsa_switch *ds, int phy, int regnum, >> return chip->ops->phy_write(chip, phy, regnum, val); >> } >> >> +static void lan9303_adjust_link(struct dsa_switch *ds, int port, >> + struct phy_device *phydev) >> +{ >> + struct lan9303 *chip = ds->priv; >> + >> + int ctl, res; >> + >> + ctl = lan9303_phy_read(ds, port, MII_BMCR); >> + >> + if (!phy_is_pseudo_fixed_link(phydev)) >> + return; >> + > > Hi Egil > > Maybe do this check before reading MII_BMCR? > OK >> + ctl &= ~BMCR_ANENABLE; > > Should this also mask out BMCR_SPEED100 and DUPLEX_FULL? Otherwise how > do you select 10/Half if it is already configured for 100/Full? > Yes you are right. I started out with setting ctl to the fixed default value, and later changed code to start by reading it from HW. >> + if (phydev->speed == SPEED_100) >> + ctl |= BMCR_SPEED100; >> + >> + if (phydev->duplex == DUPLEX_FULL) >> + ctl |= BMCR_FULLDPLX; >> + >> + res = lan9303_phy_write(ds, port, MII_BMCR, ctl); >> + >> + if (port == chip->phy_addr_sel_strap) { >> + /* Virtual Phy: Remove Turbo 200Mbit mode */ >> + lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, &ctl); >> + >> + ctl &= ~(1 << 10); // TURBO BIT > > BIT(10), or better still something like BIT(LAN9303_VIRT_SPECIAL_TURBO) > Agree >> + res = regmap_write(chip->regmap, >> + LAN9303_VIRT_SPECIAL_CTRL, ctl); >> + } >> +} > > Andrew >