sde_hw_interrupts.c 34 KB

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