From patchwork Fri Jun 3 14:05:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9153181 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 7BE486072B for ; Fri, 3 Jun 2016 14:08:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D56C28327 for ; Fri, 3 Jun 2016 14:08:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6219C28330; Fri, 3 Jun 2016 14:08:25 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id F20BD28327 for ; Fri, 3 Jun 2016 14:08:24 +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 1b8pkM-0005Q9-F9; Fri, 03 Jun 2016 14:06:46 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8pjK-0003KM-4Y for linux-arm-kernel@lists.infradead.org; Fri, 03 Jun 2016 14:05:51 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE12D63E18; Fri, 3 Jun 2016 14:05:19 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-4-176.ams2.redhat.com [10.36.4.176]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u53E5ErM019117; Fri, 3 Jun 2016 10:05:15 -0400 From: Hans de Goede To: Bin Liu , Greg Kroah-Hartman , Kishon Vijay Abraham I Subject: [PATCH v2 1/4] USB: Fix of_usb_get_dr_mode_by_phy with a shared phy block Date: Fri, 3 Jun 2016 16:05:08 +0200 Message-Id: <1464962711-5871-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 03 Jun 2016 14:05:20 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160603_070542_848764_49B8C222 X-CRM114-Status: GOOD ( 18.78 ) 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: devicetree , linux-usb@vger.kernel.org, Hans de Goede , Chen-Yu Tsai , Maxime Ripard , 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-Virus-Scanned: ClamAV using ClamSMTP Some SoCs have a single phy-hw-block with multiple phys, this is modelled by a single phy dts node, so we end up with multiple controller nodes with a phys property pointing to the phy-node of the otg-phy. Only one of these controllers typically is an otg controller, yet we were checking the first controller who uses a phy from the block and then end up looking for a dr_mode property in e.g. the ehci controller. This commit fixes this by adding an arg0 parameter to of_usb_get_dr_mode_by_phy and make of_usb_get_dr_mode_by_phy check that this matches the phandle args[0] value when looking for the otg controller. Signed-off-by: Hans de Goede --- -Changes in v2: Add a args0 parameter instead of looking for nodes with a dr_mode property --- drivers/usb/common/common.c | 31 ++++++++++++++++++------------- drivers/usb/phy/phy-am335x.c | 2 +- include/linux/usb/of.h | 4 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index e3d0161..bd716f4 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -131,32 +131,37 @@ EXPORT_SYMBOL_GPL(usb_get_dr_mode); * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device * which is associated with the given phy device_node * @np: Pointer to the given phy device_node + * @arg0: phandle args[0] for phy's with #phy-cells >= 1 * * In dts a usb controller associates with phy devices. The function gets * the string from property 'dr_mode' of the controller associated with the * given phy device node, and returns the correspondig enum usb_dr_mode. */ -enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) +enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) { struct device_node *controller = NULL; - struct device_node *phy; + struct of_phandle_args args; const char *dr_mode; int index; int err; + bool found = false; do { controller = of_find_node_with_property(controller, "phys"); - index = 0; - do { - phy = of_parse_phandle(controller, "phys", index); - of_node_put(phy); - if (phy == phy_np) - goto finish; - index++; - } while (phy); - } while (controller); - -finish: + for (index = 0; !found; index++) { + err = of_parse_phandle_with_args(controller, "phys", + "#phy-cells", index, &args); + if (err) + break; + + if (args.np == np && (args.args_count == 0 || + args.args[0] == arg0)) + found = true; + + of_node_put(args.np); + } + } while (controller && !found); + err = of_property_read_string(controller, "dr_mode", &dr_mode); of_node_put(controller); diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c index a262a43..7e5aece 100644 --- a/drivers/usb/phy/phy-am335x.c +++ b/drivers/usb/phy/phy-am335x.c @@ -54,7 +54,7 @@ static int am335x_phy_probe(struct platform_device *pdev) return am_phy->id; } - am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node); + am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1); ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL); if (ret) diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index de3237f..5ff9032 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -12,7 +12,7 @@ #include #if IS_ENABLED(CONFIG_OF) -enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); +enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0); bool of_usb_host_tpl_support(struct device_node *np); int of_usb_update_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps); @@ -20,7 +20,7 @@ struct device_node *usb_of_get_child_node(struct device_node *parent, int portnum); #else static inline enum usb_dr_mode -of_usb_get_dr_mode_by_phy(struct device_node *phy_np) +of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) { return USB_DR_MODE_UNKNOWN; }