From nobody Mon Feb 9 13:37:56 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 3CA1A1FCF44 for ; Tue, 4 Mar 2025 10:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085316; cv=none; b=MeLDYA/VMghrhcgMv+OiCNh3YrbgXFJc05uUnU6gEB6cgqIyGFHaea1t65r0EMLSn0io8PkG9JNVWagTwO5hSEquE+1dkgYAhQWpd33Qg5WRRLp9gSuJaX6Sv3KzzKlKFEXKhNU+d9AZi0Y8HP4ER/cM3y/vzNoNWanX22kndw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085316; c=relaxed/simple; bh=L+7igWmrzB3MXXLwtuLEyjoA6CAq6ItWg62jIUmYSgc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9NVWNgrsuSxqODTZv4HHMajTOmK3cQcqvwO9cCo45GwJwwsyI0ajFW1Y3PdcEjySiKfShwwtMqfDrvbG8rImzUlKPDeLQNJrgkYHyWAiNNeV/pxnxPj4RDuacY7jlQ9Tg1kMSSQ3rzBNlGPIvBBZtCf36ULRNxatXULiUp+WTw= 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=I/F1BWbC; arc=none smtp.client-ip=209.85.221.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="I/F1BWbC" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-390e3b3d432so3699087f8f.2 for ; Tue, 04 Mar 2025 02:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085312; x=1741690112; 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=gjhb9oVUG8lj7hYYtmkJhzYs0Q2lzrIfIpH+FDRUtb4=; b=I/F1BWbCFVw+I/jrTwmST+Bu+dHeRKJPywxM9ZLgUPrq6nj9E5LtC0nS+YdiH4emHa MoNon0wD5OFzQ8sRCLxmsg2sIDlQ7oRihoIf2Fil2LtofYoHM+peDllgjhyeJ+2eD8r+ VNaYBbmn17XykKvpkuBK3dqhfMUDce9IfjyJyclGQv1kahwK1eksmY9jNiAP+F+5N0e7 mVpog/qLpjGPZjy+g87pbiYZN9x0N4IZnmMAuBemnI5vxPZ89fYcoIln6rYO60lY533i WgNMsa6Uj/Ohi6pJ7akstsuEaxoQ5YSA5C5Y2u6MP3QebydSRtO0SKQh4mf2n0eX7vgb 3avg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085312; x=1741690112; 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=gjhb9oVUG8lj7hYYtmkJhzYs0Q2lzrIfIpH+FDRUtb4=; b=S/got+4huiY6Qbk+cxM2QjBwopiZSqLkahNyFp9BdrXibRl/0eTWJniahnNmlkxGWF h4MptS0N9npCjgzMcvJXh8EuJP7PJxQxNtdRrbtkVYDa64osch9asd83M3Alt+VsrGXL WUNuVrf/Qkbb6a+CKYLGStYhuWrM86lAw5CdR1pBUZik+L3azBXnIwjIxn3LTVJZJSto yuNMGlgQb1+6uWrYfkEM+qdAxd+UWeepIbWNj206lUhKLf2o/lhCSsPDjFAyCNIXkLB6 qo1k9gkIIEtfrakqqHqk1eDL0iH68RO81XzVAepkhhJqGjxJM8JRmQR0emBh/VYK8Jpr Gn8Q== X-Forwarded-Encrypted: i=1; AJvYcCUQ4/V+QXr0oa1JPqFgNvfkQeD+zkU4Uqyy4yjMmNtVCya/IzTcGiZrKU77M8UFllvjuuXMz92HDWSrr3M=@vger.kernel.org X-Gm-Message-State: AOJu0YyOHffKjd/KtUTu9uxhYHDODMu54W5PYxh3VadZbqaAjaunzZXo btzRi53ETZ6CfTn+4Bhk/lwHbDKMkkdOWrb2sfCbNAbPTSLUukHOWyW3kKM5eK4= X-Gm-Gg: ASbGncuVjil6zJFKCZHSN7fWtII7OSa9Jxia13vzD4xeRLFp3ZUD/KURYQSv094WqF+ L5QLP8uUOoWe7BR8yI4xurGdUf14dDRFJAEHmZDySvwtb+oGjqGKIHwsz/suL3oOrLlIfKuwLn5 asqSkIgKqE4+8+w7JFRkicAKlYD0P0BWzw7YuNWvjD9M/zBqUt42AAA63aSBWIQSd6ndtyZIW6c c2znMnoNuQjhO0Y4fqFNG7gx64ys3L/NGzLE5zTtYebpHiIA0LjVNKaWuER9+W7/46V4rTBDn9b LbbtnYjyIZLJruwwU8GT6Q0a7QOXO32L44H3M+OJrjbqsmcaob9XSF4JrGX9pSR7gPE1GDBDot8 = X-Google-Smtp-Source: AGHT+IHcts+Ef7abJwxoLgkZw98QU7H40GbI3oB8YyXxlG8MEQq/0M2R29xPjCZcGAJReffYT0xshg== X-Received: by 2002:a5d:64a6:0:b0:390:e889:d1d7 with SMTP id ffacd0b85a97d-390ec7cc71amr13636577f8f.13.1741085312528; Tue, 04 Mar 2025 02:48:32 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.138]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e4844a38sm17445161f8f.75.2025.03.04.02.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 02:48:32 -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, Lad Prabhakar Subject: [PATCH v3 1/5] phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind Date: Tue, 4 Mar 2025 12:48:22 +0200 Message-ID: <20250304104826.4173394-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304104826.4173394-1-claudiu.beznea.uj@bp.renesas.com> References: <20250304104826.4173394-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 Reviewed-by: Lad Prabhakar Signed-off-by: Claudiu Beznea --- Changes in v3: - collected tags 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 13:37:56 2026 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 BC21A1FECA0 for ; Tue, 4 Mar 2025 10:48:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085317; cv=none; b=sg0BqPItfVtyA4b8UJ3Kg68QqukoOEkFatbzRI7ZQrgJlzG8OOCLsmUVRIANIdpUvd2vc95Fx4mx5AcnB9TTK0Gytiwugf8v6ZCxLliw0ugO80B3oyDAOc4jFBKTHhnwlPcRKbJ5gZJ2Uzr/dd0JpY00NyC9LSjMr2MfW5TdePk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085317; c=relaxed/simple; bh=6XOq/M+XcFhFyAFXJn5ArmBoZcCZLFmoNv6AJ6fQLYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FVQCFIlgrBgqDjzhlRf0X4QuVhIMzSNgP29BlyErmwheFazvJ7J1Haw/Rfa8BTrjVKYWHFX+5rW+FSWoHoCh3GolzThAiwLGSlW6YSXnx8nuTSjfhGOld2vh73Yy9kYg21O2vOP7fmr1isKCK324URlVeCm9sdsUjM24IJa6img= 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=kdeb2FnC; arc=none smtp.client-ip=209.85.221.54 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="kdeb2FnC" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-390df942558so4264924f8f.2 for ; Tue, 04 Mar 2025 02:48:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085314; x=1741690114; 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=W/PMmHSSgrlCrvi+Z+rq9GWww30g00UqAegwGTUTxi4=; b=kdeb2FnCuJtkRQLkbsIMBilIv9UeBPDpd1P9yhlw4DFkmE+/uMCj04jKZAq1yrXSXM +9Dbdb1qpNNesZrU28R+yIXuBVFdYfUU6Qc2tRsaaOyl0sd5qIDE1Zhod4c2+7lZ6Atd NUDoh/MlCyzxFdwUGJD1ySMZeQ7VXszRtajGIgPdMzMTAczEcnYVYIbTG2ja59r4ZulQ qbuDSX1Lq8FZQpb9yeWEVh3aCHvOlfEE5u40w+Q8+67AVXpVraKys8yPm/WMhjCXM6zv SAs5O9ZOC2qmIuwPLHRB7Yx91dmgCGqccNooyEXt4+B0cIeP4Hkm7melcU8VvKBHyQR4 yAdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085314; x=1741690114; 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=W/PMmHSSgrlCrvi+Z+rq9GWww30g00UqAegwGTUTxi4=; b=Fb2m9a802xoFbY1rjaktql2LiK96tUFqQeTiD5U+jKXqJW20gvPOI3r+37GlMzSVWQ c9Le4wAAkuav1HBWHrA6PfKjZ5Cb2LqnBzxUGAsfXbWYV5zrNjUL6vnAeIKbzfnrx0Gi Z52M3wNvDF4X4QbvWFIS4sIoenFo19mYeI80ElZg5q7NvzLJ11dDW5X9n+GuKJ9vq2NZ g5KoeR1Um8Ljxe/rzU5o6guxrFM40fpxtkuamb4mUPXeV8S8ZY4ETsbLo98Kz5/1Q32v 5yOwR6AY6+ZhZd5mZJRFAlmkfTdad5zOdpA4wJ47+bcYQ3fAORC5vdWAV67cPRIwIGIX K8/A== X-Forwarded-Encrypted: i=1; AJvYcCUVcy5Nx4CQwXjFtDTDsynrvuye6SzFrGT7+BpAjpeO1jLBL2AsrGbvWYGzCOC+FmqGlEsY6npSnPIVWR8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7K7rY191j7bPbVi1HQ82Wequ+SqfkQobm7/KVxUah3LkkS69y WqeWbWdJJYNEoNCuobKZAMS5sKBISAh3Mx2fibf5IVIolTD3xqQALCFe+awDjak= X-Gm-Gg: ASbGncttqUVk4Mtdop7JSss/6WC5ME2IfG17UANw9kd2anECEnt9r2FV3eqg2ZBIq8g /oJr8r6cexdkwukw7XUKVJyAvO2XuX2aHLfnuWjedcFrysvK04Cn05tXqsJ0uq/YekcIabK4Rwu G1MQimZh3u0316Tapdmi/DvG70QK/Yt25mw3zgaPifBDpzZ92gPh33Tq5E3dCjbkv65om1TR8Gc N15lG7cGsTgvGXg8++n0rNNcesXOfcfDIDKv6XQ78yldCaJa3fT6NdiG0KfEmR/ONxbKDrvNRqB PKj4w9tq6cwVasxEWBxNClMUBW/16TROeVcjMbXijHMtLPFDL3ZNCHZMDlE7gKwB+/4rHZ32zf8 = X-Google-Smtp-Source: AGHT+IE9ccipZ/vJcPu505efAkF7yf7WoH8ct+Sjo72HUD2EpUvUGGCqBeJyxUkzLqpZgdAQEy483w== X-Received: by 2002:a05:6000:2101:b0:390:f745:bbfb with SMTP id ffacd0b85a97d-390f745bc4dmr7682113f8f.26.1741085314058; Tue, 04 Mar 2025 02:48:34 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.138]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e4844a38sm17445161f8f.75.2025.03.04.02.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 02:48:33 -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 , Lad Prabhakar Subject: [PATCH v3 2/5] phy: renesas: rcar-gen3-usb2: Move IRQ request in probe Date: Tue, 4 Mar 2025 12:48:23 +0200 Message-ID: <20250304104826.4173394-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304104826.4173394-1-claudiu.beznea.uj@bp.renesas.com> References: <20250304104826.4173394-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 Reviewed-by: Lad Prabhakar Signed-off-by: Claudiu Beznea --- Changes in v3: - collected tags - improve the validation on the value returned by platform_get_irq_optional() 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..aa9f301b5acb 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 < 0 && irq !=3D -ENXIO) { + ret =3D irq; + goto error; + } else if (irq > 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 13:37:56 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 2D7D31FCCF7 for ; Tue, 4 Mar 2025 10:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085319; cv=none; b=fFATJ20pAGwnFWUrPXdprxGnqf9IWegNpROyVWNFoQv3TvQwuiBvFt16o//fxSbnL4iHRXf3PZuva5sKqjbNNoryrh3Z22rBC9bPPDEHI23I3fNXiLRds2D4cSnTE+3W+JPP2VfjcSiYs4ileKjIzeerbTa0lb5TChdI9A9JzfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085319; c=relaxed/simple; bh=bLz2dLr/cGG8RPcAaUZ6uYH3MnmoIVfXAgqhQmzHmFE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aKJeJnvLuc5iRa15VWet+n/J9y/UZ5+cx63Tz3lHiNo7QYQ73HHsGemP52z3YI+/SSTrPX62kE1Z8Xte7CX7NvlIHHJHGsOG2bVdfzAEqh/SnqIgUW2JLTfwi36DV/sUgNs/s+lOLbHt0WXzN9UDoXRxnU5iAaR0jPi7fnXf1oo= 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=Pw0w+0nS; arc=none smtp.client-ip=209.85.221.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="Pw0w+0nS" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-38f2f391864so3001354f8f.3 for ; Tue, 04 Mar 2025 02:48:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085315; x=1741690115; 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=X+HBRuptPWMkY7eoCKW8pYKKAMIwOR9RHunbpfasXUQ=; b=Pw0w+0nS6QxX2+8DTM60kOU2pzbRXjZH61VyRg7IcSB0Mr6XjswImCaOjKlfTTkRhS M1wKdpZ2gUtd/eUWgUB5aLKhZol7TW+DgaZHySwzxb1Ciiq1kODClwtpjl8yK0J+Fu8j cm9RSUB9iFpmccDuMP+4dKqkb6/4tT6HCl+FMkQA/vCbbfR6FlPtNLM6RfVTj25KZwB6 1CPzrqXMEF/xMByI8Sumxo7WhEORJmHyqLM74Ub+WtlHzzvND2/quBy8HlNtvWPeAWoc avaDAMvWKGIodHIkZTYKynYmrk25CV3LHCf5dVzM04Ufbw72F1mX0Uhs1LbWvOipKxdv beOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085315; x=1741690115; 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=X+HBRuptPWMkY7eoCKW8pYKKAMIwOR9RHunbpfasXUQ=; b=Ho72S2KiD1qEvtKGe5EQX6YzECRE6z13hhImOKIX5X4hzrZebQ0dnUT6AsovUeyJuy BYjdCIkcH99wZGMXdyScKCkkxX7xh1kRiuRCp3FwGTOk+Y61HNNAmlu6jpgAodqRwPd+ 6y/pvw573k5r52oZx3mwxrZRsrV4PVBBaxmYFNWrj47ZkU3aOIppVj7x4Y+yuTsz6hjx 9HTTnZ/Ss18p8KkvE8q6oD3WNSCiF7N7TywlbPe56hJN/Z6IhTcWsYI+/HmtN4gbNu6y lfLBCPXkwHMb6OxLIF5uN+Bx8bhct0ptlNDgkX04ytCTKrmDe4kNax5Y18GS9blqzDSz XEWw== X-Forwarded-Encrypted: i=1; AJvYcCULx5pZxgfB9+esaYBRH3OD+KZqYxO7bvyTzuknzK6Tz5DIrFJ50jnAZwOwnZPiI8ou16NXAWuZCLOKl9M=@vger.kernel.org X-Gm-Message-State: AOJu0YwfaajUhiiIt9bTMIgUpyELcf7LFTJH8WSmzOf7bLVBvF9kPjxb qRfKYzfnriNECSf1KarHhmbM2otl1IGV2kzz6n8yIYBw4pifcK0mKTS0LJyBYlA= X-Gm-Gg: ASbGnctZ6gfksa2w++oPpWMRFC/5S+jhO4tthmsdbLQh6Q/WHQpPA0xgBzyhM5gBrFT OQaM8C2J+TsCUL556KF4sBTYIfGi+ppqIkhbzGAWLuIS5+AniDGD+dhPfjDLrRQTpM6kgjhzd5o 90FR5gDfrv8H3BhBOlPA1nsmVAAhPl3f3tqMiKPqJhlXcoyDYvNh0ohtHnznJ8xf3u1TLPLXA7p 2xt91hHIRhASDdk8SCd2LnQX321lCH6chLEME0+wPUMuL7ZVCPIYAmnK5BNsZUBgiaQQu0LY2hC XVObETWWVFkznJkdebKEYaPHXeWtAlLmetnztiImfr2dmB0Kuq/ncK7qCmoJ5F91cgygIqgQGKI = X-Google-Smtp-Source: AGHT+IF9/8llLwlKLJv4R6tkEHSQztdJzVM+800HKQOjt9Km4g2NNYfuA8atR483A4u0BuM7XJAbYQ== X-Received: by 2002:a5d:6489:0:b0:390:f641:d8bb with SMTP id ffacd0b85a97d-390f641d990mr11217312f8f.36.1741085315383; Tue, 04 Mar 2025 02:48:35 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.138]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e4844a38sm17445161f8f.75.2025.03.04.02.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 02:48:35 -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, Lad Prabhakar Subject: [PATCH v3 3/5] phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data Date: Tue, 4 Mar 2025 12:48:24 +0200 Message-ID: <20250304104826.4173394-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304104826.4173394-1-claudiu.beznea.uj@bp.renesas.com> References: <20250304104826.4173394-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 Reviewed-by: Lad Prabhakar Signed-off-by: Claudiu Beznea --- Changes in v3: - collected tags 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 aa9f301b5acb..39c73399b039 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 13:37:56 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 5E8E71FF1A7 for ; Tue, 4 Mar 2025 10:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085320; cv=none; b=N8OZPkKGvSFDSEhcoWMtInHoZvTrvzuF/vSFcRHDpCygUTnt2XByv5KNjZxsBXCr3VdH53mpwrEOeRWOCSfIEAGlWH7ADvW+UHJsT+w05IupNwyYzGDL2hW38CIGFPub3K4RtVVxE/Q1Gnpm/tgsW54wV7uAQi2W7XmMg+2G+pU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085320; c=relaxed/simple; bh=Ed0whvbRiPMkWLTpCwW5FbR8zUZHMT6ELFO54H5wtf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KRprJkstrHRtlvKK6dQggJ9tYFrf3l7nif+DbpxBKiSqcgjHGTuqqsLIx0nC9vWaFlFuYihPO0O1/o8giJdqQ4pm5sjaiviW78XzSCoED2GoVo4mSK+tvx88TIa/nHTWUqjIbfMahW+RGlKPClSz1hBfY1u2NEATmGIbg8aLYK8= 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=GkcuVq+j; arc=none smtp.client-ip=209.85.221.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="GkcuVq+j" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-390e3b3d3bcso6490668f8f.3 for ; Tue, 04 Mar 2025 02:48:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085316; x=1741690116; 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=x5a4oKKcOuJdLssc/zk2DHBl5Am0SwZ1rfHw8fwtygc=; b=GkcuVq+jjfXFW83w2lqNS/SwZCCC6aWXX0sdUcMN/XfNXjin8ZefiNPxxQdc5GCOOG +zNOAygGIVSYD5GT+U85/S+eMB5D63kPI8+wnC1A9NHKmIG0IeqMP1Cpz/FI2VtrKx3l rTT5g3bPflVlNjuBQezjYIL/g3kkciomLBO4BGyb9FRY2EhUePJhFesAK/4rzEgs9vqG gFisLcdVJiTERnBtXXMN0/SKCUhaKFzFv2u94gjkzwRII8tJozlcWbkB3Gxv7wcMNOKR ln4j7p6BGDRxQpXKS4jFEynwnSX5uGjfsvR1RtFfS1CTizV1Z8JnbttSlrHTD0KKWoDH HhdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085316; x=1741690116; 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=x5a4oKKcOuJdLssc/zk2DHBl5Am0SwZ1rfHw8fwtygc=; b=bfuZmZL4P19oUCiioriw4c23nlZJ6U2GlZwXJYsishjL+FdjaqVjHg1Fc+jOGt8bHB ZCjBy0XbrJrjukgp0nhFoupv57n2QPgGOLxaQULxQcoHT4o47CZL6FYzcW1bhjxSFyP/ klPrwu+k3imIPZmFqHHqEkIGF2KMtLi4shmVfWu9Ib57ZVQPWXSZ2r4bGcXq0BG3bAtj f3LnQUl6utF7cachvAINCHCO65wyJVO91P5P5RuKkqwtNWAiSVShmZ48i7bzIAalFAXZ F6gqOLLjTX1HT0aD2CLoPq/wLKS5fog+Nw+pgYsWAVD5xPL+jUHPsKhsSOnRnUNG2YUh aSVQ== X-Forwarded-Encrypted: i=1; AJvYcCVkwD33gs2n1T84+KtbXZIDr72/pqtr033ublae30a3f4KuSsnOtyTyMikYbV38tgt5I5bgfHDVOX+WC8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzGooHz1RNg7m7/MoP0xWsZxyLjThm+NYO7p4F4vT2NKW1wMyUM KlVIgGaHYlzJ/198+mhMEWTowUBrz+tG/C7hAvTcXr+uImHD0TadHiPFC2VclGI= X-Gm-Gg: ASbGncuoYvpqHsgwdVuTx/L+h/tD52rEMiljuetg/PBxnJTK2NF8KsUps8vHAkmhWNk /2/ju5xyF1NIrHx1jFNhYAmsqKWhMdgwhEsJJ+NcUiekVgHqPpMQiNGdz/wJ0Fy5LCMpOBU7PLK khCB2JGC1Uti7lyUsAoMZGSXElsF/CtuSPferrdTP5EgZBaVUqQNKCFw1Pc81vbCfnReXL6g5HP CZPBINUST1led2ZQMwdsjlHRZyDzlCMGwo2nEfOZ6r1+f9B3iFWazCXhC43Cx0MTZurtWMEEPyD /8N5k1KaD7iUlhvqRm/AAMJydVzjVv2+2RxvmrjSIelnZ9tXFGD6psWpzvF6Qxx3TE4meIW5MCw = X-Google-Smtp-Source: AGHT+IEe/y6XNr+Pufr0eUp0xR/8PGJhWQHFkFpwqwZ0egi8lWAzXxHeV34fKxnQfAGSlETNCc8Irg== X-Received: by 2002:a05:6000:178a:b0:391:1458:5af7 with SMTP id ffacd0b85a97d-39114585b3dmr3675285f8f.49.1741085316629; Tue, 04 Mar 2025 02:48:36 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.138]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e4844a38sm17445161f8f.75.2025.03.04.02.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 02:48:36 -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, Lad Prabhakar Subject: [PATCH v3 4/5] phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off Date: Tue, 4 Mar 2025 12:48:25 +0200 Message-ID: <20250304104826.4173394-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304104826.4173394-1-claudiu.beznea.uj@bp.renesas.com> References: <20250304104826.4173394-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 Reviewed-by: Lad Prabhakar Signed-off-by: Claudiu Beznea --- Changes in v3: - collected tags 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 39c73399b039..c663910d6163 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 13:37:56 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 75FA61FF608 for ; Tue, 4 Mar 2025 10:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085321; cv=none; b=AZvCYR8kx/14pPvvvogK4LDKU5E/7QphIVRi+BbVCFTbtvkV9I1nosar3gVVIi8bPUHQkxXtpTr415Aa5SaHPqy+NipoPeASgt1vj/1ZAGhEbumqbSQQ2mprJ/tavj1jMU5I3gBFZE+76tJIXm6/U74J2dvlIY5PzxiJUmao+Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741085321; c=relaxed/simple; bh=I6PmJhaf+aDIQD4WTRn8AyrjnmESJma46JRl4n8p0BM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MhTsS/H1dwMLUPCZTmR89iz0zjXbRwUaXA4mjl/VxEJcubxy2A9qQuIe9QpQXEAKp/7hjt3GTDNKMDas00Va5LEJiUmsW57lSJB687wlCJ6y6uGO4nlWYmAjA4ofG4cw3i89sF4FhSUvDHpd+Amjeny0bwE+mBP6Ay9tT/vjSao= 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=ln4U+5r1; arc=none smtp.client-ip=209.85.221.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="ln4U+5r1" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-390d98ae34dso4432143f8f.3 for ; Tue, 04 Mar 2025 02:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085318; x=1741690118; 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=tRJcEJEBuJZ+hz1ZoBW1GVvB+QH/3DoA+Rqlp4VSk8w=; b=ln4U+5r1D3226VagtWkAcV3mGJR+j4qgIL1B0dkhPxTeW77W9PYCxvhyEKnRdpeB9O fNsojDTyhvOTyt08zjPaUC/+oLV2Pin6sh5hd6kmVfCFDPjRXHgxUb6/+Vyq66mxACcD LiGv75szu/T2HuRfNIFKSpJaAIhNapwn3W5UwDTI0BdCrKUMOucKCiLqPe6rFDxvlxr+ OeASgB6U/gcCGt50SLlyrr8K5iIVdN1rRK55moFtqYLX8v0A8X/jGHFaQiFdo8FcUNS/ wBfP2k3HEyf8zyDp0LX4eQ1bmG69xQaQkPc743SLEYIFA40N+sG80Z/FHPDM392Fi6nF sxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085318; x=1741690118; 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=tRJcEJEBuJZ+hz1ZoBW1GVvB+QH/3DoA+Rqlp4VSk8w=; b=d3/Y2hQr/+C/NsnJnS32fO5QiJ5i4YoJ33H18m+qq9XvNrGI7fB1spHvTy5j1ll3t1 UT1eiK2wxKTC9CSgSff0neo5ffgBVBR4OX2TSKxHqgOQ9hTBwdZAWSz745nePaE5GRGe zSML57uy9C8NCrrCDNB6ZniW8nUXUfATKvZvihk5PeX0Dj9OuRE/xyArP7Owi3Uv3np8 4xy5CtYoMe5erRIy0FjTOaypbOkERWDuCWA/C1CrouOstcVcJNJ9yu1wRwjSg3CJD8Pv YV5EGvmLoOwp0MegObwr/zxEXcVRsFEZJ6HmIw0GIA6pXNGk0jw31fGZ+LLCm72PGATS jZHQ== X-Forwarded-Encrypted: i=1; AJvYcCUdvz3Nohjc37aiZmBAlGqWDef2EJ6B0Dq0NmO3grYt43z68x6w6FS9aXdjgR/bRNQYfVSlqgbe2356tkw=@vger.kernel.org X-Gm-Message-State: AOJu0YxoAoQUMGcD/yD6gwUvnNEsV+VHv/NN5ca5JRNHClPocdFmtoAG Mzdo8rL7uQmrVs+z4gTGcXBNFUjUs5Y+HcNnhTf1g/V/H6ONDejqmmGqxHpocqQ= X-Gm-Gg: ASbGncu73gXTLtkUJllEdzlypz9pvU3G9uu2ohw7z49+ipZTHqrOyAwJNTn6oQrq5EP QZlVWVIKgYqAjTg2kuRKul4SidE4SOXfBAb0tv0Kl4152by89qiCzM/zqsO83LNFfD0Qy5MqvCA 2Yoy5ojzYP1uvwyvDFB3CYRM4yEqTOn0GZ9FLWRq77JKUB7xDmT8ZlHpd8OmXWROqxprP2VyQPx ZQoU3LRDUiKbrfBgopaCWQuo1GOmPLarhlDo1gjJ7KpSEmBXQNGv+NQpO1XVw1i1je6vxEov4tm LZoq1w2VOwSeF+Q30ql72lUuFG+umhLpAWV5LfRsbDk7jhPkDrH5tiitqeXF1qRtxm8SAKuZ1Zc = X-Google-Smtp-Source: AGHT+IEzaPdRtNq5d8BIcB9aEy7PlrR49uga/gnA14JhmXxnbu44C93t/ZWbPsbG+sIUeIrfE2/bgQ== X-Received: by 2002:a05:6000:4404:b0:390:eb46:1894 with SMTP id ffacd0b85a97d-390ec9bb93emr10799958f8f.21.1741085317876; Tue, 04 Mar 2025 02:48:37 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.138]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e4844a38sm17445161f8f.75.2025.03.04.02.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 02:48:37 -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, Lad Prabhakar Subject: [PATCH v3 5/5] phy: renesas: rcar-gen3-usb2: Set timing registers only once Date: Tue, 4 Mar 2025 12:48:26 +0200 Message-ID: <20250304104826.4173394-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304104826.4173394-1-claudiu.beznea.uj@bp.renesas.com> References: <20250304104826.4173394-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 Reviewed-by: Lad Prabhakar Signed-off-by: Claudiu Beznea --- Changes in v3: - collected tags 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 c663910d6163..617962a51e81 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