From patchwork Sun Jun 26 07:28:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 70875 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp556019qgy; Sun, 26 Jun 2016 00:33:59 -0700 (PDT) X-Received: by 10.66.89.34 with SMTP id bl2mr23040299pab.80.1466926439886; Sun, 26 Jun 2016 00:33:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l189si18108519pfl.125.2016.06.26.00.33.59; Sun, 26 Jun 2016 00:33:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138AbcFZHd6 (ORCPT + 8 others); Sun, 26 Jun 2016 03:33:58 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:35630 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752020AbcFZH3D (ORCPT ); Sun, 26 Jun 2016 03:29:03 -0400 Received: by mail-pf0-f179.google.com with SMTP id c2so51927128pfa.2 for ; Sun, 26 Jun 2016 00:29:01 -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=9VWtiXgtnUzorquMBXleONJCDu21WWsPBlOQZ74S8Qc=; b=URjbnNAJf2eITJsTCJ70QL2P40L4r14D592xGKyU5vjhiAnuRaaZY+DYnPbTzIQzkZ pYDTuNQB/d/ppp15g5bjIDWsT2JCgDGPVkL09hXfyh8qgxWigJMput7VznJsQ9dubNzp PuE78ogexjA9zPnpMvNNEqWaRP9XoInLFeanU= 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=9VWtiXgtnUzorquMBXleONJCDu21WWsPBlOQZ74S8Qc=; b=fCR2oMHzSwhE3xA6M7sF9bfx2iWE9ZFOCdmDJVxHHsGrZrFw0pEOj8WQKBpAeFejne W5+fsM64WYdJZhw2K+6TegXnWpXvUX2MCvqKIFVmhBpHyTEgFK4BFIH3zvdW1vaKqeQG nW6V8njPBhhv/6WrMiIUpRmezsdUFW9RtvA9IB/c3JDAZG6/kcSYT4exMqIB5c+PePqf uAtMnkimdLlTEHO6nYmrd8JmRrU9AGkoR5vY/S13UYVkmOVxygxDQ3PQPIM7lIFBaylH b4P3YZLzrCeEqLFfLEFRTzfXODdhLSXba/A33kteXU7QFStzP0MtDgcdmax0XTClVseM 7KGw== X-Gm-Message-State: ALyK8tJhZQ+EMa5TvZm7W8PFCeCmmZwScyVYFillnuXj+6ORGDnjZGsmMBGCUhPqaXxLKIMS X-Received: by 10.98.26.148 with SMTP id a142mr22100048pfa.46.1466926141236; Sun, 26 Jun 2016 00:29:01 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id f138sm3790495pfa.17.2016.06.26.00.28.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Jun 2016 00:29:00 -0700 (PDT) From: Stephen Boyd To: linux-usb@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Andy Gross , Bjorn Andersson , Neil Armstrong , Arnd Bergmann , Felipe Balbi , Peter Chen , Greg Kroah-Hartman Subject: [PATCH 15/21] usb: chipidea: msm: Mux over secondary phy at the right time Date: Sun, 26 Jun 2016 00:28:32 -0700 Message-Id: <20160626072838.28082-16-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0.rc2.8.ga28705d In-Reply-To: <20160626072838.28082-1-stephen.boyd@linaro.org> References: <20160626072838.28082-1-stephen.boyd@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org We need to pick the correct phy at runtime based on how the SoC has been wired onto the board. If the secondary phy is used, take it out of reset and mux over to it by writing into the TCSR register. Make sure to do this on reset too, because this register is reset to the default value (primary phy) after the RESET bit is set in USBCMD. Cc: Peter Chen Cc: Greg Kroah-Hartman Signed-off-by: Stephen Boyd --- drivers/usb/chipidea/ci_hdrc_msm.c | 78 +++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) -- 2.9.0.rc2.8.ga28705d -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index 40249b0e3e93..df0f8b31db4f 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c @@ -8,30 +8,40 @@ #include #include #include -#include #include #include #include +#include +#include +#include #include "ci.h" #define HS_PHY_AHB_MODE 0x0098 +#define HS_PHY_SEC_CTRL 0x0278 +# define HS_PHY_DIG_CLAMP_N BIT(16) struct ci_hdrc_msm { struct platform_device *ci; struct clk *core_clk; struct clk *iface_clk; + bool secondary_phy; + void __iomem *base; }; static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) { - struct device *dev = ci->gadget.dev.parent; + struct device *dev = ci->dev->parent; + struct ci_hdrc_msm *msm_ci = dev_get_drvdata(dev); switch (event) { case CI_HDRC_CONTROLLER_RESET_EVENT: dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); /* use AHB transactor, allow posted data writes */ hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8); + if (msm_ci->secondary_phy) + hw_write_id_reg(ci, HS_PHY_SEC_CTRL, HS_PHY_DIG_CLAMP_N, + HS_PHY_DIG_CLAMP_N); break; default: dev_dbg(dev, "unknown ci_hdrc event\n"); @@ -49,12 +59,58 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { .notify_event = ci_hdrc_msm_notify_event, }; +static int ci_hdrc_msm_mux_phy(struct ci_hdrc_msm *ci, + struct platform_device *pdev) +{ + struct regmap *regmap; + struct device_node *syscon; + struct device *dev = &pdev->dev; + u32 off, val; + int ret; + + syscon = of_parse_phandle(dev->of_node, "phy-select", 0); + if (!syscon) + return 0; + + regmap = syscon_node_to_regmap(syscon); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + ret = of_property_read_u32_index(dev->of_node, "phy-select", 1, &off); + if (ret < 0) { + dev_err(dev, "no offset in syscon\n"); + return -EINVAL; + } + + ret = of_property_read_u32_index(dev->of_node, "phy-select", 2, &val); + if (ret < 0) { + dev_err(dev, "no value in syscon\n"); + return -EINVAL; + } + + ret = regmap_write(regmap, off, val); + if (ret) + return ret; + + ci->secondary_phy = !!val; + if (ci->secondary_phy) { + val = readl_relaxed(ci->base + HS_PHY_SEC_CTRL); + val |= HS_PHY_DIG_CLAMP_N; + writel_relaxed(val, ci->base + HS_PHY_SEC_CTRL); + } + + return 0; +} + static int ci_hdrc_msm_probe(struct platform_device *pdev) { struct ci_hdrc_msm *ci; struct platform_device *plat_ci; struct clk *clk; struct reset_control *reset; + struct resource *res; + void __iomem *base; + resource_size_t size; int ret; dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); @@ -76,6 +132,15 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) if (IS_ERR(clk)) return PTR_ERR(clk); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + size = resource_size(res); + ci->base = base = devm_ioremap(&pdev->dev, res->start, size); + if (!base) + return -ENOMEM; + reset_control_assert(reset); usleep_range(10000, 12000); reset_control_deassert(reset); @@ -88,9 +153,12 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev) if (ret) goto err_iface; - plat_ci = ci_hdrc_add_device(&pdev->dev, - pdev->resource, pdev->num_resources, - &ci_hdrc_msm_platdata); + ret = ci_hdrc_msm_mux_phy(ci, pdev); + if (ret) + goto err_mux; + + plat_ci = ci_hdrc_add_device(&pdev->dev, pdev->resource, + pdev->num_resources, &ci_hdrc_msm_platdata); if (IS_ERR(plat_ci)) { dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); ret = PTR_ERR(plat_ci);