From patchwork Wed Apr 11 07:24:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghuram Chary J X-Patchwork-Id: 897062 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40Lb832n25z9s1r for ; Wed, 11 Apr 2018 17:21:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbeDKHVw (ORCPT ); Wed, 11 Apr 2018 03:21:52 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:14621 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751858AbeDKHVv (ORCPT ); Wed, 11 Apr 2018 03:21:51 -0400 X-IronPort-AV: E=Sophos;i="5.48,435,1517900400"; d="scan'208";a="13053858" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Apr 2018 00:21:50 -0700 Received: from I20884-mchip.microchip.com (10.10.76.4) by chn-sv-exch04.mchp-main.com (10.10.76.105) with Microsoft SMTP Server id 14.3.352.0; Wed, 11 Apr 2018 00:21:49 -0700 From: Raghuram Chary J To: CC: , , , Subject: [PATCH v1 net 3/3] lan78xx: Lan7801 Support for Fixed PHY Date: Wed, 11 Apr 2018 12:54:50 +0530 Message-ID: <20180411072450.9809-4-raghuramchary.jallipalli@microchip.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180411072450.9809-1-raghuramchary.jallipalli@microchip.com> References: <20180411072450.9809-1-raghuramchary.jallipalli@microchip.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Adding Fixed PHY support to the lan78xx driver. Fixes: 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver") Signed-off-by: Raghuram Chary J --- drivers/net/usb/Kconfig | 1 + drivers/net/usb/lan78xx.c | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index f28bd74ac275..418b0904cecb 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -111,6 +111,7 @@ config USB_LAN78XX select MII select PHYLIB select MICROCHIP_PHY + select FIXED_PHY help This option adds support for Microchip LAN78XX based USB 2 & USB 3 10/100/1000 Ethernet adapters. diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index cbeec784f8b8..0c87ac1b767f 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include "lan78xx.h" #define DRIVER_AUTHOR "WOOJUNG HUH " @@ -426,6 +426,7 @@ struct lan78xx_net { struct statstage stats; struct irq_domain_data domain_data; + struct phy_device *fixedphy; }; /* define external phy id */ @@ -2061,11 +2062,39 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) int ret; u32 mii_adv; struct phy_device *phydev; + struct fixed_phy_status fphy_status = { + .link = 1, + .speed = SPEED_1000, + .duplex = DUPLEX_FULL, + }; phydev = phy_find_first(dev->mdiobus); if (!phydev) { - netdev_err(dev->net, "no PHY found\n"); - return -EIO; + if (dev->chipid == ID_REV_CHIP_ID_7801_) { + u32 buf; + + netdev_info(dev->net, "PHY Not Found!! Registering Fixed PHY\n"); + phydev = fixed_phy_register(PHY_POLL, &fphy_status, -1, + NULL); + if (IS_ERR(phydev)) { + netdev_err(dev->net, "No PHY/fixed_PHY found\n"); + return -ENODEV; + } + netdev_info(dev->net, "Registered FIXED PHY\n"); + dev->interface = PHY_INTERFACE_MODE_RGMII; + dev->fixedphy = phydev; + ret = lan78xx_write_reg(dev, MAC_RGMII_ID, + MAC_RGMII_ID_TXC_DELAY_EN_); + ret = lan78xx_write_reg(dev, RGMII_TX_BYP_DLL, 0x3D00); + ret = lan78xx_read_reg(dev, HW_CFG, &buf); + buf |= HW_CFG_CLK125_EN_; + buf |= HW_CFG_REFCLK25_EN_; + ret = lan78xx_write_reg(dev, HW_CFG, buf); + goto phyinit; + } else { + netdev_err(dev->net, "no PHY found\n"); + return -EIO; + } } if ((dev->chipid == ID_REV_CHIP_ID_7800_) || @@ -2103,7 +2132,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) ret = -EIO; goto error; } - +phyinit: /* if phyirq is not set, use polling mode in phylib */ if (dev->domain_data.phyirq > 0) phydev->irq = dev->domain_data.phyirq; @@ -3562,6 +3591,11 @@ static void lan78xx_disconnect(struct usb_interface *intf) udev = interface_to_usbdev(intf); net = dev->net; + + if (dev->fixedphy) { + fixed_phy_unregister(dev->fixedphy); + dev->fixedphy = NULL; + } unregister_netdev(net); cancel_delayed_work_sync(&dev->wq);