From patchwork Tue Nov 16 09:35:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Boger X-Patchwork-Id: 12692723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7287C433EF for ; Tue, 16 Nov 2021 09:37:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B702C61B29 for ; Tue, 16 Nov 2021 09:37:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B702C61B29 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=wirenboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=yYqIps8LDmAU+mtGKXIYR+yKZ2uQX3tbWshwH0OR1EM=; b=ws/y5Ecc22N9We y9ErcDbYtCih11W9KskAwfT2yfdY6Jp+JRa6BNhEiTHss0kRbmYLu6BIOXm5f1g9NVyUzb5CkLiOF IEC/OigR8uSgPOkMAYH4FhYsdI04/UIeN+Vvt/3HWWf/9TpEl7csWY11Plo7WS5mrasQW4xpyWdqW nL+xtLBPCqXCfWkn7N1abK/XZSywaAhmcl4zmY6C4esqGkrTXdSE2f9iwi2X3xljtvRpOpRW+L9LN mRKH7vn+uetOu2lvB0e2wNLNawDH1mjw9/GqPgfResjO4lX0JvVnXnwCkk4uoNNw+JsctRBTF2Alh Wu0yqUToCpG5TC2/ozyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmusY-000yIY-0B; Tue, 16 Nov 2021 09:35:50 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmusS-000yH1-PA for linux-arm-kernel@lists.infradead.org; Tue, 16 Nov 2021 09:35:46 +0000 Received: by mail-lj1-x22e.google.com with SMTP id v15so42034657ljc.0 for ; Tue, 16 Nov 2021 01:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wirenboard-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5a/Std0CdLhhceL3Y6/V4PWA+iMZUZInfEMYaHuWA/8=; b=2EC4inBIQ6DU4E/YdDNE1Z/ONgexouKomSmmpfYVQkvSKtLOSjBBXheuodS4tu3fAx FSpaSKubDT3enRImiyulPEEEy5Fl7g89YmRW1ddxYXsPql23Q2zuB2l4g5OzQ3zugA6x EFciMItxNcYfGzeCIN4r/77WUlxttwax/UMqp7svzChKDvUfvLMGDP+Cw+MddO3KzMWQ fvbAOTcxz0akrpzjEcBLJLrU1/KYQDtlpLIxAq5xGOeeVKyM+xkG5X5kQ7UX36uMqug7 tIfMxeaoXhr2byypT7qSTVVeDopEfsLAGJfQ0tyfAP3IuIW3rYmjxaV/UasprKnj3Vwa fL+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5a/Std0CdLhhceL3Y6/V4PWA+iMZUZInfEMYaHuWA/8=; b=LdBkeD1Svbt39pDk11g/H+z6sXv3lwg864080LVnF6TmZsjP0dxcbzi+N5oInEW1pH Et22+YB9RyYieckhXyjIa2UULDxN+pZ3g0bRk/ayRYVkjW/TmdsHtr6vyx5jAeyrsuPM UW/qXYMlZ97dfwxhb1VnJlu3WTcT6uxhFBONSCFElNCA/ohyndmXkIq16c6Mg/vQNLmb wq+yLY0EROljN4B96bVa7asSmZ+kadBFZY0BWqnk0ybzwWx1y6QS96SjgLA/2JJ0UKxz AWqOVj/ried2x3NKTuG2oAKxy/KWJWF6Ei9qTmvXzXv1y+1eUJ0R1GQLVdGCW16oWBBM iF+A== X-Gm-Message-State: AOAM530VuXmieFsHeZXX6JJob5/IZNPfWSmjuyA1Jx7d7MSGDtaOUOkR xLnu1XJO6yk/wXu8IRFIYNycuw== X-Google-Smtp-Source: ABdhPJyIslw7cKCT8hE8JR8XKYFUQof01sWdaSDzd51ceZSUftuk7ZhBqkIFCCgWW3S3r0WrRKYCvw== X-Received: by 2002:a05:651c:503:: with SMTP id o3mr5662800ljp.353.1637055341690; Tue, 16 Nov 2021 01:35:41 -0800 (PST) Received: from boger-laptop.lan (81.5.99.121.dhcp.mipt-telecom.ru. [81.5.99.121]) by smtp.gmail.com with ESMTPSA id m28sm1281080lfq.189.2021.11.16.01.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 01:35:41 -0800 (PST) From: Evgeny Boger To: linux-sunxi@lists.linux.dev Cc: Evgeny Boger , linux-arm-kernel@lists.infradead.org, Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Yangtao Li , Icenowy Zheng , andre.przywara@arm.com Subject: [PATCH RESEND] phy: sun4i-usb: fix phy write on H3 and newer Date: Tue, 16 Nov 2021 12:35:10 +0300 Message-Id: <20211116093509.346002-1-boger@wirenboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211116_013544_928191_60B348DA X-CRM114-Status: GOOD ( 19.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On older SoCs (prior to H3) PHY register are accessed by manipulating the common register for all PHYs. PHY index is specified by pulsing usbc bit. Newer SoCs leave the access procedure mostly unchanged, the difference being that the latch registers are separate for each PHY. Additionally, accessing USB PHY registers is only possible if phy0 is routed to musb IP instead of HCI. Introduce phy_reg_access_v2 cfg flag for H3 (H2+, H5), R40 (V40, A40i, T3), V3s (V3, S3) and A64 SoCs. On A83t, H6, H616, T507 and probably on more recent hardware, these PHY registers are not used in vendor BSP. So don't set v2 flag for these even newer SoCs as a precaution. Signed-off-by: Evgeny Boger --- drivers/phy/allwinner/phy-sun4i-usb.c | 44 ++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 788dd5cdbb7d..cf10e385f199 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -119,6 +119,7 @@ struct sun4i_usb_phy_cfg { bool dedicated_clocks; bool enable_pmu_unk1; bool phy0_dual_route; + bool phy_reg_access_v2; int missing_phys; }; @@ -192,13 +193,38 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data, int len) { struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy); - u32 temp, usbc_bit = BIT(phy->index * 2); + u32 otgctl_val, temp, usbc_bit; void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset; + void __iomem *phyctl_latch; unsigned long flags; int i; spin_lock_irqsave(&phy_data->reg_lock, flags); + /* On older SoCs (prior to H3) PHY register are accessed by manipulating the + * common register for all PHYs. PHY index is specified by pulsing usbc bit. + * Newer SoCs leave the access procedure mostly unchanged, the difference + * being that the latch registers are separate for each PHY. + */ + if (phy_data->cfg->phy_reg_access_v2) { + if (phy->index == 0) + phyctl_latch = phy_data->base + phy_data->cfg->phyctl_offset; + else + phyctl_latch = phy->pmu + phy_data->cfg->phyctl_offset; + usbc_bit = 1; + + /* Accessing USB PHY registers is only possible if phy0 is routed to musb. + * As it's not clear whether is this related to actual PHY + * routing or rather the hardware is just reusing the same bit, + * don't check phy0_dual_route here. + */ + otgctl_val = readl(phy_data->base + REG_PHY_OTGCTL); + writel(otgctl_val | OTGCTL_ROUTE_MUSB, phy_data->base + REG_PHY_OTGCTL); + } else { + phyctl_latch = phyctl; + usbc_bit = BIT(phy->index * 2); + } + if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) { /* SoCs newer than A33 need us to set phyctl to 0 explicitly */ writel(0, phyctl); @@ -224,17 +250,21 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data, writeb(temp, phyctl); /* pulse usbc_bit */ - temp = readb(phyctl); + temp = readb(phyctl_latch); temp |= usbc_bit; - writeb(temp, phyctl); + writeb(temp, phyctl_latch); - temp = readb(phyctl); + temp = readb(phyctl_latch); temp &= ~usbc_bit; - writeb(temp, phyctl); + writeb(temp, phyctl_latch); data >>= 1; } + /* Restore PHY routing and the rest of OTGCTL */ + if (phy_data->cfg->phy_reg_access_v2) + writel(otgctl_val, phy_data->base + REG_PHY_OTGCTL); + spin_unlock_irqrestore(&phy_data->reg_lock, flags); } @@ -927,6 +957,7 @@ static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, + .phy_reg_access_v2 = true, }; static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = { @@ -937,6 +968,7 @@ static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = { .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, + .phy_reg_access_v2 = true, }; static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = { @@ -947,6 +979,7 @@ static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = { .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, + .phy_reg_access_v2 = true, }; static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = { @@ -957,6 +990,7 @@ static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = { .dedicated_clocks = true, .enable_pmu_unk1 = true, .phy0_dual_route = true, + .phy_reg_access_v2 = true, }; static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {