Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp148234pxb; Mon, 18 Oct 2021 23:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaSkIYfCdwGAIt7/mMFarnzucLk6Tu7CenYvIWce3k6HdAJ2TBJ9/6+q4Lw7tlQh2AmQdY X-Received: by 2002:a05:6402:1c85:: with SMTP id cy5mr51916644edb.281.1634623779212; Mon, 18 Oct 2021 23:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634623779; cv=none; d=google.com; s=arc-20160816; b=zXrKAfxZyEvBN4AK8qU8k+IyO0Ydn3Ph5eoyuqBAjqjAWgdLfkAxLjG7i1RjXSmPcD sH217i52qoTJsu9VZe0epDDn7nRMc8FZ6vvoDOl6erEOhyBoaVT0rluWMDy60S1j1HVZ bUksshaIBACdCH6XZdn0umQymx8hVq8yfGLsBCaDq6JxjIf+vQfRjfLNnuptqpUVeNk/ WWH2FXpNTay3VQM9sbmzfhY8rfoUZmuvGIQAUtTbTjSFDN4d66cZYtoHeSNDoDz/8/Qk 1v8E+djCIPw8Ll9MuoOaM3slzsYWbrzHOnT9ILGirsGoA4ON5+qevs+6ozoaay3Inzrh Xxkw== 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=WdwwZ1v2WwU94RPhRnBoT8Z44Fd0GzL2pOTn7/rrgZk=; b=0Uwp+4jXct9GCO3MzfaWyOxsBcYKp08+xphhTzhQ8tyR3qoBAos1Ug4Apkl+qCnaSJ 1yAXAwbDRZoHhOnsP6wkL76BeB+SrFMu4AXUeP0/dtSq1ysiw8bZpPzJgcEt4O6BDTrT d9v1B4mQ6bdyxQNLxrz2iSR8NC8N69pK1JEDmQ+4O7rtJpVRsEMSU6cz0kHeOzh4OOe0 N47C8cFiIN9DNpjGwrdWfdFCJ123nX5znLXBnvdZc8b54qL8Zl3UNyqi5hpgcTyswbXf vCbT2aAWLpNy77fMrxK2b+TeyljZYU+f6S2T/F2Ys2k0CR5yG6UEFV2aEkqmc0iQBMrk zYuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K8rOsbDs; 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 c73si22076867edf.471.2021.10.18.23.09.06; Mon, 18 Oct 2021 23:09:39 -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=K8rOsbDs; 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 S234026AbhJSGJI (ORCPT + 99 others); Tue, 19 Oct 2021 02:09:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:46012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbhJSGJG (ORCPT ); Tue, 19 Oct 2021 02:09:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 68662611EF; Tue, 19 Oct 2021 06:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634623614; bh=KC6xpqw4gz13ScCLb4JuvbL08ma1IvkEmrgUMn1KrAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8rOsbDs/8uMM/WDiVZyleTQrqgFOtLNxR1ITiJGYEJpz+RsFyOAr0rhHA98B9Ie7 o/7gqGZbWOevgxPh7GhgrsX7abF6HTDptP3XGoDBEKZWtK0g9WVGvOZT7bQsg31WKQ SVpEm2dPidK8Lp2nGMKugGCf1zmx2fBfOFiSABb3rERv2MwjVPSqIiohmLhCU/hgoe r85/0EH34cycNtSAizOaPOwvfIxcsgvd5H+O84EWfzvecLHcsEDAYMpszaghMv8n+M VRDT7n9lTtghE+RRsHvsvQgRHdlGprvRr78XpPLotGFjtdj32r+aha9xNQcHPTjhQI tNU8x5SdhYWQQ== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mciGx-001krb-PN; Tue, 19 Oct 2021 07:06:51 +0100 From: Mauro Carvalho Chehab To: Lorenzo Pieralisi Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , "Songxiaowei" , Binghui Wang , Bjorn Helgaas , Rob Herring , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kishon Vijay Abraham I Subject: [PATCH v14 02/11] PCI: kirin: Add support for a PHY layer Date: Tue, 19 Oct 2021 07:06:39 +0100 Message-Id: <9addf6f6ece282aa3a6ff862976cc167175474cf.1634622716.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. Cc: Kishon Vijay Abraham I Acked-by: Xiaowei Song Signed-off-by: Mauro Carvalho Chehab --- See [PATCH v14 00/11] at: https://lore.kernel.org/all/cover.1634622716.git.mchehab+huawei@kernel.org/ 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..91a7c096bf8f 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 = (long)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