From patchwork Tue Apr 5 14:05:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 65097 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp489517lbc; Tue, 5 Apr 2016 07:10:47 -0700 (PDT) X-Received: by 10.98.16.93 with SMTP id y90mr39210539pfi.155.1459865442699; Tue, 05 Apr 2016 07:10:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si8053978pas.143.2016.04.05.07.10.42; Tue, 05 Apr 2016 07:10:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759237AbcDEOGP (ORCPT + 29 others); Tue, 5 Apr 2016 10:06:15 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:51250 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759187AbcDEOGM (ORCPT ); Tue, 5 Apr 2016 10:06:12 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u35E60pC013011; Tue, 5 Apr 2016 09:06:00 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u35E60Rb025959; Tue, 5 Apr 2016 09:06:00 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.224.2; Tue, 5 Apr 2016 09:05:59 -0500 Received: from lta0400828d.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u35E5NPB032137; Tue, 5 Apr 2016 09:05:56 -0500 From: Roger Quadros To: , , , CC: , , , , , , , , , , Roger Quadros Subject: [PATCH v6 08/12] usb: hcd: Adapt to OTG core Date: Tue, 5 Apr 2016 17:05:13 +0300 Message-ID: <1459865117-7032-9-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459865117-7032-1-git-send-email-rogerq@ti.com> References: <1459865117-7032-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce usb_otg_add/remove_hcd() for use by host controllers that are part of OTG/dual-role port. Non Device tree platforms can use the otg_dev argument to specify the OTG controller device. If otg_dev is NULL then the device tree node's otg-controller property is used to get the otg_dev device. Signed-off-by: Roger Quadros --- drivers/usb/core/hcd.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/hcd.h | 4 +++ 2 files changed, 75 insertions(+) -- 2.5.0 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 6b1930d..6a80193 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -46,6 +46,10 @@ #include #include #include +#include + +#include +#include #include "usb.h" @@ -3013,6 +3017,73 @@ void usb_remove_hcd(struct usb_hcd *hcd) } EXPORT_SYMBOL_GPL(usb_remove_hcd); + +static struct otg_hcd_ops otg_hcd_intf = { + .add = usb_add_hcd, + .remove = usb_remove_hcd, + .usb_bus_start_enum = usb_bus_start_enum, + .usb_control_msg = usb_control_msg, + .usb_hub_find_child = usb_hub_find_child, +}; + +/** + * usb_otg_add_hcd - Register the HCD with OTG core. + * @hcd: the usb_hcd structure to initialize + * @irqnum: Interrupt line to allocate + * @irqflags: Interrupt type flags + * @otg_dev: OTG controller device manging this HCD + * + * Registers the HCD with OTG core. OTG core will call usb_add_hcd() + * or usb_remove_hcd() as necessary. + * If otg_dev is NULL then device tree node is checked for OTG + * controller device via the otg-controller property. + */ +int usb_otg_add_hcd(struct usb_hcd *hcd, + unsigned int irqnum, unsigned long irqflags, + struct device *otg_dev) +{ + struct device *dev = hcd->self.controller; + + if (!otg_dev) { + struct device_node *np; + struct platform_device *pdev; + + np = of_parse_phandle(dev->of_node, "otg-controller", 0); + if (!np) { + dev_err(dev, + "otg_dev is NULL and no otg-controller property in DT\n"); + return -EINVAL; + } + + pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pdev) { + dev_err(dev, + "couldn't get otg-controller device\n"); + return -ENODEV; + } + + hcd->otg_dev = &pdev->dev; + } else { + hcd->otg_dev = otg_dev; + } + + return usb_otg_register_hcd(hcd, irqnum, irqflags, &otg_hcd_intf); +} +EXPORT_SYMBOL_GPL(usb_otg_add_hcd); + +/** + * usb_otg_remove_hcd - Unregister the HCD with OTG core. + * @hcd: the usb_hcd structure to remove + * + * Unregisters the HCD from the OTG core. + */ +void usb_otg_remove_hcd(struct usb_hcd *hcd) +{ + usb_otg_unregister_hcd(hcd); +} +EXPORT_SYMBOL_GPL(usb_otg_remove_hcd); + void usb_hcd_platform_shutdown(struct platform_device *dev) { diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 2017cd4..adcf2e7 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -472,6 +472,10 @@ extern int usb_hcd_is_primary_hcd(struct usb_hcd *hcd); extern int usb_add_hcd(struct usb_hcd *hcd, unsigned int irqnum, unsigned long irqflags); extern void usb_remove_hcd(struct usb_hcd *hcd); +extern int usb_otg_add_hcd(struct usb_hcd *hcd, + unsigned int irqnum, unsigned long irqflags, + struct device *otg_dev); +extern void usb_otg_remove_hcd(struct usb_hcd *hcd); extern int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1); struct platform_device;