From patchwork Thu Jun 8 20:04:28 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: 9776403 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 6EE9960393 for ; Thu, 8 Jun 2017 20:06:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3E227F98 for ; Thu, 8 Jun 2017 20:06:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 536DC2846F; Thu, 8 Jun 2017 20:06:14 +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 B29D427F98 for ; Thu, 8 Jun 2017 20:06:13 +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=yeKm96qjM3101g9hXRsLJll7nk/5s8ZetdYQsui8R8s=; b=CTdAq/rVfG0fV6 wRAhXegoJwEe3+rGMqm42aDwPRZ8Pi7oVQpzoSQqx/1ob7xvTxLFElxKe6z42qhRgQKdjf7L4G7Ax xktJePM9cRETURokGo7KxDGXAI07/9T+Ynfc4LBJT3Aa1f1HEmmxQ1C/G0p7jRJkdKcS+Ka6nITnq itkqkDed6jyOenmwTx+8nRGtvswsZIyo+NtAeCj3QzidLIOM+QNaXF90Vg9WJLCy/boMXpzFZLW/w LJnxViknNc3w5mTXR8DS+vFaVHtJ/BD9qHVi5CZfF1bFK6sf22II4da3Zn1JcB5Ct5RRUNsS+YC22 GfkbejUYvWxlTsvZW6UQ==; 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 1dJ3h6-0003xh-5j; Thu, 08 Jun 2017 20:06:12 +0000 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dJ3g6-0001Op-Bm for linux-arm-kernel@lists.infradead.org; Thu, 08 Jun 2017 20:05:14 +0000 Received: by mail-lf0-x242.google.com with SMTP id x81so3815690lfb.3 for ; Thu, 08 Jun 2017 13:04:50 -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=PzWx2MxH8BkDHzDO4uRs2TXe6o6Bm0PH6XQBCZtB+xA=; b=fJGSXgD1YHqoHrpdQXVGSial5VGRrHSyPaiUq0N5Bid0BpQsgI+pF78i9F6+h3imB2 O5Pj9PiEHB2Jp80gjQDSPS7beTleCeMkD43tzK7M+QsWg+xG3zF8d5OCM/qzkR7kQJe5 n9RfEYLaYr5uXI8A4qm314J2YTGrfExyTRSEtz8kbaKRhTgkMz1wdl3zamX+7CMfADmR lkxamKB9gzaAkzePqjI5aF9MoOUY9/hrcHGDWRtv5DRtEjqIt5qf+3M2UCb1UtI3qMIZ +21dNoF+h7BKavxuEsS+5wmG0OW7MB8TqU3GE7EeuqaINVwJY/p+iNo5a0EFTh133NLE bbQQ== 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=PzWx2MxH8BkDHzDO4uRs2TXe6o6Bm0PH6XQBCZtB+xA=; b=TB4bovy5DKJ1GevV7N7Q71K8QllifaQAXe+uQr9re0zcfdoWMMzD2IwM7Lkfevn/dg Ng4+qFkQClGRTeroxSfMbGfjEMkREnksVs7lxaVYH/7gbMrICWR81+viSsHHh1isNzAJ rFuFSV1e5BaMw43oDJ+VMVmXkYiUPZNkw88dOYSqz0h0lI6QDTzUeKzw/XozFO438qi+ 8zBb58R6iIB4Wv2GmuFJn6G/MYaLyDrM1AA4DQlVJqSDsLSyRWVGRwts1OX6qujtJzgq 2iSMIIqwUQqFzBxOhvhSnmY7SP9SYMrohmnNrJNsOYdPW0CSvKeepkzkhQdPU9b+Qwj/ n4nw== X-Gm-Message-State: AODbwcCfnxtSyJI3hcICqfTRZdYalPlVcJPaEiGQRA+aipkPB8u5slPR 0+XnDK9kzxG2Lg== X-Received: by 10.25.32.205 with SMTP id g196mr11456888lfg.133.1496952289130; Thu, 08 Jun 2017 13:04:49 -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 s14sm37477ljd.3.2017.06.08.13.04.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 13:04:48 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Kishon Vijay Abraham I Subject: [PATCH V2 5/5] phy: bcm-ns-usb3: add MDIO driver using proper bus layer Date: Thu, 8 Jun 2017 22:04:28 +0200 Message-Id: <20170608200428.9187-6-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170608200428.9187-1-zajec5@gmail.com> References: <20170511132925.14564-1-zajec5@gmail.com> <20170608200428.9187-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_130510_692975_80FAA53F X-CRM114-Status: GOOD ( 18.70 ) 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. For now keep platform device support in place. We may consider dropping it once MDIO bindings gets used "everywhere". Signed-off-by: Rafał Miłecki --- V2: Select MDIO_DEVICE which was introduced in 4.12. Add info about possible removal of platform driver in the future. --- drivers/phy/broadcom/Kconfig | 1 + drivers/phy/broadcom/phy-bcm-ns-usb3.c | 105 ++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/drivers/phy/broadcom/Kconfig b/drivers/phy/broadcom/Kconfig index d2d99023ec50..517fe0f3e639 100644 --- a/drivers/phy/broadcom/Kconfig +++ b/drivers/phy/broadcom/Kconfig @@ -31,6 +31,7 @@ config PHY_BCM_NS_USB3 depends on ARCH_BCM_IPROC || COMPILE_TEST depends on HAS_IOMEM && OF select GENERIC_PHY + select MDIO_DEVICE help Enable this to support Broadcom USB 3.0 PHY connected to the USB controller on Northstar family. diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb3.c b/drivers/phy/broadcom/phy-bcm-ns-usb3.c index 2c9a0d5f43d8..a53ae128eadf 100644 --- a/drivers/phy/broadcom/phy-bcm-ns-usb3.c +++ b/drivers/phy/broadcom/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,35 @@ 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; + + /* + * For backward compatibility we register as MDIO and platform driver. + * After getting MDIO binding commonly used (e.g. switching all DT files + * to use it) we should deprecate the old binding and eventually drop + * support for it. + */ + + 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");