PCI: dwc: miscellaneous cleanups and fixes
cover PCI: dwc: miscellaneous cleanups and fixes
This series includes miscellaneous cleanups and fixes in dra7xx pci driver and it also adds COMPILE_TEST to all designware based drivers (except dra7xx driver and hisi driver), since dra7xx driver doesn't depend on architecture specific config and hisi driver is compiled based on only ARM64.
These patches have been created after applying [1].
[1] -> https://lkml.org/lkml/2017/1/6/246
Kishon Vijay Abraham I (5):
PCI: dwc: Add COMPILE_TEST to all designware based drivers
PCI: dwc: dra7xx: Simplify the probe code
PCI: dwc: dra7xx: Add support to force RC to work in GEN1 mode
PCI: dwc: dra7xx: Enable MSI and legacy interrupts simultaneously
PCI: dwc: dra7xx: Group phy API invocations
drivers/pci/dwc/Kconfig | 16 ++-- drivers/pci/dwc/pci-dra7xx.c | 174 ++++++++++++++++++++++++------------------ 2 files changed, 106 insertions(+), 84 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/5 PCI: dwc: Add COMPILE_TEST to all designware based drivers
Add COMPILE_TEST to all designware based drivers so that it is possible to perform compile test even when a particular architecture specific config symbol is not set.
--- drivers/pci/dwc/Kconfig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/dwc/Kconfig +8 -8
@@ -29,21 +29,21 @@ config PCIE_DW_PLAT config PCI_EXYNOS bool "Samsung Exynos PCIe controller" - depends on SOC_EXYNOS5440 + depends on SOC_EXYNOS5440 || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW config PCI_IMX6 bool "Freescale i.MX6 PCIe controller" - depends on SOC_IMX6Q + depends on SOC_IMX6Q || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW config PCIE_SPEAR13XX bool "STMicroelectronics SPEAr PCIe controller" - depends on ARCH_SPEAR13XX + depends on ARCH_SPEAR13XX || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW
@@ -52,7 +52,7 @@ config PCIE_SPEAR13XX config PCI_KEYSTONE bool "TI Keystone PCIe controller" - depends on ARCH_KEYSTONE + depends on ARCH_KEYSTONE || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW
@@ -64,7 +64,7 @@ config PCI_KEYSTONE config PCI_LAYERSCAPE bool "Freescale Layerscape PCIe controller" - depends on OF && (ARM || ARCH_LAYERSCAPE) + depends on OF && (ARM || ARCH_LAYERSCAPE || COMPILE_TEST) depends on PCI_MSI_IRQ_DOMAIN select MFD_SYSCON select PCIE_DW
@@ -83,7 +83,7 @@ config PCI_HISI config PCIE_QCOM bool "Qualcomm PCIe controller" - depends on ARCH_QCOM && OF + depends on (ARCH_QCOM || COMPILE_TEST) && OF depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW
@@ -94,7 +94,7 @@ config PCIE_QCOM config PCIE_ARMADA_8K bool "Marvell Armada-8K PCIe controller" - depends on ARCH_MVEBU + depends on ARCH_MVEBU || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW
@@ -106,7 +106,7 @@ config PCIE_ARMADA_8K config PCIE_ARTPEC6 bool "Axis ARTPEC-6 PCIe controller" - depends on MACH_ARTPEC6 + depends on MACH_ARTPEC6 || COMPILE_TEST depends on PCI_MSI_IRQ_DOMAIN select PCIEPORTBUS select PCIE_DW
Signature · 1 line
1.7.9.5
PATCH 2/5 PCI: dwc: dra7xx: Simplify the probe code
In reply to Kishon Vijay Abraham INo functional change. Use the new devm_gpiod_get_optional() to simplify the probe code.
--- drivers/pci/dwc/pci-dra7xx.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/pci/dwc/pci-dra7xx.c +5 -16
@@ -320,9 +320,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct device_node *np = dev->of_node;char name[10 ]; -int gpio_sel; -enum of_gpio_flags flags; -unsigned long gpio_flags; +struct gpio_desc *reset; dra7xx =devm_kzalloc (dev,sizeof (*dra7xx),GFP_KERNEL );if (!dra7xx)
@@ -388,19 +386,10 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) goto err_get_sync; } - gpio_sel =of_get_gpio_flags (dev->of_node,0 , &flags); -if (gpio_is_valid (gpio_sel)) { - gpio_flags = (flags &OF_GPIO_ACTIVE_LOW ) ? -GPIOF_OUT_INIT_LOW :GPIOF_OUT_INIT_HIGH ; - ret =devm_gpio_request_one (dev, gpio_sel, gpio_flags, -"pcie_reset" ); -if (ret) { -dev_err (dev,"gpio%d request failed, ret %d\n" , - gpio_sel, ret); - goto err_gpio; - } - }else if (gpio_sel == -EPROBE_DEFER ) { - ret = -EPROBE_DEFER ; + reset =devm_gpiod_get_optional (dev,NULL ,GPIOD_OUT_HIGH ); +if (IS_ERR (reset)) { + ret =PTR_ERR (reset); +dev_err (&pdev->dev,"gpio request failed, ret %d\n" , ret); goto err_gpio; }
Signature · 1 line
1.7.9.5
PATCH 3/5 PCI: dwc: dra7xx: Add support to force RC to work in GEN1 mode
In reply to Kishon Vijay Abraham IPCIe in AM57x/DRA7x devices is by default configured to work in GEN2 mode. However there may be situations when working in GEN1 mode is desired. One example is limitation i925 (PCIe GEN2 mode not supported at junction temperatures < 0C).
Add support to force Root Complex to work in GEN1 mode if so desired, but don't force GEN1 mode on any board just yet.
--- drivers/pci/dwc/pci-dra7xx.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/pci/dwc/pci-dra7xx.c +29 -0
@@ -17,6 +17,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/of_gpio.h> +#include <linux/of_pci.h> #include <linux/pci.h> #include <linux/phy/phy.h> #include <linux/platform_device.h>
@@ -63,11 +64,14 @@#define LINK_UP BIT(16)#define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF +#define EXP_CAP_ID_OFFSET 0x70 +struct dra7xx_pcie {struct pcie_port pp;void __iomem *base;/* DT ti_conf */ int phy_count;/* DT phy-names count */ struct phy **phy; +int link_gen; };#define to_dra7xx_pcie (x) container_of((x), struct dra7xx_pcie, pp)
@@ -96,12 +100,33 @@ static int dra7xx_pcie_establish_link(struct dra7xx_pcie *dra7xx)struct pcie_port *pp = &dra7xx->pp;struct device *dev = pp->dev;u32 reg; +u32 exp_cap_off =EXP_CAP_ID_OFFSET ;if (dw_pcie_link_up (pp)) {dev_err (dev,"link is already up\n" );return 0 ; } +if (dra7xx->link_gen ==1 ) { +dw_pcie_cfg_read (pp->dbi_base + exp_cap_off +PCI_EXP_LNKCAP , +4 , ®); +if ((reg &PCI_EXP_LNKCAP_SLS ) !=PCI_EXP_LNKCAP_SLS_2_5GB ) { + reg &= ~((u32 )PCI_EXP_LNKCAP_SLS ); + reg |=PCI_EXP_LNKCAP_SLS_2_5GB ; +dw_pcie_cfg_write (pp->dbi_base + exp_cap_off + +PCI_EXP_LNKCAP ,4 , reg); + } + +dw_pcie_cfg_read (pp->dbi_base + exp_cap_off +PCI_EXP_LNKCTL2 , +2 , ®); +if ((reg &PCI_EXP_LNKCAP_SLS ) !=PCI_EXP_LNKCAP_SLS_2_5GB ) { + reg &= ~((u32 )PCI_EXP_LNKCAP_SLS ); + reg |=PCI_EXP_LNKCAP_SLS_2_5GB ; +dw_pcie_cfg_write (pp->dbi_base + exp_cap_off + +PCI_EXP_LNKCTL2 ,2 , reg); + } + } + reg =dra7xx_pcie_readl (dra7xx,PCIECTRL_DRA7XX_CONF_DEVICE_CMD ); reg |=LTSSM_EN ;dra7xx_pcie_writel (dra7xx,PCIECTRL_DRA7XX_CONF_DEVICE_CMD , reg);
@@ -397,6 +422,10 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) reg &= ~LTSSM_EN ;dra7xx_pcie_writel (dra7xx,PCIECTRL_DRA7XX_CONF_DEVICE_CMD , reg); + dra7xx->link_gen =of_pci_get_max_link_speed (np); +if (dra7xx->link_gen <0 || dra7xx->link_gen >2 ) + dra7xx->link_gen =2 ; + ret =dra7xx_add_pcie_port (dra7xx, pdev);if (ret <0 ) goto err_gpio;
Signature · 1 line
1.7.9.5
PATCH 4/5 PCI: dwc: dra7xx: Enable MSI and legacy interrupts simultaneously
In reply to Kishon Vijay Abraham Ipci-dra7xx driver had a bug in that if CONFIG_PCI_MSI config is enabled, it doesn't support legacy interrupt. Fix it here so that both MSI and legacy interrupts can be enabled simultaneously and the interrupt mechanism supported by the endpoint device will be used.
--- drivers/pci/dwc/pci-dra7xx.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
drivers/pci/dwc/pci-dra7xx.c +13 -19
@@ -72,6 +72,7 @@ struct dra7xx_pcie {int phy_count;/* DT phy-names count */ struct phy **phy;int link_gen; +struct irq_domain *irq_domain; };#define to_dra7xx_pcie (x) container_of((x), struct dra7xx_pcie, pp)
@@ -142,14 +143,8 @@ static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie *dra7xx) PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, INTERRUPTS);dra7xx_pcie_writel (dra7xx,PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI , ~LEG_EP_INTERRUPTS & ~MSI ); - -if (IS_ENABLED (CONFIG_PCI_MSI )) -dra7xx_pcie_writel (dra7xx, -PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI ,MSI ); -else -dra7xx_pcie_writel (dra7xx, -PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI , -LEG_EP_INTERRUPTS ); +dra7xx_pcie_writel (dra7xx,PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI , +MSI |LEG_EP_INTERRUPTS ); }static void dra7xx_pcie_host_init (struct pcie_port *pp)
@@ -164,8 +159,7 @@ static void dra7xx_pcie_host_init(struct pcie_port *pp)dw_pcie_setup_rc (pp);dra7xx_pcie_establish_link (dra7xx); -if (IS_ENABLED (CONFIG_PCI_MSI )) -dw_pcie_msi_init (pp); +dw_pcie_msi_init (pp);dra7xx_pcie_enable_interrupts (dra7xx); }
@@ -190,6 +184,7 @@ static int dra7xx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,static int dra7xx_pcie_init_irq_domain (struct pcie_port *pp) {struct device *dev = pp->dev; +struct dra7xx_pcie *dra7xx =to_dra7xx_pcie (pp);struct device_node *node = dev->of_node;struct device_node *pcie_intc_node =of_get_next_child (node,NULL );
@@ -198,9 +193,9 @@ static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)return -ENODEV ; } - pp->irq_domain =irq_domain_add_linear (pcie_intc_node,4 , - &intx_domain_ops, pp); -if (!pp->irq_domain) { + dra7xx->irq_domain =irq_domain_add_linear (pcie_intc_node,4 , + &intx_domain_ops, pp); +if (!dra7xx->irq_domain) {dev_err (dev,"Failed to get a INTx IRQ domain\n" );return -ENODEV ; }
@@ -224,7 +219,8 @@ static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)case INTB :case INTC :case INTD : -generic_handle_irq (irq_find_mapping (pp->irq_domain,ffs (reg))); +generic_handle_irq (irq_find_mapping (dra7xx->irq_domain, +ffs (reg)));break ; }
@@ -310,11 +306,9 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,return ret; } -if (!IS_ENABLED (CONFIG_PCI_MSI )) { - ret =dra7xx_pcie_init_irq_domain (pp); -if (ret <0 ) -return ret; - } + ret =dra7xx_pcie_init_irq_domain (pp); +if (ret <0 ) +return ret; res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"rc_dbics" ); pp->dbi_base =devm_ioremap (dev, res->start,resource_size (res));
Signature · 1 line
1.7.9.5
PATCH 5/5 PCI: dwc: dra7xx: Group phy API invocations
In reply to Kishon Vijay Abraham INo functional change. Phy APIs like phy_init/phy_power_on is being invoked from multiple places. Group all the phy APIs in dra7xx_pcie_enable_phy() and dra7xx_pcie_disable_phy() and use these functions for enabling or disabling the phy.
--- drivers/pci/dwc/pci-dra7xx.c | 92 +++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 41 deletions(-)
drivers/pci/dwc/pci-dra7xx.c +51 -41
@@ -324,6 +324,45 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,return 0 ; } +static void dra7xx_pcie_disable_phy (struct dra7xx_pcie *dra7xx) +{ +int phy_count = dra7xx->phy_count; + +while (phy_count--) { +phy_power_off (dra7xx->phy[phy_count]); +phy_exit (dra7xx->phy[phy_count]); + } +} + +static int dra7xx_pcie_enable_phy (struct dra7xx_pcie *dra7xx) +{ +int phy_count = dra7xx->phy_count; +int ret; +int i; + +for (i =0 ; i < phy_count; i++) { + ret =phy_init (dra7xx->phy[i]); +if (ret <0 ) + goto err_phy; + + ret =phy_power_on (dra7xx->phy[i]); +if (ret <0 ) { +phy_exit (dra7xx->phy[i]); + goto err_phy; + } + } + +return 0 ; + +err_phy: +while (--i >=0 ) { +phy_power_off (dra7xx->phy[i]); +phy_exit (dra7xx->phy[i]); + } + +return ret; +} +static int __init dra7xx_pcie_probe (struct platform_device *pdev) {u32 reg;
@@ -382,22 +421,18 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) phy[i] =devm_phy_get (dev, name);if (IS_ERR (phy[i]))return PTR_ERR (phy[i]); - - ret =phy_init (phy[i]); -if (ret <0 ) - goto err_phy; - - ret =phy_power_on (phy[i]); -if (ret <0 ) { -phy_exit (phy[i]); - goto err_phy; - } } dra7xx->base = base; dra7xx->phy = phy; dra7xx->phy_count = phy_count; + ret =dra7xx_pcie_enable_phy (dra7xx); +if (ret) { +dev_err (dev,"failed to enable phy\n" ); +return ret; + } +pm_runtime_enable (dev); ret =pm_runtime_get_sync (dev);if (ret <0 ) {
@@ -432,12 +467,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) err_get_sync:pm_runtime_disable (dev); - -err_phy: -while (--i >=0 ) { -phy_power_off (phy[i]); -phy_exit (phy[i]); - } +dra7xx_pcie_disable_phy (dra7xx);return ret; }
@@ -474,12 +504,8 @@ static int dra7xx_pcie_resume(struct device *dev)static int dra7xx_pcie_suspend_noirq (struct device *dev) {struct dra7xx_pcie *dra7xx =dev_get_drvdata (dev); -int count = dra7xx->phy_count; -while (count--) { -phy_power_off (dra7xx->phy[count]); -phy_exit (dra7xx->phy[count]); - } +dra7xx_pcie_disable_phy (dra7xx);return 0 ; }
@@ -487,31 +513,15 @@ static int dra7xx_pcie_suspend_noirq(struct device *dev)static int dra7xx_pcie_resume_noirq (struct device *dev) {struct dra7xx_pcie *dra7xx =dev_get_drvdata (dev); -int phy_count = dra7xx->phy_count;int ret; -int i; - -for (i =0 ; i < phy_count; i++) { - ret =phy_init (dra7xx->phy[i]); -if (ret <0 ) - goto err_phy; - ret =phy_power_on (dra7xx->phy[i]); -if (ret <0 ) { -phy_exit (dra7xx->phy[i]); - goto err_phy; - } + ret =dra7xx_pcie_enable_phy (dra7xx); +if (ret) { +dev_err (dev,"failed to enable phy\n" ); +return ret; }return 0 ; - -err_phy: -while (--i >=0 ) { -phy_power_off (dra7xx->phy[i]); -phy_exit (dra7xx->phy[i]); - } - -return ret; }#endif
Signature · 1 line
1.7.9.5
Quoted 17 lines · Kishon Vijay Abraham I
This series includes miscellaneous cleanups and fixes in dra7xx pci driver and it also adds
COMPILE_TESTto all designware based drivers (except dra7xx driver and hisi driver), since dra7xx driver doesn't depend on architecture specific config and hisi driver is compiled based on only ARM64.These patches have been created after applying [1].
[1] -> https://lkml.org/lkml/2017/1/6/246
Kishon Vijay Abraham I (5):
PCI: dwc: AddCOMPILE_TESTto all designware based drivers
PCI: dwc: dra7xx: Simplify the probe code
PCI: dwc: dra7xx: Add support to force RC to work in GEN1 mode
PCI: dwc: dra7xx: Enable MSI and legacy interrupts simultaneously
PCI: dwc: dra7xx: Group phy API invocations
Quoted 3 lines
drivers/pci/dwc/Kconfig | 16 ++-- drivers/pci/dwc/pci-dra7xx.c | 174 ++++++++++++++++++++++++------------------ 2 files changed, 106 insertions(+), 84 deletions(-)
Applied to pci/host-designware for v4.11, thanks! I added Pankaj's reviewed-by to the COMPILE_TEST patch. His reviewed-by was technically for your standalone post of that patch, but I think both postings have the identical patch.
Quoted 18 lines · Bjorn Helgaas
Quoted 17 lines · Kishon Vijay Abraham I
This series includes miscellaneous cleanups and fixes in dra7xx pci driver and it also adds
COMPILE_TESTto all designware based drivers (except dra7xx driver and hisi driver), since dra7xx driver doesn't depend on architecture specific config and hisi driver is compiled based on only ARM64.These patches have been created after applying [1].
[1] -> https://lkml.org/lkml/2017/1/6/246
Kishon Vijay Abraham I (5):
PCI: dwc: AddCOMPILE_TESTto all designware based drivers
PCI: dwc: dra7xx: Simplify the probe code
PCI: dwc: dra7xx: Add support to force RC to work in GEN1 mode
PCI: dwc: dra7xx: Enable MSI and legacy interrupts simultaneously
PCI: dwc: dra7xx: Group phy API invocations
Quoted 8 lines
Quoted 3 lines
drivers/pci/dwc/Kconfig | 16 ++-- drivers/pci/dwc/pci-dra7xx.c | 174 ++++++++++++++++++++++++------------------ 2 files changed, 106 insertions(+), 84 deletions(-)Applied to pci/host-designware for v4.11, thanks! I added Pankaj's reviewed-by to the
COMPILE_TESTpatch. His reviewed-by was technically for your standalone post of that patch, but I think both postings have the identical patch.
Thanks Bjorn! Right, that was the same patch.
Regards
Kishon