From nobody Thu Dec 18 23:29:18 2025 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 4E5841FDE05 for ; Wed, 19 Feb 2025 16:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981285; cv=none; b=Jp+1kvOA+9xhQbdGBYNuPuRFyqEkC/cflxqn4UFlIYO6VCRXgcKZ+pARZPZ32DXiZw7vIgCfoKdAuPG08XxKFUXBNALY7cu6fSDxN7XwOlIejvHA3MZhjk7Q2DHP89kS/zv2LiRU10uChI8/vi5Qa9S3pKup8iMbWmcc5BoLQk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981285; c=relaxed/simple; bh=wc4sN7qLZm+el405nRxJo5bxZYh7t6HvJ1R0u+zhzag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BVa901hu702xSAH3sd10P6nTqgIcMAjMx/68ovrk3a8yhxm0XjUm+FIxazTjTV4ZOI0UsCQ39Yum+Y+yl0D/ppoaqE+1VzNztGega8oM9rEuUsd8zkO1RDthoXj9QGtTjoB+hFBNODXCKWJXx400CXCZ12tr5zNW9XgIImNbznw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=i1L8Bhiq; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="i1L8Bhiq" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5e058ca6806so3170243a12.3 for ; Wed, 19 Feb 2025 08:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981279; x=1740586079; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xlGt4wExiEL/CIXJbDF0itACKrrgHmIFMrYFUtPey+c=; b=i1L8BhiqCbPhgjhqI4Fs0WESgBOn7qro6AnnWert3MTOoZLsj7G3+Mjl1knNKEPU3F RyFtGuzwiVsEN0wzECKvdfNoHo4OmYtVY6vBmyEbw2yut+r0f6BuBXFpq6454LhdYMH1 uVvamrLBEtJ/qIN+mQOtNgbYOaax7IyYSTfioADdnREZ8/5bqw3oZ3HttptNOzcaFU+Q yVgK0sgn4AW/9vVfarjUZkz8NPpmbTol5zMuryl7d7MRWVzi23tWpj/ZRm5QuGi5GfZq +VGi/mNNMz/Tw2kT+RPv3fu2B/5FQoZGomXomz7B4ckg3xVgpNmZNB+XBoS9QTQhjdof FHLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981279; x=1740586079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xlGt4wExiEL/CIXJbDF0itACKrrgHmIFMrYFUtPey+c=; b=Cv+dluOvaPrH9C+06ZjJvh5u5MyHqWsRvtsigwByCKDdJ32H+qHFBPiH4NeKH2Yiq2 Ruai9KGgXoCx9TBB0YAdTj2VWvQAbggTMzmOAC2GoCl3y2JXFermEtbkvo5TYAosQ0OA RiOzaUoPjjPSsXw4b0mst9FTiCP++UNwVINTj09Q3eE8jXt+wrEyF/Kuw8bmZaUfJB7Q ABP9kt3/yjnMt44lERnG4qJFAJ2EzhOtPdNfJPv0dBH6Drw52r96O36gp+8TGzmq+sky enoBnrrJbYC1Skl/kdyItW+SwketC4bkCJFs1lVmgSzaG3AoBvxBKDz8kju3U/h3iRpc T+pg== X-Forwarded-Encrypted: i=1; AJvYcCXDjbDVeTut4iC/AfHVRvBYzHRA71Fz5a0qYtbrPJ141PPPt3WIbKPkKN6aJqEFjwfp0eo6yBhKH3c7wB0=@vger.kernel.org X-Gm-Message-State: AOJu0YzQsoNTAebqNUIfUIfl61eXmEeXrGlnDaPooMXkrj05B5j7/eyv yGc8toKkm2RE9v6Xu6hfOapKEJ4qN6tqknpFcbhyI7nFSkZrmOO3hggRzv2LLEs= X-Gm-Gg: ASbGnctpPi88PRzscxt+e8QJ1vAL+B87A77+fU152D0iIC/qvuvK0lvCaxVXspS0h+O jielZVSpQOeb+Tt6I9e+bc74B9RhhYOwMHikDKY2042t/FXp+9YmAKNzjs8QXM9I15rUsZl47XT cZn6e/9Lnn3ONdu+guiX6yxQxdN8PiFlWPao3Ndy+sUUws2Cs5L1saOL1rsxJLhMc4WNV+rtBLX Qf8dOtu4DkY6wk3n3NVi2K+XY2eDmNaALBzB89lNhKOLZxlceIqOdOPn2OA0uwUKG+GBizLXTEI CMI78BznSarmbwzMmaRrDRCrgV79mlZeYbe0rQNqTzn1 X-Google-Smtp-Source: AGHT+IF44ZngvmvLQTa6/DYd9mBS4nelIO/FTgR44hs+O/p7Fl0s8INvjP10jVJEICLAlDgjE/nKmg== X-Received: by 2002:a17:907:6d09:b0:ab7:cb84:ecd6 with SMTP id a640c23a62f3a-abb70e0d0ecmr1908734066b.56.1739981279398; Wed, 19 Feb 2025 08:07:59 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:07:59 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro@bp.renesas.com, robh@kernel.org Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 1/5] phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind Date: Wed, 19 Feb 2025 18:07:44 +0200 Message-ID: <20250219160749.1750797-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 33 ++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas= /phy-rcar-gen3-usb2.c index 775f4f973a6c..46afba2fe0dc 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -107,7 +107,6 @@ struct rcar_gen3_phy { struct rcar_gen3_chan *ch; u32 int_enable_bits; bool initialized; - bool otg_initialized; bool powered; }; =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 Thu Dec 18 23:29:18 2025 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 86D511FDE0E for ; Wed, 19 Feb 2025 16:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981284; cv=none; b=MkJgGBEMenbrz/XXLY0oUwN9inTNHnWtklthlqOHKLIDd5a93opTTNTvE+AOD/zXHpNDY2ujo2pTlfipnqSVnA5en8GYy8qXEg5tRj5SxWe8fHSg/wkJMUGGzfksoobzzgjTkRQO71k2mtQO8Hk5IVCyOIQ1oo1k3CGWkk79JSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981284; c=relaxed/simple; bh=0MUXVyiNYa9K5Dj4ekYjbxuGe1+NWnA9eGzKs/3q5ls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T0tL9D0iIHuTlt6XVbeE3LKPbOdPTNcARObnbAAzx6kVS3grxmrrSq/yaVn3WqQoAfp9gFSHwB6F1gQjw+d431oZERw+599IoMCe7D83gfkwJwieFQYoK3vPpJNUht7b/4DeRpBRI4sbNnn2y3pPp5G8B4ioBMRnKFiogrP/ymM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=EVnSSoKM; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="EVnSSoKM" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5ded6c31344so8791742a12.1 for ; Wed, 19 Feb 2025 08:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981281; x=1740586081; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fp963bQaS09mT/Id9cROqyvlwpVlaGR8uym4PMeifJQ=; b=EVnSSoKM88wSiKXK4+gGeYazQ/2vU5iIYQ3nBgptelyqJhkidelHjZooAQNQ3iwwYH NB3T/6ZoakVJemqsxmwyQT5uM6S71DgkFx0H8E6BJi0TBLWVKtfvi4JIxZP8k9/udDcZ Z8rX1oKd5vh4lc98KPxVzsr/NzuezbzaXhq9mm6pwWTqVEmDEFkZYDAueTJiXeCzijvd fMfUNA6SyBYOkbbNWQGmawX8LOoCeo1Qm/muWJYhwnLXNFlLNaDD/9Y1Tq/f8ELP51bK eZYHu08A87mOkxx+Eb7qrs5Ku/KdkAqFBqMBxLmopBDz2Qc1j+vVesUJUQ6BNDVX/71H e+EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981281; x=1740586081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fp963bQaS09mT/Id9cROqyvlwpVlaGR8uym4PMeifJQ=; b=FN4IKY03lwRtjR1NoJkDjemV5zFVVDJoUYLL/OF1WX5j29mKDsNO5lhyEgvpBJstH7 qiXaGWUwBVKWoQZEfElHZiAjjZlFQHGxSxidmXYuNJs85Ccgy0B9DL3Mk97nQr+uy/s/ ziBeOqWwVDDgflFEN6nKubvfO8jWujYS7/uAm5iLUlC/f4QNUtRRd+YrqfGPbVDZbTZI xNZ+n6aJVb3T1X6WKIusoSm7cMncSY+HKIQFsRnwxk45xbZA+Py9GAzC3H3VedSFx3Tg bLQeiAxnC/KKoc5zpTkNATkOpJo7kAkDhTvBWn4vWwzk4bXdDukzyvjuRqVEMJiFzjXX 0WuQ== X-Forwarded-Encrypted: i=1; AJvYcCWzjzpG4Z6FNmr0mfn+vSNulL3jEcSC819IXiWADx7xlxNFc32coFv0BbVkLUsOhdzi/WU1+NL0zhrF3Ig=@vger.kernel.org X-Gm-Message-State: AOJu0Yy578noI/rxR/Cjxyvj+RKabpaAxuUqZnWQ6aUZp3Gsw1x87ct7 IwWzN2PuyzD5yU2y6zJn25tztwye1ku6MzOAyYPVPJX8fPsAdmi7TmvaaMBHdc0= X-Gm-Gg: ASbGncuG/wfuGfClqa1hg+qlGZsIdc6fmew0F1qf4ylAURTXNBFZ96qF5lkiiCYWOXU yC4Se8s7E/Qe8bwZoZ4Tdys1zojNI9Crc0ICjiOiPofP6tTeWrzo1KIVeqMyB86F+r1ZwdGaXXb cw/sHuH9XGNjOVKqCGaE6aXxu7arqNXXYo5wLx+I9ILWBzswUouVXlUYbTmO2+G9aZteE19xNkg S8OjE4JeBNHDMMith+frdz5fx6XdZHFsiXKKA3wHpTzJtxy9RFyCGIfcvjbS1MmjWxiwiSMyszo mkkGs7TnvJb7/fM92Gr2HV7KTT03//b6vk9z1WIiHcdU X-Google-Smtp-Source: AGHT+IFAgpZWz/pkyw9SWyVoJ7pk3k0HNU/QFxMAd6EP1GrHppjjqFAwOVcnx9/qFdJFy5HnODJk1w== X-Received: by 2002:a05:6402:2386:b0:5dc:6e27:e6e8 with SMTP id 4fb4d7f45d1cf-5e036139cb5mr31203335a12.24.1739981280715; Wed, 19 Feb 2025 08:08:00 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:00 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro@bp.renesas.com, robh@kernel.org Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH RFT 2/5] phy: renesas: rcar-gen3-usb2: Move IRQ request in probe Date: Wed, 19 Feb 2025 18:07:45 +0200 Message-ID: <20250219160749.1750797-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-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. Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 46 +++++++++++++----------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas= /phy-rcar-gen3-usb2.c index 46afba2fe0dc..826c9c4dd4c0 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -120,7 +120,6 @@ struct rcar_gen3_chan { struct work_struct work; struct mutex lock; /* protects rphys[...].powered */ enum usb_dr_mode dr_mode; - int irq; u32 obint_enable_bits; bool extcon_host; bool is_otg_channel; @@ -428,16 +427,25 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, vo= id *_ch) { struct rcar_gen3_chan *ch =3D _ch; void __iomem *usb2_base =3D ch->base; - u32 status =3D readl(usb2_base + USB2_OBINTSTA); + struct device *dev =3D ch->dev; irqreturn_t ret =3D IRQ_NONE; + u32 status; =20 + pm_runtime_get_noresume(dev); + + if (pm_runtime_suspended(dev)) + goto rpm_put; + + status =3D readl(usb2_base + USB2_OBINTSTA); if (status & ch->obint_enable_bits) { - dev_vdbg(ch->dev, "%s: %08x\n", __func__, status); + dev_vdbg(dev, "%s: %08x\n", __func__, status); writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); rcar_gen3_device_recognition(ch); ret =3D IRQ_HANDLED; } =20 +rpm_put: + pm_runtime_put_noidle(dev); return ret; } =20 @@ -447,17 +455,6 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) struct rcar_gen3_chan *channel =3D rphy->ch; void __iomem *usb2_base =3D channel->base; u32 val; - int ret; - - if (!rcar_gen3_is_any_rphy_initialized(channel) && channel->irq >=3D 0) { - INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); - ret =3D request_irq(channel->irq, rcar_gen3_phy_usb2_irq, - IRQF_SHARED, dev_name(channel->dev), channel); - if (ret < 0) { - dev_err(channel->dev, "No irq handler (%d)\n", channel->irq); - return ret; - } - } =20 /* Initialize USB2 part */ val =3D readl(usb2_base + USB2_INT_ENABLE); @@ -490,9 +487,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &=3D ~USB2_INT_ENABLE_UCOM_INTEN; writel(val, usb2_base + USB2_INT_ENABLE); =20 - if (channel->irq >=3D 0 && !rcar_gen3_is_any_rphy_initialized(channel)) - free_irq(channel->irq, channel); - return 0; } =20 @@ -698,7 +692,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_dev= ice *pdev) struct device *dev =3D &pdev->dev; struct rcar_gen3_chan *channel; struct phy_provider *provider; - int ret =3D 0, i; + int ret =3D 0, i, irq; =20 if (!dev->of_node) { dev_err(dev, "This driver needs device tree\n"); @@ -714,8 +708,6 @@ static int rcar_gen3_phy_usb2_probe(struct platform_dev= ice *pdev) return PTR_ERR(channel->base); =20 channel->obint_enable_bits =3D USB2_OBINT_BITS; - /* get irq number here and request_irq for OTG in phy_init */ - channel->irq =3D platform_get_irq_optional(pdev, 0); channel->dr_mode =3D rcar_gen3_get_dr_mode(dev->of_node); if (channel->dr_mode !=3D USB_DR_MODE_UNKNOWN) { channel->is_otg_channel =3D true; @@ -784,6 +776,20 @@ static int rcar_gen3_phy_usb2_probe(struct platform_de= vice *pdev) channel->vbus =3D NULL; } =20 + irq =3D platform_get_irq_optional(pdev, 0); + if (irq =3D=3D -EPROBE_DEFER) { + ret =3D -EPROBE_DEFER; + goto error; + } else if (irq >=3D 0) { + INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); + ret =3D devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, + IRQF_SHARED, dev_name(dev), channel); + if (ret < 0) { + dev_err(dev, "Failed to request irq (%d)\n", irq); + goto error; + } + } + provider =3D devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); if (IS_ERR(provider)) { dev_err(dev, "Failed to register PHY provider\n"); --=20 2.43.0 From nobody Thu Dec 18 23:29:18 2025 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 0B27A1FE479 for ; Wed, 19 Feb 2025 16:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; cv=none; b=Zo36zyo7VNrnRyf9Ci2yWrG4TaD8WCiTEi3HtlAlVFq2eOv8pXvFF3EVT75Xf2oUHD7/de12hSqrNI7UAMWUiIafK/CRt9DCk7rfYDhG5kRToLUS61YE8IwM44Tw2leisNr3rRJXSBKbdYdO+n6XuenSoipoawzBgywTv2LbjwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; c=relaxed/simple; bh=dbGXzpAY3SGMwzX9P+QBAYN0/ZylTElV2Ah8d0DRt8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=saH75ACw+A1h3S9AdSdJ6zt5VR6jApMoHU/V1vpjFYKiXftMoiWDmc8+sSD8xqeEBE99rF832CBpXjukYKyQ+zccR6tOPTu97WCpPClEeOkHw0aZ8+YW+/Xq4v9EcXx1rQJkhPD72QT0FeC33XwkbsQg8z0NKp9PvI8MZyaf0rM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=m3wENOtF; arc=none smtp.client-ip=209.85.218.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="m3wENOtF" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso1061605766b.1 for ; Wed, 19 Feb 2025 08:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981283; x=1740586083; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ag0ceyd6lnvDklvR5kTzKXppBlKmljc5PPbiPVBs5+k=; b=m3wENOtFKSu+3/5/kD97o6tN2/1TUAwDKRGiY69MblWR7v0BCNQw8/B9eGuNtK3uQy k1t+2jlrt4j3qv6eRC6H9T4Gh8CJx5c4I3oz4dGUFgnFENOt9GDGVhw8JGv2BQe9UkxP FCOj0gemSr9xmpl78AkYOgxyeiizORIViRdkgD5aTcz10gFG5F+SnSYQuFiXpqJhWrzI /K3cAoT9FS/PJiNcmaLfqp3/qwlxrLDiG1kYI1sGpKx+/5PEBIfwZL+07NOEy2CFBqS/ Gp4EZLQzzwtTIs1OSgnABYzXYB7JdUX83Qz2/Snp3HhCzYPlfz4BsFntqXi2TFHZ3ClJ 8kxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981283; x=1740586083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ag0ceyd6lnvDklvR5kTzKXppBlKmljc5PPbiPVBs5+k=; b=AzrLUtQSzW8Lo1e1gh3moyIYsUVoZoAuIRIfFOZU6fu3CemMwJA6+j0HDCXu5l7UIB mmGD2xtTFBpRGzlDT7nRsTPP1lVw5rxICYh9Q9dEK93VnGvjGnveCGIGMyHjuMV862bD WU8gfXoLoh8sHWbynuwWfun4cElak2uNSIDBiwp8RF9LZNorV44sFVBwhcOJFWggm74z 1YooDS1aS+g1rH3yf/iVYQWO5r1uI59QcBj0jvm3v3CmBiZWB5mURQm5IeaYb/n87ixG BTfAmPuuXMPjuRUt/tXeCX26LNsFVexohnLtwUJmyPP32q6lLsVOb1OOmboaeuHQEGyE OroA== X-Forwarded-Encrypted: i=1; AJvYcCXjMtll1dH1ZGdI7vltMrijEVgUYO1nN2WKMa940f7tlzZkJ+VSYAxrImkeC0yWx1N/VIRFMAaf7tbBc4k=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1t8PAZ5iWY1MiLYLow0PwqixyoH8T/MVNEPktSH5KdRWj45f9 Nxsp+8JCug+TOpwmc1YcT1Fl3B3tlmACSo8nJ4r7CEIiopJZgTq1zBuiaOdWC5s= X-Gm-Gg: ASbGncvjv3b1IeANPDTXkarQgYEm1qPpKH7pwl9s6KdfyzEeMwTj33lFT6EagZiTEPw spj2fdYp91qbqwL3fsQnMdGGBcqfH7FJMqXiAyxVtHrM6h8e+YnA3CT3keac9Sa973wB8WzKQaW F+Fc9jh+mTIKyoy5dDvVEm3A/U59fGyY45KbwYxlnMay8O9aqXcsWAxzzgGb3OkJ7k7fXG/Wryg eR5UsvXY0Ejm4lj83CdkFGCNH3MKCnL5BsY45KEcgB8oMLqpQHo+QxZre7ZtXvtrkZRCnIZZkS+ u4wMjl81ZEthRRD/7w0G91EAaIyt8O6jBoFEpBHs29qD X-Google-Smtp-Source: AGHT+IFK03MU51YyMeqqHzkdzf8lpSKD/7+03XHiHb///Jp2uJuRaLvE73Rv2ADy8FE6aZ3jeb4UfQ== X-Received: by 2002:a17:907:7e9d:b0:aab:9430:40e9 with SMTP id a640c23a62f3a-abbcce74170mr348337366b.32.1739981282218; Wed, 19 Feb 2025 08:08:02 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:01 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro@bp.renesas.com, robh@kernel.org Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 3/5] phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data Date: Wed, 19 Feb 2025 18:07:46 +0200 Message-ID: <20250219160749.1750797-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 49 +++++++++++++----------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas= /phy-rcar-gen3-usb2.c index 826c9c4dd4c0..5c0ceba09b67 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -9,6 +9,7 @@ * Copyright (C) 2014 Cogent Embedded, Inc. */ =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 Thu Dec 18 23:29:18 2025 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 958A21FE44E for ; Wed, 19 Feb 2025 16:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; cv=none; b=opY9vTnq7gWjGwmUUztLjukwK2d4a4o6TNN0ptXjA7T5Y33jeJImBVRyZB6TVhdOFIBEaS0pcRQ6AFHF3E+izY+gs65sFXvvqhYEI9TpkafzwpXb/4vnpJFnD1th22jkeMaHdhElRzlbdnZgDeTxtiU21ZaPt5U4h3rn91l2tFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981287; c=relaxed/simple; bh=LCck8XOmhlRfZGYdLsspO9mn2Js7FYYo/njobjx69Ts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E/xBOPf3z2D/vnDKPqAzimXd8aEw10ZDdw2oxTozbdPEh11fZHjy88jAKPePJwyrA1KKjy8ZUjZD6lMJcKTeq3DmJibXXqh7gQVjf8278+qMTmlcXeG+RlGyFrPpkCeTfT7omZrIWn2NMm7TlZP4Bb1HAib+c8s3zvnFi7C6jVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=K+pTgZIm; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="K+pTgZIm" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso1061609366b.1 for ; Wed, 19 Feb 2025 08:08:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981284; x=1740586084; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fQx5Obkxi7fOoCAjVu48dboJVNwAQ7ZZpMFYowfx0L4=; b=K+pTgZImwgpkYfDotOZYk/NkIuq2NByOssW7AWpDG2EkaLYN1nP8HvZ/jbNLAU78uj /nV8DCbswwktKNrxAX/aO/61oE3NimNyXM756BKG80MGQMLJfsBiql2tcvanqcqrHqSe n4kIgciNl2IsKt5DxUR054jI5prP3C4j3RWvO2SCh80KRG31Hq3unFSDDWkwJ9xOw2tl TIPkUlflWx8THpyo7yfuASl0jg21K2Nu1uHF+NMOowcSeUZ9WgomP0+exX07UxPuhEtU /gyoCroFh+6h9Fag71Er3Ev+g5nV79oULKEp2T3BoakK6RcAtzUyziNPcdldnRuO2rhC XpdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981284; x=1740586084; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fQx5Obkxi7fOoCAjVu48dboJVNwAQ7ZZpMFYowfx0L4=; b=mOcAa23lDPczkhKEKTyJCvYsUUsf8Lypsywc+Js8dK4qRfschuFewuzvBL7tikJTjR z5lqzJw9UauMzpt8dSSfKKsIGfSNhvbeNxNn9YGSMKBy1aRolxIHQQJvrIQ7+iJ/BO5J hYaWbh4JehDIemHjFw2kXYHMU+Jya6UBnwEmmnxp90ujG12HTRMWk2sAjugXkooMdPjO E5Gp3DOneLDy96WpVh16T+k2WcFpxGwxhFcGhOnloOUIkjRZzDkKI3WP+nUiulGjDj6U vL6I7teU5shY0LjS5ABWKWFkts0XTTY3uxgB0VGR779HIZiMMeTGszoO5UkJhD5i4xzs DDVg== X-Forwarded-Encrypted: i=1; AJvYcCVolQo2zbtV+KdSnFvPcgbGD5SKEWe+mfogm+Sb5K+wxqZrCgXfkOLRSGyg8mXCWzg9Ay/5jUsNzvnEsBI=@vger.kernel.org X-Gm-Message-State: AOJu0YwV6+SryN847LdUFDrgIxzyjyIhQOgzG/pt3yb/CVbgC4DtGpj0 TVf7lYU9GNeDkLgEv1ErpzQBrXwwrEPNSyB5thFiZb+OuZO90pujaLnMbuXvNA+e08zB9alwQMD Q X-Gm-Gg: ASbGncsuiWJRQY7C3gYQrQPr2dYQFyWcs6MRvILPbgcodZCcnumOa6SRAbPbILPexZX k5RnR245ylGhYAuCp3kfvZXUT9ixhd81m5cybgpWUX/4gI1RRQSJZt5bKYgLnGzFxbTRI1/DymK d1WAu6sR5Iw1vNlAIaDcStkQwHAZPptI/1ItzJ1UDSIZFLU81OwzjIQxXU1ezyrQNf+qMEY9g+k 5PsIjDWIjwABK3IiMYNs588WTWh57gh0bjtMj/P7m6RkXJyJtBzTsUcoKmfcuTX0KKwQ+IVvcO4 vDi5j/mRs3mbpEkV1ohu/AMsHd/66yIyZ1gojciTyjhq X-Google-Smtp-Source: AGHT+IEyYVLE9+celNxGo86663B2wzUsZfpExbxct9DCQIl++bGSTCDjXotnzuNdpB6wYwo2U02c/A== X-Received: by 2002:a17:907:34c7:b0:abb:cdca:1c08 with SMTP id a640c23a62f3a-abbcdca498fmr312301666b.16.1739981283761; Wed, 19 Feb 2025 08:08:03 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:03 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro@bp.renesas.com, robh@kernel.org Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 4/5] phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off Date: Wed, 19 Feb 2025 18:07:47 +0200 Message-ID: <20250219160749.1750797-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas= /phy-rcar-gen3-usb2.c index 5c0ceba09b67..087937407b0b 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -537,9 +537,16 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p) struct rcar_gen3_chan *channel =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 Thu Dec 18 23:29:18 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 E4F421FF5FC for ; Wed, 19 Feb 2025 16:08:06 +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=1739981288; cv=none; b=WBREyzNifH17dCPdcx6yT5ggxKZwt9jzf6IEZSlSHqE+0XE1HyXCZ9DsLW1E8GrzkDM5kipuAoIfX7QPaD6ZUvQzGrsdymmvFvQ6P4cUXYGL2VI49p8Ufl33qAX7zOaDCmNNgGtG75pknlFeVUIXEWARU6VdaB0XGy3EVZBuMWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739981288; c=relaxed/simple; bh=Nu+B+aent9gnDnLeup0LX+XZtFmQ3i9h19QHH4qM5Yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H1MGdbmh1X5aMqqFG7HtNiXmv3W6LjrzonCI1zAXJ8h3d2Y5vWFrCgt2soouMa6MzV3uThiC9MGUwtUg2YxI4+nqX6b2oDTXJ7gsmq2QWSIPoYFWNj93UqHtta8iVf4bK+i4rpYkVHaM9MY9qWXzvGh5eAP/tDunoZ7qsfwx3qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=Ehy0sari; arc=none smtp.client-ip=209.85.218.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="Ehy0sari" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aaf0f1adef8so1385585866b.3 for ; Wed, 19 Feb 2025 08:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1739981285; x=1740586085; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BtGBoe5coeUnXZJpUlOcRLqzBSKuMVRJ9kwi5GgXX1M=; b=Ehy0sariCfO4XSF/zqmG1HB8+NOcqx3EyYI89+XO3YwUnm05s+gG6Z8o9zMG9X+13p OiBW8ElNlzC3y84Gkc/7SMswqUa6RkS+VH3/Hl6IdWySdOzMflAc5A3cKMGu+0QgiMEu RWWbFaUCyL1mtPdcnSXXOJDoeEho21NNwTzIIp3hk90zUiQyB0W/HC+POMOQ45Emgqgx Ut1EBEVjIQU4O9V5NIU9EzOBtD+YIydLuhQe5PjZmiAkbpNUQtpXLHNmuCqGBN/3++sb R1OiDmJcdaY1oq1g81gOYmhYr6AuNfvKD4XgWc5SNaa9oKilkwY2P5h1FqSHg9GlwnUg RyWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739981285; x=1740586085; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BtGBoe5coeUnXZJpUlOcRLqzBSKuMVRJ9kwi5GgXX1M=; b=BzhhrO0mqB/XUy5rbeW4SpmRyqIAGdIDjVNZuOmZnBGuAfoXLg+kxDchsbcxYW2UPp f4MB4rDmKMxXuXp4x3uEF/YekjUZumtQ+gW9cEcN/VrXPbtKwFiOuJQ8ldRiEeuzwqeN sxWpzenqT/K4MPVVHOiAG2T1rdTGN/lpujb1gg+S6PwxGacf8Y/NQx/D917+iTbz3wX6 p5lgTBcG6nj5maxkRIEY5wlMu7EK85/GZiffjBx3qN+CUeKY8i05OVBpyiPka3LH/Wfc PncZ1c0Ouq0xyvUggm2P0ztdSwAxscDovrdU21PYSab/OBaZtNn2sifPXy83rYWtgjiV 7Skw== X-Forwarded-Encrypted: i=1; AJvYcCVcdifXjCtUElzqRmcg43+qpJjEBifMAvRLX3NVN9Ssl3pWbiFblMMr0zji5esvV/5zERrIy8R1XOVVZcw=@vger.kernel.org X-Gm-Message-State: AOJu0YyzpnUjHI+HtZoov7KTLg3A9xq0kesbRXwP4JpdvUp0cbYINw1j blmRG/XLpz/2i0oLmnt9YGtQ0pkIMa5J96X+fKiTTs88laIrqPiN+pX9c8S2Bm4= X-Gm-Gg: ASbGncvYbm7F2YULN1c8crBh4QZiuDViOjft4dF5wXBSl86PjjZiZwje6Lvt8MzBVfy f557LIxMJ91Vr5Hny6uo4QdkTQvwmK9oadLWkQmjxhICLOfhlX9WaDfuYlqYyVdsszM5TXw0Ci7 8yD07Jm/P6yNdTkQjT1rplG7w90G+5eWK0F6pRhrEQTPyXS5/h7qnvpo0luCjeKbbs0go8k+Qpm PaHKDj2nxKr4vuSlERN0DO679ZZN71RzSFTBm4hfacrRF0XVG4JDya/ln3ApDj25eg5mNfW09va I2Gn9axCNdp4HdP73piViuhPHEsgDokjpoTcMrlYgqHo X-Google-Smtp-Source: AGHT+IHxe5ZyQ3C/l0BujyjIhZwXC57yvWHfxRUBHLFeh5ZxtlbAM5sS46OrKTP8YZUtyZ2rOwWbYQ== X-Received: by 2002:a17:906:9b4b:b0:ab7:c3c9:2ab1 with SMTP id a640c23a62f3a-abbcd0d1b4emr437963966b.50.1739981285101; Wed, 19 Feb 2025 08:08:05 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.25]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abbc0d0b882sm327791066b.109.2025.02.19.08.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 08:08:04 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, kishon@kernel.org, horms+renesas@verge.net.au, fabrizio.castro@bp.renesas.com, robh@kernel.org Cc: claudiu.beznea@tuxon.dev, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 5/5] phy: renesas: rcar-gen3-usb2: Set timing registers only once Date: Wed, 19 Feb 2025 18:07:48 +0200 Message-ID: <20250219160749.1750797-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> References: <20250219160749.1750797-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-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 Signed-off-by: Claudiu Beznea --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas= /phy-rcar-gen3-usb2.c index 087937407b0b..8e57fa8c1cff 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -467,8 +467,11 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) val =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