1 From 1d1885f4a7abd7272f47b835b03d8662fb981d19 Mon Sep 17 00:00:00 2001
2 From: Eddi De Pieri <eddi@depieri.net>
3 Date: Tue, 14 Oct 2014 11:04:00 +0000
4 Subject: [PATCH] MIPS: lantiq: ifxmips_pcie: use of
6 Signed-off-by: Eddi De Pieri <eddi@depieri.net>
8 arch/mips/pci/Makefile | 2 +-
9 arch/mips/pci/ifxmips_pcie.c | 151 +++++++++++++++++++++++++++----
10 arch/mips/pci/ifxmips_pcie_vr9.h | 105 ---------------------
11 3 files changed, 133 insertions(+), 125 deletions(-)
13 --- a/arch/mips/pci/Makefile
14 +++ b/arch/mips/pci/Makefile
15 @@ -43,7 +43,7 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
16 obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
17 obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
18 obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
19 -obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
20 +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie.o fixup-lantiq-pcie.o
21 obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
22 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
23 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
24 --- a/arch/mips/pci/ifxmips_pcie.c
25 +++ b/arch/mips/pci/ifxmips_pcie.c
27 #include <asm/paccess.h>
28 #include <linux/pci.h>
29 #include <linux/pci_regs.h>
30 +#include <linux/phy/phy.h>
31 +#include <linux/regmap.h>
32 +#include <linux/reset.h>
33 +#include <linux/mfd/syscon.h>
34 #include <linux/module.h>
36 +#include <linux/of_gpio.h>
37 +#include <linux/of_platform.h>
39 #include "ifxmips_pcie.h"
40 #include "ifxmips_pcie_reg.h"
43 static DEFINE_SPINLOCK(ifx_pcie_lock);
45 u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
46 +static int pcie_reset_gpio;
47 +static struct phy *ltq_pcie_phy;
48 +static struct reset_control *ltq_pcie_reset;
49 +static struct regmap *ltq_rcu_regmap;
51 static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
53 @@ -82,6 +93,22 @@ void ifx_pcie_debug(const char *fmt, ...
57 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
59 + gpio_direction_output(pcie_reset_gpio, 1);
60 + gpio_set_value(pcie_reset_gpio, 1);
63 +static inline void pcie_device_rst_assert(int pcie_port)
65 + gpio_set_value(pcie_reset_gpio, 0);
68 +static inline void pcie_device_rst_deassert(int pcie_port)
71 + gpio_direction_output(pcie_reset_gpio, 1);
74 static inline int pcie_ltssm_enable(int pcie_port)
76 @@ -988,10 +1015,22 @@ int ifx_pcie_bios_plat_dev_init(struct
78 pcie_rc_initialize(int pcie_port)
82 #define IFX_PCIE_PHY_LOOP_CNT 5
84 - pcie_rcu_endian_setup(pcie_port);
85 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_M,
86 + IFX_RCU_AHB_BE_PCIE_M);
88 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
89 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
90 + IFX_RCU_AHB_BE_PCIE_S);
92 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
96 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
99 pcie_ep_gpio_rst_init(pcie_port);
101 @@ -1000,26 +1039,21 @@ pcie_rc_initialize(int pcie_port)
102 * reset PCIe PHY will solve this issue
104 for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
105 - /* Disable PCIe PHY Analog part for sanity check */
106 - pcie_phy_pmu_disable(pcie_port);
108 - pcie_phy_rst_assert(pcie_port);
109 - pcie_phy_rst_deassert(pcie_port);
111 - /* Make sure PHY PLL is stable */
114 - /* PCIe Core reset enabled, low active, sw programmed */
115 - pcie_core_rst_assert(pcie_port);
116 + ret = phy_init(ltq_pcie_phy);
120 /* Put PCIe EP in reset status */
121 pcie_device_rst_assert(pcie_port);
123 - /* PCI PHY & Core reset disabled, high active, sw programmed */
124 - pcie_core_rst_deassert(pcie_port);
126 + reset_control_deassert(ltq_pcie_reset);
128 - /* Already in a quiet state, program PLL, enable PHY, check ready bit */
129 - pcie_phy_clock_mode_setup(pcie_port);
130 + ret = phy_power_on(ltq_pcie_phy);
132 + phy_exit(ltq_pcie_phy);
136 /* Enable PCIe PHY and Clock */
137 pcie_core_pmu_setup(pcie_port);
138 @@ -1035,6 +1069,10 @@ pcie_rc_initialize(int pcie_port)
139 /* Once link is up, break out */
140 if (pcie_app_loigc_setup(pcie_port) == 0)
143 + phy_power_off(ltq_pcie_phy);
144 + reset_control_assert(ltq_pcie_reset);
145 + phy_exit(ltq_pcie_phy);
147 if (i >= IFX_PCIE_PHY_LOOP_CNT) {
148 printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
149 @@ -1045,17 +1083,67 @@ pcie_rc_initialize(int pcie_port)
153 -static int __init ifx_pcie_bios_init(void)
154 +static int ifx_pcie_bios_probe(struct platform_device *pdev)
156 + struct device_node *node = pdev->dev.of_node;
157 void __iomem *io_map_base;
160 + struct device_node *np;
161 + struct pci_bus *bus;
164 + * In case a PCI device is physical present, the Lantiq PCI driver need
165 + * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
168 + * In case the lantiq PCI driver is enabled in the device tree, check if
169 + * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
172 + * It will fail if there is another PCI controller, this controller is
173 + * registered before the Lantiq PCIe driver is probe and the lantiq PCI
175 + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
177 + if (of_device_is_available(np)) {
178 + bus = pci_find_next_bus(bus);
181 + return -EPROBE_DEFER;
184 /* Enable AHB Master/ Slave */
185 pcie_ahb_pmu_setup();
187 startup_port = IFX_PCIE_PORT0;
190 + ltq_pcie_phy = devm_phy_get(&pdev->dev, "pcie");
191 + if (IS_ERR(ltq_pcie_phy)) {
192 + dev_err(&pdev->dev, "failed to get the PCIe PHY\n");
193 + return PTR_ERR(ltq_pcie_phy);
196 + ltq_pcie_reset = devm_reset_control_get_shared(&pdev->dev, NULL);
197 + if (IS_ERR(ltq_pcie_reset)) {
198 + dev_err(&pdev->dev, "failed to get the PCIe reset line\n");
199 + return PTR_ERR(ltq_pcie_reset);
202 + ltq_rcu_regmap = syscon_regmap_lookup_by_phandle(node, "lantiq,rcu");
203 + if (IS_ERR(ltq_rcu_regmap))
204 + return PTR_ERR(ltq_rcu_regmap);
206 + pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
207 + if (gpio_is_valid(pcie_reset_gpio)) {
208 + int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
210 + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
213 + gpio_direction_output(pcie_reset_gpio, 1);
216 for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
217 if (pcie_rc_initialize(pcie_port) == 0) {
218 IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
219 @@ -1067,6 +1155,7 @@ static int __init ifx_pcie_bios_init(voi
222 ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
223 + pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
225 register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
226 /* XXX, clear error status */
227 @@ -1083,6 +1172,30 @@ static int __init ifx_pcie_bios_init(voi
232 +static const struct of_device_id ifxmips_pcie_match[] = {
233 + { .compatible = "lantiq,pcie-xrx200" },
236 +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
238 +static struct platform_driver ltq_pci_driver = {
239 + .probe = ifx_pcie_bios_probe,
241 + .name = "pcie-xrx200",
242 + .owner = THIS_MODULE,
243 + .of_match_table = ifxmips_pcie_match,
247 +int __init ifx_pcie_bios_init(void)
249 + int ret = platform_driver_register(<q_pci_driver);
251 + pr_info("pcie-xrx200: Error registering platform driver!");
255 arch_initcall(ifx_pcie_bios_init);
257 MODULE_LICENSE("GPL");
258 --- a/arch/mips/pci/ifxmips_pcie_vr9.h
259 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
261 #include <linux/gpio.h>
262 #include <lantiq_soc.h>
264 -#define IFX_PCIE_GPIO_RESET 494
266 #define IFX_REG_R32 ltq_r32
267 #define IFX_REG_W32 ltq_w32
268 #define CONFIG_IFX_PCIE_HW_SWAP
270 #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
273 -static inline void pcie_ep_gpio_rst_init(int pcie_port)
276 - gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
277 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
278 - gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
280 -/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
281 - ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
282 - ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
283 - ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
284 - ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
285 - ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
288 static inline void pcie_ahb_pmu_setup(void)
290 /* Enable AHB bus master/slave */
291 @@ -79,24 +62,6 @@ static inline void pcie_ahb_pmu_setup(vo
292 //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
295 -static inline void pcie_rcu_endian_setup(int pcie_port)
299 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
300 -#ifdef CONFIG_IFX_PCIE_HW_SWAP
301 - reg |= IFX_RCU_AHB_BE_PCIE_M;
302 - reg |= IFX_RCU_AHB_BE_PCIE_S;
303 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
305 - reg |= IFX_RCU_AHB_BE_PCIE_M;
306 - reg &= ~IFX_RCU_AHB_BE_PCIE_S;
307 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
308 -#endif /* CONFIG_IFX_PCIE_HW_SWAP */
309 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
310 - IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
313 static inline void pcie_phy_pmu_enable(int pcie_port)
316 @@ -115,17 +80,6 @@ static inline void pcie_phy_pmu_disable(
317 // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
320 -static inline void pcie_pdi_big_endian(int pcie_port)
324 - /* SRAM2PDI endianness control. */
325 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
326 - /* Config AHB->PCIe and PDI endianness */
327 - reg |= IFX_RCU_AHB_BE_PCIE_PDI;
328 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
331 static inline void pcie_pdi_pmu_enable(int pcie_port)
333 /* Enable PDI to access PCIe PHY register */
334 @@ -135,65 +89,6 @@ static inline void pcie_pdi_pmu_enable(i
335 //PDI_PMU_SETUP(IFX_PMU_ENABLE);
338 -static inline void pcie_core_rst_assert(int pcie_port)
342 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
344 - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
346 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
349 -static inline void pcie_core_rst_deassert(int pcie_port)
353 - /* Make sure one micro-second delay */
356 - /* Reset PCIe PHY & Core, bit 22 */
357 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
358 - reg &= ~0x00400000;
359 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
362 -static inline void pcie_phy_rst_assert(int pcie_port)
366 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
367 - reg |= 0x00001000; /* Bit 12 */
368 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
371 -static inline void pcie_phy_rst_deassert(int pcie_port)
375 - /* Make sure one micro-second delay */
378 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
379 - reg &= ~0x00001000; /* Bit 12 */
380 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
383 -static inline void pcie_device_rst_assert(int pcie_port)
385 - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
386 -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
389 -static inline void pcie_device_rst_deassert(int pcie_port)
392 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
393 -// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
394 - //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
397 static inline void pcie_core_pmu_setup(int pcie_port)