From patchwork Mon Aug 19 09:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13768089 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.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 7831615D5CE; Mon, 19 Aug 2024 09:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058277; cv=none; b=qbsT1ILGUd/GxXbgKPjkt/Ef65pOKS86y7MbjhOxdXYn7rt3qe4FvN+EPxqcmlMN1xOzFK2VTVgl1JT2jbSfMEIgAGbUr7LEOhMlGQBkjjj1V42bW0m/1/HchQBN0hq9VPbo8tAdUSK6Yw8lf/kM9Zro2Mre7Fu7DVLCmbgOJgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058277; c=relaxed/simple; bh=PBWJwpQrTmQMhxS1evGm66Kvqii7McCIh/AU7DcqbUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dR0Zf8KPFJPsXI51eiH7Regv2eGoZamlQwKoEHmlYGbs0gtoBwm7QNm1MJqk3zOMvWMOPbiyA1nnBrJrtE/e1OuZHFYLvpgUtabg+jO13U5QT0VtihHnY8GC/5yIcm9NJkVWRfccU/iUt9bgebnWSCWcu15/aUTR4doh7nN5fkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mF8POMJV; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mF8POMJV" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3719f0758c6so1340178f8f.1; Mon, 19 Aug 2024 02:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724058274; x=1724663074; 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=m1WZmnJzwRNoGQ6pe2EZwbvZJ2ojrMh6cxbYC/hMf9M=; b=mF8POMJV/6nM6FZNoyS7UyW0poWrmGkEHY4Gn0gV5QiYO9j2ACOKPquQZB8uD6sa1/ L5YDJSnAVthDPv6+KqyBNVaFpXCEIEBNK6cmOCOaGPkEUVYpuLBpAP4D7LK4oylXJA8I wDXoiywM0E405CNf5tslJuv5FoVmLg29qniNotUVb78dpg2Fj57X5L2NBqDKHeX7zCTw QLhihNTvBThjybNtus//QRYwatfJOgTqJyzkL2sUy6pzthIS5ga0DbWmXd2KF2xebxiU oP4AmVyVxpk2KJEDnFAHVdOxNCfPC8oBnUTT5zdrU+TjsrcxcaZtrr4kpKCatxWtgXVy 04Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724058274; x=1724663074; 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=m1WZmnJzwRNoGQ6pe2EZwbvZJ2ojrMh6cxbYC/hMf9M=; b=KgdlFufvzamx7vuWh6cPDqVfGmhw3nDnepozPrQJ7u2NatB2cxhpOLtdKDZ4B2vAMs jzd3SyIbx+zwXVNliunKgc/YMdn2gBMQf1HDLEUH0l2NAFbG99QzJzMN/byNJPbgsu+3 yDfP6O8xvnAmRyPyWwZ1gzTgSTuMAILDStz3ensBqd2YDKBzX3+iiDXsqIhUwUwuOUqZ hAI2Yd0HCCyiq69jw7kRsiW3XjDjjpvnznLQbUjSXu93VkeGAeweH7HFN6ZHMqRhinL+ zdENdUi8LTm+0iNTjxsQ3op9tr/9u2QeRthL2vTjfx19Ps6IifgPb2xIBUUWYpy6+i7H c2zA== X-Forwarded-Encrypted: i=1; AJvYcCV1YQH/lE6cDa7IfX/NhIESzcX7qfXoYK81TuM4dzISsPd7NdMAjgwZlJbqa36xeyjRthAMo3xqG07F85aLnSXWBmnDGed/UN1zX68N X-Gm-Message-State: AOJu0YyvoqGDlQhYt1WnESDTU57nkks/aWWg+FnfmSK1Q4Qpf0xQRunc 8FDKWPcJL3g2uavfU6D/+X+RayAhqhCmzuOVSFV3lN3oss34NAff1bth4H2Y X-Google-Smtp-Source: AGHT+IHE05TuCyt00A6s9cE1mKfpK9EVIx9TkS3oCHaFi1BhoF8/ztPZ5xgaGZQyiwuRYNARtev9jw== X-Received: by 2002:a05:6000:1a89:b0:371:8d08:6309 with SMTP id ffacd0b85a97d-371a7477af5mr5590541f8f.55.1724058273566; Mon, 19 Aug 2024 02:04:33 -0700 (PDT) Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:a64c:8731:e4fb:38f1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded19627sm154672095e9.5.2024.08.19.02.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 02:04:33 -0700 (PDT) From: Stefan Eichenberger To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v1 1/3] PCI: imx6: Add a function to deassert the reset gpio Date: Mon, 19 Aug 2024 11:03:17 +0200 Message-ID: <20240819090428.17349-2-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819090428.17349-1-eichest@gmail.com> References: <20240819090428.17349-1-eichest@gmail.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefan Eichenberger To avoid code duplication, move the code to disable the reset GPIO to a separate function. Signed-off-by: Stefan Eichenberger --- drivers/pci/controller/dwc/pci-imx6.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 964d67756eb2b..fda704d82431f 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -722,6 +722,17 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 1); } +static void imx6_pcie_deassert_reset_gpio(struct imx6_pcie *imx6_pcie) +{ + /* Some boards don't have PCIe reset GPIO. */ + if (imx6_pcie->reset_gpiod) { + msleep(100); + gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0); + /* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ + msleep(100); + } +} + static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) { struct dw_pcie *pci = imx6_pcie->pci; @@ -766,13 +777,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) break; } - /* Some boards don't have PCIe reset GPIO. */ - if (imx6_pcie->reset_gpiod) { - msleep(100); - gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 0); - /* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */ - msleep(100); - } + imx6_pcie_deassert_reset_gpio(imx6_pcie); return 0; } From patchwork Mon Aug 19 09:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13768090 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 4C15215D5CA; Mon, 19 Aug 2024 09:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058278; cv=none; b=X6/A3vvO2IkOPseqbUqLlLxEZLzN6Ga6BAoS6ei2MVBfjtsvzcNBT4stGcN+/pL/C4HOo0WV8n5dVNDLMNQWFnsFy7lJLmRXeT0xNdGKM/RNzbahxNgC/BVKoFPdYZkbuO7fnKDkwGORBCBtyQzEEbcJq+h53u1pHU6fR9aSZkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058278; c=relaxed/simple; bh=EGcprhy5mZbPF9sfa+PupUNrxqcOBkimo2HGnH8hWpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l40PsDvKgrL3PWoTaOUlTZVGtKsDActwIzfEw3ZUpJjFxSnZdnUX1gbRqeKeVb+54a+LuJ7HD/YVzeptlxWsUXJBAxlwyppc/r5awIf+/XJlOXS+i8WMJ42Q9Aic8VZloGPZAKGGaX74f1tqjuYo6LcHlYN06X8pH0ZlqDanJp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Uf1iJ9yz; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uf1iJ9yz" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4281ca54fd3so32334115e9.2; Mon, 19 Aug 2024 02:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724058275; x=1724663075; 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=73KaV9INZpxIDOJ2Xw69bHLb9GRPh7H+PU9DOGB19/g=; b=Uf1iJ9yz1KMza50hmbufWnrUDiXiVhztN/uff7dUVONejvtkjWgqNm7WG/ED+mS4zH BRdX7muNnyaTEJ2uzhEKVVEUNPGJPVXiBaaOzBwCJ4VezAycPgysoFzkHfiEHpnr461o 5lBHoGDdtWk+co6boiMEP4qCJ/4zLAEyhRUze4u+C/XIbcM/Olh8m+mxzpABoTxLAIOp tX92XrCuaKP4v5RWlucg5uvJB9LIxik6YsyPdyCQZECa2DMGnshmF6PW7px6b4bi+deP UoUotRBdrQjS5yth7H/IET/Ljb4hMVd5iUif4NYEU7y3+RbpuDXIZ304yEmvIhjncM+y id4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724058275; x=1724663075; 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=73KaV9INZpxIDOJ2Xw69bHLb9GRPh7H+PU9DOGB19/g=; b=gho3mBlah5JVyV0tXmlq49gHSzCCIvmVcgOC+BmhO5mXvMCyGgXb/Gik1XQWpYhj8I VmaAPM4VY10VstjyFH0Tgqq0Rx2N+jV9w1RJfukleRpZMh3eAj9jOngeVkxIS5VPAYxq +ha7iHKFKiMFqkOI4IzxjNVPAepbIc8nBTNMyom4C3tmQo0s9kre5OYPUVqrtDGqcCn6 4t0qWCo1UGiS5hrnHhz8lBusrSvhbAZOoMPguj5A7aR1vIEvM8YSKEmyHdl22fIQNR5E rYwQYRncUqVetOSmAapJTai8BVWJQGOJRT0AWE3QOwMcJAKZT50Gdfr22wBKJkJfiV/J RP1Q== X-Forwarded-Encrypted: i=1; AJvYcCXmr6/v1jQm7GD3pqRHv721aBKlpY+ApgZPIjwXEhvkBg0nuFTNetfpF/NBKD4BCE1SHgcfv3gjORVhb7z3n+If1dCx4e66N4zzPckr X-Gm-Message-State: AOJu0Yz4JzYkLvC/SDTkTyq+nP/1j+KEbVwOwV2rtWTrRMfkaQ64WoD9 ERHUc5u1TmuZhNgvaWlyqnwF5EyRt8Bjl6GicXfacofbeu9V4rPp X-Google-Smtp-Source: AGHT+IFj0i36M1XtioC1FP1u9W1VBkISL7S6BIM5YHh9arQA28kGUfNyxyAdUgfl+WXFeQvQpsZc6A== X-Received: by 2002:adf:e78b:0:b0:371:885f:73a with SMTP id ffacd0b85a97d-37194695bf8mr6200443f8f.58.1724058275150; Mon, 19 Aug 2024 02:04:35 -0700 (PDT) Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:a64c:8731:e4fb:38f1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded19627sm154672095e9.5.2024.08.19.02.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 02:04:34 -0700 (PDT) From: Stefan Eichenberger To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v1 2/3] PCI: imx6: move the wait for clock stabilization to enable ref clk Date: Mon, 19 Aug 2024 11:03:18 +0200 Message-ID: <20240819090428.17349-3-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819090428.17349-1-eichest@gmail.com> References: <20240819090428.17349-1-eichest@gmail.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefan Eichenberger After enabling the ref clock, we should wait for the clock to stabilize. To eliminate the need for code duplication in the future, move the usleep to the enable_ref_clk function. Signed-off-by: Stefan Eichenberger --- drivers/pci/controller/dwc/pci-imx6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index fda704d82431f..f17561791e35a 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -632,6 +632,9 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) break; } + /* allow the clocks to stabilize */ + usleep_range(200, 500); + return ret; } @@ -672,8 +675,6 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) goto err_ref_clk; } - /* allow the clocks to stabilize */ - usleep_range(200, 500); return 0; err_ref_clk: From patchwork Mon Aug 19 09:03:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13768091 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 2784F15C125; Mon, 19 Aug 2024 09:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058279; cv=none; b=ladVCd+xnN5r8/a+N/TLuWSSPk3e0J3qVlaTkNw7DbsgIIjFFk12UTxOJOX75d39tWrRQVxl9kg+Zuj8ahx8kQscFcDK7vzZwA+x9tVynS0V8TahPQKdd8aHiW7jY1tnZUNk9+PSMMZOyyEvy0F0CZGo8YllLRSI/9c4jd6aeo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724058279; c=relaxed/simple; bh=k0kc+QTAqBx5aRP9ejxkGxkgN/n6bbv6rD4rzOSvbiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J/Quk3K5bs/7myP6Yd8uKRIgD3mAFFFbxPQ81tmZEiwhWKBzPIve+Sr8qlmj00R4imfr60FGXT8tFvrWSHn7h86nOcj7vwmMDQH8Ykh/DC6/g3jTY5sCXWu08QuCyxmPdmtwGRxU0uMH5Tr7qxsdMMU/UVAC2L4O7MD7fY7yM2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PprDPzzL; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PprDPzzL" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4281ca54fd3so32334195e9.2; Mon, 19 Aug 2024 02:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724058276; x=1724663076; 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=zR4Ofv19bSC63uSv19yH+Zec5wT7Br2CN3wzGxETKgc=; b=PprDPzzLxkbTok9EGMHFB3aPhCflcz9gdKT+evFd3teAQWrIOSnsW22VlCjL7Gv3jM Uv3fqo7KkI8namMjVscV9wtlpysF4pJKNaCvEzHL0KsibWZ8DtCGA9cu+0Yr+OvFPGgM YzS3BSeN5mTNea7/sA7jDVLpNqejP/LlGmu6nAXqjO+nHh3hC9bC6OqE+OWbPpYiu2+M ryUoRHqPAVmGOmkWvPxMIfozACbS+Dz+3Jx9hnofIFVMGEO5D401qbAmh4VOqgUcTLaS 1ND++K8xd8QrNUVDSQ7+gYhs56JfFdrQP/Zop+rN+/QA8Pvg/9wtBo6J6pFLJvN9zM+1 XhVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724058276; x=1724663076; 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=zR4Ofv19bSC63uSv19yH+Zec5wT7Br2CN3wzGxETKgc=; b=bSwNxN75mVb7Lfg6vp/cd4Hy74NsIUFtYBXrfGEBRwzgMhFNkou4ys46FFtUYOOoYr os6BTWGlsz3zIw/eIwYLryVr4NBEvhgKC5NB/eMCuJ8GtUo8XqKslwtBAZ7Sdbkjnvuc rj/NPwb/V3dvesAE54jVs28jLcLzvfp09KaMZLpbCOMXaRMhVNRGcse1DmaWoYHw45pT 0NiqTcijnzUX17OuCXCelrmOsOikb3t4S9+kXeGrPPmeBEYykhUilYo9ZbAWSSW5uhiq R4iZH1RrqT8fjYhFA4GouaNzCRfH1R4HeGMR0velNb8MPG0b0pCv1YzemmWQel9XgtrZ Rk7g== X-Forwarded-Encrypted: i=1; AJvYcCWkrp5EwQLzg2C2lReq3EgpaNvnU3sahdOCop5K3hwH8JxvqfSbBywmDWtuDjo/Bhjy/ZWYJdBochjuc4omhU1ZMLyNT0OsGItiwts0 X-Gm-Message-State: AOJu0YywMu1MFelPAclsVyyCNEaDIOCl6VwgMhFaaMLfxPp3pKy4mVJM EbqLpKUuGUwz1VM6ABJC2rKnn6zQ8m3QuWkBUSoW7EIbCkv/HgmL X-Google-Smtp-Source: AGHT+IH7JYzrD4WQ2IczOX6U7P1voHwlgUZmPc1foVjQrG13R7Z0iK1/sLxIgbdwHptG5vYiK5hczA== X-Received: by 2002:a05:600c:4712:b0:426:5fbe:bf75 with SMTP id 5b1f17b1804b1-429ed7d1eccmr71255425e9.23.1724058276061; Mon, 19 Aug 2024 02:04:36 -0700 (PDT) Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:a64c:8731:e4fb:38f1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded19627sm154672095e9.5.2024.08.19.02.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 02:04:35 -0700 (PDT) From: Stefan Eichenberger To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v1 3/3] PCI: imx6: reset link on resume Date: Mon, 19 Aug 2024 11:03:19 +0200 Message-ID: <20240819090428.17349-4-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240819090428.17349-1-eichest@gmail.com> References: <20240819090428.17349-1-eichest@gmail.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefan Eichenberger According to the https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf errata, the i.MX6Q PCIe controller does not support suspend/resume. So suspend and resume was omitted. However, this does not seem to work because it looks like the PCIe link is still expecting a reset. If we do not reset the link, we end up with a frozen system after resume. The last message we see is: ath10k_pci 0000:01:00.0: Unable to change power state from D3hot to D0, device inaccessible Besides resetting the link, we also need to enable msi again, otherwise DMA access will not work and we can still end up with a frozen system. With these changes we can suspend and resume the system properly with a PCIe device attached. This was tested with a Compex WLE900VX miniPCIe Wifi module. Signed-off-by: Stefan Eichenberger --- drivers/pci/controller/dwc/pci-imx6.c | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index f17561791e35a..751243f4c519e 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1213,14 +1213,57 @@ static int imx6_pcie_suspend_noirq(struct device *dev) return 0; } +static int imx6_pcie_reset_link(struct imx6_pcie *imx6_pcie) +{ + int ret; + + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, + IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18); + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1, + IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16); + + /* Reset the PCIe device */ + gpiod_set_value_cansleep(imx6_pcie->reset_gpiod, 1); + + ret = imx6_pcie_enable_ref_clk(imx6_pcie); + if (ret) { + dev_err(imx6_pcie->pci->dev, "unable to enable pcie ref clock\n"); + return ret; + } + + imx6_pcie_deassert_reset_gpio(imx6_pcie); + + /* + * Setup the root complex again and enable msi. Without this PCIe will + * not work in msi mode and drivers will crash if they try to access + * the device memory area + */ + dw_pcie_setup_rc(&imx6_pcie->pci->pp); + if (pci_msi_enabled()) { + u32 val; + u8 offset = dw_pcie_find_capability(imx6_pcie->pci, PCI_CAP_ID_MSI); + + val = dw_pcie_readw_dbi(imx6_pcie->pci, offset + PCI_MSI_FLAGS); + val |= PCI_MSI_FLAGS_ENABLE; + dw_pcie_writew_dbi(imx6_pcie->pci, offset + PCI_MSI_FLAGS, val); + } + + return 0; +} + static int imx6_pcie_resume_noirq(struct device *dev) { int ret; struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); struct dw_pcie_rp *pp = &imx6_pcie->pci->pp; + /* + * Even though the i.MX6Q does not support suspend/resume, we need to + * reset the link after resume or the memory mapped PCIe I/O space will + * be inaccessible. This will cause the system to freeze. + */ if (!(imx6_pcie->drvdata->flags & IMX6_PCIE_FLAG_SUPPORTS_SUSPEND)) - return 0; + return imx6_pcie_reset_link(imx6_pcie); ret = imx6_pcie_host_init(pp); if (ret)