From patchwork Fri Jul 14 21:40:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 107828 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1446032qge; Fri, 14 Jul 2017 14:41:18 -0700 (PDT) X-Received: by 10.98.204.23 with SMTP id a23mr7425062pfg.59.1500068478153; Fri, 14 Jul 2017 14:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500068478; cv=none; d=google.com; s=arc-20160816; b=FL4Or1FoWYer10KCqlv1PAgT1hMwAtD8X58xtO5Q6C5PDFOhi7fNHycwsyurYuB12v 6CHZvCJLevz6ah6Kv3Iw8HcV2KRHIA26MKm4v6ym4Yjg0FAgTitFJO3gNE+xHXTFTbrb fa1yD3e6ecT8oPOWXXGo/d9v1qneoorioIKBcnJu/tdMYkGLpaEzUs6qPaGoZJ/8CRoU +6Mi5xeOs5MEu0CU36uWGmIjGzrgbxQMvd+KKbFbmtkT1877YF4fyPRlbHa79qBKT3+V hIcu6PRWk3wsehjkJFD/ziOYZTQgLiHbVILNMtVSu7WQ59smivrbdWzkDSPk4nEI3WbK yGOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BSaWw6a+xDUoGSsN4nCPJ9z58VZBw6s5QYBmlJGAuh4=; b=VG6boQ5oRK1WWMzvIqBcoge058P7nXR6mz6rNiPoQiu/xaZAQ8DGZ2rvd+W6B03NG1 drKo8aXSb7nhmu6lz4Akk5KK4LtBjRnzRtY4CPjGlh5aGtZzrAP1MyUi4JpmvKwqFP8a CSO4MzgdQE7/m9uDY9y28Vw8GMLT55crVK8tEEtSePGKGsB/WfQLn7AgXm8k6UB8Z+fw Qw3L4g3YLg1rQxq56VzpVT/EkZn5YKC2sG1xGUR5+oSrxscg8IC7soNeRb2XNDuwkOC4 U7O35JI4PaFmCFMRZ+xb+SUzgo5dJotYkGTX8em+eSKALKJovpgY1eGcmbVfRYWa8SWp yx3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=TvWVioOx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si7301899pgq.222.2017.07.14.14.41.17; Fri, 14 Jul 2017 14:41:18 -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; dkim=pass header.i=@linaro.org header.b=TvWVioOx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751273AbdGNVlO (ORCPT + 25 others); Fri, 14 Jul 2017 17:41:14 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:33535 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115AbdGNVkJ (ORCPT ); Fri, 14 Jul 2017 17:40:09 -0400 Received: by mail-pg0-f53.google.com with SMTP id k14so51396048pgr.0 for ; Fri, 14 Jul 2017 14:40:09 -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=BSaWw6a+xDUoGSsN4nCPJ9z58VZBw6s5QYBmlJGAuh4=; b=TvWVioOxW+O+cvv65lFFaV01FubZdloIvr31eAz+r24GO37t5xtHyCWHV7CvQi3bi5 lhyU2lXDkaU82vpLEA7sfJjY2YG+67XQBjRdTh+cJUhOwqzcYRx+fRTORxOWDZDUK7dG i+MHP6cNwD8SvO3ICocP+f/AGpranX3oukkCs= 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=BSaWw6a+xDUoGSsN4nCPJ9z58VZBw6s5QYBmlJGAuh4=; b=aaSBDea3MvGVeP2cV7Mhm6OrX7PNqSv1SfGZqSF3BbEat0iop7b4hSXmyNGDCgWmnE d90o9XVGMGOHRIyV6OdjdMI6t4z2o0FB4TjrWrBJQXDBNLUZ6sVceVa1HhuLIb2VCrFZ AxUPY4NNU4gdzeOAj0RUUHDzuTLuRIQ171MTmhskYGshimD4P3BFxQXH8VA6canlQFFm 26CsLk+upOpPDjP02M8BDmt+oWR7bNGL9jOHRK24MF6QlOw3dkE/8R/ogf494c4K1f7Z JwX4s2TbxOWSlMH3Sk/utK8YTKqvssFEf0z+AF9gpDQ1oT0VPqS5c3GMlc81j9HdRZbO Tsvg== X-Gm-Message-State: AIVw1127t+HBDuQrEuuYAAwrHhvzV0Wp5YyI4FdNXWlM+SGuN1A+vyqO jQwKIDAnQdDPIzDi X-Received: by 10.84.132.73 with SMTP id 67mr17985650ple.53.1500068408984; Fri, 14 Jul 2017 14:40:08 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e13sm17795271pfh.96.2017.07.14.14.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:40:08 -0700 (PDT) From: Stephen Boyd To: Peter Rosin Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.infradead.org, Rob Herring , Rob Clark , Peter Chen , Andy Gross , Jonathan Cameron , Philipp Zabel Subject: [PATCH v2 1/3] mux: Add mux_control_get_optional() API Date: Fri, 14 Jul 2017 14:40:03 -0700 Message-Id: <20170714214005.14967-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170714214005.14967-1-stephen.boyd@linaro.org> References: <20170714214005.14967-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes drivers only use muxes under certain scenarios. For example, the chipidea usb controller may be connected to a usb switch on some platforms, and connected directly to a usb port on others. The driver won't know one way or the other though, so add a mux_control_get_optional() API that allows the driver to differentiate errors getting the mux from there not being a mux for the driver to use at all. Cc: Jonathan Cameron Cc: Philipp Zabel Signed-off-by: Stephen Boyd --- Documentation/driver-model/devres.txt | 1 + drivers/mux/mux-core.c | 98 ++++++++++++++++++++++++++++------- include/linux/mux/consumer.h | 4 ++ 3 files changed, 83 insertions(+), 20 deletions(-) -- 2.10.0.297.gf6727b0 diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 30e04f7a690d..4fdd3e63ff8b 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -342,6 +342,7 @@ MUX devm_mux_chip_alloc() devm_mux_chip_register() devm_mux_control_get() + devm_mux_control_get_optional() PER-CPU MEM devm_alloc_percpu() diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c index 90b8995f07cb..a0e5bf16f02f 100644 --- a/drivers/mux/mux-core.c +++ b/drivers/mux/mux-core.c @@ -289,6 +289,9 @@ EXPORT_SYMBOL_GPL(devm_mux_chip_register); */ unsigned int mux_control_states(struct mux_control *mux) { + if (!mux) + return 0; + return mux->states; } EXPORT_SYMBOL_GPL(mux_control_states); @@ -338,6 +341,9 @@ int mux_control_select(struct mux_control *mux, unsigned int state) { int ret; + if (!mux) + return 0; + ret = down_killable(&mux->lock); if (ret < 0) return ret; @@ -370,6 +376,9 @@ int mux_control_try_select(struct mux_control *mux, unsigned int state) { int ret; + if (!mux) + return 0; + if (down_trylock(&mux->lock)) return -EBUSY; @@ -398,6 +407,9 @@ int mux_control_deselect(struct mux_control *mux) { int ret = 0; + if (!mux) + return 0; + if (mux->idle_state != MUX_IDLE_AS_IS && mux->idle_state != mux->cached_state) ret = mux_control_set(mux, mux->idle_state); @@ -422,14 +434,8 @@ static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) return dev ? to_mux_chip(dev) : NULL; } -/** - * mux_control_get() - Get the mux-control for a device. - * @dev: The device that needs a mux-control. - * @mux_name: The name identifying the mux-control. - * - * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. - */ -struct mux_control *mux_control_get(struct device *dev, const char *mux_name) +struct mux_control * +__mux_control_get(struct device *dev, const char *mux_name, bool optional) { struct device_node *np = dev->of_node; struct of_phandle_args args; @@ -441,6 +447,8 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) if (mux_name) { index = of_property_match_string(np, "mux-control-names", mux_name); + if (index == -EINVAL && optional) + return NULL; if (index < 0) { dev_err(dev, "mux controller '%s' not found\n", mux_name); @@ -451,6 +459,8 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) ret = of_parse_phandle_with_args(np, "mux-controls", "#mux-control-cells", index, &args); + if (ret == -ENOENT && optional) + return NULL; if (ret) { dev_err(dev, "%s: failed to get mux-control %s(%i)\n", np->full_name, mux_name ?: "", index); @@ -482,9 +492,35 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) get_device(&mux_chip->dev); return &mux_chip->mux[controller]; } + +/** + * mux_control_get() - Get the mux-control for a device. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control *mux_control_get(struct device *dev, const char *mux_name) +{ + return __mux_control_get(dev, mux_name, false); +} EXPORT_SYMBOL_GPL(mux_control_get); /** + * mux_control_get_optional() - Get the optional mux-control for a device. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +mux_control_get_optional(struct device *dev, const char *mux_name) +{ + return __mux_control_get(dev, mux_name, true); +} +EXPORT_SYMBOL_GPL(mux_control_get_optional); + +/** * mux_control_put() - Put away the mux-control for good. * @mux: The mux-control to put away. * @@ -492,7 +528,8 @@ EXPORT_SYMBOL_GPL(mux_control_get); */ void mux_control_put(struct mux_control *mux) { - put_device(&mux->chip->dev); + if (mux) + put_device(&mux->chip->dev); } EXPORT_SYMBOL_GPL(mux_control_put); @@ -503,16 +540,8 @@ static void devm_mux_control_release(struct device *dev, void *res) mux_control_put(mux); } -/** - * devm_mux_control_get() - Get the mux-control for a device, with resource - * management. - * @dev: The device that needs a mux-control. - * @mux_name: The name identifying the mux-control. - * - * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. - */ -struct mux_control *devm_mux_control_get(struct device *dev, - const char *mux_name) +static struct mux_control * +__devm_mux_control_get(struct device *dev, const char *mux_name, bool optional) { struct mux_control **ptr, *mux; @@ -520,7 +549,7 @@ struct mux_control *devm_mux_control_get(struct device *dev, if (!ptr) return ERR_PTR(-ENOMEM); - mux = mux_control_get(dev, mux_name); + mux = __mux_control_get(dev, mux_name, optional); if (IS_ERR(mux)) { devres_free(ptr); return mux; @@ -531,8 +560,37 @@ struct mux_control *devm_mux_control_get(struct device *dev, return mux; } + +/** + * devm_mux_control_get() - Get the mux-control for a device, with resource + * management. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +devm_mux_control_get(struct device *dev, const char *mux_name) +{ + return __devm_mux_control_get(dev, mux_name, false); +} EXPORT_SYMBOL_GPL(devm_mux_control_get); +/** + * devm_mux_control_get_optional() - Get the optional mux-control for a device, + * with resource management. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +devm_mux_control_get_optional(struct device *dev, const char *mux_name) +{ + return __devm_mux_control_get(dev, mux_name, true); +} +EXPORT_SYMBOL_GPL(devm_mux_control_get_optional); + /* * Using subsys_initcall instead of module_init here to try to ensure - for * the non-modular case - that the subsystem is initialized when mux consumers diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h index 5577e1b773c4..5e2aa046f032 100644 --- a/include/linux/mux/consumer.h +++ b/include/linux/mux/consumer.h @@ -24,9 +24,13 @@ int __must_check mux_control_try_select(struct mux_control *mux, int mux_control_deselect(struct mux_control *mux); struct mux_control *mux_control_get(struct device *dev, const char *mux_name); +struct mux_control *mux_control_get_optional(struct device *dev, + const char *mux_name); void mux_control_put(struct mux_control *mux); struct mux_control *devm_mux_control_get(struct device *dev, const char *mux_name); +struct mux_control *devm_mux_control_get_optional(struct device *dev, + const char *mux_name); #endif /* _LINUX_MUX_CONSUMER_H */ From patchwork Fri Jul 14 21:40:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 107826 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1445171qge; Fri, 14 Jul 2017 14:40:19 -0700 (PDT) X-Received: by 10.98.68.156 with SMTP id m28mr7388288pfi.159.1500068419214; Fri, 14 Jul 2017 14:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500068419; cv=none; d=google.com; s=arc-20160816; b=ISqM9NUnxgqIF5geG8cOhrRfevNeZoxmmJam0o2zJ7r4/ezFAqW4aC8mO1WQqiSONj gNK2a9yIwvpjE5F71/3Cjp7eatvp4/tqFN4JQQz+R8qusOs/JGH5hfmaxM3RhpxTdf3k OBwDO1JJlhOhCoI6mUcmI0kLzJW3NHJ3GvpOkeezrbFgIo0hLZo1Iq+i1EvQWa0ESiEB v46LtT1eIV8hfdqkly/fuMiCj1S9NdVnL3/E3WFPIpfp8yJ2rdnOAL+QEZ9ivBYFHLU5 eNBYmSZ7I6GH/UVxG1dw/R7ErNfJZC3RMUprEAuwGBaCQqHLtyH7+LvG4Q6Ddg52MIvl 2vNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=ARatMsu+0bsTPmU2qvrJ7nUsoM41XUDrO28c0fVxQRPnZeNteysiG7MimUDErJI78Z jkwrGahnthN//4hLPRTlqduMz0KQhluDgYWJHePxOtTBYJCe2Tir3rL5IS2+BZqPCeT0 Ikbjgx6auH1kjyXC1yYQYjqp9nhaqR6SB5dEX3xlXM79JkAvlUaHhZAGP1c/Kkl3l017 85+SaQU23b/RzmAthY9r3zYYfCcCMD1C4TXHaK4mjwk/3hX8571eNchUCtWLBuYoEBex tHmUPcJxG9FNeI7/F5p6OYBGVoxHRLQu+0RlS0bbohqwkV4oHf5klspBgyM5BAo5x5Oz XxBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=csXU6IjH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si7654193plj.365.2017.07.14.14.40.18; Fri, 14 Jul 2017 14:40:19 -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; dkim=pass header.i=@linaro.org header.b=csXU6IjH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdGNVkP (ORCPT + 25 others); Fri, 14 Jul 2017 17:40:15 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:35270 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751146AbdGNVkK (ORCPT ); Fri, 14 Jul 2017 17:40:10 -0400 Received: by mail-pf0-f171.google.com with SMTP id c73so51009912pfk.2 for ; Fri, 14 Jul 2017 14:40:10 -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=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=csXU6IjHGCHSQoy6SwCsFWvqi/F2yCbXDs4q4U25AsvtGM0M+/vZgiWOP0RB3PIuHH qOBcemNTb3H/PB6/bLcXUzTGr5jdCS7VUZsRL5QBXtgZUhbKDyNK8CKeVV/hDfMXYj/Z KhJamwh+6/PMkAWmmGlmCOxNqhBZuczdBjG/8= 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=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=LicSDjHH6QllOc55vCR6YIb5znsNX5ZbRZqOMMlY0YsyZC4xGMXkYGIJDx+0k/+P4j NTe+lvEU7HQRV8V1b4G3soAL/yB9J41n0lmNUfYLYw1TjEmk5jYX3v7soqVhdBmdRK7i hetHS+Xm2+5ECtP6R3mTsRKZXyJq4n5k5KiqMELuMsshZ8yme5xBuY7KHoBv/6pfaIHP eJmzgspkDy359CY7HtvMRDNCDVzM5T1vXo7LwKjDk+k3w12g+PsnT2DtA3w/X06yIDVx PnoXiN7ccqDv2SYeAMWTNY2bPTj4R4mPR1nF4GAN5aXefofXuS8+vh31PBAR0mrAz9O4 IJUw== X-Gm-Message-State: AIVw1122KSBLnxJKWdyto/Nc7AARK9Gs8hqplGDZosyPmUWPoSMMSem/ 2c4ZrtamyY6InXq+ X-Received: by 10.98.220.218 with SMTP id c87mr7359244pfl.73.1500068410240; Fri, 14 Jul 2017 14:40:10 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e13sm17795271pfh.96.2017.07.14.14.40.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:40:09 -0700 (PDT) From: Stephen Boyd To: Peter Chen Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.infradead.org, Rob Herring , Rob Clark , Andy Gross , Peter Rosin , Peter Chen , Greg Kroah-Hartman , devicetree@vger.kernel.org Subject: [PATCH v2 2/3] usb: chipidea: Hook into mux framework to toggle usb switch Date: Fri, 14 Jul 2017 14:40:04 -0700 Message-Id: <20170714214005.14967-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170714214005.14967-1-stephen.boyd@linaro.org> References: <20170714214005.14967-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the db410c 96boards platform we have a TC7USB40MU on the board to mux the D+/D- lines coming from the controller between a micro usb "device" port and a USB hub for "host" roles[1]. During a role switch, we need to toggle this mux to forward the D+/D- lines to either the port or the hub. Add the necessary code to do the role switch in chipidea core via the generic mux framework. Board configurations like on db410c are expected to change roles via the sysfs API described in Documentation/ABI/testing/sysfs-platform-chipidea-usb2. [1] https://github.com/96boards/documentation/raw/master/ConsumerEdition/DragonBoard-410c/HardwareDocs/Schematics_DragonBoard.pdf Cc: Peter Rosin Cc: Peter Chen Cc: Greg Kroah-Hartman Cc: Signed-off-by: Stephen Boyd --- Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 6 ++++++ drivers/usb/chipidea/Kconfig | 1 + drivers/usb/chipidea/core.c | 5 +++++ drivers/usb/chipidea/host.c | 7 +++++++ drivers/usb/chipidea/udc.c | 13 ++++++++++++- include/linux/usb/chipidea.h | 2 ++ 6 files changed, 33 insertions(+), 1 deletion(-) -- 2.10.0.297.gf6727b0 diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 0e03344e2e8b..2e9318151df7 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -76,6 +76,10 @@ Optional properties: needs to make sure it does not send more than 90% maximum_periodic_data_per_frame. The use case is multiple transactions, but less frame rate. +- mux-controls: The mux control for toggling host/device output of this + controller. It's expected that a mux state of 0 indicates device mode and a + mux state of 1 indicates host mode. +- mux-control-names: Shall be "usb_switch" if mux-controls is specified. i.mx specific properties - fsl,usbmisc: phandler of non-core register device, with one @@ -102,4 +106,6 @@ Example: rx-burst-size-dword = <0x10>; extcon = <0>, <&usb_id>; phy-clkgate-delay-us = <400>; + mux-controls = <&usb_switch>; + mux-control-names = "usb_switch"; }; diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 51f4157bbecf..3798e0e69d57 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -3,6 +3,7 @@ config USB_CHIPIDEA depends on ((USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)) && HAS_DMA select EXTCON select RESET_CONTROLLER + select MULTIPLEXER help Say Y here if your system has a dual role high speed USB controller based on ChipIdea silicon IP. It supports: diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index b17ed3a9a304..d088c262ebb8 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -64,6 +64,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -690,6 +691,10 @@ static int ci_get_platdata(struct device *dev, if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL)) platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA; + platdata->usb_switch = devm_mux_control_get_optional(dev, "usb_switch"); + if (IS_ERR(platdata->usb_switch)) + return PTR_ERR(platdata->usb_switch); + ext_id = ERR_PTR(-ENODEV); ext_vbus = ERR_PTR(-ENODEV); if (of_property_read_bool(dev->of_node, "extcon")) { diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 18cb8e46262d..9ef3ecf27ad3 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "../host/ehci.h" @@ -175,6 +176,10 @@ static int host_start(struct ci_hdrc *ci) if (ci_otg_is_fsm_mode(ci)) { otg->host = &hcd->self; hcd->self.otg_port = 1; + } else { + ret = mux_control_select(ci->platdata->usb_switch, 1); + if (ret) + goto disable_reg; } } @@ -195,6 +200,8 @@ static void host_stop(struct ci_hdrc *ci) struct usb_hcd *hcd = ci->hcd; if (hcd) { + if (!ci_otg_is_fsm_mode(ci)) + mux_control_deselect(ci->platdata->usb_switch); if (ci->platdata->notify_event) ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_STOPPED_EVENT); diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index d68b125796f9..deb18099e168 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -1964,16 +1965,26 @@ void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) static int udc_id_switch_for_device(struct ci_hdrc *ci) { + int ret = 0; + if (ci->is_otg) /* Clear and enable BSV irq */ hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE); - return 0; + if (!ci_otg_is_fsm_mode(ci)) + ret = mux_control_select(ci->platdata->usb_switch, 0); + + if (ci->is_otg && ret) + hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); + + return ret; } static void udc_id_switch_for_host(struct ci_hdrc *ci) { + mux_control_deselect(ci->platdata->usb_switch); + /* * host doesn't care B_SESSION_VALID event * so clear and disbale BSV irq diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index c5fdfcf99828..3b27e333de1d 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -9,6 +9,7 @@ #include struct ci_hdrc; +struct mux_control; /** * struct ci_hdrc_cable - structure for external connector cable state tracking @@ -74,6 +75,7 @@ struct ci_hdrc_platform_data { /* VBUS and ID signal state tracking, using extcon framework */ struct ci_hdrc_cable vbus_extcon; struct ci_hdrc_cable id_extcon; + struct mux_control *usb_switch; u32 phy_clkgate_delay_us; }; From patchwork Fri Jul 14 21:40:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 107827 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1445195qge; Fri, 14 Jul 2017 14:40:21 -0700 (PDT) X-Received: by 10.98.94.5 with SMTP id s5mr7387576pfb.138.1500068421100; Fri, 14 Jul 2017 14:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500068421; cv=none; d=google.com; s=arc-20160816; b=YcFB0yOt9OksngyPBdX3qS3xHN8HF37+tzAGpEvTmjjPdGIHKPOmD9qayBXbgWy+B0 cFOh/Kd/Brq+Aj8f8IaVOXtJyhyEMdjT+RV4CQl1sDZ2HXMJ/LmSWzk6H1fp7Ac0yfgp v7b0h0t8irifwwkLpMYmoKGO/5TpMDV9v3V10YnYp70SdPrjeVZStv2Yik2EhFB0lgSK BYcCrrup452x5c+BgJFDgeh2n4X/texhk6KsGBvsAFQ94w6fjW54ZtYEjtkqZ616a6Kx nYNwwiF1lGbwe7Q1nlbIrJCCu+lKGpOl+dcv18CMzV5Zv/w7b1XCl1dVtY1cFMC2JnHP 4ABQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=G2tRaYqAPwpFciGzMfhXjur1S7x1qFLHJtLRM/9X2gs=; b=cJdlfU0ys3elgC2THQGmtd5j63IMAqasaa5IUQ2mgCw24dGN1VKOj/mr3r/1JHtbwi IWYp7auYk9WScrOjGUPeOJ6FyvtJ2K7xqriBJktp19eJABKvH4j6bBXdKQGxawkEUIyh Am7ZVK1TSMkTNTAv95Aw6ivPtlYquTSLYBw2Ldx/HoUfJiDlA5bH8JHJTGSpG39QHdxs LRgQ6u0TB4nk7SXCIxZGU1MF7ZJBffxRX47aegV7gQnlIwcprjonLkt/TTB8NbVUiGMt C5feq6PZlwLbpVrQBovdVDKzKf6bsubKC0pkNAwIQIs/GCCYzog9IPCvuk44Q5YZ2cEe YKEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=PwY6iGq4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si7694566plb.102.2017.07.14.14.40.20; Fri, 14 Jul 2017 14:40:21 -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; dkim=pass header.i=@linaro.org header.b=PwY6iGq4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751223AbdGNVkR (ORCPT + 25 others); Fri, 14 Jul 2017 17:40:17 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35758 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751069AbdGNVkL (ORCPT ); Fri, 14 Jul 2017 17:40:11 -0400 Received: by mail-pg0-f51.google.com with SMTP id j186so51130258pge.2 for ; Fri, 14 Jul 2017 14:40:11 -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=G2tRaYqAPwpFciGzMfhXjur1S7x1qFLHJtLRM/9X2gs=; b=PwY6iGq4t08PPMc8JIlAEnsESEKIhcygTx/WImbsB2H6z4LHUAD6TAVsNQwz9gYIzs U/QHpJmGrmww6xUxQh7EQum/IFN8tdbq7mjwqEzCdihyK56v0FckHcPuuNQFb+tL8lfM Z9v3nNwIRjffeuZAFrzeJjhIUGll5PFJMtMV4= 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=G2tRaYqAPwpFciGzMfhXjur1S7x1qFLHJtLRM/9X2gs=; b=dwS2BH6rkUv+YQgplW/gj6RllEeBmfy6JSYULgIIp+1hUD0cS0BSFEsrZn7PeLkuYk /x5qFbRy/AmrOJyHJAORf3S1Mc02yB5Z4PKLMMLUkOdF7tvtd2mzcvB940+BXC3audBA mxaFJKmBgqIBsB+pFCL9ABfgICY+u5UCHFdnu+FbBVbKLD9RjOcayiaIhDvr/yh/gxkH HLn4sYzm0vXEj0Xi0ytK3vOHKEusc2bwBt/K0vYrYazAY7+0Z5J2y3ARhg4HEtW2RzrD wFZqrlY4MGkRyCEGfxRvQAcfnMhHkeCR415Worgh2ZBp6fYpbxBbS6L7mfvfhnVy+LZL afyg== X-Gm-Message-State: AIVw111lrOZ8JmLFGEkqrf52xM6CGhZNC01U4N4tJ/64ypnO3f2FBiye VLs2BRoYqlVEehC6 X-Received: by 10.84.193.101 with SMTP id e92mr17839013pld.209.1500068411410; Fri, 14 Jul 2017 14:40:11 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e13sm17795271pfh.96.2017.07.14.14.40.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:40:10 -0700 (PDT) From: Stephen Boyd To: Andy Gross Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.infradead.org, Rob Herring , Rob Clark , Peter Chen Subject: [PATCH v2 3/3] arm64: dts: qcom: Collapse usb support into one node Date: Fri, 14 Jul 2017 14:40:05 -0700 Message-Id: <20170714214005.14967-4-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170714214005.14967-1-stephen.boyd@linaro.org> References: <20170714214005.14967-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We currently have three device nodes for the same USB hardware block, as evident by the reuse of the same reg address multiple times. Now that the chipidea driver fully supports OTG with the MSM wrapper we can collapse all these nodes into one USB device node, reflecting the true nature of the hardware. Signed-off-by: Stephen Boyd --- arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi | 38 ++++++++++--------- arch/arm64/boot/dts/qcom/msm8916.dtsi | 62 +++++++++++++++---------------- 2 files changed, 50 insertions(+), 50 deletions(-) -- 2.10.0.297.gf6727b0 diff --git a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi index f326f4fb4d72..494560a1a6ef 100644 --- a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi +++ b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi @@ -213,24 +213,20 @@ }; usb@78d9000 { - extcon = <&usb_id>, <&usb_id>; + extcon = <&usb_id>; status = "okay"; - }; - - ehci@78d9000 { - status = "okay"; - }; - - phy@78d9000 { - v1p8-supply = <&pm8916_l7>; - v3p3-supply = <&pm8916_l13>; - vddcx-supply = <&pm8916_s1>; - extcon = <&usb_id>, <&usb_id>; - dr_mode = "otg"; - status = "okay"; - switch-gpio = <&pm8916_gpios 4 GPIO_ACTIVE_HIGH>; - pinctrl-names = "default"; - pinctrl-0 = <&usb_sw_sel_pm>; + adp-disable; + hnp-disable; + srp-disable; + mux-controls = <&usb_switch>; + mux-control-names = "usb_switch"; + + ulpi { + phy { + v1p8-supply = <&pm8916_l7>; + v3p3-supply = <&pm8916_l13>; + }; + }; }; lpass@07708000 { @@ -348,6 +344,14 @@ pinctrl-0 = <&usb_id_default>; }; + usb_switch: usb-switch { + compatible = "gpio-mux"; + mux-gpios = <&pm8916_gpios 4 GPIO_ACTIVE_HIGH>; + #mux-control-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&usb_sw_sel_pm>; + }; + hdmi-out { compatible = "hdmi-connector"; type = "a"; diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi index 17691abea608..039991f80831 100644 --- a/arch/arm64/boot/dts/qcom/msm8916.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi @@ -546,44 +546,40 @@ status = "disabled"; }; - usb_dev: usb@78d9000 { + otg: usb@78d9000 { compatible = "qcom,ci-hdrc"; - reg = <0x78d9000 0x400>; - dr_mode = "peripheral"; - interrupts = ; - usb-phy = <&usb_otg>; - status = "disabled"; - }; - - usb_host: ehci@78d9000 { - compatible = "qcom,ehci-host"; - reg = <0x78d9000 0x400>; - interrupts = ; - usb-phy = <&usb_otg>; - status = "disabled"; - }; - - usb_otg: phy@78d9000 { - compatible = "qcom,usb-otg-snps"; - reg = <0x78d9000 0x400>; + reg = <0x78d9000 0x200>, + <0x78d9200 0x200>; interrupts = , ; - - qcom,vdd-levels = <500000 1000000 1320000>; - qcom,phy-init-sequence = <0x44 0x6B 0x24 0x13>; - dr_mode = "peripheral"; - qcom,otg-control = <2>; // PMIC - qcom,manual-pullup; - clocks = <&gcc GCC_USB_HS_AHB_CLK>, - <&gcc GCC_USB_HS_SYSTEM_CLK>, - <&gcc GCC_USB2A_PHY_SLEEP_CLK>; - clock-names = "iface", "core", "sleep"; - - resets = <&gcc GCC_USB2A_PHY_BCR>, - <&gcc GCC_USB_HS_BCR>; - reset-names = "phy", "link"; + <&gcc GCC_USB_HS_SYSTEM_CLK>; + clock-names = "iface", "core"; + assigned-clocks = <&gcc GCC_USB_HS_SYSTEM_CLK>; + assigned-clock-rates = <80000000>; + resets = <&gcc GCC_USB_HS_BCR>; + reset-names = "core"; + phy_type = "ulpi"; + dr_mode = "otg"; + ahb-burst-config = <0>; + phy-names = "usb-phy"; + phys = <&usb_hs_phy>; status = "disabled"; + #reset-cells = <1>; + + ulpi { + usb_hs_phy: phy { + compatible = "qcom,usb-hs-phy-msm8916", + "qcom,usb-hs-phy"; + #phy-cells = <0>; + clocks = <&xo_board>, <&gcc GCC_USB2A_PHY_SLEEP_CLK>; + clock-names = "ref", "sleep"; + resets = <&gcc GCC_USB2A_PHY_BCR>, <&otg 0>; + reset-names = "phy", "por"; + qcom,init-seq = /bits/ 8 <0x0 0x44 + 0x1 0x6b 0x2 0x24 0x3 0x13>; + }; + }; }; intc: interrupt-controller@b000000 {