Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1287689lqb; Thu, 18 Apr 2024 05:58:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUv5g1GAgu7TePw/hMK5ZMW49zL8JECCNQPppoJCaPdRyxxeXuKcxkSdqokH12VhD8d0ZKLKUf9KALd9d7qEmWbxcLT6sXuuim+ploMmg== X-Google-Smtp-Source: AGHT+IE1tA9JoqLGeFjU7d2OsLJWTfOF3mQxAS+wj/SZbPzhLCYEpg9bi4viBol7f2ph87jeOxow X-Received: by 2002:a17:906:a051:b0:a55:387b:ef01 with SMTP id bg17-20020a170906a05100b00a55387bef01mr1554031ejb.49.1713445130528; Thu, 18 Apr 2024 05:58:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713445130; cv=pass; d=google.com; s=arc-20160816; b=vBrzpxkj7Vzr6mNU3Fd+VGtPkPpNBDMp62E9iLYjVNTSTlmMc9dMrkh+4r7EoP8kf9 6AdYR/E+CsuQdLweX98dU/q0qysPztwSm9r5OgSCEw8pzFkREecRhyrZ6NNcbLC+pPFL z9LChf+DnZt5pyqeCuYq4HUsIFu7x/758dYToGLuAxbg9BnKOSa/4eVzFIXRxpTCkp42 SY1eYvphPY+pe9an14wZXakbtCHE+pPJ7cCw6KRzlQ6jhcKn4oBtB6PH5SmHRsalegeM 5qe+mTcCXK7D/BsoPPw1GNWkhxRe8u98yQe/kf0SY1EcBvV7CPaFxMMmUIdALjj/bXry tdqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JIyMWwH9hmzbUunxmSLuj4ITw+piA838+3RC9lcn1zY=; fh=Yek51KtWkuS8F9wIb61YhKBdNUJJ2f/R79g/JeL1hhg=; b=hH8Ld+LaNMOgmLt5XIG3ZBdpC0qcephYRTWpOwE7ZoNFOW3C3h8SvA5e2U/CsStdPG Jwx34imYq5lDcA4eknfuUCXrBif8tH2sYr4SK3TqNf7NCCwq43d6c7CQkywasKceop1h lRLa+y7g0J2v99X4hGv0DYVcgqtmAVuv/jnBYqHN3c31j6XZXmcsj4FMx2Oo2wKtvXEt 83lre4gKaec938p22bqnYvbgzU+iIIat5lD1Vom9fQrBSNc3LS+63LKdGGn0Esq/JhUa Bwj8Oet/qAeYd30vZQc90BPXU7spk4wS1gEqFjav3oiqI+S5LIc6OmXAxXtWty0LrxqW Qjug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=ps+jACff; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-150110-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150110-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s11-20020a170906060b00b00a5555b468b9si812474ejb.177.2024.04.18.05.58.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 05:58:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150110-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=ps+jACff; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-150110-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150110-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 431DE1F21FDB for ; Thu, 18 Apr 2024 12:58:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D25CE161305; Thu, 18 Apr 2024 12:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="ps+jACff" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 297EF16078D; Thu, 18 Apr 2024 12:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713445062; cv=none; b=jhhFmLyL541RlukDsEC+hDBgTx0ZcUFlJjR+Ne3nGRT/XxdvfKEFS9wD7bTjrL+VqO2mnIn68BNa2B7JPTmC3djR/1R3XGUoicWvKVbrR3UZAYvIlg/IRFlLnH1UIJ4F+QC1FuWDzbV6h4KIwiUgLGpzGv2piSnPTn0atuS6m9k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713445062; c=relaxed/simple; bh=CEwgfS9fMPtSKgy5H4AI/vG3K7fhtg+kYKJ1YnEtVsg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z5TXJzv0QmB6q4K8opsnL9Mc+rF9gA4bKb4rm4F2eQms837glz9DSX7Yvlxjy2N68tiGompkb7i2k961ixsX2nM/F1nt6JfOpPX5vwR3/lz8ppaljH2nSEpXZDlpiGge3gVQRiCG1NF4MyBczbM5UdT12f/FDw6xWphsFmQRULI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=ps+jACff; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1713445061; x=1744981061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CEwgfS9fMPtSKgy5H4AI/vG3K7fhtg+kYKJ1YnEtVsg=; b=ps+jACff9Ior38PcTs6v5tlIxswml2sQBzGkvVx580rZX/MS86vvZ5u8 WP9iiAX/cDDgZLBNJ3bELIzqgSmNwA5pvN3EtK0mxdia++QCjGIzLPK2p 1Hh70UGaBUqNmmMQ4aNMtjAOvD73qjvZ+n495yjzxEa+2fkGZo4kEwDVN wstmf+rlpUJRlSezy6E3TPgQGQAaVI1ZPs932Ew4nRd3234YdFg0AUQed KHTZB5D7tO0tZR0TzDq9VBroGKXeHamLWVKkATjBZglrTKlW9MN93focL 6Je6xL4JQhJioTKnTMzFWTd2OzR5pfxOzKHKlNZKgr5/isv9HLCSGRnD8 A==; X-CSE-ConnectionGUID: wIEpAzdhSGCIIYIJVV9X/Q== X-CSE-MsgGUID: 6a6cyb+/SoeYTnfNr1hPDg== X-IronPort-AV: E=Sophos;i="6.07,212,1708412400"; d="scan'208";a="23619637" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Apr 2024 05:57:39 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 18 Apr 2024 05:57:21 -0700 Received: from CHE-LT-I17164LX.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 18 Apr 2024 05:57:13 -0700 From: Parthiban Veerasooran To: , , , , , , , , , , , , , , , , , , , CC: , , , , , , Parthiban Veerasooran Subject: [PATCH net-next v4 04/12] net: ethernet: oa_tc6: implement software reset Date: Thu, 18 Apr 2024 18:26:40 +0530 Message-ID: <20240418125648.372526-5-Parthiban.Veerasooran@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240418125648.372526-1-Parthiban.Veerasooran@microchip.com> References: <20240418125648.372526-1-Parthiban.Veerasooran@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Reset complete bit is set when the MAC-PHY reset completes and ready for configuration. 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 | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index f563329912e2..4b0f63c02c35 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -6,8 +6,18 @@ */ #include +#include #include +/* OPEN Alliance TC6 registers */ +/* Reset Control and Status Register */ +#define OA_TC6_REG_RESET 0x0003 +#define RESET_SWRESET BIT(0) /* Software Reset */ + +/* Status Register #0 */ +#define OA_TC6_REG_STATUS0 0x0008 +#define STATUS0_RESETC BIT(6) /* Reset Complete */ + /* Control command header */ #define OA_TC6_CTRL_HEADER_DATA_NOT_CTRL BIT(31) #define OA_TC6_CTRL_HEADER_WRITE_NOT_READ BIT(29) @@ -24,6 +34,8 @@ (OA_TC6_CTRL_MAX_REGISTERS *\ OA_TC6_CTRL_REG_VALUE_SIZE) +\ OA_TC6_CTRL_IGNORED_SIZE) +#define STATUS0_RESETC_POLL_DELAY 1000 +#define STATUS0_RESETC_POLL_TIMEOUT 1000000 /* Internal structure for MAC-PHY drivers */ struct oa_tc6 { @@ -279,6 +291,39 @@ int oa_tc6_write_register(struct oa_tc6 *tc6, u32 address, u32 value) } EXPORT_SYMBOL_GPL(oa_tc6_write_register); +static int oa_tc6_read_status0(struct oa_tc6 *tc6) +{ + u32 regval; + int ret; + + ret = oa_tc6_read_register(tc6, OA_TC6_REG_STATUS0, ®val); + if (ret) + return 0; + + return regval; +} + +static int oa_tc6_sw_reset_macphy(struct oa_tc6 *tc6) +{ + u32 regval = RESET_SWRESET; + int ret; + + ret = oa_tc6_write_register(tc6, OA_TC6_REG_RESET, regval); + if (ret) + return ret; + + /* Poll for soft reset complete for every 1ms until 1s timeout */ + ret = readx_poll_timeout(oa_tc6_read_status0, tc6, regval, + regval & STATUS0_RESETC, + STATUS0_RESETC_POLL_DELAY, + STATUS0_RESETC_POLL_TIMEOUT); + if (ret) + return -ENODEV; + + /* Clear the reset complete status */ + return oa_tc6_write_register(tc6, OA_TC6_REG_STATUS0, regval); +} + /** * oa_tc6_init - allocates and initializes oa_tc6 structure. * @spi: device with which data will be exchanged. @@ -289,6 +334,7 @@ EXPORT_SYMBOL_GPL(oa_tc6_write_register); struct oa_tc6 *oa_tc6_init(struct spi_device *spi) { struct oa_tc6 *tc6; + int ret; tc6 = devm_kzalloc(&spi->dev, sizeof(*tc6), GFP_KERNEL); if (!tc6) @@ -311,6 +357,13 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi) if (!tc6->spi_ctrl_rx_buf) return NULL; + ret = oa_tc6_sw_reset_macphy(tc6); + if (ret) { + dev_err(&tc6->spi->dev, + "MAC-PHY software reset failed: %d\n", ret); + return NULL; + } + return tc6; } EXPORT_SYMBOL_GPL(oa_tc6_init); -- 2.34.1