Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4990653pxv; Tue, 20 Jul 2021 16:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu1pZoO4Qnnk1dJc3JnDEpXS3K9yyL/Md+IAMO7Jtrx2pYWG72T3gv0uQiAIQs7X7l5QG8 X-Received: by 2002:a05:6638:24c3:: with SMTP id y3mr28402948jat.10.1626823740706; Tue, 20 Jul 2021 16:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626823740; cv=none; d=google.com; s=arc-20160816; b=rJUi1XL/92QgZ4c8jdNBrBKgE3a+HDA3rpWICDPD8RNMfK/sZAyAIbj9V70cuYoU7z kwI0zptXDtVWIdpwnYZJwVN7HuUDa54+0padi7/+ML7HuZD8qb3hYFtH8to46buDbdhB cGylZ5rDNC+GEtDvTEGX7ABMwPFOUI5psk+oM1IAK1xfh18eKCCbFfatMBxKkTvnUUvq ItBTBYVCuWTito8+ihwj4ZTqjnMVDs+IMS9yI2MjbE8/P9dDvl1prpZCXcwpFRUijOZ0 P7u7ZcGxbWA9lqtcGBE7qWtAqyekfAeELK3JKEw+o0TX0xUusHs4falZOuewumYrW6QN duzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=XtT4nVdJgc+rOwaVo2Ic42AIdHXn3V2MFFgYZivQGV4=; b=yhum3Y/adH+0RF8NL6zLceQlPmv6HGWXg81gBHmc8cTUY6YEk3bseb0tnCAGCAf3Fv ytMKAfeEvCDdEdqji0VbDYNFnxfnuxV5CHSxCYB0lqw655wkU+4RZ1UixLKinSlLESvQ hg+RO6aFMUUJpCrGuxQjUT10uUOCmytgbCumVEo8PHaJwxXkrvEBIGagXMAvhzcEELv6 CK1egpIj96xJAd0ziXBTsshVqNmNaxdpN5M6ISenPPnCpmtb3mCmKEBNt5Zori8Xn741 kwELM4DjgaWyJyUtW0ldlS0aNFxnxTQ4t7X5gRc4MZq6S08xKs2QoFO4KfVP7XW97VB4 CcHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U6qCzEKS; 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 j23si13691365iok.60.2021.07.20.16.28.49; Tue, 20 Jul 2021 16:29:00 -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=U6qCzEKS; 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 S235345AbhGTWqY (ORCPT + 99 others); Tue, 20 Jul 2021 18:46:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:51058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234499AbhGTWqD (ORCPT ); Tue, 20 Jul 2021 18:46:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3338E610D2; Tue, 20 Jul 2021 23:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626823600; bh=/8zNYfsDamCGJhQ1wohZAhFPeMbTvfp5/6fWraoi0qU=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=U6qCzEKSTOjdHTiHe+WshSbfpyr/BZAD0T1G6dIy+oLAR2kMtYinpSuzpbFaaffEH PyUJ8bwC0qkQxNbjJGDQ2KQmwjYTjo8jwuHMrnODiCB5vZS7xO2G5fxj22Tbg/D/fv EJrVKqD75NcUDsZyBD9OgKophdSBfn0FTjEKby2b9Aadi1FMF/cFR9anz45KgMjLBr tjJBSCBcvR3WoC/kDSs1Nuzwy3eykpu9lI8XNvvJmEkh50sckamsH+K5cncLBm+TpO eAL/B0VHlfwH2fESXKOUOuUEdVNGK3uE/l/CKhTnocR8XBHNMz9TUKXsnTJPThWr/Z SG/OFSWdnTdYA== Date: Tue, 20 Jul 2021 18:26:38 -0500 From: Bjorn Helgaas To: Mauro Carvalho Chehab Cc: Rob Herring , linuxarm@huawei.com, mauro.chehab@huawei.com, Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Binghui Wang , Bjorn Helgaas , Lorenzo Pieralisi , Xiaowei Song , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH v6 2/9] PCI: kirin: add support for a PHY layer Message-ID: <20210720232638.GA140319@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4f0580412968c2b2807251e36ba32da9aa092605.1626768323.git.mchehab+huawei@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In subject: PCI: kirin: Add support for a PHY later (s/add/Add/) On Tue, Jul 20, 2021 at 10:09:04AM +0200, Mauro Carvalho Chehab wrote: > While it is too late to remove the Kirin 960 PHY, the driver > should be able to support different PHYs used by other devices. Commit log doesn't actually say what this patch does. > 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..558188476372 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 const struct of_device_id kirin_pcie_match[] = { > + { > + .compatible = "hisilicon,kirin960-pcie", > + .data = (void *)PCIE_KIRIN_INTERNAL_PHY > + }, > + {}, > +}; Is there a benefit to moving kirin_pcie_match[] up here? Seemed nice to have it close to its use in kirin_pcie_driver, and would make the diff easier to read. But if it helps to move it, no big deal. > +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 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 >