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 X-Patchwork-Id: 14000576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11B3CC021B8 for ; Tue, 4 Mar 2025 12:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tERyjAzHxurvS3J48U6DMnTaA/HPKRuGiTbC6shyiUI=; b=cPG17iVm+NZ573 w/UQo65iJCtFXGvCy8XiDpimABseWIuZMISZhd77KGek9j8i5YOUeh3hdbhbc6yQX57a0TGm+Wft8 WJn2gzboi1vgzXo8xWSQ3zXP0Ew8kTDLj9VSjzjVTD8Ll7m57XENb09WJQAp+0aVCOowEQ5Xngq/D I+qWRif36QR39mqDGp9NjvbfZvU28vMFOhM036m9pxMm4QQn+ADdJRBWr7NodX3sZRtAOPEs9oqN8 37e/4LmZ79cHL7+1ePArkeF9yaQtPYbApPGwvqZBm6jPVW0JVSR+AToiD8LBDlNjn3CmFt5z/FQwG ngS0mXk6af0e17x+nO9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpR4o-00000004Wcl-13Ce; Tue, 04 Mar 2025 12:08:46 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tpPpC-00000004GLE-0npd for linux-phy@lists.infradead.org; Tue, 04 Mar 2025 10:48:35 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-39104c1cbbdso1108946f8f.3 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=lists.infradead.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=S2y4Sq8GNabUsqQOoT6/VGKIf/LDwJvkayK8uLTIi+Lnuew5Ntdo0KMb8cqkT/RtFX GFjUSQxExI20+6DNLLQn4lPbpaS/IQ0YK5KKNlk7fTzsfSClOg7ORuQhGkJBVyxCT1Di h1aA4vKnLDd4tt32Oqg1seZ8tsfaIf4t6uGlXI96W7y5vxjMBwNHrbYs3P58EHpNUeSh g+B6aszUvrw/7lRw8E2MggrGxb0sBLNufWbM7nOF/Vp/obDHL80JgeVZ33dMuufjTFK6 MfIGCk5xPoyMczWn5qM95YCblLO8FMGiXIuFNHWybsf2K61fiGovHfJfkEvySH1DFPBT INvg== 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=SLPtKn5om0HZTPjv+KK0CFNuzkik0fTJ+YjY7hzVk/b2NdO2HWpqRw+7W6vHT4+xc4 LZbheGSavMWGXpBHARSyGfMQn5+cRe3YDNMB/+T3csgrpsY7ln2C4mQFQTobKs64/lrX i/WPp8ibKdA+TIOk3syZegURf6DbVSf1peZ6UIG4FiuzBlHH/EACt5YGUQo8ifpTLb/9 wC+Z6/2ie+VmYrZxsaB+k0e4hB9OAVjjFcIoPODKMkMerQQlrEOQ2Ox5I+A5wPo97rm0 p9a5N9L3W7LR+QanASRP5n5xhOXXlSA1E+ATUjodDlIT76GcmZxaOsoVrdxYAV2SQtU1 xfmQ== X-Forwarded-Encrypted: i=1; AJvYcCUJWwFWcTcjbN6CBeklfGiYcSivDSxQW2o3KdMBCLOdDbLcZJxQL62lMvstFfBXqt0b3YaEwDqZf3E=@lists.infradead.org X-Gm-Message-State: AOJu0YxuGcfssqcHMP5jxUTSFswY+A+09svEpnc14zkyIC91P8P58tp4 rW1K+3qwcjTSlyVN6xVK/NkRJZI1eoaS+QvVOL9qdDZJQhIOtvcS96YUVJEcrKU= X-Gm-Gg: ASbGncvQsyeLtkBnKhSFfXxOTAdS3szhqJaxpYAdJ7JoYvhjLO9DknYvV1ieaVybcto FivBft9dK1X3rhly13W/cOKg6yYVIwQHwrLEMw85iQodIbefMzd+JrMPA9Y80XVVf+04Bm4oJ5e 8JBVFpFsnlXZJkJByVPdKHehSa+6RxfittJtGNRBcHqgYF65xf9tsJgeeIOjJSUB692pdrpSneI VnQaX8JJKRpvDnRRbS7QjH0GJWNVo2iuyycfuP2+B1oK47Mx3QU+pjDG5Rfc/CEcnUhHM8aC2gf MfsdHjR6+KVi719NgcrY2JmcVn2OBS/LuoEINUApWkMnR0/v2SLTMBYcoxgeil1hb+5YsAmvpPM = 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250304_024834_231451_892B9023 X-CRM114-Status: GOOD ( 16.86 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org 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 X-Patchwork-Id: 14000579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25AA2C282D6 for ; Tue, 4 Mar 2025 12:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Mu9qzJpVOTB9Ny8gcZvDjpkXQsyczpPYiO/SPySB21E=; b=HkJ6fNxga8gCSk 2jQ/NuCA6S1VuSxNkk3WDznTKmXDCvXlYgWnefIxdpyHPru+qKSCjDDVu7Ufcm5+WBUfPKF1yPakz P0aRNMpbq47uB6DOg+svDIbgdFT5O0wJDksUZgDMBH8oiVJ7pr1GP7LW67gPj3GZz/iQfbzYpfPAw ff9FscdJcLvmYDWxTIstcj47kDUFd4Q6ZYQOtrkadIvof5ycm5iXCADIDEI/km88eDgcsjKxIKU37 3Pb9r3Z1+jBPvmjFyvo9JoOt4UeFqwzfL+qq0qg1A3unzmM8Hw3/N7uod2HTiCAXtQsPF8IBWn8JB 8AreVx+6cKIItzOHv6rQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpR4o-00000004Wd2-2CjX; Tue, 04 Mar 2025 12:08:46 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tpPpD-00000004GML-2hW5 for linux-phy@lists.infradead.org; Tue, 04 Mar 2025 10:48:36 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3910f525165so1430386f8f.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=lists.infradead.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=K/C/uby811xTpwz9EN/Mmtm3wKUotzDqTT5WCBRfcsf5hgzy1L0BEUbBRGvd2aHwwM UfkubDuS64lr8jT/k/5g5TDO4LLbqE3B9khQUB51oY2uVLhHbHFyRD6ZqkTJXuw5wqrc 3jqDQDBDEB420fMUnKzLYw3sqFOav8WF5sOgK8kRGHqrsKbeF9tzqsjt4kIgXInpQDNq 1cAiTZe+gyzs+U6QHS0JqikY6c1FNvrX8J05ggj/o8yKUBgysJyHV/edQBgBDfncitTj 9qcPXwl73+oVA6RwlcYGfW/0kbRr+voSHxrFv+QZPZhku4gns3ofNIJbXNZgoIji31iG QOYA== 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=w2/MeU7a5zq5uJqQVCDdbMXpRQriJHkOWL7zSo3ewi57VcNP786nN7k0gjpzVQmO+u 5MYLXxAgmfCLcMNmdb7FzNUV54+mp4ZhZ8WrCq8jz8Uyhv1Vbcbbrtj7V6mNdsm1J3gx /JtcNWqdnA7fGDJp11IjHTfgak26Dp7N5Xa+SISCFKCh8LK01lUVJJ6HtG/+43Ue0Til QLTEx4Czqnr1fZmuEmd1NKBuW/8Wr8U3j/CQQPQ5GPx1JPdfInjo5bioGOLPob46DhqT duYyf+23pxplUHZcEQG/UTuzDbHEpmPIkpXRA/5B5/o4YSxZv9m4+0HN89+LCVeTOJbb FEwg== X-Forwarded-Encrypted: i=1; AJvYcCWyAyTZjPExFUH/Qsz8F6V42j+wJpT2VKUMGB7AqLjc4cPAUk4HYnc5GdfDKAz4aQ/QzbpCe/1q5Oo=@lists.infradead.org X-Gm-Message-State: AOJu0Yy1llFdU1mbpEgik5U1cMeX+Ku48xA8W+XYdrbLMybcfHe6VNJm zc21DaSScKQdhgBdzGJIhKPUT5RLbwBzL6GkV7uYLWNUQXIYmqAI4pAEVZmqrwk= X-Gm-Gg: ASbGnctGagrFvIENXkGg+iCnKqiW6mbmpLTyn1cZG8CMzu8kP3I0UzKSMIpkebcAuPx loFet61nKKvmcSMZHF3zeENAOxvNVgfF8o9yd6suI469GStOI/VaaZNu4H4kd3J7S8/qTaoaaHJ Hwc/wZEncLVCYvQpCCdr1AK9kg0rNZAJ/os9fGitHmueSFFAInJpIoasxaxGNHk3zdsATGHT7fP hTAoS9ZMvWBn+UVyKwrQRx8m9tqqLxrEprBt6irr3RPh4HkRUtu22ughQgUvO9GvGEXCo433CRQ m5+o+cAv2ObKs11W722eLKlXqU6DlYm9OMmecp1gSMnNJotqsyXUAD97v3JQtzsyxPKmAJp36e8 = 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250304_024835_687469_4CA8BC11 X-CRM114-Status: GOOD ( 20.13 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org 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 X-Patchwork-Id: 14000577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27DD0C3DA4A for ; Tue, 4 Mar 2025 12:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ta9ilxP1b98wVN+PRTZ77MDwvA3oS09vvaha07f/+20=; b=v4qxAQ6+aZUJTN j3YGaKzmYAwslk6Bfen6oBrHcbWMnaIk6NabHuSVVnsAsC2I8wbXzoJHck1qco1pX7YLr7bR1ESqF c/U3rRBZTpnLuKyErbbbBJkf0VBKj9oWZGMNd5WYBSyWe8414idXYhP3UG3hHFoHQ8IXuGUfljUMh 06xbKms7x0MZP0/aRAGfQ8wuw/sF7RcTwotts+c2v+DT8pzVgZJWl3wFwpJ7F499Ed6vmYRJtOG44 2duZcyz5THBat9fsYnAXiQ+cAhIm8gQ8kjDjZmrOnruK6u6TbH3vBS71lYG+n4LcxcH3JMc0w46/i 3h5CX9xv+cHhGkfTaPEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpR4o-00000004WdR-3KER; Tue, 04 Mar 2025 12:08:46 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tpPpF-00000004GN3-0AbK for linux-phy@lists.infradead.org; Tue, 04 Mar 2025 10:48:38 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-390ec7c2cd8so2687815f8f.1 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=lists.infradead.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=bpO+HR0ZOFKDv8TEyd5ypOPbW3j7AlrAxnvM7Vwoff5k5F5ww8ebt5S1UXUrL8k40z UHlYzp84xUC8vJ6lIyGxInRMiyrAFvkjxQK+zpAAqC6gW9wiJmoejIEyefOd530dZz5Y sfNeoy9IyToZBsXWzicvOGMgnqEitM+nPjG4wJuLFG7KoemN4ut3J5p3Uly8pFW3swp0 h5BzfgZT54TKcgPu7c2YqvrbsWYnd2/SMvAUOUa58llT4REcXn8QEaUJxAkbklO2foQG WLyveydN19A9qUmsY/il+lU+sz+1FUCysUUVU+sHRjF6VU0SgUJPRb2X2e0bW8n4WDIe TOkg== 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=XofZzV+hQTwTTIFTRUuc8IXlB96x+pdfhzT56ZI/yB71VoPpDyKBtFBnZKyNZBlGLS YBpYIfpXosI/DL7B86LQxD1vJAbCK3Bkykxkzui0to33aJpnK6ZWjHUAiO9ttC6PGP9Y 9PCXPITj1bFsTj32NhEyoycA7xz/XTtKb3cNlZJbR0uOyJA2YoL6Qs0HK+W4Jkj4oRif 9KD9hgvxi7VkDWg1itp2OCzHCQ7nPP//Wua7qh90ZLHM9w9s4ehQt83NIV5rncUjXL/m 4jr+FKBOJF9dk/fgfNKOmGWb+rS3lGBbc6Bjw5GH4xZJ3bKoeJQwm3v0Lo+nK8/1GAFX nzLQ== X-Forwarded-Encrypted: i=1; AJvYcCUke8nZ0yds0xGh//RYyadQR4x7LFO3yHOUAeVczYlq1aDavxjF9wUNf1vj73XCITcPwwcuOFvbMJU=@lists.infradead.org X-Gm-Message-State: AOJu0YyHyaNEU0ydN/vmy7qgG7T0wtSXU/eLocVyqvF5rAL+atFMjlNr KlS7t759kNR5fide3uC5jOmunt1HQPBoRxuOfMrH8CteK0NHsNkvv4z7RXmDnKk= X-Gm-Gg: ASbGncv7rmbTJnylpKukWhAz1UtlbEnBHihUkPzf4ZRVn7XmayaCmwtOCQsfkeiTka2 fkSmYTB4LRYJ4LrnAkO5gEsqterrZtwwK6gfsiEGgRPig2a59d43LgwQ5srl0VgcWBRWNdX8HAv xmfvdk8UZOkUmZNvGRFtTF1HcreI2apQdrxJm8XwzdrxHaV6fx3KllMcDmz4IGGiw7f59L5/8fE 8d1QoU9uFj+rxzTMTJG6m0eh1MBipzRudTJIq9laV2ML6YdFm3fUnOzr07Il0/qYSc09ORrHJ2/ 8oLyLR+U3KZxmp/Y0hVXX2nfmTRdg/Br1gwZL/FczdHREbEiq2ty6tNzhbkixWqzFZyJfhNxGhk = 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250304_024837_080654_B1576D07 X-CRM114-Status: GOOD ( 22.64 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org 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 X-Patchwork-Id: 14000578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A1A3C282D9 for ; Tue, 4 Mar 2025 12:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LhkrAOUhzWEeB92PLyVoGS/fS8oHI6f5m46BrZFGajs=; b=zw59K/0RQtoe6n QXXdStYYaddXmyaF+nYP2f7hOPC4+p4fqlFWUbZP6BPwQ/fiS0m7Fffh1EuK1oKqruQApbiYh2XH0 AeLgpONywcWqjD9wDe1uBy1YUyXBXLzQyNoE5gKEiRmF+ytsPzRF9+tbgjuNrGgD0I/fj1eDSzIpv XVlulEKe+m1EdgL5jaN28q59hPnFyFlKLOVpvY179t13mtKqnU84RNdk5tZTv/YQC02ztksYoaW/w ghjauaOyI2QNXMk65PpvsNCVYB8f0sqfvF9qZ7H7w8AYzcUll7/6oPv2f9WaMno3QvVl1sF83YglP sXkUPYvF9j1v+FAJBoUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpR4p-00000004Wdu-0QRv; Tue, 04 Mar 2025 12:08:47 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tpPpG-00000004GNk-0ose for linux-phy@lists.infradead.org; Tue, 04 Mar 2025 10:48:39 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-390cf7458f5so5074128f8f.2 for ; Tue, 04 Mar 2025 02:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1741085317; x=1741690117; darn=lists.infradead.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=Q/Xi9JEXKbhIDdXSDD7NMUn1NMweEVBaHqiJmgxgNDvElwv2EQtmd922IOvkXKmJE1 5cyNuWFkDb0/JfoWXuJPuJ2S2262OaFjh8EWPJdnluc1l7Pf7NvGklW/DnV9i5t2sLxR fYuIslR4BXvTvfwTSyRb7WflVb45HyoToghCVVJEmZAqopE/A0FaJJ6jVxcG0II4uK03 Cny+MbPgrLuFvg9rJVtyorUvG10xBjJC4wS6S/EeQsWJ6DfJjw0Q+zvUDmr8iHKIYjue lEouL+ZNIPOzO/bB5coVOEdrmJ+FbivKh07D7d07F+MZ7VXnZdn4eC1KC623qMMJrXOa 8GBg== 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=on8C2N4yn1dq4d5ePoDZpc/2gP+/Yd1SBOjxiA07Wwff6Yv41MT60w7mecV9xPp3ke hprPqpw5MP+vsIVKCMT+k64bPjuuX/kcA+rULgT3E9JkPMK96KHbekKt+Uw3spruofNL lu9ZgNjpSfo4GBh6cqWKn1Ljjob4ofgU7BvG8zCclUUB7X/ys3jJ3J5WLv8FybXjsljo J8qJDHNHpC+FSXvJlVoV9l6gNBTJ/doaMXQGNDUrKMHqARCtUuW8WBXw7d6iwu124pOV /d0dgn6BNGxxmu/uJd46fWfBVuYqkk7shuwef5gpMlH5v3uYSxnzEJfpMbMpFJ0rwthY lWqw== X-Forwarded-Encrypted: i=1; AJvYcCWaBrQgSW/NuP7x/sdBEjnoAEpr+wauvQwyq/aH7TeiBysHWU4F4WEbt6Z1HyJVWRudDakqkOXvut4=@lists.infradead.org X-Gm-Message-State: AOJu0YwgsuNK3vCDymmUDMj8pmXRyadiuFKoW8mBx2Pdg6sHWnz0aBP3 Bj5+HmXQtrfD/6S+1p4alY+ZPnZ60NUStDiBdUvoGDAvC1NCx/tbkeCiyWmMYH4= X-Gm-Gg: ASbGncv/b8IE0Imz/w6fkhq9lsaJcaVP2AVIM4m4VSh7MTPQzxzBFdICbZrL43NfMDf Z+EWuGA/Kzv5cWH5Qz/Fck/1V1uWb9R3oN20pOEwWaZ1S7ti1yOPuy1qejzXb/BqNWaiYGbhjim CBkWXklgOGA5DmU2++Wck5H9br204y/2pImtJAVMl8NLsiXxh1H17zmnk1t8/70YOfhqWYUDvKa tjAWJczeb2R6cP3ZnIz29lpZ93u/p0Bb9wDQMjsf+iL5HCCgpII7zehBFsiwHGOUadxFH0Kvf8U AR4WQZpDbShe4C9fOkdMmjtqW/GoLHXXN8clysv85wsj98k98ED13Mldx72y0xG+Jsrw1QVGXes = 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250304_024838_237078_9EBFBF29 X-CRM114-Status: GOOD ( 11.01 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org 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 X-Patchwork-Id: 14000580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE4D1C282D0 for ; Tue, 4 Mar 2025 12:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YSpfU7lQRWyy1ubQ5dzOykpma7jsCbZumIpNRRmNbFs=; b=osf+5Hmfx41kFo Qz87CVrgup4H5viND313qSGr88rGxzDHRyNTEquiLbfNcbuXQmhMrcEoWuo+v0JiQyMkUcbgLUtSp HzvyvriUwSSMV/2YWTa9dkp+1qsZRx/GQIrGLrGo0zEec5uMlNW7qnP0g8hchy4a6AHzLRe1GYsPV kLIhRnVaIgI7lciLPExgsCoLaAOvf2zgbkGMspJJHdAOBvvKvnbmN+jnbGdQl5ZeeTPi8IlhyqmB4 SQd49qBpbCkdUbjULaBTTTkEcmYPgdCzf1ct0ZbJIRVm7EE/s9wVPlXeTADncXPZcWM+T8kDwDsi+ Z5+gyoySN4W8XMAMXM9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpR4p-00000004WeP-1gQ6; Tue, 04 Mar 2025 12:08:47 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tpPpH-00000004GOV-23FV for linux-phy@lists.infradead.org; Tue, 04 Mar 2025 10:48:40 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-390fb1b987fso3371189f8f.1 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=lists.infradead.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=Dml0hoAD40h8+omUHL3keFx/32aMTf/6Mtd3+svLS34uMmtt7g4BAk5dteqnxQ1i2H gmIG80XzAXcRhgnPGpQhEGgjIirvLgS9UTSTQxzH2EodcTaSGCfH1MdSi7HOlJsW567g RprumqQcQiP2N/o2kdernTCyhqoRaNR664h6zgGpGg5+F58vrT3VktoMA/WSiG3LvXPS BJmbQvVbn79H2TH9h2jq3HqTMouPdCs2FTE+b1NvbQv7BzEUy0HbCxGhddmVTWCeEU2W 9ngc8LAxZ962OVIgeK4gIP72LEegb4clAjkFWgc37wcIXY7OatC0uxKzpkhGHiobEP1y qZew== 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=C2vksDKYkp0xErqmrPr609mS57PKJCY/JyRRyqbTqO/DMwpU5WSAqGO/H/HpcNfDgC hZzpaZp8nV62TS74jwvBJren/2vZngDC/L1v8r//4BgsZF9GV8mRVNujN5FCg4985dzY xZCD45HnkYTVFwzJJIyPVCvBQWvORB+6lhL1CMqhVbzaCENtxkYUDPu6StzoUK2XwVZW IODOAbroOXMpQgtEdmTV5OefwmnB3clhtmlTkwquyLDckqeySvuCUzEPkrX5UBsxS2wq I6Mnu5WTzcOqod96HLcbPe9ZnCa8JQXVg2bWsEH6x9COeybQcl9NsJxSz+MAM05A43gM IthA== X-Forwarded-Encrypted: i=1; AJvYcCX8x42hx15doBGirbzCfsiu1ym0sO/F1+HJNzbYh8Go6nM+yIJUooVCOaCLnn3e7pn+3h3P1BRemwk=@lists.infradead.org X-Gm-Message-State: AOJu0YzcH5/Hye6orzmiEPvTf/nPxRo/t3KR+zA6zMx4HjiaIWNpGImE dFW/6gOC+pBPQexXM8VPSWBC7xakJVlpWHscJD2S7BvkmxlZkRTAX3m/QUeT0a8= X-Gm-Gg: ASbGncskXqPwk2FZ+tDg3JrIxRM8tu24Wf7VXwSEUniV2Z4lWLy0xwvEH6cascBPM6t qTCFPYgrha/g2ftWTArPHKUdppdj+XSyCXG4bah69nQMGYMwYOhuo0HxerfYbLQ1ro1py4fLj4b AOuxz5YfKqY9g3Bllom44ZiiofkPxqlinpmNsPzOmJ6HPGWVdpRRtyWT+Ij6G8d+PEhSnZ8JkFJ uvl6ksHA1ZLl3VKX3JDwEYO+ZUQTndX7GchxgDooQZ6di+SBs6UedMkfSGssxALiskhVkT0fe9n VnQGKJY3uW2jcrfZzOp4BSVnJPAlQ4HNSTA7gKrj5xVeVYxSt+KSofPsr4H4GO8CpBeFAS2SIuo = 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250304_024839_530892_848AC582 X-CRM114-Status: GOOD ( 10.43 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org 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)