From patchwork Sun Aug 4 20:50:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Petrous X-Patchwork-Id: 13752714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69281C3DA7F for ; Sun, 4 Aug 2024 20:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=NMB8mNVRjdVqv2i9GDwiXIMh+SsN9kN0r8pyi7oJWD0=; b=Dnv46dQ7iWh23+qV3U/1xOOUmT MymNp7hBmlQBjK0KBV6oeD1DjQbrMo56B9RiQJbKoXg6JFJgWtUapfunyDFBwyXBom8r3w61iSzYO ooQLpl9YSAd5dcTktQ5NtXe3ZiR0+Fd0n1M+nruhyVnJnBDcN5ehxvwOgNcbMSLfTIDhP41JS4cW+ qCSHD4afjvcpzZMSj9n8B+HB9PcvhatJ7+8sh01FUFCoSusWupaQ0YO03LmEfkodYdvIQ+S0iZ3fb IdcxZ3Zu0/RX/twCCGBNAfpZA35ZOdcQlHwy/Klcgbg3ml6QQzd+LmHaOyKYpUMmcOAzQZgj4xQuL rJHWwNkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1saiCa-0000000Du70-0JQo; Sun, 04 Aug 2024 20:51:40 +0000 Received: from mail-westeuropeazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c201::3] helo=AS8PR04CU009.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1saiBB-0000000DtdD-3HT1 for linux-arm-kernel@lists.infradead.org; Sun, 04 Aug 2024 20:50:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C8i+rOUk2h8E1djyAmgQ6pRx8cKp2kWYeFsec2W/OuCpoMkFxuyp9ArJXIR9/a2yOiaqxyBbLV84Yje33VQJrMk7T0+Qe7bwXHoPtByPzBXHcFFIpSBt746Kz7b/r9FKE2/5tCMvnjUsYoksS16vLqhkauEUGX4yVs/WI0jlMWAdW7VmZ47boDyddUEXlqWc/GxMZtC5bfhNIdtZnqswjep9t+zlqIMCCW6UOJdVMTRLQarjX9dS4DcmzHHAgkbRKi8ayx3h15RkNnMAHjDDgl/ne2qUQDFvRmmdDL9R5I3g+AGgudzbrRZhIjQHHXa0q3AsxCf3+PK7x4Fs8fRRiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NMB8mNVRjdVqv2i9GDwiXIMh+SsN9kN0r8pyi7oJWD0=; b=iC+VhPIVXjuMkHYDvGwofyRSuGhebuUcEmdxlbgunr67MGi5AUdf3xCwNAFz1p/XZgcUtp3oh4xe5yn3E6Zhj0AwX4SphwO1WKWfX9qacuu9UUEDgmrg1nnzHke94VbRHl257zXrY3sSdnacVE+q5KxQLC2N17S7XJbMaBzD65gvYoGk7WuUyaBH9u1UGp/L20KWLApoyKoxS9Dkjh547ks6t393ab7OB3Flkr/ljkr0HHgZ6jt7CJOCHMb20KN0t+llDt8Hfa5fNxJaAtBtDYpT+m3Im6bGXpgVDz/dSu7kOtVs0orcOSA7ZSBKf6LlkWLAJ5s3/1gqy/RE3lmcVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NMB8mNVRjdVqv2i9GDwiXIMh+SsN9kN0r8pyi7oJWD0=; b=qWQmQIbCgh3jZqL1k6DjoQStNQtRqHgcWNsX283JCqppUR2tuqTFd9FyANj59yvXb0LN4bL1NdzDDIRWayj0a5M5J7nrqMCHgPn9P8Eqp7LAuPkFonLXzAHHiur1ofm+Eyv5J44KOIzz1yOLSp3TbaZ9fD1is4brBCOhp/QPyoWoZA4Eo/QdrG4vIqTUeHz4gZZBuKIblXndUDMa+UCI3SLqDpnVrA0vBR57FWjfT/CzuED5wGsGX09vYk5tdCPi8BqORzzMjhGeJdvab/11BX5ez3boIi6wR4gKq+b/BtFc3D2BqExnSe+WH+5PsMX3x6BKvgbF6Y6+XjH8F2emfg== Received: from AM9PR04MB8506.eurprd04.prod.outlook.com (2603:10a6:20b:431::16) by PA4PR04MB7965.eurprd04.prod.outlook.com (2603:10a6:102:c9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.25; Sun, 4 Aug 2024 20:50:10 +0000 Received: from AM9PR04MB8506.eurprd04.prod.outlook.com ([fe80::5f7:9bab:66a3:fe27]) by AM9PR04MB8506.eurprd04.prod.outlook.com ([fe80::5f7:9bab:66a3:fe27%4]) with mapi id 15.20.7828.024; Sun, 4 Aug 2024 20:50:10 +0000 From: "Jan Petrous (OSS)" To: Maxime Coquelin , Alexandre Torgue CC: dl-S32 , "linux-kernel@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , Claudiu Manoil , "netdev@vger.kernel.org" Subject: [PATCH 4/6] net: stmmac: dwmac-s32cc: add basic NXP S32G/S32R glue Thread-Topic: [PATCH 4/6] net: stmmac: dwmac-s32cc: add basic NXP S32G/S32R glue Thread-Index: AdrmrVyUKT3e9hhXSvuIq/Wc0/85TQ== Date: Sun, 4 Aug 2024 20:50:10 +0000 Message-ID: Accept-Language: cs-CZ, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AM9PR04MB8506:EE_|PA4PR04MB7965:EE_ x-ms-office365-filtering-correlation-id: b8d56ecd-c1d5-4342-4193-08dcb4c707b7 x-ms-exchange-sharedmailbox-routingagent-processed: True x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|376014|366016|1800799024|38070700018; x-microsoft-antispam-message-info: jSIjBJ9nWSoOJ+4uzv+EZfb0C7XcKCxbTUxqfxdfupQsLwcycyCP5R+oXO2dyg5/WsNKP4qUsZ+zWTKcSGgPvWLl2A52tkSVlyt4GmOWFJ+K2vqinCW7K5q4RaNP4Ey8RYSKyEM7+DeIt12MXJsq8gW1CqHY6N18AMjcUehxxrxKEeKmwTxrHcejbD7PHXYMqa/HzjulP3D/WdKZ6BrP75wYiBDMmzIrddtpERVJMoKARXaaiSp7KcR1BkUT64jiQcA53OeMpZgYOld/2mdWnr83DhVSttDuTjej+cTJFM+fOoI+xmmfweYmLExuNQIE5V4sW6QcKEpXtxoBkkwGnPwQwx32sH8im4ipSxST/EO3QVYoQ+XS6R9xjOmikw01WYxgIER+NzVR8CYzGRee3zd1QamVbLvkRIO15dEoWQsBO9rFph09pqgFMTWDh5aLy+3lwghm7nKZuN6tkgJUUuqmtjDNiai/6m0M9IQMIfIIDRXSVxnKQ1JT+lDsa//VuV4pS7/dhZTeMmdHaiYMZ2cBmo3M4lwuJSqygrlOGPoJig/YzD/CswGhc5H3tLPeQwC6xbWZK/vVKlqzsNExoUVjZzvVokB0MRnIw8hLU2l09Yhp4TpM82jXnokmtCC7MqDRcDEBxXR3UZQGlr/gS+gskCVKJLmZUebq0N7JJp7TWL0LFeyXqBNGVmi9/6oJM787zbvQ52G6e6AVHS5A7zu0uZXbwcREn8EYryLo4GWinTmK3XOSiWu6HAClRCZUapZE/NhzPlszNF/4HUeKBp84G0INLZaVSDKG6RkdIdo7DXXNVZ2Q1LJxMMg8drkFW+4UtgcXUU11eLCH3Bymi0VDfwvrteVA7GSgCqfiklw4x0ldzXneGWCtdGUSJpeLm8NDNWI2nNljP6k8xdjqbFgjeoQEjLVnSv8aknihFtG6MDl4dat0TCe1FW0+AZfjEsm1j5MaBLcCPBtmCnBZGM+J5uusYUp5HYBou/q11bg32pKq+Fx03i5lzwFC1mSC0CUtF+pxoY9QMBkw3gGuoK1zd+SiW6wG57DznANXVxMYe8D7wIXXUOm3y/whnoVVyJWucy8Mr4UdU7Ev1dVixRCPdLvtpEHcN+WqjqRb2l0Q5qptr+mcwAuVytahu7JqjZbonSQOUPzRxKMyYasq6nARyyKB7h+Ld4iVt+kx1Jx6iiKLWs5RJNq7WiqLEa9sl31O+sOYDkhExsOKagkhC89vXteSixCw1LO8EPe5Ijv+Cu3Y3HOZKrFZlaJ1hujPYDmf7QbtIhiTsdNMsAIrAFbAM0I6iCAfR1yMXhzTnSyjSuQu8HVuS82lYCs6KdCfLA1mheik/Sv0cg6GLm/WF1r24cqrkgP82zX0UrcPsouCrzFeaPOJhaWStDWfg4qTwaJHol2wruzUF4FkMvCIyw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8506.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024)(38070700018);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: qvKtB3F+fwn4IyLaSz/iMs77WRkxt+DrFBZ0B7n64Tk1q3706VXb6AB++jDSB1PDaT1A2laDuKdAKT1SV/rYAlfHL9ik1UvuUcYJIEVfvfkFK9vt+ChzqQ7/qtuNkx7VuOdm52ax2aLgsfQ7HTOJDdADJWNYLofXFz35YiwIGz8OQxd2lI80RM09wvX48sSdzRe5PfhRZHturVja4OZXFfmck+fDTrz+MCQDUHGgpYhJoDkdqlBLQCcWSNBRPcTwVP0JSo76T34aHuhpgn00eiI87DgyKDJ3zJMtiWi8sUBkYRKucAirMzr+vbdv2Ko6w70VlqVHNa9hBY8yyCm1BbX9KfUhGdHgA7oBjusCbDwmBINBZSMFUCY9zaQf6KuGOtJpgxvUOQ39RD+3JglsZ6UTeIrwvW1hxO/mKhAxDCBymxoNd97vb7iwe9KkirHeXXE4/C9a6oI7H/y01MBBIim/bW+PrTa2+J7GuROFDKktXDG3DOIM+loTN/4i0Int7Ga6LJgdY7GvyQmftd7UDAd90jxx410YaDirenfWSjuKhHQiBC4brb6ZRb4gAk+x0V7z+CVB1qKjQQMjDqNkKogL0RtQr2KTpDx8rhTzuIRzC1zUpjGrgoUP6NR9uU+/4QWGAzh4bORgTBb6gUnF7RkqrvGI77ZCncYqbHfXLfaUDIqB+f2JvC4vbP5DzSXoHQ4GPtB5qf4RcpwF4YQ107aMKm6MYzB/2WiZkYU52H/bDxIsbGPY2P5vwStxrTEfOe/l0l8exX2Wa+UduE7DIe9PL//lCVVcvZegrtCm/FW66nD7HdCjRTznG8miSczhZA1/qKCyG3I73xaxNVxz0Nu8tT9iILZLYhoWEq1wwAOl9n1EidldzgeIzTAXUh/r0Bp+SBKLaYrfWYsLXkmi0EdpTou2En8sxRi0ktn0odW9C/8Ov9CbPHa3R5L3WS5y3D6j9Xf08DyCv6FAqt9Wn8y4h6uEyXulZNmFuw2L0kzJunLM1dluIx01RCx50ZCRSwrRCJosjnTbGZSm/asytTxw5PckuGjP65eN88CfFlNQeLgGR/Ztbzm+rJiIGxkNWjGA+Eg8ygtyiomb60a5n8Gk8zOZmCSoBqzEd1s7WgSMi5bQTivuWk7FRUpRWzZm2hmYheK6gVm9hAJXfcevHxbVfvRiS3sxfNolvGO4vOCIJ8zbdnHgya7w5zsLYMgPS717Q+YfIONO4ArsRvZdtA1pXocYlVZOPhp8Gtrfc19Cs4F892D6o9OqLYbnmofgW132a3ZU4kfyyxNnzEho9dxSp/daKPzMzahlZjZl7nUsY6ujuBl75tBxlv2VjWxAOHCySENsrS8ZKkubc5IvqnIiQOsRHOfWE0wZVoaFki7l1W5jHyleWgDDdYqy/bxCn9jpixJJlP8C17nRej6Q15yy3MFuNC4DOoH2JfFm++4TMSVZjIlPY5EMNYsi2fzVwc448+GauojLveoBtWI1TGb3DIDauN8YKfVmJJWPn+n+/PBH5vA9HXjiNlXwXsuUvFvIWf9K+n+qMaI4y7HNmGrekXtGEAIpjqGkvCFUZ3bqGL2V7Q207GzQjx2yVt1Y MIME-Version: 1.0 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8506.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8d56ecd-c1d5-4342-4193-08dcb4c707b7 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Aug 2024 20:50:10.0617 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Xz/IxI7AOVA3miNaiz/6LCkkefHwCAf0U+bng/P5xf+70NoC7tHYymbyYcdpQecFlx61o2/tmte9Y3RL5EbwSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7965 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240804_135014_319894_AA630B44 X-CRM114-Status: GOOD ( 19.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org NXP S32G2xx/S32G3xx and S32R45 are automotive grade SoCs that integrate one or two Synopsys DWMAC 5.10/5.20 IPs. The basic driver supports only RGMII interface. Signed-off-by: Jan Petrous (OSS) --- drivers/net/ethernet/stmicro/stmmac/Kconfig | 11 + drivers/net/ethernet/stmicro/stmmac/Makefile | 1 + .../net/ethernet/stmicro/stmmac/dwmac-s32cc.c | 235 ++++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-s32cc.c diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 05cc07b8f48c..31628c363d71 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -153,6 +153,17 @@ config DWMAC_RZN1 This selects the Renesas RZ/N1 SoC glue layer support for the stmmac device driver. This support can make use of a custom MII converter PCS device. +config DWMAC_S32CC + tristate "NXP S32G/S32R GMAC support" + default ARCH_S32 + depends on OF && (ARCH_S32 || COMPILE_TEST) + help + Support for ethernet controller on NXP S32CC SOCs. + + This selects NXP SoC glue layer support for the stmmac + device driver. This driver is used for the S32CC series + SOCs GMAC ethernet controller, ie. S32G2xx, S32G3xx and + S32R45. config DWMAC_SOCFPGA tristate "SOCFPGA dwmac support" diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index c2f0e91f6bf8..089ef3c1c45b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_RZN1) += dwmac-rzn1.o +obj-$(CONFIG_DWMAC_S32CC) += dwmac-s32cc.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o obj-$(CONFIG_DWMAC_STARFIVE) += dwmac-starfive.o obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32cc.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32cc.c new file mode 100644 index 000000000000..2ef961efa01c --- /dev/null +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32cc.c @@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * NXP S32G/R GMAC glue layer + * + * Copyright 2019-2024 NXP + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stmmac_platform.h" + +#define GMAC_TX_RATE_125M 125000000 /* 125MHz */ +#define GMAC_TX_RATE_25M 25000000 /* 25MHz */ +#define GMAC_TX_RATE_2M5 2500000 /* 2.5MHz */ + +/* SoC PHY interface control register */ +#define PHY_INTF_SEL_MII 0x00 +#define PHY_INTF_SEL_SGMII 0x01 +#define PHY_INTF_SEL_RGMII 0x02 +#define PHY_INTF_SEL_RMII 0x08 + +struct s32cc_priv_data { + void __iomem *ioaddr; + void __iomem *ctrl_sts; + struct device *dev; + phy_interface_t intf_mode; + struct clk *tx_clk; + struct clk *rx_clk; + bool rx_clk_enabled; +}; + +static int s32cc_gmac_write_phy_intf_select(struct s32cc_priv_data *gmac) +{ + u32 intf_sel; + + switch (gmac->intf_mode) { + case PHY_INTERFACE_MODE_SGMII: + intf_sel = PHY_INTF_SEL_SGMII; + break; + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_RGMII_ID: + case PHY_INTERFACE_MODE_RGMII_TXID: + case PHY_INTERFACE_MODE_RGMII_RXID: + intf_sel = PHY_INTF_SEL_RGMII; + break; + case PHY_INTERFACE_MODE_RMII: + intf_sel = PHY_INTF_SEL_RMII; + break; + case PHY_INTERFACE_MODE_MII: + intf_sel = PHY_INTF_SEL_MII; + break; + default: + dev_err(gmac->dev, "Unsupported PHY interface: %s\n", + phy_modes(gmac->intf_mode)); + return -EINVAL; + } + + writel(intf_sel, gmac->ctrl_sts); + + dev_dbg(gmac->dev, "PHY mode set to %s\n", phy_modes(gmac->intf_mode)); + + return 0; +} + +static int s32cc_gmac_init(struct platform_device *pdev, void *priv) +{ + struct s32cc_priv_data *gmac = priv; + int ret; + + ret = clk_set_rate(gmac->tx_clk, GMAC_TX_RATE_125M); + if (!ret) + ret = clk_prepare_enable(gmac->tx_clk); + + if (ret) { + dev_err(&pdev->dev, "Can't set tx clock\n"); + return ret; + } + + ret = clk_prepare_enable(gmac->rx_clk); + if (ret) + dev_dbg(&pdev->dev, "Can't set rx, clock source is disabled.\n"); + else + gmac->rx_clk_enabled = true; + + ret = s32cc_gmac_write_phy_intf_select(gmac); + if (ret) { + dev_err(&pdev->dev, "Can't set PHY interface mode\n"); + return ret; + } + + return 0; +} + +static void s32cc_gmac_exit(struct platform_device *pdev, void *priv) +{ + struct s32cc_priv_data *gmac = priv; + + clk_disable_unprepare(gmac->tx_clk); + + clk_disable_unprepare(gmac->rx_clk); +} + +static void s32cc_fix_mac_speed(void *priv, unsigned int speed, unsigned int mode) +{ + struct s32cc_priv_data *gmac = priv; + int ret; + + if (!gmac->rx_clk_enabled) { + ret = clk_prepare_enable(gmac->rx_clk); + if (ret) { + dev_err(gmac->dev, "Can't set rx clock\n"); + return; + } + dev_dbg(gmac->dev, "rx clock enabled\n"); + gmac->rx_clk_enabled = true; + } + + switch (speed) { + case SPEED_1000: + dev_dbg(gmac->dev, "Set tx clock to 125M\n"); + ret = clk_set_rate(gmac->tx_clk, GMAC_TX_RATE_125M); + break; + case SPEED_100: + dev_dbg(gmac->dev, "Set tx clock to 25M\n"); + ret = clk_set_rate(gmac->tx_clk, GMAC_TX_RATE_25M); + break; + case SPEED_10: + dev_dbg(gmac->dev, "Set tx clock to 2.5M\n"); + ret = clk_set_rate(gmac->tx_clk, GMAC_TX_RATE_2M5); + break; + default: + dev_err(gmac->dev, "Unsupported/Invalid speed: %d\n", speed); + return; + } + + if (ret) + dev_err(gmac->dev, "Can't set tx clock\n"); +} + +static int s32cc_dwmac_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct plat_stmmacenet_data *plat; + struct s32cc_priv_data *gmac; + struct stmmac_resources res; + int ret; + + gmac = devm_kzalloc(&pdev->dev, sizeof(*gmac), GFP_KERNEL); + if (!gmac) + return PTR_ERR(gmac); + + gmac->dev = &pdev->dev; + + ret = stmmac_get_platform_resources(pdev, &res); + if (ret) + return dev_err_probe(dev, ret, + "Failed to get platform resources\n"); + + plat = devm_stmmac_probe_config_dt(pdev, res.mac); + if (IS_ERR(plat)) + return dev_err_probe(dev, PTR_ERR(plat), + "dt configuration failed\n"); + + /* PHY interface mode control reg */ + gmac->ctrl_sts = devm_platform_get_and_ioremap_resource(pdev, 1, NULL); + if (IS_ERR_OR_NULL(gmac->ctrl_sts)) + return dev_err_probe(dev, PTR_ERR(gmac->ctrl_sts), + "S32CC config region is missing\n"); + + /* tx clock */ + gmac->tx_clk = devm_clk_get(&pdev->dev, "tx"); + if (IS_ERR(gmac->tx_clk)) + return dev_err_probe(dev, PTR_ERR(gmac->tx_clk), + "tx clock not found\n"); + + /* rx clock */ + gmac->rx_clk = devm_clk_get(&pdev->dev, "rx"); + if (IS_ERR(gmac->rx_clk)) + return dev_err_probe(dev, PTR_ERR(gmac->rx_clk), + "rx clock not found\n"); + + gmac->intf_mode = plat->phy_interface; + gmac->ioaddr = res.addr; + + /* S32CC core feature set */ + plat->has_gmac4 = true; + plat->pmt = 1; + plat->flags |= STMMAC_FLAG_SPH_DISABLE; + plat->rx_fifo_size = 20480; + plat->tx_fifo_size = 20480; + + plat->init = s32cc_gmac_init; + plat->exit = s32cc_gmac_exit; + plat->fix_mac_speed = s32cc_fix_mac_speed; + + plat->bsp_priv = gmac; + + return stmmac_pltfr_probe(pdev, plat, &res); +} + +static const struct of_device_id s32cc_dwmac_match[] = { + { .compatible = "nxp,s32g2-dwmac" }, + { .compatible = "nxp,s32g3-dwmac" }, + { .compatible = "nxp,s32r45-dwmac" }, + { } +}; +MODULE_DEVICE_TABLE(of, s32cc_dwmac_match); + +static struct platform_driver s32cc_dwmac_driver = { + .probe = s32cc_dwmac_probe, + .remove_new = stmmac_pltfr_remove, + .driver = { + .name = "s32cc-dwmac", + .pm = &stmmac_pltfr_pm_ops, + .of_match_table = s32cc_dwmac_match, + }, +}; +module_platform_driver(s32cc_dwmac_driver); + +MODULE_AUTHOR("Jan Petrous (OSS) "); +MODULE_DESCRIPTION("NXP S32G/R common chassis GMAC driver"); +MODULE_LICENSE("GPL"); +