sde_hw_interrupts.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/bitops.h>
  7. #include <linux/slab.h>
  8. #include "sde_kms.h"
  9. #include "sde_hw_interrupts.h"
  10. #include "sde_hw_util.h"
  11. #include "sde_hw_mdss.h"
  12. /**
  13. * Register offsets in MDSS register file for the interrupt registers
  14. * w.r.t. base for that block. Base offsets for IRQs should come from the
  15. * device tree and get stored in the catalog(irq_offset_list) until they
  16. * are added to the sde_irq_tbl during the table initialization.
  17. */
  18. #define HW_INTR_STATUS 0x0010
  19. #define MDP_AD4_INTR_EN_OFF 0x41c
  20. #define MDP_AD4_INTR_CLEAR_OFF 0x424
  21. #define MDP_AD4_INTR_STATUS_OFF 0x420
  22. #define MDP_INTF_TEAR_INTR_EN_OFF 0x0
  23. #define MDP_INTF_TEAR_INTR_STATUS_OFF 0x4
  24. #define MDP_INTF_TEAR_INTR_CLEAR_OFF 0x8
  25. #define MDP_LTM_INTR_EN_OFF 0x50
  26. #define MDP_LTM_INTR_STATUS_OFF 0x54
  27. #define MDP_LTM_INTR_CLEAR_OFF 0x58
  28. #define MDP_WB_INTR_EN_OFF 0x18C
  29. #define MDP_WB_INTR_STATUS_OFF 0x190
  30. #define MDP_WB_INTR_CLEAR_OFF 0x194
  31. /**
  32. * WB interrupt status bit definitions
  33. */
  34. #define SDE_INTR_WB_0_DONE BIT(0)
  35. #define SDE_INTR_WB_1_DONE BIT(1)
  36. #define SDE_INTR_WB_2_DONE BIT(4)
  37. /**
  38. * WDOG timer interrupt status bit definitions
  39. */
  40. #define SDE_INTR_WD_TIMER_0_DONE BIT(2)
  41. #define SDE_INTR_WD_TIMER_1_DONE BIT(3)
  42. #define SDE_INTR_WD_TIMER_2_DONE BIT(5)
  43. #define SDE_INTR_WD_TIMER_3_DONE BIT(6)
  44. #define SDE_INTR_WD_TIMER_4_DONE BIT(7)
  45. /**
  46. * Pingpong interrupt status bit definitions
  47. */
  48. #define SDE_INTR_PING_PONG_0_DONE BIT(8)
  49. #define SDE_INTR_PING_PONG_1_DONE BIT(9)
  50. #define SDE_INTR_PING_PONG_2_DONE BIT(10)
  51. #define SDE_INTR_PING_PONG_3_DONE BIT(11)
  52. #define SDE_INTR_PING_PONG_4_DONE BIT(30)
  53. #define SDE_INTR_PING_PONG_5_DONE BIT(31)
  54. #define SDE_INTR_PING_PONG_0_RD_PTR BIT(12)
  55. #define SDE_INTR_PING_PONG_1_RD_PTR BIT(13)
  56. #define SDE_INTR_PING_PONG_2_RD_PTR BIT(14)
  57. #define SDE_INTR_PING_PONG_3_RD_PTR BIT(15)
  58. #define SDE_INTR_PING_PONG_0_WR_PTR BIT(16)
  59. #define SDE_INTR_PING_PONG_1_WR_PTR BIT(17)
  60. #define SDE_INTR_PING_PONG_2_WR_PTR BIT(18)
  61. #define SDE_INTR_PING_PONG_3_WR_PTR BIT(19)
  62. #define SDE_INTR_PING_PONG_0_AUTOREFRESH_DONE BIT(20)
  63. #define SDE_INTR_PING_PONG_1_AUTOREFRESH_DONE BIT(21)
  64. #define SDE_INTR_PING_PONG_2_AUTOREFRESH_DONE BIT(22)
  65. #define SDE_INTR_PING_PONG_3_AUTOREFRESH_DONE BIT(23)
  66. /**
  67. * Interface interrupt status bit definitions
  68. */
  69. #define SDE_INTR_INTF_0_UNDERRUN BIT(24)
  70. #define SDE_INTR_INTF_1_UNDERRUN BIT(26)
  71. #define SDE_INTR_INTF_2_UNDERRUN BIT(28)
  72. #define SDE_INTR_INTF_3_UNDERRUN BIT(30)
  73. #define SDE_INTR_INTF_0_VSYNC BIT(25)
  74. #define SDE_INTR_INTF_1_VSYNC BIT(27)
  75. #define SDE_INTR_INTF_2_VSYNC BIT(29)
  76. #define SDE_INTR_INTF_3_VSYNC BIT(31)
  77. /**
  78. * Ctl start interrupt status bit definitions
  79. */
  80. #define SDE_INTR_CTL_0_START BIT(9)
  81. #define SDE_INTR_CTL_1_START BIT(10)
  82. #define SDE_INTR_CTL_2_START BIT(11)
  83. #define SDE_INTR_CTL_3_START BIT(12)
  84. #define SDE_INTR_CTL_4_START BIT(13)
  85. #define SDE_INTR_CTL_5_START BIT(23)
  86. /**
  87. * Ctl done interrupt status bit definitions
  88. */
  89. #define SDE_INTR_CTL_0_DONE BIT(0)
  90. #define SDE_INTR_CTL_1_DONE BIT(1)
  91. #define SDE_INTR_CTL_2_DONE BIT(2)
  92. #define SDE_INTR_CTL_3_DONE BIT(3)
  93. #define SDE_INTR_CTL_4_DONE BIT(4)
  94. #define SDE_INTR_CTL_5_DONE BIT(5)
  95. /**
  96. * Concurrent WB overflow interrupt status bit definitions
  97. */
  98. #define SDE_INTR_CWB_OVERFLOW BIT(29)
  99. #define SDE_INTR_CWB_2_OVERFLOW BIT(28)
  100. /**
  101. * Histogram VIG done interrupt status bit definitions
  102. */
  103. #define SDE_INTR_HIST_VIG_0_DONE BIT(0)
  104. #define SDE_INTR_HIST_VIG_1_DONE BIT(4)
  105. #define SDE_INTR_HIST_VIG_2_DONE BIT(8)
  106. #define SDE_INTR_HIST_VIG_3_DONE BIT(10)
  107. /**
  108. * Histogram VIG reset Sequence done interrupt status bit definitions
  109. */
  110. #define SDE_INTR_HIST_VIG_0_RSTSEQ_DONE BIT(1)
  111. #define SDE_INTR_HIST_VIG_1_RSTSEQ_DONE BIT(5)
  112. #define SDE_INTR_HIST_VIG_2_RSTSEQ_DONE BIT(9)
  113. #define SDE_INTR_HIST_VIG_3_RSTSEQ_DONE BIT(11)
  114. /**
  115. * Histogram DSPP done interrupt status bit definitions
  116. */
  117. #define SDE_INTR_HIST_DSPP_0_DONE BIT(12)
  118. #define SDE_INTR_HIST_DSPP_1_DONE BIT(16)
  119. #define SDE_INTR_HIST_DSPP_2_DONE BIT(20)
  120. #define SDE_INTR_HIST_DSPP_3_DONE BIT(22)
  121. /**
  122. * Histogram DSPP reset Sequence done interrupt status bit definitions
  123. */
  124. #define SDE_INTR_HIST_DSPP_0_RSTSEQ_DONE BIT(13)
  125. #define SDE_INTR_HIST_DSPP_1_RSTSEQ_DONE BIT(17)
  126. #define SDE_INTR_HIST_DSPP_2_RSTSEQ_DONE BIT(21)
  127. #define SDE_INTR_HIST_DSPP_3_RSTSEQ_DONE BIT(23)
  128. /**
  129. * INTF interrupt status bit definitions
  130. */
  131. #define SDE_INTR_VIDEO_INTO_STATIC BIT(0)
  132. #define SDE_INTR_VIDEO_OUTOF_STATIC BIT(1)
  133. #define SDE_INTR_DSICMD_0_INTO_STATIC BIT(2)
  134. #define SDE_INTR_DSICMD_0_OUTOF_STATIC BIT(3)
  135. #define SDE_INTR_DSICMD_1_INTO_STATIC BIT(4)
  136. #define SDE_INTR_DSICMD_1_OUTOF_STATIC BIT(5)
  137. #define SDE_INTR_DSICMD_2_INTO_STATIC BIT(6)
  138. #define SDE_INTR_DSICMD_2_OUTOF_STATIC BIT(7)
  139. #define SDE_INTR_PROG_LINE BIT(8)
  140. #define SDE_INTR_INTF_WD_TIMER_0_DONE BIT(13)
  141. /**
  142. * AD4 interrupt status bit definitions
  143. */
  144. #define SDE_INTR_BRIGHTPR_UPDATED BIT(4)
  145. #define SDE_INTR_DARKENH_UPDATED BIT(3)
  146. #define SDE_INTR_STREN_OUTROI_UPDATED BIT(2)
  147. #define SDE_INTR_STREN_INROI_UPDATED BIT(1)
  148. #define SDE_INTR_BACKLIGHT_UPDATED BIT(0)
  149. /**
  150. * INTF Tear IRQ register bit definitions
  151. */
  152. #define SDE_INTR_INTF_TEAR_AUTOREFRESH_DONE BIT(0)
  153. #define SDE_INTR_INTF_TEAR_WR_PTR BIT(1)
  154. #define SDE_INTR_INTF_TEAR_RD_PTR BIT(2)
  155. #define SDE_INTR_INTF_TEAR_TE_DETECTED BIT(3)
  156. #define SDE_INTR_INTF_TEAR_TEAR_DETECTED BIT(4)
  157. #define SDE_INTR_INTF_TEAR_TE_DEASSERT_DETECTED BIT(6)
  158. /**
  159. * LTM interrupt status bit definitions
  160. */
  161. #define SDE_INTR_LTM_STATS_DONE BIT(0)
  162. #define SDE_INTR_LTM_STATS_WB_PB BIT(5)
  163. /**
  164. * WB interrupt status bit definitions
  165. */
  166. #define SDE_INTR_WB_PROG_LINE BIT(0)
  167. /**
  168. * struct sde_intr_reg - array of SDE register sets
  169. * @clr_off: offset to CLEAR reg
  170. * @en_off: offset to ENABLE reg
  171. * @status_off: offset to STATUS reg
  172. * @map_idx_start first offset in the sde_irq_map table
  173. * @map_idx_end last offset in the sde_irq_map table
  174. */
  175. struct sde_intr_reg {
  176. u32 clr_off;
  177. u32 en_off;
  178. u32 status_off;
  179. u32 map_idx_start;
  180. u32 map_idx_end;
  181. };
  182. /**
  183. * struct sde_irq_type - maps each irq with i/f
  184. * @intr_type: type of interrupt listed in sde_intr_type
  185. * @instance_idx: instance index of the associated HW block in SDE
  186. * @irq_mask: corresponding bit in the interrupt status reg
  187. * @reg_idx: index in the 'sde_irq_tbl' table, to know which
  188. * registers offsets to use.
  189. */
  190. struct sde_irq_type {
  191. u32 intr_type;
  192. u32 instance_idx;
  193. u32 irq_mask;
  194. int reg_idx;
  195. };
  196. /**
  197. * IRQ mapping tables - use for lookup an irq_idx in this table that have
  198. * a matching interface type and instance index.
  199. * Each of these tables are copied to a dynamically allocated
  200. * table, that will be used to service each of the irqs
  201. * -1 indicates an uninitialized value which should be set when copying
  202. * these tables to the sde_irq_map.
  203. */
  204. static struct sde_irq_type sde_irq_intr_map[] = {
  205. { SDE_IRQ_TYPE_WB_WFD_COMP, WB_0, SDE_INTR_WB_0_DONE, -1},
  206. { SDE_IRQ_TYPE_WB_WFD_COMP, WB_1, SDE_INTR_WB_1_DONE, -1},
  207. { SDE_IRQ_TYPE_WD_TIMER, WD_TIMER_0, SDE_INTR_WD_TIMER_0_DONE, -1},
  208. { SDE_IRQ_TYPE_WD_TIMER, WD_TIMER_1, SDE_INTR_WD_TIMER_1_DONE, -1},
  209. { SDE_IRQ_TYPE_WB_WFD_COMP, WB_2, SDE_INTR_WB_2_DONE, -1},
  210. { SDE_IRQ_TYPE_WD_TIMER, WD_TIMER_2, SDE_INTR_WD_TIMER_2_DONE, -1},
  211. { SDE_IRQ_TYPE_WD_TIMER, WD_TIMER_3, SDE_INTR_WD_TIMER_3_DONE, -1},
  212. { SDE_IRQ_TYPE_WD_TIMER, WD_TIMER_4, SDE_INTR_WD_TIMER_4_DONE, -1},
  213. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_0,
  214. SDE_INTR_PING_PONG_0_DONE, -1},
  215. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_1,
  216. SDE_INTR_PING_PONG_1_DONE, -1},
  217. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_2,
  218. SDE_INTR_PING_PONG_2_DONE, -1},
  219. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_3,
  220. SDE_INTR_PING_PONG_3_DONE, -1},
  221. { SDE_IRQ_TYPE_PING_PONG_RD_PTR, PINGPONG_0,
  222. SDE_INTR_PING_PONG_0_RD_PTR, -1},
  223. { SDE_IRQ_TYPE_PING_PONG_RD_PTR, PINGPONG_1,
  224. SDE_INTR_PING_PONG_1_RD_PTR, -1},
  225. { SDE_IRQ_TYPE_PING_PONG_RD_PTR, PINGPONG_2,
  226. SDE_INTR_PING_PONG_2_RD_PTR, -1},
  227. { SDE_IRQ_TYPE_PING_PONG_RD_PTR, PINGPONG_3,
  228. SDE_INTR_PING_PONG_3_RD_PTR, -1},
  229. { SDE_IRQ_TYPE_PING_PONG_WR_PTR, PINGPONG_0,
  230. SDE_INTR_PING_PONG_0_WR_PTR, -1},
  231. { SDE_IRQ_TYPE_PING_PONG_WR_PTR, PINGPONG_1,
  232. SDE_INTR_PING_PONG_1_WR_PTR, -1},
  233. { SDE_IRQ_TYPE_PING_PONG_WR_PTR, PINGPONG_2,
  234. SDE_INTR_PING_PONG_2_WR_PTR, -1},
  235. { SDE_IRQ_TYPE_PING_PONG_WR_PTR, PINGPONG_3,
  236. SDE_INTR_PING_PONG_3_WR_PTR, -1},
  237. { SDE_IRQ_TYPE_PING_PONG_AUTO_REF, PINGPONG_0,
  238. SDE_INTR_PING_PONG_0_AUTOREFRESH_DONE, -1},
  239. { SDE_IRQ_TYPE_PING_PONG_AUTO_REF, PINGPONG_1,
  240. SDE_INTR_PING_PONG_1_AUTOREFRESH_DONE, -1},
  241. { SDE_IRQ_TYPE_PING_PONG_AUTO_REF, PINGPONG_2,
  242. SDE_INTR_PING_PONG_2_AUTOREFRESH_DONE, -1},
  243. { SDE_IRQ_TYPE_PING_PONG_AUTO_REF, PINGPONG_3,
  244. SDE_INTR_PING_PONG_3_AUTOREFRESH_DONE, -1},
  245. { SDE_IRQ_TYPE_INTF_UNDER_RUN, INTF_0, SDE_INTR_INTF_0_UNDERRUN, -1},
  246. { SDE_IRQ_TYPE_INTF_VSYNC, INTF_0, SDE_INTR_INTF_0_VSYNC, -1},
  247. { SDE_IRQ_TYPE_INTF_UNDER_RUN, INTF_1, SDE_INTR_INTF_1_UNDERRUN, -1},
  248. { SDE_IRQ_TYPE_INTF_VSYNC, INTF_1, SDE_INTR_INTF_1_VSYNC, -1},
  249. { SDE_IRQ_TYPE_INTF_UNDER_RUN, INTF_2, SDE_INTR_INTF_2_UNDERRUN, -1},
  250. { SDE_IRQ_TYPE_INTF_VSYNC, INTF_2, SDE_INTR_INTF_2_VSYNC, -1},
  251. { SDE_IRQ_TYPE_INTF_UNDER_RUN, INTF_3, SDE_INTR_INTF_3_UNDERRUN, -1},
  252. { SDE_IRQ_TYPE_INTF_VSYNC, INTF_3, SDE_INTR_INTF_3_VSYNC, -1},
  253. };
  254. static struct sde_irq_type sde_irq_intr2_map[] = {
  255. { SDE_IRQ_TYPE_CTL_START, CTL_0,
  256. SDE_INTR_CTL_0_START, -1},
  257. { SDE_IRQ_TYPE_CTL_START, CTL_1,
  258. SDE_INTR_CTL_1_START, -1},
  259. { SDE_IRQ_TYPE_CTL_START, CTL_2,
  260. SDE_INTR_CTL_2_START, -1},
  261. { SDE_IRQ_TYPE_CTL_START, CTL_3,
  262. SDE_INTR_CTL_3_START, -1},
  263. { SDE_IRQ_TYPE_CTL_START, CTL_4,
  264. SDE_INTR_CTL_4_START, -1},
  265. { SDE_IRQ_TYPE_CTL_START, CTL_5,
  266. SDE_INTR_CTL_5_START, -1},
  267. { SDE_IRQ_TYPE_CTL_DONE, CTL_0,
  268. SDE_INTR_CTL_0_DONE, -1},
  269. { SDE_IRQ_TYPE_CTL_DONE, CTL_1,
  270. SDE_INTR_CTL_1_DONE, -1},
  271. { SDE_IRQ_TYPE_CTL_DONE, CTL_2,
  272. SDE_INTR_CTL_2_DONE, -1},
  273. { SDE_IRQ_TYPE_CTL_DONE, CTL_3,
  274. SDE_INTR_CTL_3_DONE, -1},
  275. { SDE_IRQ_TYPE_CTL_DONE, CTL_4,
  276. SDE_INTR_CTL_4_DONE, -1},
  277. { SDE_IRQ_TYPE_CTL_DONE, CTL_5,
  278. SDE_INTR_CTL_5_DONE, -1},
  279. { SDE_IRQ_TYPE_CWB_OVERFLOW, PINGPONG_CWB_0, SDE_INTR_CWB_OVERFLOW, -1},
  280. { SDE_IRQ_TYPE_CWB_OVERFLOW, PINGPONG_CWB_2, SDE_INTR_CWB_2_OVERFLOW, -1},
  281. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_4,
  282. SDE_INTR_PING_PONG_4_DONE, -1},
  283. { SDE_IRQ_TYPE_PING_PONG_COMP, PINGPONG_5,
  284. SDE_INTR_PING_PONG_5_DONE, -1},
  285. };
  286. static struct sde_irq_type sde_irq_hist_map[] = {
  287. { SDE_IRQ_TYPE_HIST_VIG_DONE, SSPP_VIG0, SDE_INTR_HIST_VIG_0_DONE, -1},
  288. { SDE_IRQ_TYPE_HIST_VIG_RSTSEQ, SSPP_VIG0,
  289. SDE_INTR_HIST_VIG_0_RSTSEQ_DONE, -1},
  290. { SDE_IRQ_TYPE_HIST_VIG_DONE, SSPP_VIG1, SDE_INTR_HIST_VIG_1_DONE, -1},
  291. { SDE_IRQ_TYPE_HIST_VIG_RSTSEQ, SSPP_VIG1,
  292. SDE_INTR_HIST_VIG_1_RSTSEQ_DONE, -1},
  293. { SDE_IRQ_TYPE_HIST_VIG_DONE, SSPP_VIG2, SDE_INTR_HIST_VIG_2_DONE, -1},
  294. { SDE_IRQ_TYPE_HIST_VIG_RSTSEQ, SSPP_VIG2,
  295. SDE_INTR_HIST_VIG_2_RSTSEQ_DONE, -1},
  296. { SDE_IRQ_TYPE_HIST_VIG_DONE, SSPP_VIG3, SDE_INTR_HIST_VIG_3_DONE, -1},
  297. { SDE_IRQ_TYPE_HIST_VIG_RSTSEQ, SSPP_VIG3,
  298. SDE_INTR_HIST_VIG_3_RSTSEQ_DONE, -1},
  299. { SDE_IRQ_TYPE_HIST_DSPP_DONE, DSPP_0, SDE_INTR_HIST_DSPP_0_DONE, -1},
  300. { SDE_IRQ_TYPE_HIST_DSPP_RSTSEQ, DSPP_0,
  301. SDE_INTR_HIST_DSPP_0_RSTSEQ_DONE, -1},
  302. { SDE_IRQ_TYPE_HIST_DSPP_DONE, DSPP_1, SDE_INTR_HIST_DSPP_1_DONE, -1},
  303. { SDE_IRQ_TYPE_HIST_DSPP_RSTSEQ, DSPP_1,
  304. SDE_INTR_HIST_DSPP_1_RSTSEQ_DONE, -1},
  305. { SDE_IRQ_TYPE_HIST_DSPP_DONE, DSPP_2, SDE_INTR_HIST_DSPP_2_DONE, -1},
  306. { SDE_IRQ_TYPE_HIST_DSPP_RSTSEQ, DSPP_2,
  307. SDE_INTR_HIST_DSPP_2_RSTSEQ_DONE, -1},
  308. { SDE_IRQ_TYPE_HIST_DSPP_DONE, DSPP_3, SDE_INTR_HIST_DSPP_3_DONE, -1},
  309. { SDE_IRQ_TYPE_HIST_DSPP_RSTSEQ, DSPP_3,
  310. SDE_INTR_HIST_DSPP_3_RSTSEQ_DONE, -1},
  311. };
  312. static struct sde_irq_type sde_irq_intf_map[] = {
  313. { SDE_IRQ_TYPE_SFI_VIDEO_IN, -1,
  314. SDE_INTR_VIDEO_INTO_STATIC, -1},
  315. { SDE_IRQ_TYPE_SFI_VIDEO_OUT, -1,
  316. SDE_INTR_VIDEO_OUTOF_STATIC, -1},
  317. { SDE_IRQ_TYPE_SFI_CMD_0_IN, -1,
  318. SDE_INTR_DSICMD_0_INTO_STATIC, -1},
  319. { SDE_IRQ_TYPE_SFI_CMD_0_OUT, -1,
  320. SDE_INTR_DSICMD_0_OUTOF_STATIC, -1},
  321. { SDE_IRQ_TYPE_SFI_CMD_1_IN, -1,
  322. SDE_INTR_DSICMD_1_INTO_STATIC, -1},
  323. { SDE_IRQ_TYPE_SFI_CMD_1_OUT, -1,
  324. SDE_INTR_DSICMD_1_OUTOF_STATIC, -1},
  325. { SDE_IRQ_TYPE_SFI_CMD_2_IN, -1,
  326. SDE_INTR_DSICMD_2_INTO_STATIC, -1},
  327. { SDE_IRQ_TYPE_SFI_CMD_2_OUT, -1,
  328. SDE_INTR_DSICMD_2_OUTOF_STATIC, -1},
  329. { SDE_IRQ_TYPE_PROG_LINE, -1, SDE_INTR_PROG_LINE, -1},
  330. { SDE_IRQ_TYPE_WD_TIMER, -1, SDE_INTR_WD_TIMER_0_DONE, -1},
  331. };
  332. static struct sde_irq_type sde_irq_ad4_map[] = {
  333. { SDE_IRQ_TYPE_AD4_BL_DONE, -1, SDE_INTR_BACKLIGHT_UPDATED, -1},
  334. };
  335. static struct sde_irq_type sde_irq_intf_te_map[] = {
  336. { SDE_IRQ_TYPE_INTF_TEAR_AUTO_REF, -1,
  337. SDE_INTR_INTF_TEAR_AUTOREFRESH_DONE, -1},
  338. { SDE_IRQ_TYPE_INTF_TEAR_WR_PTR, -1,
  339. SDE_INTR_INTF_TEAR_WR_PTR, -1},
  340. { SDE_IRQ_TYPE_INTF_TEAR_RD_PTR, -1,
  341. SDE_INTR_INTF_TEAR_RD_PTR, -1},
  342. { SDE_IRQ_TYPE_INTF_TEAR_TEAR_DETECT, -1,
  343. SDE_INTR_INTF_TEAR_TEAR_DETECTED, -1},
  344. { SDE_IRQ_TYPE_INTF_TEAR_TE_ASSERT, -1,
  345. SDE_INTR_INTF_TEAR_TE_DETECTED, -1},
  346. { SDE_IRQ_TYPE_INTF_TEAR_TE_DEASSERT, -1,
  347. SDE_INTR_INTF_TEAR_TE_DEASSERT_DETECTED, -1},
  348. };
  349. static struct sde_irq_type sde_irq_ltm_map[] = {
  350. { SDE_IRQ_TYPE_LTM_STATS_DONE, -1, SDE_INTR_LTM_STATS_DONE, -1},
  351. { SDE_IRQ_TYPE_LTM_STATS_WB_PB, -1, SDE_INTR_LTM_STATS_WB_PB, -1},
  352. };
  353. static struct sde_irq_type sde_irq_wb_map[] = {
  354. { SDE_IRQ_TYPE_WB_PROG_LINE, -1, SDE_INTR_WB_PROG_LINE, -1},
  355. };
  356. static int sde_hw_intr_irqidx_lookup(struct sde_hw_intr *intr,
  357. enum sde_intr_type intr_type, u32 instance_idx)
  358. {
  359. int i;
  360. for (i = 0; i < intr->sde_irq_map_size; i++) {
  361. if (intr_type == intr->sde_irq_map[i].intr_type &&
  362. instance_idx == intr->sde_irq_map[i].instance_idx)
  363. return i;
  364. }
  365. pr_debug("IRQ lookup fail!! intr_type=%d, instance_idx=%d\n",
  366. intr_type, instance_idx);
  367. return -EINVAL;
  368. }
  369. static void sde_hw_intr_dispatch_irq(struct sde_hw_intr *intr,
  370. void (*cbfunc)(void *, int),
  371. void *arg)
  372. {
  373. int reg_idx;
  374. int irq_idx;
  375. int start_idx;
  376. int end_idx;
  377. u32 irq_status;
  378. u32 enable_mask;
  379. unsigned long irq_flags;
  380. if (!intr)
  381. return;
  382. /*
  383. * The dispatcher will save the IRQ status before calling here.
  384. * Now need to go through each IRQ status and find matching
  385. * irq lookup index.
  386. */
  387. spin_lock_irqsave(&intr->irq_lock, irq_flags);
  388. for (reg_idx = 0; reg_idx < intr->sde_irq_size; reg_idx++) {
  389. /*
  390. * Each Interrupt register has dynamic range of indexes,
  391. * initialized during hw_intr_init when sde_irq_tbl is created.
  392. */
  393. start_idx = intr->sde_irq_tbl[reg_idx].map_idx_start;
  394. end_idx = intr->sde_irq_tbl[reg_idx].map_idx_end;
  395. if (start_idx >= intr->sde_irq_map_size ||
  396. end_idx > intr->sde_irq_map_size)
  397. continue;
  398. /* Skip the interrupts which are not enabled */
  399. if (!intr->cache_irq_mask[reg_idx])
  400. continue;
  401. /* Read interrupt status */
  402. irq_status = SDE_REG_READ(&intr->hw, intr->sde_irq_tbl[reg_idx].status_off);
  403. /* Read enable mask */
  404. enable_mask = SDE_REG_READ(&intr->hw, intr->sde_irq_tbl[reg_idx].en_off);
  405. /* and clear the interrupt */
  406. if (irq_status)
  407. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[reg_idx].clr_off,
  408. irq_status);
  409. /* Finally update IRQ status based on enable mask */
  410. irq_status &= enable_mask;
  411. /*
  412. * Search through matching intr status from irq map.
  413. * start_idx and end_idx defined the search range in
  414. * the sde_irq_map.
  415. */
  416. for (irq_idx = start_idx;
  417. (irq_idx < end_idx) && irq_status;
  418. irq_idx++)
  419. if ((irq_status &
  420. intr->sde_irq_map[irq_idx].irq_mask) &&
  421. (intr->sde_irq_map[irq_idx].reg_idx ==
  422. reg_idx)) {
  423. /*
  424. * Once a match on irq mask, perform a callback
  425. * to the given cbfunc. This callback is done
  426. * after clearing the interrupt registers.
  427. */
  428. if (cbfunc)
  429. cbfunc(arg, irq_idx);
  430. /*
  431. * When callback finish, clear the irq_status
  432. * with the matching mask. Once irq_status
  433. * is all cleared, the search can be stopped.
  434. */
  435. irq_status &=
  436. ~intr->sde_irq_map[irq_idx].irq_mask;
  437. }
  438. }
  439. /* ensure register writes go through */
  440. wmb();
  441. spin_unlock_irqrestore(&intr->irq_lock, irq_flags);
  442. }
  443. static int sde_hw_intr_enable_irq_nolock(struct sde_hw_intr *intr, int irq_idx)
  444. {
  445. int reg_idx;
  446. const struct sde_intr_reg *reg;
  447. const struct sde_irq_type *irq;
  448. const char *dbgstr = NULL;
  449. uint32_t cache_irq_mask;
  450. if (!intr)
  451. return -EINVAL;
  452. if (irq_idx < 0 || irq_idx >= intr->sde_irq_map_size) {
  453. pr_err("invalid IRQ index: [%d]\n", irq_idx);
  454. return -EINVAL;
  455. }
  456. irq = &intr->sde_irq_map[irq_idx];
  457. reg_idx = irq->reg_idx;
  458. if (reg_idx < 0 || reg_idx > intr->sde_irq_size) {
  459. pr_err("invalid irq reg:%d irq:%d\n", reg_idx, irq_idx);
  460. return -EINVAL;
  461. }
  462. reg = &intr->sde_irq_tbl[reg_idx];
  463. cache_irq_mask = intr->cache_irq_mask[reg_idx];
  464. if (cache_irq_mask & irq->irq_mask) {
  465. dbgstr = "SDE IRQ already set:";
  466. } else {
  467. dbgstr = "SDE IRQ enabled:";
  468. cache_irq_mask |= irq->irq_mask;
  469. /* Cleaning any pending interrupt */
  470. SDE_REG_WRITE(&intr->hw, reg->clr_off, irq->irq_mask);
  471. /* Enabling interrupts with the new mask */
  472. SDE_REG_WRITE(&intr->hw, reg->en_off, cache_irq_mask);
  473. /* ensure register write goes through */
  474. wmb();
  475. intr->cache_irq_mask[reg_idx] = cache_irq_mask;
  476. }
  477. pr_debug("%s MASK:0x%.8x, CACHE-MASK:0x%.8x\n", dbgstr,
  478. irq->irq_mask, cache_irq_mask);
  479. return 0;
  480. }
  481. static int sde_hw_intr_disable_irq_nolock(struct sde_hw_intr *intr, int irq_idx)
  482. {
  483. int reg_idx;
  484. const struct sde_intr_reg *reg;
  485. const struct sde_irq_type *irq;
  486. const char *dbgstr = NULL;
  487. uint32_t cache_irq_mask;
  488. if (!intr)
  489. return -EINVAL;
  490. if (irq_idx < 0 || irq_idx >= intr->sde_irq_map_size) {
  491. pr_err("invalid IRQ index: [%d]\n", irq_idx);
  492. return -EINVAL;
  493. }
  494. irq = &intr->sde_irq_map[irq_idx];
  495. reg_idx = irq->reg_idx;
  496. if (reg_idx < 0 || reg_idx > intr->sde_irq_size) {
  497. pr_err("invalid irq reg:%d irq:%d\n", reg_idx, irq_idx);
  498. return -EINVAL;
  499. }
  500. reg = &intr->sde_irq_tbl[reg_idx];
  501. cache_irq_mask = intr->cache_irq_mask[reg_idx];
  502. if ((cache_irq_mask & irq->irq_mask) == 0) {
  503. dbgstr = "SDE IRQ is already cleared:";
  504. } else {
  505. dbgstr = "SDE IRQ mask disable:";
  506. cache_irq_mask &= ~irq->irq_mask;
  507. /* Disable interrupts based on the new mask */
  508. SDE_REG_WRITE(&intr->hw, reg->en_off, cache_irq_mask);
  509. /* Cleaning any pending interrupt */
  510. SDE_REG_WRITE(&intr->hw, reg->clr_off, irq->irq_mask);
  511. /* ensure register write goes through */
  512. wmb();
  513. intr->cache_irq_mask[reg_idx] = cache_irq_mask;
  514. }
  515. pr_debug("%s MASK:0x%.8x, CACHE-MASK:0x%.8x\n", dbgstr,
  516. irq->irq_mask, cache_irq_mask);
  517. return 0;
  518. }
  519. static int sde_hw_intr_clear_irqs(struct sde_hw_intr *intr)
  520. {
  521. int i;
  522. if (!intr)
  523. return -EINVAL;
  524. for (i = 0; i < intr->sde_irq_size; i++)
  525. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[i].clr_off,
  526. 0xffffffff);
  527. /* ensure register writes go through */
  528. wmb();
  529. return 0;
  530. }
  531. static int sde_hw_intr_disable_irqs(struct sde_hw_intr *intr)
  532. {
  533. int i;
  534. if (!intr)
  535. return -EINVAL;
  536. for (i = 0; i < intr->sde_irq_size; i++)
  537. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[i].en_off,
  538. 0x00000000);
  539. /* ensure register writes go through */
  540. wmb();
  541. return 0;
  542. }
  543. static int sde_hw_intr_get_interrupt_sources(struct sde_hw_intr *intr,
  544. uint32_t *sources)
  545. {
  546. if (!intr || !sources)
  547. return -EINVAL;
  548. *sources = SDE_REG_READ(&intr->hw, HW_INTR_STATUS);
  549. return 0;
  550. }
  551. static void sde_hw_intr_clear_intr_status_nolock(struct sde_hw_intr *intr,
  552. int irq_idx)
  553. {
  554. int reg_idx;
  555. if (!intr)
  556. return;
  557. if (irq_idx >= intr->sde_irq_map_size || irq_idx < 0) {
  558. pr_err("invalid IRQ index: [%d]\n", irq_idx);
  559. return;
  560. }
  561. reg_idx = intr->sde_irq_map[irq_idx].reg_idx;
  562. if (reg_idx < 0 || reg_idx > intr->sde_irq_size) {
  563. pr_err("invalid irq reg:%d irq:%d\n", reg_idx, irq_idx);
  564. return;
  565. }
  566. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[reg_idx].clr_off,
  567. intr->sde_irq_map[irq_idx].irq_mask);
  568. /* ensure register writes go through */
  569. wmb();
  570. }
  571. static void sde_hw_intr_clear_interrupt_status(struct sde_hw_intr *intr,
  572. int irq_idx)
  573. {
  574. unsigned long irq_flags;
  575. if (!intr)
  576. return;
  577. spin_lock_irqsave(&intr->irq_lock, irq_flags);
  578. sde_hw_intr_clear_intr_status_nolock(intr, irq_idx);
  579. spin_unlock_irqrestore(&intr->irq_lock, irq_flags);
  580. }
  581. static u32 sde_hw_intr_get_intr_status_nolock(struct sde_hw_intr *intr,
  582. int irq_idx, bool clear)
  583. {
  584. int reg_idx;
  585. u32 intr_status;
  586. if (!intr)
  587. return 0;
  588. if (irq_idx >= intr->sde_irq_map_size || irq_idx < 0) {
  589. pr_err("invalid IRQ index: [%d]\n", irq_idx);
  590. return 0;
  591. }
  592. reg_idx = intr->sde_irq_map[irq_idx].reg_idx;
  593. if (reg_idx < 0 || reg_idx > intr->sde_irq_size) {
  594. pr_err("invalid irq reg:%d irq:%d\n", reg_idx, irq_idx);
  595. return 0;
  596. }
  597. intr_status = SDE_REG_READ(&intr->hw,
  598. intr->sde_irq_tbl[reg_idx].status_off) &
  599. intr->sde_irq_map[irq_idx].irq_mask;
  600. if (intr_status && clear)
  601. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[reg_idx].clr_off,
  602. intr_status);
  603. /* ensure register writes go through */
  604. wmb();
  605. return intr_status;
  606. }
  607. static u32 sde_hw_intr_get_interrupt_status(struct sde_hw_intr *intr,
  608. int irq_idx, bool clear)
  609. {
  610. int reg_idx;
  611. unsigned long irq_flags;
  612. u32 intr_status;
  613. if (!intr)
  614. return 0;
  615. if (irq_idx >= intr->sde_irq_map_size || irq_idx < 0) {
  616. pr_err("invalid IRQ index: [%d]\n", irq_idx);
  617. return 0;
  618. }
  619. reg_idx = intr->sde_irq_map[irq_idx].reg_idx;
  620. if (reg_idx < 0 || reg_idx > intr->sde_irq_size) {
  621. pr_err("invalid irq reg:%d irq:%d\n", reg_idx, irq_idx);
  622. return 0;
  623. }
  624. spin_lock_irqsave(&intr->irq_lock, irq_flags);
  625. intr_status = SDE_REG_READ(&intr->hw,
  626. intr->sde_irq_tbl[reg_idx].status_off) &
  627. intr->sde_irq_map[irq_idx].irq_mask;
  628. if (intr_status && clear)
  629. SDE_REG_WRITE(&intr->hw, intr->sde_irq_tbl[reg_idx].clr_off,
  630. intr_status);
  631. /* ensure register writes go through */
  632. wmb();
  633. spin_unlock_irqrestore(&intr->irq_lock, irq_flags);
  634. return intr_status;
  635. }
  636. static int _set_sde_irq_tbl_offset_top(struct sde_intr_reg *sde_irq,
  637. struct sde_intr_irq_offsets *item)
  638. {
  639. u32 base_offset;
  640. if (!sde_irq || !item)
  641. return -EINVAL;
  642. base_offset = item->base_offset;
  643. switch (item->instance_idx) {
  644. case SDE_INTR_TOP_INTR:
  645. sde_irq->clr_off = base_offset + INTR_CLEAR;
  646. sde_irq->en_off = base_offset + INTR_EN;
  647. sde_irq->status_off = base_offset + INTR_STATUS;
  648. break;
  649. case SDE_INTR_TOP_INTR2:
  650. sde_irq->clr_off = base_offset + INTR2_CLEAR;
  651. sde_irq->en_off = base_offset + INTR2_EN;
  652. sde_irq->status_off = base_offset + INTR2_STATUS;
  653. break;
  654. case SDE_INTR_TOP_HIST_INTR:
  655. sde_irq->clr_off = base_offset + HIST_INTR_CLEAR;
  656. sde_irq->en_off = base_offset + HIST_INTR_EN;
  657. sde_irq->status_off = base_offset + HIST_INTR_STATUS;
  658. break;
  659. default:
  660. pr_err("invalid TOP intr for instance %d\n",
  661. item->instance_idx);
  662. return -EINVAL;
  663. }
  664. return 0;
  665. }
  666. static int _set_sde_irq_tbl_offset(struct sde_intr_reg *sde_irq,
  667. struct sde_intr_irq_offsets *item)
  668. {
  669. u32 base_offset, rc = 0;
  670. if (!sde_irq || !item)
  671. return -EINVAL;
  672. base_offset = item->base_offset;
  673. switch (item->type) {
  674. case SDE_INTR_HWBLK_TOP:
  675. rc = _set_sde_irq_tbl_offset_top(sde_irq, item);
  676. break;
  677. case SDE_INTR_HWBLK_INTF:
  678. sde_irq->clr_off = base_offset + INTF_INTR_CLEAR;
  679. sde_irq->en_off = base_offset + INTF_INTR_EN;
  680. sde_irq->status_off = base_offset + INTF_INTR_STATUS;
  681. break;
  682. case SDE_INTR_HWBLK_AD4:
  683. sde_irq->clr_off = base_offset + MDP_AD4_INTR_CLEAR_OFF;
  684. sde_irq->en_off = base_offset + MDP_AD4_INTR_EN_OFF;
  685. sde_irq->status_off = base_offset + MDP_AD4_INTR_STATUS_OFF;
  686. break;
  687. case SDE_INTR_HWBLK_INTF_TEAR:
  688. sde_irq->clr_off = base_offset + MDP_INTF_TEAR_INTR_CLEAR_OFF;
  689. sde_irq->en_off = base_offset + MDP_INTF_TEAR_INTR_EN_OFF;
  690. sde_irq->status_off = base_offset +
  691. MDP_INTF_TEAR_INTR_STATUS_OFF;
  692. break;
  693. case SDE_INTR_HWBLK_LTM:
  694. sde_irq->clr_off = base_offset + MDP_LTM_INTR_CLEAR_OFF;
  695. sde_irq->en_off = base_offset + MDP_LTM_INTR_EN_OFF;
  696. sde_irq->status_off = base_offset + MDP_LTM_INTR_STATUS_OFF;
  697. break;
  698. case SDE_INTR_HWBLK_WB:
  699. sde_irq->clr_off = base_offset + MDP_WB_INTR_CLEAR_OFF;
  700. sde_irq->en_off = base_offset + MDP_WB_INTR_EN_OFF;
  701. sde_irq->status_off = base_offset + MDP_WB_INTR_STATUS_OFF;
  702. break;
  703. default:
  704. pr_err("unrecognized intr blk type %d\n",
  705. item->type);
  706. rc = -EINVAL;
  707. }
  708. return rc;
  709. }
  710. static void __setup_intr_ops(struct sde_hw_intr_ops *ops)
  711. {
  712. ops->irq_idx_lookup = sde_hw_intr_irqidx_lookup;
  713. ops->enable_irq_nolock = sde_hw_intr_enable_irq_nolock;
  714. ops->disable_irq_nolock = sde_hw_intr_disable_irq_nolock;
  715. ops->dispatch_irqs = sde_hw_intr_dispatch_irq;
  716. ops->clear_all_irqs = sde_hw_intr_clear_irqs;
  717. ops->disable_all_irqs = sde_hw_intr_disable_irqs;
  718. ops->get_interrupt_sources = sde_hw_intr_get_interrupt_sources;
  719. ops->clear_interrupt_status = sde_hw_intr_clear_interrupt_status;
  720. ops->get_interrupt_status = sde_hw_intr_get_interrupt_status;
  721. ops->get_intr_status_nolock = sde_hw_intr_get_intr_status_nolock;
  722. }
  723. static struct sde_mdss_base_cfg *__intr_offset(struct sde_mdss_cfg *m,
  724. void __iomem *addr, struct sde_hw_blk_reg_map *hw)
  725. {
  726. if (!m || !addr || !hw || m->mdp_count == 0)
  727. return NULL;
  728. hw->base_off = addr;
  729. hw->blk_off = m->mdss[0].base;
  730. hw->hw_rev = m->hw_rev;
  731. return &m->mdss[0];
  732. }
  733. void sde_hw_intr_destroy(struct sde_hw_intr *intr)
  734. {
  735. if (intr) {
  736. kfree(intr->sde_irq_tbl);
  737. kfree(intr->sde_irq_map);
  738. kfree(intr->cache_irq_mask);
  739. kfree(intr);
  740. }
  741. }
  742. static inline u32 _get_irq_map_size_top(enum sde_intr_top_intr inst)
  743. {
  744. u32 ret = 0;
  745. switch (inst) {
  746. case SDE_INTR_TOP_INTR:
  747. ret = ARRAY_SIZE(sde_irq_intr_map);
  748. break;
  749. case SDE_INTR_TOP_INTR2:
  750. ret = ARRAY_SIZE(sde_irq_intr2_map);
  751. break;
  752. case SDE_INTR_TOP_HIST_INTR:
  753. ret = ARRAY_SIZE(sde_irq_hist_map);
  754. break;
  755. default:
  756. pr_err("invalid top inst:%d\n", inst);
  757. }
  758. return ret;
  759. }
  760. static inline u32 _get_irq_map_size(struct sde_intr_irq_offsets *item)
  761. {
  762. u32 ret = 0;
  763. switch (item->type) {
  764. case SDE_INTR_HWBLK_TOP:
  765. ret = _get_irq_map_size_top(item->instance_idx);
  766. break;
  767. case SDE_INTR_HWBLK_INTF:
  768. ret = ARRAY_SIZE(sde_irq_intf_map);
  769. break;
  770. case SDE_INTR_HWBLK_AD4:
  771. ret = ARRAY_SIZE(sde_irq_ad4_map);
  772. break;
  773. case SDE_INTR_HWBLK_INTF_TEAR:
  774. ret = ARRAY_SIZE(sde_irq_intf_te_map);
  775. break;
  776. case SDE_INTR_HWBLK_LTM:
  777. ret = ARRAY_SIZE(sde_irq_ltm_map);
  778. break;
  779. case SDE_INTR_HWBLK_WB:
  780. ret = ARRAY_SIZE(sde_irq_wb_map);
  781. break;
  782. default:
  783. pr_err("invalid type: %d\n", item->type);
  784. }
  785. return ret;
  786. }
  787. static inline struct sde_irq_type *_get_irq_map_addr_top(
  788. enum sde_intr_top_intr inst)
  789. {
  790. struct sde_irq_type *ret = NULL;
  791. switch (inst) {
  792. case SDE_INTR_TOP_INTR:
  793. ret = sde_irq_intr_map;
  794. break;
  795. case SDE_INTR_TOP_INTR2:
  796. ret = sde_irq_intr2_map;
  797. break;
  798. case SDE_INTR_TOP_HIST_INTR:
  799. ret = sde_irq_hist_map;
  800. break;
  801. default:
  802. pr_err("invalid top inst:%d\n", inst);
  803. }
  804. return ret;
  805. }
  806. static inline struct sde_irq_type *_get_irq_map_addr(
  807. struct sde_intr_irq_offsets *item)
  808. {
  809. struct sde_irq_type *ret = NULL;
  810. switch (item->type) {
  811. case SDE_INTR_HWBLK_TOP:
  812. ret = _get_irq_map_addr_top(item->instance_idx);
  813. break;
  814. case SDE_INTR_HWBLK_INTF:
  815. ret = sde_irq_intf_map;
  816. break;
  817. case SDE_INTR_HWBLK_AD4:
  818. ret = sde_irq_ad4_map;
  819. break;
  820. case SDE_INTR_HWBLK_INTF_TEAR:
  821. ret = sde_irq_intf_te_map;
  822. break;
  823. case SDE_INTR_HWBLK_LTM:
  824. ret = sde_irq_ltm_map;
  825. break;
  826. case SDE_INTR_HWBLK_WB:
  827. ret = sde_irq_wb_map;
  828. break;
  829. default:
  830. pr_err("invalid type: %d\n", item->type);
  831. }
  832. return ret;
  833. }
  834. static int _sde_copy_regs(struct sde_irq_type *sde_irq_map, u32 size,
  835. struct sde_intr_irq_offsets *item, u32 low_idx, u32 high_idx)
  836. {
  837. int i, j = 0;
  838. struct sde_irq_type *src = _get_irq_map_addr(item);
  839. u32 src_size = _get_irq_map_size(item);
  840. if (!src)
  841. return -EINVAL;
  842. if (low_idx >= size || high_idx > size ||
  843. (high_idx - low_idx > src_size)) {
  844. pr_err("invalid size l:%d h:%d dst:%d src:%d\n",
  845. low_idx, high_idx, size, src_size);
  846. return -EINVAL;
  847. }
  848. for (i = low_idx; i < high_idx; i++)
  849. sde_irq_map[i] = src[j++];
  850. return 0;
  851. }
  852. static int _sde_hw_intr_init_irq_tables(struct sde_hw_intr *intr,
  853. struct sde_mdss_cfg *m)
  854. {
  855. struct sde_intr_irq_offsets *item;
  856. int i, sde_irq_tbl_idx = 0, ret = 0;
  857. u32 low_idx, high_idx;
  858. u32 sde_irq_map_idx = 0;
  859. /* Initialize offsets in the sde_irq_map & sde_irq_tbl tables */
  860. list_for_each_entry(item, &m->irq_offset_list, list) {
  861. low_idx = sde_irq_map_idx;
  862. high_idx = low_idx + _get_irq_map_size(item);
  863. if (sde_irq_tbl_idx >= intr->sde_irq_size ||
  864. sde_irq_tbl_idx < 0) {
  865. ret = -EINVAL;
  866. goto exit;
  867. }
  868. /* init sde_irq_map with the global irq mapping table */
  869. if (_sde_copy_regs(intr->sde_irq_map, intr->sde_irq_map_size,
  870. item, low_idx, high_idx)) {
  871. ret = -EINVAL;
  872. goto exit;
  873. }
  874. /* init irq map with its reg & instance idxs in the irq tbl */
  875. for (i = low_idx; i < high_idx; i++) {
  876. intr->sde_irq_map[i].reg_idx = sde_irq_tbl_idx;
  877. if (item->type != SDE_INTR_HWBLK_TOP)
  878. intr->sde_irq_map[i].instance_idx =
  879. item->instance_idx;
  880. pr_debug("sde_irq_map[%d].reg_idx=%d .inst_idx = %d\n",
  881. i, sde_irq_tbl_idx, item->instance_idx);
  882. }
  883. /* track the idx of the mapping table for this irq in
  884. * sde_irq_map, this to only access the indexes of this
  885. * irq during the irq dispatch
  886. */
  887. intr->sde_irq_tbl[sde_irq_tbl_idx].map_idx_start = low_idx;
  888. intr->sde_irq_tbl[sde_irq_tbl_idx].map_idx_end = high_idx;
  889. ret = _set_sde_irq_tbl_offset(
  890. &intr->sde_irq_tbl[sde_irq_tbl_idx], item);
  891. if (ret)
  892. goto exit;
  893. /* increment idx for both tables accordingly */
  894. sde_irq_tbl_idx++;
  895. sde_irq_map_idx = high_idx;
  896. }
  897. exit:
  898. sde_hw_catalog_irq_offset_list_delete(&m->irq_offset_list);
  899. return ret;
  900. }
  901. struct sde_hw_intr *sde_hw_intr_init(void __iomem *addr,
  902. struct sde_mdss_cfg *m)
  903. {
  904. struct sde_hw_intr *intr = NULL;
  905. struct sde_mdss_base_cfg *cfg;
  906. struct sde_intr_irq_offsets *item;
  907. u32 irq_regs_count = 0;
  908. u32 irq_map_count = 0;
  909. u32 size;
  910. int ret = 0;
  911. if (!addr || !m) {
  912. ret = -EINVAL;
  913. goto exit;
  914. }
  915. intr = kzalloc(sizeof(*intr), GFP_KERNEL);
  916. if (!intr) {
  917. ret = -ENOMEM;
  918. goto exit;
  919. }
  920. cfg = __intr_offset(m, addr, &intr->hw);
  921. if (!cfg) {
  922. ret = -EINVAL;
  923. goto exit;
  924. }
  925. __setup_intr_ops(&intr->ops);
  926. /* check how many irq's this target supports */
  927. list_for_each_entry(item, &m->irq_offset_list, list) {
  928. size = _get_irq_map_size(item);
  929. if (!size || irq_map_count >= UINT_MAX - size) {
  930. pr_err("wrong map cnt idx:%d blk:%d/%d sz:%d cnt:%d\n",
  931. irq_regs_count, item->type, item->instance_idx,
  932. size, irq_map_count);
  933. ret = -EINVAL;
  934. goto exit;
  935. }
  936. irq_regs_count++;
  937. irq_map_count += size;
  938. }
  939. if (irq_regs_count == 0 || irq_map_count == 0) {
  940. pr_err("invalid irq map: %d %d\n",
  941. irq_regs_count, irq_map_count);
  942. ret = -EINVAL;
  943. goto exit;
  944. }
  945. /* Allocate table for the irq registers */
  946. intr->sde_irq_size = irq_regs_count;
  947. intr->sde_irq_tbl = kcalloc(irq_regs_count, sizeof(*intr->sde_irq_tbl),
  948. GFP_KERNEL);
  949. if (intr->sde_irq_tbl == NULL) {
  950. ret = -ENOMEM;
  951. goto exit;
  952. }
  953. /* Allocate table with the valid interrupts bits */
  954. intr->sde_irq_map_size = irq_map_count;
  955. intr->sde_irq_map = kcalloc(irq_map_count, sizeof(*intr->sde_irq_map),
  956. GFP_KERNEL);
  957. if (intr->sde_irq_map == NULL) {
  958. ret = -ENOMEM;
  959. goto exit;
  960. }
  961. /* Initialize IRQs tables */
  962. ret = _sde_hw_intr_init_irq_tables(intr, m);
  963. if (ret)
  964. goto exit;
  965. intr->cache_irq_mask = kcalloc(intr->sde_irq_size,
  966. sizeof(*intr->cache_irq_mask), GFP_KERNEL);
  967. if (intr->cache_irq_mask == NULL) {
  968. ret = -ENOMEM;
  969. goto exit;
  970. }
  971. spin_lock_init(&intr->irq_lock);
  972. exit:
  973. if (ret) {
  974. sde_hw_intr_destroy(intr);
  975. return ERR_PTR(ret);
  976. }
  977. return intr;
  978. }