Received: by 10.213.65.68 with SMTP id h4csp1836126imn; Thu, 5 Apr 2018 04:46:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49FivRCtRy+H/a/pFnLZpwjMNEHGKta3fWbCFv40E0lmU76+qo/MYEa/jmYrPmIjzqfuPfO X-Received: by 2002:a17:902:8d98:: with SMTP id v24-v6mr22544640plo.21.1522928802118; Thu, 05 Apr 2018 04:46:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522928802; cv=none; d=google.com; s=arc-20160816; b=BFgZsnXXWRg2N7Yg3+zDMEqqP3iRa7UgYnhmzMTBRT060C3AhttaSeOiRIanDQZhss VerEVozsOanANLnOrvxa8Bz0zN3EENyDEHxG02ropLvYRriFEaIRBjkDuBgNXhjzVMdV 7np688kgDhAYxu2PSKdKPx77kBY4Pv5mSBB6Bu0epMDt7nw7Oso4GbqqnKOluQnHCC9N M+z4VIjceytFVxSBrmlg5LJ+/pQJ9wGtmHJb8O7WVEQGsPjbOa1ifYhupymelOatqlJ1 2wtq8/G1JKJ/ceAysCn3qmIJn3b1rBOQfAckwFK0wYCk/rd6W91mHwwRuTmiC+8mGlde Ljdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WbNhkhwDtDGEzOjWxEySo74PeQxNg/gP/f/lWSsXCA0=; b=EqYN/v7oWMIb9cA3PnDwhZmype2lkrX8TXoFYLcywSelEhM3lFrQ919pb3UVTinGBZ XlWFpzKLB09RZ077EZBfpfRy4EsiSOZ0H73i7wsEr6sxnwe8rVDUb49YtfEQIPfp5y+1 xt2U/fiqGsYXI01im02SvIMwATlqp4rUInkkswSSDU6fljQMZTl1vK5GfS2OmmyHTbgW RtkA4I7E0wc6ExBz+z/1iR40kyuP4uee/stlyWZo5o8W8GAxwPMtrytsCmXPCySHNeUH DxihgwVYePgukx/y6NKqDGcuhPxJXe21A6XvNkdnc0gOgCkRAg7GFWS1vjg7KhQ0jCIx TuyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Saoy7hWh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si5171306pgu.633.2018.04.05.04.46.27; Thu, 05 Apr 2018 04:46:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Saoy7hWh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751529AbeDELo3 (ORCPT + 99 others); Thu, 5 Apr 2018 07:44:29 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39407 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbeDELo1 (ORCPT ); Thu, 5 Apr 2018 07:44:27 -0400 Received: by mail-wm0-f68.google.com with SMTP id f125so6142955wme.4; Thu, 05 Apr 2018 04:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=WbNhkhwDtDGEzOjWxEySo74PeQxNg/gP/f/lWSsXCA0=; b=Saoy7hWh6MK6C1ibsMdJeA9ovhL68EZG3oMcv3woPpiztWMhtq6SAdPd1va76XTM1h KJS3nqepi5O933LDCCCkcoIBTuEJDzTNGVFVUrOqpu018sfsXI3agghsSbN+oMceGnxQ m6Vihp9hSydJTbr3qtwSllNcG7b/5TQZNvBbHXdeh9TIRoEVAcXNIxMUe8Hjju8oMxtp HfhHdF1Phc3YQGkozdtQEGS0QnCHP7xNQMDc2N6zS/OsQkZmMkWoNRljPj1NMJoF3Pow 01wNfXNKzPNNGraJWtMk51Le5bPWUO0tdTrmvb5q7yAZrRU2Zn7ooaauJrp4fNU8mfOq JuFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=WbNhkhwDtDGEzOjWxEySo74PeQxNg/gP/f/lWSsXCA0=; b=pXhOuTz//3u9cTGt+OyT3IqJ8o4j9qrlCBF8zaJik63gzAGi6txZ6lozOUipb6Yu/P rdzIKIX+hh5e/on6SQHW7eDO0KhhgagL4pzdOpAFwdjTfXkj8Jswupy1FlB4avARgKRI ni7967cOA42SCIyj/arpEw6tZZ/el7NPgIjvRtIkVxHIWbZtYIlC79fT0S9ogCI0wcIZ r/PH/jX6/K2DzzCOYQhv5npgZmTkkNn6ZoAvltQl/tC7ZJz4I2pOIAUzdixg0hlOlM0h Cwj6URYHYL4PMo37sJ++rKztuu9A5GgNHfSNQwhUW+vyaHmqboxBruCLpJJx68YrliGl CQYg== X-Gm-Message-State: ALQs6tAmgsM0qTrYTsqq1g1UXSiDA3upiMLVsRlw4fJyUbT0vqNLyKkI f2Ps0z1ceHiPD7nDkdI+iHc= X-Received: by 10.46.99.93 with SMTP id x90mr14089558ljb.2.1522928666418; Thu, 05 Apr 2018 04:44:26 -0700 (PDT) Received: from localhost (87-57-30-174-static.dk.customer.tdc.net. [87.57.30.174]) by smtp.gmail.com with ESMTPSA id z81-v6sm1474231lff.20.2018.04.05.04.44.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Apr 2018 04:44:25 -0700 (PDT) From: esben.haabendal@gmail.com To: Andrew Lunn , Florian Fainelli , netdev@vger.kernel.org (open list:ETHERNET PHY LIBRARY), linux-kernel@vger.kernel.org (open list) Cc: Esben Haabendal , Rasmus Villemoes Subject: [PATCH 1/2] net: phy: Helper function for reading strapped configuration values Date: Thu, 5 Apr 2018 13:44:23 +0200 Message-Id: <20180405114424.8519-1-esben.haabendal@gmail.com> X-Mailer: git-send-email 2.16.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Esben Haabendal Add a function for use in PHY driver probe functions, reading current autoneg, speed and duplex configuration from BMCR register. Useful for PHY that supports hardware strapped configuration, enabling Linux to respect that configuration (i.e. strapped non-autoneg configuration). Signed-off-by: Esben Haabendal Cc: Rasmus Villemoes --- drivers/net/phy/phy_device.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 1 + 2 files changed, 42 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 74664a6c0cdc..cc52ff2a2344 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1673,6 +1673,47 @@ int genphy_config_init(struct phy_device *phydev) } EXPORT_SYMBOL(genphy_config_init); +/** + * genphy_read_config - read configuration from PHY + * @phydev: target phy_device struct + * + * Description: Reads MII_BMCR and sets phydev autoneg, speed and duplex + * accordingly. For use in driver probe functions, to respect strapped + * configuration settings. + */ +int genphy_read_config(struct phy_device *phydev) +{ + int bmcr; + + bmcr = phy_read(phydev, MII_BMCR); + if (bmcr < 0) + return bmcr; + + if (BMCR_ANENABLE & bmcr) { + phydev->autoneg = AUTONEG_ENABLE; + + phydev->speed = 0; + phydev->duplex = -1; + } else { + phydev->autoneg = AUTONEG_DISABLE; + + if (bmcr & BMCR_FULLDPLX) + phydev->duplex = DUPLEX_FULL; + else + phydev->duplex = DUPLEX_HALF; + + if (bmcr & BMCR_SPEED1000) + phydev->speed = SPEED_1000; + else if (bmcr & BMCR_SPEED100) + phydev->speed = SPEED_100; + else + phydev->speed = SPEED_10; + } + + return 0; +} +EXPORT_SYMBOL(genphy_read_config); + /* This is used for the phy device which doesn't support the MMD extended * register access, but it does have side effect when we are trying to access * the MMD register via indirect method. diff --git a/include/linux/phy.h b/include/linux/phy.h index 7c4c2379e010..5a8821c8105d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -970,6 +970,7 @@ void phy_attached_info(struct phy_device *phydev); /* Clause 22 PHY */ int genphy_config_init(struct phy_device *phydev); +int genphy_read_config(struct phy_device *phydev); int genphy_setup_forced(struct phy_device *phydev); int genphy_restart_aneg(struct phy_device *phydev); int genphy_config_aneg(struct phy_device *phydev); -- 2.16.3