0151-lantiq-ifxmips_pcie-use-of.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. From 1d1885f4a7abd7272f47b835b03d8662fb981d19 Mon Sep 17 00:00:00 2001
  2. From: Eddi De Pieri <[email protected]>
  3. Date: Tue, 14 Oct 2014 11:04:00 +0000
  4. Subject: [PATCH] MIPS: lantiq: ifxmips_pcie: use of
  5. Signed-off-by: Eddi De Pieri <[email protected]>
  6. ---
  7. arch/mips/pci/Makefile | 2 +-
  8. arch/mips/pci/ifxmips_pcie.c | 151 +++++++++++++++++++++++++++----
  9. arch/mips/pci/ifxmips_pcie_vr9.h | 105 ---------------------
  10. 3 files changed, 133 insertions(+), 125 deletions(-)
  11. --- a/arch/mips/pci/Makefile
  12. +++ b/arch/mips/pci/Makefile
  13. @@ -43,7 +43,7 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
  14. obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
  15. obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
  16. obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
  17. -obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
  18. +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie.o fixup-lantiq-pcie.o
  19. obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
  20. obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
  21. obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
  22. --- a/arch/mips/pci/ifxmips_pcie.c
  23. +++ b/arch/mips/pci/ifxmips_pcie.c
  24. @@ -16,8 +16,15 @@
  25. #include <asm/paccess.h>
  26. #include <linux/pci.h>
  27. #include <linux/pci_regs.h>
  28. +#include <linux/phy/phy.h>
  29. +#include <linux/regmap.h>
  30. +#include <linux/reset.h>
  31. +#include <linux/mfd/syscon.h>
  32. #include <linux/module.h>
  33. +#include <linux/of_gpio.h>
  34. +#include <linux/of_platform.h>
  35. +
  36. #include "ifxmips_pcie.h"
  37. #include "ifxmips_pcie_reg.h"
  38. @@ -40,6 +47,11 @@
  39. static DEFINE_SPINLOCK(ifx_pcie_lock);
  40. u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
  41. +static int pcie_reset_gpio;
  42. +static struct phy *ltq_pcie_phy;
  43. +static struct reset_control *ltq_pcie_reset;
  44. +static struct regmap *ltq_rcu_regmap;
  45. +static bool switch_pcie_endianess;
  46. static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
  47. {
  48. @@ -82,6 +94,22 @@ void ifx_pcie_debug(const char *fmt, ...
  49. printk("%s", buf);
  50. }
  51. +static inline void pcie_ep_gpio_rst_init(int pcie_port)
  52. +{
  53. + gpio_direction_output(pcie_reset_gpio, 1);
  54. + gpio_set_value(pcie_reset_gpio, 1);
  55. +}
  56. +
  57. +static inline void pcie_device_rst_assert(int pcie_port)
  58. +{
  59. + gpio_set_value(pcie_reset_gpio, 0);
  60. +}
  61. +
  62. +static inline void pcie_device_rst_deassert(int pcie_port)
  63. +{
  64. + mdelay(100);
  65. + gpio_direction_output(pcie_reset_gpio, 1);
  66. +}
  67. static inline int pcie_ltssm_enable(int pcie_port)
  68. {
  69. @@ -988,10 +1016,26 @@ int ifx_pcie_bios_plat_dev_init(struct
  70. static int
  71. pcie_rc_initialize(int pcie_port)
  72. {
  73. - int i;
  74. + int i, ret;
  75. #define IFX_PCIE_PHY_LOOP_CNT 5
  76. - pcie_rcu_endian_setup(pcie_port);
  77. + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_M,
  78. + IFX_RCU_AHB_BE_PCIE_M);
  79. +
  80. +#ifdef CONFIG_IFX_PCIE_HW_SWAP
  81. + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
  82. + IFX_RCU_AHB_BE_PCIE_S);
  83. + if (switch_pcie_endianess) {
  84. + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_S,
  85. + IFX_RCU_AHB_BE_XBAR_S);
  86. + }
  87. +#else
  88. + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
  89. + 0x0);
  90. +#endif
  91. +
  92. + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
  93. + 0x0);
  94. pcie_ep_gpio_rst_init(pcie_port);
  95. @@ -1000,26 +1044,21 @@ pcie_rc_initialize(int pcie_port)
  96. * reset PCIe PHY will solve this issue
  97. */
  98. for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
  99. - /* Disable PCIe PHY Analog part for sanity check */
  100. - pcie_phy_pmu_disable(pcie_port);
  101. -
  102. - pcie_phy_rst_assert(pcie_port);
  103. - pcie_phy_rst_deassert(pcie_port);
  104. -
  105. - /* Make sure PHY PLL is stable */
  106. - udelay(20);
  107. -
  108. - /* PCIe Core reset enabled, low active, sw programmed */
  109. - pcie_core_rst_assert(pcie_port);
  110. + ret = phy_init(ltq_pcie_phy);
  111. + if (ret)
  112. + continue;
  113. /* Put PCIe EP in reset status */
  114. pcie_device_rst_assert(pcie_port);
  115. - /* PCI PHY & Core reset disabled, high active, sw programmed */
  116. - pcie_core_rst_deassert(pcie_port);
  117. + udelay(1);
  118. + reset_control_deassert(ltq_pcie_reset);
  119. - /* Already in a quiet state, program PLL, enable PHY, check ready bit */
  120. - pcie_phy_clock_mode_setup(pcie_port);
  121. + ret = phy_power_on(ltq_pcie_phy);
  122. + if (ret) {
  123. + phy_exit(ltq_pcie_phy);
  124. + continue;
  125. + }
  126. /* Enable PCIe PHY and Clock */
  127. pcie_core_pmu_setup(pcie_port);
  128. @@ -1035,6 +1074,10 @@ pcie_rc_initialize(int pcie_port)
  129. /* Once link is up, break out */
  130. if (pcie_app_loigc_setup(pcie_port) == 0)
  131. break;
  132. +
  133. + phy_power_off(ltq_pcie_phy);
  134. + reset_control_assert(ltq_pcie_reset);
  135. + phy_exit(ltq_pcie_phy);
  136. }
  137. if (i >= IFX_PCIE_PHY_LOOP_CNT) {
  138. printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
  139. @@ -1045,17 +1088,74 @@ pcie_rc_initialize(int pcie_port)
  140. return 0;
  141. }
  142. -static int __init ifx_pcie_bios_init(void)
  143. +static int ifx_pcie_bios_probe(struct platform_device *pdev)
  144. {
  145. + struct device_node *node = pdev->dev.of_node;
  146. void __iomem *io_map_base;
  147. int pcie_port;
  148. int startup_port;
  149. + struct device_node *np;
  150. + struct pci_bus *bus;
  151. +
  152. + /*
  153. + * In case a PCI device is physical present, the Lantiq PCI driver need
  154. + * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
  155. + * will work.
  156. + *
  157. + * In case the lantiq PCI driver is enabled in the device tree, check if
  158. + * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
  159. + * registered.
  160. + *
  161. + * It will fail if there is another PCI controller, this controller is
  162. + * registered before the Lantiq PCIe driver is probe and the lantiq PCI
  163. + */
  164. + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
  165. +
  166. + if (of_device_is_available(np)) {
  167. + bus = pci_find_next_bus(bus);
  168. +
  169. + if (!bus)
  170. + return -EPROBE_DEFER;
  171. + }
  172. /* Enable AHB Master/ Slave */
  173. pcie_ahb_pmu_setup();
  174. startup_port = IFX_PCIE_PORT0;
  175. -
  176. +
  177. + ltq_pcie_phy = devm_phy_get(&pdev->dev, "pcie");
  178. + if (IS_ERR(ltq_pcie_phy)) {
  179. + dev_err(&pdev->dev, "failed to get the PCIe PHY\n");
  180. + return PTR_ERR(ltq_pcie_phy);
  181. + }
  182. +
  183. + ltq_pcie_reset = devm_reset_control_get_shared(&pdev->dev, NULL);
  184. + if (IS_ERR(ltq_pcie_reset)) {
  185. + dev_err(&pdev->dev, "failed to get the PCIe reset line\n");
  186. + return PTR_ERR(ltq_pcie_reset);
  187. + }
  188. +
  189. + if (of_property_read_bool(node, "lantiq,switch-pcie-endianess")) {
  190. + switch_pcie_endianess = true;
  191. + dev_info(&pdev->dev, "switch pcie endianess requested\n");
  192. + } else {
  193. + switch_pcie_endianess = false;
  194. + }
  195. +
  196. + ltq_rcu_regmap = syscon_regmap_lookup_by_phandle(node, "lantiq,rcu");
  197. + if (IS_ERR(ltq_rcu_regmap))
  198. + return PTR_ERR(ltq_rcu_regmap);
  199. +
  200. + pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
  201. + if (gpio_is_valid(pcie_reset_gpio)) {
  202. + int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
  203. + if (ret) {
  204. + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
  205. + return ret;
  206. + }
  207. + gpio_direction_output(pcie_reset_gpio, 1);
  208. + }
  209. +
  210. for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
  211. if (pcie_rc_initialize(pcie_port) == 0) {
  212. IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
  213. @@ -1067,6 +1167,7 @@ static int __init ifx_pcie_bios_init(voi
  214. return -ENOMEM;
  215. }
  216. ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
  217. + pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
  218. register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
  219. /* XXX, clear error status */
  220. @@ -1083,6 +1184,30 @@ static int __init ifx_pcie_bios_init(voi
  221. return 0;
  222. }
  223. +
  224. +static const struct of_device_id ifxmips_pcie_match[] = {
  225. + { .compatible = "lantiq,pcie-xrx200" },
  226. + {},
  227. +};
  228. +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
  229. +
  230. +static struct platform_driver ltq_pci_driver = {
  231. + .probe = ifx_pcie_bios_probe,
  232. + .driver = {
  233. + .name = "pcie-xrx200",
  234. + .owner = THIS_MODULE,
  235. + .of_match_table = ifxmips_pcie_match,
  236. + },
  237. +};
  238. +
  239. +int __init ifx_pcie_bios_init(void)
  240. +{
  241. + int ret = platform_driver_register(&ltq_pci_driver);
  242. + if (ret)
  243. + pr_info("pcie-xrx200: Error registering platform driver!");
  244. + return ret;
  245. +}
  246. +
  247. arch_initcall(ifx_pcie_bios_init);
  248. MODULE_LICENSE("GPL");
  249. --- a/arch/mips/pci/ifxmips_pcie_vr9.h
  250. +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
  251. @@ -22,8 +22,6 @@
  252. #include <linux/gpio.h>
  253. #include <lantiq_soc.h>
  254. -#define IFX_PCIE_GPIO_RESET 494
  255. -
  256. #define IFX_REG_R32 ltq_r32
  257. #define IFX_REG_W32 ltq_w32
  258. #define CONFIG_IFX_PCIE_HW_SWAP
  259. @@ -54,21 +52,6 @@
  260. #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
  261. -static inline void pcie_ep_gpio_rst_init(int pcie_port)
  262. -{
  263. -
  264. - gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
  265. - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
  266. - gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
  267. -
  268. -/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  269. - ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  270. - ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  271. - ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  272. - ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  273. - ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
  274. -}
  275. -
  276. static inline void pcie_ahb_pmu_setup(void)
  277. {
  278. /* Enable AHB bus master/slave */
  279. @@ -80,24 +63,6 @@ static inline void pcie_ahb_pmu_setup(vo
  280. //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
  281. }
  282. -static inline void pcie_rcu_endian_setup(int pcie_port)
  283. -{
  284. - u32 reg;
  285. -
  286. - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
  287. -#ifdef CONFIG_IFX_PCIE_HW_SWAP
  288. - reg |= IFX_RCU_AHB_BE_PCIE_M;
  289. - reg |= IFX_RCU_AHB_BE_PCIE_S;
  290. - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
  291. -#else
  292. - reg |= IFX_RCU_AHB_BE_PCIE_M;
  293. - reg &= ~IFX_RCU_AHB_BE_PCIE_S;
  294. - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
  295. -#endif /* CONFIG_IFX_PCIE_HW_SWAP */
  296. - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
  297. - IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
  298. -}
  299. -
  300. static inline void pcie_phy_pmu_enable(int pcie_port)
  301. {
  302. struct clk *clk;
  303. @@ -116,17 +81,6 @@ static inline void pcie_phy_pmu_disable(
  304. // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
  305. }
  306. -static inline void pcie_pdi_big_endian(int pcie_port)
  307. -{
  308. - u32 reg;
  309. -
  310. - /* SRAM2PDI endianness control. */
  311. - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
  312. - /* Config AHB->PCIe and PDI endianness */
  313. - reg |= IFX_RCU_AHB_BE_PCIE_PDI;
  314. - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
  315. -}
  316. -
  317. static inline void pcie_pdi_pmu_enable(int pcie_port)
  318. {
  319. /* Enable PDI to access PCIe PHY register */
  320. @@ -136,65 +90,6 @@ static inline void pcie_pdi_pmu_enable(i
  321. //PDI_PMU_SETUP(IFX_PMU_ENABLE);
  322. }
  323. -static inline void pcie_core_rst_assert(int pcie_port)
  324. -{
  325. - u32 reg;
  326. -
  327. - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
  328. -
  329. - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
  330. - reg |= 0x00400000;
  331. - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
  332. -}
  333. -
  334. -static inline void pcie_core_rst_deassert(int pcie_port)
  335. -{
  336. - u32 reg;
  337. -
  338. - /* Make sure one micro-second delay */
  339. - udelay(1);
  340. -
  341. - /* Reset PCIe PHY & Core, bit 22 */
  342. - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
  343. - reg &= ~0x00400000;
  344. - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
  345. -}
  346. -
  347. -static inline void pcie_phy_rst_assert(int pcie_port)
  348. -{
  349. - u32 reg;
  350. -
  351. - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
  352. - reg |= 0x00001000; /* Bit 12 */
  353. - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
  354. -}
  355. -
  356. -static inline void pcie_phy_rst_deassert(int pcie_port)
  357. -{
  358. - u32 reg;
  359. -
  360. - /* Make sure one micro-second delay */
  361. - udelay(1);
  362. -
  363. - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
  364. - reg &= ~0x00001000; /* Bit 12 */
  365. - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
  366. -}
  367. -
  368. -static inline void pcie_device_rst_assert(int pcie_port)
  369. -{
  370. - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
  371. -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  372. -}
  373. -
  374. -static inline void pcie_device_rst_deassert(int pcie_port)
  375. -{
  376. - mdelay(100);
  377. - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
  378. -// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
  379. - //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
  380. -}
  381. -
  382. static inline void pcie_core_pmu_setup(int pcie_port)
  383. {
  384. struct clk *clk;