From patchwork Thu Oct 20 04:14:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 78396 Delivered-To: patches@linaro.org Received: by 10.140.97.247 with SMTP id m110csp585910qge; Wed, 19 Oct 2016 21:14:48 -0700 (PDT) X-Received: by 10.99.102.69 with SMTP id a66mr14232951pgc.71.1476936888851; Wed, 19 Oct 2016 21:14:48 -0700 (PDT) Return-Path: Received: from mail-pf0-x231.google.com (mail-pf0-x231.google.com. [2607:f8b0:400e:c00::231]) by mx.google.com with ESMTPS id f84si42635824pfd.206.2016.10.19.21.14.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 21:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::231 as permitted sender) client-ip=2607:f8b0:400e:c00::231; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::231 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x231.google.com with SMTP id r16so28042820pfg.1 for ; Wed, 19 Oct 2016 21:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6o7qC/YNcPNA0unGh3rDfU7Niw52KkyBEcGbIZf+K8M=; b=PtJTtb78aWNfXtQmHV39zHYyrzNdg2oGNAoaaJUH15eDcLCFOQQKXuNHsZhx2jHGZU Yxx0ZynKtMQDgMM3Z9SRl1frYihUd+mrXRzm1hnkBFobkxYCFthTR9dmk1JpjAJals06 7Z0UwbwrPLFUsAU+AMeRayjUN4pxHkZV2Jvn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6o7qC/YNcPNA0unGh3rDfU7Niw52KkyBEcGbIZf+K8M=; b=VkxAorz9x8D8v+X/hOlqGokyhOuG9VUbOsF8k/xQLlxtFbfza4fme94FvLWJPho3/p s/kyn/7Ixd88q8myv06fhdcBZzRQg/TzGuWctwpvleotexq7KgHR/hUyIPdJkBhCWY/n UjTa6a1EGOd+0wJWnXDgL/D3lA2aUhG0hl8ARGVggmUxZovzHlnShuXkNSE8q3N1Jk0M gT1N4dQdzZ4kSmZPJn9bZohboV8zQ7NyiihKulnhB/9IAAE+ZBsg29MyLAfay0GzCnA1 RyYj0Bv7xg/xJx7S+ZvwpAfPcbNEmP9zL3PXQj+UfFWf0jtPXEeIzhW6jWjQ4a7+Fv9j l0Ag== X-Gm-Message-State: AA6/9Rn4Y4EtlUzQqylwARiXukIEkJ09jDdwpT9+8ak8WsgMzzb+E1FWjQJYRL31yrFFD/kdIBA= X-Received: by 10.99.51.15 with SMTP id z15mr14515739pgz.41.1476936888528; Wed, 19 Oct 2016 21:14:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id g9sm41355655paw.40.2016.10.19.21.14.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Oct 2016 21:14:48 -0700 (PDT) From: John Stultz To: lkml Cc: Chen Yu , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Douglas Anderson , Greg Kroah-Hartman , linux-usb@vger.kernel.org, John Stultz Subject: [RFC][PATCH 2/2 v2] usb: dwc2: Add a quirk to allow speed negotiation for Hisilicon Hi6220 Date: Wed, 19 Oct 2016 21:14:41 -0700 Message-Id: <1476936881-30743-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476936881-30743-1-git-send-email-john.stultz@linaro.org> References: <1476936881-30743-1-git-send-email-john.stultz@linaro.org> From: Chen Yu The Hi6220's usb controller is limited in that it does not support "Split Transactions", so it does not support communicating with low-speed and full-speed devices behind a high-speed hub. Thus it requires a quirk so that we can manually drop the usb speed when low/full-speed are attached, and bump back to high speed when they are removed. Cc: Wei Xu Cc: Guodong Xu Cc: Amit Pundir Cc: Rob Herring Cc: John Youn Cc: Douglas Anderson Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: Chen Yu [jstultz: Reworked to simplify the patch, and made commit log to be more specific about the issue] Signed-off-by: John Stultz --- v2: * Fix build issue reported by kbuildbot * Rework to avoid using new dts entry suggested by RobH * Further tweaks from Chen Yu to try to address comments from John Youn * Further simplified logic --- drivers/usb/dwc2/core.h | 6 +++++ drivers/usb/dwc2/hcd.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc2/platform.c | 1 + 3 files changed, 68 insertions(+) -- 2.7.4 diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 2a21a04..baa4f64 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -417,6 +417,11 @@ enum dwc2_ep0_state { * needed. * 0 - No (default) * 1 - Yes + * @change_speed_quirk: Change speed configuration to DWC2_SPEED_PARAM_FULL + * while full&low speed device connect. And change speed + * back to DWC2_SPEED_PARAM_HIGH while device is gone. + * 0 - No (default) + * 1 - Yes * * The following parameters may be specified when starting the module. These * parameters define how the DWC_otg controller should be configured. A @@ -457,6 +462,7 @@ struct dwc2_core_params { int uframe_sched; int external_id_pin_ctl; int hibernation; + int change_speed_quirk; }; /** diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index b374e60..85121e2 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4868,6 +4868,62 @@ static void _dwc2_hcd_clear_tt_buffer_complete(struct usb_hcd *hcd, spin_unlock_irqrestore(&hsotg->lock, flags); } +/* + * HPRT0_SPD_HIGH_SPEED: high speed + * HPRT0_SPD_FULL_SPEED: full speed + */ +static void dwc2_change_bus_speed(struct usb_hcd *hcd, int speed) +{ + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); + + if (hsotg->core_params->speed == speed) + return; + + hsotg->core_params->speed = speed; + queue_work(hsotg->wq_otg, &hsotg->wf_otg); +} + +static void dwc2_free_dev(struct usb_hcd *hcd, struct usb_device *udev) +{ + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); + + if (!hsotg->core_params->change_speed_quirk) + return; + + /* + * On removal, set speed to default high-speed. + */ + if (udev->parent && + udev->parent->speed > USB_SPEED_UNKNOWN && + udev->parent->speed < USB_SPEED_HIGH) { + dev_info(hsotg->dev, "Set speed to default high-speed\n"); + dwc2_change_bus_speed(hcd, HPRT0_SPD_HIGH_SPEED); + } +} + +static int dwc2_reset_device(struct usb_hcd *hcd, struct usb_device *udev) +{ + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); + + if (!hsotg->core_params->change_speed_quirk) + return 0; + + if (udev->speed == USB_SPEED_HIGH) { + dev_info(hsotg->dev, "Set speed to high-speed\n"); + dwc2_change_bus_speed(hcd, HPRT0_SPD_HIGH_SPEED); + } else if ((udev->speed == USB_SPEED_FULL || + udev->speed == USB_SPEED_LOW)) { + /* + * Change speed setting to full-speed if there's + * a full-speed or low-speed device plugged in. + */ + dev_info(hsotg->dev, "Set speed to full-speed\n"); + dwc2_change_bus_speed(hcd, HPRT0_SPD_FULL_SPEED); + } + + return 0; +} + static struct hc_driver dwc2_hc_driver = { .description = "dwc2_hsotg", .product_desc = "DWC OTG Controller", @@ -5023,6 +5079,11 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); } + if (hsotg->core_params->change_speed_quirk) { + dwc2_hc_driver.free_dev = dwc2_free_dev; + dwc2_hc_driver.reset_device = dwc2_reset_device; + } + hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); if (!hcd) goto error1; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 8e1728b..17eb5fd 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -85,6 +85,7 @@ static const struct dwc2_core_params params_hi6220 = { .uframe_sched = 0, .external_id_pin_ctl = -1, .hibernation = -1, + .change_speed_quirk = 1, }; static const struct dwc2_core_params params_bcm2835 = {