pcie-tegra194.c 68 KB

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