Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1754584ybb; Thu, 26 Mar 2020 06:47:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvCXL7DXOvTx5Ag4wiJ+rvnFK/oyYOYkySV0aKoOZV8+mcxH/hGVEl/kuVKF2y4sayHDMYY X-Received: by 2002:aca:4b56:: with SMTP id y83mr69354oia.142.1585230422386; Thu, 26 Mar 2020 06:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585230422; cv=none; d=google.com; s=arc-20160816; b=TlyUxeRt3BrCNjpbIpBw3g96Yi+QyF2gWp6Rr194sr7Utpt9td38kcNA4nDc5D2S1Y 0rTvwVGd24gQLg9M0d4YVjL+fmOPgWDUpe33ozHmTIiLbKqDJm2ZWJIVQxx1UcvYx8/E IGSbjhjUtSdK8r8yVDkt3EbbmhfAduMecM+ncmWrSvDCY46xQFmuVWngQFx+8C0uCVzr mGTbfKL6LIuojIYdU991vblZdQ0zfeZDbAzq3gdCin7IXlAtVda0ff2lK6GCMWlvFBX5 rwGXdbSkLRJzhavQlEfbkOogTnIGhHQrsOsVXwGUcSQUouYaJgY3Y7HTs7SRNSNbYHqt UcWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h4OQGeeefykddJTLyHhR+pmXKSb4WyyElXj03N7FWqg=; b=jaYQ6G7m1/tBBwspa1Z0qYQ0m8Xrb7ZLnHyqoMReIqa0jLstcZefGWuNbK9GbMzJQ5 YrKxMoH2dEBiYE5ueDhis+JQQumQxtDhnlgSB/Gq+QkGyvE6f2Nm170xjPhATLCjzhIb 14fc5EKDxN17EvUfKqoYcwSuimpB5QrRBfBzISU9J38WdSwu9VJOdQh1uaiqzbN+baFA zYp8/dK6UGrPEiQpXtktThb9XcI65h0fQ7F291h3kWtcSmHKK4CS4FYGv/4Of1uDCPJf C7Jr4cZb97oLkP9zACHYw/UUcIy8/2sz0VzSiZrckOdXNDYc1F+/3RIEJwaQYAtia2FH YOUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=FtpRIc5l; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si1099364otq.204.2020.03.26.06.46.49; Thu, 26 Mar 2020 06:47:02 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=FtpRIc5l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbgCZNp7 (ORCPT + 99 others); Thu, 26 Mar 2020 09:45:59 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39618 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCZNpX (ORCPT ); Thu, 26 Mar 2020 09:45:23 -0400 Received: by mail-wm1-f66.google.com with SMTP id a9so7026456wmj.4 for ; Thu, 26 Mar 2020 06:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h4OQGeeefykddJTLyHhR+pmXKSb4WyyElXj03N7FWqg=; b=FtpRIc5lQGp8K83aq1yBJ9kHII2tvynMr9OZ1jinKDHRFhKu+pu1lRsB8/ypHmm0sB 2rNd5Uf7wqk4JllPfjgUO4QdjbgiMucnOFVmi7JmOz7a5rEaxq+cwr+3OI1uMs7cZxS9 V1xSKr5BaUH7tJA/Jaki3uukc35M2swP5S50gL7AQZFbitadAoEPF0HF4rSnQj09drKs Lw4xeykbulQmyPURhw+KjGVPnNniAoYdSZt9TQ/l0UFDnGdQ5FZyxqkvSMlbX+ybckzZ TlkvOdAxuQatyA/6VzLxIH1ChGhBZCnKbFceW3Y/6jZ0c67Ht4N0xzyGbnpfLEaI7vvj Oymw== 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:mime-version:content-transfer-encoding; bh=h4OQGeeefykddJTLyHhR+pmXKSb4WyyElXj03N7FWqg=; b=YSsfyLg1+tg9JGYL5R75KkAtdg/zu/PsG8cpNAmh1SgYY5iV/OsvEXdglT6zDLCvNg Evy74/IeK6NTbEgL5DQCeUXPD5NMysreLC+UPiRVJl3mmHl49yk2TAyjRIKIteowbrju Xc1s2ELQxJCKxxFWuzcCjlgMjb02+cizkkCXG7jZV5M+L30gdCpO1o42V99RR0m/WMjh eSFyOuNaCyLjONn1inEhAzl3OqinDbPsKxgVIykcYp1gyZsvpMUWOlRE65ewg0V74xZs pdZ1b2SXQAOrQPeSvqhDX3Cd2NJzzvPmaYgFgu/POQ9ETuDKFhEOzTe6neshxWSgO5Nr Icxw== X-Gm-Message-State: ANhLgQ2AGCTN+n8JQK0WxdGxLjDoMMClTsWe6iFiK2V2SA2RcpNxPahK uHsIeGQitBXI8P9Ite2y/JRL3Q== X-Received: by 2002:a1c:f60d:: with SMTP id w13mr2519wmc.171.1585230318771; Thu, 26 Mar 2020 06:45:18 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:5c5f:613e:f775:b6a2]) by smtp.gmail.com with ESMTPSA id h29sm4079617wrc.64.2020.03.26.06.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 06:45:18 -0700 (PDT) From: Neil Armstrong To: kishon@ti.com, balbi@kernel.org, khilman@baylibre.com, martin.blumenstingl@googlemail.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/14] usb: dwc3: meson-g12a: refactor usb2 phy init Date: Thu, 26 Mar 2020 14:44:58 +0100 Message-Id: <20200326134507.4808-7-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200326134507.4808-1-narmstrong@baylibre.com> References: <20200326134507.4808-1-narmstrong@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor the USB2 PHY init code patch to handle the Amlogic GXL/GXM not having the PHY mode control registers in the Glue but in the PHY registers. The Amlogic GXL/GXM will call phy_set_mode() instead of programming the PHY mode control registers, thus add two new callbacks to the SoC match data. Signed-off-by: Neil Armstrong --- drivers/usb/dwc3/dwc3-meson-g12a.c | 74 +++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index 69381c42a6d3..328e74def56f 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -136,11 +136,21 @@ struct dwc3_meson_g12a_drvdata { const char **phy_names; int num_phys; int (*setup_regmaps)(struct dwc3_meson_g12a *priv, void __iomem *base); + int (*usb2_init_phy)(struct dwc3_meson_g12a *priv, int i, + enum phy_mode mode); + int (*set_phy_mode)(struct dwc3_meson_g12a *priv, int i, + enum phy_mode mode); }; static int dwc3_meson_g12a_setup_regmaps(struct dwc3_meson_g12a *priv, void __iomem *base); +static int dwc3_meson_g12a_usb2_init_phy(struct dwc3_meson_g12a *priv, int i, + enum phy_mode mode); + +static int dwc3_meson_g12a_set_phy_mode(struct dwc3_meson_g12a *priv, + int i, enum phy_mode mode); + static struct dwc3_meson_g12a_drvdata g12a_drvdata = { .otg_switch_supported = true, .clks = meson_g12a_clocks, @@ -148,6 +158,8 @@ static struct dwc3_meson_g12a_drvdata g12a_drvdata = { .phy_names = meson_g12a_phy_names, .num_phys = ARRAY_SIZE(meson_g12a_phy_names), .setup_regmaps = dwc3_meson_g12a_setup_regmaps, + .usb2_init_phy = dwc3_meson_g12a_usb2_init_phy, + .set_phy_mode = dwc3_meson_g12a_set_phy_mode, }; static struct dwc3_meson_g12a_drvdata a1_drvdata = { @@ -157,6 +169,8 @@ static struct dwc3_meson_g12a_drvdata a1_drvdata = { .phy_names = meson_a1_phy_names, .num_phys = ARRAY_SIZE(meson_a1_phy_names), .setup_regmaps = dwc3_meson_g12a_setup_regmaps, + .usb2_init_phy = dwc3_meson_g12a_usb2_init_phy, + .set_phy_mode = dwc3_meson_g12a_set_phy_mode, }; struct dwc3_meson_g12a { @@ -175,8 +189,8 @@ struct dwc3_meson_g12a { const struct dwc3_meson_g12a_drvdata *drvdata; }; -static void dwc3_meson_g12a_usb2_set_mode(struct dwc3_meson_g12a *priv, - int i, enum phy_mode mode) +static int dwc3_meson_g12a_set_phy_mode(struct dwc3_meson_g12a *priv, + int i, enum phy_mode mode) { if (mode == PHY_MODE_USB_HOST) regmap_update_bits(priv->u2p_regmap[i], U2P_R0, @@ -185,11 +199,41 @@ static void dwc3_meson_g12a_usb2_set_mode(struct dwc3_meson_g12a *priv, else regmap_update_bits(priv->u2p_regmap[i], U2P_R0, U2P_R0_HOST_DEVICE, 0); + + return 0; +} + +static int dwc3_meson_g12a_usb2_init_phy(struct dwc3_meson_g12a *priv, int i, + enum phy_mode mode) +{ + int ret; + + regmap_update_bits(priv->u2p_regmap[i], U2P_R0, + U2P_R0_POWER_ON_RESET, + U2P_R0_POWER_ON_RESET); + + if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) { + regmap_update_bits(priv->u2p_regmap[i], U2P_R0, + U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS, + U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS); + + ret = priv->drvdata->set_phy_mode(priv, i, mode); + } else + ret = priv->drvdata->set_phy_mode(priv, i, + PHY_MODE_USB_HOST); + + if (ret) + return ret; + + regmap_update_bits(priv->u2p_regmap[i], U2P_R0, + U2P_R0_POWER_ON_RESET, 0); + + return 0; } static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv) { - int i; + int i, ret; if (priv->otg_mode == USB_DR_MODE_PERIPHERAL) priv->otg_phy_mode = PHY_MODE_USB_DEVICE; @@ -203,23 +247,9 @@ static int dwc3_meson_g12a_usb2_init(struct dwc3_meson_g12a *priv) if (!strstr(priv->drvdata->phy_names[i], "usb2")) continue; - regmap_update_bits(priv->u2p_regmap[i], U2P_R0, - U2P_R0_POWER_ON_RESET, - U2P_R0_POWER_ON_RESET); - - if (priv->drvdata->otg_switch_supported && i == USB2_OTG_PHY) { - regmap_update_bits(priv->u2p_regmap[i], U2P_R0, - U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS, - U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS); - - dwc3_meson_g12a_usb2_set_mode(priv, i, - priv->otg_phy_mode); - } else - dwc3_meson_g12a_usb2_set_mode(priv, i, - PHY_MODE_USB_HOST); - - regmap_update_bits(priv->u2p_regmap[i], U2P_R0, - U2P_R0_POWER_ON_RESET, 0); + ret = priv->drvdata->usb2_init_phy(priv, i, priv->otg_phy_mode); + if (ret) + return ret; } return 0; @@ -372,7 +402,9 @@ static int dwc3_meson_g12a_otg_mode_set(struct dwc3_meson_g12a *priv, priv->otg_phy_mode = mode; - dwc3_meson_g12a_usb2_set_mode(priv, USB2_OTG_PHY, mode); + ret = priv->drvdata->set_phy_mode(priv, USB2_OTG_PHY, mode); + if (ret) + return ret; dwc3_meson_g12a_usb_otg_apply_mode(priv); -- 2.22.0