From nobody Sun Dec 14 23:24:10 2025 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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 77E5F28003F for ; Wed, 7 May 2025 12:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622242; cv=none; b=PwKtqnYT4x7WyKekJMO6737C9Vz3IDbYFQX7dDWxEqemnio+cRMUGR2XEhGZbGjmHBl5Y55T616BR4hyVyHfhdw6eQV/fql10t1iBOK7gAeuK/rJ6AGUsQ+prpuTrVl00VVSqiHyoocIGO/4cuYL8Yoi56KPrT6MNh8hhHQQjE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622242; c=relaxed/simple; bh=L+7igWmrzB3MXXLwtuLEyjoA6CAq6ItWg62jIUmYSgc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PBW3MQNav876r9JIMMNENYwwXvlkuQe7evgUR95lOsUQDpBVajQVMTzrU4fHtBmW6JRLUPERON+LZTU6wllvRW+RDFuAHwolbJkt7n9v8LbPoBJVGM/iojo1F81iT/PHMfwQRD3xZPz0wk8t9dgsEVMfM0NPhjZfqxwRZanD5p4= 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=LmAJzbDI; arc=none smtp.client-ip=209.85.218.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="LmAJzbDI" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-acbb85ce788so345332166b.3 for ; Wed, 07 May 2025 05:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1746622238; x=1747227038; 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=LmAJzbDIIa6oQleSKu2dT59bkNrULYd7Vie3PIRvVLpls+UNL/P15VzZZKSseq8h7/ QPIvNEQ5zNylT2yaxv6u9l/mc6Hyqpnjd4x1drItDQbjzqg+FqMokz45VESYtD9zcqEx dCDfpOYuLG02nZiqRcXibDAsfU5NHuVu2bqLBMHXK8ZEAPCiUq2bk+BB8cUW3hXHbdN1 8eRAFkUiVVoGvQOfCPDpnIvlySTK616NkRb1QHdSHRCfjThrhjPcjnXQyhNHE0DrR05r 9MbuCzB87AGhDWSZ97z1cOVr9OSDXIc3bMOAYsNJGhKUwNcxI8Z/PiKpJr2kozm/nxLg rJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746622238; x=1747227038; 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=qfhyGdoEWbUE+MAoKCk023DMSsv0EiXSj4prurTlpgnS3ab8GP8pZb7XUfZvNpU3Ac CLXivTxqaOgDjaoS0x5QU1548jWwlBvzgJB1Ic37kNIIchQlHAV0lEr1bLH1sj8FOSwa oOwp3IGjK/0W88xLJ5xuxMgLiKXdkhf9X/ea/PiMYpDuST1Pal5K8ZfRl0KpALCVeMQn 6H2HdWRaTKoUW8ozz4AVwj+6x4Hwd9LdE+jQvpoLGMk/OkMdbA7RcQtJ8WzH8rN+12II fz3X/Rh1/3R3p4/YWED3raa2x7v4If0jqbIrZN27z8fkoC86Bg0TTv9lhFL+p8Gc44Me 0kWQ== X-Forwarded-Encrypted: i=1; AJvYcCUNBc2D77WIlThfUW6a//8Jri/PHTO9KSSbYpXeaOcySOoMja4CdWn6T7+m81MjHPgwE66+WPDPURCyqeU=@vger.kernel.org X-Gm-Message-State: AOJu0YzAWq8cXrH1q1gDYHjZWe3s3Xk5YkZuMwZcpXuVdkED2g6aJEOZ vqpXnZD103uALzyXyBKVzyenpwggT0jLPRzo7o1j3CaWjIYJdYrrz1xTqdQZIBw= X-Gm-Gg: ASbGncvaDbTM5B9wlnF4r6XbX3BIRtKO5Sy08+MRHQvV1Mj6nRg47IQA7E0O72/tURp c4FWhAWZwCCodVjEP+q97qDWKmSKWis40x0teUNDlzNseGXFjt0Fn9bnv3/Lf5177Z+vwYhFrR6 N4PTVklsddQLcf2p34gN/+AxeZnQCgl+EeyhLylwSdGJua6onUXjz8aJFsBmZO16+UPFfZDFdpw D9wctqdABXBsq98F/7av9LP9w8iVZadEjT8dvtrphnaddY48bJmQ3YMVXIry35mUcHilO7RrDyA EA0o2nG0pBRBFCrudl6+HUablwfBoHukB/Yk2yElVQFak11KSifuou4fOqW7O5GZHcZwsWc= X-Google-Smtp-Source: AGHT+IGeR56fcf3ibbnLTGP7y2GNB5PTnIKgbVR+VbLAq/tWAyDh+kKlVjb4q2s7LL9nLtMZbmFZAA== X-Received: by 2002:a17:907:6ea6:b0:ac7:e5c4:1187 with SMTP id a640c23a62f3a-ad1e8bc319emr239738466b.11.1746622237574; Wed, 07 May 2025 05:50:37 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.147]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad189146fb4sm913182766b.10.2025.05.07.05.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 05:50:37 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, horms+renesas@verge.net.au, fabrizio.castro@bp.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 RESEND v3 1/5] phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind Date: Wed, 7 May 2025 15:50:28 +0300 Message-ID: <20250507125032.565017-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250507125032.565017-1-claudiu.beznea.uj@bp.renesas.com> References: <20250507125032.565017-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 Sun Dec 14 23:24:10 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 B2844280CD1 for ; Wed, 7 May 2025 12:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622242; cv=none; b=j8154QYM7GGZaTLlEJn+9af4pl7ggESKjp3NwhsrKMYO2uyHD3wIBekzadNDZenf/MFrETdZqJro66/qnWmuRCiALzQxHgrblE9Klh9Q/AZw8d9OpCPu4oIWkLoGxT2sO75oFO9XtZDi34fNqtGTT56CUk4GWUXRJu3cVoLBNEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622242; c=relaxed/simple; bh=fXWAFfM6xGQH5vtg2vnG2G4Rm9Srbao7e5lC4KEsF5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mpJ8KxJBFdt0ZdOeSo7XnS4cvFCVsCsJR5G6Dpq2OaoBTn3n9Z/1zBj/qkYTySktcC2CLbSUx/WFzVyOxFdxIRappEgjXTuLnFQycgxdEjQ8qOOQr3kvaAyIX7icdACIjnIBKddJm4DLwQyqKNAwcycT+9HJY3Uip8WO1O9vvnQ= 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=abPQSpiR; arc=none smtp.client-ip=209.85.208.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="abPQSpiR" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5efe8d9eb12so11123863a12.1 for ; Wed, 07 May 2025 05:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1746622239; x=1747227039; 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=zxQTUgTe7v6lzhxqGuewV0dNwPB+Lcd+avBxe9zfMDc=; b=abPQSpiR+Wto6h/MgLgeH7JJqHb6AeKVuTseK95gAYZmb7YsMwEswf541OL15fsEYg oY2SzB6U/eZQ0Kur5hqS0v8AsbL0yXTUq4tQwgvmuJp6uOa9pZrYNjN85ftazeFdWYfN XhUmbBE6GOly8A8w+KEhVKP7rCsFu+XV6qotAdwAXemas8aDBI7nbRRMU5yo9TRqcEZO meoGX2keeAKBmFUlCduV91za0QEAxuJbr3ZZLID39Wq0tsDedJnr9vXWYQZd5YcJTWQ8 oOXSCH3GuuNS+VQqoY8LkcnRbF4Hc4scoxPGX6MS2nUWf7bH9D4rxYb6P/XSKG5f3wPb CrKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746622239; x=1747227039; 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=zxQTUgTe7v6lzhxqGuewV0dNwPB+Lcd+avBxe9zfMDc=; b=IMSsX/Tgpra7cfZKr9MX4q1yfgGDBnRzufo8656kn528ku6fvGxBGwfbkvyOEtQpb9 u0uQkLXEUHRHuMBAR7qW/DBtonzkH8BUNMIVbUs3VUV8TQNwr8YBHmtR5A8I4mraEVF3 H4C7kPh1e7pyTqyH+jnJ5NrKERK5kpIRu3KZkQIskK9Lok0Hb8enz5LPPcJHWoq/v87o vifId+4N9KJi2XnMFHbYQFaS/lMCMK35LPzQ2X6s2ehx1hupwc/4L/Ixkx+9g+DUHlpQ YkwxSRqIwx8OEfLLXDf/z2dgcy5RoJx349gwAj8vAomUaot/x1/oiwdk073EyRCYzlwG 714A== X-Forwarded-Encrypted: i=1; AJvYcCWTHeGrsZKAKY8GpVQL/eC2Peqj2vywZyTJaSBFEIhfOieZs3ntLv68KqlUiKJ9pMFRuJWUSho6tdH+TCQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyTOFQLi2HGcwYY/0oYxk8o2KIwDj5EEcENEql4AOY552aDPQ/f ofIL/EDUgBjUiU5vgswvqaTKH/BKziYR/2Epwakq85SSPy5sahMn+IzxsVcGA5k= X-Gm-Gg: ASbGncv79NlUT380Zg6q1LhzTR9ciWcI5lEpbjwKhLvkKPMaWE+YAsehmrAAm7+PN4F x0PKqVJHs/6+fyFUmGbwjfQbGs44wouqlrJ3trWD52L0JouTsS8CeeWNCReBvWsQ9kgTa69pwGN sB5Ox0nJAVmAbt/YEfMNzz3gQPnvEL9K2M6Ed3wG8Ny5kH3lYmTEoH8YZSkezU59Jzt32HZARC/ m5ahJ83Z2ZJOWuMYqA/BgrjHzvUrwvSslbcOW1f5/tCwxU87M6Vgqv713dvFzoWb4o9ylDZerO9 QTZuGUtVt2nVwoUqa70fIvEA2p829rD2rCdqh/1UdutiJiwjhtnvckDaiGvr/ZxDIhQUEq8= X-Google-Smtp-Source: AGHT+IFfsvW3/hnEPeIc/j2uIPUA7et6tDXubR245UWFhKei3VhQaP8pS15fFAz6cgAd8k7V193d5A== X-Received: by 2002:a17:907:998e:b0:aca:d83b:611b with SMTP id a640c23a62f3a-ad1e8dbc866mr330662166b.43.1746622238928; Wed, 07 May 2025 05:50:38 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.147]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad189146fb4sm913182766b.10.2025.05.07.05.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 05:50:38 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, horms+renesas@verge.net.au, fabrizio.castro@bp.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 RESEND v3 2/5] phy: renesas: rcar-gen3-usb2: Move IRQ request in probe Date: Wed, 7 May 2025 15:50:29 +0300 Message-ID: <20250507125032.565017-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250507125032.565017-1-claudiu.beznea.uj@bp.renesas.com> References: <20250507125032.565017-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..bb05fd26eb7f 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 Sun Dec 14 23:24:10 2025 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 3A7A62820BD for ; Wed, 7 May 2025 12:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622244; cv=none; b=eSYCwpcR9wfnZuxk7N6x0FDk6KnZVrf5MZhKQrOoXyhc/iw/tu+x/YNU2dFxvBIVi7oyoweUUlbSMmVWYgUc+xAgnbI3bO39BNfPjJFn6xEb9V2xbHgx5X55R7PD5UiePg/1whLIA6mxj4chqtOw5AsxDPcfl6KTa7OXjDJUwt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622244; c=relaxed/simple; bh=CGQXFNBuFkDlPVyujBIKgR/l750YwFvTyq0wDnlSLYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tQ1Af5ZoWJ8nMFwa9Kgb93EWdadvR1H0LtbYnKH4wMWWnUsejjNxwTf9mjwk2AcuKli3/JEn3Ay1OPoubf/yBYAn/h8rZzfzzeppXKvBraKB9yJAOUqXtjluITtsGiVW8cTEvh/ywDR+cXcKL3d9k857tSmxEU+1ghkzdiw76bM= 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=HnWm41uA; arc=none smtp.client-ip=209.85.218.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="HnWm41uA" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ac25520a289so1162948266b.3 for ; Wed, 07 May 2025 05:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1746622240; x=1747227040; 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=6Krsu3iFJs3WuPR2+yQl0l+lGXqlJHvRHEcEZZxnmYw=; b=HnWm41uARU+Q406VO0lEHGwjTwa3cpd4cdNzpCusDokjqibVch1itK8ZnE8DEAvyhW eDpA9OG1bRXcEtMFl9lHJ26LOdFMQ0ET4acOR6wDC10U/Tsiy/siGQxLU9Cu7RbY9PgQ zMpX4qji8K6zBh1uUxe+9oWUejbmVYtEB6rE0jAJ55Xjeht6h8nWnHSf4ikAJ/Q4cUE6 Qr/MEBCeyQLisCSQ5mLbfmLIV1UX6t52o3VGoUcDs2B6Ypztscm7pLRyOTqtY6j0pmRY +iEKBgph9jEHy9cqSTp+b+0mV6SZFdLDeZ0+D0/7wk2Z1qRJ+mwyUW4nYjLlP0DWzBBp MeEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746622240; x=1747227040; 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=6Krsu3iFJs3WuPR2+yQl0l+lGXqlJHvRHEcEZZxnmYw=; b=kAoo5piPpU7TvTe6YpCho8WNnJzLVcmhlfVvcVHW+QsN4X9vpOe9k1+MDTUwe69GN7 j+adLI19KHQwpAvGQqaDaMMVqxodv/r4ok+Gk2Tj5qHDw9CKmWlRe1gWpyP/D37eje3U VSZnFN4OXyY2IyotHHMy/AynHJ4HbxUmDAD/g/5NokfBEjCPpZyrHZiiVuqEiuc8ok+m bh/VUajaDuSkCZGZZB2/eSEmmsw+ZAMyQwWjKxJocLqD1GQDPiDTotRVTPDfsErvwxkL 0mjreMqgyVIQ6njGIcpEcs07WnaXnjTGFrj1Rc5e9iSL3zYFIJ2LqESd5lb979ZWIjSA YbfA== X-Forwarded-Encrypted: i=1; AJvYcCVfhltP0v9ao+xVkWNK0utVtXzJvl8X/CvrFXbp5WVdPmSSK5inZ9mk0bOoPzdTTq+bKN8MVJ/m6aJAYBw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9efjE6QPby3mGaJxEG4Z7BEqIhxVj6EkPjm9p34k/EcPc4Y+o EoynLDFIFhHJycUecq1icxlkKLjK/UOuG0rLXy504Wljpsl22A7eARhiQxbeaAg= X-Gm-Gg: ASbGnctPjKW+iHXS90C2nP+3ChY23TUIl0Lj3h7xIQSDdiorKN5+Jvpy08v+IbFDb3L eNIT4XmU3hRPvDUgmDadjFpqyesPbEvuTLZGc2KOBH4vh9UvUPAYM84gMfCRzBRrm0KiJ09CyaS 6A/oontQVSn4CP4//ck6H0+IWgIw7BFjfiqT3sMhzU8/T4sPwRY91Px57AZIhG9gXdha8Oa7b3u oIWb0SvkhZgRc5iOwbUqxP19509uf2Xh5fne4GgtraPiBPcE0apuqKnv4VVTrI0EP9oPV/yoZa7 PS47EQUz7Nb5A1c811TEewyL7EScfOtKembXhPHciCPVTXr4aOz06ctmDwG5cSgHmaXl+D3eRFP gFQpQUg== X-Google-Smtp-Source: AGHT+IHbtkK1R9C+vJyXVcpU7egt2919dNgZ8VPlNKCWWQxqKoqhZ1YYP0fCMjDMcIxIMTfg3ofdKA== X-Received: by 2002:a17:907:d8c:b0:aca:e2d6:508c with SMTP id a640c23a62f3a-ad1e8e6bfe9mr304366066b.56.1746622240359; Wed, 07 May 2025 05:50:40 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.147]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad189146fb4sm913182766b.10.2025.05.07.05.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 05:50:39 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, horms+renesas@verge.net.au, fabrizio.castro@bp.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 RESEND v3 3/5] phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data Date: Wed, 7 May 2025 15:50:30 +0300 Message-ID: <20250507125032.565017-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250507125032.565017-1-claudiu.beznea.uj@bp.renesas.com> References: <20250507125032.565017-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 bb05fd26eb7f..00ce564463de 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 Sun Dec 14 23:24:10 2025 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 7B553283FC9 for ; Wed, 7 May 2025 12:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622245; cv=none; b=YKzrzWRCQQ3NqBtXVN6vCiiCQjudIOlN4eeN2WkAIOe82bsbikdxpzSoxmsaqeNY4DmWaBspoez7q8WCOMyKq9Isgr8b8o0lYsPBFoqMRKu1H2x2cinibkmGtXz5CLyvr4sfkiMlepBFZ/kfTiJYkVcl4iSlTFwZL8WOLDiOY3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622245; c=relaxed/simple; bh=cSM0SXbi9Fi+cYc6Hqvd1VUGwSL3FdGobsRiWjVTLxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=annz406zuyw6fNV2XTtCfzdmtx0OekEYuQ+LTDTWhdmQNjzknVPrI4/E/00mWJJdSB40zEF8qYl3jZA/gyWAocJZRrbZN5TYfHoYB5np4zD+j5wMwv+P48cM1Gbt9MSbCrDiB0PxLquD385AfLZwXl98CAvK4JHHvrDz6tMrNVw= 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=Lo4kv64Z; arc=none smtp.client-ip=209.85.208.53 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="Lo4kv64Z" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5fbf29d0ff1so955427a12.0 for ; Wed, 07 May 2025 05:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1746622242; x=1747227042; 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=II15ozzD5Ll5bPmianAxLgZ6qAOgIxXenrt045Eb9ZI=; b=Lo4kv64ZopQ0mXQOobY7q8w5WtWOeuwyKhu7i6D8uYw9eHObqv22iSMZburpsMq5DC vUqE+sB/aNbYyXDsBdSnUU9XaqTypjMR8nXgR3wVKPpuG3y88vuTLdYJB0w0TLOts1Tk KQ1VAXahhB3mjqEuPwkBQj/qLPBV+Uq5mCkdWPAclmZwIs1gmxihB7PWaSntNw2qIO5y OpWHTDgIa5PmEy7O/O7KDJGMGEeGknxsne+xD/IFjYeDIP4iy9c8UsZ+S+y1CYIGjlXw VtSL+22LegsWWWrghttxf0gbO5//1YsyFCEcPM4gZBpvOJYeI3rP9PenGjcYrG0/eyi+ ThrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746622242; x=1747227042; 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=II15ozzD5Ll5bPmianAxLgZ6qAOgIxXenrt045Eb9ZI=; b=waWzjyyARhE7dWVfPZ66Z+seJTGvYwxxAZwK38Yz7E1d+87LAfqKRy0pKUuLO2RGqs T/GIy73MaOKyMMQ3vARSx6chmjKo6PIiwKWuItk7FVZ8ac6HmLVsxaW2XnQLGd9CfynB ZJAdlZK9SMGS4O7tCwgVH4QgWt1UxneXxU7SH2HbxPtcelJ2THIp+10E82VU5oA2+pQr M1CEzoW65Av59rWAIoTyV5hFRGqKKpL5uZuXu4oL314Gfwkbz5Ox2JN8URpr6Nh9jxkA ULbGFQAEsCnizkgJP24ud4sy1F0/YloE0+TfByaOEGdYhb6DOjSr87wkaipE73XXqlyv xpFQ== X-Forwarded-Encrypted: i=1; AJvYcCXmy2b8BbKzOaqwMS+dPlOM7TeO/ytfec+dl5p+oEvbjwI9weEzXU9qZViJQ/U4WDmLV2h5aSpaowx5RJQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywz6zjeFSMGSMK/RlbWdsFelISQuLOEXA7rBlZZBKpjBGR+oag3 g8krwIDACOLwGcnMzaqf8jJzLUL1wlbA7fCiwaR2G9+v1d71cVPrTdLkWfJjrkI= X-Gm-Gg: ASbGncvYRi1tA7bHmzIrHxl5e9TCixBTjUHqZ56W2paW6Ijj3/yoDesrl9NKBan4/tO R3Lh8zmC6l7uiD+PTsGjuafJ7WRyKUHltYRs45VgJjPeSjQLMmY+FZczma+s4j6+AWKVSbOCyTs /Dh9icATOZn0mZXL3eNnG2vBH3o117qD+8Vb2Dixet2gDVyxe8TbAhDhke/xH80Y0HenNSLd9pk ji6c/P28vgRjmZxw1sO6UzE+kyRdZmkDO6XKcAGcSnbdLHMllKkfmdSPGAQ2BqeQMvMzmIViMIG yDiEINuY/PjOwkhmLsjofyd+ZJVGeYbirTWgSX56fGdyTlRcO3lXeZVnslPJsVFBmG1ynkE= X-Google-Smtp-Source: AGHT+IFlk8miHuB42VMfUHBSf4Jai1MFWbXY60yj6sLC16sMrTufuU3xeUkiepwAWbCikXCtbz3w5w== X-Received: by 2002:a17:907:9411:b0:ac7:391b:e684 with SMTP id a640c23a62f3a-ad1e8d9c78bmr295475866b.58.1746622241642; Wed, 07 May 2025 05:50:41 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.147]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad189146fb4sm913182766b.10.2025.05.07.05.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 05:50:41 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, horms+renesas@verge.net.au, fabrizio.castro@bp.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 RESEND v3 4/5] phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off Date: Wed, 7 May 2025 15:50:31 +0300 Message-ID: <20250507125032.565017-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250507125032.565017-1-claudiu.beznea.uj@bp.renesas.com> References: <20250507125032.565017-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 00ce564463de..118899efda70 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 Sun Dec 14 23:24:10 2025 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 B800D28136B for ; Wed, 7 May 2025 12:50:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622246; cv=none; b=LW1SUTF1YOt6wcvorxqx1vhy2Eu/qqSuU6X7paFZlhtZmSTJ+pj5Hs6WogG1YVIP4hPOeE+3lCPrPpx4J/rfIOp4ZN32/653JT0GaPbzI3J5VENzKJHXLYZK4Z6g07zYxaTVUJzXz29iEE9Lf9Wc+D4KgvvvpUMkr0I4BllDHpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746622246; c=relaxed/simple; bh=NNbI2mZc7orPCD96orrUtGmro7jcN7TH/vdaWXSEFkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AvFwwK4YEH/ehTweNt2c6Cj7K0+XpUOlRBwiUkE36fFmips2vjUpXz1LhuHaIpFysJ9IRv36hXGo64Rgj6iBsDYcPLJrMQgxAzQBWVOII3Zkd5tNFJ0Bnst/06Jtxw8b/dVkbhuyxki6RnL2p5hOBZWUlhpLc3ma9aRX50DUIws= 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=aINOKAg1; arc=none smtp.client-ip=209.85.218.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="aINOKAg1" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ad1f6aa2f84so55782566b.0 for ; Wed, 07 May 2025 05:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1746622243; x=1747227043; 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=TPcRXEDFKMfOBueOV1ZZggEMaCzz9uMyyXHjT+cR4Zg=; b=aINOKAg12P7aT0KDfpvr4TYz1todh2ccAr3rMKqqx5DEVwdEiDgNYU/Bf6ZOnsP6VK fezUWRbWeUjcy6xj4EM+v0bmi4zKOAWT7/aJBZrREVMwSn3XypGztXtIOc/pLIX32PUu Vm/8eEwWVr5nH7Nv2YBXfGyyHh/iLRXCQQ2FCNDFNP6k4siM762/0CqRi6nTh74Z1Rqb aocClaXrViap9AfDFaI9WMRTnfOD+AJqlKp1r5e3j4lOofFouZm0Xy0bU6kO5Hw+yinY g8QicAR7wRyCKhtvr7ixQ/oMEg9ys8OYLT/w9rjr2DiMo6b5xxoBmebcRnl0BXTXy+hF PtrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746622243; x=1747227043; 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=TPcRXEDFKMfOBueOV1ZZggEMaCzz9uMyyXHjT+cR4Zg=; b=uN4fR+kEs7S2SjPVb3Un9qMva3FbVF0srOlNoUDfvcLJLJjxFEnWgFTjm7qp5zmsMs olShtN3TA04InZOiW133vRnsLJ9P+KLJBimELLJbu6om2dBK6e+3rBITeg2q/8AIrNU7 EOCvXanQXj+PnbSBDX/sdn8KsnJRqVcQU9aLQUg2PsCbBzQvQKzzcqhsKhFR8hL2Tch7 OqwSN0SNyNrlRmW1/D7LA8plexBFgA94ER6J2MbLEr5cLasMMymYfpc7XjPULP9wWwAS Fm2Nmh3NicDSwjz0p3sI+KiBK8d2BD3RAmOUGGOHqm2+uajanLxaHAXTYH/oJ4dfOGCc ADLQ== X-Forwarded-Encrypted: i=1; AJvYcCUGgTTkxlvkqcYlejUpNqlrGcfYWACAKgFfhZ7qAL5ua/kV4WdxhaJ+EZ/NPL4EyFRc8k/VLwkXc2YGTYE=@vger.kernel.org X-Gm-Message-State: AOJu0YzrvVviOY6z7WsmqixvlapCEpWlNCrE35BKAX+qzqNqzf8CAdFF y6cHy5jRRbPNhTmjjPaPnorMBpa45FoifuGFvmzlIBsbxu63VTkKfyZ7MH83V8c= X-Gm-Gg: ASbGncsNEOBQoajLbN6z0/9Mdohb8L7kOXkiXdF1QHR3H5O7XvkwURyewAGqXbfi63U 7MldMl8hW9N83gaIvdXbymm74otNuJOu3jAluaNOtL+g/JEjtO6CD2DHcTTd76QjxvZsPS4O72z c2RHNSZCWrS7x+oNeP1cgfXoLh8VW/+Dndr4O9r/0i3R4j1nE80VBGf6nsHPrZBlrAixBKnRgB6 fF+wtoxLFlzcr2svM6VnEMY+Lu3o8FC69j0A8n0z5dLRLQbSuJFVxUBKjpALwFug38cDUV7lJGr d7fGSGHxvVhuQ6LkkApqyGauSX758uhxxe5atSiLgJfedes+YNU/UWzv/K6R9drzEN18y/Q= X-Google-Smtp-Source: AGHT+IFgr60R6EGG/hfv1qbucadH38+M65/DG+xuJSaXMntsG1skx5u3NWADh8GI7FcyDwNsoxp1ZQ== X-Received: by 2002:a17:907:1c9c:b0:acf:877c:ccc7 with SMTP id a640c23a62f3a-ad1eafbe4f6mr342734766b.13.1746622242991; Wed, 07 May 2025 05:50:42 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.147]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad189146fb4sm913182766b.10.2025.05.07.05.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 05:50:42 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, geert+renesas@glider.be, magnus.damm@gmail.com, horms+renesas@verge.net.au, fabrizio.castro@bp.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 RESEND v3 5/5] phy: renesas: rcar-gen3-usb2: Set timing registers only once Date: Wed, 7 May 2025 15:50:32 +0300 Message-ID: <20250507125032.565017-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250507125032.565017-1-claudiu.beznea.uj@bp.renesas.com> References: <20250507125032.565017-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 118899efda70..9fdf17e0848a 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