From patchwork Thu May 11 13:29:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 9721517 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 554F860364 for ; Thu, 11 May 2017 13:30:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4967028635 for ; Thu, 11 May 2017 13:30:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DD8528663; Thu, 11 May 2017 13:30:57 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham 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 9DFC22865D for ; Thu, 11 May 2017 13:30:56 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=QD/3ei7/fZo6rUwvSgI4VBY+SpLDGcG3SG/wRSCbczs=; b=F3fyBynurodlBJ TuhRoo6VbM0IoxYMamvUS6UP4NT2+6fKCBAilrNbdqGB7PxexE8cJ8C8TmzZsMq8jS9r1jrfHoBBy RwHZGp8HcneDkTo3Z6tcINbM4n4xurrWpu20awvqv8tD0NYYVGpIjS0qEXa/BcNtaM77TZtaFNyGI saphBS2ECtncl4vmlcAjKkFUhrJ7otGBc6VK+trVV1H6EG0tYCjIi5Sew0/Vzy5OOJ4OkFL2F3Ahi ZfeHMgBuoV94WHSgUriWl6NbHiHPWKg6bJ7Vd/L6mm5BTRhGN7txvsxMDIbcWC6Of4yROMoIKajfx rfM7vnlKAkmdSsoD9niQ==; 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 1d8oBC-0005i2-I6; Thu, 11 May 2017 13:30:54 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d8oAU-0003PV-8r for linux-arm-kernel@lists.infradead.org; Thu, 11 May 2017 13:30:12 +0000 Received: by mail-wm0-x243.google.com with SMTP id v4so7013851wmb.2 for ; Thu, 11 May 2017 06:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KNScACDAmXNE3jrikCc8zu5gyWFOvvNFEGxhrmZ7fbk=; b=n7bOBQKzl2IKld3dK4gR0+ZpGvXzTrCOhcKT/5KKtBhRIzdyMaohhHRv7asXEv3TBy RFB4WLoKTNGL/N8Gkm3de7JUkVl8H0jG7EP50QhwKDJMX6geel/bs2QyCRWVTgXg1e06 iW++iALAxc3DbgZ/zw8xk+dhYVWy+nFTbFBySoOEoc6RLtocpVeo8LCw5RVzSVJU2Xwy adwNfUFzQdTSRqO+1azgguUsmU41TDpGuV9CO1tiWbCoTamv2KvJdcRO82mGwzj5bdrg KMqSewKXZ85PvsQVM/n/bAhj2cxs2Lc9jtFqYoYEQtLzSuDIFLQEFUask6WiJPFnNi8c RuZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KNScACDAmXNE3jrikCc8zu5gyWFOvvNFEGxhrmZ7fbk=; b=seDPt/jg+dNZ9ixKJAdMb1UbDqAf1HJh3jsZGqjSmUCMPv0mZj1JCHzrwvq1fAsu0T YQeXagxPDbZoWutn3tLN5v1Q8GTjTdOWRpL42g6RHElFqapay6kdHKtKfa2wJD9KPD0B bFfycVp5k1z6M/6VHqtmIdyjjOa/pT8lZcX9YL71vPuLNG+Ik4hUJRZA/f8kgP6eEHoM yznECT5LXuNgRVrHEI4urHDxptOMe6zMM+KKsUC8w+KUxZmYvBRdHRLFBuD2h/Buz3Um qRHBnV1WhJukp2uPk6kiFw2fiPXgbGedRvc0kNq9RmhHgymx/PTR2EEDxyvPfHlMJZ4L CIIg== X-Gm-Message-State: AODbwcA0wsg5/AnYAIQfz30OBj60KTfBvYVbTsryUAFomF2qjmD3rb7X 6UmI5u6GtYCdDw== X-Received: by 10.25.4.149 with SMTP id 143mr129958lfe.144.1494509390196; Thu, 11 May 2017 06:29:50 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id i18sm31725ljd.28.2017.05.11.06.29.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 May 2017 06:29:49 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Kishon Vijay Abraham I Subject: [PATCH 5/5] phy: bcm-ns-usb3: add MDIO driver using proper bus layer Date: Thu, 11 May 2017 15:29:25 +0200 Message-Id: <20170511132925.14564-6-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170511132925.14564-1-zajec5@gmail.com> References: <20170511132925.14564-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170511_063010_570621_154ECE09 X-CRM114-Status: GOOD ( 16.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Florian Fainelli , Jon Mason , linux-kernel@vger.kernel.org, Yendapally Reddy Dhananjaya Reddy , bcm-kernel-feedback-list@broadcom.com, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-arm-kernel@lists.infradead.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 From: Rafał Miłecki As USB 3.0 PHY is attached to the MDIO bus this module should provide a MDIO driver and use a proper bus layer. This is a proper (cleaner) solution which doesn't require code to know this specific MDIO bus details. It also allows reusing the driver with other MDIO buses. Signed-off-by: Rafał Miłecki --- drivers/phy/Kconfig | 1 + drivers/phy/phy-bcm-ns-usb3.c | 98 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index afaf7b643eeb..2a9186b98ae0 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -29,6 +29,7 @@ config PHY_BCM_NS_USB3 depends on ARCH_BCM_IPROC || COMPILE_TEST depends on HAS_IOMEM && OF select GENERIC_PHY + select PHYLIB help Enable this to support Broadcom USB 3.0 PHY connected to the USB controller on Northstar family. diff --git a/drivers/phy/phy-bcm-ns-usb3.c b/drivers/phy/phy-bcm-ns-usb3.c index 2c9a0d5f43d8..389f5e5a6238 100644 --- a/drivers/phy/phy-bcm-ns-usb3.c +++ b/drivers/phy/phy-bcm-ns-usb3.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -52,6 +54,7 @@ struct bcm_ns_usb3 { enum bcm_ns_family family; void __iomem *dmp; void __iomem *ccb_mii; + struct mdio_device *mdiodev; struct phy *phy; int (*phy_write)(struct bcm_ns_usb3 *usb3, u16 reg, u16 value); @@ -183,6 +186,77 @@ static const struct phy_ops ops = { }; /************************************************** + * MDIO driver code + **************************************************/ + +static int bcm_ns_usb3_mdiodev_phy_write(struct bcm_ns_usb3 *usb3, u16 reg, + u16 value) +{ + struct mdio_device *mdiodev = usb3->mdiodev; + + return mdiobus_write(mdiodev->bus, mdiodev->addr, reg, value); +} + +static int bcm_ns_usb3_mdio_probe(struct mdio_device *mdiodev) +{ + struct device *dev = &mdiodev->dev; + const struct of_device_id *of_id; + struct phy_provider *phy_provider; + struct device_node *syscon_np; + struct bcm_ns_usb3 *usb3; + struct resource res; + int err; + + usb3 = devm_kzalloc(dev, sizeof(*usb3), GFP_KERNEL); + if (!usb3) + return -ENOMEM; + + usb3->dev = dev; + usb3->mdiodev = mdiodev; + + of_id = of_match_device(bcm_ns_usb3_id_table, dev); + if (!of_id) + return -EINVAL; + usb3->family = (enum bcm_ns_family)of_id->data; + + syscon_np = of_parse_phandle(dev->of_node, "usb3-dmp-syscon", 0); + err = of_address_to_resource(syscon_np, 0, &res); + of_node_put(syscon_np); + if (err) + return err; + + usb3->dmp = devm_ioremap_resource(dev, &res); + if (IS_ERR(usb3->dmp)) { + dev_err(dev, "Failed to map DMP regs\n"); + return PTR_ERR(usb3->dmp); + } + + usb3->phy_write = bcm_ns_usb3_mdiodev_phy_write; + + usb3->phy = devm_phy_create(dev, NULL, &ops); + if (IS_ERR(usb3->phy)) { + dev_err(dev, "Failed to create PHY\n"); + return PTR_ERR(usb3->phy); + } + + phy_set_drvdata(usb3->phy, usb3); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static struct mdio_driver bcm_ns_usb3_mdio_driver = { + .mdiodrv = { + .driver = { + .name = "bcm_ns_mdio_usb3", + .of_match_table = bcm_ns_usb3_id_table, + }, + }, + .probe = bcm_ns_usb3_mdio_probe, +}; + +/************************************************** * Platform driver code **************************************************/ @@ -297,6 +371,28 @@ static struct platform_driver bcm_ns_usb3_driver = { .of_match_table = bcm_ns_usb3_id_table, }, }; -module_platform_driver(bcm_ns_usb3_driver); + +static int __init bcm_ns_usb3_module_init(void) +{ + int err; + + err = mdio_driver_register(&bcm_ns_usb3_mdio_driver); + if (err) + return err; + + err = platform_driver_register(&bcm_ns_usb3_driver); + if (err) + mdio_driver_unregister(&bcm_ns_usb3_mdio_driver); + + return err; +} +module_init(bcm_ns_usb3_module_init); + +static void __exit bcm_ns_usb3_module_exit(void) +{ + platform_driver_unregister(&bcm_ns_usb3_driver); + mdio_driver_unregister(&bcm_ns_usb3_mdio_driver); +} +module_exit(bcm_ns_usb3_module_exit) MODULE_LICENSE("GPL v2");