123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- From 1d1885f4a7abd7272f47b835b03d8662fb981d19 Mon Sep 17 00:00:00 2001
- From: Eddi De Pieri <[email protected]>
- Date: Tue, 14 Oct 2014 11:04:00 +0000
- Subject: [PATCH] MIPS: lantiq: ifxmips_pcie: use of
- Signed-off-by: Eddi De Pieri <[email protected]>
- ---
- arch/mips/pci/Makefile | 2 +-
- arch/mips/pci/ifxmips_pcie.c | 151 +++++++++++++++++++++++++++----
- arch/mips/pci/ifxmips_pcie_vr9.h | 105 ---------------------
- 3 files changed, 133 insertions(+), 125 deletions(-)
- --- a/arch/mips/pci/Makefile
- +++ b/arch/mips/pci/Makefile
- @@ -43,7 +43,7 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
- obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
- obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
- obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
- -obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
- +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie.o fixup-lantiq-pcie.o
- obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
- obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
- obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
- --- a/arch/mips/pci/ifxmips_pcie.c
- +++ b/arch/mips/pci/ifxmips_pcie.c
- @@ -16,8 +16,15 @@
- #include <asm/paccess.h>
- #include <linux/pci.h>
- #include <linux/pci_regs.h>
- +#include <linux/phy/phy.h>
- +#include <linux/regmap.h>
- +#include <linux/reset.h>
- +#include <linux/mfd/syscon.h>
- #include <linux/module.h>
-
- +#include <linux/of_gpio.h>
- +#include <linux/of_platform.h>
- +
- #include "ifxmips_pcie.h"
- #include "ifxmips_pcie_reg.h"
-
- @@ -40,6 +47,11 @@
- static DEFINE_SPINLOCK(ifx_pcie_lock);
-
- u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
- +static int pcie_reset_gpio;
- +static struct phy *ltq_pcie_phy;
- +static struct reset_control *ltq_pcie_reset;
- +static struct regmap *ltq_rcu_regmap;
- +static bool switch_pcie_endianess;
-
- static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
- {
- @@ -82,6 +94,22 @@ void ifx_pcie_debug(const char *fmt, ...
- printk("%s", buf);
- }
-
- +static inline void pcie_ep_gpio_rst_init(int pcie_port)
- +{
- + gpio_direction_output(pcie_reset_gpio, 1);
- + gpio_set_value(pcie_reset_gpio, 1);
- +}
- +
- +static inline void pcie_device_rst_assert(int pcie_port)
- +{
- + gpio_set_value(pcie_reset_gpio, 0);
- +}
- +
- +static inline void pcie_device_rst_deassert(int pcie_port)
- +{
- + mdelay(100);
- + gpio_direction_output(pcie_reset_gpio, 1);
- +}
-
- static inline int pcie_ltssm_enable(int pcie_port)
- {
- @@ -988,10 +1016,26 @@ int ifx_pcie_bios_plat_dev_init(struct
- static int
- pcie_rc_initialize(int pcie_port)
- {
- - int i;
- + int i, ret;
- #define IFX_PCIE_PHY_LOOP_CNT 5
-
- - pcie_rcu_endian_setup(pcie_port);
- + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_M,
- + IFX_RCU_AHB_BE_PCIE_M);
- +
- +#ifdef CONFIG_IFX_PCIE_HW_SWAP
- + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
- + IFX_RCU_AHB_BE_PCIE_S);
- + if (switch_pcie_endianess) {
- + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_S,
- + IFX_RCU_AHB_BE_XBAR_S);
- + }
- +#else
- + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
- + 0x0);
- +#endif
- +
- + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
- + 0x0);
-
- pcie_ep_gpio_rst_init(pcie_port);
-
- @@ -1000,26 +1044,21 @@ pcie_rc_initialize(int pcie_port)
- * reset PCIe PHY will solve this issue
- */
- for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
- - /* Disable PCIe PHY Analog part for sanity check */
- - pcie_phy_pmu_disable(pcie_port);
- -
- - pcie_phy_rst_assert(pcie_port);
- - pcie_phy_rst_deassert(pcie_port);
- -
- - /* Make sure PHY PLL is stable */
- - udelay(20);
- -
- - /* PCIe Core reset enabled, low active, sw programmed */
- - pcie_core_rst_assert(pcie_port);
- + ret = phy_init(ltq_pcie_phy);
- + if (ret)
- + continue;
-
- /* Put PCIe EP in reset status */
- pcie_device_rst_assert(pcie_port);
-
- - /* PCI PHY & Core reset disabled, high active, sw programmed */
- - pcie_core_rst_deassert(pcie_port);
- + udelay(1);
- + reset_control_deassert(ltq_pcie_reset);
-
- - /* Already in a quiet state, program PLL, enable PHY, check ready bit */
- - pcie_phy_clock_mode_setup(pcie_port);
- + ret = phy_power_on(ltq_pcie_phy);
- + if (ret) {
- + phy_exit(ltq_pcie_phy);
- + continue;
- + }
-
- /* Enable PCIe PHY and Clock */
- pcie_core_pmu_setup(pcie_port);
- @@ -1035,6 +1074,10 @@ pcie_rc_initialize(int pcie_port)
- /* Once link is up, break out */
- if (pcie_app_loigc_setup(pcie_port) == 0)
- break;
- +
- + phy_power_off(ltq_pcie_phy);
- + reset_control_assert(ltq_pcie_reset);
- + phy_exit(ltq_pcie_phy);
- }
- if (i >= IFX_PCIE_PHY_LOOP_CNT) {
- printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
- @@ -1045,17 +1088,74 @@ pcie_rc_initialize(int pcie_port)
- return 0;
- }
-
- -static int __init ifx_pcie_bios_init(void)
- +static int ifx_pcie_bios_probe(struct platform_device *pdev)
- {
- + struct device_node *node = pdev->dev.of_node;
- void __iomem *io_map_base;
- int pcie_port;
- int startup_port;
- + struct device_node *np;
- + struct pci_bus *bus;
- +
- + /*
- + * In case a PCI device is physical present, the Lantiq PCI driver need
- + * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
- + * will work.
- + *
- + * In case the lantiq PCI driver is enabled in the device tree, check if
- + * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
- + * registered.
- + *
- + * It will fail if there is another PCI controller, this controller is
- + * registered before the Lantiq PCIe driver is probe and the lantiq PCI
- + */
- + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
- +
- + if (of_device_is_available(np)) {
- + bus = pci_find_next_bus(bus);
- +
- + if (!bus)
- + return -EPROBE_DEFER;
- + }
-
- /* Enable AHB Master/ Slave */
- pcie_ahb_pmu_setup();
-
- startup_port = IFX_PCIE_PORT0;
- -
- +
- + ltq_pcie_phy = devm_phy_get(&pdev->dev, "pcie");
- + if (IS_ERR(ltq_pcie_phy)) {
- + dev_err(&pdev->dev, "failed to get the PCIe PHY\n");
- + return PTR_ERR(ltq_pcie_phy);
- + }
- +
- + ltq_pcie_reset = devm_reset_control_get_shared(&pdev->dev, NULL);
- + if (IS_ERR(ltq_pcie_reset)) {
- + dev_err(&pdev->dev, "failed to get the PCIe reset line\n");
- + return PTR_ERR(ltq_pcie_reset);
- + }
- +
- + if (of_property_read_bool(node, "lantiq,switch-pcie-endianess")) {
- + switch_pcie_endianess = true;
- + dev_info(&pdev->dev, "switch pcie endianess requested\n");
- + } else {
- + switch_pcie_endianess = false;
- + }
- +
- + ltq_rcu_regmap = syscon_regmap_lookup_by_phandle(node, "lantiq,rcu");
- + if (IS_ERR(ltq_rcu_regmap))
- + return PTR_ERR(ltq_rcu_regmap);
- +
- + pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
- + if (gpio_is_valid(pcie_reset_gpio)) {
- + int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
- + if (ret) {
- + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
- + return ret;
- + }
- + gpio_direction_output(pcie_reset_gpio, 1);
- + }
- +
- for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
- if (pcie_rc_initialize(pcie_port) == 0) {
- IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
- @@ -1067,6 +1167,7 @@ static int __init ifx_pcie_bios_init(voi
- return -ENOMEM;
- }
- ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
- + pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
-
- register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
- /* XXX, clear error status */
- @@ -1083,6 +1184,30 @@ static int __init ifx_pcie_bios_init(voi
-
- return 0;
- }
- +
- +static const struct of_device_id ifxmips_pcie_match[] = {
- + { .compatible = "lantiq,pcie-xrx200" },
- + {},
- +};
- +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
- +
- +static struct platform_driver ltq_pci_driver = {
- + .probe = ifx_pcie_bios_probe,
- + .driver = {
- + .name = "pcie-xrx200",
- + .owner = THIS_MODULE,
- + .of_match_table = ifxmips_pcie_match,
- + },
- +};
- +
- +int __init ifx_pcie_bios_init(void)
- +{
- + int ret = platform_driver_register(<q_pci_driver);
- + if (ret)
- + pr_info("pcie-xrx200: Error registering platform driver!");
- + return ret;
- +}
- +
- arch_initcall(ifx_pcie_bios_init);
-
- MODULE_LICENSE("GPL");
- --- a/arch/mips/pci/ifxmips_pcie_vr9.h
- +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
- @@ -22,8 +22,6 @@
- #include <linux/gpio.h>
- #include <lantiq_soc.h>
-
- -#define IFX_PCIE_GPIO_RESET 494
- -
- #define IFX_REG_R32 ltq_r32
- #define IFX_REG_W32 ltq_w32
- #define CONFIG_IFX_PCIE_HW_SWAP
- @@ -54,21 +52,6 @@
- #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
-
-
- -static inline void pcie_ep_gpio_rst_init(int pcie_port)
- -{
- -
- - gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
- - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
- - gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
- -
- -/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- - ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- - ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- - ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- - ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- - ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
- -}
- -
- static inline void pcie_ahb_pmu_setup(void)
- {
- /* Enable AHB bus master/slave */
- @@ -80,24 +63,6 @@ static inline void pcie_ahb_pmu_setup(vo
- //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
- }
-
- -static inline void pcie_rcu_endian_setup(int pcie_port)
- -{
- - u32 reg;
- -
- - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
- -#ifdef CONFIG_IFX_PCIE_HW_SWAP
- - reg |= IFX_RCU_AHB_BE_PCIE_M;
- - reg |= IFX_RCU_AHB_BE_PCIE_S;
- - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
- -#else
- - reg |= IFX_RCU_AHB_BE_PCIE_M;
- - reg &= ~IFX_RCU_AHB_BE_PCIE_S;
- - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
- -#endif /* CONFIG_IFX_PCIE_HW_SWAP */
- - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
- - IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
- -}
- -
- static inline void pcie_phy_pmu_enable(int pcie_port)
- {
- struct clk *clk;
- @@ -116,17 +81,6 @@ static inline void pcie_phy_pmu_disable(
- // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
- }
-
- -static inline void pcie_pdi_big_endian(int pcie_port)
- -{
- - u32 reg;
- -
- - /* SRAM2PDI endianness control. */
- - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
- - /* Config AHB->PCIe and PDI endianness */
- - reg |= IFX_RCU_AHB_BE_PCIE_PDI;
- - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
- -}
- -
- static inline void pcie_pdi_pmu_enable(int pcie_port)
- {
- /* Enable PDI to access PCIe PHY register */
- @@ -136,65 +90,6 @@ static inline void pcie_pdi_pmu_enable(i
- //PDI_PMU_SETUP(IFX_PMU_ENABLE);
- }
-
- -static inline void pcie_core_rst_assert(int pcie_port)
- -{
- - u32 reg;
- -
- - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
- -
- - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
- - reg |= 0x00400000;
- - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
- -}
- -
- -static inline void pcie_core_rst_deassert(int pcie_port)
- -{
- - u32 reg;
- -
- - /* Make sure one micro-second delay */
- - udelay(1);
- -
- - /* Reset PCIe PHY & Core, bit 22 */
- - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
- - reg &= ~0x00400000;
- - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
- -}
- -
- -static inline void pcie_phy_rst_assert(int pcie_port)
- -{
- - u32 reg;
- -
- - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
- - reg |= 0x00001000; /* Bit 12 */
- - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
- -}
- -
- -static inline void pcie_phy_rst_deassert(int pcie_port)
- -{
- - u32 reg;
- -
- - /* Make sure one micro-second delay */
- - udelay(1);
- -
- - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
- - reg &= ~0x00001000; /* Bit 12 */
- - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
- -}
- -
- -static inline void pcie_device_rst_assert(int pcie_port)
- -{
- - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
- -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- -}
- -
- -static inline void pcie_device_rst_deassert(int pcie_port)
- -{
- - mdelay(100);
- - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
- -// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
- - //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
- -}
- -
- static inline void pcie_core_pmu_setup(int pcie_port)
- {
- struct clk *clk;
|