From patchwork Tue Jan 3 19:52:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 89733 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8169830qgi; Tue, 3 Jan 2017 11:52:49 -0800 (PST) X-Received: by 10.84.210.35 with SMTP id z32mr126886221plh.112.1483473169115; Tue, 03 Jan 2017 11:52:49 -0800 (PST) Return-Path: Received: from mail-pg0-x229.google.com (mail-pg0-x229.google.com. [2607:f8b0:400e:c05::229]) by mx.google.com with ESMTPS id 23si52581pfs.129.2017.01.03.11.52.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 11:52:49 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::229 as permitted sender) client-ip=2607:f8b0:400e:c05::229; 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:c05::229 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x229.google.com with SMTP id g1so178868528pgn.0 for ; Tue, 03 Jan 2017 11:52:49 -0800 (PST) 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=tVrUgI4gAT+4k03kZl7jFAlOWmNtthCP9jNNlaETQVw=; b=GVs7Qfex/wjIxvr5HvV/LeDWuQDtoPI7mSfxbTGzjVF5SQ+QqfYs3KZvLB8E8uMJ9P G1Q53SEV7ZAsxxYq2wN3qo7fUXfy2ctwr5r/IUKhi5TTWkMNhxkCaFg6/WYlLQAXje/+ NkqeiprgZyRpuW1zw64U7v5ULYkr3vc3h3Jaw= 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; bh=tVrUgI4gAT+4k03kZl7jFAlOWmNtthCP9jNNlaETQVw=; b=srNQEewSn+KDXqlwq391OWJw9gh18u0AxzyvAjjoyoM52xcOWXYEI0Trh4D4NqKg9R 38m7hJkQqA+4hQdrlixiU+mGZLdzJXOiEN4gz6cLLQbAZZbQYCkPqaW7RgJl2FyU72I7 tz44FJ0G3V0ypbsfeefTpbs0kBiUP5HSSJg7NjxbIuI+Upt/IAE/IlxW+ji9KsltZSzT PvBP+7pxqbIT5alALqk/9DdtT0qexZn/iKCAbRaiyi9jotlGVoDtF2VWiNBrS9xtusjJ u5IYhfXs0n9fLbbz7hBc9Bt/Vy88FU4DtvFnVecPrDV6l5oErpdshlwwaPaW+uNqkHdT znFw== X-Gm-Message-State: AIkVDXJglMfpMMgS9o3HFKbBfCyhbelsdE1dMkTKo4wyPLIKULuZELVnBKcSkckhq1NU+lwet6w= X-Received: by 10.84.210.233 with SMTP id a96mr139095162pli.118.1483473168803; Tue, 03 Jan 2017 11:52:48 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id r1sm93771794pgn.48.2017.01.03.11.52.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jan 2017 11:52:47 -0800 (PST) From: John Stultz To: lkml Cc: Chen Yu , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Douglas Anderson , Vardan Mikayelyan , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH 5/5 v2] usb: dwc2: Add a quirk to allow speed negotiation for Hisilicon Hi6220 Date: Tue, 3 Jan 2017 11:52:37 -0800 Message-Id: <1483473157-16678-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483473157-16678-1-git-send-email-john.stultz@linaro.org> References: <1483473157-16678-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: Chen Yu Cc: Vardan Mikayelyan Cc: Kishon Vijay Abraham I Cc: Felipe Balbi 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: * Reworked to adapt around changes that landed in 4.10-rc drivers/usb/dwc2/core.h | 7 ++++++ drivers/usb/dwc2/hcd.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc2/params.c | 19 +++++++++++++++ 3 files changed, 86 insertions(+) -- 2.7.4 diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index eb2d628..4074752 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -444,6 +444,11 @@ enum dwc2_ep0_state { * in DWORDS with possible values from from * 16-32768 (default: 256, 256, 256, 256, 768, * 768, 768, 768, 0, 0, 0, 0, 0, 0, 0). + * @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 @@ -516,6 +521,8 @@ struct dwc2_core_params { u16 g_rx_fifo_size; u16 g_np_tx_fifo_size; u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; + + int change_speed_quirk; }; /** diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 6e4ec8a..81997d2 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4876,6 +4876,61 @@ 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->params.speed == speed) + return; + + hsotg->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->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->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", @@ -5031,6 +5086,11 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); } + if (hsotg->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/params.c b/drivers/usb/dwc2/params.c index a786256..71ca9c2 100644 --- a/drivers/usb/dwc2/params.c +++ b/drivers/usb/dwc2/params.c @@ -67,6 +67,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 = { @@ -227,6 +228,7 @@ static const struct dwc2_core_params params_default = { .uframe_sched = -1, .external_id_pin_ctl = -1, .hibernation = -1, + .change_speed_quirk = -1, }; const struct of_device_id dwc2_of_match_table[] = { @@ -1110,6 +1112,22 @@ static void dwc2_set_gadget_dma(struct dwc2_hsotg *hsotg) !!hw->dma_desc_enable); } +static void dwc2_set_change_speed_quirk(struct dwc2_hsotg *hsotg, int val) +{ + if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { + if (val >= 0) { + dev_err(hsotg->dev, + "'%d' invalid for parameter change_speed_quirk\n", + val); + dev_err(hsotg->dev, "change_speed_quirk must be 0 or 1\n"); + } + val = 0; + dev_dbg(hsotg->dev, "Setting change_speed_quirk to %d\n", val); + } + + hsotg->params.change_speed_quirk = val; +} + /** * dwc2_set_parameters() - Set all core parameters. * @@ -1170,6 +1188,7 @@ static void dwc2_set_parameters(struct dwc2_hsotg *hsotg, dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl); dwc2_set_param_hibernation(hsotg, params->hibernation); + dwc2_set_change_speed_quirk(hsotg, params->change_speed_quirk); /* * Set devicetree-only parameters. These parameters do not