From patchwork Tue Aug 21 13:55:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 144727 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5306598ljj; Tue, 21 Aug 2018 06:56:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwNaWIkq49ELFLh8XQjix4qsIX2wCWHCCFtE3Iz1KHhXQOEAR5ARVQyeW01hqwVfbyOyuR5 X-Received: by 2002:a63:447:: with SMTP id 68-v6mr13728922pge.409.1534859761451; Tue, 21 Aug 2018 06:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534859761; cv=none; d=google.com; s=arc-20160816; b=jmnVj2RC5gnnyeOmVn9/8kl8Q85Skoc3RevITZV496PwtK/PieRmUjc7MetuLdzE6y 2IxFXNMscoaLxR5mpNFKPDV2wqhziw39m5KPWl24PO9ToZrs3g8qtR9c0rbMYx43AQ1I ezQljyfn52o7nXkraDJ5XD+8EvrCvdheKdSJpLyEHLjJRzmkYGil7GlOXIqY6QF/Coo+ cwqmIP88PK5q3zAiEaPb96LDuz+uPpOXwfyfABpWTzuqqeJGomLthOGjCf5LFwIgPZVV sLwCShq7LfwJ06bEJT6ly05MwarcDr9aNd/3tkjGx5u2qZFR6Krfmhp1XGcTCOW+GnMe dUuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Aliud5qkHWFHnlXE71yeRM0s4uv6gb9kNd4H2LghQsg=; b=TF+i1K/rXsH426fSVoM6UuE6QOz2lmYpwEbZIrUT+41H6pUJO/kJrzZkcIedMq3Acy VaRg+WXSKRCsBFfWW45sx1Klvlm3ftkQjhtc9KLIGazQdG0rYPJhI0zcyUt3avmmnQhB 7ZOW1F1JYeNdNYZO65aSyufCKTQs5K2/jUukI6CgGWhekXHvNqy0rQjOXAm0Y2sn1bxJ u9py8gPiIqcfUbJK02+0ckSU6dWdCYjNS04zwgIFs3STzKbkQ48g88OvKKHqNMhAIg2y UGc9zb4BH8T5ynXZ8m0ffUZh2IKtgeGRiV01l7hyL1CWEajtQH/EAEHxALeM0FnugVr5 uD2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K3NxjPX4; 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=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 x11-v6si12072078plv.360.2018.08.21.06.56.01; Tue, 21 Aug 2018 06:56:01 -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=pass header.i=@linaro.org header.s=google header.b=K3NxjPX4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbeHURQP (ORCPT + 13 others); Tue, 21 Aug 2018 13:16:15 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:53505 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbeHURQO (ORCPT ); Tue, 21 Aug 2018 13:16:14 -0400 Received: by mail-wm0-f65.google.com with SMTP id s9-v6so3027704wmh.3 for ; Tue, 21 Aug 2018 06:55:59 -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; bh=Aliud5qkHWFHnlXE71yeRM0s4uv6gb9kNd4H2LghQsg=; b=K3NxjPX4qL/IBVbLG+eL6gRx0we5J1WNGI8iFC4Udt40SLsXQCT+ecix5mS3YAhuqF 3QjyYdlTEctf6KkuWHY9F5pChHcIfWuJPI/Bkbmwc/1XhvZZBu2vvLmtYtufBOlRgSmI Xya1UmA5JWcJOklvf1l2CpLbMpWNYaVEQAb+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; bh=Aliud5qkHWFHnlXE71yeRM0s4uv6gb9kNd4H2LghQsg=; b=h5Mb9qD8l2BsLFFoRq8RdAq2ysO+gFt0ZYNPGXzJcXnZVhJSEPv9kA+pOz6Tict4jg uWare5bF9EVvOw5qNQABtfhoBIe4Ka/gye2RJzRR34aMtHAiADbE9SYuU/e6KFA/HGLw CSiX6w+lfnA3VPt112xCkfvain+Ad0phKNABSF+bzGCC6K4eYF29IEAxJtcmuBHY0fza nnvv+UB8QugTsuzGv5qRtGkm7WtUP68TA8lwnVHxgyCxHKQEFifUhYx12NeTxClbjvm1 egCFptVKK+EAKipEo476PUZeq+Dq4Jt/vsWeUGRnj30XefHzzI+GT/l95TJHL+4ig+oR /vVQ== X-Gm-Message-State: APzg51CdXsxA4d/u1GOOn5WOZvCk5UQVtkHqzNsbti+OdNWQKu0+iCNz b3YUUaScnL8kBI4t/P1p2wB/EQ== X-Received: by 2002:a1c:ea9d:: with SMTP id g29-v6mr2270169wmi.152.1534859758613; Tue, 21 Aug 2018 06:55:58 -0700 (PDT) Received: from lpoulain-ThinkPad-T470p.home (AToulouse-655-1-762-165.w109-220.abo.wanadoo.fr. [109.220.142.165]) by smtp.gmail.com with ESMTPSA id l24-v6sm16728523wrb.65.2018.08.21.06.55.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Aug 2018 06:55:57 -0700 (PDT) From: Loic Poulain To: Peter.Chen@nxp.com Cc: linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org, david.brown@linaro.org, robh+dt@kernel.org, bjorn.andersson@linaro.org, andy.gross@linaro.org, Loic Poulain Subject: [PATCH 1/6] usb: chipidea: Add dynamic pinctrl selection Date: Tue, 21 Aug 2018 15:55:51 +0200 Message-Id: <1534859756-6955-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Some hardware implementations require to configure pins differently according to the USB role (host/device), this can be an update of the pins routing or a simple GPIO value change. This patch introduces new optional "host" and "device" pinctrls. If these pinctrls are defined by the device, they are respectively selected on host/device role start. If a default pinctrl exist, it is restored on host/device role stop. Signed-off-by: Loic Poulain --- drivers/usb/chipidea/core.c | 19 +++++++++++++++++++ drivers/usb/chipidea/host.c | 9 +++++++++ drivers/usb/chipidea/udc.c | 9 +++++++++ include/linux/usb/chipidea.h | 6 ++++++ 4 files changed, 43 insertions(+) -- 2.7.4 diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 85fc6db..03e52fc 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -723,6 +724,24 @@ static int ci_get_platdata(struct device *dev, else cable->connected = false; } + + platdata->pctl = devm_pinctrl_get(dev); + if (!IS_ERR(platdata->pctl)) { + struct pinctrl_state *p; + + p = pinctrl_lookup_state(platdata->pctl, "default"); + if (!IS_ERR(p)) + platdata->pins_default = p; + + p = pinctrl_lookup_state(platdata->pctl, "host"); + if (!IS_ERR(p)) + platdata->pins_host = p; + + p = pinctrl_lookup_state(platdata->pctl, "device"); + if (!IS_ERR(p)) + platdata->pins_device = p; + } + return 0; } diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index af45aa32..55dbd49 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "../host/ehci.h" @@ -150,6 +151,10 @@ static int host_start(struct ci_hdrc *ci) } } + if (ci->platdata->pins_host) + pinctrl_select_state(ci->platdata->pctl, + ci->platdata->pins_host); + ret = usb_add_hcd(hcd, 0, 0); if (ret) { goto disable_reg; @@ -194,6 +199,10 @@ static void host_stop(struct ci_hdrc *ci) } ci->hcd = NULL; ci->otg.host = NULL; + + if (ci->platdata->pins_host && ci->platdata->pins_default) + pinctrl_select_state(ci->platdata->pctl, + ci->platdata->pins_default); } diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 9852ec5..c04384e 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -1965,6 +1966,10 @@ void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) static int udc_id_switch_for_device(struct ci_hdrc *ci) { + if (ci->platdata->pins_device) + pinctrl_select_state(ci->platdata->pctl, + ci->platdata->pins_device); + if (ci->is_otg) /* Clear and enable BSV irq */ hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, @@ -1983,6 +1988,10 @@ static void udc_id_switch_for_host(struct ci_hdrc *ci) hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); ci->vbus_active = 0; + + if (ci->platdata->pins_device && ci->platdata->pins_default) + pinctrl_select_state(ci->platdata->pctl, + ci->platdata->pins_default); } /** diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 07f9936..63758c3 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -77,6 +77,12 @@ struct ci_hdrc_platform_data { struct ci_hdrc_cable vbus_extcon; struct ci_hdrc_cable id_extcon; u32 phy_clkgate_delay_us; + + /* pins */ + struct pinctrl *pctl; + struct pinctrl_state *pins_default; + struct pinctrl_state *pins_host; + struct pinctrl_state *pins_device; }; /* Default offset of capability registers */