pcie-tegra194.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PCIe host controller driver for the following SoCs
  4. * Tegra194
  5. * Tegra234
  6. *
  7. * Copyright (C) 2019-2022 NVIDIA Corporation.
  8. *
  9. * Author: Vidya Sagar <vidyas@nvidia.com>
  10. */
  11. #include <linux/bitfield.h>
  12. #include <linux/clk.h>
  13. #include <linux/debugfs.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio/consumer.h>
  16. #include <linux/interconnect.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/iopoll.h>
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/of_pci.h>
  23. #include <linux/pci.h>
  24. #include <linux/phy/phy.h>
  25. #include <linux/pinctrl/consumer.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/random.h>
  29. #include <linux/reset.h>
  30. #include <linux/resource.h>
  31. #include <linux/types.h>
  32. #include "pcie-designware.h"
  33. #include <soc/tegra/bpmp.h>
  34. #include <soc/tegra/bpmp-abi.h>
  35. #include "../../pci.h"
  36. #define TEGRA194_DWC_IP_VER 0x490A
  37. #define TEGRA234_DWC_IP_VER 0x562A
  38. #define APPL_PINMUX 0x0
  39. #define APPL_PINMUX_PEX_RST BIT(0)
  40. #define APPL_PINMUX_CLKREQ_OVERRIDE_EN BIT(2)
  41. #define APPL_PINMUX_CLKREQ_OVERRIDE BIT(3)
  42. #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN BIT(4)
  43. #define APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE BIT(5)
  44. #define APPL_CTRL 0x4
  45. #define APPL_CTRL_SYS_PRE_DET_STATE BIT(6)
  46. #define APPL_CTRL_LTSSM_EN BIT(7)
  47. #define APPL_CTRL_HW_HOT_RST_EN BIT(20)
  48. #define APPL_CTRL_HW_HOT_RST_MODE_MASK GENMASK(1, 0)
  49. #define APPL_CTRL_HW_HOT_RST_MODE_SHIFT 22
  50. #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST 0x1
  51. #define APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN 0x2
  52. #define APPL_INTR_EN_L0_0 0x8
  53. #define APPL_INTR_EN_L0_0_LINK_STATE_INT_EN BIT(0)
  54. #define APPL_INTR_EN_L0_0_MSI_RCV_INT_EN BIT(4)
  55. #define APPL_INTR_EN_L0_0_INT_INT_EN BIT(8)
  56. #define APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN BIT(15)
  57. #define APPL_INTR_EN_L0_0_CDM_REG_CHK_INT_EN BIT(19)
  58. #define APPL_INTR_EN_L0_0_SYS_INTR_EN BIT(30)
  59. #define APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN BIT(31)
  60. #define APPL_INTR_STATUS_L0 0xC
  61. #define APPL_INTR_STATUS_L0_LINK_STATE_INT BIT(0)
  62. #define APPL_INTR_STATUS_L0_INT_INT BIT(8)
  63. #define APPL_INTR_STATUS_L0_PCI_CMD_EN_INT BIT(15)
  64. #define APPL_INTR_STATUS_L0_PEX_RST_INT BIT(16)
  65. #define APPL_INTR_STATUS_L0_CDM_REG_CHK_INT BIT(18)
  66. #define APPL_INTR_EN_L1_0_0 0x1C
  67. #define APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN BIT(1)
  68. #define APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN BIT(3)
  69. #define APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN BIT(30)
  70. #define APPL_INTR_STATUS_L1_0_0 0x20
  71. #define APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED BIT(1)
  72. #define APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED BIT(3)
  73. #define APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE BIT(30)
  74. #define APPL_INTR_STATUS_L1_1 0x2C
  75. #define APPL_INTR_STATUS_L1_2 0x30
  76. #define APPL_INTR_STATUS_L1_3 0x34
  77. #define APPL_INTR_STATUS_L1_6 0x3C
  78. #define APPL_INTR_STATUS_L1_7 0x40
  79. #define APPL_INTR_STATUS_L1_15_CFG_BME_CHGED BIT(1)
  80. #define APPL_INTR_EN_L1_8_0 0x44
  81. #define APPL_INTR_EN_L1_8_BW_MGT_INT_EN BIT(2)
  82. #define APPL_INTR_EN_L1_8_AUTO_BW_INT_EN BIT(3)
  83. #define APPL_INTR_EN_L1_8_INTX_EN BIT(11)
  84. #define APPL_INTR_EN_L1_8_AER_INT_EN BIT(15)
  85. #define APPL_INTR_STATUS_L1_8_0 0x4C
  86. #define APPL_INTR_STATUS_L1_8_0_EDMA_INT_MASK GENMASK(11, 6)
  87. #define APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS BIT(2)
  88. #define APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS BIT(3)
  89. #define APPL_INTR_STATUS_L1_9 0x54
  90. #define APPL_INTR_STATUS_L1_10 0x58
  91. #define APPL_INTR_STATUS_L1_11 0x64
  92. #define APPL_INTR_STATUS_L1_13 0x74
  93. #define APPL_INTR_STATUS_L1_14 0x78
  94. #define APPL_INTR_STATUS_L1_15 0x7C
  95. #define APPL_INTR_STATUS_L1_17 0x88
  96. #define APPL_INTR_EN_L1_18 0x90
  97. #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMPLT BIT(2)
  98. #define APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
  99. #define APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
  100. #define APPL_INTR_STATUS_L1_18 0x94
  101. #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT BIT(2)
  102. #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR BIT(1)
  103. #define APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR BIT(0)
  104. #define APPL_MSI_CTRL_1 0xAC
  105. #define APPL_MSI_CTRL_2 0xB0
  106. #define APPL_LEGACY_INTX 0xB8
  107. #define APPL_LTR_MSG_1 0xC4
  108. #define LTR_MSG_REQ BIT(15)
  109. #define LTR_NOSNOOP_MSG_REQ BIT(31)
  110. #define APPL_LTR_MSG_2 0xC8
  111. #define APPL_LTR_MSG_2_LTR_MSG_REQ_STATE BIT(3)
  112. #define APPL_LINK_STATUS 0xCC
  113. #define APPL_LINK_STATUS_RDLH_LINK_UP BIT(0)
  114. #define APPL_DEBUG 0xD0
  115. #define APPL_DEBUG_PM_LINKST_IN_L2_LAT BIT(21)
  116. #define APPL_DEBUG_PM_LINKST_IN_L0 0x11
  117. #define APPL_DEBUG_LTSSM_STATE_MASK GENMASK(8, 3)
  118. #define APPL_DEBUG_LTSSM_STATE_SHIFT 3
  119. #define LTSSM_STATE_PRE_DETECT 5
  120. #define APPL_RADM_STATUS 0xE4
  121. #define APPL_PM_XMT_TURNOFF_STATE BIT(0)
  122. #define APPL_DM_TYPE 0x100
  123. #define APPL_DM_TYPE_MASK GENMASK(3, 0)
  124. #define APPL_DM_TYPE_RP 0x4
  125. #define APPL_DM_TYPE_EP 0x0
  126. #define APPL_CFG_BASE_ADDR 0x104
  127. #define APPL_CFG_BASE_ADDR_MASK GENMASK(31, 12)
  128. #define APPL_CFG_IATU_DMA_BASE_ADDR 0x108
  129. #define APPL_CFG_IATU_DMA_BASE_ADDR_MASK GENMASK(31, 18)
  130. #define APPL_CFG_MISC 0x110
  131. #define APPL_CFG_MISC_SLV_EP_MODE BIT(14)
  132. #define APPL_CFG_MISC_ARCACHE_MASK GENMASK(13, 10)
  133. #define APPL_CFG_MISC_ARCACHE_SHIFT 10
  134. #define APPL_CFG_MISC_ARCACHE_VAL 3
  135. #define APPL_CFG_SLCG_OVERRIDE 0x114
  136. #define APPL_CFG_SLCG_OVERRIDE_SLCG_EN_MASTER BIT(0)
  137. #define APPL_CAR_RESET_OVRD 0x12C
  138. #define APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N BIT(0)
  139. #define IO_BASE_IO_DECODE BIT(0)
  140. #define IO_BASE_IO_DECODE_BIT8 BIT(8)
  141. #define CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE BIT(0)
  142. #define CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE BIT(16)
  143. #define CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF 0x718
  144. #define CFG_TIMER_CTRL_ACK_NAK_SHIFT (19)
  145. #define N_FTS_VAL 52
  146. #define FTS_VAL 52
  147. #define PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT 0x8D0
  148. #define AMBA_ERROR_RESPONSE_RRS_SHIFT 3
  149. #define AMBA_ERROR_RESPONSE_RRS_MASK GENMASK(1, 0)
  150. #define AMBA_ERROR_RESPONSE_RRS_OKAY 0
  151. #define AMBA_ERROR_RESPONSE_RRS_OKAY_FFFFFFFF 1
  152. #define AMBA_ERROR_RESPONSE_RRS_OKAY_FFFF0001 2
  153. #define MSIX_ADDR_MATCH_LOW_OFF 0x940
  154. #define MSIX_ADDR_MATCH_LOW_OFF_EN BIT(0)
  155. #define MSIX_ADDR_MATCH_LOW_OFF_MASK GENMASK(31, 2)
  156. #define MSIX_ADDR_MATCH_HIGH_OFF 0x944
  157. #define MSIX_ADDR_MATCH_HIGH_OFF_MASK GENMASK(31, 0)
  158. #define PORT_LOGIC_MSIX_DOORBELL 0x948
  159. #define CAP_SPCIE_CAP_OFF 0x154
  160. #define CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK GENMASK(3, 0)
  161. #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK GENMASK(11, 8)
  162. #define CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT 8
  163. #define PME_ACK_TIMEOUT 10000
  164. #define LTSSM_TIMEOUT 50000 /* 50ms */
  165. #define GEN3_GEN4_EQ_PRESET_INIT 5
  166. #define GEN1_CORE_CLK_FREQ 62500000
  167. #define GEN2_CORE_CLK_FREQ 125000000
  168. #define GEN3_CORE_CLK_FREQ 250000000
  169. #define GEN4_CORE_CLK_FREQ 500000000
  170. #define LTR_MSG_TIMEOUT (100 * 1000)
  171. #define PERST_DEBOUNCE_TIME (5 * 1000)
  172. #define EP_STATE_DISABLED 0
  173. #define EP_STATE_ENABLED 1
  174. static const unsigned int pcie_gen_freq[] = {
  175. GEN1_CORE_CLK_FREQ, /* PCI_EXP_LNKSTA_CLS == 0; undefined */
  176. GEN1_CORE_CLK_FREQ,
  177. GEN2_CORE_CLK_FREQ,
  178. GEN3_CORE_CLK_FREQ,
  179. GEN4_CORE_CLK_FREQ
  180. };
  181. struct tegra_pcie_dw_of_data {
  182. u32 version;
  183. enum dw_pcie_device_mode mode;
  184. bool has_msix_doorbell_access_fix;
  185. bool has_sbr_reset_fix;
  186. bool has_l1ss_exit_fix;
  187. bool has_ltr_req_fix;
  188. u32 cdm_chk_int_en_bit;
  189. u32 gen4_preset_vec;
  190. u8 n_fts[2];
  191. };
  192. struct tegra_pcie_dw {
  193. struct device *dev;
  194. struct resource *appl_res;
  195. struct resource *dbi_res;
  196. struct resource *atu_dma_res;
  197. void __iomem *appl_base;
  198. struct clk *core_clk;
  199. struct reset_control *core_apb_rst;
  200. struct reset_control *core_rst;
  201. struct dw_pcie pci;
  202. struct tegra_bpmp *bpmp;
  203. struct tegra_pcie_dw_of_data *of_data;
  204. bool supports_clkreq;
  205. bool enable_cdm_check;
  206. bool enable_srns;
  207. bool link_state;
  208. bool update_fc_fixup;
  209. bool enable_ext_refclk;
  210. u8 init_link_width;
  211. u32 msi_ctrl_int;
  212. u32 num_lanes;
  213. u32 cid;
  214. u32 ras_des_cap;
  215. u32 pcie_cap_base;
  216. u32 aspm_cmrt;
  217. u32 aspm_pwr_on_t;
  218. u32 aspm_l0s_enter_lat;
  219. struct regulator *pex_ctl_supply;
  220. struct regulator *slot_ctl_3v3;
  221. struct regulator *slot_ctl_12v;
  222. unsigned int phy_count;
  223. struct phy **phys;
  224. struct dentry *debugfs;
  225. /* Endpoint mode specific */
  226. struct gpio_desc *pex_rst_gpiod;
  227. struct gpio_desc *pex_refclk_sel_gpiod;
  228. unsigned int pex_rst_irq;
  229. int ep_state;
  230. long link_status;
  231. struct icc_path *icc_path;
  232. };
  233. static inline struct tegra_pcie_dw *to_tegra_pcie(struct dw_pcie *pci)
  234. {
  235. return container_of(pci, struct tegra_pcie_dw, pci);
  236. }
  237. static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value,
  238. const u32 reg)
  239. {
  240. writel_relaxed(value, pcie->appl_base + reg);
  241. }
  242. static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg)
  243. {
  244. return readl_relaxed(pcie->appl_base + reg);
  245. }
  246. static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie)
  247. {
  248. struct dw_pcie *pci = &pcie->pci;
  249. u32 val, speed, width;
  250. val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
  251. speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
  252. width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
  253. val = width * PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]);
  254. if (icc_set_bw(pcie->icc_path, Mbps_to_icc(val), 0))
  255. dev_err(pcie->dev, "can't set bw[%u]\n", val);
  256. if (speed >= ARRAY_SIZE(pcie_gen_freq))
  257. speed = 0;
  258. clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
  259. }
  260. static void apply_bad_link_workaround(struct dw_pcie_rp *pp)
  261. {
  262. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  263. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  264. u32 current_link_width;
  265. u16 val;
  266. /*
  267. * NOTE:- Since this scenario is uncommon and link as such is not
  268. * stable anyway, not waiting to confirm if link is really
  269. * transitioning to Gen-2 speed
  270. */
  271. val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
  272. if (val & PCI_EXP_LNKSTA_LBMS) {
  273. current_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
  274. if (pcie->init_link_width > current_link_width) {
  275. dev_warn(pci->dev, "PCIe link is bad, width reduced\n");
  276. val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  277. PCI_EXP_LNKCTL2);
  278. val &= ~PCI_EXP_LNKCTL2_TLS;
  279. val |= PCI_EXP_LNKCTL2_TLS_2_5GT;
  280. dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
  281. PCI_EXP_LNKCTL2, val);
  282. val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  283. PCI_EXP_LNKCTL);
  284. val |= PCI_EXP_LNKCTL_RL;
  285. dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
  286. PCI_EXP_LNKCTL, val);
  287. }
  288. }
  289. }
  290. static irqreturn_t tegra_pcie_rp_irq_handler(int irq, void *arg)
  291. {
  292. struct tegra_pcie_dw *pcie = arg;
  293. struct dw_pcie *pci = &pcie->pci;
  294. struct dw_pcie_rp *pp = &pci->pp;
  295. u32 val, status_l0, status_l1;
  296. u16 val_w;
  297. status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
  298. if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
  299. status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
  300. appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
  301. if (!pcie->of_data->has_sbr_reset_fix &&
  302. status_l1 & APPL_INTR_STATUS_L1_0_0_LINK_REQ_RST_NOT_CHGED) {
  303. /* SBR & Surprise Link Down WAR */
  304. val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
  305. val &= ~APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
  306. appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
  307. udelay(1);
  308. val = appl_readl(pcie, APPL_CAR_RESET_OVRD);
  309. val |= APPL_CAR_RESET_OVRD_CYA_OVERRIDE_CORE_RST_N;
  310. appl_writel(pcie, val, APPL_CAR_RESET_OVRD);
  311. val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
  312. val |= PORT_LOGIC_SPEED_CHANGE;
  313. dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
  314. }
  315. }
  316. if (status_l0 & APPL_INTR_STATUS_L0_INT_INT) {
  317. status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0);
  318. if (status_l1 & APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS) {
  319. appl_writel(pcie,
  320. APPL_INTR_STATUS_L1_8_0_AUTO_BW_INT_STS,
  321. APPL_INTR_STATUS_L1_8_0);
  322. apply_bad_link_workaround(pp);
  323. }
  324. if (status_l1 & APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS) {
  325. val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  326. PCI_EXP_LNKSTA);
  327. val_w |= PCI_EXP_LNKSTA_LBMS;
  328. dw_pcie_writew_dbi(pci, pcie->pcie_cap_base +
  329. PCI_EXP_LNKSTA, val_w);
  330. appl_writel(pcie,
  331. APPL_INTR_STATUS_L1_8_0_BW_MGT_INT_STS,
  332. APPL_INTR_STATUS_L1_8_0);
  333. val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  334. PCI_EXP_LNKSTA);
  335. dev_dbg(pci->dev, "Link Speed : Gen-%u\n", val_w &
  336. PCI_EXP_LNKSTA_CLS);
  337. }
  338. }
  339. if (status_l0 & APPL_INTR_STATUS_L0_CDM_REG_CHK_INT) {
  340. status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_18);
  341. val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS);
  342. if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMPLT) {
  343. dev_info(pci->dev, "CDM check complete\n");
  344. val |= PCIE_PL_CHK_REG_CHK_REG_COMPLETE;
  345. }
  346. if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_CMP_ERR) {
  347. dev_err(pci->dev, "CDM comparison mismatch\n");
  348. val |= PCIE_PL_CHK_REG_CHK_REG_COMPARISON_ERROR;
  349. }
  350. if (status_l1 & APPL_INTR_STATUS_L1_18_CDM_REG_CHK_LOGIC_ERR) {
  351. dev_err(pci->dev, "CDM Logic error\n");
  352. val |= PCIE_PL_CHK_REG_CHK_REG_LOGIC_ERROR;
  353. }
  354. dw_pcie_writel_dbi(pci, PCIE_PL_CHK_REG_CONTROL_STATUS, val);
  355. val = dw_pcie_readl_dbi(pci, PCIE_PL_CHK_REG_ERR_ADDR);
  356. dev_err(pci->dev, "CDM Error Address Offset = 0x%08X\n", val);
  357. }
  358. return IRQ_HANDLED;
  359. }
  360. static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie)
  361. {
  362. u32 val;
  363. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
  364. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
  365. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
  366. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
  367. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
  368. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
  369. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
  370. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
  371. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
  372. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
  373. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
  374. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
  375. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
  376. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
  377. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
  378. appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2);
  379. val = appl_readl(pcie, APPL_CTRL);
  380. val |= APPL_CTRL_LTSSM_EN;
  381. appl_writel(pcie, val, APPL_CTRL);
  382. }
  383. static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
  384. {
  385. struct tegra_pcie_dw *pcie = arg;
  386. struct dw_pcie_ep *ep = &pcie->pci.ep;
  387. struct dw_pcie *pci = &pcie->pci;
  388. u32 val;
  389. if (test_and_clear_bit(0, &pcie->link_status))
  390. dw_pcie_ep_linkup(ep);
  391. tegra_pcie_icc_set(pcie);
  392. if (pcie->of_data->has_ltr_req_fix)
  393. return IRQ_HANDLED;
  394. /* If EP doesn't advertise L1SS, just return */
  395. if (!pci->l1ss_support)
  396. return IRQ_HANDLED;
  397. /* Check if BME is set to '1' */
  398. val = dw_pcie_readl_dbi(pci, PCI_COMMAND);
  399. if (val & PCI_COMMAND_MASTER) {
  400. ktime_t timeout;
  401. /* 110us for both snoop and no-snoop */
  402. val = FIELD_PREP(PCI_LTR_VALUE_MASK, 110) |
  403. FIELD_PREP(PCI_LTR_SCALE_MASK, 2) |
  404. LTR_MSG_REQ |
  405. FIELD_PREP(PCI_LTR_NOSNOOP_VALUE, 110) |
  406. FIELD_PREP(PCI_LTR_NOSNOOP_SCALE, 2) |
  407. LTR_NOSNOOP_MSG_REQ;
  408. appl_writel(pcie, val, APPL_LTR_MSG_1);
  409. /* Send LTR upstream */
  410. val = appl_readl(pcie, APPL_LTR_MSG_2);
  411. val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
  412. appl_writel(pcie, val, APPL_LTR_MSG_2);
  413. timeout = ktime_add_us(ktime_get(), LTR_MSG_TIMEOUT);
  414. for (;;) {
  415. val = appl_readl(pcie, APPL_LTR_MSG_2);
  416. if (!(val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE))
  417. break;
  418. if (ktime_after(ktime_get(), timeout))
  419. break;
  420. usleep_range(1000, 1100);
  421. }
  422. if (val & APPL_LTR_MSG_2_LTR_MSG_REQ_STATE)
  423. dev_err(pcie->dev, "Failed to send LTR message\n");
  424. }
  425. return IRQ_HANDLED;
  426. }
  427. static irqreturn_t tegra_pcie_ep_hard_irq(int irq, void *arg)
  428. {
  429. struct tegra_pcie_dw *pcie = arg;
  430. int spurious = 1;
  431. u32 status_l0, status_l1, link_status;
  432. status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0);
  433. if (status_l0 & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
  434. status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
  435. appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0);
  436. if (status_l1 & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE)
  437. pex_ep_event_hot_rst_done(pcie);
  438. if (status_l1 & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
  439. link_status = appl_readl(pcie, APPL_LINK_STATUS);
  440. if (link_status & APPL_LINK_STATUS_RDLH_LINK_UP) {
  441. dev_dbg(pcie->dev, "Link is up with Host\n");
  442. set_bit(0, &pcie->link_status);
  443. return IRQ_WAKE_THREAD;
  444. }
  445. }
  446. spurious = 0;
  447. }
  448. if (status_l0 & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
  449. status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
  450. appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15);
  451. if (status_l1 & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED)
  452. return IRQ_WAKE_THREAD;
  453. spurious = 0;
  454. }
  455. if (spurious) {
  456. dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
  457. status_l0);
  458. appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0);
  459. }
  460. return IRQ_HANDLED;
  461. }
  462. static int tegra_pcie_dw_rd_own_conf(struct pci_bus *bus, u32 devfn, int where,
  463. int size, u32 *val)
  464. {
  465. struct dw_pcie_rp *pp = bus->sysdata;
  466. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  467. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  468. /*
  469. * This is an endpoint mode specific register happen to appear even
  470. * when controller is operating in root port mode and system hangs
  471. * when it is accessed with link being in ASPM-L1 state.
  472. * So skip accessing it altogether
  473. */
  474. if (!pcie->of_data->has_msix_doorbell_access_fix &&
  475. !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL) {
  476. *val = 0x00000000;
  477. return PCIBIOS_SUCCESSFUL;
  478. }
  479. return pci_generic_config_read(bus, devfn, where, size, val);
  480. }
  481. static int tegra_pcie_dw_wr_own_conf(struct pci_bus *bus, u32 devfn, int where,
  482. int size, u32 val)
  483. {
  484. struct dw_pcie_rp *pp = bus->sysdata;
  485. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  486. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  487. /*
  488. * This is an endpoint mode specific register happen to appear even
  489. * when controller is operating in root port mode and system hangs
  490. * when it is accessed with link being in ASPM-L1 state.
  491. * So skip accessing it altogether
  492. */
  493. if (!pcie->of_data->has_msix_doorbell_access_fix &&
  494. !PCI_SLOT(devfn) && where == PORT_LOGIC_MSIX_DOORBELL)
  495. return PCIBIOS_SUCCESSFUL;
  496. return pci_generic_config_write(bus, devfn, where, size, val);
  497. }
  498. static struct pci_ops tegra_pci_ops = {
  499. .map_bus = dw_pcie_own_conf_map_bus,
  500. .read = tegra_pcie_dw_rd_own_conf,
  501. .write = tegra_pcie_dw_wr_own_conf,
  502. };
  503. #if defined(CONFIG_PCIEASPM)
  504. static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event)
  505. {
  506. u32 val;
  507. val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
  508. PCIE_RAS_DES_EVENT_COUNTER_CONTROL);
  509. val &= ~(EVENT_COUNTER_EVENT_SEL_MASK << EVENT_COUNTER_EVENT_SEL_SHIFT);
  510. val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
  511. val |= event << EVENT_COUNTER_EVENT_SEL_SHIFT;
  512. val |= EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
  513. dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
  514. PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
  515. val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
  516. PCIE_RAS_DES_EVENT_COUNTER_DATA);
  517. return val;
  518. }
  519. static int aspm_state_cnt(struct seq_file *s, void *data)
  520. {
  521. struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *)
  522. dev_get_drvdata(s->private);
  523. u32 val;
  524. seq_printf(s, "Tx L0s entry count : %u\n",
  525. event_counter_prog(pcie, EVENT_COUNTER_EVENT_Tx_L0S));
  526. seq_printf(s, "Rx L0s entry count : %u\n",
  527. event_counter_prog(pcie, EVENT_COUNTER_EVENT_Rx_L0S));
  528. seq_printf(s, "Link L1 entry count : %u\n",
  529. event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1));
  530. seq_printf(s, "Link L1.1 entry count : %u\n",
  531. event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_1));
  532. seq_printf(s, "Link L1.2 entry count : %u\n",
  533. event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2));
  534. /* Clear all counters */
  535. dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
  536. PCIE_RAS_DES_EVENT_COUNTER_CONTROL,
  537. EVENT_COUNTER_ALL_CLEAR);
  538. /* Re-enable counting */
  539. val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
  540. val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
  541. dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
  542. PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
  543. return 0;
  544. }
  545. static void init_host_aspm(struct tegra_pcie_dw *pcie)
  546. {
  547. struct dw_pcie *pci = &pcie->pci;
  548. u32 l1ss, val;
  549. l1ss = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_L1SS);
  550. pcie->ras_des_cap = dw_pcie_find_ext_capability(&pcie->pci,
  551. PCI_EXT_CAP_ID_VNDR);
  552. /* Enable ASPM counters */
  553. val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
  554. val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
  555. dw_pcie_writel_dbi(pci, pcie->ras_des_cap +
  556. PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
  557. /* Program T_cmrt and T_pwr_on values */
  558. val = dw_pcie_readl_dbi(pci, l1ss + PCI_L1SS_CAP);
  559. val &= ~(PCI_L1SS_CAP_CM_RESTORE_TIME | PCI_L1SS_CAP_P_PWR_ON_VALUE);
  560. val |= (pcie->aspm_cmrt << 8);
  561. val |= (pcie->aspm_pwr_on_t << 19);
  562. dw_pcie_writel_dbi(pci, l1ss + PCI_L1SS_CAP, val);
  563. if (pcie->supports_clkreq)
  564. pci->l1ss_support = true;
  565. /* Program L0s and L1 entrance latencies */
  566. val = dw_pcie_readl_dbi(pci, PCIE_PORT_AFR);
  567. val &= ~PORT_AFR_L0S_ENTRANCE_LAT_MASK;
  568. val |= (pcie->aspm_l0s_enter_lat << PORT_AFR_L0S_ENTRANCE_LAT_SHIFT);
  569. val |= PORT_AFR_ENTER_ASPM;
  570. dw_pcie_writel_dbi(pci, PCIE_PORT_AFR, val);
  571. }
  572. static void init_debugfs(struct tegra_pcie_dw *pcie)
  573. {
  574. struct device *dev = pcie->dev;
  575. char *name;
  576. name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
  577. if (!name)
  578. return;
  579. pcie->debugfs = debugfs_create_dir(name, NULL);
  580. debugfs_create_devm_seqfile(dev, "aspm_state_cnt", pcie->debugfs,
  581. aspm_state_cnt);
  582. }
  583. #else
  584. static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; }
  585. static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; }
  586. #endif
  587. static void tegra_pcie_enable_system_interrupts(struct dw_pcie_rp *pp)
  588. {
  589. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  590. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  591. u32 val;
  592. u16 val_w;
  593. val = appl_readl(pcie, APPL_INTR_EN_L0_0);
  594. val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
  595. appl_writel(pcie, val, APPL_INTR_EN_L0_0);
  596. if (!pcie->of_data->has_sbr_reset_fix) {
  597. val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
  598. val |= APPL_INTR_EN_L1_0_0_LINK_REQ_RST_NOT_INT_EN;
  599. appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
  600. }
  601. if (pcie->enable_cdm_check) {
  602. val = appl_readl(pcie, APPL_INTR_EN_L0_0);
  603. val |= pcie->of_data->cdm_chk_int_en_bit;
  604. appl_writel(pcie, val, APPL_INTR_EN_L0_0);
  605. val = appl_readl(pcie, APPL_INTR_EN_L1_18);
  606. val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_CMP_ERR;
  607. val |= APPL_INTR_EN_L1_18_CDM_REG_CHK_LOGIC_ERR;
  608. appl_writel(pcie, val, APPL_INTR_EN_L1_18);
  609. }
  610. val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
  611. PCI_EXP_LNKSTA);
  612. pcie->init_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val_w);
  613. val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base +
  614. PCI_EXP_LNKCTL);
  615. val_w |= PCI_EXP_LNKCTL_LBMIE;
  616. dw_pcie_writew_dbi(&pcie->pci, pcie->pcie_cap_base + PCI_EXP_LNKCTL,
  617. val_w);
  618. }
  619. static void tegra_pcie_enable_intx_interrupts(struct dw_pcie_rp *pp)
  620. {
  621. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  622. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  623. u32 val;
  624. /* Enable INTX interrupt generation */
  625. val = appl_readl(pcie, APPL_INTR_EN_L0_0);
  626. val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
  627. val |= APPL_INTR_EN_L0_0_INT_INT_EN;
  628. appl_writel(pcie, val, APPL_INTR_EN_L0_0);
  629. val = appl_readl(pcie, APPL_INTR_EN_L1_8_0);
  630. val |= APPL_INTR_EN_L1_8_INTX_EN;
  631. val |= APPL_INTR_EN_L1_8_AUTO_BW_INT_EN;
  632. val |= APPL_INTR_EN_L1_8_BW_MGT_INT_EN;
  633. if (IS_ENABLED(CONFIG_PCIEAER))
  634. val |= APPL_INTR_EN_L1_8_AER_INT_EN;
  635. appl_writel(pcie, val, APPL_INTR_EN_L1_8_0);
  636. }
  637. static void tegra_pcie_enable_msi_interrupts(struct dw_pcie_rp *pp)
  638. {
  639. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  640. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  641. u32 val;
  642. /* Enable MSI interrupt generation */
  643. val = appl_readl(pcie, APPL_INTR_EN_L0_0);
  644. val |= APPL_INTR_EN_L0_0_SYS_MSI_INTR_EN;
  645. val |= APPL_INTR_EN_L0_0_MSI_RCV_INT_EN;
  646. appl_writel(pcie, val, APPL_INTR_EN_L0_0);
  647. }
  648. static void tegra_pcie_enable_interrupts(struct dw_pcie_rp *pp)
  649. {
  650. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  651. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  652. /* Clear interrupt statuses before enabling interrupts */
  653. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
  654. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
  655. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
  656. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
  657. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
  658. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
  659. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
  660. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
  661. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
  662. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
  663. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
  664. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
  665. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
  666. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
  667. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
  668. tegra_pcie_enable_system_interrupts(pp);
  669. tegra_pcie_enable_intx_interrupts(pp);
  670. if (IS_ENABLED(CONFIG_PCI_MSI))
  671. tegra_pcie_enable_msi_interrupts(pp);
  672. }
  673. static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie)
  674. {
  675. struct dw_pcie *pci = &pcie->pci;
  676. u32 val, offset, i;
  677. /* Program init preset */
  678. for (i = 0; i < pcie->num_lanes; i++) {
  679. val = dw_pcie_readw_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2));
  680. val &= ~CAP_SPCIE_CAP_OFF_DSP_TX_PRESET0_MASK;
  681. val |= GEN3_GEN4_EQ_PRESET_INIT;
  682. val &= ~CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_MASK;
  683. val |= (GEN3_GEN4_EQ_PRESET_INIT <<
  684. CAP_SPCIE_CAP_OFF_USP_TX_PRESET0_SHIFT);
  685. dw_pcie_writew_dbi(pci, CAP_SPCIE_CAP_OFF + (i * 2), val);
  686. offset = dw_pcie_find_ext_capability(pci,
  687. PCI_EXT_CAP_ID_PL_16GT) +
  688. PCI_PL_16GT_LE_CTRL;
  689. val = dw_pcie_readb_dbi(pci, offset + i);
  690. val &= ~PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK;
  691. val |= GEN3_GEN4_EQ_PRESET_INIT;
  692. val &= ~PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK;
  693. val |= (GEN3_GEN4_EQ_PRESET_INIT <<
  694. PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT);
  695. dw_pcie_writeb_dbi(pci, offset + i, val);
  696. }
  697. val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
  698. val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
  699. dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
  700. val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
  701. val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC;
  702. val |= FIELD_PREP(GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC, 0x3ff);
  703. val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE;
  704. dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
  705. val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
  706. val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
  707. val |= (0x1 << GEN3_RELATED_OFF_RATE_SHADOW_SEL_SHIFT);
  708. dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
  709. val = dw_pcie_readl_dbi(pci, GEN3_EQ_CONTROL_OFF);
  710. val &= ~GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC;
  711. val |= FIELD_PREP(GEN3_EQ_CONTROL_OFF_PSET_REQ_VEC,
  712. pcie->of_data->gen4_preset_vec);
  713. val &= ~GEN3_EQ_CONTROL_OFF_FB_MODE;
  714. dw_pcie_writel_dbi(pci, GEN3_EQ_CONTROL_OFF, val);
  715. val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
  716. val &= ~GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK;
  717. dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
  718. }
  719. static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
  720. {
  721. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  722. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  723. u32 val;
  724. u16 val_16;
  725. pp->bridge->ops = &tegra_pci_ops;
  726. if (!pcie->pcie_cap_base)
  727. pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
  728. PCI_CAP_ID_EXP);
  729. val = dw_pcie_readl_dbi(pci, PCI_IO_BASE);
  730. val &= ~(IO_BASE_IO_DECODE | IO_BASE_IO_DECODE_BIT8);
  731. dw_pcie_writel_dbi(pci, PCI_IO_BASE, val);
  732. val = dw_pcie_readl_dbi(pci, PCI_PREF_MEMORY_BASE);
  733. val |= CFG_PREF_MEM_LIMIT_BASE_MEM_DECODE;
  734. val |= CFG_PREF_MEM_LIMIT_BASE_MEM_LIMIT_DECODE;
  735. dw_pcie_writel_dbi(pci, PCI_PREF_MEMORY_BASE, val);
  736. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
  737. /* Enable as 0xFFFF0001 response for RRS */
  738. val = dw_pcie_readl_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT);
  739. val &= ~(AMBA_ERROR_RESPONSE_RRS_MASK << AMBA_ERROR_RESPONSE_RRS_SHIFT);
  740. val |= (AMBA_ERROR_RESPONSE_RRS_OKAY_FFFF0001 <<
  741. AMBA_ERROR_RESPONSE_RRS_SHIFT);
  742. dw_pcie_writel_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT, val);
  743. /* Clear Slot Clock Configuration bit if SRNS configuration */
  744. if (pcie->enable_srns) {
  745. val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  746. PCI_EXP_LNKSTA);
  747. val_16 &= ~PCI_EXP_LNKSTA_SLC;
  748. dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
  749. val_16);
  750. }
  751. config_gen3_gen4_eq_presets(pcie);
  752. init_host_aspm(pcie);
  753. if (!pcie->of_data->has_l1ss_exit_fix) {
  754. val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
  755. val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
  756. dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
  757. }
  758. if (pcie->update_fc_fixup) {
  759. val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
  760. val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
  761. dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
  762. }
  763. clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
  764. return 0;
  765. }
  766. static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
  767. {
  768. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  769. struct dw_pcie_rp *pp = &pci->pp;
  770. u32 val, offset, tmp;
  771. bool retry = true;
  772. if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
  773. enable_irq(pcie->pex_rst_irq);
  774. return 0;
  775. }
  776. retry_link:
  777. /* Assert RST */
  778. val = appl_readl(pcie, APPL_PINMUX);
  779. val &= ~APPL_PINMUX_PEX_RST;
  780. appl_writel(pcie, val, APPL_PINMUX);
  781. usleep_range(100, 200);
  782. /* Enable LTSSM */
  783. val = appl_readl(pcie, APPL_CTRL);
  784. val |= APPL_CTRL_LTSSM_EN;
  785. appl_writel(pcie, val, APPL_CTRL);
  786. /* De-assert RST */
  787. val = appl_readl(pcie, APPL_PINMUX);
  788. val |= APPL_PINMUX_PEX_RST;
  789. appl_writel(pcie, val, APPL_PINMUX);
  790. msleep(100);
  791. if (dw_pcie_wait_for_link(pci)) {
  792. if (!retry)
  793. return 0;
  794. /*
  795. * There are some endpoints which can't get the link up if
  796. * root port has Data Link Feature (DLF) enabled.
  797. * Refer Spec rev 4.0 ver 1.0 sec 3.4.2 & 7.7.4 for more info
  798. * on Scaled Flow Control and DLF.
  799. * So, need to confirm that is indeed the case here and attempt
  800. * link up once again with DLF disabled.
  801. */
  802. val = appl_readl(pcie, APPL_DEBUG);
  803. val &= APPL_DEBUG_LTSSM_STATE_MASK;
  804. val >>= APPL_DEBUG_LTSSM_STATE_SHIFT;
  805. tmp = appl_readl(pcie, APPL_LINK_STATUS);
  806. tmp &= APPL_LINK_STATUS_RDLH_LINK_UP;
  807. if (!(val == 0x11 && !tmp)) {
  808. /* Link is down for all good reasons */
  809. return 0;
  810. }
  811. dev_info(pci->dev, "Link is down in DLL");
  812. dev_info(pci->dev, "Trying again with DLFE disabled\n");
  813. /* Disable LTSSM */
  814. val = appl_readl(pcie, APPL_CTRL);
  815. val &= ~APPL_CTRL_LTSSM_EN;
  816. appl_writel(pcie, val, APPL_CTRL);
  817. reset_control_assert(pcie->core_rst);
  818. reset_control_deassert(pcie->core_rst);
  819. offset = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_DLF);
  820. val = dw_pcie_readl_dbi(pci, offset + PCI_DLF_CAP);
  821. val &= ~PCI_DLF_EXCHANGE_ENABLE;
  822. dw_pcie_writel_dbi(pci, offset + PCI_DLF_CAP, val);
  823. tegra_pcie_dw_host_init(pp);
  824. dw_pcie_setup_rc(pp);
  825. retry = false;
  826. goto retry_link;
  827. }
  828. tegra_pcie_icc_set(pcie);
  829. tegra_pcie_enable_interrupts(pp);
  830. return 0;
  831. }
  832. static bool tegra_pcie_dw_link_up(struct dw_pcie *pci)
  833. {
  834. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  835. u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
  836. return val & PCI_EXP_LNKSTA_DLLLA;
  837. }
  838. static void tegra_pcie_dw_stop_link(struct dw_pcie *pci)
  839. {
  840. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  841. disable_irq(pcie->pex_rst_irq);
  842. }
  843. static const struct dw_pcie_ops tegra_dw_pcie_ops = {
  844. .link_up = tegra_pcie_dw_link_up,
  845. .start_link = tegra_pcie_dw_start_link,
  846. .stop_link = tegra_pcie_dw_stop_link,
  847. };
  848. static const struct dw_pcie_host_ops tegra_pcie_dw_host_ops = {
  849. .init = tegra_pcie_dw_host_init,
  850. };
  851. static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie)
  852. {
  853. unsigned int phy_count = pcie->phy_count;
  854. while (phy_count--) {
  855. phy_power_off(pcie->phys[phy_count]);
  856. phy_exit(pcie->phys[phy_count]);
  857. }
  858. }
  859. static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie)
  860. {
  861. unsigned int i;
  862. int ret;
  863. for (i = 0; i < pcie->phy_count; i++) {
  864. ret = phy_init(pcie->phys[i]);
  865. if (ret < 0)
  866. goto phy_power_off;
  867. ret = phy_power_on(pcie->phys[i]);
  868. if (ret < 0)
  869. goto phy_exit;
  870. }
  871. return 0;
  872. phy_power_off:
  873. while (i--) {
  874. phy_power_off(pcie->phys[i]);
  875. phy_exit:
  876. phy_exit(pcie->phys[i]);
  877. }
  878. return ret;
  879. }
  880. static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie)
  881. {
  882. struct platform_device *pdev = to_platform_device(pcie->dev);
  883. struct device_node *np = pcie->dev->of_node;
  884. int ret;
  885. pcie->dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
  886. if (!pcie->dbi_res) {
  887. dev_err(pcie->dev, "Failed to find \"dbi\" region\n");
  888. return -ENODEV;
  889. }
  890. ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt);
  891. if (ret < 0) {
  892. dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret);
  893. return ret;
  894. }
  895. ret = of_property_read_u32(np, "nvidia,aspm-pwr-on-t-us",
  896. &pcie->aspm_pwr_on_t);
  897. if (ret < 0)
  898. dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n",
  899. ret);
  900. ret = of_property_read_u32(np, "nvidia,aspm-l0s-entrance-latency-us",
  901. &pcie->aspm_l0s_enter_lat);
  902. if (ret < 0)
  903. dev_info(pcie->dev,
  904. "Failed to read ASPM L0s Entrance latency: %d\n", ret);
  905. ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes);
  906. if (ret < 0) {
  907. dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret);
  908. return ret;
  909. }
  910. ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid);
  911. if (ret) {
  912. dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret);
  913. return ret;
  914. }
  915. ret = of_property_count_strings(np, "phy-names");
  916. if (ret < 0) {
  917. dev_err(pcie->dev, "Failed to find PHY entries: %d\n",
  918. ret);
  919. return ret;
  920. }
  921. pcie->phy_count = ret;
  922. if (of_property_read_bool(np, "nvidia,update-fc-fixup"))
  923. pcie->update_fc_fixup = true;
  924. /* RP using an external REFCLK is supported only in Tegra234 */
  925. if (pcie->of_data->version == TEGRA194_DWC_IP_VER) {
  926. if (pcie->of_data->mode == DW_PCIE_EP_TYPE)
  927. pcie->enable_ext_refclk = true;
  928. } else {
  929. pcie->enable_ext_refclk =
  930. of_property_read_bool(pcie->dev->of_node,
  931. "nvidia,enable-ext-refclk");
  932. }
  933. pcie->supports_clkreq =
  934. of_property_read_bool(pcie->dev->of_node, "supports-clkreq");
  935. pcie->enable_cdm_check =
  936. of_property_read_bool(np, "snps,enable-cdm-check");
  937. if (pcie->of_data->version == TEGRA234_DWC_IP_VER)
  938. pcie->enable_srns =
  939. of_property_read_bool(np, "nvidia,enable-srns");
  940. if (pcie->of_data->mode == DW_PCIE_RC_TYPE)
  941. return 0;
  942. /* Endpoint mode specific DT entries */
  943. pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN);
  944. if (IS_ERR(pcie->pex_rst_gpiod)) {
  945. int err = PTR_ERR(pcie->pex_rst_gpiod);
  946. const char *level = KERN_ERR;
  947. if (err == -EPROBE_DEFER)
  948. level = KERN_DEBUG;
  949. dev_printk(level, pcie->dev,
  950. dev_fmt("Failed to get PERST GPIO: %d\n"),
  951. err);
  952. return err;
  953. }
  954. pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev,
  955. "nvidia,refclk-select",
  956. GPIOD_OUT_HIGH);
  957. if (IS_ERR(pcie->pex_refclk_sel_gpiod)) {
  958. int err = PTR_ERR(pcie->pex_refclk_sel_gpiod);
  959. const char *level = KERN_ERR;
  960. if (err == -EPROBE_DEFER)
  961. level = KERN_DEBUG;
  962. dev_printk(level, pcie->dev,
  963. dev_fmt("Failed to get REFCLK select GPIOs: %d\n"),
  964. err);
  965. pcie->pex_refclk_sel_gpiod = NULL;
  966. }
  967. return 0;
  968. }
  969. static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie,
  970. bool enable)
  971. {
  972. struct mrq_uphy_response resp;
  973. struct tegra_bpmp_message msg;
  974. struct mrq_uphy_request req;
  975. int err;
  976. /*
  977. * Controller-5 doesn't need to have its state set by BPMP-FW in
  978. * Tegra194
  979. */
  980. if (pcie->of_data->version == TEGRA194_DWC_IP_VER && pcie->cid == 5)
  981. return 0;
  982. memset(&req, 0, sizeof(req));
  983. memset(&resp, 0, sizeof(resp));
  984. req.cmd = CMD_UPHY_PCIE_CONTROLLER_STATE;
  985. req.controller_state.pcie_controller = pcie->cid;
  986. req.controller_state.enable = enable;
  987. memset(&msg, 0, sizeof(msg));
  988. msg.mrq = MRQ_UPHY;
  989. msg.tx.data = &req;
  990. msg.tx.size = sizeof(req);
  991. msg.rx.data = &resp;
  992. msg.rx.size = sizeof(resp);
  993. err = tegra_bpmp_transfer(pcie->bpmp, &msg);
  994. if (err)
  995. return err;
  996. if (msg.rx.ret)
  997. return -EINVAL;
  998. return 0;
  999. }
  1000. static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
  1001. bool enable)
  1002. {
  1003. struct mrq_uphy_response resp;
  1004. struct tegra_bpmp_message msg;
  1005. struct mrq_uphy_request req;
  1006. int err;
  1007. memset(&req, 0, sizeof(req));
  1008. memset(&resp, 0, sizeof(resp));
  1009. if (enable) {
  1010. req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_INIT;
  1011. req.ep_ctrlr_pll_init.ep_controller = pcie->cid;
  1012. } else {
  1013. req.cmd = CMD_UPHY_PCIE_EP_CONTROLLER_PLL_OFF;
  1014. req.ep_ctrlr_pll_off.ep_controller = pcie->cid;
  1015. }
  1016. memset(&msg, 0, sizeof(msg));
  1017. msg.mrq = MRQ_UPHY;
  1018. msg.tx.data = &req;
  1019. msg.tx.size = sizeof(req);
  1020. msg.rx.data = &resp;
  1021. msg.rx.size = sizeof(resp);
  1022. err = tegra_bpmp_transfer(pcie->bpmp, &msg);
  1023. if (err)
  1024. return err;
  1025. if (msg.rx.ret)
  1026. return -EINVAL;
  1027. return 0;
  1028. }
  1029. static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie)
  1030. {
  1031. struct dw_pcie_rp *pp = &pcie->pci.pp;
  1032. struct pci_bus *child, *root_port_bus = NULL;
  1033. struct pci_dev *pdev;
  1034. /*
  1035. * link doesn't go into L2 state with some of the endpoints with Tegra
  1036. * if they are not in D0 state. So, need to make sure that immediate
  1037. * downstream devices are in D0 state before sending PME_TurnOff to put
  1038. * link into L2 state.
  1039. * This is as per PCI Express Base r4.0 v1.0 September 27-2017,
  1040. * 5.2 Link State Power Management (Page #428).
  1041. */
  1042. list_for_each_entry(child, &pp->bridge->bus->children, node) {
  1043. if (child->parent == pp->bridge->bus) {
  1044. root_port_bus = child;
  1045. break;
  1046. }
  1047. }
  1048. if (!root_port_bus) {
  1049. dev_err(pcie->dev, "Failed to find downstream bus of Root Port\n");
  1050. return;
  1051. }
  1052. /* Bring downstream devices to D0 if they are not already in */
  1053. list_for_each_entry(pdev, &root_port_bus->devices, bus_list) {
  1054. if (PCI_SLOT(pdev->devfn) == 0) {
  1055. if (pci_set_power_state(pdev, PCI_D0))
  1056. dev_err(pcie->dev,
  1057. "Failed to transition %s to D0 state\n",
  1058. dev_name(&pdev->dev));
  1059. }
  1060. }
  1061. }
  1062. static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie)
  1063. {
  1064. pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3");
  1065. if (IS_ERR(pcie->slot_ctl_3v3)) {
  1066. if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV)
  1067. return PTR_ERR(pcie->slot_ctl_3v3);
  1068. pcie->slot_ctl_3v3 = NULL;
  1069. }
  1070. pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v");
  1071. if (IS_ERR(pcie->slot_ctl_12v)) {
  1072. if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV)
  1073. return PTR_ERR(pcie->slot_ctl_12v);
  1074. pcie->slot_ctl_12v = NULL;
  1075. }
  1076. return 0;
  1077. }
  1078. static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie)
  1079. {
  1080. int ret;
  1081. if (pcie->slot_ctl_3v3) {
  1082. ret = regulator_enable(pcie->slot_ctl_3v3);
  1083. if (ret < 0) {
  1084. dev_err(pcie->dev,
  1085. "Failed to enable 3.3V slot supply: %d\n", ret);
  1086. return ret;
  1087. }
  1088. }
  1089. if (pcie->slot_ctl_12v) {
  1090. ret = regulator_enable(pcie->slot_ctl_12v);
  1091. if (ret < 0) {
  1092. dev_err(pcie->dev,
  1093. "Failed to enable 12V slot supply: %d\n", ret);
  1094. goto fail_12v_enable;
  1095. }
  1096. }
  1097. /*
  1098. * According to PCI Express Card Electromechanical Specification
  1099. * Revision 1.1, Table-2.4, T_PVPERL (Power stable to PERST# inactive)
  1100. * should be a minimum of 100ms.
  1101. */
  1102. if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v)
  1103. msleep(100);
  1104. return 0;
  1105. fail_12v_enable:
  1106. if (pcie->slot_ctl_3v3)
  1107. regulator_disable(pcie->slot_ctl_3v3);
  1108. return ret;
  1109. }
  1110. static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie)
  1111. {
  1112. if (pcie->slot_ctl_12v)
  1113. regulator_disable(pcie->slot_ctl_12v);
  1114. if (pcie->slot_ctl_3v3)
  1115. regulator_disable(pcie->slot_ctl_3v3);
  1116. }
  1117. static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie,
  1118. bool en_hw_hot_rst)
  1119. {
  1120. int ret;
  1121. u32 val;
  1122. ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
  1123. if (ret) {
  1124. dev_err(pcie->dev,
  1125. "Failed to enable controller %u: %d\n", pcie->cid, ret);
  1126. return ret;
  1127. }
  1128. if (pcie->enable_ext_refclk) {
  1129. ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
  1130. if (ret) {
  1131. dev_err(pcie->dev, "Failed to init UPHY: %d\n", ret);
  1132. goto fail_pll_init;
  1133. }
  1134. }
  1135. ret = tegra_pcie_enable_slot_regulators(pcie);
  1136. if (ret < 0)
  1137. goto fail_slot_reg_en;
  1138. ret = regulator_enable(pcie->pex_ctl_supply);
  1139. if (ret < 0) {
  1140. dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret);
  1141. goto fail_reg_en;
  1142. }
  1143. ret = clk_prepare_enable(pcie->core_clk);
  1144. if (ret) {
  1145. dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret);
  1146. goto fail_core_clk;
  1147. }
  1148. ret = reset_control_deassert(pcie->core_apb_rst);
  1149. if (ret) {
  1150. dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n",
  1151. ret);
  1152. goto fail_core_apb_rst;
  1153. }
  1154. if (en_hw_hot_rst || pcie->of_data->has_sbr_reset_fix) {
  1155. /* Enable HW_HOT_RST mode */
  1156. val = appl_readl(pcie, APPL_CTRL);
  1157. val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
  1158. APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
  1159. val |= (APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST_LTSSM_EN <<
  1160. APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
  1161. val |= APPL_CTRL_HW_HOT_RST_EN;
  1162. appl_writel(pcie, val, APPL_CTRL);
  1163. }
  1164. ret = tegra_pcie_enable_phy(pcie);
  1165. if (ret) {
  1166. dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret);
  1167. goto fail_phy;
  1168. }
  1169. /* Update CFG base address */
  1170. appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
  1171. APPL_CFG_BASE_ADDR);
  1172. /* Configure this core for RP mode operation */
  1173. appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE);
  1174. appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
  1175. val = appl_readl(pcie, APPL_CTRL);
  1176. appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL);
  1177. val = appl_readl(pcie, APPL_CFG_MISC);
  1178. val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
  1179. appl_writel(pcie, val, APPL_CFG_MISC);
  1180. if (pcie->enable_srns || pcie->enable_ext_refclk) {
  1181. /*
  1182. * When Tegra PCIe RP is using external clock, it cannot supply
  1183. * same clock to its downstream hierarchy. Hence, gate PCIe RP
  1184. * REFCLK out pads when RP & EP are using separate clocks or RP
  1185. * is using an external REFCLK.
  1186. */
  1187. val = appl_readl(pcie, APPL_PINMUX);
  1188. val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
  1189. val &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
  1190. appl_writel(pcie, val, APPL_PINMUX);
  1191. }
  1192. if (!pcie->supports_clkreq) {
  1193. val = appl_readl(pcie, APPL_PINMUX);
  1194. val |= APPL_PINMUX_CLKREQ_OVERRIDE_EN;
  1195. val &= ~APPL_PINMUX_CLKREQ_OVERRIDE;
  1196. appl_writel(pcie, val, APPL_PINMUX);
  1197. }
  1198. /* Update iATU_DMA base address */
  1199. appl_writel(pcie,
  1200. pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
  1201. APPL_CFG_IATU_DMA_BASE_ADDR);
  1202. reset_control_deassert(pcie->core_rst);
  1203. return ret;
  1204. fail_phy:
  1205. reset_control_assert(pcie->core_apb_rst);
  1206. fail_core_apb_rst:
  1207. clk_disable_unprepare(pcie->core_clk);
  1208. fail_core_clk:
  1209. regulator_disable(pcie->pex_ctl_supply);
  1210. fail_reg_en:
  1211. tegra_pcie_disable_slot_regulators(pcie);
  1212. fail_slot_reg_en:
  1213. if (pcie->enable_ext_refclk)
  1214. tegra_pcie_bpmp_set_pll_state(pcie, false);
  1215. fail_pll_init:
  1216. tegra_pcie_bpmp_set_ctrl_state(pcie, false);
  1217. return ret;
  1218. }
  1219. static void tegra_pcie_unconfig_controller(struct tegra_pcie_dw *pcie)
  1220. {
  1221. int ret;
  1222. ret = reset_control_assert(pcie->core_rst);
  1223. if (ret)
  1224. dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", ret);
  1225. tegra_pcie_disable_phy(pcie);
  1226. ret = reset_control_assert(pcie->core_apb_rst);
  1227. if (ret)
  1228. dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret);
  1229. clk_disable_unprepare(pcie->core_clk);
  1230. ret = regulator_disable(pcie->pex_ctl_supply);
  1231. if (ret)
  1232. dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret);
  1233. tegra_pcie_disable_slot_regulators(pcie);
  1234. if (pcie->enable_ext_refclk) {
  1235. ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
  1236. if (ret)
  1237. dev_err(pcie->dev, "Failed to deinit UPHY: %d\n", ret);
  1238. }
  1239. ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false);
  1240. if (ret)
  1241. dev_err(pcie->dev, "Failed to disable controller %d: %d\n",
  1242. pcie->cid, ret);
  1243. }
  1244. static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie)
  1245. {
  1246. struct dw_pcie *pci = &pcie->pci;
  1247. struct dw_pcie_rp *pp = &pci->pp;
  1248. int ret;
  1249. ret = tegra_pcie_config_controller(pcie, false);
  1250. if (ret < 0)
  1251. return ret;
  1252. pp->ops = &tegra_pcie_dw_host_ops;
  1253. ret = dw_pcie_host_init(pp);
  1254. if (ret < 0) {
  1255. dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret);
  1256. goto fail_host_init;
  1257. }
  1258. return 0;
  1259. fail_host_init:
  1260. tegra_pcie_unconfig_controller(pcie);
  1261. return ret;
  1262. }
  1263. static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie)
  1264. {
  1265. u32 val;
  1266. if (!tegra_pcie_dw_link_up(&pcie->pci))
  1267. return 0;
  1268. val = appl_readl(pcie, APPL_RADM_STATUS);
  1269. val |= APPL_PM_XMT_TURNOFF_STATE;
  1270. appl_writel(pcie, val, APPL_RADM_STATUS);
  1271. return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val,
  1272. val & APPL_DEBUG_PM_LINKST_IN_L2_LAT,
  1273. 1, PME_ACK_TIMEOUT);
  1274. }
  1275. static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie)
  1276. {
  1277. u32 data;
  1278. int err;
  1279. if (!tegra_pcie_dw_link_up(&pcie->pci)) {
  1280. dev_dbg(pcie->dev, "PCIe link is not up...!\n");
  1281. return;
  1282. }
  1283. /*
  1284. * PCIe controller exits from L2 only if reset is applied, so
  1285. * controller doesn't handle interrupts. But in cases where
  1286. * L2 entry fails, PERST# is asserted which can trigger surprise
  1287. * link down AER. However this function call happens in
  1288. * suspend_noirq(), so AER interrupt will not be processed.
  1289. * Disable all interrupts to avoid such a scenario.
  1290. */
  1291. appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0);
  1292. if (tegra_pcie_try_link_l2(pcie)) {
  1293. dev_info(pcie->dev, "Link didn't transition to L2 state\n");
  1294. /*
  1295. * TX lane clock freq will reset to Gen1 only if link is in L2
  1296. * or detect state.
  1297. * So apply pex_rst to end point to force RP to go into detect
  1298. * state
  1299. */
  1300. data = appl_readl(pcie, APPL_PINMUX);
  1301. data &= ~APPL_PINMUX_PEX_RST;
  1302. appl_writel(pcie, data, APPL_PINMUX);
  1303. /*
  1304. * Some cards do not go to detect state even after de-asserting
  1305. * PERST#. So, de-assert LTSSM to bring link to detect state.
  1306. */
  1307. data = readl(pcie->appl_base + APPL_CTRL);
  1308. data &= ~APPL_CTRL_LTSSM_EN;
  1309. writel(data, pcie->appl_base + APPL_CTRL);
  1310. err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG,
  1311. data,
  1312. ((data &
  1313. APPL_DEBUG_LTSSM_STATE_MASK) >>
  1314. APPL_DEBUG_LTSSM_STATE_SHIFT) ==
  1315. LTSSM_STATE_PRE_DETECT,
  1316. 1, LTSSM_TIMEOUT);
  1317. if (err)
  1318. dev_info(pcie->dev, "Link didn't go to detect state\n");
  1319. }
  1320. /*
  1321. * DBI registers may not be accessible after this as PLL-E would be
  1322. * down depending on how CLKREQ is pulled by end point
  1323. */
  1324. data = appl_readl(pcie, APPL_PINMUX);
  1325. data |= (APPL_PINMUX_CLKREQ_OVERRIDE_EN | APPL_PINMUX_CLKREQ_OVERRIDE);
  1326. /* Cut REFCLK to slot */
  1327. data |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
  1328. data &= ~APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
  1329. appl_writel(pcie, data, APPL_PINMUX);
  1330. }
  1331. static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie)
  1332. {
  1333. tegra_pcie_downstream_dev_to_D0(pcie);
  1334. dw_pcie_host_deinit(&pcie->pci.pp);
  1335. tegra_pcie_dw_pme_turnoff(pcie);
  1336. tegra_pcie_unconfig_controller(pcie);
  1337. }
  1338. static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie)
  1339. {
  1340. struct device *dev = pcie->dev;
  1341. int ret;
  1342. pm_runtime_enable(dev);
  1343. ret = pm_runtime_get_sync(dev);
  1344. if (ret < 0) {
  1345. dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
  1346. ret);
  1347. goto fail_pm_get_sync;
  1348. }
  1349. ret = pinctrl_pm_select_default_state(dev);
  1350. if (ret < 0) {
  1351. dev_err(dev, "Failed to configure sideband pins: %d\n", ret);
  1352. goto fail_pm_get_sync;
  1353. }
  1354. ret = tegra_pcie_init_controller(pcie);
  1355. if (ret < 0) {
  1356. dev_err(dev, "Failed to initialize controller: %d\n", ret);
  1357. goto fail_pm_get_sync;
  1358. }
  1359. pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci);
  1360. if (!pcie->link_state) {
  1361. ret = -ENOMEDIUM;
  1362. goto fail_host_init;
  1363. }
  1364. init_debugfs(pcie);
  1365. return ret;
  1366. fail_host_init:
  1367. tegra_pcie_deinit_controller(pcie);
  1368. fail_pm_get_sync:
  1369. pm_runtime_put_sync(dev);
  1370. pm_runtime_disable(dev);
  1371. return ret;
  1372. }
  1373. static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie)
  1374. {
  1375. u32 val;
  1376. int ret;
  1377. if (pcie->ep_state == EP_STATE_DISABLED)
  1378. return;
  1379. /* Disable LTSSM */
  1380. val = appl_readl(pcie, APPL_CTRL);
  1381. val &= ~APPL_CTRL_LTSSM_EN;
  1382. appl_writel(pcie, val, APPL_CTRL);
  1383. ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val,
  1384. ((val & APPL_DEBUG_LTSSM_STATE_MASK) >>
  1385. APPL_DEBUG_LTSSM_STATE_SHIFT) ==
  1386. LTSSM_STATE_PRE_DETECT,
  1387. 1, LTSSM_TIMEOUT);
  1388. if (ret)
  1389. dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret);
  1390. reset_control_assert(pcie->core_rst);
  1391. tegra_pcie_disable_phy(pcie);
  1392. reset_control_assert(pcie->core_apb_rst);
  1393. clk_disable_unprepare(pcie->core_clk);
  1394. pm_runtime_put_sync(pcie->dev);
  1395. if (pcie->enable_ext_refclk) {
  1396. ret = tegra_pcie_bpmp_set_pll_state(pcie, false);
  1397. if (ret)
  1398. dev_err(pcie->dev, "Failed to turn off UPHY: %d\n",
  1399. ret);
  1400. }
  1401. ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false);
  1402. if (ret)
  1403. dev_err(pcie->dev, "Failed to disable controller: %d\n", ret);
  1404. pcie->ep_state = EP_STATE_DISABLED;
  1405. dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n");
  1406. }
  1407. static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie)
  1408. {
  1409. struct dw_pcie *pci = &pcie->pci;
  1410. struct dw_pcie_ep *ep = &pci->ep;
  1411. struct device *dev = pcie->dev;
  1412. u32 val;
  1413. int ret;
  1414. u16 val_16;
  1415. if (pcie->ep_state == EP_STATE_ENABLED)
  1416. return;
  1417. ret = pm_runtime_resume_and_get(dev);
  1418. if (ret < 0) {
  1419. dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n",
  1420. ret);
  1421. return;
  1422. }
  1423. ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true);
  1424. if (ret) {
  1425. dev_err(pcie->dev, "Failed to enable controller %u: %d\n",
  1426. pcie->cid, ret);
  1427. goto fail_set_ctrl_state;
  1428. }
  1429. if (pcie->enable_ext_refclk) {
  1430. ret = tegra_pcie_bpmp_set_pll_state(pcie, true);
  1431. if (ret) {
  1432. dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n",
  1433. ret);
  1434. goto fail_pll_init;
  1435. }
  1436. }
  1437. ret = clk_prepare_enable(pcie->core_clk);
  1438. if (ret) {
  1439. dev_err(dev, "Failed to enable core clock: %d\n", ret);
  1440. goto fail_core_clk_enable;
  1441. }
  1442. ret = reset_control_deassert(pcie->core_apb_rst);
  1443. if (ret) {
  1444. dev_err(dev, "Failed to deassert core APB reset: %d\n", ret);
  1445. goto fail_core_apb_rst;
  1446. }
  1447. ret = tegra_pcie_enable_phy(pcie);
  1448. if (ret) {
  1449. dev_err(dev, "Failed to enable PHY: %d\n", ret);
  1450. goto fail_phy;
  1451. }
  1452. /* Perform cleanup that requires refclk */
  1453. pci_epc_deinit_notify(pcie->pci.ep.epc);
  1454. dw_pcie_ep_cleanup(&pcie->pci.ep);
  1455. /* Clear any stale interrupt statuses */
  1456. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0);
  1457. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0);
  1458. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1);
  1459. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2);
  1460. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3);
  1461. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6);
  1462. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7);
  1463. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0);
  1464. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9);
  1465. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10);
  1466. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11);
  1467. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13);
  1468. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14);
  1469. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15);
  1470. appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17);
  1471. /* configure this core for EP mode operation */
  1472. val = appl_readl(pcie, APPL_DM_TYPE);
  1473. val &= ~APPL_DM_TYPE_MASK;
  1474. val |= APPL_DM_TYPE_EP;
  1475. appl_writel(pcie, val, APPL_DM_TYPE);
  1476. appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE);
  1477. val = appl_readl(pcie, APPL_CTRL);
  1478. val |= APPL_CTRL_SYS_PRE_DET_STATE;
  1479. val |= APPL_CTRL_HW_HOT_RST_EN;
  1480. appl_writel(pcie, val, APPL_CTRL);
  1481. val = appl_readl(pcie, APPL_CFG_MISC);
  1482. val |= APPL_CFG_MISC_SLV_EP_MODE;
  1483. val |= (APPL_CFG_MISC_ARCACHE_VAL << APPL_CFG_MISC_ARCACHE_SHIFT);
  1484. appl_writel(pcie, val, APPL_CFG_MISC);
  1485. val = appl_readl(pcie, APPL_PINMUX);
  1486. val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE_EN;
  1487. val |= APPL_PINMUX_CLK_OUTPUT_IN_OVERRIDE;
  1488. appl_writel(pcie, val, APPL_PINMUX);
  1489. appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK,
  1490. APPL_CFG_BASE_ADDR);
  1491. appl_writel(pcie, pcie->atu_dma_res->start &
  1492. APPL_CFG_IATU_DMA_BASE_ADDR_MASK,
  1493. APPL_CFG_IATU_DMA_BASE_ADDR);
  1494. val = appl_readl(pcie, APPL_INTR_EN_L0_0);
  1495. val |= APPL_INTR_EN_L0_0_SYS_INTR_EN;
  1496. val |= APPL_INTR_EN_L0_0_LINK_STATE_INT_EN;
  1497. val |= APPL_INTR_EN_L0_0_PCI_CMD_EN_INT_EN;
  1498. appl_writel(pcie, val, APPL_INTR_EN_L0_0);
  1499. val = appl_readl(pcie, APPL_INTR_EN_L1_0_0);
  1500. val |= APPL_INTR_EN_L1_0_0_HOT_RESET_DONE_INT_EN;
  1501. val |= APPL_INTR_EN_L1_0_0_RDLH_LINK_UP_INT_EN;
  1502. appl_writel(pcie, val, APPL_INTR_EN_L1_0_0);
  1503. reset_control_deassert(pcie->core_rst);
  1504. if (pcie->update_fc_fixup) {
  1505. val = dw_pcie_readl_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF);
  1506. val |= 0x1 << CFG_TIMER_CTRL_ACK_NAK_SHIFT;
  1507. dw_pcie_writel_dbi(pci, CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF, val);
  1508. }
  1509. config_gen3_gen4_eq_presets(pcie);
  1510. init_host_aspm(pcie);
  1511. if (!pcie->of_data->has_l1ss_exit_fix) {
  1512. val = dw_pcie_readl_dbi(pci, GEN3_RELATED_OFF);
  1513. val &= ~GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL;
  1514. dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, val);
  1515. }
  1516. pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci,
  1517. PCI_CAP_ID_EXP);
  1518. /* Clear Slot Clock Configuration bit if SRNS configuration */
  1519. if (pcie->enable_srns) {
  1520. val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base +
  1521. PCI_EXP_LNKSTA);
  1522. val_16 &= ~PCI_EXP_LNKSTA_SLC;
  1523. dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA,
  1524. val_16);
  1525. }
  1526. clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ);
  1527. val = (ep->msi_mem_phys & MSIX_ADDR_MATCH_LOW_OFF_MASK);
  1528. val |= MSIX_ADDR_MATCH_LOW_OFF_EN;
  1529. dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_LOW_OFF, val);
  1530. val = (upper_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK);
  1531. dw_pcie_writel_dbi(pci, MSIX_ADDR_MATCH_HIGH_OFF, val);
  1532. ret = dw_pcie_ep_init_registers(ep);
  1533. if (ret) {
  1534. dev_err(dev, "Failed to complete initialization: %d\n", ret);
  1535. goto fail_init_complete;
  1536. }
  1537. pci_epc_init_notify(ep->epc);
  1538. /* Program the private control to allow sending LTR upstream */
  1539. if (pcie->of_data->has_ltr_req_fix) {
  1540. val = appl_readl(pcie, APPL_LTR_MSG_2);
  1541. val |= APPL_LTR_MSG_2_LTR_MSG_REQ_STATE;
  1542. appl_writel(pcie, val, APPL_LTR_MSG_2);
  1543. }
  1544. /* Enable LTSSM */
  1545. val = appl_readl(pcie, APPL_CTRL);
  1546. val |= APPL_CTRL_LTSSM_EN;
  1547. appl_writel(pcie, val, APPL_CTRL);
  1548. pcie->ep_state = EP_STATE_ENABLED;
  1549. dev_dbg(dev, "Initialization of endpoint is completed\n");
  1550. return;
  1551. fail_init_complete:
  1552. reset_control_assert(pcie->core_rst);
  1553. tegra_pcie_disable_phy(pcie);
  1554. fail_phy:
  1555. reset_control_assert(pcie->core_apb_rst);
  1556. fail_core_apb_rst:
  1557. clk_disable_unprepare(pcie->core_clk);
  1558. fail_core_clk_enable:
  1559. tegra_pcie_bpmp_set_pll_state(pcie, false);
  1560. fail_pll_init:
  1561. tegra_pcie_bpmp_set_ctrl_state(pcie, false);
  1562. fail_set_ctrl_state:
  1563. pm_runtime_put_sync(dev);
  1564. }
  1565. static irqreturn_t tegra_pcie_ep_pex_rst_irq(int irq, void *arg)
  1566. {
  1567. struct tegra_pcie_dw *pcie = arg;
  1568. if (gpiod_get_value(pcie->pex_rst_gpiod))
  1569. pex_ep_event_pex_rst_assert(pcie);
  1570. else
  1571. pex_ep_event_pex_rst_deassert(pcie);
  1572. return IRQ_HANDLED;
  1573. }
  1574. static void tegra_pcie_ep_init(struct dw_pcie_ep *ep)
  1575. {
  1576. struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
  1577. enum pci_barno bar;
  1578. for (bar = 0; bar < PCI_STD_NUM_BARS; bar++)
  1579. dw_pcie_ep_reset_bar(pci, bar);
  1580. };
  1581. static int tegra_pcie_ep_raise_intx_irq(struct tegra_pcie_dw *pcie, u16 irq)
  1582. {
  1583. /* Tegra194 supports only INTA */
  1584. if (irq > 1)
  1585. return -EINVAL;
  1586. appl_writel(pcie, 1, APPL_LEGACY_INTX);
  1587. usleep_range(1000, 2000);
  1588. appl_writel(pcie, 0, APPL_LEGACY_INTX);
  1589. return 0;
  1590. }
  1591. static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
  1592. {
  1593. if (unlikely(irq > 32))
  1594. return -EINVAL;
  1595. appl_writel(pcie, BIT(irq - 1), APPL_MSI_CTRL_1);
  1596. return 0;
  1597. }
  1598. static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq)
  1599. {
  1600. struct dw_pcie_ep *ep = &pcie->pci.ep;
  1601. writel(irq, ep->msi_mem);
  1602. return 0;
  1603. }
  1604. static int tegra_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
  1605. unsigned int type, u16 interrupt_num)
  1606. {
  1607. struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
  1608. struct tegra_pcie_dw *pcie = to_tegra_pcie(pci);
  1609. switch (type) {
  1610. case PCI_IRQ_INTX:
  1611. return tegra_pcie_ep_raise_intx_irq(pcie, interrupt_num);
  1612. case PCI_IRQ_MSI:
  1613. return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num);
  1614. case PCI_IRQ_MSIX:
  1615. return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num);
  1616. default:
  1617. dev_err(pci->dev, "Unknown IRQ type\n");
  1618. return -EPERM;
  1619. }
  1620. return 0;
  1621. }
  1622. static const struct pci_epc_features tegra_pcie_epc_features = {
  1623. DWC_EPC_COMMON_FEATURES,
  1624. .linkup_notifier = true,
  1625. .msi_capable = true,
  1626. .bar[BAR_0] = { .type = BAR_FIXED, .fixed_size = SZ_1M,
  1627. .only_64bit = true, },
  1628. .bar[BAR_1] = { .type = BAR_RESERVED, },
  1629. .bar[BAR_2] = { .type = BAR_RESERVED, },
  1630. .bar[BAR_3] = { .type = BAR_RESERVED, },
  1631. .bar[BAR_4] = { .type = BAR_RESERVED, },
  1632. .bar[BAR_5] = { .type = BAR_RESERVED, },
  1633. .align = SZ_64K,
  1634. };
  1635. static const struct pci_epc_features*
  1636. tegra_pcie_ep_get_features(struct dw_pcie_ep *ep)
  1637. {
  1638. return &tegra_pcie_epc_features;
  1639. }
  1640. static const struct dw_pcie_ep_ops pcie_ep_ops = {
  1641. .init = tegra_pcie_ep_init,
  1642. .raise_irq = tegra_pcie_ep_raise_irq,
  1643. .get_features = tegra_pcie_ep_get_features,
  1644. };
  1645. static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie,
  1646. struct platform_device *pdev)
  1647. {
  1648. struct dw_pcie *pci = &pcie->pci;
  1649. struct device *dev = pcie->dev;
  1650. struct dw_pcie_ep *ep;
  1651. char *name;
  1652. int ret;
  1653. ep = &pci->ep;
  1654. ep->ops = &pcie_ep_ops;
  1655. ep->page_size = SZ_64K;
  1656. ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME);
  1657. if (ret < 0) {
  1658. dev_err(dev, "Failed to set PERST GPIO debounce time: %d\n",
  1659. ret);
  1660. return ret;
  1661. }
  1662. ret = gpiod_to_irq(pcie->pex_rst_gpiod);
  1663. if (ret < 0) {
  1664. dev_err(dev, "Failed to get IRQ for PERST GPIO: %d\n", ret);
  1665. return ret;
  1666. }
  1667. pcie->pex_rst_irq = (unsigned int)ret;
  1668. name = devm_kasprintf(dev, GFP_KERNEL, "tegra_pcie_%u_pex_rst_irq",
  1669. pcie->cid);
  1670. if (!name) {
  1671. dev_err(dev, "Failed to create PERST IRQ string\n");
  1672. return -ENOMEM;
  1673. }
  1674. irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN);
  1675. pcie->ep_state = EP_STATE_DISABLED;
  1676. ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL,
  1677. tegra_pcie_ep_pex_rst_irq,
  1678. IRQF_TRIGGER_RISING |
  1679. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1680. name, (void *)pcie);
  1681. if (ret < 0) {
  1682. dev_err(dev, "Failed to request IRQ for PERST: %d\n", ret);
  1683. return ret;
  1684. }
  1685. pm_runtime_enable(dev);
  1686. ret = dw_pcie_ep_init(ep);
  1687. if (ret) {
  1688. dev_err(dev, "Failed to initialize DWC Endpoint subsystem: %d\n",
  1689. ret);
  1690. pm_runtime_disable(dev);
  1691. return ret;
  1692. }
  1693. return 0;
  1694. }
  1695. static int tegra_pcie_dw_probe(struct platform_device *pdev)
  1696. {
  1697. const struct tegra_pcie_dw_of_data *data;
  1698. struct device *dev = &pdev->dev;
  1699. struct resource *atu_dma_res;
  1700. struct tegra_pcie_dw *pcie;
  1701. struct dw_pcie_rp *pp;
  1702. struct dw_pcie *pci;
  1703. struct phy **phys;
  1704. char *name;
  1705. int ret;
  1706. u32 i;
  1707. data = of_device_get_match_data(dev);
  1708. pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
  1709. if (!pcie)
  1710. return -ENOMEM;
  1711. pci = &pcie->pci;
  1712. pci->dev = &pdev->dev;
  1713. pci->ops = &tegra_dw_pcie_ops;
  1714. pcie->dev = &pdev->dev;
  1715. pcie->of_data = (struct tegra_pcie_dw_of_data *)data;
  1716. pci->n_fts[0] = pcie->of_data->n_fts[0];
  1717. pci->n_fts[1] = pcie->of_data->n_fts[1];
  1718. pp = &pci->pp;
  1719. pp->num_vectors = MAX_MSI_IRQS;
  1720. ret = tegra_pcie_dw_parse_dt(pcie);
  1721. if (ret < 0) {
  1722. const char *level = KERN_ERR;
  1723. if (ret == -EPROBE_DEFER)
  1724. level = KERN_DEBUG;
  1725. dev_printk(level, dev,
  1726. dev_fmt("Failed to parse device tree: %d\n"),
  1727. ret);
  1728. return ret;
  1729. }
  1730. ret = tegra_pcie_get_slot_regulators(pcie);
  1731. if (ret < 0) {
  1732. const char *level = KERN_ERR;
  1733. if (ret == -EPROBE_DEFER)
  1734. level = KERN_DEBUG;
  1735. dev_printk(level, dev,
  1736. dev_fmt("Failed to get slot regulators: %d\n"),
  1737. ret);
  1738. return ret;
  1739. }
  1740. if (pcie->pex_refclk_sel_gpiod)
  1741. gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1);
  1742. pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl");
  1743. if (IS_ERR(pcie->pex_ctl_supply)) {
  1744. ret = PTR_ERR(pcie->pex_ctl_supply);
  1745. if (ret != -EPROBE_DEFER)
  1746. dev_err(dev, "Failed to get regulator: %ld\n",
  1747. PTR_ERR(pcie->pex_ctl_supply));
  1748. return ret;
  1749. }
  1750. pcie->core_clk = devm_clk_get(dev, "core");
  1751. if (IS_ERR(pcie->core_clk)) {
  1752. dev_err(dev, "Failed to get core clock: %ld\n",
  1753. PTR_ERR(pcie->core_clk));
  1754. return PTR_ERR(pcie->core_clk);
  1755. }
  1756. pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1757. "appl");
  1758. if (!pcie->appl_res) {
  1759. dev_err(dev, "Failed to find \"appl\" region\n");
  1760. return -ENODEV;
  1761. }
  1762. pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res);
  1763. if (IS_ERR(pcie->appl_base))
  1764. return PTR_ERR(pcie->appl_base);
  1765. pcie->core_apb_rst = devm_reset_control_get(dev, "apb");
  1766. if (IS_ERR(pcie->core_apb_rst)) {
  1767. dev_err(dev, "Failed to get APB reset: %ld\n",
  1768. PTR_ERR(pcie->core_apb_rst));
  1769. return PTR_ERR(pcie->core_apb_rst);
  1770. }
  1771. phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL);
  1772. if (!phys)
  1773. return -ENOMEM;
  1774. for (i = 0; i < pcie->phy_count; i++) {
  1775. name = kasprintf(GFP_KERNEL, "p2u-%u", i);
  1776. if (!name) {
  1777. dev_err(dev, "Failed to create P2U string\n");
  1778. return -ENOMEM;
  1779. }
  1780. phys[i] = devm_phy_get(dev, name);
  1781. kfree(name);
  1782. if (IS_ERR(phys[i])) {
  1783. ret = PTR_ERR(phys[i]);
  1784. if (ret != -EPROBE_DEFER)
  1785. dev_err(dev, "Failed to get PHY: %d\n", ret);
  1786. return ret;
  1787. }
  1788. }
  1789. pcie->phys = phys;
  1790. atu_dma_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1791. "atu_dma");
  1792. if (!atu_dma_res) {
  1793. dev_err(dev, "Failed to find \"atu_dma\" region\n");
  1794. return -ENODEV;
  1795. }
  1796. pcie->atu_dma_res = atu_dma_res;
  1797. pci->atu_size = resource_size(atu_dma_res);
  1798. pci->atu_base = devm_ioremap_resource(dev, atu_dma_res);
  1799. if (IS_ERR(pci->atu_base))
  1800. return PTR_ERR(pci->atu_base);
  1801. pcie->core_rst = devm_reset_control_get(dev, "core");
  1802. if (IS_ERR(pcie->core_rst)) {
  1803. dev_err(dev, "Failed to get core reset: %ld\n",
  1804. PTR_ERR(pcie->core_rst));
  1805. return PTR_ERR(pcie->core_rst);
  1806. }
  1807. pp->irq = platform_get_irq_byname(pdev, "intr");
  1808. if (pp->irq < 0)
  1809. return pp->irq;
  1810. pcie->bpmp = tegra_bpmp_get(dev);
  1811. if (IS_ERR(pcie->bpmp))
  1812. return PTR_ERR(pcie->bpmp);
  1813. platform_set_drvdata(pdev, pcie);
  1814. pcie->icc_path = devm_of_icc_get(&pdev->dev, "write");
  1815. ret = PTR_ERR_OR_ZERO(pcie->icc_path);
  1816. if (ret) {
  1817. tegra_bpmp_put(pcie->bpmp);
  1818. dev_err_probe(&pdev->dev, ret, "failed to get write interconnect\n");
  1819. return ret;
  1820. }
  1821. switch (pcie->of_data->mode) {
  1822. case DW_PCIE_RC_TYPE:
  1823. ret = devm_request_irq(dev, pp->irq, tegra_pcie_rp_irq_handler,
  1824. IRQF_SHARED, "tegra-pcie-intr", pcie);
  1825. if (ret) {
  1826. dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
  1827. ret);
  1828. goto fail;
  1829. }
  1830. ret = tegra_pcie_config_rp(pcie);
  1831. if (ret && ret != -ENOMEDIUM)
  1832. goto fail;
  1833. else
  1834. return 0;
  1835. break;
  1836. case DW_PCIE_EP_TYPE:
  1837. ret = devm_request_threaded_irq(dev, pp->irq,
  1838. tegra_pcie_ep_hard_irq,
  1839. tegra_pcie_ep_irq_thread,
  1840. IRQF_SHARED | IRQF_ONESHOT,
  1841. "tegra-pcie-ep-intr", pcie);
  1842. if (ret) {
  1843. dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq,
  1844. ret);
  1845. goto fail;
  1846. }
  1847. ret = tegra_pcie_config_ep(pcie, pdev);
  1848. if (ret < 0)
  1849. goto fail;
  1850. else
  1851. return 0;
  1852. break;
  1853. default:
  1854. dev_err(dev, "Invalid PCIe device type %d\n",
  1855. pcie->of_data->mode);
  1856. ret = -EINVAL;
  1857. }
  1858. fail:
  1859. tegra_bpmp_put(pcie->bpmp);
  1860. return ret;
  1861. }
  1862. static void tegra_pcie_dw_remove(struct platform_device *pdev)
  1863. {
  1864. struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
  1865. if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
  1866. if (!pcie->link_state)
  1867. return;
  1868. debugfs_remove_recursive(pcie->debugfs);
  1869. tegra_pcie_deinit_controller(pcie);
  1870. pm_runtime_put_sync(pcie->dev);
  1871. } else {
  1872. disable_irq(pcie->pex_rst_irq);
  1873. pex_ep_event_pex_rst_assert(pcie);
  1874. }
  1875. pm_runtime_disable(pcie->dev);
  1876. tegra_bpmp_put(pcie->bpmp);
  1877. if (pcie->pex_refclk_sel_gpiod)
  1878. gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0);
  1879. }
  1880. static int tegra_pcie_dw_suspend_late(struct device *dev)
  1881. {
  1882. struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
  1883. u32 val;
  1884. if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
  1885. dev_err(dev, "Failed to Suspend as Tegra PCIe is in EP mode\n");
  1886. return -EPERM;
  1887. }
  1888. if (!pcie->link_state)
  1889. return 0;
  1890. /* Enable HW_HOT_RST mode */
  1891. if (!pcie->of_data->has_sbr_reset_fix) {
  1892. val = appl_readl(pcie, APPL_CTRL);
  1893. val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
  1894. APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
  1895. val |= APPL_CTRL_HW_HOT_RST_EN;
  1896. appl_writel(pcie, val, APPL_CTRL);
  1897. }
  1898. return 0;
  1899. }
  1900. static int tegra_pcie_dw_suspend_noirq(struct device *dev)
  1901. {
  1902. struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
  1903. if (!pcie->link_state)
  1904. return 0;
  1905. tegra_pcie_downstream_dev_to_D0(pcie);
  1906. tegra_pcie_dw_pme_turnoff(pcie);
  1907. tegra_pcie_unconfig_controller(pcie);
  1908. return 0;
  1909. }
  1910. static int tegra_pcie_dw_resume_noirq(struct device *dev)
  1911. {
  1912. struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
  1913. int ret;
  1914. if (!pcie->link_state)
  1915. return 0;
  1916. ret = tegra_pcie_config_controller(pcie, true);
  1917. if (ret < 0)
  1918. return ret;
  1919. ret = tegra_pcie_dw_host_init(&pcie->pci.pp);
  1920. if (ret < 0) {
  1921. dev_err(dev, "Failed to init host: %d\n", ret);
  1922. goto fail_host_init;
  1923. }
  1924. dw_pcie_setup_rc(&pcie->pci.pp);
  1925. ret = tegra_pcie_dw_start_link(&pcie->pci);
  1926. if (ret < 0)
  1927. goto fail_host_init;
  1928. return 0;
  1929. fail_host_init:
  1930. tegra_pcie_unconfig_controller(pcie);
  1931. return ret;
  1932. }
  1933. static int tegra_pcie_dw_resume_early(struct device *dev)
  1934. {
  1935. struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
  1936. u32 val;
  1937. if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
  1938. dev_err(dev, "Suspend is not supported in EP mode");
  1939. return -ENOTSUPP;
  1940. }
  1941. if (!pcie->link_state)
  1942. return 0;
  1943. /* Disable HW_HOT_RST mode */
  1944. if (!pcie->of_data->has_sbr_reset_fix) {
  1945. val = appl_readl(pcie, APPL_CTRL);
  1946. val &= ~(APPL_CTRL_HW_HOT_RST_MODE_MASK <<
  1947. APPL_CTRL_HW_HOT_RST_MODE_SHIFT);
  1948. val |= APPL_CTRL_HW_HOT_RST_MODE_IMDT_RST <<
  1949. APPL_CTRL_HW_HOT_RST_MODE_SHIFT;
  1950. val &= ~APPL_CTRL_HW_HOT_RST_EN;
  1951. appl_writel(pcie, val, APPL_CTRL);
  1952. }
  1953. return 0;
  1954. }
  1955. static void tegra_pcie_dw_shutdown(struct platform_device *pdev)
  1956. {
  1957. struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev);
  1958. if (pcie->of_data->mode == DW_PCIE_RC_TYPE) {
  1959. if (!pcie->link_state)
  1960. return;
  1961. debugfs_remove_recursive(pcie->debugfs);
  1962. tegra_pcie_downstream_dev_to_D0(pcie);
  1963. disable_irq(pcie->pci.pp.irq);
  1964. if (IS_ENABLED(CONFIG_PCI_MSI))
  1965. disable_irq(pcie->pci.pp.msi_irq[0]);
  1966. tegra_pcie_dw_pme_turnoff(pcie);
  1967. tegra_pcie_unconfig_controller(pcie);
  1968. pm_runtime_put_sync(pcie->dev);
  1969. } else {
  1970. disable_irq(pcie->pex_rst_irq);
  1971. pex_ep_event_pex_rst_assert(pcie);
  1972. }
  1973. }
  1974. static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_rc_of_data = {
  1975. .version = TEGRA194_DWC_IP_VER,
  1976. .mode = DW_PCIE_RC_TYPE,
  1977. .cdm_chk_int_en_bit = BIT(19),
  1978. /* Gen4 - 5, 6, 8 and 9 presets enabled */
  1979. .gen4_preset_vec = 0x360,
  1980. .n_fts = { 52, 52 },
  1981. };
  1982. static const struct tegra_pcie_dw_of_data tegra194_pcie_dw_ep_of_data = {
  1983. .version = TEGRA194_DWC_IP_VER,
  1984. .mode = DW_PCIE_EP_TYPE,
  1985. .cdm_chk_int_en_bit = BIT(19),
  1986. /* Gen4 - 5, 6, 8 and 9 presets enabled */
  1987. .gen4_preset_vec = 0x360,
  1988. .n_fts = { 52, 52 },
  1989. };
  1990. static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_rc_of_data = {
  1991. .version = TEGRA234_DWC_IP_VER,
  1992. .mode = DW_PCIE_RC_TYPE,
  1993. .has_msix_doorbell_access_fix = true,
  1994. .has_sbr_reset_fix = true,
  1995. .has_l1ss_exit_fix = true,
  1996. .cdm_chk_int_en_bit = BIT(18),
  1997. /* Gen4 - 6, 8 and 9 presets enabled */
  1998. .gen4_preset_vec = 0x340,
  1999. .n_fts = { 52, 80 },
  2000. };
  2001. static const struct tegra_pcie_dw_of_data tegra234_pcie_dw_ep_of_data = {
  2002. .version = TEGRA234_DWC_IP_VER,
  2003. .mode = DW_PCIE_EP_TYPE,
  2004. .has_l1ss_exit_fix = true,
  2005. .has_ltr_req_fix = true,
  2006. .cdm_chk_int_en_bit = BIT(18),
  2007. /* Gen4 - 6, 8 and 9 presets enabled */
  2008. .gen4_preset_vec = 0x340,
  2009. .n_fts = { 52, 80 },
  2010. };
  2011. static const struct of_device_id tegra_pcie_dw_of_match[] = {
  2012. {
  2013. .compatible = "nvidia,tegra194-pcie",
  2014. .data = &tegra194_pcie_dw_rc_of_data,
  2015. },
  2016. {
  2017. .compatible = "nvidia,tegra194-pcie-ep",
  2018. .data = &tegra194_pcie_dw_ep_of_data,
  2019. },
  2020. {
  2021. .compatible = "nvidia,tegra234-pcie",
  2022. .data = &tegra234_pcie_dw_rc_of_data,
  2023. },
  2024. {
  2025. .compatible = "nvidia,tegra234-pcie-ep",
  2026. .data = &tegra234_pcie_dw_ep_of_data,
  2027. },
  2028. {}
  2029. };
  2030. static const struct dev_pm_ops tegra_pcie_dw_pm_ops = {
  2031. .suspend_late = tegra_pcie_dw_suspend_late,
  2032. .suspend_noirq = tegra_pcie_dw_suspend_noirq,
  2033. .resume_noirq = tegra_pcie_dw_resume_noirq,
  2034. .resume_early = tegra_pcie_dw_resume_early,
  2035. };
  2036. static struct platform_driver tegra_pcie_dw_driver = {
  2037. .probe = tegra_pcie_dw_probe,
  2038. .remove = tegra_pcie_dw_remove,
  2039. .shutdown = tegra_pcie_dw_shutdown,
  2040. .driver = {
  2041. .name = "tegra194-pcie",
  2042. .pm = &tegra_pcie_dw_pm_ops,
  2043. .of_match_table = tegra_pcie_dw_of_match,
  2044. },
  2045. };
  2046. module_platform_driver(tegra_pcie_dw_driver);
  2047. MODULE_DEVICE_TABLE(of, tegra_pcie_dw_of_match);
  2048. MODULE_AUTHOR("Vidya Sagar <vidyas@nvidia.com>");
  2049. MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");
  2050. MODULE_LICENSE("GPL v2");