From: Kishon Vijay Abraham I <kishon@ti.com> To: Jaehoon Chung <jh80.chung@samsung.com>, <linux-pci@vger.kernel.org> Cc: <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-samsung-soc@vger.kernel.org>, <bhelgaas@google.com>, <robh+dt@kernel.org>, <mark.rutland@arm.com>, <kgene@kernel.org>, <krzk@kernel.org>, <jingoohan1@gmail.com>, <vivek.gautam@codeaurora.org>, <pankaj.dubey@samsung.com>, <alim.akhtar@samsung.com>, <cpgs@samsung.com> Subject: Re: [PATCH V2 2/5] phy: phy-exynos-pcie: Add support for Exynos PCIe phy Date: Mon, 16 Jan 2017 14:07:07 +0530 [thread overview] Message-ID: <587C8633.5000100@ti.com> (raw) In-Reply-To: <20170104123435.30740-3-jh80.chung@samsung.com> Hi, On Wednesday 04 January 2017 06:04 PM, Jaehoon Chung wrote: > This patch supports to use Generic Phy framework for Exynos PCIe phy. > When Exynos that supported the pcie want to use the PCIe, > it needs to control the phy resgister. > But it should be more complex to control in their own PCIe device drivers. > > Currently, there is an exynos5440 case to support the pcie. > So this driver is based on Exynos5440 PCIe. > In future, will support the Other exynos SoCs likes exynos5433, exynos7. please re-write the commit message. > > Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com> > --- > Changelog on V2: > - Not include the codes relevant to pci-exynos. > - Remove the getting child node. > > drivers/phy/Kconfig | 9 ++ > drivers/phy/Makefile | 1 + > drivers/phy/phy-exynos-pcie.c | 280 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 290 insertions(+) > create mode 100644 drivers/phy/phy-exynos-pcie.c > > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig > index e8eb7f2..2dddef4 100644 > --- a/drivers/phy/Kconfig > +++ b/drivers/phy/Kconfig > @@ -331,6 +331,15 @@ config PHY_EXYNOS5_USBDRD > This driver provides PHY interface for USB 3.0 DRD controller > present on Exynos5 SoC series. > > +config PHY_EXYNOS_PCIE > + bool "Exynos PCIe PHY driver" > + depends on ARCH_EXYNOS && OF include COMPILE_TEST > + depends on PCI_EXYNOS PCI_EXYNOS should depend on PHY_EXYNOS_PCIE if at all required. Or else do away with this dependency. > + select GENERIC_PHY > + help > + Enable PCIe PHY support for Exynos SoC series. > + This driver provides PHY interface for Exynos PCIe controller. > + > config PHY_PISTACHIO_USB > tristate "IMG Pistachio USB2.0 PHY driver" > depends on MACH_PISTACHIO > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile > index 65eb2f4..081aeb4 100644 > --- a/drivers/phy/Makefile > +++ b/drivers/phy/Makefile > @@ -37,6 +37,7 @@ phy-exynos-usb2-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o > phy-exynos-usb2-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o > phy-exynos-usb2-$(CONFIG_PHY_S5PV210_USB2) += phy-s5pv210-usb2.o > obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o > +obj-$(CONFIG_PHY_EXYNOS_PCIE) += phy-exynos-pcie.o > obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o > obj-$(CONFIG_PHY_ROCKCHIP_USB) += phy-rockchip-usb.o > obj-$(CONFIG_PHY_ROCKCHIP_INNO_USB2) += phy-rockchip-inno-usb2.o > diff --git a/drivers/phy/phy-exynos-pcie.c b/drivers/phy/phy-exynos-pcie.c > new file mode 100644 > index 0000000..b57f49b > --- /dev/null > +++ b/drivers/phy/phy-exynos-pcie.c > @@ -0,0 +1,280 @@ > +/* > + * Samsung EXYNOS SoC series PCIe PHY driver > + * > + * Phy provider for PCIe controller on Exynos SoC series > + * > + * Copyright (C) 2016 Samsung Electronics Co., Ltd. 2017? > + * Jaehoon Chung <jh80.chung@samsung.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > + > +#include <linux/delay.h> > +#include <linux/io.h> > +#include <linux/mfd/syscon.h> > +#include <linux/module.h> > +#include <linux/of.h> > +#include <linux/of_address.h> > +#include <linux/of_platform.h> > +#include <linux/platform_device.h> > +#include <linux/phy/phy.h> > +#include <linux/regmap.h> > + > +/* PCIe Purple registers */ > +#define PCIE_PHY_GLOBAL_RESET 0x000 > +#define PCIE_PHY_COMMON_RESET 0x004 > +#define PCIE_PHY_CMN_REG 0x008 > +#define PCIE_PHY_MAC_RESET 0x00c > +#define PCIE_PHY_PLL_LOCKED 0x010 > +#define PCIE_PHY_TRSVREG_RESET 0x020 > +#define PCIE_PHY_TRSV_RESET 0x024 Please use BIT() macro for bit definitions. > + > +/* PCIe PHY registers */ > +#define PCIE_PHY_IMPEDANCE 0x004 > +#define PCIE_PHY_PLL_DIV_0 0x008 > +#define PCIE_PHY_PLL_BIAS 0x00c > +#define PCIE_PHY_DCC_FEEDBACK 0x014 > +#define PCIE_PHY_PLL_DIV_1 0x05c > +#define PCIE_PHY_COMMON_POWER 0x064 > +#define PCIE_PHY_COMMON_PD_CMN BIT(3) > +#define PCIE_PHY_TRSV0_EMP_LVL 0x084 > +#define PCIE_PHY_TRSV0_DRV_LVL 0x088 > +#define PCIE_PHY_TRSV0_RXCDR 0x0ac > +#define PCIE_PHY_TRSV0_POWER 0x0c4 > +#define PCIE_PHY_TRSV0_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV0_LVCC 0x0dc > +#define PCIE_PHY_TRSV1_EMP_LVL 0x144 > +#define PCIE_PHY_TRSV1_RXCDR 0x16c > +#define PCIE_PHY_TRSV1_POWER 0x184 > +#define PCIE_PHY_TRSV1_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV1_LVCC 0x19c > +#define PCIE_PHY_TRSV2_EMP_LVL 0x204 > +#define PCIE_PHY_TRSV2_RXCDR 0x22c > +#define PCIE_PHY_TRSV2_POWER 0x244 > +#define PCIE_PHY_TRSV2_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV2_LVCC 0x25c > +#define PCIE_PHY_TRSV3_EMP_LVL 0x2c4 > +#define PCIE_PHY_TRSV3_RXCDR 0x2ec > +#define PCIE_PHY_TRSV3_POWER 0x304 > +#define PCIE_PHY_TRSV3_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV3_LVCC 0x31c > + > +struct exynos_pcie_phy_data { > + struct phy_ops *ops; > +}; > + > +/* For Exynos pcie phy */ > +struct exynos_pcie_phy { > + const struct exynos_pcie_phy_data *drv_data; > + void __iomem *phy_base; > + void __iomem *blk_base; /* For exynos5440 */ > +}; > + > +static void exynos_pcie_phy_writel(void __iomem *base, u32 val, u32 offset) > +{ > + writel(val, base + offset); > +} > + > +static u32 exynos_pcie_phy_readl(void __iomem *base, u32 offset) > +{ > + return readl(base + offset); > +} > + > +/* For Exynos5440 specific functions */ > +static int exynos5440_pcie_phy_init(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + > + /* DCC feedback control off */ > + exynos_pcie_phy_writel(ep->phy_base, 0x29, PCIE_PHY_DCC_FEEDBACK); > + > + /* set TX/RX impedance */ > + exynos_pcie_phy_writel(ep->phy_base, 0xd5, PCIE_PHY_IMPEDANCE); > + > + /* set 50Mhz PHY clock */ > + exynos_pcie_phy_writel(ep->phy_base, 0x14, PCIE_PHY_PLL_DIV_0); > + exynos_pcie_phy_writel(ep->phy_base, 0x12, PCIE_PHY_PLL_DIV_1); > + > + /* set TX Differential output for lane 0 */ > + exynos_pcie_phy_writel(ep->phy_base, 0x7f, PCIE_PHY_TRSV0_DRV_LVL); > + > + /* set TX Pre-emphasis Level Control for lane 0 to minimum */ > + exynos_pcie_phy_writel(ep->phy_base, 0x0, PCIE_PHY_TRSV0_EMP_LVL); > + > + /* set RX clock and data recovery bandwidth */ > + exynos_pcie_phy_writel(ep->phy_base, 0xe7, PCIE_PHY_PLL_BIAS); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV0_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV1_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV2_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV3_RXCDR); > + > + /* change TX Pre-emphasis Level Control for lanes */ > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV0_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV1_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV2_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV3_EMP_LVL); > + > + /* set LVCC */ > + exynos_pcie_phy_writel(ep->phy_base, 0x20, PCIE_PHY_TRSV0_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV1_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV2_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV3_LVCC); I'm starting to dis-like all this hard-coded hw params. All this should come from dt. Define a dt binding like this for all hw params.. phy,tx-differential = <val, reg-offset, mask> and have one API in phy-core to do all these settings. > + > + /* pulse for common reset */ > + exynos_pcie_phy_writel(ep->blk_base, 1, PCIE_PHY_COMMON_RESET); > + udelay(500); how did you get this delay value? Adding a comment might help. > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_COMMON_RESET); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_power_on(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + u32 val; > + > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_COMMON_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_CMN_REG); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_TRSVREG_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_TRSV_RESET); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_COMMON_POWER); > + val &= ~PCIE_PHY_COMMON_PD_CMN; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_COMMON_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV0_POWER); > + val &= ~PCIE_PHY_TRSV0_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV0_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV1_POWER); > + val &= ~PCIE_PHY_TRSV1_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV1_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV2_POWER); > + val &= ~PCIE_PHY_TRSV2_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV2_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV3_POWER); > + val &= ~PCIE_PHY_TRSV3_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV3_POWER); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_power_off(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + u32 val; > + > + while (exynos_pcie_phy_readl(ep->phy_base, > + PCIE_PHY_PLL_LOCKED) == 0) { > + val = exynos_pcie_phy_readl(ep->blk_base, > + PCIE_PHY_PLL_LOCKED); > + dev_info(&phy->dev, "PLL Locked: 0x%x\n", val); > + } > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_COMMON_POWER); > + val |= PCIE_PHY_COMMON_PD_CMN; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_COMMON_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV0_POWER); > + val |= PCIE_PHY_TRSV0_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV0_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV1_POWER); > + val |= PCIE_PHY_TRSV1_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV1_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV2_POWER); > + val |= PCIE_PHY_TRSV2_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV2_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV3_POWER); > + val |= PCIE_PHY_TRSV3_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV3_POWER); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_reset(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_MAC_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 1, PCIE_PHY_GLOBAL_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_GLOBAL_RESET); > + > + return 0; > +} > + > +static struct phy_ops exynos5440_phy_ops = { > + .init = exynos5440_pcie_phy_init, > + .power_on = exynos5440_pcie_phy_power_on, > + .power_off = exynos5440_pcie_phy_power_off, > + .reset = exynos5440_pcie_phy_reset, add .owner > +}; > + > +static const struct exynos_pcie_phy_data exynos5440_pcie_phy_data = { > + .ops = &exynos5440_phy_ops, why do you need a wrapper for phy_ops? > +}; > + > +static const struct of_device_id exynos_pcie_phy_match[] = { > + { > + .compatible = "samsung,exynos5440-pcie-phy", > + .data = &exynos5440_pcie_phy_data, > + }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, exynos_pcie_phy_match); > + > +static int exynos_pcie_phy_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct exynos_pcie_phy *exynos_phy; > + struct phy *generic_phy; > + struct phy_provider *phy_provider; > + struct resource *res; > + const struct exynos_pcie_phy_data *drv_data; > + > + drv_data = of_device_get_match_data(dev); > + if (!drv_data) > + return -ENODEV; > + > + exynos_phy = devm_kzalloc(dev, sizeof(*exynos_phy), GFP_KERNEL); > + if (!exynos_phy) > + return -ENOMEM; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + exynos_phy->phy_base = devm_ioremap_resource(dev, res); > + if (IS_ERR(exynos_phy->phy_base)) > + return PTR_ERR(exynos_phy->phy_base); > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); > + exynos_phy->blk_base = devm_ioremap_resource(dev, res); > + if (IS_ERR(exynos_phy->phy_base)) > + return PTR_ERR(exynos_phy->phy_base); > + > + exynos_phy->drv_data = drv_data; > + > + generic_phy = devm_phy_create(dev, dev->of_node, drv_data->ops); > + if (IS_ERR(generic_phy)) { > + dev_err(dev, "failed to create PHY\n"); > + return PTR_ERR(generic_phy); > + } > + > + phy_set_drvdata(generic_phy, exynos_phy); > + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); > + > + return PTR_ERR_OR_ZERO(phy_provider); > +} > + > +static struct platform_driver exynos_pcie_phy_driver = { > + .probe = exynos_pcie_phy_probe, > + .driver = { > + .of_match_table = exynos_pcie_phy_match, > + .name = "exynos_pcie_phy", > + } > +}; > +module_platform_driver(exynos_pcie_phy_driver); > Thanks Kishon
WARNING: multiple messages have this Message-ID (diff)
From: Kishon Vijay Abraham I <kishon@ti.com> To: Jaehoon Chung <jh80.chung@samsung.com>, linux-pci@vger.kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, bhelgaas@google.com, robh+dt@kernel.org, mark.rutland@arm.com, kgene@kernel.org, krzk@kernel.org, jingoohan1@gmail.com, vivek.gautam@codeaurora.org, pankaj.dubey@samsung.com, alim.akhtar@samsung.com, cpgs@samsung.com Subject: Re: [PATCH V2 2/5] phy: phy-exynos-pcie: Add support for Exynos PCIe phy Date: Mon, 16 Jan 2017 14:07:07 +0530 [thread overview] Message-ID: <587C8633.5000100@ti.com> (raw) In-Reply-To: <20170104123435.30740-3-jh80.chung@samsung.com> Hi, On Wednesday 04 January 2017 06:04 PM, Jaehoon Chung wrote: > This patch supports to use Generic Phy framework for Exynos PCIe phy. > When Exynos that supported the pcie want to use the PCIe, > it needs to control the phy resgister. > But it should be more complex to control in their own PCIe device drivers. > > Currently, there is an exynos5440 case to support the pcie. > So this driver is based on Exynos5440 PCIe. > In future, will support the Other exynos SoCs likes exynos5433, exynos7. please re-write the commit message. > > Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com> > --- > Changelog on V2: > - Not include the codes relevant to pci-exynos. > - Remove the getting child node. > > drivers/phy/Kconfig | 9 ++ > drivers/phy/Makefile | 1 + > drivers/phy/phy-exynos-pcie.c | 280 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 290 insertions(+) > create mode 100644 drivers/phy/phy-exynos-pcie.c > > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig > index e8eb7f2..2dddef4 100644 > --- a/drivers/phy/Kconfig > +++ b/drivers/phy/Kconfig > @@ -331,6 +331,15 @@ config PHY_EXYNOS5_USBDRD > This driver provides PHY interface for USB 3.0 DRD controller > present on Exynos5 SoC series. > > +config PHY_EXYNOS_PCIE > + bool "Exynos PCIe PHY driver" > + depends on ARCH_EXYNOS && OF include COMPILE_TEST > + depends on PCI_EXYNOS PCI_EXYNOS should depend on PHY_EXYNOS_PCIE if at all required. Or else do away with this dependency. > + select GENERIC_PHY > + help > + Enable PCIe PHY support for Exynos SoC series. > + This driver provides PHY interface for Exynos PCIe controller. > + > config PHY_PISTACHIO_USB > tristate "IMG Pistachio USB2.0 PHY driver" > depends on MACH_PISTACHIO > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile > index 65eb2f4..081aeb4 100644 > --- a/drivers/phy/Makefile > +++ b/drivers/phy/Makefile > @@ -37,6 +37,7 @@ phy-exynos-usb2-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o > phy-exynos-usb2-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o > phy-exynos-usb2-$(CONFIG_PHY_S5PV210_USB2) += phy-s5pv210-usb2.o > obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o > +obj-$(CONFIG_PHY_EXYNOS_PCIE) += phy-exynos-pcie.o > obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o > obj-$(CONFIG_PHY_ROCKCHIP_USB) += phy-rockchip-usb.o > obj-$(CONFIG_PHY_ROCKCHIP_INNO_USB2) += phy-rockchip-inno-usb2.o > diff --git a/drivers/phy/phy-exynos-pcie.c b/drivers/phy/phy-exynos-pcie.c > new file mode 100644 > index 0000000..b57f49b > --- /dev/null > +++ b/drivers/phy/phy-exynos-pcie.c > @@ -0,0 +1,280 @@ > +/* > + * Samsung EXYNOS SoC series PCIe PHY driver > + * > + * Phy provider for PCIe controller on Exynos SoC series > + * > + * Copyright (C) 2016 Samsung Electronics Co., Ltd. 2017? > + * Jaehoon Chung <jh80.chung@samsung.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > + > +#include <linux/delay.h> > +#include <linux/io.h> > +#include <linux/mfd/syscon.h> > +#include <linux/module.h> > +#include <linux/of.h> > +#include <linux/of_address.h> > +#include <linux/of_platform.h> > +#include <linux/platform_device.h> > +#include <linux/phy/phy.h> > +#include <linux/regmap.h> > + > +/* PCIe Purple registers */ > +#define PCIE_PHY_GLOBAL_RESET 0x000 > +#define PCIE_PHY_COMMON_RESET 0x004 > +#define PCIE_PHY_CMN_REG 0x008 > +#define PCIE_PHY_MAC_RESET 0x00c > +#define PCIE_PHY_PLL_LOCKED 0x010 > +#define PCIE_PHY_TRSVREG_RESET 0x020 > +#define PCIE_PHY_TRSV_RESET 0x024 Please use BIT() macro for bit definitions. > + > +/* PCIe PHY registers */ > +#define PCIE_PHY_IMPEDANCE 0x004 > +#define PCIE_PHY_PLL_DIV_0 0x008 > +#define PCIE_PHY_PLL_BIAS 0x00c > +#define PCIE_PHY_DCC_FEEDBACK 0x014 > +#define PCIE_PHY_PLL_DIV_1 0x05c > +#define PCIE_PHY_COMMON_POWER 0x064 > +#define PCIE_PHY_COMMON_PD_CMN BIT(3) > +#define PCIE_PHY_TRSV0_EMP_LVL 0x084 > +#define PCIE_PHY_TRSV0_DRV_LVL 0x088 > +#define PCIE_PHY_TRSV0_RXCDR 0x0ac > +#define PCIE_PHY_TRSV0_POWER 0x0c4 > +#define PCIE_PHY_TRSV0_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV0_LVCC 0x0dc > +#define PCIE_PHY_TRSV1_EMP_LVL 0x144 > +#define PCIE_PHY_TRSV1_RXCDR 0x16c > +#define PCIE_PHY_TRSV1_POWER 0x184 > +#define PCIE_PHY_TRSV1_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV1_LVCC 0x19c > +#define PCIE_PHY_TRSV2_EMP_LVL 0x204 > +#define PCIE_PHY_TRSV2_RXCDR 0x22c > +#define PCIE_PHY_TRSV2_POWER 0x244 > +#define PCIE_PHY_TRSV2_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV2_LVCC 0x25c > +#define PCIE_PHY_TRSV3_EMP_LVL 0x2c4 > +#define PCIE_PHY_TRSV3_RXCDR 0x2ec > +#define PCIE_PHY_TRSV3_POWER 0x304 > +#define PCIE_PHY_TRSV3_PD_TSV BIT(7) > +#define PCIE_PHY_TRSV3_LVCC 0x31c > + > +struct exynos_pcie_phy_data { > + struct phy_ops *ops; > +}; > + > +/* For Exynos pcie phy */ > +struct exynos_pcie_phy { > + const struct exynos_pcie_phy_data *drv_data; > + void __iomem *phy_base; > + void __iomem *blk_base; /* For exynos5440 */ > +}; > + > +static void exynos_pcie_phy_writel(void __iomem *base, u32 val, u32 offset) > +{ > + writel(val, base + offset); > +} > + > +static u32 exynos_pcie_phy_readl(void __iomem *base, u32 offset) > +{ > + return readl(base + offset); > +} > + > +/* For Exynos5440 specific functions */ > +static int exynos5440_pcie_phy_init(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + > + /* DCC feedback control off */ > + exynos_pcie_phy_writel(ep->phy_base, 0x29, PCIE_PHY_DCC_FEEDBACK); > + > + /* set TX/RX impedance */ > + exynos_pcie_phy_writel(ep->phy_base, 0xd5, PCIE_PHY_IMPEDANCE); > + > + /* set 50Mhz PHY clock */ > + exynos_pcie_phy_writel(ep->phy_base, 0x14, PCIE_PHY_PLL_DIV_0); > + exynos_pcie_phy_writel(ep->phy_base, 0x12, PCIE_PHY_PLL_DIV_1); > + > + /* set TX Differential output for lane 0 */ > + exynos_pcie_phy_writel(ep->phy_base, 0x7f, PCIE_PHY_TRSV0_DRV_LVL); > + > + /* set TX Pre-emphasis Level Control for lane 0 to minimum */ > + exynos_pcie_phy_writel(ep->phy_base, 0x0, PCIE_PHY_TRSV0_EMP_LVL); > + > + /* set RX clock and data recovery bandwidth */ > + exynos_pcie_phy_writel(ep->phy_base, 0xe7, PCIE_PHY_PLL_BIAS); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV0_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV1_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV2_RXCDR); > + exynos_pcie_phy_writel(ep->phy_base, 0x82, PCIE_PHY_TRSV3_RXCDR); > + > + /* change TX Pre-emphasis Level Control for lanes */ > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV0_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV1_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV2_EMP_LVL); > + exynos_pcie_phy_writel(ep->phy_base, 0x39, PCIE_PHY_TRSV3_EMP_LVL); > + > + /* set LVCC */ > + exynos_pcie_phy_writel(ep->phy_base, 0x20, PCIE_PHY_TRSV0_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV1_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV2_LVCC); > + exynos_pcie_phy_writel(ep->phy_base, 0xa0, PCIE_PHY_TRSV3_LVCC); I'm starting to dis-like all this hard-coded hw params. All this should come from dt. Define a dt binding like this for all hw params.. phy,tx-differential = <val, reg-offset, mask> and have one API in phy-core to do all these settings. > + > + /* pulse for common reset */ > + exynos_pcie_phy_writel(ep->blk_base, 1, PCIE_PHY_COMMON_RESET); > + udelay(500); how did you get this delay value? Adding a comment might help. > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_COMMON_RESET); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_power_on(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + u32 val; > + > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_COMMON_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_CMN_REG); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_TRSVREG_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_TRSV_RESET); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_COMMON_POWER); > + val &= ~PCIE_PHY_COMMON_PD_CMN; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_COMMON_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV0_POWER); > + val &= ~PCIE_PHY_TRSV0_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV0_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV1_POWER); > + val &= ~PCIE_PHY_TRSV1_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV1_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV2_POWER); > + val &= ~PCIE_PHY_TRSV2_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV2_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV3_POWER); > + val &= ~PCIE_PHY_TRSV3_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV3_POWER); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_power_off(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + u32 val; > + > + while (exynos_pcie_phy_readl(ep->phy_base, > + PCIE_PHY_PLL_LOCKED) == 0) { > + val = exynos_pcie_phy_readl(ep->blk_base, > + PCIE_PHY_PLL_LOCKED); > + dev_info(&phy->dev, "PLL Locked: 0x%x\n", val); > + } > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_COMMON_POWER); > + val |= PCIE_PHY_COMMON_PD_CMN; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_COMMON_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV0_POWER); > + val |= PCIE_PHY_TRSV0_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV0_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV1_POWER); > + val |= PCIE_PHY_TRSV1_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV1_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV2_POWER); > + val |= PCIE_PHY_TRSV2_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV2_POWER); > + > + val = exynos_pcie_phy_readl(ep->phy_base, PCIE_PHY_TRSV3_POWER); > + val |= PCIE_PHY_TRSV3_PD_TSV; > + exynos_pcie_phy_writel(ep->phy_base, val, PCIE_PHY_TRSV3_POWER); > + > + return 0; > +} > + > +static int exynos5440_pcie_phy_reset(struct phy *phy) > +{ > + struct exynos_pcie_phy *ep = phy_get_drvdata(phy); > + > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_MAC_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 1, PCIE_PHY_GLOBAL_RESET); > + exynos_pcie_phy_writel(ep->blk_base, 0, PCIE_PHY_GLOBAL_RESET); > + > + return 0; > +} > + > +static struct phy_ops exynos5440_phy_ops = { > + .init = exynos5440_pcie_phy_init, > + .power_on = exynos5440_pcie_phy_power_on, > + .power_off = exynos5440_pcie_phy_power_off, > + .reset = exynos5440_pcie_phy_reset, add .owner > +}; > + > +static const struct exynos_pcie_phy_data exynos5440_pcie_phy_data = { > + .ops = &exynos5440_phy_ops, why do you need a wrapper for phy_ops? > +}; > + > +static const struct of_device_id exynos_pcie_phy_match[] = { > + { > + .compatible = "samsung,exynos5440-pcie-phy", > + .data = &exynos5440_pcie_phy_data, > + }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, exynos_pcie_phy_match); > + > +static int exynos_pcie_phy_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct exynos_pcie_phy *exynos_phy; > + struct phy *generic_phy; > + struct phy_provider *phy_provider; > + struct resource *res; > + const struct exynos_pcie_phy_data *drv_data; > + > + drv_data = of_device_get_match_data(dev); > + if (!drv_data) > + return -ENODEV; > + > + exynos_phy = devm_kzalloc(dev, sizeof(*exynos_phy), GFP_KERNEL); > + if (!exynos_phy) > + return -ENOMEM; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + exynos_phy->phy_base = devm_ioremap_resource(dev, res); > + if (IS_ERR(exynos_phy->phy_base)) > + return PTR_ERR(exynos_phy->phy_base); > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); > + exynos_phy->blk_base = devm_ioremap_resource(dev, res); > + if (IS_ERR(exynos_phy->phy_base)) > + return PTR_ERR(exynos_phy->phy_base); > + > + exynos_phy->drv_data = drv_data; > + > + generic_phy = devm_phy_create(dev, dev->of_node, drv_data->ops); > + if (IS_ERR(generic_phy)) { > + dev_err(dev, "failed to create PHY\n"); > + return PTR_ERR(generic_phy); > + } > + > + phy_set_drvdata(generic_phy, exynos_phy); > + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); > + > + return PTR_ERR_OR_ZERO(phy_provider); > +} > + > +static struct platform_driver exynos_pcie_phy_driver = { > + .probe = exynos_pcie_phy_probe, > + .driver = { > + .of_match_table = exynos_pcie_phy_match, > + .name = "exynos_pcie_phy", > + } > +}; > +module_platform_driver(exynos_pcie_phy_driver); > Thanks Kishon
next prev parent reply other threads:[~2017-01-16 8:37 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <CGME20170104123435epcas1p182b241236048160fb81ac473a74540da@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 0/5] PCI: exynos: use the PHY generic framework Jaehoon Chung [not found] ` <CGME20170104123436epcas1p1d3d840e4ade396a60ce690b09d486990@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 1/5] Documetation: samsung-phy: add the exynos-pcie-phy binding Jaehoon Chung 2017-01-04 15:17 ` Rob Herring 2017-01-04 15:17 ` Rob Herring 2017-01-05 4:16 ` Alim Akhtar 2017-01-05 6:06 ` pankaj.dubey 2017-01-05 6:06 ` pankaj.dubey [not found] ` <CGME20170104123436epcas1p1a729583c3c2307d8539a186f1050ea98@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 2/5] phy: phy-exynos-pcie: Add support for Exynos PCIe phy Jaehoon Chung 2017-01-04 17:52 ` Krzysztof Kozlowski 2017-01-05 2:22 ` Jaehoon Chung 2017-01-04 20:21 ` Jingoo Han 2017-01-04 20:21 ` Jingoo Han 2017-01-05 6:18 ` pankaj.dubey 2017-01-09 13:34 ` Alim Akhtar 2017-01-10 6:07 ` Vivek Gautam 2017-01-10 6:07 ` Vivek Gautam 2017-01-10 6:10 ` Jaehoon Chung 2017-01-16 8:37 ` Kishon Vijay Abraham I [this message] 2017-01-16 8:37 ` Kishon Vijay Abraham I 2017-01-16 11:00 ` Jaehoon Chung [not found] ` <CGME20170104123436epcas1p1040f1e074748fabe58af52eb0b833713@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 3/5] Documetation: binding: modify the exynos5440 pcie binding Jaehoon Chung 2017-01-04 15:18 ` Rob Herring 2017-01-05 6:21 ` pankaj.dubey 2017-01-09 13:36 ` Alim Akhtar [not found] ` <CGME20170104123436epcas1p1651443c5fe13f67006864aed2f70fa9d@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 4/5] PCI: exynos: support the using PHY generic framework Jaehoon Chung 2017-01-04 17:50 ` Krzysztof Kozlowski 2017-01-05 2:21 ` Jaehoon Chung 2017-01-04 19:56 ` Jingoo Han 2017-01-04 19:56 ` Jingoo Han 2017-01-05 9:01 ` pankaj.dubey 2017-01-09 13:39 ` Alim Akhtar [not found] ` <CGME20170104123436epcas1p10b52f24e7d6c00edb44e4331a1870e4d@epcas1p1.samsung.com> 2017-01-04 12:34 ` [PATCH V2 5/5] ARM: dts: exynos5440: support the phy-pcie node for pcie Jaehoon Chung 2017-01-04 17:58 ` Krzysztof Kozlowski 2017-01-04 18:02 ` Jingoo Han 2017-01-04 18:02 ` Jingoo Han 2017-01-05 2:24 ` Jaehoon Chung 2017-01-05 9:04 ` pankaj.dubey 2017-01-12 21:01 ` [PATCH V2 0/5] PCI: exynos: use the PHY generic framework Bjorn Helgaas
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=587C8633.5000100@ti.com \ --to=kishon@ti.com \ --cc=alim.akhtar@samsung.com \ --cc=bhelgaas@google.com \ --cc=cpgs@samsung.com \ --cc=devicetree@vger.kernel.org \ --cc=jh80.chung@samsung.com \ --cc=jingoohan1@gmail.com \ --cc=kgene@kernel.org \ --cc=krzk@kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=linux-samsung-soc@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=pankaj.dubey@samsung.com \ --cc=robh+dt@kernel.org \ --cc=vivek.gautam@codeaurora.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.