Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1648809pxb; Wed, 10 Feb 2021 13:15:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbWF+3k4L/+RSMD0oy22pkw8sjUJa+oeRRyqjeRxre3nNRUneoYOUh5fRPrU1DJgQo4gCH X-Received: by 2002:a17:906:8053:: with SMTP id x19mr4808484ejw.470.1612991753266; Wed, 10 Feb 2021 13:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612991753; cv=none; d=google.com; s=arc-20160816; b=YFhSOLt8Pq00K3Kk6ou0pwuYpNFzCtt2GYTiZnnVkNSlkt4C58PqhZNx5GY43finSq 7N8xCS8VVG8FEIxeJjiTQdWyoEvbbIGNZcSRyFj51n0SUfXMdhThC2bPuK22+z/wI9Lg 9RC2thDwDJyTRi5tcAMz2Exsuadu1HaNgGpaiQfFvVPRTUZ9NxwxeYUU4AoyQqRJN+Hx QJFBOfCIlJSX/R9pdOKn7TzkiUHUgigubKEJ8lh8W3kPQi1gPfGp56Trflyit6UqzQK2 yihWRnIyLxIkx0zQRpGrcZCd8bSG/oXUjAmzSD0MRXHWX8Pdk6/OWy0cuFsgocHMqCMy n9AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NVX+H/KckEk3Q9kbsydiFWuYci0hCbQGEYpv9ujCIzA=; b=zrzqbNUGafmdFvurOsL1gan0Tz8dymelETy7eivAShyLF7ageJ3QTNEcBxTNCXlM5F QGL5Ny/wY/Qu2ZTnPXT5NOhSYgoMdJ+K5PKDFRAbTMtwbh7f0uh7+/tIFkWH1fRg1Wbi MAfDjXWMqqmUCKtu/M+FG3k5TEpBPBVpd7uh3Qc/7MKcF/QfIkAETnFKVYNPLT1uDtHu iPrqXXx1B0CIycONjPWqGxr2EnogP/TFJBRiI3VD6MdNVOBo4eVEovJbpWQNqahdYph0 0arYToi8joB8txdzhvVkNyiF9YE1wA5QgW8dT68pwHkgTutE2tb6vMeVMpwJx0oM4BCe 7lEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=oxfaPD2i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay19si2065444ejb.621.2021.02.10.13.15.29; Wed, 10 Feb 2021 13:15:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=oxfaPD2i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbhBJVMs (ORCPT + 99 others); Wed, 10 Feb 2021 16:12:48 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:34937 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233006AbhBJVJD (ORCPT ); Wed, 10 Feb 2021 16:09:03 -0500 Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 31EC423E78; Wed, 10 Feb 2021 22:08:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1612991299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NVX+H/KckEk3Q9kbsydiFWuYci0hCbQGEYpv9ujCIzA=; b=oxfaPD2iGqJo8+Mf7yOKXpdPx6jXvNMPhcpnJ3ffHb6VX3LhpCPCe4g8L3yK0tWVgwpbwa rzM+dIezncKhNm3dtjJxRv6J0og+6fZZ8cto/tJBy8Frsv6U0RvjdaqFI0JOzNOVDmROrr XoBAwX7m6WvhySX+wfprakRrXH6SaeI= From: Michael Walle To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Michael Walle Subject: [PATCH net-next v3 5/9] net: phy: icplus: split IP101A/G driver Date: Wed, 10 Feb 2021 22:08:05 +0100 Message-Id: <20210210210809.30125-6-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210210210809.30125-1-michael@walle.cc> References: <20210210210809.30125-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unfortunately, the IP101A and IP101G share the same PHY identifier. While most of the functions are somewhat backwards compatible, there is for example the APS_EN bit on the IP101A but on the IP101G this bit reserved. Also, the IP101G has many more functionalities. Deduce the model by accessing the page select register which - according to the datasheet - is not available on the IP101A. If this register is writable, assume we have an IP101G. Split the combined IP101A/G driver into two separate drivers. Signed-off-by: Michael Walle --- Changes since v2: - dropped the PHY_BASIC_FEATURES comments as suggested by Heiner - converted the ternary operator to a simple comparison as suggested by Heiner Changes since v1: - use match_phy_device() as suggested by Heiner Andrew, I've dropped your Reviewed-by because of this. drivers/net/phy/icplus.c | 69 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c index 036bac628b11..dee4f4d988a2 100644 --- a/drivers/net/phy/icplus.c +++ b/drivers/net/phy/icplus.c @@ -44,6 +44,8 @@ MODULE_LICENSE("GPL"); #define IP101A_G_IRQ_DUPLEX_CHANGE BIT(1) #define IP101A_G_IRQ_LINK_CHANGE BIT(0) +#define IP101G_PAGE_CONTROL 0x14 +#define IP101G_PAGE_CONTROL_MASK GENMASK(4, 0) #define IP101G_DIGITAL_IO_SPEC_CTRL 0x1d #define IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32 BIT(2) @@ -301,6 +303,58 @@ static irqreturn_t ip101a_g_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } +static int ip101a_g_has_page_register(struct phy_device *phydev) +{ + int oldval, val, ret; + + oldval = phy_read(phydev, IP101G_PAGE_CONTROL); + if (oldval < 0) + return oldval; + + ret = phy_write(phydev, IP101G_PAGE_CONTROL, 0xffff); + if (ret) + return ret; + + val = phy_read(phydev, IP101G_PAGE_CONTROL); + if (val < 0) + return val; + + ret = phy_write(phydev, IP101G_PAGE_CONTROL, oldval); + if (ret) + return ret; + + return val == IP101G_PAGE_CONTROL_MASK; +} + +static int ip101a_g_match_phy_device(struct phy_device *phydev, bool ip101a) +{ + int ret; + + if (phydev->phy_id != IP101A_PHY_ID) + return 0; + + /* The IP101A and the IP101G share the same PHY identifier.The IP101G + * seems to be a successor of the IP101A and implements more functions. + * Amongst other things there is a page select register, which is not + * available on the IP101A. Use this to distinguish these two. + */ + ret = ip101a_g_has_page_register(phydev); + if (ret < 0) + return ret; + + return ip101a == !ret; +} + +static int ip101a_match_phy_device(struct phy_device *phydev) +{ + return ip101a_g_match_phy_device(phydev, true); +} + +static int ip101g_match_phy_device(struct phy_device *phydev) +{ + return ip101a_g_match_phy_device(phydev, false); +} + static struct phy_driver icplus_driver[] = { { PHY_ID_MATCH_MODEL(IP175C_PHY_ID), @@ -320,9 +374,18 @@ static struct phy_driver icplus_driver[] = { .suspend = genphy_suspend, .resume = genphy_resume, }, { - PHY_ID_MATCH_EXACT(IP101A_PHY_ID), - .name = "ICPlus IP101A/G", - /* PHY_BASIC_FEATURES */ + .name = "ICPlus IP101A", + .match_phy_device = ip101a_match_phy_device, + .probe = ip101a_g_probe, + .config_intr = ip101a_g_config_intr, + .handle_interrupt = ip101a_g_handle_interrupt, + .config_init = ip101a_g_config_init, + .soft_reset = genphy_soft_reset, + .suspend = genphy_suspend, + .resume = genphy_resume, +}, { + .name = "ICPlus IP101G", + .match_phy_device = ip101g_match_phy_device, .probe = ip101a_g_probe, .config_intr = ip101a_g_config_intr, .handle_interrupt = ip101a_g_handle_interrupt, -- 2.20.1