bdisp-hw.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics SA 2014
  4. * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
  5. */
  6. #include <linux/delay.h>
  7. #include "bdisp.h"
  8. #include "bdisp-filter.h"
  9. #include "bdisp-reg.h"
  10. /* Max width of the source frame in a single node */
  11. #define MAX_SRC_WIDTH 2048
  12. /* Reset & boot poll config */
  13. #define POLL_RST_MAX 500
  14. #define POLL_RST_DELAY_MS 2
  15. enum bdisp_target_plan {
  16. BDISP_RGB,
  17. BDISP_Y,
  18. BDISP_CBCR
  19. };
  20. struct bdisp_op_cfg {
  21. bool cconv; /* RGB - YUV conversion */
  22. bool hflip; /* Horizontal flip */
  23. bool vflip; /* Vertical flip */
  24. bool wide; /* Wide (>MAX_SRC_WIDTH) */
  25. bool scale; /* Scale */
  26. u16 h_inc; /* Horizontal increment in 6.10 format */
  27. u16 v_inc; /* Vertical increment in 6.10 format */
  28. bool src_interlaced; /* is the src an interlaced buffer */
  29. u8 src_nbp; /* nb of planes of the src */
  30. bool src_yuv; /* is the src a YUV color format */
  31. bool src_420; /* is the src 4:2:0 chroma subsampled */
  32. u8 dst_nbp; /* nb of planes of the dst */
  33. bool dst_yuv; /* is the dst a YUV color format */
  34. bool dst_420; /* is the dst 4:2:0 chroma subsampled */
  35. };
  36. struct bdisp_filter_addr {
  37. u16 min; /* Filter min scale factor (6.10 fixed point) */
  38. u16 max; /* Filter max scale factor (6.10 fixed point) */
  39. void *virt; /* Virtual address for filter table */
  40. dma_addr_t paddr; /* Physical address for filter table */
  41. };
  42. static const struct bdisp_filter_h_spec bdisp_h_spec[] = {
  43. {
  44. .min = 0,
  45. .max = 921,
  46. .coef = {
  47. 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0xff, 0x07, 0x3d, 0xfc, 0x01, 0x00,
  49. 0x00, 0x01, 0xfd, 0x11, 0x36, 0xf9, 0x02, 0x00,
  50. 0x00, 0x01, 0xfb, 0x1b, 0x2e, 0xf9, 0x02, 0x00,
  51. 0x00, 0x01, 0xf9, 0x26, 0x26, 0xf9, 0x01, 0x00,
  52. 0x00, 0x02, 0xf9, 0x30, 0x19, 0xfb, 0x01, 0x00,
  53. 0x00, 0x02, 0xf9, 0x39, 0x0e, 0xfd, 0x01, 0x00,
  54. 0x00, 0x01, 0xfc, 0x3e, 0x06, 0xff, 0x00, 0x00
  55. }
  56. },
  57. {
  58. .min = 921,
  59. .max = 1024,
  60. .coef = {
  61. 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  62. 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
  63. 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
  64. 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
  65. 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
  66. 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
  67. 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
  68. 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
  69. }
  70. },
  71. {
  72. .min = 1024,
  73. .max = 1126,
  74. .coef = {
  75. 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  76. 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
  77. 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
  78. 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
  79. 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
  80. 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
  81. 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
  82. 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
  83. }
  84. },
  85. {
  86. .min = 1126,
  87. .max = 1228,
  88. .coef = {
  89. 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  90. 0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
  91. 0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
  92. 0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
  93. 0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
  94. 0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
  95. 0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
  96. 0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
  97. }
  98. },
  99. {
  100. .min = 1228,
  101. .max = 1331,
  102. .coef = {
  103. 0xfd, 0x04, 0xfc, 0x05, 0x39, 0x05, 0xfc, 0x04,
  104. 0xfc, 0x06, 0xf9, 0x0c, 0x39, 0xfe, 0x00, 0x02,
  105. 0xfb, 0x08, 0xf6, 0x17, 0x35, 0xf9, 0x02, 0x00,
  106. 0xfc, 0x08, 0xf4, 0x20, 0x30, 0xf4, 0x05, 0xff,
  107. 0xfd, 0x07, 0xf4, 0x29, 0x28, 0xf3, 0x07, 0xfd,
  108. 0xff, 0x05, 0xf5, 0x31, 0x1f, 0xf3, 0x08, 0xfc,
  109. 0x00, 0x02, 0xf9, 0x38, 0x14, 0xf6, 0x08, 0xfb,
  110. 0x02, 0x00, 0xff, 0x3a, 0x0b, 0xf8, 0x06, 0xfc
  111. }
  112. },
  113. {
  114. .min = 1331,
  115. .max = 1433,
  116. .coef = {
  117. 0xfc, 0x06, 0xf9, 0x09, 0x34, 0x09, 0xf9, 0x06,
  118. 0xfd, 0x07, 0xf7, 0x10, 0x32, 0x02, 0xfc, 0x05,
  119. 0xfe, 0x07, 0xf6, 0x17, 0x2f, 0xfc, 0xff, 0x04,
  120. 0xff, 0x06, 0xf5, 0x20, 0x2a, 0xf9, 0x01, 0x02,
  121. 0x00, 0x04, 0xf6, 0x27, 0x25, 0xf6, 0x04, 0x00,
  122. 0x02, 0x01, 0xf9, 0x2d, 0x1d, 0xf5, 0x06, 0xff,
  123. 0x04, 0xff, 0xfd, 0x31, 0x15, 0xf5, 0x07, 0xfe,
  124. 0x05, 0xfc, 0x02, 0x35, 0x0d, 0xf7, 0x07, 0xfd
  125. }
  126. },
  127. {
  128. .min = 1433,
  129. .max = 1536,
  130. .coef = {
  131. 0xfe, 0x06, 0xf8, 0x0b, 0x30, 0x0b, 0xf8, 0x06,
  132. 0xff, 0x06, 0xf7, 0x12, 0x2d, 0x05, 0xfa, 0x06,
  133. 0x00, 0x04, 0xf6, 0x18, 0x2c, 0x00, 0xfc, 0x06,
  134. 0x01, 0x02, 0xf7, 0x1f, 0x27, 0xfd, 0xff, 0x04,
  135. 0x03, 0x00, 0xf9, 0x24, 0x24, 0xf9, 0x00, 0x03,
  136. 0x04, 0xff, 0xfd, 0x29, 0x1d, 0xf7, 0x02, 0x01,
  137. 0x06, 0xfc, 0x00, 0x2d, 0x17, 0xf6, 0x04, 0x00,
  138. 0x06, 0xfa, 0x05, 0x30, 0x0f, 0xf7, 0x06, 0xff
  139. }
  140. },
  141. {
  142. .min = 1536,
  143. .max = 2048,
  144. .coef = {
  145. 0x05, 0xfd, 0xfb, 0x13, 0x25, 0x13, 0xfb, 0xfd,
  146. 0x05, 0xfc, 0xfd, 0x17, 0x24, 0x0f, 0xf9, 0xff,
  147. 0x04, 0xfa, 0xff, 0x1b, 0x24, 0x0b, 0xf9, 0x00,
  148. 0x03, 0xf9, 0x01, 0x1f, 0x23, 0x08, 0xf8, 0x01,
  149. 0x02, 0xf9, 0x04, 0x22, 0x20, 0x04, 0xf9, 0x02,
  150. 0x01, 0xf8, 0x08, 0x25, 0x1d, 0x01, 0xf9, 0x03,
  151. 0x00, 0xf9, 0x0c, 0x25, 0x1a, 0xfe, 0xfa, 0x04,
  152. 0xff, 0xf9, 0x10, 0x26, 0x15, 0xfc, 0xfc, 0x05
  153. }
  154. },
  155. {
  156. .min = 2048,
  157. .max = 3072,
  158. .coef = {
  159. 0xfc, 0xfd, 0x06, 0x13, 0x18, 0x13, 0x06, 0xfd,
  160. 0xfc, 0xfe, 0x08, 0x15, 0x17, 0x12, 0x04, 0xfc,
  161. 0xfb, 0xfe, 0x0a, 0x16, 0x18, 0x10, 0x03, 0xfc,
  162. 0xfb, 0x00, 0x0b, 0x18, 0x17, 0x0f, 0x01, 0xfb,
  163. 0xfb, 0x00, 0x0d, 0x19, 0x17, 0x0d, 0x00, 0xfb,
  164. 0xfb, 0x01, 0x0f, 0x19, 0x16, 0x0b, 0x00, 0xfb,
  165. 0xfc, 0x03, 0x11, 0x19, 0x15, 0x09, 0xfe, 0xfb,
  166. 0xfc, 0x04, 0x12, 0x1a, 0x12, 0x08, 0xfe, 0xfc
  167. }
  168. },
  169. {
  170. .min = 3072,
  171. .max = 4096,
  172. .coef = {
  173. 0xfe, 0x02, 0x09, 0x0f, 0x0e, 0x0f, 0x09, 0x02,
  174. 0xff, 0x02, 0x09, 0x0f, 0x10, 0x0e, 0x08, 0x01,
  175. 0xff, 0x03, 0x0a, 0x10, 0x10, 0x0d, 0x07, 0x00,
  176. 0x00, 0x04, 0x0b, 0x10, 0x0f, 0x0c, 0x06, 0x00,
  177. 0x00, 0x05, 0x0c, 0x10, 0x0e, 0x0c, 0x05, 0x00,
  178. 0x00, 0x06, 0x0c, 0x11, 0x0e, 0x0b, 0x04, 0x00,
  179. 0x00, 0x07, 0x0d, 0x11, 0x0f, 0x0a, 0x03, 0xff,
  180. 0x01, 0x08, 0x0e, 0x11, 0x0e, 0x09, 0x02, 0xff
  181. }
  182. },
  183. {
  184. .min = 4096,
  185. .max = 5120,
  186. .coef = {
  187. 0x00, 0x04, 0x09, 0x0c, 0x0e, 0x0c, 0x09, 0x04,
  188. 0x01, 0x05, 0x09, 0x0c, 0x0d, 0x0c, 0x08, 0x04,
  189. 0x01, 0x05, 0x0a, 0x0c, 0x0e, 0x0b, 0x08, 0x03,
  190. 0x02, 0x06, 0x0a, 0x0d, 0x0c, 0x0b, 0x07, 0x03,
  191. 0x02, 0x07, 0x0a, 0x0d, 0x0d, 0x0a, 0x07, 0x02,
  192. 0x03, 0x07, 0x0b, 0x0d, 0x0c, 0x0a, 0x06, 0x02,
  193. 0x03, 0x08, 0x0b, 0x0d, 0x0d, 0x0a, 0x05, 0x01,
  194. 0x04, 0x08, 0x0c, 0x0d, 0x0c, 0x09, 0x05, 0x01
  195. }
  196. },
  197. {
  198. .min = 5120,
  199. .max = 65535,
  200. .coef = {
  201. 0x03, 0x06, 0x09, 0x0b, 0x09, 0x0b, 0x09, 0x06,
  202. 0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
  203. 0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
  204. 0x04, 0x07, 0x09, 0x0b, 0x0b, 0x0a, 0x08, 0x04,
  205. 0x04, 0x07, 0x0a, 0x0b, 0x0b, 0x0a, 0x07, 0x04,
  206. 0x04, 0x08, 0x0a, 0x0b, 0x0b, 0x09, 0x07, 0x04,
  207. 0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03,
  208. 0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03
  209. }
  210. }
  211. };
  212. #define NB_H_FILTER ARRAY_SIZE(bdisp_h_spec)
  213. static const struct bdisp_filter_v_spec bdisp_v_spec[] = {
  214. {
  215. .min = 0,
  216. .max = 1024,
  217. .coef = {
  218. 0x00, 0x00, 0x40, 0x00, 0x00,
  219. 0x00, 0x06, 0x3d, 0xfd, 0x00,
  220. 0xfe, 0x0f, 0x38, 0xfb, 0x00,
  221. 0xfd, 0x19, 0x2f, 0xfb, 0x00,
  222. 0xfc, 0x24, 0x24, 0xfc, 0x00,
  223. 0xfb, 0x2f, 0x19, 0xfd, 0x00,
  224. 0xfb, 0x38, 0x0f, 0xfe, 0x00,
  225. 0xfd, 0x3d, 0x06, 0x00, 0x00
  226. }
  227. },
  228. {
  229. .min = 1024,
  230. .max = 1331,
  231. .coef = {
  232. 0xfc, 0x05, 0x3e, 0x05, 0xfc,
  233. 0xf8, 0x0e, 0x3b, 0xff, 0x00,
  234. 0xf5, 0x18, 0x38, 0xf9, 0x02,
  235. 0xf4, 0x21, 0x31, 0xf5, 0x05,
  236. 0xf4, 0x2a, 0x27, 0xf4, 0x07,
  237. 0xf6, 0x30, 0x1e, 0xf4, 0x08,
  238. 0xf9, 0x35, 0x15, 0xf6, 0x07,
  239. 0xff, 0x37, 0x0b, 0xf9, 0x06
  240. }
  241. },
  242. {
  243. .min = 1331,
  244. .max = 1433,
  245. .coef = {
  246. 0xf8, 0x0a, 0x3c, 0x0a, 0xf8,
  247. 0xf6, 0x12, 0x3b, 0x02, 0xfb,
  248. 0xf4, 0x1b, 0x35, 0xfd, 0xff,
  249. 0xf4, 0x23, 0x30, 0xf8, 0x01,
  250. 0xf6, 0x29, 0x27, 0xf6, 0x04,
  251. 0xf9, 0x2e, 0x1e, 0xf5, 0x06,
  252. 0xfd, 0x31, 0x16, 0xf6, 0x06,
  253. 0x02, 0x32, 0x0d, 0xf8, 0x07
  254. }
  255. },
  256. {
  257. .min = 1433,
  258. .max = 1536,
  259. .coef = {
  260. 0xf6, 0x0e, 0x38, 0x0e, 0xf6,
  261. 0xf5, 0x15, 0x38, 0x06, 0xf8,
  262. 0xf5, 0x1d, 0x33, 0x00, 0xfb,
  263. 0xf6, 0x23, 0x2d, 0xfc, 0xfe,
  264. 0xf9, 0x28, 0x26, 0xf9, 0x00,
  265. 0xfc, 0x2c, 0x1e, 0xf7, 0x03,
  266. 0x00, 0x2e, 0x18, 0xf6, 0x04,
  267. 0x05, 0x2e, 0x11, 0xf7, 0x05
  268. }
  269. },
  270. {
  271. .min = 1536,
  272. .max = 2048,
  273. .coef = {
  274. 0xfb, 0x13, 0x24, 0x13, 0xfb,
  275. 0xfd, 0x17, 0x23, 0x0f, 0xfa,
  276. 0xff, 0x1a, 0x23, 0x0b, 0xf9,
  277. 0x01, 0x1d, 0x22, 0x07, 0xf9,
  278. 0x04, 0x20, 0x1f, 0x04, 0xf9,
  279. 0x07, 0x22, 0x1c, 0x01, 0xfa,
  280. 0x0b, 0x24, 0x17, 0xff, 0xfb,
  281. 0x0f, 0x24, 0x14, 0xfd, 0xfc
  282. }
  283. },
  284. {
  285. .min = 2048,
  286. .max = 3072,
  287. .coef = {
  288. 0x05, 0x10, 0x16, 0x10, 0x05,
  289. 0x06, 0x11, 0x16, 0x0f, 0x04,
  290. 0x08, 0x13, 0x15, 0x0e, 0x02,
  291. 0x09, 0x14, 0x16, 0x0c, 0x01,
  292. 0x0b, 0x15, 0x15, 0x0b, 0x00,
  293. 0x0d, 0x16, 0x13, 0x0a, 0x00,
  294. 0x0f, 0x17, 0x13, 0x08, 0xff,
  295. 0x11, 0x18, 0x12, 0x07, 0xfe
  296. }
  297. },
  298. {
  299. .min = 3072,
  300. .max = 4096,
  301. .coef = {
  302. 0x09, 0x0f, 0x10, 0x0f, 0x09,
  303. 0x09, 0x0f, 0x12, 0x0e, 0x08,
  304. 0x0a, 0x10, 0x11, 0x0e, 0x07,
  305. 0x0b, 0x11, 0x11, 0x0d, 0x06,
  306. 0x0c, 0x11, 0x12, 0x0c, 0x05,
  307. 0x0d, 0x12, 0x11, 0x0c, 0x04,
  308. 0x0e, 0x12, 0x11, 0x0b, 0x04,
  309. 0x0f, 0x13, 0x11, 0x0a, 0x03
  310. }
  311. },
  312. {
  313. .min = 4096,
  314. .max = 5120,
  315. .coef = {
  316. 0x0a, 0x0e, 0x10, 0x0e, 0x0a,
  317. 0x0b, 0x0e, 0x0f, 0x0e, 0x0a,
  318. 0x0b, 0x0f, 0x10, 0x0d, 0x09,
  319. 0x0c, 0x0f, 0x10, 0x0d, 0x08,
  320. 0x0d, 0x0f, 0x0f, 0x0d, 0x08,
  321. 0x0d, 0x10, 0x10, 0x0c, 0x07,
  322. 0x0e, 0x10, 0x0f, 0x0c, 0x07,
  323. 0x0f, 0x10, 0x10, 0x0b, 0x06
  324. }
  325. },
  326. {
  327. .min = 5120,
  328. .max = 65535,
  329. .coef = {
  330. 0x0b, 0x0e, 0x0e, 0x0e, 0x0b,
  331. 0x0b, 0x0e, 0x0f, 0x0d, 0x0b,
  332. 0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
  333. 0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
  334. 0x0d, 0x0f, 0x0e, 0x0d, 0x09,
  335. 0x0d, 0x0f, 0x0f, 0x0c, 0x09,
  336. 0x0e, 0x0f, 0x0e, 0x0c, 0x09,
  337. 0x0e, 0x0f, 0x0f, 0x0c, 0x08
  338. }
  339. }
  340. };
  341. #define NB_V_FILTER ARRAY_SIZE(bdisp_v_spec)
  342. static struct bdisp_filter_addr bdisp_h_filter[NB_H_FILTER];
  343. static struct bdisp_filter_addr bdisp_v_filter[NB_V_FILTER];
  344. /**
  345. * bdisp_hw_reset
  346. * @bdisp: bdisp entity
  347. *
  348. * Resets HW
  349. *
  350. * RETURNS:
  351. * 0 on success.
  352. */
  353. int bdisp_hw_reset(struct bdisp_dev *bdisp)
  354. {
  355. unsigned int i;
  356. dev_dbg(bdisp->dev, "%s\n", __func__);
  357. /* Mask Interrupt */
  358. writel(0, bdisp->regs + BLT_ITM0);
  359. /* Reset */
  360. writel(readl(bdisp->regs + BLT_CTL) | BLT_CTL_RESET,
  361. bdisp->regs + BLT_CTL);
  362. writel(0, bdisp->regs + BLT_CTL);
  363. /* Wait for reset done */
  364. for (i = 0; i < POLL_RST_MAX; i++) {
  365. if (readl(bdisp->regs + BLT_STA1) & BLT_STA1_IDLE)
  366. break;
  367. udelay(POLL_RST_DELAY_MS * 1000);
  368. }
  369. if (i == POLL_RST_MAX)
  370. dev_err(bdisp->dev, "Reset timeout\n");
  371. return (i == POLL_RST_MAX) ? -EAGAIN : 0;
  372. }
  373. /**
  374. * bdisp_hw_get_and_clear_irq
  375. * @bdisp: bdisp entity
  376. *
  377. * Read then reset interrupt status
  378. *
  379. * RETURNS:
  380. * 0 if expected interrupt was raised.
  381. */
  382. int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp)
  383. {
  384. u32 its;
  385. its = readl(bdisp->regs + BLT_ITS);
  386. /* Check for the only expected IT: LastNode of AQ1 */
  387. if (!(its & BLT_ITS_AQ1_LNA)) {
  388. dev_dbg(bdisp->dev, "Unexpected IT status: 0x%08X\n", its);
  389. writel(its, bdisp->regs + BLT_ITS);
  390. return -1;
  391. }
  392. /* Clear and mask */
  393. writel(its, bdisp->regs + BLT_ITS);
  394. writel(0, bdisp->regs + BLT_ITM0);
  395. return 0;
  396. }
  397. /**
  398. * bdisp_hw_free_nodes
  399. * @ctx: bdisp context
  400. *
  401. * Free node memory
  402. *
  403. * RETURNS:
  404. * None
  405. */
  406. void bdisp_hw_free_nodes(struct bdisp_ctx *ctx)
  407. {
  408. if (ctx && ctx->node[0])
  409. dma_free_attrs(ctx->bdisp_dev->dev,
  410. sizeof(struct bdisp_node) * MAX_NB_NODE,
  411. ctx->node[0], ctx->node_paddr[0],
  412. DMA_ATTR_WRITE_COMBINE);
  413. }
  414. /**
  415. * bdisp_hw_alloc_nodes
  416. * @ctx: bdisp context
  417. *
  418. * Allocate dma memory for nodes
  419. *
  420. * RETURNS:
  421. * 0 on success
  422. */
  423. int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx)
  424. {
  425. struct device *dev = ctx->bdisp_dev->dev;
  426. unsigned int i, node_size = sizeof(struct bdisp_node);
  427. void *base;
  428. dma_addr_t paddr;
  429. /* Allocate all the nodes within a single memory page */
  430. base = dma_alloc_attrs(dev, node_size * MAX_NB_NODE, &paddr,
  431. GFP_KERNEL, DMA_ATTR_WRITE_COMBINE);
  432. if (!base) {
  433. dev_err(dev, "%s no mem\n", __func__);
  434. return -ENOMEM;
  435. }
  436. memset(base, 0, node_size * MAX_NB_NODE);
  437. for (i = 0; i < MAX_NB_NODE; i++) {
  438. ctx->node[i] = base;
  439. ctx->node_paddr[i] = paddr;
  440. dev_dbg(dev, "node[%d]=0x%p (paddr=%pad)\n", i, ctx->node[i],
  441. &paddr);
  442. base += node_size;
  443. paddr += node_size;
  444. }
  445. return 0;
  446. }
  447. /**
  448. * bdisp_hw_free_filters
  449. * @dev: device
  450. *
  451. * Free filters memory
  452. *
  453. * RETURNS:
  454. * None
  455. */
  456. void bdisp_hw_free_filters(struct device *dev)
  457. {
  458. int size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
  459. if (bdisp_h_filter[0].virt)
  460. dma_free_attrs(dev, size, bdisp_h_filter[0].virt,
  461. bdisp_h_filter[0].paddr, DMA_ATTR_WRITE_COMBINE);
  462. }
  463. /**
  464. * bdisp_hw_alloc_filters
  465. * @dev: device
  466. *
  467. * Allocate dma memory for filters
  468. *
  469. * RETURNS:
  470. * 0 on success
  471. */
  472. int bdisp_hw_alloc_filters(struct device *dev)
  473. {
  474. unsigned int i, size;
  475. void *base;
  476. dma_addr_t paddr;
  477. /* Allocate all the filters within a single memory page */
  478. size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
  479. base = dma_alloc_attrs(dev, size, &paddr, GFP_KERNEL | GFP_DMA,
  480. DMA_ATTR_WRITE_COMBINE);
  481. if (!base)
  482. return -ENOMEM;
  483. /* Setup filter addresses */
  484. for (i = 0; i < NB_H_FILTER; i++) {
  485. bdisp_h_filter[i].min = bdisp_h_spec[i].min;
  486. bdisp_h_filter[i].max = bdisp_h_spec[i].max;
  487. memcpy(base, bdisp_h_spec[i].coef, BDISP_HF_NB);
  488. bdisp_h_filter[i].virt = base;
  489. bdisp_h_filter[i].paddr = paddr;
  490. base += BDISP_HF_NB;
  491. paddr += BDISP_HF_NB;
  492. }
  493. for (i = 0; i < NB_V_FILTER; i++) {
  494. bdisp_v_filter[i].min = bdisp_v_spec[i].min;
  495. bdisp_v_filter[i].max = bdisp_v_spec[i].max;
  496. memcpy(base, bdisp_v_spec[i].coef, BDISP_VF_NB);
  497. bdisp_v_filter[i].virt = base;
  498. bdisp_v_filter[i].paddr = paddr;
  499. base += BDISP_VF_NB;
  500. paddr += BDISP_VF_NB;
  501. }
  502. return 0;
  503. }
  504. /**
  505. * bdisp_hw_get_hf_addr
  506. * @inc: resize increment
  507. *
  508. * Find the horizontal filter table that fits the resize increment
  509. *
  510. * RETURNS:
  511. * table physical address
  512. */
  513. static dma_addr_t bdisp_hw_get_hf_addr(u16 inc)
  514. {
  515. unsigned int i;
  516. for (i = NB_H_FILTER - 1; i > 0; i--)
  517. if ((bdisp_h_filter[i].min < inc) &&
  518. (inc <= bdisp_h_filter[i].max))
  519. break;
  520. return bdisp_h_filter[i].paddr;
  521. }
  522. /**
  523. * bdisp_hw_get_vf_addr
  524. * @inc: resize increment
  525. *
  526. * Find the vertical filter table that fits the resize increment
  527. *
  528. * RETURNS:
  529. * table physical address
  530. */
  531. static dma_addr_t bdisp_hw_get_vf_addr(u16 inc)
  532. {
  533. unsigned int i;
  534. for (i = NB_V_FILTER - 1; i > 0; i--)
  535. if ((bdisp_v_filter[i].min < inc) &&
  536. (inc <= bdisp_v_filter[i].max))
  537. break;
  538. return bdisp_v_filter[i].paddr;
  539. }
  540. /**
  541. * bdisp_hw_get_inc
  542. * @from: input size
  543. * @to: output size
  544. * @inc: resize increment in 6.10 format
  545. *
  546. * Computes the increment (inverse of scale) in 6.10 format
  547. *
  548. * RETURNS:
  549. * 0 on success
  550. */
  551. static int bdisp_hw_get_inc(u32 from, u32 to, u16 *inc)
  552. {
  553. u32 tmp;
  554. if (!to)
  555. return -EINVAL;
  556. if (to == from) {
  557. *inc = 1 << 10;
  558. return 0;
  559. }
  560. tmp = (from << 10) / to;
  561. if ((tmp > 0xFFFF) || (!tmp))
  562. /* overflow (downscale x 63) or too small (upscale x 1024) */
  563. return -EINVAL;
  564. *inc = (u16)tmp;
  565. return 0;
  566. }
  567. /**
  568. * bdisp_hw_get_hv_inc
  569. * @ctx: device context
  570. * @h_inc: horizontal increment
  571. * @v_inc: vertical increment
  572. *
  573. * Computes the horizontal & vertical increments (inverse of scale)
  574. *
  575. * RETURNS:
  576. * 0 on success
  577. */
  578. static int bdisp_hw_get_hv_inc(struct bdisp_ctx *ctx, u16 *h_inc, u16 *v_inc)
  579. {
  580. u32 src_w, src_h, dst_w, dst_h;
  581. src_w = ctx->src.crop.width;
  582. src_h = ctx->src.crop.height;
  583. dst_w = ctx->dst.crop.width;
  584. dst_h = ctx->dst.crop.height;
  585. if (bdisp_hw_get_inc(src_w, dst_w, h_inc) ||
  586. bdisp_hw_get_inc(src_h, dst_h, v_inc)) {
  587. dev_err(ctx->bdisp_dev->dev,
  588. "scale factors failed (%dx%d)->(%dx%d)\n",
  589. src_w, src_h, dst_w, dst_h);
  590. return -EINVAL;
  591. }
  592. return 0;
  593. }
  594. /**
  595. * bdisp_hw_get_op_cfg
  596. * @ctx: device context
  597. * @c: operation configuration
  598. *
  599. * Check which blitter operations are expected and sets the scaling increments
  600. *
  601. * RETURNS:
  602. * 0 on success
  603. */
  604. static int bdisp_hw_get_op_cfg(struct bdisp_ctx *ctx, struct bdisp_op_cfg *c)
  605. {
  606. struct device *dev = ctx->bdisp_dev->dev;
  607. struct bdisp_frame *src = &ctx->src;
  608. struct bdisp_frame *dst = &ctx->dst;
  609. if (src->width > MAX_SRC_WIDTH * MAX_VERTICAL_STRIDES) {
  610. dev_err(dev, "Image width out of HW caps\n");
  611. return -EINVAL;
  612. }
  613. c->wide = src->width > MAX_SRC_WIDTH;
  614. c->hflip = ctx->hflip;
  615. c->vflip = ctx->vflip;
  616. c->src_interlaced = (src->field == V4L2_FIELD_INTERLACED);
  617. c->src_nbp = src->fmt->nb_planes;
  618. c->src_yuv = (src->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
  619. (src->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
  620. c->src_420 = c->src_yuv;
  621. c->dst_nbp = dst->fmt->nb_planes;
  622. c->dst_yuv = (dst->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
  623. (dst->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
  624. c->dst_420 = c->dst_yuv;
  625. c->cconv = (c->src_yuv != c->dst_yuv);
  626. if (bdisp_hw_get_hv_inc(ctx, &c->h_inc, &c->v_inc)) {
  627. dev_err(dev, "Scale factor out of HW caps\n");
  628. return -EINVAL;
  629. }
  630. /* Deinterlacing adjustment : stretch a field to a frame */
  631. if (c->src_interlaced)
  632. c->v_inc /= 2;
  633. if ((c->h_inc != (1 << 10)) || (c->v_inc != (1 << 10)))
  634. c->scale = true;
  635. else
  636. c->scale = false;
  637. return 0;
  638. }
  639. /**
  640. * bdisp_hw_color_format
  641. * @pixelformat: v4l2 pixel format
  642. *
  643. * v4l2 to bdisp pixel format convert
  644. *
  645. * RETURNS:
  646. * bdisp pixel format
  647. */
  648. static u32 bdisp_hw_color_format(u32 pixelformat)
  649. {
  650. u32 ret;
  651. switch (pixelformat) {
  652. case V4L2_PIX_FMT_YUV420:
  653. ret = (BDISP_YUV_3B << BLT_TTY_COL_SHIFT);
  654. break;
  655. case V4L2_PIX_FMT_NV12:
  656. ret = (BDISP_NV12 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
  657. break;
  658. case V4L2_PIX_FMT_RGB565:
  659. ret = (BDISP_RGB565 << BLT_TTY_COL_SHIFT);
  660. break;
  661. case V4L2_PIX_FMT_XBGR32: /* This V4L format actually refers to xRGB */
  662. ret = (BDISP_XRGB8888 << BLT_TTY_COL_SHIFT);
  663. break;
  664. case V4L2_PIX_FMT_RGB24: /* RGB888 format */
  665. ret = (BDISP_RGB888 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
  666. break;
  667. case V4L2_PIX_FMT_ABGR32: /* This V4L format actually refers to ARGB */
  668. default:
  669. ret = (BDISP_ARGB8888 << BLT_TTY_COL_SHIFT) | BLT_TTY_ALPHA_R;
  670. break;
  671. }
  672. return ret;
  673. }
  674. /**
  675. * bdisp_hw_build_node
  676. * @ctx: device context
  677. * @cfg: operation configuration
  678. * @node: node to be set
  679. * @t_plan: whether the node refers to a RGB/Y or a CbCr plane
  680. * @src_x_offset: x offset in the source image
  681. *
  682. * Build a node
  683. *
  684. * RETURNS:
  685. * None
  686. */
  687. static void bdisp_hw_build_node(struct bdisp_ctx *ctx,
  688. struct bdisp_op_cfg *cfg,
  689. struct bdisp_node *node,
  690. enum bdisp_target_plan t_plan, int src_x_offset)
  691. {
  692. struct bdisp_frame *src = &ctx->src;
  693. struct bdisp_frame *dst = &ctx->dst;
  694. u16 h_inc, v_inc, yh_inc, yv_inc;
  695. struct v4l2_rect src_rect = src->crop;
  696. struct v4l2_rect dst_rect = dst->crop;
  697. int dst_x_offset;
  698. s32 dst_width = dst->crop.width;
  699. u32 src_fmt, dst_fmt;
  700. const u32 *ivmx;
  701. dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__);
  702. memset(node, 0, sizeof(*node));
  703. /* Adjust src and dst areas wrt src_x_offset */
  704. src_rect.left += src_x_offset;
  705. src_rect.width -= src_x_offset;
  706. src_rect.width = min_t(__s32, MAX_SRC_WIDTH, src_rect.width);
  707. dst_x_offset = (src_x_offset * dst_width) / ctx->src.crop.width;
  708. dst_rect.left += dst_x_offset;
  709. dst_rect.width = (src_rect.width * dst_width) / ctx->src.crop.width;
  710. /* General */
  711. src_fmt = src->fmt->pixelformat;
  712. dst_fmt = dst->fmt->pixelformat;
  713. node->nip = 0;
  714. node->cic = BLT_CIC_ALL_GRP;
  715. node->ack = BLT_ACK_BYPASS_S2S3;
  716. switch (cfg->src_nbp) {
  717. case 1:
  718. /* Src2 = RGB / Src1 = Src3 = off */
  719. node->ins = BLT_INS_S1_OFF | BLT_INS_S2_MEM | BLT_INS_S3_OFF;
  720. break;
  721. case 2:
  722. /* Src3 = Y
  723. * Src2 = CbCr or ColorFill if writing the Y plane
  724. * Src1 = off */
  725. node->ins = BLT_INS_S1_OFF | BLT_INS_S3_MEM;
  726. if (t_plan == BDISP_Y)
  727. node->ins |= BLT_INS_S2_CF;
  728. else
  729. node->ins |= BLT_INS_S2_MEM;
  730. break;
  731. case 3:
  732. default:
  733. /* Src3 = Y
  734. * Src2 = Cb or ColorFill if writing the Y plane
  735. * Src1 = Cr or ColorFill if writing the Y plane */
  736. node->ins = BLT_INS_S3_MEM;
  737. if (t_plan == BDISP_Y)
  738. node->ins |= BLT_INS_S2_CF | BLT_INS_S1_CF;
  739. else
  740. node->ins |= BLT_INS_S2_MEM | BLT_INS_S1_MEM;
  741. break;
  742. }
  743. /* Color convert */
  744. node->ins |= cfg->cconv ? BLT_INS_IVMX : 0;
  745. /* Scale needed if scaling OR 4:2:0 up/downsampling */
  746. node->ins |= (cfg->scale || cfg->src_420 || cfg->dst_420) ?
  747. BLT_INS_SCALE : 0;
  748. /* Target */
  749. node->tba = (t_plan == BDISP_CBCR) ? dst->paddr[1] : dst->paddr[0];
  750. node->tty = dst->bytesperline;
  751. node->tty |= bdisp_hw_color_format(dst_fmt);
  752. node->tty |= BLT_TTY_DITHER;
  753. node->tty |= (t_plan == BDISP_CBCR) ? BLT_TTY_CHROMA : 0;
  754. node->tty |= cfg->hflip ? BLT_TTY_HSO : 0;
  755. node->tty |= cfg->vflip ? BLT_TTY_VSO : 0;
  756. if (cfg->dst_420 && (t_plan == BDISP_CBCR)) {
  757. /* 420 chroma downsampling */
  758. dst_rect.height /= 2;
  759. dst_rect.width /= 2;
  760. dst_rect.left /= 2;
  761. dst_rect.top /= 2;
  762. dst_x_offset /= 2;
  763. dst_width /= 2;
  764. }
  765. node->txy = cfg->vflip ? (dst_rect.height - 1) : dst_rect.top;
  766. node->txy <<= 16;
  767. node->txy |= cfg->hflip ? (dst_width - dst_x_offset - 1) :
  768. dst_rect.left;
  769. node->tsz = dst_rect.height << 16 | dst_rect.width;
  770. if (cfg->src_interlaced) {
  771. /* handle only the top field which is half height of a frame */
  772. src_rect.top /= 2;
  773. src_rect.height /= 2;
  774. }
  775. if (cfg->src_nbp == 1) {
  776. /* Src 2 : RGB */
  777. node->s2ba = src->paddr[0];
  778. node->s2ty = src->bytesperline;
  779. if (cfg->src_interlaced)
  780. node->s2ty *= 2;
  781. node->s2ty |= bdisp_hw_color_format(src_fmt);
  782. node->s2xy = src_rect.top << 16 | src_rect.left;
  783. node->s2sz = src_rect.height << 16 | src_rect.width;
  784. } else {
  785. /* Src 2 : Cb or CbCr */
  786. if (cfg->src_420) {
  787. /* 420 chroma upsampling */
  788. src_rect.top /= 2;
  789. src_rect.left /= 2;
  790. src_rect.width /= 2;
  791. src_rect.height /= 2;
  792. }
  793. node->s2ba = src->paddr[1];
  794. node->s2ty = src->bytesperline;
  795. if (cfg->src_nbp == 3)
  796. node->s2ty /= 2;
  797. if (cfg->src_interlaced)
  798. node->s2ty *= 2;
  799. node->s2ty |= bdisp_hw_color_format(src_fmt);
  800. node->s2xy = src_rect.top << 16 | src_rect.left;
  801. node->s2sz = src_rect.height << 16 | src_rect.width;
  802. if (cfg->src_nbp == 3) {
  803. /* Src 1 : Cr */
  804. node->s1ba = src->paddr[2];
  805. node->s1ty = node->s2ty;
  806. node->s1xy = node->s2xy;
  807. }
  808. /* Src 3 : Y */
  809. node->s3ba = src->paddr[0];
  810. node->s3ty = src->bytesperline;
  811. if (cfg->src_interlaced)
  812. node->s3ty *= 2;
  813. node->s3ty |= bdisp_hw_color_format(src_fmt);
  814. if ((t_plan != BDISP_CBCR) && cfg->src_420) {
  815. /* No chroma upsampling for output RGB / Y plane */
  816. node->s3xy = node->s2xy * 2;
  817. node->s3sz = node->s2sz * 2;
  818. } else {
  819. /* No need to read Y (Src3) when writing Chroma */
  820. node->s3ty |= BLT_S3TY_BLANK_ACC;
  821. node->s3xy = node->s2xy;
  822. node->s3sz = node->s2sz;
  823. }
  824. }
  825. /* Resize (scale OR 4:2:0: chroma up/downsampling) */
  826. if (node->ins & BLT_INS_SCALE) {
  827. /* no need to compute Y when writing CbCr from RGB input */
  828. bool skip_y = (t_plan == BDISP_CBCR) && !cfg->src_yuv;
  829. /* FCTL */
  830. if (cfg->scale) {
  831. node->fctl = BLT_FCTL_HV_SCALE;
  832. if (!skip_y)
  833. node->fctl |= BLT_FCTL_Y_HV_SCALE;
  834. } else {
  835. node->fctl = BLT_FCTL_HV_SAMPLE;
  836. if (!skip_y)
  837. node->fctl |= BLT_FCTL_Y_HV_SAMPLE;
  838. }
  839. /* RSF - Chroma may need to be up/downsampled */
  840. h_inc = cfg->h_inc;
  841. v_inc = cfg->v_inc;
  842. if (!cfg->src_420 && cfg->dst_420 && (t_plan == BDISP_CBCR)) {
  843. /* RGB to 4:2:0 for Chroma: downsample */
  844. h_inc *= 2;
  845. v_inc *= 2;
  846. } else if (cfg->src_420 && !cfg->dst_420) {
  847. /* 4:2:0: to RGB: upsample*/
  848. h_inc /= 2;
  849. v_inc /= 2;
  850. }
  851. node->rsf = v_inc << 16 | h_inc;
  852. /* RZI */
  853. node->rzi = BLT_RZI_DEFAULT;
  854. /* Filter table physical addr */
  855. node->hfp = bdisp_hw_get_hf_addr(h_inc);
  856. node->vfp = bdisp_hw_get_vf_addr(v_inc);
  857. /* Y version */
  858. if (!skip_y) {
  859. yh_inc = cfg->h_inc;
  860. yv_inc = cfg->v_inc;
  861. node->y_rsf = yv_inc << 16 | yh_inc;
  862. node->y_rzi = BLT_RZI_DEFAULT;
  863. node->y_hfp = bdisp_hw_get_hf_addr(yh_inc);
  864. node->y_vfp = bdisp_hw_get_vf_addr(yv_inc);
  865. }
  866. }
  867. /* Versatile matrix for RGB / YUV conversion */
  868. if (cfg->cconv) {
  869. ivmx = cfg->src_yuv ? bdisp_yuv_to_rgb : bdisp_rgb_to_yuv;
  870. node->ivmx0 = ivmx[0];
  871. node->ivmx1 = ivmx[1];
  872. node->ivmx2 = ivmx[2];
  873. node->ivmx3 = ivmx[3];
  874. }
  875. }
  876. /**
  877. * bdisp_hw_build_all_nodes
  878. * @ctx: device context
  879. *
  880. * Build all the nodes for the blitter operation
  881. *
  882. * RETURNS:
  883. * 0 on success
  884. */
  885. static int bdisp_hw_build_all_nodes(struct bdisp_ctx *ctx)
  886. {
  887. struct bdisp_op_cfg cfg;
  888. unsigned int i, nid = 0;
  889. int src_x_offset = 0;
  890. for (i = 0; i < MAX_NB_NODE; i++)
  891. if (!ctx->node[i]) {
  892. dev_err(ctx->bdisp_dev->dev, "node %d is null\n", i);
  893. return -EINVAL;
  894. }
  895. /* Get configuration (scale, flip, ...) */
  896. if (bdisp_hw_get_op_cfg(ctx, &cfg))
  897. return -EINVAL;
  898. /* Split source in vertical strides (HW constraint) */
  899. for (i = 0; i < MAX_VERTICAL_STRIDES; i++) {
  900. /* Build RGB/Y node and link it to the previous node */
  901. bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
  902. cfg.dst_nbp == 1 ? BDISP_RGB : BDISP_Y,
  903. src_x_offset);
  904. if (nid)
  905. ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
  906. nid++;
  907. /* Build additional Cb(Cr) node, link it to the previous one */
  908. if (cfg.dst_nbp > 1) {
  909. bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
  910. BDISP_CBCR, src_x_offset);
  911. ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
  912. nid++;
  913. }
  914. /* Next stride until full width covered */
  915. src_x_offset += MAX_SRC_WIDTH;
  916. if (src_x_offset >= ctx->src.crop.width)
  917. break;
  918. }
  919. /* Mark last node as the last */
  920. ctx->node[nid - 1]->nip = 0;
  921. return 0;
  922. }
  923. /**
  924. * bdisp_hw_save_request
  925. * @ctx: device context
  926. *
  927. * Save a copy of the request and of the built nodes
  928. *
  929. * RETURNS:
  930. * None
  931. */
  932. static void bdisp_hw_save_request(struct bdisp_ctx *ctx)
  933. {
  934. struct bdisp_node **copy_node = ctx->bdisp_dev->dbg.copy_node;
  935. struct bdisp_request *request = &ctx->bdisp_dev->dbg.copy_request;
  936. struct bdisp_node **node = ctx->node;
  937. int i;
  938. /* Request copy */
  939. request->src = ctx->src;
  940. request->dst = ctx->dst;
  941. request->hflip = ctx->hflip;
  942. request->vflip = ctx->vflip;
  943. request->nb_req++;
  944. /* Nodes copy */
  945. for (i = 0; i < MAX_NB_NODE; i++) {
  946. /* Allocate memory if not done yet */
  947. if (!copy_node[i]) {
  948. copy_node[i] = devm_kzalloc(ctx->bdisp_dev->dev,
  949. sizeof(*copy_node[i]),
  950. GFP_ATOMIC);
  951. if (!copy_node[i])
  952. return;
  953. }
  954. *copy_node[i] = *node[i];
  955. }
  956. }
  957. /**
  958. * bdisp_hw_update
  959. * @ctx: device context
  960. *
  961. * Send the request to the HW
  962. *
  963. * RETURNS:
  964. * 0 on success
  965. */
  966. int bdisp_hw_update(struct bdisp_ctx *ctx)
  967. {
  968. int ret;
  969. struct bdisp_dev *bdisp = ctx->bdisp_dev;
  970. struct device *dev = bdisp->dev;
  971. unsigned int node_id;
  972. dev_dbg(dev, "%s\n", __func__);
  973. /* build nodes */
  974. ret = bdisp_hw_build_all_nodes(ctx);
  975. if (ret) {
  976. dev_err(dev, "cannot build nodes (%d)\n", ret);
  977. return ret;
  978. }
  979. /* Save a copy of the request */
  980. bdisp_hw_save_request(ctx);
  981. /* Configure interrupt to 'Last Node Reached for AQ1' */
  982. writel(BLT_AQ1_CTL_CFG, bdisp->regs + BLT_AQ1_CTL);
  983. writel(BLT_ITS_AQ1_LNA, bdisp->regs + BLT_ITM0);
  984. /* Write first node addr */
  985. writel(ctx->node_paddr[0], bdisp->regs + BLT_AQ1_IP);
  986. /* Find and write last node addr : this starts the HW processing */
  987. for (node_id = 0; node_id < MAX_NB_NODE - 1; node_id++) {
  988. if (!ctx->node[node_id]->nip)
  989. break;
  990. }
  991. writel(ctx->node_paddr[node_id], bdisp->regs + BLT_AQ1_LNA);
  992. return 0;
  993. }