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: 13982484 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AA341FDE10 for ; Wed, 19 Feb 2025 16:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981283; cv=none; b=gl80GZBM5XtUUxEgRBTwgeOovWl3tHpTJsOAU+DaHPCGzHlZUNLN73Tom2TvAdWPBTBtbWx3B+gfcJ8bFITrb9AjDAbocwH4mvzN4EwBRn5+Cqft6LJrxJpNorK6NHaVr9vte4lFP9wL/0Wjx4jnF2izsr/soNPyuY3KgZnYIo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981283; c=relaxed/simple; bh=wc4sN7qLZm+el405nRxJo5bxZYh7t6HvJ1R0u+zhzag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y0+6ou2PkxK5zW+sspkWrkAOGdjz0xHFNWKBED8NDzNvTKVksgEVCG8mMyBpdNgWoR3fLL4NK3Xtn0pmUEn+5/weWMPy3dc0hcODCj1tiH0F2FCkJYT/7gTrwU9EieBpBFG6TJtqGAyX1metAT9r/nVbMPtvb/DstH30EITHfgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=i1L8Bhiq; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="i1L8Bhiq" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-aaf3c3c104fso1163543566b.1 for ; Wed, 19 Feb 2025 08:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981279; x=1740586079; darn=vger.kernel.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=i1L8BhiqCbPhgjhqI4Fs0WESgBOn7qro6AnnWert3MTOoZLsj7G3+Mjl1knNKEPU3F RyFtGuzwiVsEN0wzECKvdfNoHo4OmYtVY6vBmyEbw2yut+r0f6BuBXFpq6454LhdYMH1 uVvamrLBEtJ/qIN+mQOtNgbYOaax7IyYSTfioADdnREZ8/5bqw3oZ3HttptNOzcaFU+Q yVgK0sgn4AW/9vVfarjUZkz8NPpmbTol5zMuryl7d7MRWVzi23tWpj/ZRm5QuGi5GfZq +VGi/mNNMz/Tw2kT+RPv3fu2B/5FQoZGomXomz7B4ckg3xVgpNmZNB+XBoS9QTQhjdof FHLA== 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=tcMAeBm0FxIBhRHGytTQx8azPwzebKC2jidbyWEeFQfK4vLENkIKWQCfB4xjo6MkP/ gJ/lbDop7h2wvRl30HrKEOXeI8Hb3/hXIhjZPa9mq9k12g4C+AhMc/FCi6xEovNlqTeW T8hV5j4pyPGvd3J9WmzWRTxdrX7/F9lP7qAQn3j5hwOBiV22H5eaHM7bUrwOg6PoW24d m7zxz0halPzHNVrvPIKRFto4r9t2SFPGD9EXm+EemSPy+s3tp7qsPsOfo8JuLNwCEFEv tWLiCqOG+srD6eHbwWDnD4YQS0FETyGKWub+3gmMX0hZujkp+7hsWb8zkDCR1/PskQ7E XwLA== X-Forwarded-Encrypted: i=1; AJvYcCX3a1uSNc6ybHzcYgyWp+sUjtVhrE3p9AjfQAZUhOYEzP/QGOyjKTrBZgvjr1U81+Gal8aMmr2qPzPln+siVQwtMA==@vger.kernel.org X-Gm-Message-State: AOJu0YwSCFTUrSo37MyTM5vBjxvsGCivq4O0laj0DoyuXBONbMRoazRk OPEkdeJPN6ECDYo7SDLMbn+jXtEL9sABkRGWkJ6PTMpnu0EhYC02M544tnXd2x0= X-Gm-Gg: ASbGncul4grtzH5aHkXo3evEoOCho3oIOGWDirrVxF5blH3/0z+yMnWn1CUL4h1+Lxg EFcfCQ985TA8KMPcsJDxy3Bl+3gI3/MvE1INN/leCQXsbxz3VHKQRw7AZbq+TFCp3VAWfE4edPj nua79/rl5zqnzLiBPCsetdVZRepVuFPBxw6hF5kueOiHuJtWHzM+GZRfCwVp1LL6vACk8t9DL8j a1nms9CywUMectzyvdHxdQ/uge4z/TBCtQUucaDNFpDBDO4hVlXlD80/xwtBlRXkwtwnOZfO8oS AJXn45MpkpVyO4pWYOUhnDFvjB54UVVshkRLpdYTRpY9 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> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13982485 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8801E1FDE2F for ; Wed, 19 Feb 2025 16:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981284; cv=none; b=oCRxtqnhCKMkb5IPxi2RlZh6O4iVD4JjlsqShLTMY8EVtRlXJfIMukCCi0ScxBKsIGvl6W/1ObQjl7MTkw3F2lF7THKi4ckpUyZcEcMffuUXmC2mxYBo54eSS89093fFWe/S4jJTpU6I4CDqfvTBqlWOtWOcTH4TMC7oabdwHUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981284; c=relaxed/simple; bh=0MUXVyiNYa9K5Dj4ekYjbxuGe1+NWnA9eGzKs/3q5ls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T0tL9D0iIHuTlt6XVbeE3LKPbOdPTNcARObnbAAzx6kVS3grxmrrSq/yaVn3WqQoAfp9gFSHwB6F1gQjw+d431oZERw+599IoMCe7D83gfkwJwieFQYoK3vPpJNUht7b/4DeRpBRI4sbNnn2y3pPp5G8B4ioBMRnKFiogrP/ymM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=EVnSSoKM; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="EVnSSoKM" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5e04f2b1685so5256882a12.0 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=vger.kernel.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=EVnSSoKM88wSiKXK4+gGeYazQ/2vU5iIYQ3nBgptelyqJhkidelHjZooAQNQ3iwwYH NB3T/6ZoakVJemqsxmwyQT5uM6S71DgkFx0H8E6BJi0TBLWVKtfvi4JIxZP8k9/udDcZ Z8rX1oKd5vh4lc98KPxVzsr/NzuezbzaXhq9mm6pwWTqVEmDEFkZYDAueTJiXeCzijvd fMfUNA6SyBYOkbbNWQGmawX8LOoCeo1Qm/muWJYhwnLXNFlLNaDD/9Y1Tq/f8ELP51bK eZYHu08A87mOkxx+Eb7qrs5Ku/KdkAqFBqMBxLmopBDz2Qc1j+vVesUJUQ6BNDVX/71H e+EQ== 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=wUJ3d3V5rOIpILLrHiT4u4oCmxaoJws5T9H1UNJjQrajfNpdE4cNr/mA1kidBEVkSc L3uOhJbSqogGsmdnhF0of1WWxa3mTIjKi/DM6UL/qZ7wgCPaOKy0gm3YhHTgeFNDP6ei /GJHeqYxrMasVBlLMdP2P9MxHy0lJshf6XlsVkoporxZml2cLOxBsrPHJk3nSX8fRB1J 6/EOHIdi6FINvTnbusXo/gv9hbs4AXidcq+EeD1Z51lhq32qnUXv7JSiwXwHpHjkMIVx lsBJtdO4A9COAavZGotIdG28b582a7atX9Y1CEoQsSpQzvuRrscAmMhwT45wHXLlwnh4 XR0g== X-Forwarded-Encrypted: i=1; AJvYcCUtGhXTUM6oCfAufXncO39IDTHbN8AwEUJyG3BumHsd/q1pAuLoxpRXIj857XyslB6sebZmb0PPjB5LYjhqxkbRxw==@vger.kernel.org X-Gm-Message-State: AOJu0Yy04aTK4XtySz5ksmo763IbAB2uMeqtPp0b0KLlC+ZHlqeenpIu 9vpLmA8Ph2WJhAJ0p1XzpVwNWdLCCY5kVhbIqpfrls2EknaPNnoL4gkT657s+8DrAKpcT0Tgv7p + X-Gm-Gg: ASbGncur9dMRzYsgUUdaBv3jrdASMXJSzfhh5ZPOeX3UIYpzBDSwc9zYQkVG8tWxxfo Yp89WKKXvWFA7kmn5UT4rsel7f4DTgUgY1vJ0d2M4htfNrWarEX/uvHfhj9Kta3660ZZFLPbaI8 W8AXE1kEgcSQ2ekhIXmG1giVWqTXqP7sjy/xctcRMX1FgCBcl2SK8uooN0fj22m0IW4WCc2Q8FM QWX7eLJCajmRKJ+CndxNVyDtsl3oDgHGRlg6Gou2Ic7hs3DG6vJoIIKqLVfOE3Eo+htHDehB33t AJLdA9l20XlfDKGqigTMUavHd8I/w/Ltib54vULV4iMC 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> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13982486 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E74F11FE471 for ; Wed, 19 Feb 2025 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981286; cv=none; b=jE5e+MpmfZidB7hbdah4KrQroZfM8mv+ykjVsRhJxp5Vd0Xe6OD31eLdMyJ6uDAwlgRaUFxB2kPBNMbQf0P6EfALr85+JP/5otJ+bTxslhWYkb9WffveIi0d3EPCwnynXP5jnO9q0pENrwg7Oc3FcdDDetmuWSC0/RqAT2bo/Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981286; c=relaxed/simple; bh=dbGXzpAY3SGMwzX9P+QBAYN0/ZylTElV2Ah8d0DRt8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bsvkrlhx+1i50wlY/yXHi3xw+d4WIKK84WdUQ06DbHJJsJwwvFRqJFdrb59qH77Nbg2TyruofTYbfSCnfIiWJqKXtvAHDMO7YEVtfxYUcr+GYOABek8Ah5UvO+rD67bk0zkCluWqdG3je6yWBLf5S10P/qyqR+NB0TDNUWHKGwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=m3wENOtF; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="m3wENOtF" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso1061605666b.1 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=vger.kernel.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=m3wENOtFKSu+3/5/kD97o6tN2/1TUAwDKRGiY69MblWR7v0BCNQw8/B9eGuNtK3uQy k1t+2jlrt4j3qv6eRC6H9T4Gh8CJx5c4I3oz4dGUFgnFENOt9GDGVhw8JGv2BQe9UkxP FCOj0gemSr9xmpl78AkYOgxyeiizORIViRdkgD5aTcz10gFG5F+SnSYQuFiXpqJhWrzI /K3cAoT9FS/PJiNcmaLfqp3/qwlxrLDiG1kYI1sGpKx+/5PEBIfwZL+07NOEy2CFBqS/ Gp4EZLQzzwtTIs1OSgnABYzXYB7JdUX83Qz2/Snp3HhCzYPlfz4BsFntqXi2TFHZ3ClJ 8kxg== 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=sTWmYxBi0oosBicy1ou4I6LjnmWjmQh08BgsAcvptkHiZcjY/sZv2CdSC/tTATH9Fo glpzs3V5hbwK7Foh2WxhdpwPvZN0XUDd3+Z7CjlCpdyhGtSipc87L7YN9R9TvgKtkxyJ /TpiuptwXlkz+3fP5ky8IL94Ke5XQAQ/hLEinkJZ2efQ6pXAtSOkR/tDnzJK2QYfSobV +35KoDtpS4dKbikF766/K0zibZ+JsKkE4Lw1nYSTplpOxZKB3C2/CuPId2yZstl76UH3 yCbbBxMaPHyedjCP4xScexQfkhq6SY9GAmaVBIbw7/treuvzi2QFJyCOZlaLI1JSTkkW 22Vg== X-Forwarded-Encrypted: i=1; AJvYcCVGv3NoRDv3ctvWOO9YcBySss5fwlUoC6UnftSzk19xgz2izSS3JGQy97siiVyIrEoAxCZrRsR/9LBj+F/lKKDfbQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyG6aN8cAFSZysqTDXvaFpfkTgIwZfQvSLxMEzkB3pD6tXocCdw lcpzJLcT83B7cy7RQvp0a6L1cATXOyaNk8DYLGFDXrV/Hx9EHcpBLVw9EQ1Csws= X-Gm-Gg: ASbGnctOS0ly1DfU7Eq+s5PVNSlcQokkrVPY1GOOREeOoT6cfnIakAqCf5jS45/Uz3I nJXayahqNjtLk6hQJoHZz4swimhKqCB9Olc6LYvJRXQgF5XmhUOcQGdshd/3a8YR2NSsrhAUI2b LCNIlr+rEGTJQP3LrLx6KZdMht2BskDPkFRcH8bRfXpYC/WeffqdWqNMMlnXPToYDdKAEhqKXjr R0zOHalBtUkdYwfgj6/aTTIF7Io6PDxrsnzxRfCREDqk0zkY/hbgZV+RAYNEH/lpkKXrtZv0PhP 9EIlVZv7hgxLjYJ1NK6yOP723uboI/HULOUIGoMGEqZL 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> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13982487 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A13A21FF1C9 for ; Wed, 19 Feb 2025 16:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; cv=none; b=s3Vd2//27Nje2QYUJdBVvDbMqtMCcL9qIuELNQS7wucHj/+3L6ge7r90B9RuihwAIGZEqC1DJu7UB0G/oWi+ZA6YCs7aYpJ5xXkXxJl2GwSwv8BjiBQ9mjVrwP+gHiIj3wUV1b4f852ICfsGnigiATImD+MhRmMQdmKBwx40bg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; c=relaxed/simple; bh=LCck8XOmhlRfZGYdLsspO9mn2Js7FYYo/njobjx69Ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E/xBOPf3z2D/vnDKPqAzimXd8aEw10ZDdw2oxTozbdPEh11fZHjy88jAKPePJwyrA1KKjy8ZUjZD6lMJcKTeq3DmJibXXqh7gQVjf8278+qMTmlcXeG+RlGyFrPpkCeTfT7omZrIWn2NMm7TlZP4Bb1HAib+c8s3zvnFi7C6jVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=K+pTgZIm; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="K+pTgZIm" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso1061609566b.1 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=vger.kernel.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=K+pTgZImwgpkYfDotOZYk/NkIuq2NByOssW7AWpDG2EkaLYN1nP8HvZ/jbNLAU78uj /nV8DCbswwktKNrxAX/aO/61oE3NimNyXM756BKG80MGQMLJfsBiql2tcvanqcqrHqSe n4kIgciNl2IsKt5DxUR054jI5prP3C4j3RWvO2SCh80KRG31Hq3unFSDDWkwJ9xOw2tl TIPkUlflWx8THpyo7yfuASl0jg21K2Nu1uHF+NMOowcSeUZ9WgomP0+exX07UxPuhEtU /gyoCroFh+6h9Fag71Er3Ev+g5nV79oULKEp2T3BoakK6RcAtzUyziNPcdldnRuO2rhC XpdQ== 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=UxdAbVyeUcJlkOgwdtIf2dIG0wnLWRyxy8Z+2zR4Kd927g/D2Tz18/02XiIy9CJRzD B9W8peLNzfPj81mu4v1t2jo/liso/g75TBKDZENMGe+hNycDTmCC/32czxJFFZvMxO7Q MSORGbmBydMLSYQo+H6uGWYWQL643fITdF7L22y+nBlQsryXuPK54EjzOBIx34319Dgk bDR1gLMIIOGqryBkrF2QaJxNnAckemjc6UMxyrouXHtGoOQ9c36Uy/WCCDSmymGcbvGz 1mEbjUY1GGiGdAUW7a4CdZdhRHfqE9VrpaVu4hofulHQjtOINDkjxYsWhfa8qbvd2gmG H7Iw== X-Forwarded-Encrypted: i=1; AJvYcCXzfkZIHTXJwZ9zul9cJQFzFBoQ/YDD+inOkFbOmGmU3f8eLDc1MYPuRrmzzD9je5YZoultyt9blH8qe+YnK0BXVw==@vger.kernel.org X-Gm-Message-State: AOJu0Yxs1cuM3K2GJkMfCJf1I1OhWfcEB9UnAxvxlkzMOhmd5yER69QD ROVRR0GKHV4qcjhtLKSg6CQu3g6sKo/8nPTOKrNeM5F7rMFBC7lu/ooRtXAitbk= X-Gm-Gg: ASbGncvisnCD6jNv2B0Ds4TVnouep/S1N63oxanXMTtjxhrPkaGtPt+sGZ+OOYtRrUA NDaJM6fBGHy7zTVn0wbLjrpbMwk1fBpxrcMCyYU2WdvWiqEZj8PaJ1rydB/2BqMdTAWcTYuMxn4 +OxHLPV0l0qe95HtkL1gWQDdX4Cig5YhFxrCQ0zL8d/pYzRwwEJenbxYquVIAZ8W742HuWzSQ0J m5BPnwPoBqBZY9TWSnnP7inRMlgvjhHVJXl6biLyMwiQJ7Z1nIvJa0Phl7jCVas5t+F8oyn1eIi Y28Ch8dGmRIP0VDmCq8HjEhceSlIYvBrAfvPDOPFVsYx 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> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13982488 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD9631FF5F6 for ; Wed, 19 Feb 2025 16:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981292; cv=none; b=GA10X4ZQIGh7J8/tfiBdf5Iddc4pyfhBvY8lfn4nmX3VogL45qoeYHFx+LztkVKDrrj+kYmvrcxkKSDvYkNKZW7WEOnvHYO0EWxohQ5/u6becE0AiEJ40t1uOZBR5wtXxds6k9QF8jPBdP+QRcEaDgyKkoOVCyJ1MthQljdpFQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981292; c=relaxed/simple; bh=Nu+B+aent9gnDnLeup0LX+XZtFmQ3i9h19QHH4qM5Yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tqY3ymnZAKTqqpB1P8G7li8MiHTq0vIrliSPXnB/HVS/3wM1uc1P7QFbf6FvwjU90KC3/bNQqUiyO02Src3RqoLNNAU+j8jCtxiboQ/+q2H7py+PDfBBGlXQUq3tRkXIkHaBojI2OH36QkVKpB6OatjpEaEwHCit+wPwOyzVXAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=Ehy0sari; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="Ehy0sari" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-aaec111762bso1600281666b.2 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=vger.kernel.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=Ehy0sariCfO4XSF/zqmG1HB8+NOcqx3EyYI89+XO3YwUnm05s+gG6Z8o9zMG9X+13p OiBW8ElNlzC3y84Gkc/7SMswqUa6RkS+VH3/Hl6IdWySdOzMflAc5A3cKMGu+0QgiMEu RWWbFaUCyL1mtPdcnSXXOJDoeEho21NNwTzIIp3hk90zUiQyB0W/HC+POMOQ45Emgqgx Ut1EBEVjIQU4O9V5NIU9EzOBtD+YIydLuhQe5PjZmiAkbpNUQtpXLHNmuCqGBN/3++sb R1OiDmJcdaY1oq1g81gOYmhYr6AuNfvKD4XgWc5SNaa9oKilkwY2P5h1FqSHg9GlwnUg RyWA== 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=Q1rv6APypt79SyfIRX157d3cKt8YWZbYuAm39Jg93LmsybJOB8JN8I1QwKNTexFFXI 6FbU90OyiPDISewFYmSbObPq1GgJu8wMlnjp2H0nCgstswzFHvrZA7pQcR7xkBg87fQa ThtoczAcfVf85/Ufcfqegdd39YdnHCm3mFHA+RFwYrS0MynMRQaouBhFFEgBnGWkSFaK 1FL0m4NJFdJHVo08BZvTNaoQyi9n+Nk5jTikqEQp4vSME6tlBikQbZ+MDG9gqDEsM0u1 +Qlv5mryAVeoS9m/pU4PSFcM0XvmmAbhOTPo6ODI02WpQSOSlSpbKAKT4Cp7JW5g7cv+ Unrw== X-Forwarded-Encrypted: i=1; AJvYcCV6CfX7XCiaTBF51tcqOcAJenZ/A6aiXPXQhYJCGl0r9FZkxRh8U56WfDfrtjvgi31ljPv3V7/JK/wgtrQATon5XQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yz4TLTSlBQJrFWhBUwHMM8wGaWZ0RCAAHLT84uRttPHKWAwAQ4x 0XkTuYlR4A/8S21Kj4x5FSoFfZSXV30w1jUU/BB3HtQhac9RcjAPxrv3r7oa2qw= X-Gm-Gg: ASbGncupuwvvoY5omD4nnHukANr9cCG3JDq141enMmHlqevqax+HJsjpwE2wFjCIV5Y PM2UIPFK+Fj7s49O0Rt7nATpPUVUrBcaPUSYeKG/0EmBzXiIA3R9s6h8Ai8mZQ5ia5IbJSat7IG CZvpzAbNLSghtdLODEWbFNeg/xEL/kjsXLh9+iLrnsh7Dp0cenUhyEH6mBadhNAc/OldvmLVzAe T24N7oWRjWLTUlkaAohC8ckOkFgYTsm3FzYCYc5XABUU9qK7WFCb2ACH9Kus/qixcXyXll8ks3B me/cDSL9kdAs1Cizj4YABZ36RbU9zz89BTH7U5SFvWWX 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> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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)