From patchwork Tue Sep 4 15:18:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 145931 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3791513ljw; Tue, 4 Sep 2018 08:19:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYRBcj++6AB+xrPMxVpFQ5Prozjz7y50/hDmZgptiGEa929t5MuernRwyAlE94Z8SgcRlMl X-Received: by 2002:a63:d443:: with SMTP id i3-v6mr30895181pgj.216.1536074349080; Tue, 04 Sep 2018 08:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536074349; cv=none; d=google.com; s=arc-20160816; b=kXl6Xqv/SUeTu3lWK6/yhlLCavGJF59JufvkVyFCleVl8P1fWakiVQhU89BQ5Sb6zE NW3+4VrCRtHrUndkA3ST6xVlZdJL3fzyUHBSfxcUQz0zy3kzOU8LAJir9oyilTtKa6QJ g3yTd+MlhE8du8SUU7ld/CQtAyq4tjKchOBAbllA0dNxkW177AEfJUfTJBY0DuRe4+WK ufoBzFbcen5DmBr8oicegVVVgKxo8DxM8pzIiLM99SYUHO18+QMitw2hzEBVPIEu5luy ycUAQuuUexsg5j29yBldeu06ca/pwarwSPDGdS/Z1S/br7EX8iIxlFp4+n67c458fheq uhxA== 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=BZCgv7ZnNziCVwocxEfa9B5JEWHWfgm+orGzJkzoN1U=; b=XZe10WejtltZ8/cfdDRgFGLew1jOMHZf82fyidR3DTj7JcwrzP9VzcGZJQTobP9RIy 8LixEEvhf0ZKxpiXJXN3FsOSJKxG50xmHNMIqnIGwKga/sKe/bxxJXzdw0Djx6+B3uFL JQd1CsZb91SvQW+9rr1QQxRuQpiv5qXqEJKnhlqMRIDrkVLOl9kFr7MXfjnXSnZLO/Tg ck+urdY6hvKBDjtxW/vzuaA4dswXtrniRu0RjFpesFjaWgRMnXAzKjzR+ZLWQqAJZEH2 Ewpjl3PGPn1CxWS6EMmqThzXsaTb+wfFyIhERLFzE9AcymtwDeprZXNYRshG/l6807GJ uB8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GuPutQlk; 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 n15-v6si23319017pgc.309.2018.09.04.08.19.08; Tue, 04 Sep 2018 08:19:09 -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=GuPutQlk; 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 S1726015AbeIDToi (ORCPT + 13 others); Tue, 4 Sep 2018 15:44:38 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:51510 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727388AbeIDToh (ORCPT ); Tue, 4 Sep 2018 15:44:37 -0400 Received: by mail-wm0-f44.google.com with SMTP id y2-v6so4872133wma.1 for ; Tue, 04 Sep 2018 08:19:04 -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=BZCgv7ZnNziCVwocxEfa9B5JEWHWfgm+orGzJkzoN1U=; b=GuPutQlk/s7bEGKqGuFigDaEuJwClH4ZX+lkyJHNAeRDhEUtsMnFUYPEzNFs2qxsr4 9Ai3XhCa4Ee7k/L052IR0vkhUXZNckDewQvoqMQk4sMKgAutoQdY5qYApebzx3+UDbZw /zM7yt4VgSOe6+dq9IQ7OnU+jZeGSV9BA6Alc= 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=BZCgv7ZnNziCVwocxEfa9B5JEWHWfgm+orGzJkzoN1U=; b=gwzNUasJCOI3H0WcMBxAVXQPDB4HVI6xPOWK1iXdRQDaN1IKfcXKkTn4XtNGoMuLJr XvVAG3R1saMLKlm29Rm3icDL4KCDeyhBLs6Y2J/EBYRd2kjUsT0aWpQeGZHhHsRw5w0s aGe/aq8ux8ZaVZBHwGLl/n9Akct+yB72UBC+LUtiPXkmdSzYL69Xm+ANJRZ4mDHrwyJS vNzxMiY5Ymy3zSHC3nnbmtqSfyEqpXKPzp4OSUBwf2yQJhHLtOn10nB+WAqXpt6lqtwJ ROM3M4I1o7y2uZ+T64zoRpByvmdnH/AK4iFnfcgsLAXhbfk0Gamw4Z/syVea5tuvjvt0 o8dw== X-Gm-Message-State: APzg51AlBqwHrD/SbxyNHz3Xxm/5xfoW70SQBijYLdGvAeIUw1S2u0h2 wgWXkpIk39AcznkMGieqSoeSqA== X-Received: by 2002:a1c:a745:: with SMTP id q66-v6mr8152425wme.49.1536074343417; Tue, 04 Sep 2018 08:19:03 -0700 (PDT) Received: from lpoulain-ThinkPad-T470p.home (AToulouse-654-1-394-222.w90-55.abo.wanadoo.fr. [90.55.193.222]) by smtp.gmail.com with ESMTPSA id l24-v6sm40255033wrb.65.2018.09.04.08.19.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Sep 2018 08:19:02 -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 v3 1/6] usb: chipidea: Add dynamic pinctrl selection Date: Tue, 4 Sep 2018 17:18:55 +0200 Message-Id: <1536074340-14840-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 --- v2: includes ordering v3: no change 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..7bfcbb2 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -53,6 +53,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 4638d9b..d858a82 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" @@ -153,6 +154,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; @@ -197,6 +202,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..829e947 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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 */