sde_hw_interrupts.c 33 KB

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