Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1465251pxb; Wed, 10 Feb 2021 08:56:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx04KRuUO6WRbePWLPSJwh9t22vscUH8FV+y9TVjmLQi3DwQFJKMvGQQdGjXYNkgplC+IgW X-Received: by 2002:a17:906:17d3:: with SMTP id u19mr4036022eje.316.1612976196515; Wed, 10 Feb 2021 08:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612976196; cv=none; d=google.com; s=arc-20160816; b=XD9fugqrYYh0KqbAhvnF8CmG6lCC/9mwOiUDFeElPUrjmuJuWb8NqDLApaoeHtCY8j jtooWb98MeEjZ1bUHlzd3kX/i5zZKmIKyTpAsDylF7OXk1Z0Ggqr6ndcjh/s6ir9UYjj Dh+CnL8pxBZW9xZONEJRlOXWaDgt2q05iHDk5cA4/g8v9YYfS/VAdqWy04J4oWPgkIJU 6mNsil6xFNUSWlDYG/ePnuGKgNMHwj4He0ebJmJVvHdxd+wjuudf8SHTSlMDwGlqdrck VlkP9Qad/PuV9ATAA2Sr+vgm2ZF14j7HuJUThAbMPULZb3523mC8INhhvWrEGVj0EAo+ zEsQ== 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=HOk8FU5aNzbxZFRMHXvhBJsCoU8i/72M6o4pS66b2UU=; b=ksqk/n8N3w8JgLlW4GQLsg9CfuPD+ETDPCObCkenXPkRoo5m1HIz7JIeALzpBRO8a3 Dyxsz1UTSGVjlwFJrZb09KFT79FhkIUX7h2IGlTv6JZwTfOEHis0KKGlfQqsw4nxJkS+ Qo9WehHRb6lZ4RundSf71IwL430IsvhXjp456iMhfmfnrgvN5VmTXEEixBm9AMI7rF/J ZLZoENQJCHl0/4pWXoqKonD8Wc89J/GWSpMysoZtRK5VFi0in9hJttmXqGEtFB/K+0vg cXxpV+SEZXWqypVwIIVqOc7XGNqWwHKNWc6n36yc2dKv3pBDhAPx5/sADt9h2rAmRRwp sasg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=bQnI9A2D; 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 b1si1805131ejb.401.2021.02.10.08.56.11; Wed, 10 Feb 2021 08:56:36 -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=bQnI9A2D; 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 S232797AbhBJQwb (ORCPT + 99 others); Wed, 10 Feb 2021 11:52:31 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:39949 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233088AbhBJQty (ORCPT ); Wed, 10 Feb 2021 11:49:54 -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 C73D523E83; Wed, 10 Feb 2021 17:48:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1612975681; 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=HOk8FU5aNzbxZFRMHXvhBJsCoU8i/72M6o4pS66b2UU=; b=bQnI9A2DPvVPWMVpfchXUVMuVndTc4oRIF8BPrG2hBMTgvqsbJNGjim7hVp/mhmZS7w7Xx iP38Vz4ALaUJ3nRpoR8ZwbjJNAJ7mQBnJSJNdhB0bx8A2FdGIlDEyzRgY6IhYC3PygSZ/u jhh+y4nTcms84yuMMOVOHbHFzANueHQ= 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 v2 9/9] net: phy: icplus: add MDI/MDIX support for IP101A/G Date: Wed, 10 Feb 2021 17:47:46 +0100 Message-Id: <20210210164746.26336-10-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210210164746.26336-1-michael@walle.cc> References: <20210210164746.26336-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the operations to set desired mode and retrieve the current mode. This feature was tested with an IP101G. Signed-off-by: Michael Walle Reviewed-by: Andrew Lunn --- Changes since v1: - none, except that the callbacks are register for both IP101A and IP101G PHY drivers drivers/net/phy/icplus.c | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c index 52ba5a697025..26b591e18120 100644 --- a/drivers/net/phy/icplus.c +++ b/drivers/net/phy/icplus.c @@ -37,12 +37,17 @@ MODULE_LICENSE("GPL"); #define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */ #define IP1001_APS_ON 11 /* IP1001 APS Mode bit */ #define IP101A_G_APS_ON BIT(1) /* IP101A/G APS Mode bit */ +#define IP101A_G_AUTO_MDIX_DIS BIT(11) #define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */ #define IP101A_G_IRQ_PIN_USED BIT(15) /* INTR pin used */ #define IP101A_G_IRQ_ALL_MASK BIT(11) /* IRQ's inactive */ #define IP101A_G_IRQ_SPEED_CHANGE BIT(2) #define IP101A_G_IRQ_DUPLEX_CHANGE BIT(1) #define IP101A_G_IRQ_LINK_CHANGE BIT(0) +#define IP101A_G_PHY_STATUS 18 +#define IP101A_G_MDIX BIT(9) +#define IP101A_G_PHY_SPEC_CTRL 30 +#define IP101A_G_FORCE_MDIX BIT(3) #define IP101G_PAGE_CONTROL 0x14 #define IP101G_PAGE_CONTROL_MASK GENMASK(4, 0) @@ -297,6 +302,90 @@ static int ip101g_config_init(struct phy_device *phydev) return ip101a_g_config_intr_pin(phydev); } +static int ip101a_g_read_status(struct phy_device *phydev) +{ + int oldpage, ret, stat1, stat2; + + ret = genphy_read_status(phydev); + if (ret) + return ret; + + oldpage = phy_select_page(phydev, IP101G_DEFAULT_PAGE); + + ret = __phy_read(phydev, IP10XX_SPEC_CTRL_STATUS); + if (ret < 0) + goto out; + stat1 = ret; + + ret = __phy_read(phydev, IP101A_G_PHY_SPEC_CTRL); + if (ret < 0) + goto out; + stat2 = ret; + + if (stat1 & IP101A_G_AUTO_MDIX_DIS) { + if (stat2 & IP101A_G_FORCE_MDIX) + phydev->mdix_ctrl = ETH_TP_MDI_X; + else + phydev->mdix_ctrl = ETH_TP_MDI; + } else { + phydev->mdix_ctrl = ETH_TP_MDI_AUTO; + } + + if (stat2 & IP101A_G_MDIX) + phydev->mdix = ETH_TP_MDI_X; + else + phydev->mdix = ETH_TP_MDI; + + ret = 0; + +out: + return phy_restore_page(phydev, oldpage, ret); +} + +static int ip101a_g_config_mdix(struct phy_device *phydev) +{ + u16 ctrl = 0, ctrl2 = 0; + int oldpage, ret; + + switch (phydev->mdix_ctrl) { + case ETH_TP_MDI: + ctrl = IP101A_G_AUTO_MDIX_DIS; + break; + case ETH_TP_MDI_X: + ctrl = IP101A_G_AUTO_MDIX_DIS; + ctrl2 = IP101A_G_FORCE_MDIX; + break; + case ETH_TP_MDI_AUTO: + break; + default: + return 0; + } + + oldpage = phy_select_page(phydev, IP101G_DEFAULT_PAGE); + + ret = __phy_modify(phydev, IP10XX_SPEC_CTRL_STATUS, + IP101A_G_AUTO_MDIX_DIS, ctrl); + if (ret) + goto out; + + ret = __phy_modify(phydev, IP101A_G_PHY_SPEC_CTRL, + IP101A_G_FORCE_MDIX, ctrl2); + +out: + return phy_restore_page(phydev, oldpage, ret); +} + +static int ip101a_g_config_aneg(struct phy_device *phydev) +{ + int ret; + + ret = ip101a_g_config_mdix(phydev); + if (ret) + return ret; + + return genphy_config_aneg(phydev); +} + static int ip101a_g_ack_interrupt(struct phy_device *phydev) { int err; @@ -503,6 +592,8 @@ static struct phy_driver icplus_driver[] = { .config_intr = ip101a_g_config_intr, .handle_interrupt = ip101a_g_handle_interrupt, .config_init = ip101a_config_init, + .config_aneg = ip101a_g_config_aneg, + .read_status = ip101a_g_read_status, .soft_reset = genphy_soft_reset, .suspend = genphy_suspend, .resume = genphy_resume, @@ -516,6 +607,8 @@ static struct phy_driver icplus_driver[] = { .config_intr = ip101a_g_config_intr, .handle_interrupt = ip101a_g_handle_interrupt, .config_init = ip101g_config_init, + .config_aneg = ip101a_g_config_aneg, + .read_status = ip101a_g_read_status, .soft_reset = genphy_soft_reset, .get_sset_count = ip101g_get_sset_count, .get_strings = ip101g_get_strings, -- 2.20.1