Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2865085ybg; Mon, 28 Oct 2019 03:45:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEqTy/Tc48RvT3pKXqr0toCqXLeNEL48p7ekzkJqkHAuAWQ+F/f+wzJbjuEQHfeaYfX/6N X-Received: by 2002:aa7:c048:: with SMTP id k8mr8058936edo.254.1572259524486; Mon, 28 Oct 2019 03:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572259524; cv=none; d=google.com; s=arc-20160816; b=arJLRh8BMG/DifhM9fN7uNUFYH9i4zWIMw7s25mwltazHzpv8p8Rb5DX6l09feS4UJ Ao4RHSRDX1mg2gfcIdzA9qFgimLXcIITvlKdA6tUutycSBs4cnwFIxtq33fyfrEAjhz7 rWUCg0fd3UdldI5IxXhhJE4LBxgOP008c1TUOLv2442CB5MCCPOuXnwkUzdLAAjHk6C/ 4mCszVz+vyTApFq9pElDOCpKVBMmUTxNmiTScWn/3zyMhKhwD0eF+9zZF+e87O+qKc76 SYsWLnxOoZKvu47jHPuSar1lknsFCGoP7NoT46iFu3E5Q/dHrtZF0zdb4EOr8+DxgG4C mvjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fZTm7s22xyCjwWt3k5f5mxUzWvFEi4GMusmfPT2M2RE=; b=MICLepsMChITE/oDaJaPlgS8KoY8ZOcPPHLhEfi7+SGzA36V202b0aQ24H3NA0AaZp ohVNHL7G/gsfYoXeAyVNYufxnckEOdRQgH0c+NHnyazYNb/o0cU3n1P/5eUitpJVcuVC dfIFLAo3ePKz4ni2yK0JDPKpWd01alhkPukVdrT36GML9WSVL/cdpaXS5PevS8lJT13Q XwwpGZA9L/cG5Stw3umrjHhR77oDhwJq4HzB5lsQV4AloIGcYqgr85wdz5HWAVQyXasX ewhVF/3UJOOnlsXsT7dL1dvioSp2Ka9tLmFEiRFQL/Qq6cNFSXGfuQm1csqkUsQiBu61 +gdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hOhm3e1F; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si2635063edl.442.2019.10.28.03.45.00; Mon, 28 Oct 2019 03:45:24 -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=pass header.i=@kernel.org header.s=default header.b=hOhm3e1F; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732347AbfJ0V2F (ORCPT + 99 others); Sun, 27 Oct 2019 17:28:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732343AbfJ0VXY (ORCPT ); Sun, 27 Oct 2019 17:23:24 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64226205C9; Sun, 27 Oct 2019 21:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211403; bh=UWRrMZJKv5UW1deDCzyVTEjunYLbL4c4zEt1YclGpx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOhm3e1FXQA/WRDsOFsedToMMi/v2aBZbDjrRHiSxsYprO+zSSFhUhA/TqP9X5XJ1 lJsi6G2/UpNKJcj69sity72m7E6cu++3v+/sgpRqS9MPj6M0tumL6GeYE9i+sKeG/V qP6jhUelpWGlHnU+7UNerx08xASiItXF57cB+A3I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Vasut , Andrew Lunn , "David S. Miller" , Florian Fainelli , George McCollister , Heiner Kallweit , Sean Nyekjaer , Tristram Ha , Woojung Huh Subject: [PATCH 5.3 085/197] net: phy: micrel: Discern KSZ8051 and KSZ8795 PHYs Date: Sun, 27 Oct 2019 22:00:03 +0100 Message-Id: <20191027203356.311768827@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marek Vasut [ Upstream commit 8b95599c55ed24b36cf44a4720067cfe67edbcb4 ] The KSZ8051 PHY and the KSZ8794/KSZ8795/KSZ8765 switch share exactly the same PHY ID. Since KSZ8051 is higher in the ksphy_driver[] list of PHYs in the micrel PHY driver, it is used even with the KSZ87xx switch. This is wrong, since the KSZ8051 configures registers of the PHY which are not present on the simplified KSZ87xx switch PHYs and misconfigures other registers of the KSZ87xx switch PHYs. Fortunatelly, it is possible to tell apart the KSZ8051 PHY from the KSZ87xx switch by checking the Basic Status register Bit 0, which is read-only and indicates presence of the Extended Capability Registers. The KSZ8051 PHY has those registers while the KSZ87xx switch does not. This patch implements simple check for the presence of this bit for both the KSZ8051 PHY and KSZ87xx switch, to let both use the correct PHY driver instance. Fixes: 9d162ed69f51 ("net: phy: micrel: add support for KSZ8795") Signed-off-by: Marek Vasut Cc: Andrew Lunn Cc: David S. Miller Cc: Florian Fainelli Cc: George McCollister Cc: Heiner Kallweit Cc: Sean Nyekjaer Cc: Tristram Ha Cc: Woojung Huh Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/micrel.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -341,6 +341,35 @@ static int ksz8041_config_aneg(struct ph return genphy_config_aneg(phydev); } +static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev, + const u32 ksz_phy_id) +{ + int ret; + + if ((phydev->phy_id & MICREL_PHY_ID_MASK) != ksz_phy_id) + return 0; + + ret = phy_read(phydev, MII_BMSR); + if (ret < 0) + return ret; + + /* KSZ8051 PHY and KSZ8794/KSZ8795/KSZ8765 switch share the same + * exact PHY ID. However, they can be told apart by the extended + * capability registers presence. The KSZ8051 PHY has them while + * the switch does not. + */ + ret &= BMSR_ERCAP; + if (ksz_phy_id == PHY_ID_KSZ8051) + return ret; + else + return !ret; +} + +static int ksz8051_match_phy_device(struct phy_device *phydev) +{ + return ksz8051_ksz8795_match_phy_device(phydev, PHY_ID_KSZ8051); +} + static int ksz8081_config_init(struct phy_device *phydev) { /* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line @@ -364,6 +393,11 @@ static int ksz8061_config_init(struct ph return kszphy_config_init(phydev); } +static int ksz8795_match_phy_device(struct phy_device *phydev) +{ + return ksz8051_ksz8795_match_phy_device(phydev, PHY_ID_KSZ8795); +} + static int ksz9021_load_values_from_of(struct phy_device *phydev, const struct device_node *of_node, u16 reg, @@ -1017,8 +1051,6 @@ static struct phy_driver ksphy_driver[] .suspend = genphy_suspend, .resume = genphy_resume, }, { - .phy_id = PHY_ID_KSZ8051, - .phy_id_mask = MICREL_PHY_ID_MASK, .name = "Micrel KSZ8051", /* PHY_BASIC_FEATURES */ .driver_data = &ksz8051_type, @@ -1029,6 +1061,7 @@ static struct phy_driver ksphy_driver[] .get_sset_count = kszphy_get_sset_count, .get_strings = kszphy_get_strings, .get_stats = kszphy_get_stats, + .match_phy_device = ksz8051_match_phy_device, .suspend = genphy_suspend, .resume = genphy_resume, }, { @@ -1141,13 +1174,12 @@ static struct phy_driver ksphy_driver[] .suspend = genphy_suspend, .resume = genphy_resume, }, { - .phy_id = PHY_ID_KSZ8795, - .phy_id_mask = MICREL_PHY_ID_MASK, .name = "Micrel KSZ8795", /* PHY_BASIC_FEATURES */ .config_init = kszphy_config_init, .config_aneg = ksz8873mll_config_aneg, .read_status = ksz8873mll_read_status, + .match_phy_device = ksz8795_match_phy_device, .suspend = genphy_suspend, .resume = genphy_resume, }, {