Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6805577pxv; Fri, 30 Jul 2021 02:51:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2fz4VjdLHqbgPftXCEDzCAfhO5eFrGBOxXwbafUAGOOw/tgjALqK1imkpRAeaoeYDaWMC X-Received: by 2002:a6b:b2d7:: with SMTP id b206mr1819282iof.155.1627638689181; Fri, 30 Jul 2021 02:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627638689; cv=none; d=google.com; s=arc-20160816; b=vx7loiGgK6lnPZCDhjDQYstAiLK3BrUsJBBGkBbqr2ZYL0J4eBEtH9FolW9ijHXrXJ 6scVxSztwKshnF8JR7WvGYeV4VXa9iUzQ/3G2vWTMJAb59Fnq+WzRVS/OjpR8u/xZ64y L8fJHvV4OwqOAio1Zufl45m6A314AXaVHgjFRGDQErIyr79os+tjOHzomBcwacxoVNX7 c59iu/I21yUeFT2quU1MlOHds2o5jX2k1W3Y0xIarFePRFyhtULP0l/4fc4jFriZU6/s qX/t7+ZXkEt9dPz4lPRYza5xQVUzcxmhw9sN4t+0BSsr8PMOnlFjoz+bIdfc4yXa+VUj xjWw== 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=OqqJMp1RTaBXFeoRIJhZkUzthDA1Pn8Z89lB+uutQdo=; b=Vikgo7/o5MuAylo1h8P1r5K0MtaxtXtWJY6L/x1YBayqJKKXXGcm5RN5lwmSUwi9Fn piHMry3KHsaR94p0cSsnk0lfJy2G9UcxwSDMdzMvq4EEzBhGpE+TKsnXNta0zroV1off LrCMXyhyAsGT2UeS8Kr7h2ojdN16xNzDJcxy8HJtyQWqsyUKjJxu4IhbB8xd674ofG+O 0AaJAaWs1h7o8/5qgD0O4HS2pY/6qjJEQd2eMmboFcl4PnM0YcsO2pLWPhxuZoIvKbll bo7MBBuE20Ye4HuTj1fy9pU88mYy0N8p5bNua9bvwMn8KGedT2do8ZH07vjIlj9JH7m0 vbsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OF0Eq2JF; 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 g2si1515583jat.88.2021.07.30.02.51.17; Fri, 30 Jul 2021 02:51:29 -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=OF0Eq2JF; 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 S238317AbhG3Juc (ORCPT + 99 others); Fri, 30 Jul 2021 05:50:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:59572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbhG3Jub (ORCPT ); Fri, 30 Jul 2021 05:50:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14BA060F12; 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=LKKm93bvLtmQwufCM71y/2Zcq2n0/ZxkrnwxYZPX1WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OF0Eq2JFnFYfdsJMpeRJTkhboAw1IUj0XWqusfii11/ZYkszy7RsAoMy+zDISUmYo hvDhEoHma2V5usLyfwMyqU1ARhILikjTtOUIKOyZp8SqN3hTEDAmbnUCIFlWqnAFsi VFeTthj5+91wc3Mp1DGljlyB6DS2YH7NUsmb6Ce3pfcLZ5CKibm4i8pt1uFhPKgbo7 xTf4cXj7PpqV3Hu6+en1f4sPd388uIPpiiBMFw7BB8NicnbbiVMybNV0Qunk0eWS1c NK7XTgVX2IHr+mfH6/LOJ3AoBpmIgL4gqJ85mZeiLTXbL2PNfG1P3SS+UN1vkRMFUS omH9Uv7RWMBQg== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1m9P9t-006s42-7f; 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 03/11] PCI: kirin: Add support for a PHY layer Date: Fri, 30 Jul 2021 11:50:06 +0200 Message-Id: <420dc0182a3f682109da3dad45720367d1451232.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 The pcie-kirin driver contains both PHY and generic PCI driver on it. The best would be, instead, to support a PCI PHY driver, making the driver more generic. However, it is too late to remove the Kirin 960 PHY, as a change like that would make the DT schema incompatible with past versions. So, add support for an external PHY driver without removing the existing Kirin 960 PHY from it. Signed-off-by: Mauro Carvalho Chehab --- drivers/pci/controller/dwc/pcie-kirin.c | 95 +++++++++++++++++++++---- 1 file changed, 80 insertions(+), 15 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index b4063a3434df..31514a5d4bb4 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -8,16 +8,18 @@ * Author: Xiaowei Song */ -#include #include +#include #include #include #include #include #include #include +#include #include #include +#include #include #include #include @@ -50,11 +52,18 @@ #define PCIE_DEBOUNCE_PARAM 0xF0F400 #define PCIE_OE_BYPASS (0x3 << 28) +enum pcie_kirin_phy_type { + PCIE_KIRIN_INTERNAL_PHY, + PCIE_KIRIN_EXTERNAL_PHY +}; + struct kirin_pcie { + enum pcie_kirin_phy_type type; + struct dw_pcie *pci; struct phy *phy; void __iomem *apb_base; - void *phy_priv; /* Needed for Kirin 960 PHY */ + void *phy_priv; /* only for PCIE_KIRIN_INTERNAL_PHY */ }; /* @@ -476,8 +485,63 @@ static const struct dw_pcie_host_ops kirin_pcie_host_ops = { .host_init = kirin_pcie_host_init, }; +static int kirin_pcie_power_on(struct platform_device *pdev, + struct kirin_pcie *kirin_pcie) +{ + struct device *dev = &pdev->dev; + int ret; + + if (kirin_pcie->type == PCIE_KIRIN_INTERNAL_PHY) { + ret = hi3660_pcie_phy_init(pdev, kirin_pcie); + if (ret) + return ret; + + return hi3660_pcie_phy_power_on(kirin_pcie); + } + + kirin_pcie->phy = devm_of_phy_get(dev, dev->of_node, NULL); + if (IS_ERR(kirin_pcie->phy)) + return PTR_ERR(kirin_pcie->phy); + + ret = phy_init(kirin_pcie->phy); + if (ret) + goto err; + + ret = phy_power_on(kirin_pcie->phy); + if (ret) + goto err; + + return 0; +err: + phy_exit(kirin_pcie->phy); + return ret; +} + +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 0; + + phy_power_off(kirin_pcie->phy); + phy_exit(kirin_pcie->phy); + + return 0; +} + +static const struct of_device_id kirin_pcie_match[] = { + { + .compatible = "hisilicon,kirin960-pcie", + .data = (void *)PCIE_KIRIN_INTERNAL_PHY + }, + {}, +}; + static int kirin_pcie_probe(struct platform_device *pdev) { + enum pcie_kirin_phy_type phy_type; + const struct of_device_id *of_id; struct device *dev = &pdev->dev; struct kirin_pcie *kirin_pcie; struct dw_pcie *pci; @@ -488,6 +552,14 @@ static int kirin_pcie_probe(struct platform_device *pdev) return -EINVAL; } + of_id = of_match_device(kirin_pcie_match, dev); + if (!of_id) { + dev_err(dev, "OF data missing\n"); + return -EINVAL; + } + + phy_type = (enum pcie_kirin_phy_type)of_id->data; + kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL); if (!kirin_pcie) return -ENOMEM; @@ -500,31 +572,24 @@ static int kirin_pcie_probe(struct platform_device *pdev) pci->ops = &kirin_dw_pcie_ops; pci->pp.ops = &kirin_pcie_host_ops; kirin_pcie->pci = pci; - - ret = hi3660_pcie_phy_init(pdev, kirin_pcie); - if (ret) - return ret; + kirin_pcie->type = phy_type; ret = kirin_pcie_get_resource(kirin_pcie, pdev); if (ret) return ret; - ret = hi3660_pcie_phy_power_on(kirin_pcie); - if (ret) - return ret; - platform_set_drvdata(pdev, kirin_pcie); + ret = kirin_pcie_power_on(pdev, kirin_pcie); + if (ret) + return ret; + return dw_pcie_host_init(&pci->pp); } -static const struct of_device_id kirin_pcie_match[] = { - { .compatible = "hisilicon,kirin960-pcie" }, - {}, -}; - static struct platform_driver kirin_pcie_driver = { .probe = kirin_pcie_probe, + .remove = __exit_p(kirin_pcie_remove), .driver = { .name = "kirin-pcie", .of_match_table = kirin_pcie_match, -- 2.31.1