Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6806065pxv; Fri, 30 Jul 2021 02:52:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4F5TjPuaUlcESTd4+YNfUfyvbZvMSZ1CFW8jye8MAnCF0B8BFGCIFQlDEd8UqD+K4dVh2 X-Received: by 2002:a6b:b24e:: with SMTP id b75mr1843110iof.94.1627638738304; Fri, 30 Jul 2021 02:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627638738; cv=none; d=google.com; s=arc-20160816; b=Deu1dvgQGPBqBDaCgOeh0KjIxSHwdvZcBRb98HSOWJkYiRzWwocJXCHK0LIEW/Vadd pRdxs7qzqzW4+fL47hTtKJH9CVXwEPu5Lo1U/5b+PSveZN8nx6jtyxhb6gDbdiKHeXde HYvhKnHc1BiQtkQNvqxb4j8RS4R9klHrTQQRfRYzhe1GEvH0I5eG1aLzEFjIKIHyAh+a ehjNCxk6cTTJQVqWxkPCrfOiKwMZhN2xnzOpmE8uQz0XH0anYhDbVk4WGOTpBYH0E3Fw 2g2z0mXdoTWJQSM//XMLgCPm7JVn6CqEtBnRzA6+vzpVN9gEOIe+UXyzTuV0A0RnFekv v5Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SDA12TI3qRffWpsUje4Wzgz3yRMoIxS3gGPVgoxVGyI=; b=n4e0bAyJIqkPTk5VfqRC+BAQns5xg6ZN1gZ2+51J3BJJlCCk4kuL1pAzxQ1nefRxIR 6LJOlaVa3rndX0Ju2I8M050U2Cc+1zl2X0ys3fSgbncc2q+pka6rI4zTbYG3D12VJvLR Jjso6IXSD+R0Zs62SFH7MPJJLQBhluT/tBGspnm2EPlJscJ5VvKHvRAgNtnmBkWD2pp9 q3stJ6IA+ziaWd/yx4PXgE/iv55TPHQf9shKmj6226Xdc/F31GE0ED9eUXob9v0mH8GL jBacTL6PkwDQ59jiw454Y5/wCXD7IXVrtewlFnrpEexbr+7sN1PwowwVuawVSdn0KtMe QuEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CXCYNp/1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si1444998ilm.77.2021.07.30.02.52.07; Fri, 30 Jul 2021 02:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CXCYNp/1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238477AbhG3Juw (ORCPT + 99 others); Fri, 30 Jul 2021 05:50:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:59654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238294AbhG3Juc (ORCPT ); Fri, 30 Jul 2021 05:50:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5BED161077; Fri, 30 Jul 2021 09:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627638627; bh=ukoqfl26CBpwVmmOL/beytBaSmonlOp5+JYrCjwnr8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CXCYNp/1RKhqOwir2CSkGYmc1UA2AIdMV3a0/cRNZ8PnEoCE7JeMqZOtBvo4hYr88 Xh4SdaQgXolCsvgM3Ey/91CL5JMiiIn2UjjP0jgcdi3ILCzd3tsFHHkNW4QpuzkvxZ 5ekP8utrwzIvkxDKBYkgf53diREomSE44b6oFuhD/5HV9z1nMamVY7JCZEV5xrtMss ksjo9Q3TITTk3a/w7M8ikcQcZq/V9KjYQ/HqcyB3v56jM6C/QO3ZGBZviSeuRhY8kX Bn7GnJTSmPvmJdH9J/VUnP2G5Cc8NzqUvvpVZsJT0m8Rq1uwqjxNQc+OmvZ5DvTaq7 PhY9ijsmjniwA== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1m9P9t-006s4U-Jf; Fri, 30 Jul 2021 11:50:25 +0200 From: Mauro Carvalho Chehab To: Vinod Koul , Bjorn Helgaas , Rob Herring Cc: Mauro Carvalho Chehab , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Binghui Wang , Lorenzo Pieralisi , Xiaowei Song , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v8 10/11] PCI: kirin: fix poweroff sequence Date: Fri, 30 Jul 2021 11:50:13 +0200 Message-Id: <00de31f5b43974cfa870a0eed67f7ae821475bc9.1627637745.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver currently doesn't call dw_pcie_host_deinit() at the .remove() callback. This can cause an OOPS if the driver is unbound. While here, add a poweroff function, in order to abstract between the internal and external PHY logic. Signed-off-by: Mauro Carvalho Chehab --- drivers/pci/controller/dwc/pcie-kirin.c | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index 58a993a998f3..bdf45d29cdc3 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -683,6 +683,23 @@ static const struct dw_pcie_host_ops kirin_pcie_host_ops = { .host_init = kirin_pcie_host_init, }; +static int kirin_pcie_power_off(struct kirin_pcie *kirin_pcie) +{ + int i; + + if (kirin_pcie->type == PCIE_KIRIN_INTERNAL_PHY) + return hi3660_pcie_phy_power_off(kirin_pcie); + + for (i = 0; i < kirin_pcie->n_gpio_clkreq; i++) { + gpio_direction_output(kirin_pcie->gpio_id_clkreq[i], 1); + } + + phy_power_off(kirin_pcie->phy); + phy_exit(kirin_pcie->phy); + + return 0; +} + static int kirin_pcie_power_on(struct platform_device *pdev, struct kirin_pcie *kirin_pcie) { @@ -728,12 +745,7 @@ static int kirin_pcie_power_on(struct platform_device *pdev, return 0; err: - if (kirin_pcie->type == PCIE_KIRIN_INTERNAL_PHY) { - hi3660_pcie_phy_power_off(kirin_pcie); - } else { - phy_power_off(kirin_pcie->phy); - phy_exit(kirin_pcie->phy); - } + kirin_pcie_power_off(kirin_pcie); return ret; } @@ -742,11 +754,9 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev) { struct kirin_pcie *kirin_pcie = platform_get_drvdata(pdev); - if (kirin_pcie->type == PCIE_KIRIN_INTERNAL_PHY) - return hi3660_pcie_phy_power_off(kirin_pcie); + dw_pcie_host_deinit(&kirin_pcie->pci->pp); - phy_power_off(kirin_pcie->phy); - phy_exit(kirin_pcie->phy); + kirin_pcie_power_off(kirin_pcie); return 0; } -- 2.31.1