From: Bjorn Helgaas <helgaas@kernel.org>
To: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: "Rob Herring" <robh@kernel.org>,
linuxarm@huawei.com, mauro.chehab@huawei.com,
"Krzysztof Wilczyński" <kw@linux.com>,
"Binghui Wang" <wangbinghui@hisilicon.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Xiaowei Song" <songxiaowei@hisilicon.com>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v6 2/9] PCI: kirin: add support for a PHY layer
Date: Tue, 20 Jul 2021 18:26:38 -0500 [thread overview]
Message-ID: <20210720232638.GA140319@bjorn-Precision-5520> (raw)
In-Reply-To: <4f0580412968c2b2807251e36ba32da9aa092605.1626768323.git.mchehab+huawei@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 <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..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 <songxiaowei@huawei.com>
> */
>
> -#include <linux/compiler.h>
> #include <linux/clk.h>
> +#include <linux/compiler.h>
> #include <linux/delay.h>
> #include <linux/err.h>
> #include <linux/gpio.h>
> #include <linux/interrupt.h>
> #include <linux/mfd/syscon.h>
> #include <linux/of_address.h>
> +#include <linux/of_device.h>
> #include <linux/of_gpio.h>
> #include <linux/of_pci.h>
> +#include <linux/phy/phy.h>
> #include <linux/pci.h>
> #include <linux/pci_regs.h>
> #include <linux/platform_device.h>
> @@ -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
>
next prev parent reply other threads:[~2021-07-20 23:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 8:09 [PATCH v6 0/9] Add support for Hikey 970 PCIe Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 1/9] PCI: kirin: Reorganize the PHY logic inside the driver Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 2/9] PCI: kirin: add support for a PHY layer Mauro Carvalho Chehab
2021-07-20 23:26 ` Bjorn Helgaas [this message]
2021-07-20 8:09 ` [PATCH v6 3/9] PCI: kirin: Use regmap for APB registers Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 4/9] dt-bindings: PCI: kirin: Fix compatible string Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 5/9] dt-bindings: phy: Add bindings for HiKey 970 PCIe PHY Mauro Carvalho Chehab
2021-07-20 13:11 ` Rob Herring
2021-07-20 8:09 ` [PATCH v6 6/9] phy: HiSilicon: Add driver for Kirin " Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 7/9] arm64: dts: HiSilicon: Add support for HiKey 970 PCIe controller hardware Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 8/9] dt-bindings: PCI: kirin-pcie.txt: Convert it to yaml Mauro Carvalho Chehab
2021-07-20 8:09 ` [PATCH v6 9/9] phy-hi3670-pcie: move reset-gpios to the PCIe DT schema Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210720232638.GA140319@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=lorenzo.pieralisi@arm.com \
--cc=mauro.chehab@huawei.com \
--cc=mchehab+huawei@kernel.org \
--cc=robh@kernel.org \
--cc=songxiaowei@hisilicon.com \
--cc=wangbinghui@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).