From patchwork Mon Jul 4 09:04:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Appana Durga Kedareswara rao X-Patchwork-Id: 9212035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A2356048B for ; Mon, 4 Jul 2016 09:06:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87A1428603 for ; Mon, 4 Jul 2016 09:06:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BCEF2860D; Mon, 4 Jul 2016 09:06:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 177F428603 for ; Mon, 4 Jul 2016 09:06:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bJzok-0004dX-8j; Mon, 04 Jul 2016 09:05:26 +0000 Received: from mail-cys01nam02on0079.outbound.protection.outlook.com ([104.47.37.79] helo=NAM02-CY1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bJzoY-0003Kr-89 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2016 09:05:16 +0000 Received: from SN1NAM02FT013.eop-nam02.prod.protection.outlook.com (10.152.72.54) by SN1NAM02HT177.eop-nam02.prod.protection.outlook.com (10.152.73.233) with Microsoft SMTP Server (TLS) id 15.1.523.9; Mon, 4 Jul 2016 09:04:51 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by SN1NAM02FT013.mail.protection.outlook.com (10.152.72.98) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.534.7 via Frontend Transport; Mon, 4 Jul 2016 09:04:51 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1bJzo7-0005gc-6G; Mon, 04 Jul 2016 02:04:47 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1bJzoA-0008B7-GL; Mon, 04 Jul 2016 02:04:50 -0700 Received: from xsj-pvapsmtp01 (xsj-mail.xilinx.com [149.199.38.66]) by xsj-smtp-dlp2.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u6494m6V001672; Mon, 4 Jul 2016 02:04:48 -0700 Received: from [172.23.64.208] (helo=xhdrdevl6.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1bJzo7-0008AS-Kl; Mon, 04 Jul 2016 02:04:48 -0700 Received: by xhdrdevl6.xilinx.com (Postfix, from userid 13614) id B3C9BF20010; Mon, 4 Jul 2016 14:34:46 +0530 (IST) From: Kedareswara rao Appana To: , , , , , , , , , Subject: [RFC PATCH v2 2/4] net: ethernet: xilinx: Add gmii2rgmii converter support Date: Mon, 4 Jul 2016 14:34:42 +0530 Message-ID: <1467623084-15471-3-git-send-email-appanad@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1467623084-15471-1-git-send-email-appanad@xilinx.com> References: <1467623084-15471-1-git-send-email-appanad@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-22430.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.83; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(50944005)(199003)(189002)(4326007)(81166006)(2950100001)(36756003)(2201001)(92566002)(107886002)(19580405001)(48376002)(36386004)(8676002)(47776003)(5001770100001)(4001450100002)(2906002)(356003)(33646002)(4001430100002)(305945005)(7846002)(90966002)(50466002)(106466001)(81156014)(189998001)(575784001)(19580395003)(8936002)(50226002)(86362001)(52956003)(42186005)(87936001)(11100500001)(46386002)(76176999)(50986999)(229853001)(5890100001)(103686003)(63266004)(5003940100001)(586003)(45336002)(921003)(107986001)(2004002)(1121003)(217873001)(2101003)(83996005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1NAM02HT177; H:xsj-pvapsmtpgw01; FPR:; SPF:Pass; PTR:unknown-60-83.xilinx.com; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: eeaf506e-ff5e-4441-729f-08d3a3ea423c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:SN1NAM02HT177; X-Microsoft-Antispam-PRVS: <60e1a97915664d78a001f58fd4ff5875@SN1NAM02HT177.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13015025)(13024025)(13017025)(8121501046)(13018025)(5005006)(3002001)(10201501046)(6055026); SRVR:SN1NAM02HT177; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT177; X-Forefront-PRVS: 0993689CD1 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jul 2016 09:04:51.3929 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.83]; Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT177 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160704_020514_513972_1974AFEE X-CRM114-Status: GOOD ( 20.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Kedareswara rao Appana , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for gmii2rgmii converter. The GMII to RGMII IP core provides the Reduced Gigabit Media Independent Interface (RGMII) between Ethernet physical media Devices and the Gigabit Ethernet controller. This core can Switch dynamically between the three different speed modes of Operation by configuring the converter register through mdio write. MDIO interface is used to set operating speed of Ethernet MAC. Signed-off-by: Kedareswara rao Appana --- Changes for v2: --> Passed struct xphy pointer directly to the fix_mac_speed API as suggested by the Florian. --> Added checks for the phy-node fail case as suggested by the Florian. drivers/net/ethernet/xilinx/Kconfig | 8 +++ drivers/net/ethernet/xilinx/Makefile | 1 + drivers/net/ethernet/xilinx/xilinx_gmii2rgmii.c | 79 +++++++++++++++++++++++++ include/linux/xilinx_gmii2rgmii.h | 24 ++++++++ 4 files changed, 112 insertions(+) create mode 100644 drivers/net/ethernet/xilinx/xilinx_gmii2rgmii.c create mode 100644 include/linux/xilinx_gmii2rgmii.h diff --git a/drivers/net/ethernet/xilinx/Kconfig b/drivers/net/ethernet/xilinx/Kconfig index 4f5c024..4b65174 100644 --- a/drivers/net/ethernet/xilinx/Kconfig +++ b/drivers/net/ethernet/xilinx/Kconfig @@ -39,4 +39,12 @@ config XILINX_LL_TEMAC This driver supports the Xilinx 10/100/1000 LocalLink TEMAC core used in Xilinx Spartan and Virtex FPGAs +config XILINX_GMII2RGMII + tristate "Xilinx GMII2RGMII converter driver" + default y + ---help--- + This driver support xilinx GMII to RGMII IP core it provides + the Reduced Gigabit Media Independent Interface(RGMII) between + Ethernet physical media devices and the Gigabit Ethernet controller. + endif # NET_VENDOR_XILINX diff --git a/drivers/net/ethernet/xilinx/Makefile b/drivers/net/ethernet/xilinx/Makefile index 214205e..bca0da0 100644 --- a/drivers/net/ethernet/xilinx/Makefile +++ b/drivers/net/ethernet/xilinx/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_XILINX_LL_TEMAC) += ll_temac.o obj-$(CONFIG_XILINX_EMACLITE) += xilinx_emaclite.o xilinx_emac-objs := xilinx_axienet_main.o xilinx_axienet_mdio.o obj-$(CONFIG_XILINX_AXI_EMAC) += xilinx_emac.o +obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o diff --git a/drivers/net/ethernet/xilinx/xilinx_gmii2rgmii.c b/drivers/net/ethernet/xilinx/xilinx_gmii2rgmii.c new file mode 100644 index 0000000..de3bd89 --- /dev/null +++ b/drivers/net/ethernet/xilinx/xilinx_gmii2rgmii.c @@ -0,0 +1,79 @@ +/* Xilinx GMII2RGMII Converter driver + * + * Copyright (C) 2016 Xilinx, Inc. + * + * Author: Kedareswara rao Appana + * + * Description: + * This driver is developed for Xilinx GMII2RGMII Converter + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void xgmii2rgmii_fix_mac_speed(struct gmii2rgmii *xphy, + unsigned int speed) +{ + struct phy_device *gmii2rgmii_phydev = xphy->gmii2rgmii_phy_dev; + u16 gmii2rgmii_reg = 0; + + switch (speed) { + case 1000: + gmii2rgmii_reg |= XILINX_GMII2RGMII_SPEED1000; + break; + case 100: + gmii2rgmii_reg |= XILINX_GMII2RGMII_SPEED100; + break; + default: + return; + } + + xphy->mdio_write(xphy->mii_bus, gmii2rgmii_phydev->mdio.addr, + XILINX_GMII2RGMII_REG_NUM, + gmii2rgmii_reg); +} + +int gmii2rgmii_phyprobe(struct gmii2rgmii *xphy) +{ + struct device_node *phy_node; + struct phy_device *phydev; + struct device_node *np = (struct device_node *)xphy->platform_data; + + phy_node = of_parse_phandle(np, "gmii2rgmii-phy-handle", 0); + if (phy_node) { + phydev = of_phy_attach(xphy->dev, phy_node, 0, 0); + if (!phydev) { + netdev_err(xphy->dev, + "%s: no gmii to rgmii converter found\n", + xphy->dev->name); + return -1; + } + xphy->gmii2rgmii_phy_dev = phydev; + xphy->fix_mac_speed = xgmii2rgmii_fix_mac_speed; + } else { + xphy->gmii2rgmii_phy_dev = 0; + xphy->fix_mac_speed = 0; + } + + return 0; +} +EXPORT_SYMBOL(gmii2rgmii_phyprobe); + +MODULE_DESCRIPTION("Xilinx GMII2RGMII converter driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/xilinx_gmii2rgmii.h b/include/linux/xilinx_gmii2rgmii.h new file mode 100644 index 0000000..b328ee7 --- /dev/null +++ b/include/linux/xilinx_gmii2rgmii.h @@ -0,0 +1,24 @@ +#ifndef _GMII2RGMII_H +#define _GMII2RGMII_H + +#include +#include +#include + +#define XILINX_GMII2RGMII_FULLDPLX BMCR_FULLDPLX +#define XILINX_GMII2RGMII_SPEED1000 BMCR_SPEED1000 +#define XILINX_GMII2RGMII_SPEED100 BMCR_SPEED100 +#define XILINX_GMII2RGMII_REG_NUM 0x10 + +struct gmii2rgmii { + struct net_device *dev; + struct mii_bus *mii_bus; + struct phy_device *gmii2rgmii_phy_dev; + void *platform_data; + int (*mdio_write)(struct mii_bus *bus, int mii_id, int reg, + u16 val); + void (*fix_mac_speed)(struct gmii2rgmii *xphy, unsigned int speed); +}; + +extern int gmii2rgmii_phyprobe(struct gmii2rgmii *xphy); +#endif