Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3578383pxj; Tue, 15 Jun 2021 04:11:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywaExMYoX+T+7+0rE3+ij6K+teHkeHOxkaMr2USuTTvnEa/tUG1q0QR84v0HDjYJiu20On X-Received: by 2002:a92:cc51:: with SMTP id t17mr17310752ilq.113.1623755465882; Tue, 15 Jun 2021 04:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623755465; cv=none; d=google.com; s=arc-20160816; b=hR0eBNQerevJHTU02MDnM5ZICzKV6KYF/HXI9hjPtrip0nZJwTtNAh/qTq/SCjl32o SQcIsCcPBWJNCWqxD3ocAXYxQKjL610nLT5bwql2TEab1dkdVPlw/nsIhhSZw8b/bMY0 R91Ocud5z9t7XW9BKCERz3qKTQ0TL8iL2DVhsq6zCQ+eSQ9HHPsu8BeZoYFxFRgn0qwK pZ7ATGThkHzGVKm63JWSOfXOYE5rJB2pm68btxyWqyj5rOfMFP+n/I6XUih9gF2J7sI5 /vrnHhCJ0pWkjRiZwZVBY3VAw2G7Tzw5bwJyuI3MG7H1dhzo0zt9aE4tvHVTRX/D5qAY ZTpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=snehl87cAIr9Cpohb6RagTYh4ofnOzEjNE2UDTiAUL8=; b=c60i9/bJN0cpjJtKkB6wLOZQtdLbosMbzExbYUFIzdcfUH9XegcMjMeFbuw5yuLguG bXI4GrafentEQh4/F4FmzXTH2EiDnCQqLkqAgb4YWfl9+7XhTKrR6/gD1wIUwbANn8Qh Lwp3y+ASnZdtc4U04qQI8VIf2eRWVaefyGHSQT7/gp1odO7iX9kpD9Fn7ebQcUG4g6OO FFcFam3M5wMyWBmRWS4N7s6hxv+Ne0F6i3ixRjuF3YQIkXYLRB6H5nriwnd8VWtPZ/RJ esOjTGqAmKp1qt/ThEirM6LQKymH/VGtbuz47n0VSEvvXiJDTNTMkPp7mlY+p9/goRLv sQjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si22089203ilr.53.2021.06.15.04.10.53; Tue, 15 Jun 2021 04:11:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231854AbhFOLKQ (ORCPT + 99 others); Tue, 15 Jun 2021 07:10:16 -0400 Received: from foss.arm.com ([217.140.110.172]:60548 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbhFOLJj (ORCPT ); Tue, 15 Jun 2021 07:09:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D2581476; Tue, 15 Jun 2021 04:07:33 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 469393F719; Tue, 15 Jun 2021 04:07:31 -0700 (PDT) From: Andre Przywara To: Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec Cc: Rob Herring , Icenowy Zheng , Samuel Holland , linux-arm-kernel@lists.infradead.org, linux-sunxi@googlegroups.com, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Ondrej Jirman , Kishon Vijay Abraham I , Vinod Koul , linux-phy@lists.infradead.org, linux-usb@vger.kernel.org Subject: [PATCH v7 14/19] phy: sun4i-usb: Introduce port2 SIDDQ quirk Date: Tue, 15 Jun 2021 12:06:31 +0100 Message-Id: <20210615110636.23403-15-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210615110636.23403-1-andre.przywara@arm.com> References: <20210615110636.23403-1-andre.przywara@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At least the Allwinner H616 SoC requires a weird quirk to make most USB PHYs work: Only port2 works out of the box, but all other ports need some help from this port2 to work correctly: The CLK_BUS_PHY2 and RST_USB_PHY2 clock and reset need to be enabled, and the SIDDQ bit in the PMU PHY control register needs to be cleared. For this register to be accessible, CLK_BUS_ECHI2 needs to be ungated. Don't ask .... Instead of disguising this as some generic feature, do exactly that in our PHY init: If the quirk bit is set, and we initialise a PHY other than PHY2, ungate this one special clock, and clear the SIDDQ bit. We can pull in the other required clocks via the DT. Signed-off-by: Andre Przywara --- drivers/phy/allwinner/phy-sun4i-usb.c | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 126ef74d013c..316ef5fca831 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -120,6 +120,7 @@ struct sun4i_usb_phy_cfg { u8 phyctl_offset; bool dedicated_clocks; bool phy0_dual_route; + bool needs_phy2_siddq; int missing_phys; }; @@ -289,6 +290,50 @@ static int sun4i_usb_phy_init(struct phy *_phy) return ret; } + /* Some PHYs on some SoCs need the help of PHY2 to work. */ + if (data->cfg->needs_phy2_siddq && phy->index != 2) { + struct sun4i_usb_phy *phy2 = &data->phys[2]; + + ret = clk_prepare_enable(phy2->clk); + if (ret) { + reset_control_assert(phy->reset); + clk_disable_unprepare(phy->clk2); + clk_disable_unprepare(phy->clk); + return ret; + } + + ret = reset_control_deassert(phy2->reset); + if (ret) { + clk_disable_unprepare(phy2->clk); + reset_control_assert(phy->reset); + clk_disable_unprepare(phy->clk2); + clk_disable_unprepare(phy->clk); + return ret; + } + + /* + * This extra clock is just needed to access the + * REG_HCI_PHY_CTL PMU register for PHY2. + */ + ret = clk_prepare_enable(phy2->clk2); + if (ret) { + reset_control_assert(phy2->reset); + clk_disable_unprepare(phy2->clk); + reset_control_assert(phy->reset); + clk_disable_unprepare(phy->clk2); + clk_disable_unprepare(phy->clk); + return ret; + } + + if (phy2->pmu && data->cfg->hci_phy_ctl_clear) { + val = readl(phy2->pmu + REG_HCI_PHY_CTL); + val &= ~data->cfg->hci_phy_ctl_clear; + writel(val, phy2->pmu + REG_HCI_PHY_CTL); + } + + clk_disable_unprepare(phy->clk2); + } + if (phy->pmu && data->cfg->hci_phy_ctl_clear) { val = readl(phy->pmu + REG_HCI_PHY_CTL); val &= ~data->cfg->hci_phy_ctl_clear; @@ -354,6 +399,13 @@ static int sun4i_usb_phy_exit(struct phy *_phy) data->phy0_init = false; } + if (data->cfg->needs_phy2_siddq && phy->index != 2) { + struct sun4i_usb_phy *phy2 = &data->phys[2]; + + clk_disable_unprepare(phy2->clk); + reset_control_assert(phy2->reset); + } + sun4i_usb_phy_passby(phy, 0); reset_control_assert(phy->reset); clk_disable_unprepare(phy->clk2); @@ -785,6 +837,13 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) dev_err(dev, "failed to get clock %s\n", name); return PTR_ERR(phy->clk2); } + } else { + snprintf(name, sizeof(name), "pmu%d_clk", i); + phy->clk2 = devm_clk_get_optional(dev, name); + if (IS_ERR(phy->clk2)) { + dev_err(dev, "failed to get clock %s\n", name); + return PTR_ERR(phy->clk2); + } } snprintf(name, sizeof(name), "usb%d_reset", i); -- 2.17.5