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: 13768098 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 20499C3DA4A for ; Mon, 19 Aug 2024 09:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=m1WZmnJzwRNoGQ6pe2EZwbvZJ2ojrMh6cxbYC/hMf9M=; b=ayEdwWsarqLlxpn/Z/SlQjzsZu U8akxqAx+bS/KW+llO3nRTo3hlYxcGgGZzfgS+pwIRzsSeASMew0W50kbusxJHjcGSCoIUoQFpDN5 19siADX02ZsNMOW2gbWxYvGu4dwQ3CJpyGM1P8NPmDOA0B7BJbXt4mvlz2HIyzn3B42Iqa6psFwGK tyl+Aw2RC4joVWh/eAersjhwWUKCsISyLvzh/P8tScQHM1NX/Be8qHcey5jBd+Ho+ai+2f5jPLdqM AWJTuVPIY9S/bsDIDKeGQYYDwxYG3zfV/wqhUhiSH3Y+X/2lc04mfIDiPrZz0uoJjUhsbppltJPGz ia+QEp/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyKo-00000000sIc-3epD; Mon, 19 Aug 2024 09:05:54 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyJX-00000000rqV-1j6z for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 09:04:36 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-371893dd249so2153359f8f.2 for ; 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=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=m1WZmnJzwRNoGQ6pe2EZwbvZJ2ojrMh6cxbYC/hMf9M=; b=kPqwgzFDOB14HyfhD8m52Tu92oMc2lIinD7BcKlFdh7DwP7c+khqENgSlzfUCOiEnH 1rrjv1VNNBxvFxSj5phrD3XIPlJMKUNmL35sS2hR22kQB62EO3VtqrlGXgperaOaw6+Z 76PT/YwKdS3AMJGFno8i9LrtBOLliWp3bHo+781/rXrnPIYZc12lGL97d2JW66246qNl WpQzMWf1g22DRuiwt5i+jZ+m+LRhF1Ch7Ek1wOQOCOqL80VDFuPvZDiBCH6xW9e40SUU d8KOc//lMBibiBycKceXOhWU8Ec/bBdeQlhG255u0bdrG7G8QX7hVALVq/4xCujrTnlz /q4Q== 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=QoZBZjm+0+bRrGUU+gluzwQEsgVcTCrdo1iXzFN5cKDwXRg2CzhD/G3znBPb60vA90 sAv1L0LtGk5F3HTfuHU0AcCp5axB0r/NbiTPysF0JoPmMHBrRYmpJKsRUxaD0/MbtYKT gzPBFJI+FwHpYETOjyLAxFfBpHkiYna0idXu1RPQP94JzOqpyWqhAZe2c/bGd3bSoZoo ljLmgrbMQ4Y6nr3H2pQ+NNA8iDyn9srCXFCq/Ar4XX0RwgiZi0Qyhv5Aq9GxVUpNPX6S SLHQEb+jZnLBWuw6oAOB8PlZHrA1cUF5NZdR+aTk2xwKgsZhEua2pbFfvuJmpj9qijmQ kE6Q== X-Forwarded-Encrypted: i=1; AJvYcCWcmxzFay3nhAb/paertUV4ysTdogsA85hXSu6lFQI4V+riY05eMFXlGpubFw14eIGXUa8lxfQNS0DkQo9pdF57EJ9osaerGSHa+Zamzj7LWsQYZbY= X-Gm-Message-State: AOJu0YwQ6cehfvianHvzJJxTniBsi1wM+Bz5OydlUEw7mNu0uk4aJ3gl w36hwFlko95rIuY23NTsYqRIqGud9p0XVmxq5rO/xS2lcCjLzQ6h 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_020435_477841_D8864C0E X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13768100 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 AE0CDC5320E for ; Mon, 19 Aug 2024 09:06: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=73KaV9INZpxIDOJ2Xw69bHLb9GRPh7H+PU9DOGB19/g=; b=K7zZn8W4l4RwMu8LukWE5Uptnn tBoM++LcW8QXjd5OuoYARUoUTBlzFOUTwWsFE1roaCBy303XH8/KKgdKcLczK4T/A3/AIrc+GovUj 6sezLRY5cG/ExEE2lwTHO7vlMhoxgq51V9mptgKXFud+i5EQSczw/gKwmebIOSAWRv+CJ8r755AEf wyvxnn7aq6Im4nt2JGzSXEZm5pnsrzQe4SaA9ETSUckDb8q4Hv1jQnz8RO1GFuaMWIGWQpG2moclT Y7oHjpqtH6YRN+kV8eZ9bhx70kIbNT/QvIlPR16WBv3CyaIluMrZ8ToDuuVC0uJU711wibNqFNuHV pkPc83oQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyLS-00000000sTg-2yT2; Mon, 19 Aug 2024 09:06:35 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyJZ-00000000rrH-2RVd for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 09:04:38 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-371941bbfb0so1858756f8f.0 for ; Mon, 19 Aug 2024 02:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724058275; x=1724663075; 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=73KaV9INZpxIDOJ2Xw69bHLb9GRPh7H+PU9DOGB19/g=; b=h/tBho5RjfREO8oR9uOJAvj+yOM9kNwUuaNv/+KrT+2zPD4KAU+jZMYqwBH3U14Mr5 2pzM9QOc08UUohChEc3M0KmAbeh5zzG5ACPC/PIES3A75QT1xHRXBf/YeCbJzhoBe2Vc AcyQiooCVNG4lxneJYUZuc0TXwV6LJM6ESqHIcrdQDn171Sc1tjjIFWT2EQn3/oKOenq eVa2/vpRvvegYTMWtqFZfQ1X15ozTLVBrR/8AKd3vz88GMrwk5im4NC1+GPlS+UcipJQ tM3ygWVbZAAyiqezXIZ8EDPmjPzZLDapodaBh1JYnRSvqfYSgvAa36+OMXuZsu3w+SDB TDWQ== 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=TRLNDrx+KOko2pc//YJWlDe6fdw1qfQiJCVWwcV4YudxboPXgZIrdCnomHSeiFC4LV 0hPw2IJhsuG18Qoo3wt/bkiL/6ed+XwXlKLZPdKeZTnvRY2BQA5RMB3lzUc1szLpaC8P GVV0w+78/uEUKQCevnJeCLxL9OgecP7dtm6hhDEQ2FPYoDZ7NxCD95/VuHkUIAQ3p8TY Hh3/ntDndMvj5Qc0a+HgR04D9sec7Otzdsfp1L6L1PLF7aYl5oNQNH0uX3HSNmY7RS35 D7u6ohFRxPHYM453PG8Di6AWudSY1MTZeWlXqJCEd3CAC1qE+s8k1KkeB/ms3otevrOF 9h3w== X-Forwarded-Encrypted: i=1; AJvYcCWNa/J3MfoBSAPMag/eMbJTJIr4Eri7TatAckHn6E40sd7e7V7+sik4ASyv+6Gk+vQXWZOOvusqw3aN1SykPNn1kuq3vgTWrIVjJtTRHq1neUcmulQ= X-Gm-Message-State: AOJu0YwgQAHq0GOpc1FDeTEfA/i+nZMKFAxRlJYSopATlWzkyL57xtSq 1VRVg+Sfl8LZDWWmQGwalcd3IkBA9L5EAJJWQwWhanVR1uN9oqWG 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_020437_646717_06BC3964 X-CRM114-Status: GOOD ( 13.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13768101 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 8F2D1C3DA4A for ; Mon, 19 Aug 2024 09:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zR4Ofv19bSC63uSv19yH+Zec5wT7Br2CN3wzGxETKgc=; b=clOEtqZIXOdDWTbqGtKxYekzWt pOlJbpjYR+OUiDU/IsQcnEne/k2PTapSSTiNPOJrxj/dMyIHRdQ/cp7CgnIT/k1cJwrr9W1SUUkud x00DgiJQwvZe6SKUO32r4VnJFDAoi/RYmpPyxXJRf5JkMe+9aYEG6WF1G2vyyztZmHBdIbk00NrPI 7sxAKncwPGOQl2uybdsFaMIY62EbES6cv7pWrci8UfTTaVXQlGeAaU2Wz/hc1nkztp2nFeoBShWWA luUQxZ7v/VwS4FnB5Ps9uObIFyFcquRpMqo5zim2LjUu9rEX5n97YjXHT5ko+rcP9cLqRnqk7Ynlk xk5Fx77Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyM5-00000000sfs-2ai7; Mon, 19 Aug 2024 09:07:13 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfyJa-00000000rrr-0Rar for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 09:04:40 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42808071810so32384865e9.1 for ; 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=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=zR4Ofv19bSC63uSv19yH+Zec5wT7Br2CN3wzGxETKgc=; b=I9pslXJrDrl96cOkCIzyc1MKvxU2X2qfDZTENp5Wji1+WhcBmtJSQtQysJ08iKsE6Y /sb89WoCNottf7q1iA2i3pxYDzRnMCDa/6VQG8suFAAJg7oY2K7QMNCjUxo4IcQafkkQ XHp7Yx6sPJ7c2sxCygqdR7u31RjFBj0HHPUtNtj1BxpuVS/gkkCOm0trgKhHGwetVCMA lNk6M18cZUmnzTrVkScXxzp3iZ4Ou5ivGU6FOLWrMsU7BL7+3geMcZOW/GgWNu5lswHf 1m2xBCMpRL/0nPJKOwIyY1uSjwm7CoW+runc1Rd7rGkdQrYi+nRSD4PGSngKJGwkHhA7 fB9w== 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=SjZlSJnlkpVjtIZvjQS7DE8q6EJa2op9w0W8cMLJz75yZxc2T2A/ULjAtx8MY6g2+k PLUXsfee6FfJdTk44HiqqvqY0f4uOyiglZn0Jj6wDo0fFZk3MPb1ny9oAfl+edttRCBb z2LGzDW3rxlKS3M+eh7nCLuauFxB8x87MasYgcGEtGV7amzcBnZDv1MqfFr79ECM00gI ihtvRqr815an6Q6jRTATuUbg3ule9zLIQ873ih1f3OoYXEsz+PGyQByXpyAGckIuAuQN dNDG/S255nJpCUb1VPyu15AfN/nBc3FjeUzbWxB8t77fxS6GxEeimSRwFcGHNU7+KSB0 JUsw== X-Forwarded-Encrypted: i=1; AJvYcCU1X1j73YA3YR3ruG7K8Ne5BnEkTXT3QdNuXQik3joBUus+0gEjtplsO3r9TKSGEfPTKmtVBEMIUXufUBYK140XivHbGARwSu3u/F4fxVrEJa1Y2lk= X-Gm-Message-State: AOJu0Yy/msNNZYBf0YcoYarudlblE/sd3dzCmiKaypulYS/oiSjzbrli eJZ6ZRSdmRRS+bqDKz5s85KflYT5BikffqsuY3cTgGs2LkRu9fD/ 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_020438_224051_5F87B2EA X-CRM114-Status: GOOD ( 22.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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)