Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6459028rwi; Mon, 24 Oct 2022 01:28:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Aa8FKpV4FrhMUxQ69kmbomORTxcsan095opHPFz77oe8CjoGd4lZ2FfRJ82b6qz6g8NxL X-Received: by 2002:a17:906:d54d:b0:78e:2fbf:ca2a with SMTP id cr13-20020a170906d54d00b0078e2fbfca2amr27088430ejc.488.1666600114099; Mon, 24 Oct 2022 01:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666600114; cv=none; d=google.com; s=arc-20160816; b=dQYEwcvASmvmt/o3mw5/Rp9e8CA0LYpT6fJsxBrkw0qRkLmzKV3QmNYQCQuQ/es9j/ +sQkLeVbHY/3IOTDOx4NxzZGug+Rp13VLpN6eAjA0y+EuByzLyCE3znuBURSIu6nV076 9E22CALvP4Ac+nyK628GqQ70+21m/PyHgDxTd1Ob/8QM9qTHMfL5Qr9heBLAxBrqPmkM fqD2MrBrnKuG465CJMH1R2yA0M6xF28WEW0o8a16aIv6dpnVQKCtN1cTGyxQ7uNF7BR6 FbXLVA9vbhBhifvUs6uNoa0lm1llr4kOrLsmWQ3tkZU6ydBlRVqte4JJAJ7B845eA/UK UCrQ== 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=1PJdK+KGgkN5Xn5uGmZzK6auDJwR9GcuF/VLtqe3nMY=; b=Uhk21TndTeLFXLFL5EAq/GYnl4qldlLM1SL5orjFyDyVqb+2rFO0J87B2Dw6f2alyN +sfoTfBHLnsaX7KsD3SXqHTWz+SWc0c7/SgQf2yRCez2BE1gAqTAz4JQS3AkIK2ERrB3 RqId7al5UX0OSCNqxk7imA3XxrxqkvgSWoJq19G/0HstQBx+95E9/TF5v36mLSLhCh5+ 5mjwPbOrA999PZi7LvfwDjdXLFfExhCtheGcUBVmC5t+6Q6XkIGMQVPZsiikM0iKwwiD ZzoJaLm1E3jQxx9KnV3irE2bKOldvgDmE0PJkNl57TyPnCxExAluCVfjLzhwcHdqIxhd pPqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JsJHSGip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906794f00b0078da3cd3073si29467264ejo.628.2022.10.24.01.28.08; Mon, 24 Oct 2022 01:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=JsJHSGip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbiJXI06 (ORCPT + 99 others); Mon, 24 Oct 2022 04:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiJXI0d (ORCPT ); Mon, 24 Oct 2022 04:26:33 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 718013F1EC; Mon, 24 Oct 2022 01:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1666599936; x=1698135936; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h6vVDwnnEIYrZbU2Lnzxt0EZEFuZqlq6YJWy0K1QXkw=; b=JsJHSGipunFV/VAE+28BxIMm6bLT2p7I5rKI2l327Av2QxOlMGQ2XeuJ rDRNjEoE0x1Rui0PficdUV/doz2TKWraMPyft4BlC2j3Ap5nR+FxU/6wz Qp/wZZQl7YdzrPt+lPS8dtRhfJlbYagsbRNXep1Cs4Jhkk62nGmSWOOpr 8u6M00OsRCH/QKV85P3wFYtMKEjtWEd5Cr6XlOqDrfngsNLeJ712ecsDF U3i6wjCEoHnGh/ZoQmOjZl/Fi2nFr3Cnw35EugncPfFWIChaE19Oi44lU 0Jsq2AKSmJF7v/DJvZPMHcsLoxSrnjKFyzvbeHBaaO40ufZucUaq96GxD Q==; X-IronPort-AV: E=Sophos;i="5.95,207,1661842800"; d="scan'208";a="185983469" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 24 Oct 2022 01:25:34 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 24 Oct 2022 01:25:32 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 24 Oct 2022 01:25:28 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , Subject: [PATCH net-next V1 2/2] net: phy: micrel: Add PHY Auto/MDI/MDI-X set driver for KSZ9131 Date: Mon, 24 Oct 2022 13:55:16 +0530 Message-ID: <20221024082516.661199-3-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024082516.661199-1-Raju.Lakkaraju@microchip.com> References: <20221024082516.661199-1-Raju.Lakkaraju@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for MDI-X status and configuration for KSZ9131 chips Signed-off-by: Raju Lakkaraju --- Change List: ============ V0 -> V1: - Drop the "_" from the end of the macros - Add KSZ9131 MDI-X specific register contain 9131 in macro names drivers/net/phy/micrel.c | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 54a17b576eac..26ce0c5defcd 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -1295,6 +1295,81 @@ static int ksz9131_config_init(struct phy_device *phydev) return 0; } +#define MII_KSZ9131_AUTO_MDIX 0x1C +#define MII_KSZ9131_AUTO_MDI_SET BIT(7) +#define MII_KSZ9131_AUTO_MDIX_SWAP_OFF BIT(6) + +static int ksz9131_mdix_update(struct phy_device *phydev) +{ + int ret; + + ret = phy_read(phydev, MII_KSZ9131_AUTO_MDIX); + if (ret < 0) + return ret; + + if (ret & MII_KSZ9131_AUTO_MDIX_SWAP_OFF) { + if (ret & MII_KSZ9131_AUTO_MDI_SET) + phydev->mdix_ctrl = ETH_TP_MDI; + else + phydev->mdix_ctrl = ETH_TP_MDI_X; + } else { + phydev->mdix_ctrl = ETH_TP_MDI_AUTO; + } + + if (ret & MII_KSZ9131_AUTO_MDI_SET) + phydev->mdix = ETH_TP_MDI; + else + phydev->mdix = ETH_TP_MDI_X; + + return 0; +} + +static int ksz9131_config_mdix(struct phy_device *phydev, u8 ctrl) +{ + u16 val; + + switch (ctrl) { + case ETH_TP_MDI: + val = MII_KSZ9131_AUTO_MDIX_SWAP_OFF | + MII_KSZ9131_AUTO_MDI_SET; + break; + case ETH_TP_MDI_X: + val = MII_KSZ9131_AUTO_MDIX_SWAP_OFF; + break; + case ETH_TP_MDI_AUTO: + val = 0; + break; + default: + return 0; + } + + return phy_modify(phydev, MII_KSZ9131_AUTO_MDIX, + MII_KSZ9131_AUTO_MDIX_SWAP_OFF | + MII_KSZ9131_AUTO_MDI_SET, val); +} + +static int ksz9131_read_status(struct phy_device *phydev) +{ + int ret; + + ret = ksz9131_mdix_update(phydev); + if (ret < 0) + return ret; + + return genphy_read_status(phydev); +} + +static int ksz9131_config_aneg(struct phy_device *phydev) +{ + int ret; + + ret = ksz9131_config_mdix(phydev, phydev->mdix_ctrl); + if (ret) + return ret; + + return genphy_config_aneg(phydev); +} + #define KSZ8873MLL_GLOBAL_CONTROL_4 0x06 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX BIT(6) #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED BIT(4) @@ -3304,6 +3379,8 @@ static struct phy_driver ksphy_driver[] = { .probe = kszphy_probe, .config_init = ksz9131_config_init, .config_intr = kszphy_config_intr, + .config_aneg = ksz9131_config_aneg, + .read_status = ksz9131_read_status, .handle_interrupt = kszphy_handle_interrupt, .get_sset_count = kszphy_get_sset_count, .get_strings = kszphy_get_strings, -- 2.25.1