From patchwork Wed Feb 19 16:07:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "claudiu beznea (tuxon)" X-Patchwork-Id: 13982495 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 646E5C021B1 for ; Wed, 19 Feb 2025 16:11:14 +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=2MRNGJfuNiO3/du22sFM/QQ8uvgpcsFyG8KqYpmEgiw=; b=Ll9zcdT7dkBXPH SZIhO4Z17GLWJFGE5hhFbsj/HpCxZhIBmUjWierZZk+K2PFySlhEUpGdF5ERdqpZhhnxHlOgQQ2xN 2Mh2WZY6UFk/ItM2LNtmLW1SJqQ8X/N4w8cu/qfFG7/fi2G0UL1svqs6GHc9W8dYhds2lKuz3p6iv r2KP3wX5ctG+Z3sJSMuTS5zsimqKxRJJppucwiYgRiGCOaRV1NaOdNI1gvRE9RG4aImBKnom8E0D9 w8c2VGVqq0IlEMFlwwA71Ij393UnNsoCpLL8PFV99qkR6uV5udKEcwHPSQOY/GXycWlmCNeZp/ZUa 3zvv9tvrQci2/f39VwVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkmfK-0000000DjjZ-0Upn; Wed, 19 Feb 2025 16:11:14 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkmcD-0000000Dihc-0hkt for linux-phy@lists.infradead.org; Wed, 19 Feb 2025 16:08:02 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-ab7430e27b2so1173998566b.3 for ; Wed, 19 Feb 2025 08:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981279; x=1740586079; 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=xlGt4wExiEL/CIXJbDF0itACKrrgHmIFMrYFUtPey+c=; b=KqZNywJ1H/o1T1cglztmGh/8idD/yvfRyZInVtmW93SAEtC3FGUf7zBNVIGFsx6s7H zBSyjU6k+RQfkdSSafNfHfYSdQ6P5EbZRUVSRBMlCmDRs02uBCkaSh00dobAEItTF3fo 7cj6ouTiU4QWsU4eWG+LaglEjTt1pSencOy4wcZ9B3oe50MBljtUxvBgyXFzj5SP9npT ZXuroca662rS072WgCALFTRIV6uAv1oudds1Bo+Xg/MjCMkhjAhxSHHHynkL5Gdj0fKQ 3Q1U96xO7NriI89DsHEfHnWZNyP4/GuItZkzcodnuJ+uacBU8Uua1HHaVtHfNtGG/Gwp 6wvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981279; x=1740586079; 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=xlGt4wExiEL/CIXJbDF0itACKrrgHmIFMrYFUtPey+c=; b=uRsdQApibDm1Xk5EatPhtkOYYO5aggt5nS3FymA13zjtWcRZOTy/VCjGuJ48k4QA7g +H4BB4dMx5XPIuELOfHLZ+k2489A+mGipMPPD1pE833U/qTMJ4QPaij6j4me174wzhCK WnWNBj6s8uWt1gnlhXnOyB89OOIYptfErbZLT8XFp5dspcgwU19joj2reMRjIAUY8aCT 1mxF57Mr9UJNvcCPKkZ+LDUN/McwKexsH+q4iiSo963josNdtkXkZVfMWikcb1L6yNPV 034Jfd6F0r8Z4t6m2YUxFT/XI4pT3KCvoRMRM3redC9IA7bqC0iBzrQN/L92pMrk3T8b 5DGw== X-Forwarded-Encrypted: i=1; AJvYcCU0bElhgnojBMvEHA7CP2x6ofRgHGZUO9mrnQqOmgTiHagvUpjpBM5VbrdlwZM521nc1l8ZDC5aGIE=@lists.infradead.org X-Gm-Message-State: AOJu0Yzkc5ZzLewPjiFMlkZGtiS2c+zGc9k7I+vm/SY9AnmZnc4c99Eb zTXYuO3AlTd9XvLt8fIz6QeioWVBcCn3AWY+1jZyLjcrt83Z1QeopR4Cf7151r4= X-Gm-Gg: ASbGncszeJawtKDQZ2aqBgppg9M1KvgtXGer2Zaj/CgXAokOQs8q/Nj+xQbMm5e1p/V ArqYGS0aHDx4DZKj6JGemhJLIlHBrLHYjp2nay37zYPhAN+AJQ81etuYRRDsuUvw71RJxYG8MvG ZBKM41NF4oIbAl8vAvg9126xbOLLLyB0QvXpNP0+OKXlULrb5nW3iOFEOv6saKCh5RV+XUdY/7k GrzGgxY391s2jeUCnucPBAL5rc/9x4KwIMJgw52R+JlCQ4rCnAeWeDJatz7Hk+Z0FaXvYXcgP2n p6n563kCq8U44+LnF2e1DbOn8Yk9VNYD2dUa6ufX5Oor X-Google-Smtp-Source: AGHT+IF44ZngvmvLQTa6/DYd9mBS4nelIO/FTgR44hs+O/p7Fl0s8INvjP10jVJEICLAlDgjE/nKmg== X-Received: by 2002:a17:907:6d09:b0:ab7:cb84:ecd6 with SMTP id a640c23a62f3a-abb70e0d0ecmr1908734066b.56.1739981279398; Wed, 19 Feb 2025 08:07:59 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:07:59 -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@bp.renesas.com, robh@kernel.org 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 RFT 1/5] phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind Date: Wed, 19 Feb 2025 18:07:44 +0200 Message-ID: <20250219160749.1750797-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-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-20250219_080801_208322_E35A6AF2 X-CRM114-Status: GOOD ( 16.21 ) 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 Signed-off-by: Claudiu Beznea --- 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 Wed Feb 19 16:07:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "claudiu beznea (tuxon)" X-Patchwork-Id: 13982499 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 B551EC021B0 for ; Wed, 19 Feb 2025 16:11:14 +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=qyuHqB4Us3jmaiIDJXZsrw2j7MPbxkaysZDFGKjO6+8=; b=TDFlOE5qTU2Xtl bZkEsTIURZ8n6aTJyL6c1EidBemgc75GxwkFmiSiafJHJVvWRAu3+xfSYqh99tY0AEU/T6DQv/Dx6 sWDJcjFmCQGn+pScwFR2dILqDGwKee1ZQxE2VfnnfqJYM8YspyLdDhUO4fDnwN/plUYjP5rkDKhx4 RYPmOVqr3ypaKOp9QHY2kFqd9q0eudL8aAlDoT5h5XbZ88NVEgwYdVx/I+0TJ2H9x1pH/jbpA3Ryk sJQBoDNtgLwIofaeaFfaYJA7mzgDt1EjgtqmVO43bJnFNr4J0LBHCmSG2iYhb7rr3YukBK6au3nFr 6bbyzCI0cfZE7uGsgX2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkmfK-0000000Djk9-1yWF; Wed, 19 Feb 2025 16:11:14 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkmcE-0000000Dii5-29rL for linux-phy@lists.infradead.org; Wed, 19 Feb 2025 16:08:05 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5e033c2f106so6447168a12.3 for ; Wed, 19 Feb 2025 08:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981281; x=1740586081; 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=Fp963bQaS09mT/Id9cROqyvlwpVlaGR8uym4PMeifJQ=; b=o4QTYGm2OR4exF4Tq6PWiSVOEYAxmJnSZf+A/7eDXt+G+4yAelSWUd8qUMROPDpJiw +pjdKS5rvdLvM8RtBsS1kmstAqT5lqM4pb3pj1+GZBHg3C8fEpUJHqSuAT2++BLM18Yt wkbgeX7vQoYI45+eir+on/iohmq4T99qqn/zQ/a/WMPKRScHBzPxlHOUQjPQgc6LDKCI +JB756UUWeeDX5kOURBqEaZYK2UxFo7Exh3gjXpE+/MZ74FQa6jHXFxrbTLClxrehcjf qAp3ssNxqwWmOIUgLNzfFQ65bkkmSjcSzsuJxpkmjdL0ZtTBoZilPSWPELKUoNahGn6k FT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981281; x=1740586081; 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=Fp963bQaS09mT/Id9cROqyvlwpVlaGR8uym4PMeifJQ=; b=hY9snb+0OPiRScuo7SjnROElOagWUBq7FyZBH5B+hmQ2z2GEG9Vy4YRhW5sPRhu8aR 31+VclJpFTK0TyBQmJwB6uA/x4+AfpknxUy+/8dCqTEorNZ63tvNrlYX9rRlKExjPAY/ 3bRaf/iOYIpdTfMe70UE1s+cM0+V3qo96VTcXrasPbgVrZUhHQdKNOV97WaXhcaIIKoP mNI8VYXnBbyWfI7PXGY/pi9oVvHQEyMcxnVRGwxf2X92W4YbQ3YoA2V0ATRn55WOLYYp DnEGkmgELCFpjBJJ+ltO8EzY8ZaLXNcsLXvzVRB9B1yUC0bYs+Iq3D4boNuYkgZBrjDq BhmQ== X-Forwarded-Encrypted: i=1; AJvYcCUoA6MKZQtXhHo2wunv04KfokmSC3JFpe3VgUUED36Sp1ejFW18Sj0Au5f6dXV3Wkw4rIcerrMAoWE=@lists.infradead.org X-Gm-Message-State: AOJu0YwgAD79dXIiQSuoeDJ6vk1SkFjSSE38ptGKTHkFkC/Z9lCEL0eW Xer+OoUASfJe5ZqQDwEvgG/NWUwB4NWArHLnpTf3n9nv1gqDSNlimAUZe9pCMiY= X-Gm-Gg: ASbGncv9eNJQ6bNzeIk3SHljmymnhnuzo+2nrJYvJll2cJmEawniv46SHnFRoYoF7Z6 1DleRYU/f5oG7Axsfe+oEFcvNEzyc3PE5oy+iHwUo75odg41qz8hA+79wI0Kr+RtivqOi4O7Gno YeYp7emqfRHT4F2YvX9hHJqu7mAzFZw1Lv4vmKFMzmwv+MLl3qHwBLhBK+pBEfRftLmoleroIFp jwUOWjSql6ALMbNaY5oP9kd1IgyyveyjaCk0abR+2MpncDWtN0dPyjel+POJzlNCFHhRy+py0TD iE0jHU7ydLjSrsgas0c62tvWmeyHkbGjcfAhZ3vR8Btv X-Google-Smtp-Source: AGHT+IFAgpZWz/pkyw9SWyVoJ7pk3k0HNU/QFxMAd6EP1GrHppjjqFAwOVcnx9/qFdJFy5HnODJk1w== X-Received: by 2002:a05:6402:2386:b0:5dc:6e27:e6e8 with SMTP id 4fb4d7f45d1cf-5e036139cb5mr31203335a12.24.1739981280715; Wed, 19 Feb 2025 08:08:00 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:00 -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@bp.renesas.com, robh@kernel.org 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 RFT 2/5] phy: renesas: rcar-gen3-usb2: Move IRQ request in probe Date: Wed, 19 Feb 2025 18:07:45 +0200 Message-ID: <20250219160749.1750797-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-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-20250219_080802_555574_8C338978 X-CRM114-Status: GOOD ( 19.01 ) 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. Signed-off-by: Claudiu Beznea --- 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 Wed Feb 19 16:07:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "claudiu beznea (tuxon)" X-Patchwork-Id: 13982498 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 1973CC021B2 for ; Wed, 19 Feb 2025 16:11:15 +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=L7uKU/EQ2WhJ7nKockeKSLBN40Z+ITPeEp5+tz5Zec4=; b=WgvoyXB7HPY8/C Ewzh3/GuNU0CGu1jn1E2Gl9J1QNu2GWDwaaAaFVPUOWnWmafQCAzrOok2khNyDu2jCUeLUQuiOFHP D9r6ld4tGz+cEu2Tc2wKSGP+q5GYRJCzP89fg/1UduQnodstNtFf8ce68TpEOx0wBiIJ6OjANEHgX L9XyDHcDP0P9KXDKNRDYOt/zRnmRBhjRT1yXAvBwbUBNotAwiSQ/6rnCIuuUjDAIeZLkd1+y713hu wlYAPr69RUj/Z4mAn6T/N6fiRGpulGIY/Ge6oUnndU+3XaB+KDPVIeHYzkhm40jHWDg8rw2oEaHlg 9VFxN8dcgCI3LeLD7zJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkmfK-0000000Djkj-3TVt; Wed, 19 Feb 2025 16:11:14 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkmcG-0000000Dij8-3uXc for linux-phy@lists.infradead.org; Wed, 19 Feb 2025 16:08:07 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-ab7483b9bf7so912112766b.3 for ; Wed, 19 Feb 2025 08:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981283; x=1740586083; 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=ag0ceyd6lnvDklvR5kTzKXppBlKmljc5PPbiPVBs5+k=; b=XcHXMvXDrKtLDYlJbA8tHWqfzxtZKorWSY7oTP+ff3unHGQAMTE/YhSJvipoadzVSd 7JHDDJL3HPcgmGtHoIRO+cyh497GEV3Ysze6xW+VI+jeYYAYmjfWmnVoe3sJiLzcmwxo aK7q1Sra6X1NnY36YTydsQ3dX4BOIeFLKVanktqsy2wtf9G3N0qt3SgXwasgvDHjqJMd 94I5WcXlbtjNBJPm2T6i0BK3QMbPbrCWKgaFFIkAqpmBnvdsEjrWft9Copv8rQ0/ap12 RZTtjIQkYmwZ8qSfL1rB9FqiP3roHncRWkK4VWkHXKNzCjpxB5WcI1QeZu7ETUrLgy+F ocQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981283; x=1740586083; 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=ag0ceyd6lnvDklvR5kTzKXppBlKmljc5PPbiPVBs5+k=; b=pbcDR5V/hwBo91yW2sMl09rY8xbf9o8BvLpXZXlefkWMluyu57r9eiY16bJumTnnl0 oAIiv3JkZrNB8z0WAzwMHxBv8AgxLLMi6B/+HSsetMTHQhqTFc9bLqWNCiVUn7JQe5Hy qdumla8Ax8ZXiolsyWuzYGPbZ9x13An7m7rvNtg8t9bjX186aBqRas6tGO5ESVkdxpAX 9GBuzEgIUyiTB5tNKwhfy9gZ+LJtizvOMgY5mmJsSwVFZ/Mh5K2k5qthmCpSRPKmn4n1 BzjMUILlc5WexgMPTVCX1YFnrlxEeT4TqujxAMQC/9M0NRiNc064rIy1NV0IxUzvlH19 wNuw== X-Forwarded-Encrypted: i=1; AJvYcCXCSCqVBIZ4EzNJNscgSnCWozS6InZP4WVfbB8a/65VRqQDIMACvV3Z1E66SML+/HLanXwc+6OLL2c=@lists.infradead.org X-Gm-Message-State: AOJu0YyGk4fLuY666rK0jGIfhrwZij8raNGMfaSh90VW/P8ki3P105vd VJGAcTZvf1lVchRO8p1KqiXcMBKEV3DGrNj5Og7RI5ijDByxC8dUDluIgL6Qulk= X-Gm-Gg: ASbGnct2R71cTeCgXqNaWLmvlr63Osny3R2ahyRWYfbrswYOKdunG/FFSXyVDJcafcv MzVLq130+LxreaAzWxkvYzSdXWLUqbW5zl2mZZngRwDEX218OP1BgkL1crMJBdsthNDiS60aecr FkT+nZHfbnMoV0ZLn3fDVixCSCATCJauZpkkwJ8IlgiAfXNH5nbfdMisUkxaaEXA+xuhkpghFeJ o+Sni4++eVRQFjkGsgpc+0lffjhmntnBlE819EzAZoWpQczrJKK8RbGyTyouowpsdzl4jcxXKvZ 8L2rupbCCFfLBLnks8Lzz6iskIQbA/0e1y0BqEMurbqY X-Google-Smtp-Source: AGHT+IFK03MU51YyMeqqHzkdzf8lpSKD/7+03XHiHb///Jp2uJuRaLvE73Rv2ADy8FE6aZ3jeb4UfQ== X-Received: by 2002:a17:907:7e9d:b0:aab:9430:40e9 with SMTP id a640c23a62f3a-abbcce74170mr348337366b.32.1739981282218; Wed, 19 Feb 2025 08:08:02 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:01 -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@bp.renesas.com, robh@kernel.org 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 RFT 3/5] phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data Date: Wed, 19 Feb 2025 18:07:46 +0200 Message-ID: <20250219160749.1750797-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-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-20250219_080804_974021_FB5EEA59 X-CRM114-Status: GOOD ( 22.08 ) 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 Signed-off-by: Claudiu Beznea --- 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 Wed Feb 19 16:07:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "claudiu beznea (tuxon)" X-Patchwork-Id: 13982496 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 762CAC021B4 for ; Wed, 19 Feb 2025 16:11:15 +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=0ufBpuu8fNkJy0zu6KR7UI1wmPo0JDFxL55v8Xr+u3I=; b=TBy8VkxDln5JeU PXkviNtwUX+aiK9OZr306EY7cijkvym3q0yKE/iASO3Sc3Jwaq9rgd1JmM8BiBwghUSOdHjCkERkq k23ldvcCQLqkPq2jP4Sk2xd+c5BdxmbzQboAs6GJQn1d5E/ndW9XcMhRrBdq1dzUdxY3H5TdpcWLP 7xc7GLDk9eM71vVPfJtXWC3enQ4hR/QqmjFrXUPX5fbBqQtp0rzbyLcP899wLu3b2aezQH+Z79fd4 uL2tI7xUUwUzythUT5OPSaSIIOYvzqCUOMbIT4Xwa1bYhyF1szpe7g54D8QAk6Z/cIlXnmlmMSy9f tRI+koInjI2DhYYvPNOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkmfL-0000000DjlH-0Rzu; Wed, 19 Feb 2025 16:11:15 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkmcH-0000000DijI-1Mpd for linux-phy@lists.infradead.org; Wed, 19 Feb 2025 16:08:07 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-ab7483b9bf7so912114866b.3 for ; Wed, 19 Feb 2025 08:08:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981284; x=1740586084; 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=fQx5Obkxi7fOoCAjVu48dboJVNwAQ7ZZpMFYowfx0L4=; b=KfFEe7BzzSaxfCKuqNIAsK7kg/nub1IKv3MmZuhJzBXgDhvpV3yOJQdKrbTxfH+oG+ NryOzectynDKz8p4oF1eyQYFKoYiVd1l/UYc/2Di6P+B4tjez27RKtaA+dawGUDBeH8x 8jFhQc7/E6Q9eRlA9aKX2YkVfqQHDJV/CnpCUNbpQiv3GJYdC2gDjT31LF9wOmYeQEQI 4JUnwFtE2d9z3jIFdbMx3db9NCBZTXnTpTlds5KKbB20yotx+QfjqyKO+Kz8m0rtUe7s xlaXWJb5YQdbEhvoP4FlsDF5L4qTqAcG14NGBJWb1h9NjFsBy9p5m3KTUtKtwp5hrAYa Sh0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981284; x=1740586084; 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=fQx5Obkxi7fOoCAjVu48dboJVNwAQ7ZZpMFYowfx0L4=; b=Pnmw7wGBjAXxfZdMTCSqiF3NOI1/9VJvyVxU39GzFjqpZlfCjWjFCYwfmHc20HcrNy QaugX6AkA7UsPhiMmeaLM7IKOIYvRAciQ6Kn72/6tMhe2hTY2R1s4B0zbHHUc5SDEMXe ArWEF9SvG6IqGP5g2bH1E6//MhEe0u6AyBkLDHhwe1i0mnHYEnr1kNo1BjCGNq3P07iu KpqbcTVs0SLFcn4r4tAydpnUE1IxYElTFRm5rkAjuYHpC/hQWB5j3zp7EB3azVB2sVXY IsqvJC/PxzHFvkFM7KYTox8OMEeTrJX3Ko3oD1FsgN+kR9tdE57zLW5iwWobawDiE638 zIIg== X-Forwarded-Encrypted: i=1; AJvYcCX25KWYKuCxQVoLBHFHmEdGPYnFWWvYs+xsNEBxsElT9jaLAkypiVJdxmNWhecKjs5MAIaoy3Mdp6k=@lists.infradead.org X-Gm-Message-State: AOJu0Yw1Jt0j8yr2urPtaEU5C155Kh4GUlrfYSAOOhzLWCsOoF5/eIea 7/dCa3elZL1YLtSG+Lw+puEmOvSJDcY8wZdMzjTgoDM1vKhCImPnFZ42E9X7q0k= X-Gm-Gg: ASbGncv9JSayLNrNjoecMFd+9CFg5bGLT0KLEFKjUmjDLhaT5v+IgqMfDLbqc8RiYyZ ueKpR6XrIF3HtxhSQwekhFFeXNPLW8p7dFCG7J5ybfY8/gFQyoAPwx3dHYuSKD4FUQPEoabO2M2 9irKRSETO+5vV1S7IL6Zxb9IEW93Ssgo4u9RvhBZeFLTFscQmLCKGL9bMtLddcBaJMDl70vm66Y MPC9KcvRZWqa04V5HJyh9Nd/AQlon424u1yrWg29CnVGgShzCCIJrpWIze9kzfWmz9Jkat94E4w 2GCORkKmUvxJuYml6CRK8oGF5zzxjMch31zRow0K7S/A X-Google-Smtp-Source: AGHT+IEyYVLE9+celNxGo86663B2wzUsZfpExbxct9DCQIl++bGSTCDjXotnzuNdpB6wYwo2U02c/A== X-Received: by 2002:a17:907:34c7:b0:abb:cdca:1c08 with SMTP id a640c23a62f3a-abbcdca498fmr312301666b.16.1739981283761; Wed, 19 Feb 2025 08:08:03 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:03 -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@bp.renesas.com, robh@kernel.org 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 RFT 4/5] phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off Date: Wed, 19 Feb 2025 18:07:47 +0200 Message-ID: <20250219160749.1750797-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-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-20250219_080805_367430_76D6857C X-CRM114-Status: UNSURE ( 9.32 ) X-CRM114-Notice: Please train this message. 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 Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 9 ++++++++- 1 file changed, 8 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..087937407b0b 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -537,9 +537,16 @@ 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 Wed Feb 19 16:07:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "claudiu beznea (tuxon)" X-Patchwork-Id: 13982497 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 D98E4C021B3 for ; Wed, 19 Feb 2025 16:11:15 +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=uERPquHINU00KvMuZ4vjNTkMnbZZuBzETOEzY/kP9h0=; b=n4b7l8hX+Ttf2f npXbin+p4TiaD9+4YPMvmRzypjcIncUF+CXcPH2CnZvtieIC8Ow6Py/gSkj2m6riyJVeOFiOgsRU0 ox9a+tntqIckByjWkH+htJNKBKN7SnIGImXdKVHkvesplzh0qqOJb5eVAJ7z8KQQ0yzlG9HaahhUR Efc13RCPr1ZSodiJryj8nPG9ClFoZt6cTMaIfGkaeYd7tvqrtq2oH4Xe1VRLRaNGylyaNx4q94HVu 87cCw7wvmo8MXvnd1nzBNubtpLmif6KDLNL2CjsESRvuQP4cIEbmBNagg6ucl63rfshl8tb+1OdZv naN4254hgVIyBmE5qX7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkmfL-0000000Djlq-1sYD; Wed, 19 Feb 2025 16:11:15 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkmcI-0000000Dika-26jv for linux-phy@lists.infradead.org; Wed, 19 Feb 2025 16:08:09 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-abb97e15bcbso607115566b.0 for ; Wed, 19 Feb 2025 08:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981285; x=1740586085; 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=BtGBoe5coeUnXZJpUlOcRLqzBSKuMVRJ9kwi5GgXX1M=; b=E08N2s+2LuzKNjIBiDUyIYsFwoXz8WAv1OEeQ0JodfsWl9DLZOK8SWpQEyJk0QEnVx LDDoINtUQ/q65/tlLhWR+zEw8OGBEYZeHKB6WUtAGLCZOm2Hb5dqmkTxbifO+wgDRnpJ AUc7D3jnD1XwEeV0j4fa0jCMDHo2qrCREjdqqxFBYiJgc6io9FcTMhLgv1m/xDnl+tZJ MBNDTMZDbQUtX4nDnrC6Ku/qHZFwUevXFBKDTBKMDsAzTLDlmfO9xi8UNYpzwP5ycx0y vwJtr/0jcxPzEvB5UR1QwlhBo5RNrZuYEozR1yTgKKwkrb+6ztBbxuadO39USY6AU1Ag PtmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981285; x=1740586085; 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=BtGBoe5coeUnXZJpUlOcRLqzBSKuMVRJ9kwi5GgXX1M=; b=L5zE8kF1Qi735ehc3aF8eIkH36Lg0BOM5h/ZUV+KaNaQG3E25eD9CVecGzyGTogJWf kEIC5vM3Hdhd9Mdad3Bmiq8WcR9yiF/9rzE6assZVlXYwP4k/45O7UezfJNJbG4TkXtp mQYRAaCLTdOAAGuwXVPWJo9GvdFjgPzQ5ioL6zLJiCfDbvgN8T1JZOyan92byrrO1/OV NEnj4NhLWTDgJnGbyojOSBIlGmw1atWyqDmyKkaH1keCygpLn40cfXEzbBda51QPg8iZ aTkbBRXrROW7B2wwgmGVRlrOc8mlglCmTrWWqxaqht4Lmv94UIj2ZXXRAvyu95T+XKfY aHhg== X-Forwarded-Encrypted: i=1; AJvYcCU8sYadaIiWe/wk7ByuQHJ/BE8paMD1uEVcrvT4sduNHK98Ti4uXACG8hEM09FkwCIixAEtywMTfaM=@lists.infradead.org X-Gm-Message-State: AOJu0YxK3t6js8rPEvwHASv68fAb34Q1J8GbojsPW/LIf8T7irHHrdHP ALfZ1czYLFwvcKjsidtkR+QWqjwMKlg/5bcl0DyDTtccPRk3Nj0LtT0MZg8Ox2U= X-Gm-Gg: ASbGncv3gHHrPReKyTyz+pKd7pgOvfE7Yhytygc07EO8V2mtkjsGdgl0TxY856dBq59 cuwtlTZ297WXp9XJe0k83NrFKU6T0oX8LdFLahqI3Md97dirrz0DoI16ITS9EnCdboS/unNr8vH XuOonEglQbU0MwJCYsM3bTtsxC8TX+k710M3fQGuEbq3n244OVxgLh+KISkC/z+t0cikMwAHUtb mEqoEduIC8w+18mnA4t70bTCbJ2R/+HifKUhBFz/r9bzxmSbzcpDcOwH3VWQueSp0TKDjl3y6b/ q8x/LeyekkVASqn9TskeG3oDWvTfk2D21i2JrjB41mlN X-Google-Smtp-Source: AGHT+IHxe5ZyQ3C/l0BujyjIhZwXC57yvWHfxRUBHLFeh5ZxtlbAM5sS46OrKTP8YZUtyZ2rOwWbYQ== X-Received: by 2002:a17:906:9b4b:b0:ab7:c3c9:2ab1 with SMTP id a640c23a62f3a-abbcd0d1b4emr437963966b.50.1739981285101; Wed, 19 Feb 2025 08:08:05 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:04 -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@bp.renesas.com, robh@kernel.org 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 RFT 5/5] phy: renesas: rcar-gen3-usb2: Set timing registers only once Date: Wed, 19 Feb 2025 18:07:48 +0200 Message-ID: <20250219160749.1750797-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-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-20250219_080806_542951_7EE9701A X-CRM114-Status: GOOD ( 10.19 ) 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 Signed-off-by: Claudiu Beznea --- 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 087937407b0b..8e57fa8c1cff 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)