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

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