From patchwork Tue Mar 4 10:48:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 14000424 X-Patchwork-Delegate: geert@linux-m68k.org 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 3BF0D1FCCF7 for ; Tue, 4 Mar 2025 10:48:34 +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=1741085316; cv=none; b=qV3KlubkOMnHcw5yzXSi7XwwMs3udEAhpx2KrQkvn64FDIKWE2kgepsjGfmDL90qo53EF6/yKVs8xJfpFwB4NNPwH+XuemJMJYce+yLZPf4kIF5rtH4qEQraKuMaFmi+3RCZKjBROhniMEE79A63fBnsQ8pV4gdRpCM0nrUT6rE= 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.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="I/F1BWbC" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43bcbdf79cdso3659455e9.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=gOGbeJxivDg6SlKsm11QleDF93y9IHjEAppEaEe56b1cLTjziz19KHT+kawnXGT7Il jVPtZoP3RwX70c03EUe992fHGCYIW8cGKVARdaCVrCInv3MdYkplUCXjZ0/2bpVNdxq3 qfRK6DwNRT76f6kwWLzCC2Y8t0STpurUZQLyttQVDQbEp9ifzSin4RCq+mBhqzymn6Tj 3LkHIoNW3jLAXHuFOB49aHEQsykTbsb9BWtlBZgRmxZXMpFIuqjGxOjnlCj+KKuWQgLZ 0VMwH+DAYOgZQi9akBdA6ZO5JTkgxiopT9JTF6Mu22/lGxVvH2LpqYCdSIWZuvhrFam3 qH1g== X-Forwarded-Encrypted: i=1; AJvYcCUMMnjc3OaHspHfoehucCKkcrYwYFvTuzr66UIt7ccNxGNOfRi8WRHPdfpIoB79AS8SlkrCwrqMxX41OI02DsnIkw==@vger.kernel.org X-Gm-Message-State: AOJu0YxXlEZHf2Lnpz3CqwxRTwhf4QJGB4tkbneuf8COFel+WhEGNsiN KdrcCH/PywITRux5HTIBbHUh2WzHPcTwcqXGhLoxEgaC5iQPjvyZJv2DuZsAmhM= X-Gm-Gg: ASbGncukCXF9J3UTJYJw3oaiT0rXKRHKbHNbgpD6ppxCG5+mG0v8jcR7Rnj12jZ2Mpe hrRKudCCd7JPcxw31pEpQQPJSy88hiqXaVELwHH3+kqEg6qr8iYpOla5RlXWSRm5OFj+W1z6epG q3whbqKyNUB/XRx0FoqB7YI7bGBOGNxqvLFKMmesyleMkAW5tGCAiZU6PXBGrLUYlryKQV2oPhA zR5WeElglvv+iPemoXoAFBFfwvici72jLiP6UhJHWGl/RFqHRSU1m7Dy3n0Uu+v32CmXRGG9hy7 K8AHclONJ/1Hon9VosJbcQFmwZOLRHOW5vQqed8Vz/cVl7xbDiXq73ust87twI2IeF6mCZitCkI = 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-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 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; }; @@ -320,16 +319,15 @@ static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch) return false; } -static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch) +static bool rcar_gen3_is_any_otg_rphy_initialized(struct rcar_gen3_chan *ch) { - int i; - - for (i = 0; i < NUM_OF_PHYS; i++) { - if (ch->rphys[i].otg_initialized) - return false; + for (enum rcar_gen3_phy_index i = PHY_INDEX_BOTH_HC; i <= PHY_INDEX_EHCI; + i++) { + if (ch->rphys[i].initialized) + return true; } - return true; + return false; } static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch) @@ -351,7 +349,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; - if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; if (sysfs_streq(buf, "host")) @@ -389,7 +387,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, { struct rcar_gen3_chan *ch = dev_get_drvdata(dev); - if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" : @@ -402,6 +400,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) void __iomem *usb2_base = ch->base; u32 val; + if (!ch->is_otg_channel || rcar_gen3_is_any_otg_rphy_initialized(ch)) + return; + /* Should not use functions of read-modify-write a register */ val = readl(usb2_base + USB2_LINECTRL1); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN | @@ -465,12 +466,9 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); - /* Initialize otg part */ - if (channel->is_otg_channel) { - if (rcar_gen3_needs_init_otg(channel)) - rcar_gen3_init_otg(channel); - rphy->otg_initialized = true; - } + /* Initialize otg part (only if we initialize a PHY with IRQs). */ + if (rphy->int_enable_bits) + rcar_gen3_init_otg(channel); rphy->initialized = true; @@ -486,9 +484,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) rphy->initialized = false; - if (channel->is_otg_channel) - rphy->otg_initialized = false; - val = readl(usb2_base + USB2_INT_ENABLE); val &= ~rphy->int_enable_bits; if (!rcar_gen3_is_any_rphy_initialized(channel)) From patchwork Tue Mar 4 10:48:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 14000425 X-Patchwork-Delegate: geert@linux-m68k.org 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 B5CDB1FAC5A for ; Tue, 4 Mar 2025 10:48:35 +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=1741085317; cv=none; b=AcAmRzFLNswfCNaTRXyhLN4ImbvCjS5n04TSfsXJtCTfNYpljyaINjPBGklLkcWZttOgCMc7FAPvCp8ovEJ/V7HripM+5nynxmEjKVUXH8NBE4+m8HiPT7YXVzCcjtFXxp3hhUGvJJaYwLBd0D3bUaOxY1c3UjGC+HeYzcepVOY= 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.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="kdeb2FnC" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3910f525165so1430384f8f.1 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=ajmN5cgVMi3TvbgwJSvk//I4Br2wNw+pIwQ7pQ2jYEBosoDOsszgug9g9vucvxr5br CIUb+2KUbTYTjmdAKyDSNevGSuthn+jOMnv1wS9XiZ7Z3nc4FM6cbfRmMYKMuwFF8G41 KL4v5WMiVk8/RS6/wvv5RCRluIrhGFVexVWdRnzu2+bw+Ij03XuKw6zPtBlSn3zd/+Gz DBKejPmcqXcilGt6jIAStpJ4o0tGgfpCEa7fShzLEfrBgDd4taJBWV0GyYaCQTwba/lE XM+495AbeYJM8FD2yo1PtLet5b7TC6ZlR6HydNXxDBIxg1gvm+9MXl8ypdzHA0s2QFg9 Zy8w== X-Forwarded-Encrypted: i=1; AJvYcCWk241/h5t0z81Q+iKv0AtqTzQRQfZ6aUqvUWbbPdaKFi4DizQyV8M6ocYSoakEGS5hLaOFXmT9wjZURPAEOLHbeg==@vger.kernel.org X-Gm-Message-State: AOJu0Ywm5lQfQfzWf5hIywcN0hIuTXl7yLaxONf4gZmMUb3g9Giwsa3s Mc9Bp7D1Ms1803W9C1KsqlBzbC3qcE1O/qq1RcWOeuOAnaLlzCnRfwNg6+Tx6Qo= X-Gm-Gg: ASbGnctx8m+k5yO4lx2LhAsMf2eKpgLP+jb+P46SHhZ/SfxcJXRKJVqeSBnAp/gnM8W hiQpJXULp90n7+EE/BiKV+GAVdybGzJR74H1rWwhRm1khkIrVWu15i+3fJ8e1C62Jt7yUHvzCaC /QwU1ZuOeVTHnemli7ti+6ZCzpROBNM4SMrG6BXtPP1sTkYdzpWhsW3Y/k59fZC3pstDeQzeCBr jHB9DX8Tmg+XfJGtGRxY/gX51jd4Ret7YdsHRzXj3cJr2xwrB1UBTyezX35Aoq6/4nEZqGTEKq9 WsjnUY7yqSLXPz9dyemELaio+zT2ESSS6JkFC7tr1fTncnhHwvFy3eL8lFPtiRCq8Cc/xBK7VMw = 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-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. 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, 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 < 0 && irq != -ENXIO) { + ret = irq; + goto error; + } else if (irq > 0) { + INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); + ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, + IRQF_SHARED, dev_name(dev), channel); + if (ret < 0) { + dev_err(dev, "Failed to request irq (%d)\n", irq); + goto error; + } + } + provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); if (IS_ERR(provider)) { dev_err(dev, "Failed to register PHY provider\n"); From patchwork Tue Mar 4 10:48:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 14000426 X-Patchwork-Delegate: geert@linux-m68k.org 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 283991FF1CE for ; Tue, 4 Mar 2025 10:48:36 +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=1741085319; cv=none; b=dTfVWtcjGujBwEMK+XqXWXMpjiA5ql/bofxtNWwnPJvpknc5T6E8vn4zKz22ybQAm1Tfkxblg/qkPBsSLNcPUTPGoI7xLUIYbNGcode7PK3Gs5asBxWTWZUGVC5/LHLpM6mFDKV2UkUFRsgP8x00KkY9GNGrElEF1zIRVHmQOVc= 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.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="Pw0w+0nS" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-390eebcc371so2182954f8f.0 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=wEvscqE1p2LaAZaWJwAHibMd+kj3JywYmTWPJlJ4BRT7h0+ryU7bgTM9y4hSgS5Duf 2XzpWtXjNyGRYmbg/gUPHXKZ1o3mbh5AsD4tIrVishqQe0vl2yiK6xqGZWwEtOn8+ELc 7tZsUXzi/65tFdkinf0ObPJnO1zy2sJyWBXnqqNZEuAyWRWodsAe12NzOOC9Lj+K3Whm tTz/MH943uu5DnLWmFrUUPZNK/hduPkK455SsmiUDBylwX4dTPHWMnTji6jwFlJybmuU +VHZBiz+JU+Yr7Q0kXe6DX0X9ZFVvPcPkkIeVTiqQwj9xVopMrNjnuWPSoEE1+LRh1AH /0vQ== X-Forwarded-Encrypted: i=1; AJvYcCVSs10rSG2tMvnawZXTDbOMX2O1aM3Kxg1mlhrnbMstHNV5r4KszOdk+Q9ovbTPencp7h6DkwXUHAVp1GRP0FQmHA==@vger.kernel.org X-Gm-Message-State: AOJu0YxTze4Isd6xktGq94lnYsiOfSdh2y45heOhnSP8KcOgNhcSh0Z5 r8+WnsOrIpzyEkUh/uo4GXUtbrlRFg9tGXOKb/zt7YaCN2zSiN3RsZInTM4T+Xw= X-Gm-Gg: ASbGncuiOyUFy9wH/MQTTs2QL6kXb1TKgdr3QYSaM7lJSVFWkLQFoiu6m54jBSaelc8 qhaFrpcNBPO8/2jWfM+IgPHW/QBDx2B1wqlX39fZiQULAd/VwgaGApjt13zQXPutVLeB5lFQLQc t5Ri7L3nbU1nDzDGvc6DAUTMFZUOVR2X+reUk5jEvQ4F/g5GngP4VzqHL6uFh6MFowNr3mLMPei iFX5hsvgWwc0dzyV4mb0x2Y09GyJQ7hQBtFr23vBDxLl5wJ7ewOEoM0mxQSR8ifUH4Yfkdt31HE ivCyi5Aifnz+8FA6O8vhtrzBGZ38xVzAzOJtsD47cn6euy+wd1YPjQV4AeNRKib0caS6WfyXyVk = 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-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 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. */ +#include #include #include #include @@ -118,7 +119,7 @@ struct rcar_gen3_chan { struct regulator *vbus; struct reset_control *rstc; struct work_struct work; - struct mutex lock; /* protects rphys[...].powered */ + spinlock_t lock; /* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode; u32 obint_enable_bits; bool extcon_host; @@ -348,6 +349,8 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, bool is_b_device; enum phy_mode cur_mode, new_mode; + guard(spinlock_irqsave)(&ch->lock); + if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch)) return -EIO; @@ -415,7 +418,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val = readl(usb2_base + USB2_ADPCTRL); writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); } - msleep(20); + mdelay(20); writel(0xffffffff, usb2_base + USB2_OBINTSTA); writel(ch->obint_enable_bits, usb2_base + USB2_OBINTEN); @@ -436,12 +439,14 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) if (pm_runtime_suspended(dev)) goto rpm_put; - status = readl(usb2_base + USB2_OBINTSTA); - if (status & ch->obint_enable_bits) { - dev_vdbg(dev, "%s: %08x\n", __func__, status); - writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); - rcar_gen3_device_recognition(ch); - ret = IRQ_HANDLED; + scoped_guard(spinlock, &ch->lock) { + status = readl(usb2_base + USB2_OBINTSTA); + if (status & ch->obint_enable_bits) { + dev_vdbg(dev, "%s: %08x\n", __func__, status); + writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); + rcar_gen3_device_recognition(ch); + ret = IRQ_HANDLED; + } } rpm_put: @@ -456,6 +461,8 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) void __iomem *usb2_base = channel->base; u32 val; + guard(spinlock_irqsave)(&channel->lock); + /* Initialize USB2 part */ val = readl(usb2_base + USB2_INT_ENABLE); val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits; @@ -479,6 +486,8 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) void __iomem *usb2_base = channel->base; u32 val; + guard(spinlock_irqsave)(&channel->lock); + rphy->initialized = false; val = readl(usb2_base + USB2_INT_ENABLE); @@ -498,16 +507,17 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) u32 val; int ret = 0; - mutex_lock(&channel->lock); - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; - if (channel->vbus) { ret = regulator_enable(channel->vbus); if (ret) - goto out; + return ret; } + guard(spinlock_irqsave)(&channel->lock); + + if (!rcar_gen3_are_all_rphys_power_off(channel)) + goto out; + val = readl(usb2_base + USB2_USBCTR); val |= USB2_USBCTR_PLL_RST; writel(val, usb2_base + USB2_USBCTR); @@ -517,7 +527,6 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p) out: /* The powered flag should be set for any other phys anyway */ rphy->powered = true; - mutex_unlock(&channel->lock); return 0; } @@ -528,18 +537,12 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel = rphy->ch; int ret = 0; - mutex_lock(&channel->lock); - rphy->powered = false; - - if (!rcar_gen3_are_all_rphys_power_off(channel)) - goto out; + scoped_guard(spinlock_irqsave, &channel->lock) + rphy->powered = false; if (channel->vbus) ret = regulator_disable(channel->vbus); -out: - mutex_unlock(&channel->lock); - return ret; } @@ -750,7 +753,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) if (phy_data->no_adp_ctrl) channel->obint_enable_bits = USB2_OBINT_IDCHG_EN; - mutex_init(&channel->lock); + spin_lock_init(&channel->lock); for (i = 0; i < NUM_OF_PHYS; i++) { channel->rphys[i].phy = devm_phy_create(dev, NULL, phy_data->phy_usb2_ops); From patchwork Tue Mar 4 10:48:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 14000427 X-Patchwork-Delegate: geert@linux-m68k.org 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 416AC1FF5E6 for ; Tue, 4 Mar 2025 10:48:38 +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=1741085320; cv=none; b=gn1T1kkqaQrutH6mM+2iU09QsHNj2jB9SHpCXsc4LHgIO7iUMfL7I1zRW9/xlCm47tOewB2okrBXPzR/SC7fs0wgT2CWxgaUT9yxQZdKvyvCKtjcNxxvRfH3jFZfdui6iSPNJi7AcIWmNgKGomnTBIodptxRrtt/zeBtudzG8VA= 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=VB7c72yz; 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="VB7c72yz" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-390ec449556so4281467f8f.1 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=1741085317; x=1741690117; 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=VB7c72yzwAXsBnycwcZ3P+Aw15MMmvOJ64ZgY8zKuVeNAdgJmfu5dp0c6of5864ePZ FRTNyPveMvc07XSfYpTJC1FRQ8uIaaT2NsNw/Z5rDwkIaKAAttA9/06VbHXyE4Z0DbdQ xYmZ50Oq4DSC9pJZzuW2pEy7Cntq4zOCYffPQ0VSX46nLigzr5FCa5dOkGHXaOKGDPgD m9kVxX0eJf+Q+QB472g4kWSeG6Tt+wfqpBxs11SV9gpEHG7RgCIDQWgppX9usnQs647I fDfhYVU5D6quiVHSQnhFgPXDvUdlW2V0bLTRfAT//VcxdySYvPcohyzydn+RLqjE5wz6 oqxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741085317; x=1741690117; 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=HgrADv478FrMBVh44X4Y/BhwbVvfUqVCXWmipvR9g4/SDQJW0c9fHL4oUkaEUKAdeS WCfHUuMTbctMyn/+t3lx5s4gdJE/XYqgZwWltTxjny2gnvBgglyXRtmY6hNojn2mk6jY njroUK+HVFEmFBe7huAYAmsyjJrZ19pN9rnAz9N19QGj/dlgYJ3c4UBSN/wM4nJPV5C9 +56oN18XGjNEJQabecu7K9BoI1lCmxvBl5Jpw24c+UAo+REkQZiHONKnZJxGTlgjLGvA DFnqu5bURPt2CxnkhbYy4W4ch1RQEfABVbr81W2DYN4FMYcQsPiP4NxSLbxF8Hebs9T6 kyAw== X-Forwarded-Encrypted: i=1; AJvYcCWZD2Ow2I5jzFYs6sO3peHgtTRZ5lO6WPWtGcyP0Av/2XNoBvNXNW8zr9YFtr9IIphXsHloEolYPOG4Aa9PvoJV7w==@vger.kernel.org X-Gm-Message-State: AOJu0YylQTO0LmvTSPn0HTC6EBRRbAOZ1icc2GpXR41u9IO0kp26SXsP wXJIdJeZLFKQ0ge4pmx46iVp9FhRcMCXYzu3mgjBxH75RvKTWVOlEOD+GN9ebm8= X-Gm-Gg: ASbGncv1yy5NDf3yymPz+mHcFleV+tbSRE5S5FvJyW2yNWlyF1grssVcjNhq9OgznNc 4YTr1es8H7zOY/jTMjSnRfxap7D2PSUuEtojWYKYeH6XZZw2oMHWPwGkwA20pRXFVO7zbLK+j/8 BHccygQgjQXHkxthX3T/m7kjwr/oB80jDO3YMxGvCRdhvYLYpHrheAulYJhvkd/Rimn3+eZYpxW IW5x9kXEJgysc6+kpueABcdPVLKZVdVeE0SEzO8YhX0Jr8HpdfvUvEXUa916dQAkwyhupntCawR u+qQ0y0ECqG0FnxIazr0TIDL1Tcqz3h645mOSAMNw8NFAtR0QrWeqA2X2GHGFSBWgCjgbBa4XXM = 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-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 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 = rphy->ch; int ret = 0; - scoped_guard(spinlock_irqsave, &channel->lock) + scoped_guard(spinlock_irqsave, &channel->lock) { rphy->powered = false; + if (rcar_gen3_are_all_rphys_power_off(channel)) { + u32 val = readl(channel->base + USB2_USBCTR); + + val |= USB2_USBCTR_PLL_RST; + writel(val, channel->base + USB2_USBCTR); + } + } + if (channel->vbus) ret = regulator_disable(channel->vbus); From patchwork Tue Mar 4 10:48:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 14000428 X-Patchwork-Delegate: geert@linux-m68k.org 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 760031FF609 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-38f406e9f80so4136064f8f.2 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=vt0vq+LmAjVqyTGfKDMPKT6eXVaPVVghskTmYtuD+mvEc0OhMXzTdEljZlkhQem02D 94hL+ZkWE6JqHJYiWp8se0Dl+2Iyi3kfH28SoINKJB1P9YG1G/LepI0LNx28+qkONTqJ Uxi7gB7a4s1AP+1cWTp4okX3umsUqRuSkIsRNFPFX//kJNY7Bk8NIGMKT8NF1nlJ2Den uf3nCFVxZo/ql4XZoZ/B3uwYZ7am6AqLNQbY/k0Culg0d+r0DPtekjrbdQMUtCpibxOe 90NVDvJDk3XPo9DjNpCtWNnMyBIOPfgXRaQN23Fxc8IJog+kn/5yzKVhwDYEIEppTLEo H1QQ== X-Forwarded-Encrypted: i=1; AJvYcCUSTCE+3W2vjBLYAxz+NMWgxa2uVOMjXBaS/a3kkaF4iT03uYIhKMw1fmn+DdwaGAda40KbRnZCozaaMmYDLmNk8w==@vger.kernel.org X-Gm-Message-State: AOJu0Yy9DfEoLbj15hi4Qa/81Bio88PKku+Crjap1vuDDDudeGgU5NZC 6EM592MYNnh3XrsSwaxnN/gyGjXtq5X+tgjD+L53Mrq+mXW/ydK49jRAkSsdGx8= X-Gm-Gg: ASbGnct6p8VwwwNOgoNmC8MzODDtXM/S+epUoodfIslaG2JJpgkLqhC0r4PZRKKRFCq HpptjvCR0Hlk7MBYggWszUKekJqIA+njDp06GL/lwnVHVzavJgwCMc6UTJR7TqzQ3IT31IE7d8G 2t1e4Jv1YQmyY7Mhp/vxlFxW0r4HxbccIs9nnyvDLR9RUC2ryyDBr50mHdmj0LMT3gWbB598fuS 7QIoQXPb0+fKpVgLHIh2PtvtLeCWBrv//1HxOGnu1s7wxgv0oTMGe6/8oOCEFyhgdCljfWv/4Xd MYeZgLh0N2+qgLy4srgHL30s1PUSYiksfsIse/K71RSmHItUhuzPGGNACoA4A0KT3QIz7+m1T3I = 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-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 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 = 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)