From patchwork Thu Apr 21 09:18:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Kumar X-Patchwork-Id: 8898051 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D40339F1C1 for ; Thu, 21 Apr 2016 09:21:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25D85202FF for ; Thu, 21 Apr 2016 09:21:20 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 1A4E820256 for ; Thu, 21 Apr 2016 09:21:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1atAm1-0002TY-77; Thu, 21 Apr 2016 09:19:45 +0000 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1atAld-0001rV-Fi for linux-arm-kernel@lists.infradead.org; Thu, 21 Apr 2016 09:19:22 +0000 X-IronPort-AV: E=Sophos;i="5.24,512,1455004800"; d="scan'208";a="93233597" Received: from mail-irv-18.broadcom.com ([10.15.198.37]) by mail-gw3-out.broadcom.com with ESMTP; 21 Apr 2016 02:30:56 -0700 Received: from mail-irva-12.broadcom.com (mail-irva-12.broadcom.com [10.11.16.101]) by mail-irv-18.broadcom.com (Postfix) with ESMTP id 4318C82032; Thu, 21 Apr 2016 02:19:01 -0700 (PDT) Received: from pramodku-OptiPlex-7010.ban.broadcom.com (unknown [10.132.81.79]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id D55161276E1; Thu, 21 Apr 2016 02:18:45 -0700 (PDT) From: Pramod Kumar To: Rob Herring , Catalin Marinas , Will Deacon , Masahiro Yamada , Chen-Yu Tsai Subject: [PATCH 6/6] net:phy: Add Ethernet Master for iProc Shared MDIO Controller Date: Thu, 21 Apr 2016 14:48:43 +0530 Message-Id: <1461230323-27891-7-git-send-email-pramod.kumar@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461230323-27891-1-git-send-email-pramod.kumar@broadcom.com> References: <1461230323-27891-1-git-send-email-pramod.kumar@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160421_021921_974384_4D8F91D2 X-CRM114-Status: GOOD ( 19.29 ) X-Spam-Score: -5.2 (-----) 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: Mark Rutland , devicetree@vger.kernel.org, Pawel Moll , Arnd Bergmann , Suzuki K Poulose , netdev@vger.kernel.org, Punit Agrawal , linux-kernel@vger.kernel.org, Pramod Kumar , BCM Kernel Feedback , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add Ethernet master driver which registers the ethernet phy to standard legacy mdio framework. Signed-off-by: Pramod Kumar Reviewed-by: Ray Jui Reviewed-by: Scott Branden --- drivers/net/phy/Kconfig | 11 +++ drivers/net/phy/Makefile | 1 + drivers/net/phy/mdio-bcm-iproc-shared.c | 116 ++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 drivers/net/phy/mdio-bcm-iproc-shared.c diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 6dad9a9..35a7d59 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -271,6 +271,17 @@ config MDIO_BCM_IPROC This module provides a driver for the MDIO busses found in the Broadcom iProc SoC's. +config MDIO_BCM_IPROC_SHARED + tristate "Ethernet Master for Broadcom iProc Shared MDIO Controller" + depends on OF && OF_MDIO && (ARCH_BCM_IPROC || COMPILE_TEST) + default ARCH_BCM_IPROC + help + This module provides a driver for the ethernet master found in + shared MDIO controller in the Broadcom iProc SoC's. + + Enable this to support the Shared MDIO controller. + if unsure, say N. + endif # PHYLIB config MICREL_KS8995MA diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index fcdbb92..e1c0bc5 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -44,3 +44,4 @@ obj-$(CONFIG_MDIO_MOXART) += mdio-moxart.o obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o obj-$(CONFIG_MICROCHIP_PHY) += microchip.o obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o +obj-$(CONFIG_MDIO_BCM_IPROC_SHARED) += mdio-bcm-iproc-shared.o diff --git a/drivers/net/phy/mdio-bcm-iproc-shared.c b/drivers/net/phy/mdio-bcm-iproc-shared.c new file mode 100644 index 0000000..6844107 --- /dev/null +++ b/drivers/net/phy/mdio-bcm-iproc-shared.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2016 Broadcom + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; 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 + +struct iproc_mdio_priv { + struct shared_mdio_master *master; + struct mii_bus *mii_bus; +}; + +static int iproc_mdio_mii_read(struct mii_bus *bus, int phyadr, int reg) +{ + struct iproc_mdio_priv *priv = (struct iproc_mdio_priv *)bus->priv; + + return shared_mdio_read(priv->master, phyadr, reg); +} + +static int iproc_mdio_mii_write(struct mii_bus *bus, int phyadr, int reg, + u16 val) +{ + struct iproc_mdio_priv *priv = bus->priv; + + return shared_mdio_write(priv->master, phyadr, reg, val); +} + +static int iproc_mdio_probe(struct shared_mdio_master *master) +{ + struct device *dev = &master->dev; + struct iproc_mdio_priv *priv; + struct mii_bus *bus; + struct device_node *dn = dev->of_node; + int rc = 0; + + if (of_get_child_count(dn) == 0) + return -ENODEV; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + priv->master = master; + + priv->mii_bus = mdiobus_alloc(); + if (!priv->mii_bus) { + dev_err(dev, "mdio bus alloc failed\n"); + return -ENOMEM; + } + + bus = priv->mii_bus; + bus->priv = priv; + bus->name = "iProc MDIO bus"; + snprintf(bus->id, MII_BUS_ID_SIZE, "%s-%d", dev_name(&master->dev), + master->dev_num); + bus->parent = &master->dev; + bus->read = iproc_mdio_mii_read; + bus->write = iproc_mdio_mii_write; + + rc = of_mdiobus_register(bus, master->dev.of_node); + if (rc) { + dev_err(dev, "mdio bus registration failed\n"); + goto mdiobus_err; + } + + shared_mdio_set_drvdata(master, priv); + dev_info(dev, "iProc MDIO bus registered\n"); + return 0; + +mdiobus_err: + mdiobus_free(bus); + return rc; +} + +int iproc_mdio_remove(struct shared_mdio_master *master) +{ + struct iproc_mdio_priv *priv = shared_mdio_get_drvdata(master); + + mdiobus_unregister(priv->mii_bus); + mdiobus_free(priv->mii_bus); + + return 0; +} + +static const struct of_device_id iproc_mdio_of_match[] = { + { .compatible = "brcm,iproc-mdio-master-eth" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, iproc_mdio_of_match); + +static struct shared_mdio_driver iproc_mdio_driver = { + .driver = { + .name = "iproc-mdio-master-eth", + .of_match_table = iproc_mdio_of_match, + }, + .probe = iproc_mdio_probe, + .remove = iproc_mdio_remove, +}; +module_shared_mdio_driver(iproc_mdio_driver); + +MODULE_DESCRIPTION("Broadcom iProc shared mdio master driver"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Pramod Kumar ");