Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1312003rda; Mon, 23 Oct 2023 08:48:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH307qFMAvUTti7LTzsfbtv09j9t/lGhpIiCKs+U8zgulFQHuBrOWGxxpjCV0NYfifHS5Lm X-Received: by 2002:a05:6a21:7802:b0:171:c88a:8927 with SMTP id be2-20020a056a21780200b00171c88a8927mr6330256pzc.29.1698076085638; Mon, 23 Oct 2023 08:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698076085; cv=none; d=google.com; s=arc-20160816; b=Aqdsmsq0Sc56eZD0hHrWNetsaimggJB+HTpsxtTacT3zPGou8KB8+JYAFBPq4fmgEN x17dUXvlSIxhZLdTFBzaoWO2JmzlrXTS7FcAGACJOJwwo/4dnlFS7ge055JseqnTyI1f Ks6IQN9S3OjnJka9JwJ8baAAlCRc//UJzU5H1cKyqjYjK+bDeZRNvsCaqU+UCMl9NYwF 2HhB+0yowZWGQ2RbK88+LqCcY3eRHDfqtub/78DKbB+iOJDIS88LiugSmC3NquC0qDBm twFOzT7hdfYM9Skv9rWnqkaRHggUzo3rbDoPnoIyyMqvZGWrp8eIe/1NrbmtGUqcw/12 borg== 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=2d+m2iUi9j7SgycWbCA18K0TlwUyEBn+YNKqMUUW3No=; fh=Q8NcdHh7ZH3WNhS8B25W7Zd1jgCsteS1Xfmmwt5FzZY=; b=Iv9C02nn5WFOHTey9syU2AHtmTipySAAP81i7ejs1GU720G2VXDjw+5LqLVUhJhOp/ tBsHCuPxmEqkEv25Y2Mr7swiCiWazQAtT2lwA6pK7Ys1Kvxsb2x8DtwTEF9UxpoWU5Lh ChNxKm/sWxe19RAEu+Lpg3jYeFURNXDUAcAhjbb4FOLz+rykWIpqgvA4OlTk0hwEnDQA w8gUYUP4ge/cUThBHGAfQ573Vq6AfajtMLyYX5ZVNAwT0Nt+0f1rZrV7iVSEWzp7uJnb LpfljvUFxghCacwZX9Ye75BO8XxMGXXK/umVCVaUJrerVFeyt83UqwAmjExByxxaW9k6 uuRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=xXheGG3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id r19-20020a638f53000000b005aaaedab297si6499704pgn.234.2023.10.23.08.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 08:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=xXheGG3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 00FA780AC8EF; Mon, 23 Oct 2023 08:48:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbjJWPro (ORCPT + 99 others); Mon, 23 Oct 2023 11:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232139AbjJWPrl (ORCPT ); Mon, 23 Oct 2023 11:47:41 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E23101; Mon, 23 Oct 2023 08:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1698076059; x=1729612059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IcLRsqXm3RrW6Za2geboSU2UmP+psDSYEwOcvrxgQTE=; b=xXheGG3IiXnnrypW4IEiTgZ57kW/rh+U/uAsXIn+VRwWBG357eo5wQyK R2XfpDhFswEroKpQKE9x7BV1WOzdIgeKiu2BXRr0XxHSODDKRZimSLwbH miCv1s3gEDNWsKMABy2DgfboTiQBfC1PpC12OTh/wup9m3c3XJU2OHhNL 7ttL9VJS6ScUG+eN00E5MUAIpAM1nJQr2esGn5k1/xkzuLNGBvOFG7a+4 YImK0bM1U6juHMs1toUpxYip01wEdLkW98yZpOlO0MJG7sR7S+hwOtk7M XNQsRLvxUrecyWAIaCDAfN2jYciNAifyy+SOEhdp1kYt0SFO+lWaN4DWr Q==; X-CSE-ConnectionGUID: 4O8X7pv4TK2a1gqzb4d+ug== X-CSE-MsgGUID: br4/HxjgT1+QYrysW4eXBQ== X-ThreatScanner-Verdict: Negative X-IronPort-AV: E=Sophos;i="6.03,244,1694761200"; d="scan'208";a="10448736" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 23 Oct 2023 08:47:35 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) 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.21; Mon, 23 Oct 2023 08:47:34 -0700 Received: from CHE-LT-I17164LX.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Mon, 23 Oct 2023 08:47:22 -0700 From: Parthiban Veerasooran To: , , , , , , , , , , , , CC: , , , , , , , , , Parthiban Veerasooran Subject: [PATCH net-next v2 2/9] net: ethernet: oa_tc6: implement mac-phy software reset Date: Mon, 23 Oct 2023 21:16:42 +0530 Message-ID: <20231023154649.45931-3-Parthiban.Veerasooran@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023154649.45931-1-Parthiban.Veerasooran@microchip.com> References: <20231023154649.45931-1-Parthiban.Veerasooran@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 08:48:03 -0700 (PDT) Reset complete bit is set when the MAC-PHY reset completes and ready for configuration. When it is set, it will generate a non-maskable interrupt to alert the SPI host. Additionally reset complete bit in the STS0 register has to be written by one upon reset complete to clear the interrupt. Signed-off-by: Parthiban Veerasooran --- drivers/net/ethernet/oa_tc6.c | 64 ++++++++++++++++++++++++++++++++--- include/linux/oa_tc6.h | 9 +++++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index acedc327b05e..e4457569135f 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -6,6 +6,8 @@ */ #include +#include +#include #include /* Opaque structure for MACPHY drivers */ @@ -169,10 +171,15 @@ static int oa_tc6_perform_ctrl(struct oa_tc6 *tc6, u32 addr, u32 val[], u8 len, if (ret) return ret; - /* Check echoed/received control reply for errors */ - ret = oa_tc6_check_control(tc6, tx_buf, rx_buf, len, wnr, prote); - if (ret) - return ret; + /* In case of reset write, the echoed control command doesn't have any + * valid data. So no need to check for errors. + */ + if (addr != RESET) { + /* Check echoed/received control reply for errors */ + ret = oa_tc6_check_control(tc6, tx_buf, rx_buf, len, wnr, prote); + if (ret) + return ret; + } if (!wnr) { /* Copy read data from the rx data in case of ctrl read */ @@ -191,6 +198,49 @@ static int oa_tc6_perform_ctrl(struct oa_tc6 *tc6, u32 addr, u32 val[], u8 len, return ret; } +static int oa_tc6_sw_reset(struct oa_tc6 *tc6) +{ + u32 regval; + int ret; + + /* Perform software reset with both protected and unprotected control + * commands because the driver doesn't know the current status of the + * MAC-PHY. + */ + regval = SWRESET; + ret = oa_tc6_perform_ctrl(tc6, RESET, ®val, 1, true, true); + if (ret) + return ret; + + ret = oa_tc6_perform_ctrl(tc6, RESET, ®val, 1, true, false); + if (ret) + return ret; + + /* The chip completes a reset in 3us, we might get here earlier than + * that, as an added margin we'll conditionally sleep 5us. + */ + udelay(5); + + ret = oa_tc6_perform_ctrl(tc6, STATUS0, ®val, 1, false, false); + if (ret) + return ret; + + /* Check for reset complete interrupt status */ + if (regval & RESETC) { + regval = RESETC; + /* SPI host should write RESETC bit with one to + * clear the reset interrupt status. + */ + ret = oa_tc6_perform_ctrl(tc6, STATUS0, ®val, 1, true, false); + if (ret) + return ret; + } else { + return -ENODEV; + } + + return 0; +} + /** * oa_tc6_write_register - function for writing a MACPHY register. * @tc6: oa_tc6 struct. @@ -279,6 +329,12 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, bool prote) tc6->spi = spi; tc6->prote = prote; + /* Perform MAC-PHY software reset */ + if (oa_tc6_sw_reset(tc6)) { + dev_err(&spi->dev, "MAC-PHY software reset failed\n"); + return NULL; + } + return tc6; } EXPORT_SYMBOL_GPL(oa_tc6_init); diff --git a/include/linux/oa_tc6.h b/include/linux/oa_tc6.h index 6284828bda42..8a838499da97 100644 --- a/include/linux/oa_tc6.h +++ b/include/linux/oa_tc6.h @@ -21,6 +21,15 @@ #define TC6_FTR_SIZE 4 /* Ctrl command footer size ss per OA */ #define TC6_CTRL_BUF_SIZE 1032 /* Max ctrl buffer size for 128 regs */ +/* Open Alliance TC6 Standard Control and Status Registers */ +/* Reset Control and Status Register */ +#define RESET 0x0003 +#define SWRESET BIT(0) /* Software Reset */ + +/* Status Register #0 */ +#define STATUS0 0x0008 +#define RESETC BIT(6) /* Reset Complete */ + struct oa_tc6 *oa_tc6_init(struct spi_device *spi, bool prote); int oa_tc6_write_register(struct oa_tc6 *tc6, u32 addr, u32 val); int oa_tc6_read_register(struct oa_tc6 *tc6, u32 addr, u32 *val); -- 2.34.1