sde_hw_interrupts.c 40 KB

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