From patchwork Tue Feb 25 10:59:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13989915 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 332E7C021B2 for ; Tue, 25 Feb 2025 12:05:40 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=cW6oAtBCdbsNAeNkeBhmoCOAUSMfjZqo0suGDhbWOZE=; b=gSq6Ej33WDjJp5 AqbpYmm8Xs+IVFiBvmVvmT4phJLC8hSjO9gbMtyIyiFLRLbHvpBVmgRH28GHOvoe3r9H+6P/Jf2gR z//FdKtfsoJ+STpJpYudzLsgU4hhC5KuyUMmCEh1w1Wvksbe/pzLK3kMF+li58o6r8dT15CD60icB ofnuocS4MDZjfVgpCVpPybq+7cCFKsAMmCBJQEUO14C83at7sTca97jY4EWXtaDxa3xBYVyxj40+Q urioHIvj3lWZTnTEza//QqiSKHhaQDzCrhnIFD9xw2Lr0xYyhMQTo9LuJQ+ojYo7MwxosoKZ/9Lew glkYxNuAzu4JBP7TEJnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmtgx-0000000H98R-3xE4; Tue, 25 Feb 2025 12:05:39 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmsej-0000000Gvln-32nl for linux-phy@lists.infradead.org; Tue, 25 Feb 2025 10:59:18 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-438a39e659cso35555525e9.2 for ; Tue, 25 Feb 2025 02:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1740481156; x=1741085956; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kH7eCOhtqxJ18+f2Lrbq8HST1vCFK6UWg0TuF7cMRvY=; b=JNUSQP4/Ftj8EoUotzTbLHjhPXr+bYAIQIfI1xm6ZC6PEHvUHGLjcP1cJ5PKyY+kN1 2EoLfc35G1qXXL+6n5V9xx59mN/o7G1Zb/PmnvILjpJPIGxsF55QdcvGcI97+Vramylx N/1YXzfuVrBVVaRpF5K7H6t3FbWyaJIWfP1MUgv1StzsUXud5LIWmB1bvwVCytDxC2M4 5upi3tS1n60dXbU5ExWz06Lze6+jQ6sPDOsExANkhM6BNgFZ3RsOutJ0ddmzBs6VZ9sS G1sf3E9hdJB36R50O24JKxbNuPHk3Ii+GMLfS//s6tHTZMrPMcEHXAqpo7Lg5pqm2HJW YnUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740481156; x=1741085956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kH7eCOhtqxJ18+f2Lrbq8HST1vCFK6UWg0TuF7cMRvY=; b=qYzcDzDIPkcBv/jNf6e/Br1v5zErpLx+LEpQaPFXR8cSK5Idh1Gz9OI7wNCZkJdGc1 3SFontzb84hHz2NFZ0jkRluNnOGi+SmiFpqPTuiUgA0ak8zy2GC04UiQuvsXb+ESpek5 RVtI61b7xiFOH9RgE8nIyS18gDonfqabqBGwZ7sviyAFRJb4zzyrRF1wqJ39eSi3M1Nc pdL/yeiIH/CQGrAIgny3E4btF1KkkfngZ0WvkVG+xvSqrS+hvuI40j5iJ6PdL80Wm5sX XWiurH1w7DYJtgCmjNaBgefJnwqL5pl2gHYwTrwyXz9qtAmNsJTHnwqCiwLpeUEVwQ6d 5pAQ== X-Forwarded-Encrypted: i=1; AJvYcCVx2RMVmnAz3bflbQS4C3jx+xoU3PxoqV6f7Jr8CpJd34SQKMpBxT4Orjg3oU2/d8WNAsJymTrSw7U=@lists.infradead.org X-Gm-Message-State: AOJu0YyIJlF4C3xRWAy3//D7g5eCxYys4O/eUzNEE7lbTEG76+VTsWP+ rBL/V7/59U1raojqB8MfQeyqBfw1OMMaoIDt+hkTOYNHzy8kq4Rt20nzDE8/n5g= X-Gm-Gg: ASbGncuHzYBjoy2bcQf6VnfiGKoE7y2kS0Ms3f96sMG1m3NmCAE57DPVfJSRgvYpBl6 ztFA2ua4PT7Oa0baZ8bwuHCvJAJVFmdjYHrvVqjWf5Q2K9uCu9LQ8zrmq3S6ZRm+POUyKWF1By3 /82jQEcIF63DoiE7fFcLrnTduFnJD2zdXUzz3tjSaxUhLg++NPl3tNeEOTCqCPwU6xOOp8TVP3W xjWhhx6WXWzD7IqCiuI6vbDZW7uljn/dGq84jEnt+fuJjRfo7hXMN1AGhHPOxO4XC0nTfmo84Uc Hs2Uoq1csN7FpOaoDwnXfobIfcMUIzYwcGHkDQsmcFMtj6x3BbVg0tQ= X-Google-Smtp-Source: AGHT+IFdOUFXqI73ftpxREcI5cD1cyJ6UWKG6ZRltd1AfX3lyAlJrJ3iiVYWT+u+hgxLgX7yWWhCJw== X-Received: by 2002:a05:600c:4507:b0:439:8e95:795b with SMTP id 5b1f17b1804b1-439aebf38b2mr148209225e9.31.1740481155909; Tue, 25 Feb 2025 02:59:15 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab2c50dcfsm12588815e9.0.2025.02.25.02.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 02:59:15 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v2 1/5] phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind Date: Tue, 25 Feb 2025 12:59:03 +0200 Message-ID: <20250225105907.845347-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> References: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_025917_771726_D0D760DE X-CRM114-Status: GOOD ( 16.56 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Claudiu Beznea It has been observed on the Renesas RZ/G3S SoC that unbinding and binding the PHY driver leads to role autodetection failures. This issue occurs when PHY 3 is the first initialized PHY. PHY 3 does not have an interrupt associated with the USB2_INT_ENABLE register (as rcar_gen3_int_enable[3] = 0). As a result, rcar_gen3_init_otg() is called to initialize OTG without enabling PHY interrupts. To resolve this, add rcar_gen3_is_any_otg_rphy_initialized() and call it in role_store(), role_show(), and rcar_gen3_init_otg(). At the same time, rcar_gen3_init_otg() is only called when initialization for a PHY with interrupt bits is in progress. As a result, the struct rcar_gen3_phy::otg_initialized is no longer needed. Fixes: 549b6b55b005 ("phy: renesas: rcar-gen3-usb2: enable/disable independent irqs") Cc: stable@vger.kernel.org Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Claudiu Beznea Reviewed-by: Lad Prabhakar --- Changes in v2: - collected tags drivers/phy/renesas/phy-rcar-gen3-usb2.c | 33 ++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 775f4f973a6c..46afba2fe0dc 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -107,7 +107,6 @@ struct rcar_gen3_phy { struct rcar_gen3_chan *ch; u32 int_enable_bits; bool initialized; - bool otg_initialized; bool powered; }; @@ -320,16 +319,15 @@ static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch) return false; } -static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch) +static bool rcar_gen3_is_any_otg_rphy_initialized(struct rcar_gen3_chan *ch) { - int i; - - for (i = 0; i < NUM_OF_PHYS; i++) { - if (ch->rphys[i].otg_initialized) - return false; + for (enum rcar_gen3_phy_index i = PHY_INDEX_BOTH_HC; i <= PHY_INDEX_EHCI; + i++) { + if (ch->rphys[i].initialized) + return true; } - return true; + return false; } static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch) @@ -351,7 +349,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; - if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; if (sysfs_streq(buf, "host")) @@ -389,7 +387,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, { struct rcar_gen3_chan *ch = dev_get_drvdata(dev); - if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" : @@ -402,6 +400,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) void __iomem *usb2_base = ch->base; u32 val; + if (!ch->is_otg_channel || rcar_gen3_is_any_otg_rphy_initialized(ch)) + return; + /* Should not use functions of read-modify-write a register */ val = readl(usb2_base + USB2_LINECTRL1); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN | @@ -465,12 +466,9 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); - /* Initialize otg part */ - if (channel->is_otg_channel) { - if (rcar_gen3_needs_init_otg(channel)) - rcar_gen3_init_otg(channel); - rphy->otg_initialized = true; - } + /* Initialize otg part (only if we initialize a PHY with IRQs). */ + if (rphy->int_enable_bits) + rcar_gen3_init_otg(channel); rphy->initialized = true; @@ -486,9 +484,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) rphy->initialized = false; - if (channel->is_otg_channel) - rphy->otg_initialized = false; - val = readl(usb2_base + USB2_INT_ENABLE); val &= ~rphy->int_enable_bits; if (!rcar_gen3_is_any_rphy_initialized(channel)) From patchwork Tue Feb 25 10:59:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13989916 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 71D8BC021BF for ; Tue, 25 Feb 2025 12:05:40 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=VNuDTkwxSFHmur8Q+vDJLtyjcwwtiyNI5ws0OJjE7KU=; b=3SlaagorwACKBe gpsWUIwEQGyaAKzXhJAx29i6r8kVgJVzvzlFu/L+q4UvhIHA/OZ6+wur8pL2aJdXz0wUP71RN5IxW sHWxhgGRSJqepTC/H7DSGTrGjwlcAcYhIpL5iIsF9RL81BeU0jlcdSGkZcjDNlTtgE4Piy5wRbemV gPGD2u2DNQrsNDvI4m6ywDgUG2hqMh6shiFSv/q7kkdStBtCtFYjnlKF02tJIB/7WxdnX7ZWKbqNX khj9ZGq89o/GHNwZYtbipcjUIThcedNozP42CXdNhCQy91dW2v9LxtergcjqYurBg/KtwfthfTFrI hHKQVZBqD3xJ+d2V9y3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmtgy-0000000H998-0tp6; Tue, 25 Feb 2025 12:05:40 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmsel-0000000Gvmo-0ECQ for linux-phy@lists.infradead.org; Tue, 25 Feb 2025 10:59:20 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-38f73e6ed7fso1922974f8f.0 for ; Tue, 25 Feb 2025 02:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1740481157; x=1741085957; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sfEy8KyELUmcQMIeUv/rU8Wl18U2U4X/a9mtDNA/tmQ=; b=pWEAF4ABWldNSvt/by756YgY8U/H3VHBokPiu3dfUT6RdILhN1lrAK0yrRbI1YPsXn Gt3VJ1wrpNbWYIxZZj1yjXqTcd7uGxenEgvhjvwKp39D990qutlBCtJUu0Pteka3HhlB 62QU3a0QiQQlk61VRC1IYMkLZbz2sZamWK1kYpu3SOaxugUkddGAWJ0XpvfsKWXGJGlR l54yqU/H3s2MSFb3CTLMZdHhUOnVEU1xd28nB+8OxWOv0/sfT9U5dI6imJkXIF5cB0bc /aLN4Jdfb0wdSWrnxVpgGOAAWEiY5bcKNmWSegQ2XkK9MCKwEz/OyaTQbLuaZEB7nUjW DnBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740481157; x=1741085957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sfEy8KyELUmcQMIeUv/rU8Wl18U2U4X/a9mtDNA/tmQ=; b=Wqrc/ZXMvtozj0J1Igep+AlSqrLkGRMWW6cWBglwSKAhHle1sqBxirGzx06T7HNjtG IwraLvblVzTX1h3N+G9sOsxJnV7xZYFEJRerca8vQhdpm3MMe8UESDpr5eKysKA2TauH YSTxJZynLz5T8+H1+QukbghGIYgV3Mh3V79mfoYMsU61zKbUBob2/cloqHx5nmfljLka frlLcIzPi2DLsWr5SFkCTPWSvvSyJduPHnmXYtlPnBc+Vq2xi7XpLL2d2WHMg4i2D41r xvEl8ss6Kvqfk15g0DFzeouu5cQUlCMueI5CYEDaT2j4yAwzf4FRxnxs9oD3PSvSrqYm ntoA== X-Forwarded-Encrypted: i=1; AJvYcCWNaQIUR1aNiYuaQPpJ7ST/Kd58U9ws5AQgXz1UeKXV2olGaHmf/XgOusbxVIRx/CDEplnE+kJs/SA=@lists.infradead.org X-Gm-Message-State: AOJu0Yw9pzhrfkvTWQi2VNLLtwdZtQa3Nq+qCSo9wKz4DM4FTxcpOMha 5XoXU7oP4Jeex+irBzAa9+xpGNmr6ovbq6ROOT7zrGMGbGkbPtq9idcCfP75s6U= X-Gm-Gg: ASbGncsTtZDwAaw9A2sE8lNywPNfQwg6RFJbxyemNbP88PmHMl8ZXgSvEuj0HIXYjC6 c5AW15kfPwdAuKgSi4bYXlgnBxTfHceUw+9p1YXEb1GOYN7hr+E8oP+J5ZMp2+J1pAV7Zg9j/Q/ O4vzliDXIZRCBYUfuTWc38uMn7AFlXRvQfeTYcZ4WAv1PAu4c6uuL3f7mW10+JRDd+aINOF4uCb SVmydjpW55kecHIC95iqQbrsHiRTDgOMKLAushoQPqglmtTi8jQgDYrUOx6aDSY0+HNrHpveTwx 00Cz229IbnssSDQf1v/95v0EHeEglnMTJvLzLOsa1tbt2XHEqRFMZwc= X-Google-Smtp-Source: AGHT+IGg2Tqjf61sKeAO2o+T9GqclFS/489mJaot1ECtYZrKmZ7QXTKiBSZMoZvXY0WSJE1lG6b2Rg== X-Received: by 2002:a05:6000:4025:b0:38b:d7c3:3768 with SMTP id ffacd0b85a97d-38f6e946edbmr10740765f8f.12.1740481157261; Tue, 25 Feb 2025 02:59:17 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab2c50dcfsm12588815e9.0.2025.02.25.02.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 02:59:16 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH v2 2/5] phy: renesas: rcar-gen3-usb2: Move IRQ request in probe Date: Tue, 25 Feb 2025 12:59:04 +0200 Message-ID: <20250225105907.845347-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> References: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_025919_098527_B29DB705 X-CRM114-Status: GOOD ( 19.26 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Claudiu Beznea Commit 08b0ad375ca6 ("phy: renesas: rcar-gen3-usb2: move IRQ registration to init") moved the IRQ request operation from probe to struct phy_ops::phy_init API to avoid triggering interrupts (which lead to register accesses) while the PHY clocks (enabled through runtime PM APIs) are not active. If this happens, it results in a synchronous abort. One way to reproduce this issue is by enabling CONFIG_DEBUG_SHIRQ, which calls free_irq() on driver removal. Move the IRQ request and free operations back to probe, and take the runtime PM state into account in IRQ handler. This commit is preparatory for the subsequent fixes in this series. Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Claudiu Beznea Reviewed-by: Lad Prabhakar --- Changes in v2: - collected tags drivers/phy/renesas/phy-rcar-gen3-usb2.c | 46 +++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 46afba2fe0dc..826c9c4dd4c0 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -120,7 +120,6 @@ struct rcar_gen3_chan { struct work_struct work; struct mutex lock; /* protects rphys[...].powered */ enum usb_dr_mode dr_mode; - int irq; u32 obint_enable_bits; bool extcon_host; bool is_otg_channel; @@ -428,16 +427,25 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) { struct rcar_gen3_chan *ch = _ch; void __iomem *usb2_base = ch->base; - u32 status = readl(usb2_base + USB2_OBINTSTA); + struct device *dev = ch->dev; irqreturn_t ret = IRQ_NONE; + u32 status; + pm_runtime_get_noresume(dev); + + if (pm_runtime_suspended(dev)) + goto rpm_put; + + status = readl(usb2_base + USB2_OBINTSTA); if (status & ch->obint_enable_bits) { - dev_vdbg(ch->dev, "%s: %08x\n", __func__, status); + dev_vdbg(dev, "%s: %08x\n", __func__, status); writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); rcar_gen3_device_recognition(ch); ret = IRQ_HANDLED; } +rpm_put: + pm_runtime_put_noidle(dev); return ret; } @@ -447,17 +455,6 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; void __iomem *usb2_base = channel->base; u32 val; - int ret; - - if (!rcar_gen3_is_any_rphy_initialized(channel) && channel->irq >= 0) { - INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); - ret = request_irq(channel->irq, rcar_gen3_phy_usb2_irq, - IRQF_SHARED, dev_name(channel->dev), channel); - if (ret < 0) { - dev_err(channel->dev, "No irq handler (%d)\n", channel->irq); - return ret; - } - } /* Initialize USB2 part */ val = readl(usb2_base + USB2_INT_ENABLE); @@ -490,9 +487,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &= ~USB2_INT_ENABLE_UCOM_INTEN; writel(val, usb2_base + USB2_INT_ENABLE); - if (channel->irq >= 0 && !rcar_gen3_is_any_rphy_initialized(channel)) - free_irq(channel->irq, channel); - return 0; } @@ -698,7 +692,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rcar_gen3_chan *channel; struct phy_provider *provider; - int ret = 0, i; + int ret = 0, i, irq; if (!dev->of_node) { dev_err(dev, "This driver needs device tree\n"); @@ -714,8 +708,6 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) return PTR_ERR(channel->base); channel->obint_enable_bits = USB2_OBINT_BITS; - /* get irq number here and request_irq for OTG in phy_init */ - channel->irq = platform_get_irq_optional(pdev, 0); channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node); if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { channel->is_otg_channel = true; @@ -784,6 +776,20 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) channel->vbus = NULL; } + irq = platform_get_irq_optional(pdev, 0); + if (irq == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; + goto error; + } else if (irq >= 0) { + INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); + ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, + IRQF_SHARED, dev_name(dev), channel); + if (ret < 0) { + dev_err(dev, "Failed to request irq (%d)\n", irq); + goto error; + } + } + provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); if (IS_ERR(provider)) { dev_err(dev, "Failed to register PHY provider\n"); From patchwork Tue Feb 25 10:59:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13989918 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B9D02C021BC for ; Tue, 25 Feb 2025 12:05:40 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=alF68c8I08W5gOcJsqHjInTk5GrEJmFL3YrP5dKJ/Vc=; b=EAVaB/hBb5vcPm MrC4PxUpT0WP6W/rmxV+v5yezmpMVFINP5CNKSiPPXu0BgtCCb3DAMLab2Y/6L2CxzvZLrRd4DCAt wwAFmHoLDwdYDN/I4YdfqKW48mIPA+yzbPG/GuDmNrd+O1cDcv8XcXEFAz9dzpFhZNucCDzbFIhqJ cwEiOF2EbEptKX43D3e3Og2l3BG/npSxo6ZtPAtIOZZwyFUuaGn6+jiLn/PYL1Rd8E55GFkqtTThT zGhBvM40FzKeZtNxmHaS8tJrbdVTOZi2liDotzMQoVPL6g6Y3IEb2EHAzDtKijKII8Fvyyp0SyXMI NZ4R3SAvLzNu3OZbLJ0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmtgy-0000000H99R-245F; Tue, 25 Feb 2025 12:05:40 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmsem-0000000GvnY-1Re4 for linux-phy@lists.infradead.org; Tue, 25 Feb 2025 10:59:21 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-439350f1a0bso32350045e9.0 for ; Tue, 25 Feb 2025 02:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1740481159; x=1741085959; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BxEGGaill+3QT6cynJkChqHPKlrdFel9L50qblkRAYs=; b=n3LZuTNMIzAWseN0BhmlxyD1MR5Ro6ocQdhivf7U+z5mZ97cnBBHWijHDFfzzxa/ka ENkyA1ZUJxLMxlM/jBqURE2IsJmSLB96nr+GQMRppa3BQmWgtVXijGLErHWE3cl6l6+s sVzMHaB2V18uGnOvvEcY/L7Pe3VwItDqIFMAjoMYgMspeLNgzJqntJ40xu7/FOiIX9+j +uC0jPvY6Fd9tmnTQZ452xrykckiIJtQTdSXeF+NXdm/Msr6ZeCMbimLOMNQ+ueOGiO9 QRto6J/NswY4c7Qd7betg4bIkmhDFwChONoQZv60Xewc2CpBxpDxErmVWp0uKlNJCY4c +uCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740481159; x=1741085959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BxEGGaill+3QT6cynJkChqHPKlrdFel9L50qblkRAYs=; b=qF2zQf5nLah+C2uqeEXh2V5fHqAGoj0ypOAgg9CvhzgSznitdQeGrl2KE7vZEoE7oO V3dClTbFxCCJ2SeKvB57VEIuTVt3h2JfKjt10pYZoiVEbjsHKVqN2fOG3KraKP34emTw o4OYJx8n43ZsFJIjZjcabyzk/EkztSZWtTj5LX3I5OsHWq1JzSYtHXfn+X2sT5+dDw1I W/+4l77KH+KPXXR0jjmU1p/FHp+DTjwcLVxQ4K0+goy8VJ4W3KLXR1MXItYozowY4XGT p9MdlDdbmRnsXLpjAyMK+tglRSIGPfwCY00TkKyMhVjoEqZT0SA2kXe6pZG/3zLsYvyn uIyQ== X-Forwarded-Encrypted: i=1; AJvYcCX3xZXfPv9qjqDDAdT5t6Me0vSx2ZrOenxz2CS2uDoS3hTZT+dNhLeueHdUJBAAPKN8dmbTZLLvrK0=@lists.infradead.org X-Gm-Message-State: AOJu0YyDKWWTZzssr8kFjc+mtzQXNB7KiYT1eyTBq6a6UsYHKzCK2pbY U+XQhFam5cjc/0yziY5z+JzspwdLftJpW0cK5MYDMKGNbM2Eb74oxWc70/IXuaI= X-Gm-Gg: ASbGnctcaXv0FcCRbjwgGCF+nFe1l9sn92fRTbojHzHY7d3Aolq9Im+fZlzuQWijUnh DqMui8ZoP+rbHwW0UGWj0yZ4nqcuX+2uJc3pXXqZHBV3vl5Y6fd70f3AlMlUBXaFAr0d7s/8pAN vQSi3J8ul5QAx4AshFxxSVLYNLBug7SI1JsTiPF1ONLKQ663CLwlERA920FxXUd7A9oec0Xckhx d6o2NNU8OQalqkvayH83DlklPdJsa5wH34slnhkDyWzyoDjN0jiWk+XKBLhErj+w+16ePA4YPAa ELPGYMW7sbH5NbpnTss1+bscTIwgkrNWAu4QYDixOGL3ZHuSyIlGvMU= X-Google-Smtp-Source: AGHT+IGbTxVltMIpKusffszCMrx2cQCERYqFZQ0ZCSyKXHeb3hnPDeVY0ws2Q4gsdOXA2juRIrXnIA== X-Received: by 2002:a05:600c:5949:b0:439:8345:17a6 with SMTP id 5b1f17b1804b1-439a30d38e9mr150779135e9.12.1740481158679; Tue, 25 Feb 2025 02:59:18 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab2c50dcfsm12588815e9.0.2025.02.25.02.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 02:59:18 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v2 3/5] phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data Date: Tue, 25 Feb 2025 12:59:05 +0200 Message-ID: <20250225105907.845347-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> References: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_025920_387371_13B62C03 X-CRM114-Status: GOOD ( 22.44 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Claudiu Beznea The phy-rcar-gen3-usb2 driver exposes four individual PHYs that are requested and configured by PHY users. The struct phy_ops APIs access the same set of registers to configure all PHYs. Additionally, PHY settings can be modified through sysfs or an IRQ handler. While some struct phy_ops APIs are protected by a driver-wide mutex, others rely on individual PHY-specific mutexes. This approach can lead to various issues, including: 1/ the IRQ handler may interrupt PHY settings in progress, racing with hardware configuration protected by a mutex lock 2/ due to msleep(20) in rcar_gen3_init_otg(), while a configuration thread suspends to wait for the delay, another thread may try to configure another PHY (with phy_init() + phy_power_on()); re-running the phy_init() goes to the exact same configuration code, re-running the same hardware configuration on the same set of registers (and bits) which might impact the result of the msleep for the 1st configuring thread 3/ sysfs can configure the hardware (though role_store()) and it can still race with the phy_init()/phy_power_on() APIs calling into the drivers struct phy_ops To address these issues, add a spinlock to protect hardware register access and driver private data structures (e.g., calls to rcar_gen3_is_any_rphy_initialized()). Checking driver-specific data remains necessary as all PHY instances share common settings. With this change, the existing mutex protection is removed and the cleanup.h helpers are used. While at it, to keep the code simpler, do not skip regulator_enable()/regulator_disable() APIs in rcar_gen3_phy_usb2_power_on()/rcar_gen3_phy_usb2_power_off() as the regulators enable/disable operations are reference counted anyway. Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver") Cc: stable@vger.kernel.org Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Claudiu Beznea Reviewed-by: Lad Prabhakar --- Changes in v2: - collected tags drivers/phy/renesas/phy-rcar-gen3-usb2.c | 49 +++++++++++++----------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 826c9c4dd4c0..5c0ceba09b67 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -9,6 +9,7 @@ * Copyright (C) 2014 Cogent Embedded, Inc. */ +#include #include #include #include @@ -118,7 +119,7 @@ struct rcar_gen3_chan { struct regulator *vbus; struct reset_control *rstc; struct work_struct work; - struct mutex lock; /* protects rphys[...].powered */ + spinlock_t lock; /* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode; u32 obint_enable_bits; bool extcon_host; @@ -348,6 +349,8 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; + guard(spinlock_irqsave)(&ch->lock); + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; @@ -415,7 +418,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val = readl(usb2_base + USB2_ADPCTRL); writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); } - msleep(20); + mdelay(20); writel(0xffffffff, usb2_base + USB2_OBINTSTA); writel(ch->obint_enable_bits, usb2_base + USB2_OBINTEN); @@ -436,12 +439,14 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) if (pm_runtime_suspended(dev)) goto rpm_put; - status = readl(usb2_base + USB2_OBINTSTA); - if (status & ch->obint_enable_bits) { - dev_vdbg(dev, "%s: %08x\n", __func__, status); - writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); - rcar_gen3_device_recognition(ch); - ret = IRQ_HANDLED; + scoped_guard(spinlock, &ch->lock) { + status = readl(usb2_base + USB2_OBINTSTA); + if (status & ch->obint_enable_bits) { + dev_vdbg(dev, "%s: %08x\n", __func__, status); + writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); + rcar_gen3_device_recognition(ch); + ret = IRQ_HANDLED; + } } rpm_put: @@ -456,6 +461,8 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) void __iomem *usb2_base = channel->base; u32 val; + guard(spinlock_irqsave)(&channel->lock); + /* Initialize USB2 part */ val = readl(usb2_base + USB2_INT_ENABLE); val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits; @@ -479,6 +486,8 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) void __iomem *usb2_base = channel->base; u32 val; + guard(spinlock_irqsave)(&channel->lock); + rphy->initialized = false; val = readl(usb2_base + USB2_INT_ENABLE); @@ -498,16 +507,17 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) u32 val; int ret = 0; - mutex_lock(&channel->lock); - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; - if (channel->vbus) { ret = regulator_enable(channel->vbus); if (ret) - goto out; + return ret; } + guard(spinlock_irqsave)(&channel->lock); + + if (!rcar_gen3_are_all_rphys_power_off(channel)) + goto out; + val = readl(usb2_base + USB2_USBCTR); val |= USB2_USBCTR_PLL_RST; writel(val, usb2_base + USB2_USBCTR); @@ -517,7 +527,6 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) out: /* The powered flag should be set for any other phys anyway */ rphy->powered = true; - mutex_unlock(&channel->lock); return 0; } @@ -528,18 +537,12 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; int ret = 0; - mutex_lock(&channel->lock); - rphy->powered = false; - - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; + scoped_guard(spinlock_irqsave, &channel->lock) + rphy->powered = false; if (channel->vbus) ret = regulator_disable(channel->vbus); -out: - mutex_unlock(&channel->lock); - return ret; } @@ -750,7 +753,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) if (phy_data->no_adp_ctrl) channel->obint_enable_bits = USB2_OBINT_IDCHG_EN; - mutex_init(&channel->lock); + spin_lock_init(&channel->lock); for (i = 0; i < NUM_OF_PHYS; i++) { channel->rphys[i].phy = devm_phy_create(dev, NULL, phy_data->phy_usb2_ops); From patchwork Tue Feb 25 10:59:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13989919 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 24F19C18E7C for ; Tue, 25 Feb 2025 12:05:41 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=xKsjFB+1nSJI6pOueFAY23kfPslsIWIhwV7+9PyDJhM=; b=hNFH2J3pE2seTW vAwqXLFzmOcyITdKGxYT1wJmbLA3J9QGAbaTlv+k0u3Q12JhRrnfB5yCa824WDK12SnzXsLmGhDOI ZXwU9h17xX9N/l2sMF85O9KtibIdwHQPJxwFVO/kfEuVnC9rfBFlpog1QGTl4zSXMdM36HAfVachX CoUy8sBEk2/SS4oVZFXO74lKvkdCg8/7yRwqz65wRNPfupZleRiiVIBrqDIpFdI04dScuFzqEDIqP Mpqdq7ow+AhqSuAZ1TfuHT02DlvDkNJ6MMnrn97GaWVZ/dFztZL2z2bn2TWylGD5MR0eh4WFbBvNm yhKyC1HjMP9uv3URPT6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmtgy-0000000H99n-3BgO; Tue, 25 Feb 2025 12:05:40 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmseo-0000000Gvoa-0J3J for linux-phy@lists.infradead.org; Tue, 25 Feb 2025 10:59:23 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4397e5d5d99so33646285e9.1 for ; Tue, 25 Feb 2025 02:59:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1740481160; x=1741085960; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gvELEwWWQBEiORRake36OoQXvOrT2uHpRxrgYMRnO6c=; b=IFmcmeZqKReUwu8rzytmI/v51shhnI5Q6lxlYyKYMu30BHEj7cLmY4cZAfzRW0pRzS VeD+qWsa8p3vvH5vScqBTsKOIkPEp0boA9+AK2wAWCyDhJiilBdobY6IPCrUcYovDZVm +WyXquDAcUgSvXog1eNR3rLgUZc7mFhwOuW9c2sEMYXtLgGnHGw9jTT/5KfOibuJtDCS YjWtXUUJD/u62waDXUrPsy92Fx8Wtu/hQA/Za/woME5pTVQn8fmo/hmCL8pYvnW+z7yW O43YjwFhiZFqZGpPV9nqYbW/CjdBV8B6uMRTny2+965IXO5n/piEoyIWz4U/S0VDRNmN ycUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740481160; x=1741085960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gvELEwWWQBEiORRake36OoQXvOrT2uHpRxrgYMRnO6c=; b=YOP7pt3WfvrpNGuY7Pvclcg4Pvnd1l66OaUiMFxnbewie2jrJP6vgt8U7FPxHX/tVd XB0knUHyOKcJhMDyM9X8WuGOvNTPY+ETihurEs+ZpRF5AzyHi6EI1rC+9ggYl+V3OnK/ 4+pxysdMD46Up4MWjO9SOjqun8vkC4X4bIpa5P70E8R+EbEjSLtqBUrOMUEVQgavK3ci bU0bEC3X0tdY7sOWGkpbnFKqfUz9Z5tvNfIsoB8hj5/urbE9WhN/K9uhk764awSd6Q2B EDkX51iiR+aqvEeahQF/OiBZWy6wuKPHKX9IOkC/uJpUJ3nvvsiHIoRPzgFeaugamS2m nKWA== X-Forwarded-Encrypted: i=1; AJvYcCV1b7hKB+8R8zOxZNgu/DNj1UaAubRELU/NqID0MYqw8JwBG9xyPUzPIA9rXNjzMdXk3r9M4lNtR6Q=@lists.infradead.org X-Gm-Message-State: AOJu0YwtMw+v4W87nXPQ21QAtVc9sK7KKiUzpkTVJJmMx1ddMrIZeAYS 47zopqOaqPlBtwKwa5VpFJzXoXulPLHrcGLC4N0Dd1kofFYyOhqtM82hMUraxi0= X-Gm-Gg: ASbGnctLyN2L3usmMCKkFi50F26h0o5KMnb9XIRwp40NdxvlHngQKd9XkQ6RPeiNP/3 /SnQh3hyfWtA0g72+hRraFUkYkzoni3DVdVmW7oSCSCIEzIWSiGj8dIf+Kf0HxP7pgQq6/dgmCv 69JuV+q9zKJ52epu7VE8rAGT85baS8iFDBDhrTQy/14kvWqmoNfdFRPN50a5MIdbRhXXkwyzeh6 ys8T9baQYCNawni3Dp2PAyYoKch3YdmTnY62kCzaZBM/+msYsPBukL1b0TYuZbC9zStIp1P5ft8 bjeSMYfr6mkZLI/h2klHsBEZLVtfK7JmR81DruyZqGdwJIedAcJxI+g= X-Google-Smtp-Source: AGHT+IHtRIhZcnRthP8uOU/cg1Oi5cOCbCc+gYuPmxUUUX5BgUtaRXrGdvBE+71WlZEL5TaXm3qZ/w== X-Received: by 2002:a05:600c:3111:b0:439:9f42:c137 with SMTP id 5b1f17b1804b1-43ab0f31010mr26280405e9.11.1740481160397; Tue, 25 Feb 2025 02:59:20 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab2c50dcfsm12588815e9.0.2025.02.25.02.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 02:59:19 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v2 4/5] phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off Date: Tue, 25 Feb 2025 12:59:06 +0200 Message-ID: <20250225105907.845347-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> References: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_025922_110818_15CE4729 X-CRM114-Status: GOOD ( 10.91 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Claudiu Beznea Assert PLL reset on PHY power off. This saves power. Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver") Cc: stable@vger.kernel.org Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Claudiu Beznea Reviewed-by: Lad Prabhakar --- Changes in v2: - collected tags - add an empty line after definition of val to get rid of the checkpatch.pl warning drivers/phy/renesas/phy-rcar-gen3-usb2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 5c0ceba09b67..21cf14ea3437 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -537,9 +537,17 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; int ret = 0; - scoped_guard(spinlock_irqsave, &channel->lock) + scoped_guard(spinlock_irqsave, &channel->lock) { rphy->powered = false; + if (rcar_gen3_are_all_rphys_power_off(channel)) { + u32 val = readl(channel->base + USB2_USBCTR); + + val |= USB2_USBCTR_PLL_RST; + writel(val, channel->base + USB2_USBCTR); + } + } + if (channel->vbus) ret = regulator_disable(channel->vbus); From patchwork Tue Feb 25 10:59:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13989917 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5BED1C19777 for ; Tue, 25 Feb 2025 12:05:41 +0000 (UTC) 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:References:In-Reply-To: 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: List-Owner; bh=fhts68k0Mpki+80EBm0h+zBZ5Nkvl0YG9/69g+B++Pc=; b=Di351SiO/PnQHx gh4B+PXl2CWjZi01zp4nodoy77TUDlyysWz93kVSZxvjHSZoE+NCrhN+LWUGedJ1HLJ/3Uqgx2kRt Epj5569cSMF+f9D6o4Rg2yG3fFuCdphdzknwZtjrU13jevcuqbdUROUUq5avXUuVeWj5qn7xvSBOR g4PUVjILXUgBVDqDFVpr1i9vmLiMzpBs3WiCNhpKJTvSyDoU8fC+MKDcGOWAd9PIkM/OfuqEnDMMq wkmppwdN7Y6IAdYLlolADaq17YeFQs5v2N1RnLBcmRDVCK/odN4PXFjn5V7zU87I7qvOApw413NWy LNPj6q65URW0K3WepwVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmtgz-0000000H9AV-0CDw; Tue, 25 Feb 2025 12:05:41 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmsep-0000000GvpI-1BbV for linux-phy@lists.infradead.org; Tue, 25 Feb 2025 10:59:24 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4394a823036so51710555e9.0 for ; Tue, 25 Feb 2025 02:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1740481162; x=1741085962; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SvjAeJYy02UXwEIBH2Mapc2zFP4oPiRLlb+kj3I0bAc=; b=eiPQaqun7J38YppGRnULO//1XGW1vIByPXnei5tNbhbbDLIVMcDrlWda0DwSHcWqB2 CBQkB/V6lk1YiZAZIPxrLAjO/AnXojTW4SPu3Ogss3I3P6q9m/mX+8k1mayHy+Jv5tUY hg9HgSwplZN9DUVNeafPeF7TXjHR0Vii7xwIcS+/u2PS2/mS1FBMG52ZNB637Qdl3Mt6 K8DF9eUGRc5/yAElJIactJhGUJikomJCxCgPVPu6O6pfhnD62QtWSbWULGOa3CQtwVDz JyIDnAeNci0U+Hh5ApbrqZWoRNLtIS6O5zAun+698UFkxI3Z3BcIgZI940y5efXkkc9u evVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740481162; x=1741085962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SvjAeJYy02UXwEIBH2Mapc2zFP4oPiRLlb+kj3I0bAc=; b=lXVvvD9X4pHc2VkPLkE41qpfcqcGMAkYA9yU/B40A/cszyLJOQP91hK4nV5jDmNfio MK6M+eVcbijpb/TnuCCIZBtdBLVUVmEnMSVbtWXAaSKhGrJRaejvTYI0+CjXRE/LeT7R v6wEW4grKbC5dBLNA33d5H93Wu8g5PtrCHbgehVgB9UR6thUZljXz0yvvxZP9vd/OMQE Za0vn2nxn9daXVoOWvX2wAue1pJXPOqprYqBmVReII9Lf2o7y1n994UAuwpwFbV+kRDv ZafgTC4ozlXfYkouy0Onw+Fb8Dvmnv+HXURRKWx7KhD1l8pju9wEi7FgIJkIZe+zuSj0 DAoQ== X-Forwarded-Encrypted: i=1; AJvYcCU3Q81lYyD2e+ioq55uy6wMW6CqD5hfbwZv6f+9akNFd2CQCibAbKy50Aw28Xxxo+TqkdNipvYOycU=@lists.infradead.org X-Gm-Message-State: AOJu0Yz98l3UVf7RmdDnVL6h/cdMFaGo5HSpObwI0T4qr67jA1yCK13l /lizR1y9xm8FJlEinHXLUwhU4IcugGSqVV8FxUggwxmGyTNUUF6h5pqUSXRKPrI= X-Gm-Gg: ASbGnct0mZpFCmCWP3j5gubNcBWxGSC4BTXPVrtMddJ7ncjMC0/1jlbYdUESzdL8RbQ dEyyow9Buh85gVgZ53Yf085dzy0ChXymv47Fp7Xrv5gGcfI1BaFjJq5I9aw9S1mkepu76dXlh6g +bCDX+cTAeS3i9OR5trdrll/DLM8UXGk2ZCil4F0v1LniSz4B5EkvrsJcTOJSCTKYlQ+nY/tHPP UupZtfeCrsv05uRInG3/jEG2gLU5KA+JyhIr+H/JyNfC3dO8LcUDnmo4Xecde0XY82MT/jtTms0 mlKMlnZtBw5PwmeermwFiW1MPnczZCB2qjH4Iex2a6Sjg1Y0I2vZ1BU= X-Google-Smtp-Source: AGHT+IHJusFfOvPLQ/wSNXmqs3trKdVlwIwzvO0DcaifSitYECfthSTp3FPUoDPwRVwIMqUgzX4gfA== X-Received: by 2002:a05:600c:4592:b0:439:94ef:3780 with SMTP id 5b1f17b1804b1-439aebe4a26mr165557195e9.30.1740481161783; Tue, 25 Feb 2025 02:59:21 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab2c50dcfsm12588815e9.0.2025.02.25.02.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 02:59:21 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH v2 5/5] phy: renesas: rcar-gen3-usb2: Set timing registers only once Date: Tue, 25 Feb 2025 12:59:07 +0200 Message-ID: <20250225105907.845347-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> References: <20250225105907.845347-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_025923_372450_3A66195E X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Claudiu Beznea phy-rcar-gen3-usb2 driver exports 4 PHYs. The timing registers are common to all PHYs. There is no need to set them every time a PHY is initialized. Set timing register only when the 1st PHY is initialized. Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver") Cc: stable@vger.kernel.org Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Signed-off-by: Claudiu Beznea Reviewed-by: Lad Prabhakar --- Changes in v2: - collected tags drivers/phy/renesas/phy-rcar-gen3-usb2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index 21cf14ea3437..a89621d3f94b 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -467,8 +467,11 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) val = readl(usb2_base + USB2_INT_ENABLE); val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits; writel(val, usb2_base + USB2_INT_ENABLE); - writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); - writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); + + if (!rcar_gen3_is_any_rphy_initialized(channel)) { + writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); + writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); + } /* Initialize otg part (only if we initialize a PHY with IRQs). */ if (rphy->int_enable_bits)