From nobody Mon Feb 9 10:52:18 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 A6F062676F2 for ; Tue, 25 Feb 2025 10:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481160; cv=none; b=s/5eUnTc2bQIAskw4D0XWvDnLsov30Pw94HGTuDcmZZA1y3cw9iyXTs1H3Avhuit7HjvR4Yep0E3tMlFdSBaSddM85IQF54+IqShH3/TU2KlT/lniKXmMTne70jGuqedRB47DEfU6vBaTBgPGTIjTa2h74dztKMvprsc6X9rLAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481160; c=relaxed/simple; bh=aRLrhUecBs7vYsSHOF02+roIq61av/C2p8cKhrDLy5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jJTZ1Zv1RwYYa0LAicbIMPV1G7S5+V5l2LXxGn0YtbIpugr3FT+qdJrwc23KfvZi4SE1grq860e7ggv25i2xn94au+yMdyYVj0PSFcAO2DCKrTOU2lh6BkEmF3pTCrwwDdf307bm3yUI+ppgJdl4u79D6raeY7QNGYFWM9JDxw4= 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=j36kgmgJ; arc=none smtp.client-ip=209.85.128.41 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="j36kgmgJ" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-439ac3216dcso31437995e9.1 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=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=kH7eCOhtqxJ18+f2Lrbq8HST1vCFK6UWg0TuF7cMRvY=; b=j36kgmgJ/5DR06t9WgegxnMIDjZrGf3MYCnIGqzQEUG4Sm3gRD3xPDsRS9aaE2oA63 3qZqayhp4q+hAmHHhksC2TcxE3PLGYTnJhjQsVg/8SsUxW2FyQv87+EPTfRT+BYM4J8T yoZfDL5ikvE0L2Y5nEhyl3gPAzE6WqwX/lUvwBg5S9mQaxoIAgnIEOUXh9HyRznmEDkA QpIai/tgk3IoNqFSEDRubUSCgjMjS80zZJDvg57a3YVDxKs1jcFVYI/IyFC1p6ucK5d2 F1SjP5wlHrH7t/arsHBEG3mqYxL/7vhn+eaLWETMz20YBf53TqrkTfQKOYf2jQ3XhLTg Fvew== 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=Sliv1SVaPzBXBPtX8ZUHkABxJjB2HrhzLTg0LAxbFF2eMCF/Ek+PK7MkF/rkCrdV9R Dz0GFaFMuXBm5dd7ya8ZUhVGxnsbsxtaxrRivtvMUWMdAiIcjg5AWPGK6DWvvhpu5dpM bUnwg1PPY0DB6R8agd/fulzuvLRH95t03Oq+8zOEWE5NPi+gUtKUOGaznYHBHlwuI5zE AJt2W7AjjfwUzsu5YJdbVVCQgBI0D7xN4MuQ+34uP+lwiCltp/bvvsOTypc7ryq0mKFo m0JWoJzWfBYpUFZR+IsUNI495uBi9Z7tLoEGXE6W4BYzEk/kjdAOFgK2LshrCrnbloDZ p+zg== X-Forwarded-Encrypted: i=1; AJvYcCXZTZ+KQy0blQP7zspqjWdFgZboKa16H/7JQH3zWzqz16kIRmm1IzAUPPFoM7py5b9mAlBqjl5G6MjAwa4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx27RtFQZn9czJUNYkCDK4RaU0JSHRuwas5v0eoS36kBzVUeRAa IlrQvWL+bYrmzJXaI9D7zcXydXYnQ7igv7fBOPq8HSt/sAO2fJyC7Yw8dKl1YVA= X-Gm-Gg: ASbGncvk9WcteI3JA1rVHWcJJi7ugkyo8C2phnwZNvrb9e6EkHH60RBRJck5TC1Pfzf D63H0llZfW5BOAo+sIlcI89dI8T0FY8IoNq+RmIo8lhXUuPpMkG9eKZu8M6WDXR59yjr951Ha07 GYKVE9FlGCABMZsySZNdiTN7gmyF24d09Djtkm7BiTZ4fZ8nXB0gCP1zIeBYCWUEZajFoC0rrYy ODIVI/IzOuA515WYgX48NzCLqs8kLcswHIgHzIxaDDuM34ki5K+i9joeISx8TXEaG/ADHmSCC37 I/e6fp0e0r61BIffPU0oVIjgpkrxfoc7KqX3cRbwXT4VloSGRdZzwj8= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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] =3D 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 independ= ent 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; }; =20 @@ -320,16 +319,15 @@ static bool rcar_gen3_is_any_rphy_initialized(struct = rcar_gen3_chan *ch) return false; } =20 -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 *c= h) { - int i; - - for (i =3D 0; i < NUM_OF_PHYS; i++) { - if (ch->rphys[i].otg_initialized) - return false; + for (enum rcar_gen3_phy_index i =3D PHY_INDEX_BOTH_HC; i <=3D PHY_INDEX_E= HCI; + i++) { + if (ch->rphys[i].initialized) + return true; } =20 - return true; + return false; } =20 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 de= vice_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; =20 - 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; =20 if (sysfs_streq(buf, "host")) @@ -389,7 +387,7 @@ static ssize_t role_show(struct device *dev, struct dev= ice_attribute *attr, { struct rcar_gen3_chan *ch =3D dev_get_drvdata(dev); =20 - 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; =20 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 *c= h) void __iomem *usb2_base =3D ch->base; u32 val; =20 + 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 =3D readl(usb2_base + USB2_LINECTRL1); val =3D (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); =20 - /* Initialize otg part */ - if (channel->is_otg_channel) { - if (rcar_gen3_needs_init_otg(channel)) - rcar_gen3_init_otg(channel); - rphy->otg_initialized =3D true; - } + /* Initialize otg part (only if we initialize a PHY with IRQs). */ + if (rphy->int_enable_bits) + rcar_gen3_init_otg(channel); =20 rphy->initialized =3D true; =20 @@ -486,9 +484,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) =20 rphy->initialized =3D false; =20 - if (channel->is_otg_channel) - rphy->otg_initialized =3D false; - val =3D readl(usb2_base + USB2_INT_ENABLE); val &=3D ~rphy->int_enable_bits; if (!rcar_gen3_is_any_rphy_initialized(channel)) --=20 2.43.0 From nobody Mon Feb 9 10:52:18 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 1A1662676F9 for ; Tue, 25 Feb 2025 10:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481160; cv=none; b=ffeCth4U7FS6l+b9lOUpBpKhjRIEVfF11URNN1t7pFVtBIeTnJrUoEcWGgOtvXIUTroDrVQ8aPuSRlWP5p88N4dyCf3bRPLmUaCOaXzGJ1mt9LjV2gUi7GEwywumB3XPRfdEeDsqe4qzDThMV49ZeI5M8w/2PvQ8I2tf3unB920= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481160; c=relaxed/simple; bh=q4+rbjdozfqJae8haxIluthHFrTaZjDmIslxIv4pu6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MOCuWVdwqY75OR90DR6LdV0i2T16RudjM4CTihrGjtscf8Dpv0FVpIauIcsFOCkdIM3rg0reJul7tmwI3RcuJxT+7fRxTzJQH5pbWkWOzqfC/ghYt8sNL0mu2DDpi2ffpETKbr1DvB8Y/UlomuDClId86iNektaFlJdS2IxjCXU= 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=M+NAZZ3W; arc=none smtp.client-ip=209.85.221.43 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="M+NAZZ3W" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-38f6475f747so2489682f8f.3 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=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=sfEy8KyELUmcQMIeUv/rU8Wl18U2U4X/a9mtDNA/tmQ=; b=M+NAZZ3WgfVCYZzZKpmCmoUaXpCpqPDcKtnW7EfaqpCoNAZigz9xP3Tzmc984FQ+wL vtx8uHrFsYcusqdHvbnELh4q1q+DRIR5Eqv+86Rg47LWntdajlhQa1KLVy5zIqqYmx9v CF2bixLKWGwW09Ce26J3fva09/DPF5J/IzKT7N9qp2BDfhJzwuwHurUUj1PKRyqbtFR5 CejYkSoJ7h52onlFn5Wawf5w3ZYNRmoEVtdkJuB7q/H5OdNCTajxkU25AHa4CZ4+olZ3 g4zynTpdyaXTtEi3LAQ5tlBYoBFdEqgfTDA7dS4OiexeJVQSViJ7xbCgaBJJ8jLVzjfy iyGg== 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=GrTvk+7JlGYKTFoTVR7E92uZEuzt6pX3HOTVvnKlts/61weOzoRNN76bnD9GXdZ+72 0ZTwvrYJVl8x1EQlTvDHLFtxATpJyj3DTwE7n2dBYLi2XSZMxgGL9QqeTsJ9M6tVmVlD NNWVBffsSNvgBRTpN5gM/gKMbeLFadjfNIhNqLEov23oMveluwTaOkNA6bRrzh8VPIbP ud7wH/rPM48uyrPet4Jd3a9GAiF5fQX59ci1xfNAdJ0SuuTaYYx/fRr6M7Km/pdbMwpc ywdE28oX/jUXuYuDTOy5nqOn8DEEGgqESeO4cxFLrRUXrDSlC13EsKO8XMUHpJm4ldSa af0g== X-Forwarded-Encrypted: i=1; AJvYcCXNke/iAANgsB0Th7rPyopzj0qZ+fjxYHR1d4ojVa4LEJabwIxRSRM5RXkhazGBi6vqVz4L201ViakP96Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxJ/tQd6iz0xg5MbqtCTzjXKZt17D5cW4+3Gzvn0yd/sbYkDwsJ ylehWLoIfm6Nw89gFCubh+dRSwZH0cSL9XVBA/geRwGvr+6JBjiaAsgetZWgPGkHHabO7P4nDNJ 3aiI= X-Gm-Gg: ASbGnctRiS6ieityuQzzlO4cMaj8X+Z41c/CXQmruUaSSgT7mZGd3wk1ZISnMaUXkDf fIdeqt4K0fViCP3hVln56MYiTDdO48SG9Lp+7SBhFmtXtzDuR/GhGnYjO/A586LQ7Tv+A7x3lTK 6tF3zr5o53Kim6njQYssl7Hmyju8G+tQmLxFY3ciOgZjv9ShNRBbH3mRohrDk0VsBfNlvyCYghG 1PLZtSESwA+Bd/kSmZn4TV2yB9RB7/l5ElMGIF2goBjhBVLeLrho0FkCGW2yPMOLZfZGK8TrtVs Hm8mZJ5drngbVIFOrQGWueQy5pe8/8DfVLxD8Am6KiO6iyxu2fP+MOk= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, vo= id *_ch) { struct rcar_gen3_chan *ch =3D _ch; void __iomem *usb2_base =3D ch->base; - u32 status =3D readl(usb2_base + USB2_OBINTSTA); + struct device *dev =3D ch->dev; irqreturn_t ret =3D IRQ_NONE; + u32 status; =20 + pm_runtime_get_noresume(dev); + + if (pm_runtime_suspended(dev)) + goto rpm_put; + + status =3D 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 =3D IRQ_HANDLED; } =20 +rpm_put: + pm_runtime_put_noidle(dev); return ret; } =20 @@ -447,17 +455,6 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) struct rcar_gen3_chan *channel =3D rphy->ch; void __iomem *usb2_base =3D channel->base; u32 val; - int ret; - - if (!rcar_gen3_is_any_rphy_initialized(channel) && channel->irq >=3D 0) { - INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); - ret =3D 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; - } - } =20 /* Initialize USB2 part */ val =3D readl(usb2_base + USB2_INT_ENABLE); @@ -490,9 +487,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &=3D ~USB2_INT_ENABLE_UCOM_INTEN; writel(val, usb2_base + USB2_INT_ENABLE); =20 - if (channel->irq >=3D 0 && !rcar_gen3_is_any_rphy_initialized(channel)) - free_irq(channel->irq, channel); - return 0; } =20 @@ -698,7 +692,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_dev= ice *pdev) struct device *dev =3D &pdev->dev; struct rcar_gen3_chan *channel; struct phy_provider *provider; - int ret =3D 0, i; + int ret =3D 0, i, irq; =20 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_dev= ice *pdev) return PTR_ERR(channel->base); =20 channel->obint_enable_bits =3D USB2_OBINT_BITS; - /* get irq number here and request_irq for OTG in phy_init */ - channel->irq =3D platform_get_irq_optional(pdev, 0); channel->dr_mode =3D rcar_gen3_get_dr_mode(dev->of_node); if (channel->dr_mode !=3D USB_DR_MODE_UNKNOWN) { channel->is_otg_channel =3D true; @@ -784,6 +776,20 @@ static int rcar_gen3_phy_usb2_probe(struct platform_de= vice *pdev) channel->vbus =3D NULL; } =20 + irq =3D platform_get_irq_optional(pdev, 0); + if (irq =3D=3D -EPROBE_DEFER) { + ret =3D -EPROBE_DEFER; + goto error; + } else if (irq >=3D 0) { + INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); + ret =3D 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 =3D devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); if (IS_ERR(provider)) { dev_err(dev, "Failed to register PHY provider\n"); --=20 2.43.0 From nobody Mon Feb 9 10:52:18 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 6A031267708 for ; Tue, 25 Feb 2025 10:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481162; cv=none; b=onjSqpZoSLMR2HrNvzGf5GuTT1d2u4H1A4VHJSVp+OdWxcnUHrnKg3d46pOdPi0YZckpjQRHZAHEshcQCOeuIRAAyX0M1KwSymNdNCUYvs0SbmkJeUgeUdKI+Gof2u3Vo3odEPmig1J0tt0NdGsd3gwsx+v81bl10wTP2lgY5VU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481162; c=relaxed/simple; bh=PAej6HiOIJnD3H8JGnZM2j0gT+XUHSn7Hk7wBnY1sPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMqVIXeUwl3zX4RpI87hg5iiWNkFgt2kFTFUdiGWsTQJIT3SEkfirobN7QlpDXSrPK+lYSFQAt6DXGUC/A0GQ1YpFU9stEfEaEnLhPf9MGX3ZjlIK+mAdmMryfoDnKwVlvgXEzeePvLW5OGuQYQq9qhMj+F7gSgcRzAgA6RFWo4= 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=CfcZyu0d; arc=none smtp.client-ip=209.85.128.41 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="CfcZyu0d" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-439350f1a0bso32350025e9.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=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=BxEGGaill+3QT6cynJkChqHPKlrdFel9L50qblkRAYs=; b=CfcZyu0dk9q2jRI/p/58XExd/N3XT+5Zsy58XWFOKHO2TMlVw171i+CZAWD8k6QIlk 4v8e+WeP5eJYHFWQjafzgEwwXkuVnbre9tIArSE9dAHifBjxk0EkujkFjnf9YwjtjSxy fKpUWc7ORklQtnQKhqDDaHUOFTQvWlU+RAYsbgTWYHnv58uIcb2Ij2fJo/IswO/oape8 FYp75p7+thl7LwsZHV9dEKSqkY+lsxYa9k6KzuXz6yejFzI68IhVyD971hSo0OOcglyP cIwxE7CmFG/pKd4biQQMes/hSqhVgQLFyJsEfz2xJJuo2LEuPbJyXafpFShSBzyY5zn8 /59w== 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=kpJ0KrWxrxbHgGCmLK7PFaXAg6JWjME86DID1W0XKEst9YKuaklG7a4jPjl0guMEw8 VMRwsYErR3AS4qT1eYtI6W+bmpg6Aqoq4+cE5hqOuwHR+enlnfKYSkCIVhJF3WenXB2G XNip/SRFMpySHY3L3XjMCNKvkzrvNOU5/3EkxsUuULTLKimEKVa3iO9JE3GEvCk24uWj 4kK1FaOuDfmYqoZKPNSKNLjjWw0yz3Si3Xh5AEq4hu4fbDxDcfqXa+hRwsSxEIJsnUeC H91dk2dCYRAGRLkNyE3XmS4vUHMt2GtbBGePGju5jtm7zRyn8bj9REy1Tp6D19fXsPXU akpg== X-Forwarded-Encrypted: i=1; AJvYcCUySYLDYtGBb44PL4ZMCOyAE0cq4vKhFDHeAFP2f01Dumuo8mo42GAt0d6Y7sYWB0XnLJfi8nZ3AcwBlak=@vger.kernel.org X-Gm-Message-State: AOJu0YxB4/pu+nDDZhR1PYomNkpRttroPiVJBzIIWyh/I6+gzPt6biiB l5d6rwPpRkHj6Y8iRinFJmrnMl2vWQWwMBYdk2ZoN6b/OgeSN8PWy9WQ568QzSk= X-Gm-Gg: ASbGncuFOrVbHxkwGFxX3poCmb8sEehBVyYvcSENioXCnSD0vfQLxRaxfKxv7u8WePB W1CRx1YTruXUjRdAqJZ+gMDfMRQClCyqLixvhzdKgalskaV5k9Wp3YaHWX2dZKprunSZDW6iSz7 MQhX2SJNPDNZZCXYReBHoMedzfB8/EqfvvOf+ZP0pFlzy9tE0YeVmyzNwFlm7RPIguOccZxqw9w 0tgG+msKwkKnvdq3gcFUeYSiacTWCrC6nFz7v2zNd8nMbbTxoiFLGLrbbEpGsAwquEFORIG/bVh 4FJmw2L4qv48ewqAZt+5pJVNR8pADYKNqfaiN450p9r1QJw9WrQrqbE= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. */ =20 +#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 de= vice_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; =20 + guard(spinlock_irqsave)(&ch->lock); + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; =20 @@ -415,7 +418,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *c= h) val =3D readl(usb2_base + USB2_ADPCTRL); writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); } - msleep(20); + mdelay(20); =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, vo= id *_ch) if (pm_runtime_suspended(dev)) goto rpm_put; =20 - status =3D 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 =3D IRQ_HANDLED; + scoped_guard(spinlock, &ch->lock) { + status =3D 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 =3D IRQ_HANDLED; + } } =20 rpm_put: @@ -456,6 +461,8 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) void __iomem *usb2_base =3D channel->base; u32 val; =20 + guard(spinlock_irqsave)(&channel->lock); + /* Initialize USB2 part */ val =3D readl(usb2_base + USB2_INT_ENABLE); val |=3D 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 =3D channel->base; u32 val; =20 + guard(spinlock_irqsave)(&channel->lock); + rphy->initialized =3D false; =20 val =3D 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 =3D 0; =20 - mutex_lock(&channel->lock); - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; - if (channel->vbus) { ret =3D regulator_enable(channel->vbus); if (ret) - goto out; + return ret; } =20 + guard(spinlock_irqsave)(&channel->lock); + + if (!rcar_gen3_are_all_rphys_power_off(channel)) + goto out; + val =3D readl(usb2_base + USB2_USBCTR); val |=3D 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 =3D true; - mutex_unlock(&channel->lock); =20 return 0; } @@ -528,18 +537,12 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel =3D rphy->ch; int ret =3D 0; =20 - mutex_lock(&channel->lock); - rphy->powered =3D false; - - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; + scoped_guard(spinlock_irqsave, &channel->lock) + rphy->powered =3D false; =20 if (channel->vbus) ret =3D regulator_disable(channel->vbus); =20 -out: - mutex_unlock(&channel->lock); - return ret; } =20 @@ -750,7 +753,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_dev= ice *pdev) if (phy_data->no_adp_ctrl) channel->obint_enable_bits =3D USB2_OBINT_IDCHG_EN; =20 - mutex_init(&channel->lock); + spin_lock_init(&channel->lock); for (i =3D 0; i < NUM_OF_PHYS; i++) { channel->rphys[i].phy =3D devm_phy_create(dev, NULL, phy_data->phy_usb2_ops); --=20 2.43.0 From nobody Mon Feb 9 10:52:18 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 32F76267B0E for ; Tue, 25 Feb 2025 10:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481164; cv=none; b=VQ4wjeAhH6/ptaj5sz/ZYr2OEZqbZyOnKt12L4CLaSxqSS3mHP5b+BK5hyLCstgXMZ3d413AWtkqLHDdcMAWE5ppmMg+TMPr8lQAxJoUoOyDfLYcRJ+4VjgkovV0peNGagzNlbtE/e8uJ0sL414BnK20WVh9WMqB84/G5RibCZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481164; c=relaxed/simple; bh=y651O+anxjWjbDnEXvCcVWHQZHRy4LozMZWKz+3pUNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dT0F5mz4vHxR/e8f4NwpIkcSBVMxwNz6fXy+Vhp0kdz13jSLj4YnpOfs/CmBHD0xdEIYE3IaJBlsti7h/BHy3AIm7yyBe7Wl3QTzhTTVlbhPvyIQeXcFWzRAnydtRqnE+Vc4nnLUIcQVAhOmEqhRYz6IslGH9/VLMDGD6DeCzOA= 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=ObSs2RLa; arc=none smtp.client-ip=209.85.128.47 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="ObSs2RLa" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43995b907cfso33572175e9.3 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=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=gvELEwWWQBEiORRake36OoQXvOrT2uHpRxrgYMRnO6c=; b=ObSs2RLaSgSSHKZMiGnoxHB9p0S/lH1Y5LQW5wV7NtkXcrxrPOhIYIgsl7Fm1Zzr+V iYIhjJlqTrb8CcaUiOW0By0MLacCQYbtOtW+kX0D2w72Fk90o2k9XTPtlCP+ooPzIX+N ggK8ZrrXZ4oZI3Jnx77wy09ujasS1kIYT92NynJG6agjrYWIHyvLoUT6bd98nKgWCMZN CL0T4YHdjGk0MM/0GgtQ0ui8CbvgneaE7r1EdsoVpShy72sAhwtPE9+o0BOqpH0/SX1h DArO3nc4xJWkWaYRFmZXbkoTYgTXUcxkljA87kutaoBExceFKShwnj237R0ve+OmmkEE LGYA== 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=g4hSpuLatOG951JfQFABtxnwQYB2U8nVNrKr37k3I/mUwK92VqH7hUBpGDJvVosUzK 1JG3saR3VQ8gRgY/xyFQV9bd1c8RjGzPvIVW0AnCA6e7cD7e+uC4ebEiVirEhnClwm00 TOBwuUHVJlIQ7vzyhEmW67i6N3ydUDogsZm2TnYJ8ljvYQVdMddFSfQgnGVwbHevdjwi dxfVhh6ozwwAfJPNT9IImF5J5UuPwq85dwDFNCCLUAa0BO7lapfR08ce6q5ofQ3TxPpw ZQmeRg0H6SqsZdkZgvBfqr9Lf1L2ZRMBpATjwu3VmsEIc8G2s5Z3A4IA5ixQvioJ4X5h VWnQ== X-Forwarded-Encrypted: i=1; AJvYcCWPM3yTr1F73fdXQcN4K/uLJknEshEqp5MyocLrxt8uibVYGdj5e5D7xkgd9ap2rjj66789K8GjmoM4XeY=@vger.kernel.org X-Gm-Message-State: AOJu0YzdUS7C6G6fMzoX4XXPz71kjbdf3ExSVDt0Wq5ZSLzWFZYqbrHj rLanbO74v+LPAp5zwOLQ6qwe4w0D8kE1G4PlF7GTB1SZ7a9K3MMwaX0pjFPTbw8= X-Gm-Gg: ASbGncsiAD2uD4MNMzSAsgOyz6euOYisK+4sbBJVF8BEujQ9F7QxvgASLZESizTZfH7 TuyEsPSCic0ZIAiSW4oHkqCR6sa8HpaBH9lQI1EFtSbJPBja7h/IYEHTwviiM72/cxnnN6hwuj2 myC6x1QulJcZk9uDXwGvQmSl5ZqBbI4DylavfnMGom6gIjIZQn1pX/mSuZlYpSH6tpLIKTMdIsx jRDZglxWJfEccJlWIVzoFXsgQS6rqQ18XnC0lugd31BEwRSfEEYnwTZK2GUxf4UlnlZJsmw6qpb L4sbLdTAP6Xbn5O8+mzAixcrJZbCeB0auaWwtXszj9pQXLrQiUKsiK0= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D rphy->ch; int ret =3D 0; =20 - scoped_guard(spinlock_irqsave, &channel->lock) + scoped_guard(spinlock_irqsave, &channel->lock) { rphy->powered =3D false; =20 + if (rcar_gen3_are_all_rphys_power_off(channel)) { + u32 val =3D readl(channel->base + USB2_USBCTR); + + val |=3D USB2_USBCTR_PLL_RST; + writel(val, channel->base + USB2_USBCTR); + } + } + if (channel->vbus) ret =3D regulator_disable(channel->vbus); =20 --=20 2.43.0 From nobody Mon Feb 9 10:52:18 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 7EB94267B71 for ; Tue, 25 Feb 2025 10:59:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481165; cv=none; b=iAZis7tAMoi5c8wANMLoZgYf7BVcw/yBBIRhR0wiUYpQvHmXy60Clm6fFGxRVs9QPfWla6P3AIAzzs3dr4Z9apt/D6nnIG56pRUzSacK560qnfj4GEaX6OB/upeXIqO0xcPc+5HuYn8PuWL5D6YALf8i1arpjNBGNTg9svG4Ddc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740481165; c=relaxed/simple; bh=LfDfyXvE/k/3wAGzTHexcKD+CL/7mAcO9M0iYyr9AMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VdC+mBKPEB6E7vqEzoU+sijqryx+Ibvuq1wLCDahfw0p400Ole5Dd5Pcgc75PvDJKO978dlDKe2cBlc7jERvokD1Qe4qmiQzcTR4YomOyCkJ6drQ+Oiryb+S09ELnC3lam6ZjaZ3d0yTvGXFJNRTsZAxW5DFlnFbovXZFR04ODA= 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=SQFfGtrq; arc=none smtp.client-ip=209.85.128.44 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="SQFfGtrq" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43998deed24so51470215e9.2 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=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=SvjAeJYy02UXwEIBH2Mapc2zFP4oPiRLlb+kj3I0bAc=; b=SQFfGtrqStETV0emOtuM5j6SAPam0pIRGci1TVIYL/ZilkOaLL/AvIJUjp3j9/h6St BUVRTOoXi8K+sfWfAqzjZ4OSrti9af3657dYNjbAVMeaBIon5lIQJUDsMffMTDdw3yWw SLN+EKHmWuXtIxZ1QMsHgeqMQYWeIMB9LWNk6AShlFfDzQE19FS9/MpX3m+MSNTvibrE AgK6uirXm20xX12yPsaLMJlMFFkh5yU3l4H7hclPUa7zwQaxJ1TNBJoxH9/xg890mrT+ rDsUbtIz+q66ljha1zLXONPjJa6qx4A7Chinr2cZJ2MPa98oJoKuqixIk3kPbmX7kbpU ny3w== 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=kjzILJMoODYXgvwKSfdHHer1XFuqnl1AKWerTR2TlMNpBHhnEdUvBdwmRQrbqV5TQt oo1PrRVXJ+CTMkVoAXKQNoGjYm6L48GoszVTbd0Sov+YXOfKSd2I46DvdSZnQWpf7B5M ecQlV2UOQ5QEo+b1FfY34rHO9iS7h8nTAVuOGUyOAXILse289xZ9cxfcO1khrkUBH0j1 RcbXsVW1FsmimCvv1wiog2GclVip+1xpw2jtkpXsd9U6AT398s0MEbzn7LqXgToHGoYL oLFVKjYUsfXjDQ00ocgQqnFdEwFg6uXeADbKTvc01lJ4ZXNaHGTz3TNWbwc4hIzFutC8 TcUw== X-Forwarded-Encrypted: i=1; AJvYcCWGEowL0IXw9Tm+6/FR9jhPirJMk7VbLDpJU+/R1wz/9gfzPSn6kJpiFxrhkfJnPeGCVslUnrzTP4xjufs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw71wJLS4UxjmSORGvFfQCThs2FqGuzuX0+aKrm4VOd4fT8YiIn u9pJ8FSGJMTrFu9/4pnFnPFhTJhHAH+zcaYIeZe7Q4ktRz/+ujTc1IrqXFfgHKA= X-Gm-Gg: ASbGncvUZN4+diR4WrleSsfQY63XbsspyjfP+xEc1H0bE8h/t7xX0bc5G2Gk7HFY1QL R49KJ+MdRMq2/jFMYOArrSB4ydN325F12z/wrLr+I4O7Voje7M2CHXwWdiiWNi7ssjWK/z7TBPN fn6TyvNORez+7VGbJ7VwsQKAxFDiS/pe249jm8A2tyHSXDT1Ak+3e2Ay3JuMM2W34gbfRZTG0VL F00pSpLMt7jVYJx34mhcgeATaE56T990T+a8yCIAvnLRg8sb0jfUnBDLc8zon7cRPeV9L5iUn+Z KHfrRXV/HeYDWjdiFGDFpdBsO+k/c7nyIhYPnVqyYdA+Teg6KVfR2FM= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D readl(usb2_base + USB2_INT_ENABLE); val |=3D 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); + } =20 /* Initialize otg part (only if we initialize a PHY with IRQs). */ if (rphy->int_enable_bits) --=20 2.43.0