Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp206331pxt; Wed, 4 Aug 2021 09:06:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE3nd4OoWqYfPK3wynDtK7HBBircv8mHs0vnqTdUYY+QvJiP07P2DOViAhyumJKgyJ5paP X-Received: by 2002:aa7:cd4c:: with SMTP id v12mr534441edw.155.1628093185091; Wed, 04 Aug 2021 09:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628093185; cv=none; d=google.com; s=arc-20160816; b=IHmA9SwCZJRcsKgdKid0OJFMNF4i1CfDT8GDIaPmhyszHfs6pCiYfLnJXJZJEZGBrF EzSBxob7FPFfAwzeU8m98UxiflJ9cplDQgYiyTVpnmreSsA6B40q36NWm4YuykaAb9os iqDaBJ6YuCpQVidoSDAJcJP4GaJAJI7yCHiUgv5a9BTn+TyZW96a0Ycdn7cUeHpTLjwo rRON9rJxQypKm3UknT166u9c5pq/CjwyC0x7PYZ9ivM7Mdvsw9PmiYGXajaxU0/hDYCM a7Zz3zCPcb1hSgeHFODFUQ/z1XH5KWb75zY+FETNS81pQU5pHRQ3tfiPnsjbJL/kWu5w qMbQ== 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=qPbFgZI4B8UE1b8CGxlloIoYu/BbMXqHJcow7YiKCtc=; b=jlrYGTDuPs7RJZ4SN+TE/51+dGDDsHRYHg446rW7UEteTcME1hYDCloBTjcfZrP8IG HSTKiO+Ch3WObUKO4QOKkaEZZ9iGnGWa0gw3THZeKKM4F06aHxB1oSU7Q8Grc5MdnC4g CQl8x1UmIk8gba/1dAynSyJxoF0z2igI5msiEqNZGtgUBeieILtuE/b5qcLIK0YhrVpS xODxIzhn6TBN6dszFWOdMfTt8SZMLA/yfA+Ix/xVKlj6Ay95q2EFa7001gMZMXyxvPQ5 c4DNtyCOupTMDzaWE1qcrlV31+bNtbDNpngFw45qvdBCVsYi56V5yTX+mB2p1Gm9Iqzw XmcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I0xnPWFH; 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 e22si2510640edq.549.2021.08.04.09.05.56; Wed, 04 Aug 2021 09:06:25 -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=I0xnPWFH; 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 S230085AbhHDQDw (ORCPT + 99 others); Wed, 4 Aug 2021 12:03:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:58932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbhHDQDX (ORCPT ); Wed, 4 Aug 2021 12:03:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8B343610FD; Wed, 4 Aug 2021 16:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628092990; bh=UYZhcF8SdCV22LVBIEl5MSwPHs1EOM8F4GeLieaMtJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0xnPWFHD1M/eiVF9Gd/mCtDzFyz2Kmi57uKNc5BeEgoaedbeOX2m23tEFE+V1Pq3 gBDxw+TDxOvUQu7lk3zZO/6dI/wrqeI70gJdbBvdvoNHt+XCsN/n7pA8JIJAf/3oF+ hJNIIdgPfHon4E/JCJ7TF6J+79NWcL907YUUFcvGmSuLF2IOhc/JoI0ZNYYLEzznuX Zl5O13AGALhn1OCW2XyVlk3gxhplo3mzIkhP2YDYh1Byzmr6gciEhfdEvzLCTKRayA +UTIkKl2s+9Ub7O5QtfpFVg/pR/h+rYsHhPe7R5u/RaOo23/1863owYn7bR0oJ5/aq JqAsHPcilaUaQ== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mBJMK-000Pzw-Q3; Wed, 04 Aug 2021 18:03:08 +0200 From: Mauro Carvalho Chehab To: Vinod Koul , Bjorn Helgaas Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , "Rob Herring" , Binghui Wang , Lorenzo Pieralisi , Xiaowei Song , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v9 10/11] PCI: kirin: fix poweroff sequence Date: Wed, 4 Aug 2021 18:03:06 +0200 Message-Id: <2703565f2227d161bc568e63cebf706e0c3be10c.1628092716.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 b7cc0c6701e4..81fcd46d1346 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -682,6 +682,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) { @@ -727,12 +744,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; } @@ -741,11 +753,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