From patchwork Mon Aug 27 09:33:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 145162 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3975540ljw; Mon, 27 Aug 2018 02:33:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbnkNLfpbogIiDyCgK9xGbQOQPEQxVPXhBN6/mtKVZF5hXPMplw1H5Jte0QmseZoZ4EiyFB X-Received: by 2002:a62:4fd9:: with SMTP id f86-v6mr13699272pfj.110.1535362420712; Mon, 27 Aug 2018 02:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535362420; cv=none; d=google.com; s=arc-20160816; b=MhYdbTyaKwn1MRvSVAGyS/YS1a/LLFX2Vcq0FJiAc2usi1En2OwlpZI0TRzBksKOHI OKcgFTmXrEpfFuHH4puo3xvEcQ7MZB7ueMTrApeGt+W82yvCyrf50uDTVCk7/cTsOKBB FukWdsCms3e8RpzXuzDBbali+ILiQoQNZnoOohBJjx8WfUc21gcaNZueDtArFhffKVIA 10AY69rtpzl28yj+xH2i752Y6rv5ZeAuyVuPRlRprJQyl/lIon7LlThl3vLJ+ypgE3Z4 m3qTn4B/OMQn//1cGB66KOifanz1BZKomif/z6A3R7JCvITRvqUJPKg01K5oRDvYyNSC suGg== 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=7hwg7iwuKZ5uZKb4tYvRSPSR6S8BEdgvJekXN1LZzwU=; b=OZ6lRLMVDJ4U2N9DQyoAhBDJsEbFHnmQCFAcBiNlO5Ae+OTN1U/7SeXYBhKjlYUUDL VYhycj4bai1N33pLS6n2jOCq51qzqWm3hD2OzgNQjEIe21ia/XVoikA4OpYYoVMq3GJ4 8/NHGsBwJF59Xmfis/UPt8Ttq1AWpu/iwwlGDFb05SM1q1jrUKN52F11jAyOM+E7fVdu cxjKLCFM4y2LivDd4nRH0JX2hDLiFRWyYpZDsrQpxMCdm6zfd6/R8WzttUmLl5or96Xq tRC+sKtrKW7TT7ccB+MU5P1eqjbXlKlpul+/Nb3kSG3t28y5LPFs9lJ6EeNYpJ5bM6HP XPpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUmNnzQY; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-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 y1-v6si13854007pgf.146.2018.08.27.02.33.40; Mon, 27 Aug 2018 02:33:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-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=JUmNnzQY; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-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 S1726926AbeH0NTc (ORCPT + 5 others); Mon, 27 Aug 2018 09:19:32 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43222 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbeH0NTc (ORCPT ); Mon, 27 Aug 2018 09:19:32 -0400 Received: by mail-wr1-f66.google.com with SMTP id k5-v6so12961006wre.10 for ; Mon, 27 Aug 2018 02:33:38 -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=7hwg7iwuKZ5uZKb4tYvRSPSR6S8BEdgvJekXN1LZzwU=; b=JUmNnzQYtWiz+OXI7+9YhO+w5W+FvkLgS3LtVxAhDeU2smXne7xvSoABHWKmehZNY9 WL7elFaE2jGUsV3fB+q+tRdvqNJkty3BJHI3h5APRbTGm1bneVoWdo5/KAN1yuLaJuUR WwtV/wsl4qoJL+WBmHzjO6yd1l9k6S2o3mx8Y= 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=7hwg7iwuKZ5uZKb4tYvRSPSR6S8BEdgvJekXN1LZzwU=; b=rd5DD3WhL58mty5YfnuwiV2qLg0BryMxSxLOcP6Hg8JZEFeRjpvN20snf8Ctd0Lnlw okTZrn+RfZbNYQuiVkD975v9GWerfYBlVP0Kl7b/nAdp2O5k2uaS5t/2FfPHEkPz6mji AkeTlJxD+KkxMANevYKWV92XXrSN0ek63G8ipkRxMbV0j6P+SqA5aGzTCNL7BkiJDWBP EcHy0yrj+KqAzkeOhKjoyByUZpzzb1dWql2yjxWlagMSsjkXiM8m63PXPYyBSrMl8Q8o u5UP/xsHuwJP3PW6yocWJbJgCdb1xasjJ+r+zvBzqRjuBLfltFf96mnku2K0a7YQCs8Z H3Jg== X-Gm-Message-State: APzg51D6G0g/9DLGCztLu2fCbLLF4pb6CF5q9u+R7k9h35z2r/Sp/Y6U OQvuS6mitLzvEU8UGb0rWEj9pA== X-Received: by 2002:adf:9d1c:: with SMTP id k28-v6mr8539539wre.104.1535362417759; Mon, 27 Aug 2018 02:33:37 -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 y203-v6sm8022828wmd.1.2018.08.27.02.33.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Aug 2018 02:33:37 -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, andy.shevchenko@gmail.com, Loic Poulain Subject: [PATCH v2 1/7] usb: chipidea: Add dynamic pinctrl selection Date: Mon, 27 Aug 2018 11:33:29 +0200 Message-Id: <1535362415-16559-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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 --- v2: includes ordering 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 43ea5fb..cdac778 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -726,6 +727,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 18cb8e4..3729672 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" @@ -164,6 +165,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; @@ -208,6 +213,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 fe8a905..3f09a0d 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1964,6 +1965,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, @@ -1982,6 +1987,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 */