From patchwork Fri Jun 23 04:41:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wu X-Patchwork-Id: 9805573 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 4D59660349 for ; Fri, 23 Jun 2017 04:40:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4060E286B1 for ; Fri, 23 Jun 2017 04:40:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31D0B286B5; Fri, 23 Jun 2017 04:40:03 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4F59286B1 for ; Fri, 23 Jun 2017 04:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=eD2i6qy33u/HRB6/SzfT6dc6aWaEJ95lw03/XIM9xx8=; b=U2goMIsXTd/XZSyy6cxeDoI6HN /USvBS3MD5Js6lieEwF3arKZvVSY8GW6+nRValA1UFKAXaudxUXra0MTVTlhVRtfX8B0jHzpi5/Y3 Sj/xnjneMPuUYYQIEchPx6IhGsgvt3IO5qMNfchwnU67WaNzidXBt+ZVouMBDoiHfwpp9UcTkgsTm BoqpevBlNN1W1hsSh+Iso/yaK9cj0CeEiJR3O6NhT8J+myarOG7NhSKtiC9LEB37mnbKssAivbF44 wiloOjqSiluw5OwKXTW5oBz9SruUH6EtpVKKHREI1+Lvia4MPYXZsLpskMPa8GQeydkNFrs6j9Lz/ VKjuvGYw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dOGO1-0000pd-0Q; Fri, 23 Jun 2017 04:40:01 +0000 Received: from lucky1.263xmail.com ([211.157.147.131]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dOGNo-0008Pd-BJ; Fri, 23 Jun 2017 04:39:50 +0000 Received: from david.wu?rock-chips.com (unknown [192.168.167.231]) by lucky1.263xmail.com (Postfix) with ESMTP id 4D9828F553; Fri, 23 Jun 2017 12:39:21 +0800 (CST) X-263anti-spam: X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 3CE1E3BC; Fri, 23 Jun 2017 12:39:18 +0800 (CST) X-RL-SENDER: david.wu@rock-chips.com X-FST-TO: davem@davemloft.net X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: david.wu@rock-chips.com X-UNIQUE-TAG: <26d02b47d12464a9a6a0ec09efd7a70f> X-ATTACHMENT-NUM: 0 X-SENDER: wdc@rock-chips.com X-DNS-TYPE: 0 Received: from unknown (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith SMTP id 834IMLZNY; Fri, 23 Jun 2017 12:39:20 +0800 (CST) From: David Wu To: davem@davemloft.net, heiko@sntech.de, robh+dt@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, olof@lixom.net, linux@armlinux.org.uk, arnd@arndb.de Subject: [PATCH 01/11] net: phy: Add rockchip phy driver support Date: Fri, 23 Jun 2017 12:41:59 +0800 Message-Id: <1498192929-7519-2-git-send-email-david.wu@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498192929-7519-1-git-send-email-david.wu@rock-chips.com> References: <1498192929-7519-1-git-send-email-david.wu@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170622_213948_760196_29B69463 X-CRM114-Status: GOOD ( 12.93 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangtao@rock-chips.com, andrew@lunn.ch, hwg@rock-chips.com, f.fainelli@gmail.com, alexandre.torgue@st.com, devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, David Wu , peppe.cavallaro@st.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Support internal ephy currently. Signed-off-by: David Wu --- drivers/net/phy/Kconfig | 4 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/rockchip.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/net/phy/rockchip.c diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index c360dd6..86010d4 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -350,6 +350,10 @@ config XILINX_GMII2RGMII the Reduced Gigabit Media Independent Interface(RGMII) between Ethernet physical media devices and the Gigabit Ethernet controller. +config ROCKCHIP_MAC_PHY + tristate "Drivers for ROCKCHIP MAC PHY" + ---help--- + Currently supports the mac internal ephy. endif # PHYLIB config MICREL_KS8995MA diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index e36db9a..6d96779 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -69,3 +69,4 @@ obj-$(CONFIG_STE10XP) += ste10Xp.o obj-$(CONFIG_TERANETICS_PHY) += teranetics.o obj-$(CONFIG_VITESSE_PHY) += vitesse.o obj-$(CONFIG_XILINX_GMII2RGMII) += xilinx_gmii2rgmii.o +obj-$(CONFIG_ROCKCHIP_MAC_PHY) += rockchip.o diff --git a/drivers/net/phy/rockchip.c b/drivers/net/phy/rockchip.c new file mode 100644 index 0000000..69e96ec --- /dev/null +++ b/drivers/net/phy/rockchip.c @@ -0,0 +1,94 @@ +/** + * Rockchip mac phy driver + * + * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd + * + * David Wu + * + * 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. + * + */ + + +#include +#include +#include +#include +#include +#include + +static int internal_config_init(struct phy_device *phydev) +{ + int val; + u32 features; + + /*enable auto mdix*/ + phy_write(phydev, 0x11, 0x0080); + + features = (SUPPORTED_TP | SUPPORTED_MII + | SUPPORTED_AUI | SUPPORTED_FIBRE | + SUPPORTED_BNC); + + /* Do we support autonegotiation? */ + val = phy_read(phydev, MII_BMSR); + if (val < 0) + return val; + + if (val & BMSR_ANEGCAPABLE) + features |= SUPPORTED_Autoneg; + + if (val & BMSR_100FULL) + features |= SUPPORTED_100baseT_Full; + if (val & BMSR_100HALF) + features |= SUPPORTED_100baseT_Half; + if (val & BMSR_10FULL) + features |= SUPPORTED_10baseT_Full; + if (val & BMSR_10HALF) + features |= SUPPORTED_10baseT_Half; + + if (val & BMSR_ESTATEN) { + val = phy_read(phydev, MII_ESTATUS); + if (val < 0) + return val; + + if (val & ESTATUS_1000_TFULL) + features |= SUPPORTED_1000baseT_Full; + if (val & ESTATUS_1000_THALF) + features |= SUPPORTED_1000baseT_Half; + } + + phydev->supported = features; + phydev->advertising = features; + + return 0; +} + +static struct phy_driver rockchip_phy_driver[] = { +{ + .phy_id = 0x1234d400, + .phy_id_mask = 0xffffffff, + .name = "rockchip internal ephy", + .features = 0, + .config_init = internal_config_init, + .config_aneg = genphy_config_aneg, + .read_status = genphy_read_status, + .suspend = genphy_suspend, + .resume = genphy_resume, +}, +}; + +module_phy_driver(rockchip_phy_driver); + +static struct mdio_device_id __maybe_unused rockchip_phy_tbl[] = { + { 0x1234d400, 0xffffffff }, + { } +}; + +MODULE_DEVICE_TABLE(mdio, rockchip_phy_tbl); + +MODULE_AUTHOR("David Wu"); +MODULE_DESCRIPTION("Rockchip mac phy driver"); +MODULE_LICENSE("GPL v2");