sti_hqvdp.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/component.h>
  8. #include <linux/firmware.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/reset.h>
  12. #include <drm/drmP.h>
  13. #include <drm/drm_fb_cma_helper.h>
  14. #include <drm/drm_gem_cma_helper.h>
  15. #include "sti_compositor.h"
  16. #include "sti_hqvdp_lut.h"
  17. #include "sti_plane.h"
  18. #include "sti_vtg.h"
  19. /* Firmware name */
  20. #define HQVDP_FMW_NAME "hqvdp-stih407.bin"
  21. /* Regs address */
  22. #define HQVDP_DMEM 0x00000000 /* 0x00000000 */
  23. #define HQVDP_PMEM 0x00040000 /* 0x00040000 */
  24. #define HQVDP_RD_PLUG 0x000E0000 /* 0x000E0000 */
  25. #define HQVDP_RD_PLUG_CONTROL (HQVDP_RD_PLUG + 0x1000) /* 0x000E1000 */
  26. #define HQVDP_RD_PLUG_PAGE_SIZE (HQVDP_RD_PLUG + 0x1004) /* 0x000E1004 */
  27. #define HQVDP_RD_PLUG_MIN_OPC (HQVDP_RD_PLUG + 0x1008) /* 0x000E1008 */
  28. #define HQVDP_RD_PLUG_MAX_OPC (HQVDP_RD_PLUG + 0x100C) /* 0x000E100C */
  29. #define HQVDP_RD_PLUG_MAX_CHK (HQVDP_RD_PLUG + 0x1010) /* 0x000E1010 */
  30. #define HQVDP_RD_PLUG_MAX_MSG (HQVDP_RD_PLUG + 0x1014) /* 0x000E1014 */
  31. #define HQVDP_RD_PLUG_MIN_SPACE (HQVDP_RD_PLUG + 0x1018) /* 0x000E1018 */
  32. #define HQVDP_WR_PLUG 0x000E2000 /* 0x000E2000 */
  33. #define HQVDP_WR_PLUG_CONTROL (HQVDP_WR_PLUG + 0x1000) /* 0x000E3000 */
  34. #define HQVDP_WR_PLUG_PAGE_SIZE (HQVDP_WR_PLUG + 0x1004) /* 0x000E3004 */
  35. #define HQVDP_WR_PLUG_MIN_OPC (HQVDP_WR_PLUG + 0x1008) /* 0x000E3008 */
  36. #define HQVDP_WR_PLUG_MAX_OPC (HQVDP_WR_PLUG + 0x100C) /* 0x000E300C */
  37. #define HQVDP_WR_PLUG_MAX_CHK (HQVDP_WR_PLUG + 0x1010) /* 0x000E3010 */
  38. #define HQVDP_WR_PLUG_MAX_MSG (HQVDP_WR_PLUG + 0x1014) /* 0x000E3014 */
  39. #define HQVDP_WR_PLUG_MIN_SPACE (HQVDP_WR_PLUG + 0x1018) /* 0x000E3018 */
  40. #define HQVDP_MBX 0x000E4000 /* 0x000E4000 */
  41. #define HQVDP_MBX_IRQ_TO_XP70 (HQVDP_MBX + 0x0000) /* 0x000E4000 */
  42. #define HQVDP_MBX_INFO_HOST (HQVDP_MBX + 0x0004) /* 0x000E4004 */
  43. #define HQVDP_MBX_IRQ_TO_HOST (HQVDP_MBX + 0x0008) /* 0x000E4008 */
  44. #define HQVDP_MBX_INFO_XP70 (HQVDP_MBX + 0x000C) /* 0x000E400C */
  45. #define HQVDP_MBX_SW_RESET_CTRL (HQVDP_MBX + 0x0010) /* 0x000E4010 */
  46. #define HQVDP_MBX_STARTUP_CTRL1 (HQVDP_MBX + 0x0014) /* 0x000E4014 */
  47. #define HQVDP_MBX_STARTUP_CTRL2 (HQVDP_MBX + 0x0018) /* 0x000E4018 */
  48. #define HQVDP_MBX_GP_STATUS (HQVDP_MBX + 0x001C) /* 0x000E401C */
  49. #define HQVDP_MBX_NEXT_CMD (HQVDP_MBX + 0x0020) /* 0x000E4020 */
  50. #define HQVDP_MBX_CURRENT_CMD (HQVDP_MBX + 0x0024) /* 0x000E4024 */
  51. #define HQVDP_MBX_SOFT_VSYNC (HQVDP_MBX + 0x0028) /* 0x000E4028 */
  52. /* Plugs config */
  53. #define PLUG_CONTROL_ENABLE 0x00000001
  54. #define PLUG_PAGE_SIZE_256 0x00000002
  55. #define PLUG_MIN_OPC_8 0x00000003
  56. #define PLUG_MAX_OPC_64 0x00000006
  57. #define PLUG_MAX_CHK_2X 0x00000001
  58. #define PLUG_MAX_MSG_1X 0x00000000
  59. #define PLUG_MIN_SPACE_1 0x00000000
  60. /* SW reset CTRL */
  61. #define SW_RESET_CTRL_FULL BIT(0)
  62. #define SW_RESET_CTRL_CORE BIT(1)
  63. /* Startup ctrl 1 */
  64. #define STARTUP_CTRL1_RST_DONE BIT(0)
  65. #define STARTUP_CTRL1_AUTH_IDLE BIT(2)
  66. /* Startup ctrl 2 */
  67. #define STARTUP_CTRL2_FETCH_EN BIT(1)
  68. /* Info xP70 */
  69. #define INFO_XP70_FW_READY BIT(15)
  70. #define INFO_XP70_FW_PROCESSING BIT(14)
  71. #define INFO_XP70_FW_INITQUEUES BIT(13)
  72. /* SOFT_VSYNC */
  73. #define SOFT_VSYNC_HW 0x00000000
  74. #define SOFT_VSYNC_SW_CMD 0x00000001
  75. #define SOFT_VSYNC_SW_CTRL_IRQ 0x00000003
  76. /* Reset & boot poll config */
  77. #define POLL_MAX_ATTEMPT 50
  78. #define POLL_DELAY_MS 20
  79. #define SCALE_FACTOR 8192
  80. #define SCALE_MAX_FOR_LEG_LUT_F 4096
  81. #define SCALE_MAX_FOR_LEG_LUT_E 4915
  82. #define SCALE_MAX_FOR_LEG_LUT_D 6654
  83. #define SCALE_MAX_FOR_LEG_LUT_C 8192
  84. enum sti_hvsrc_orient {
  85. HVSRC_HORI,
  86. HVSRC_VERT
  87. };
  88. /* Command structures */
  89. struct sti_hqvdp_top {
  90. u32 config;
  91. u32 mem_format;
  92. u32 current_luma;
  93. u32 current_enh_luma;
  94. u32 current_right_luma;
  95. u32 current_enh_right_luma;
  96. u32 current_chroma;
  97. u32 current_enh_chroma;
  98. u32 current_right_chroma;
  99. u32 current_enh_right_chroma;
  100. u32 output_luma;
  101. u32 output_chroma;
  102. u32 luma_src_pitch;
  103. u32 luma_enh_src_pitch;
  104. u32 luma_right_src_pitch;
  105. u32 luma_enh_right_src_pitch;
  106. u32 chroma_src_pitch;
  107. u32 chroma_enh_src_pitch;
  108. u32 chroma_right_src_pitch;
  109. u32 chroma_enh_right_src_pitch;
  110. u32 luma_processed_pitch;
  111. u32 chroma_processed_pitch;
  112. u32 input_frame_size;
  113. u32 input_viewport_ori;
  114. u32 input_viewport_ori_right;
  115. u32 input_viewport_size;
  116. u32 left_view_border_width;
  117. u32 right_view_border_width;
  118. u32 left_view_3d_offset_width;
  119. u32 right_view_3d_offset_width;
  120. u32 side_stripe_color;
  121. u32 crc_reset_ctrl;
  122. };
  123. /* Configs for interlaced : no IT, no pass thru, 3 fields */
  124. #define TOP_CONFIG_INTER_BTM 0x00000000
  125. #define TOP_CONFIG_INTER_TOP 0x00000002
  126. /* Config for progressive : no IT, no pass thru, 3 fields */
  127. #define TOP_CONFIG_PROGRESSIVE 0x00000001
  128. /* Default MemFormat: in=420_raster_dual out=444_raster;opaque Mem2Tv mode */
  129. #define TOP_MEM_FORMAT_DFLT 0x00018060
  130. /* Min/Max size */
  131. #define MAX_WIDTH 0x1FFF
  132. #define MAX_HEIGHT 0x0FFF
  133. #define MIN_WIDTH 0x0030
  134. #define MIN_HEIGHT 0x0010
  135. struct sti_hqvdp_vc1re {
  136. u32 ctrl_prv_csdi;
  137. u32 ctrl_cur_csdi;
  138. u32 ctrl_nxt_csdi;
  139. u32 ctrl_cur_fmd;
  140. u32 ctrl_nxt_fmd;
  141. };
  142. struct sti_hqvdp_fmd {
  143. u32 config;
  144. u32 viewport_ori;
  145. u32 viewport_size;
  146. u32 next_next_luma;
  147. u32 next_next_right_luma;
  148. u32 next_next_next_luma;
  149. u32 next_next_next_right_luma;
  150. u32 threshold_scd;
  151. u32 threshold_rfd;
  152. u32 threshold_move;
  153. u32 threshold_cfd;
  154. };
  155. struct sti_hqvdp_csdi {
  156. u32 config;
  157. u32 config2;
  158. u32 dcdi_config;
  159. u32 prev_luma;
  160. u32 prev_enh_luma;
  161. u32 prev_right_luma;
  162. u32 prev_enh_right_luma;
  163. u32 next_luma;
  164. u32 next_enh_luma;
  165. u32 next_right_luma;
  166. u32 next_enh_right_luma;
  167. u32 prev_chroma;
  168. u32 prev_enh_chroma;
  169. u32 prev_right_chroma;
  170. u32 prev_enh_right_chroma;
  171. u32 next_chroma;
  172. u32 next_enh_chroma;
  173. u32 next_right_chroma;
  174. u32 next_enh_right_chroma;
  175. u32 prev_motion;
  176. u32 prev_right_motion;
  177. u32 cur_motion;
  178. u32 cur_right_motion;
  179. u32 next_motion;
  180. u32 next_right_motion;
  181. };
  182. /* Config for progressive: by pass */
  183. #define CSDI_CONFIG_PROG 0x00000000
  184. /* Config for directional deinterlacing without motion */
  185. #define CSDI_CONFIG_INTER_DIR 0x00000016
  186. /* Additional configs for fader, blender, motion,... deinterlace algorithms */
  187. #define CSDI_CONFIG2_DFLT 0x000001B3
  188. #define CSDI_DCDI_CONFIG_DFLT 0x00203803
  189. struct sti_hqvdp_hvsrc {
  190. u32 hor_panoramic_ctrl;
  191. u32 output_picture_size;
  192. u32 init_horizontal;
  193. u32 init_vertical;
  194. u32 param_ctrl;
  195. u32 yh_coef[NB_COEF];
  196. u32 ch_coef[NB_COEF];
  197. u32 yv_coef[NB_COEF];
  198. u32 cv_coef[NB_COEF];
  199. u32 hori_shift;
  200. u32 vert_shift;
  201. };
  202. /* Default ParamCtrl: all controls enabled */
  203. #define HVSRC_PARAM_CTRL_DFLT 0xFFFFFFFF
  204. struct sti_hqvdp_iqi {
  205. u32 config;
  206. u32 demo_wind_size;
  207. u32 pk_config;
  208. u32 coeff0_coeff1;
  209. u32 coeff2_coeff3;
  210. u32 coeff4;
  211. u32 pk_lut;
  212. u32 pk_gain;
  213. u32 pk_coring_level;
  214. u32 cti_config;
  215. u32 le_config;
  216. u32 le_lut[64];
  217. u32 con_bri;
  218. u32 sat_gain;
  219. u32 pxf_conf;
  220. u32 default_color;
  221. };
  222. /* Default Config : IQI bypassed */
  223. #define IQI_CONFIG_DFLT 0x00000001
  224. /* Default Contrast & Brightness gain = 256 */
  225. #define IQI_CON_BRI_DFLT 0x00000100
  226. /* Default Saturation gain = 256 */
  227. #define IQI_SAT_GAIN_DFLT 0x00000100
  228. /* Default PxfConf : P2I bypassed */
  229. #define IQI_PXF_CONF_DFLT 0x00000001
  230. struct sti_hqvdp_top_status {
  231. u32 processing_time;
  232. u32 input_y_crc;
  233. u32 input_uv_crc;
  234. };
  235. struct sti_hqvdp_fmd_status {
  236. u32 fmd_repeat_move_status;
  237. u32 fmd_scene_count_status;
  238. u32 cfd_sum;
  239. u32 field_sum;
  240. u32 next_y_fmd_crc;
  241. u32 next_next_y_fmd_crc;
  242. u32 next_next_next_y_fmd_crc;
  243. };
  244. struct sti_hqvdp_csdi_status {
  245. u32 prev_y_csdi_crc;
  246. u32 cur_y_csdi_crc;
  247. u32 next_y_csdi_crc;
  248. u32 prev_uv_csdi_crc;
  249. u32 cur_uv_csdi_crc;
  250. u32 next_uv_csdi_crc;
  251. u32 y_csdi_crc;
  252. u32 uv_csdi_crc;
  253. u32 uv_cup_crc;
  254. u32 mot_csdi_crc;
  255. u32 mot_cur_csdi_crc;
  256. u32 mot_prev_csdi_crc;
  257. };
  258. struct sti_hqvdp_hvsrc_status {
  259. u32 y_hvsrc_crc;
  260. u32 u_hvsrc_crc;
  261. u32 v_hvsrc_crc;
  262. };
  263. struct sti_hqvdp_iqi_status {
  264. u32 pxf_it_status;
  265. u32 y_iqi_crc;
  266. u32 u_iqi_crc;
  267. u32 v_iqi_crc;
  268. };
  269. /* Main commands. We use 2 commands one being processed by the firmware, one
  270. * ready to be fetched upon next Vsync*/
  271. #define NB_VDP_CMD 2
  272. struct sti_hqvdp_cmd {
  273. struct sti_hqvdp_top top;
  274. struct sti_hqvdp_vc1re vc1re;
  275. struct sti_hqvdp_fmd fmd;
  276. struct sti_hqvdp_csdi csdi;
  277. struct sti_hqvdp_hvsrc hvsrc;
  278. struct sti_hqvdp_iqi iqi;
  279. struct sti_hqvdp_top_status top_status;
  280. struct sti_hqvdp_fmd_status fmd_status;
  281. struct sti_hqvdp_csdi_status csdi_status;
  282. struct sti_hqvdp_hvsrc_status hvsrc_status;
  283. struct sti_hqvdp_iqi_status iqi_status;
  284. };
  285. /*
  286. * STI HQVDP structure
  287. *
  288. * @dev: driver device
  289. * @drm_dev: the drm device
  290. * @regs: registers
  291. * @plane: plane structure for hqvdp it self
  292. * @clk: IP clock
  293. * @clk_pix_main: pix main clock
  294. * @reset: reset control
  295. * @vtg_nb: notifier to handle VTG Vsync
  296. * @btm_field_pending: is there any bottom field (interlaced frame) to display
  297. * @curr_field_count: number of field updates
  298. * @last_field_count: number of field updates since last fps measure
  299. * @hqvdp_cmd: buffer of commands
  300. * @hqvdp_cmd_paddr: physical address of hqvdp_cmd
  301. * @vtg: vtg for main data path
  302. * @xp70_initialized: true if xp70 is already initialized
  303. */
  304. struct sti_hqvdp {
  305. struct device *dev;
  306. struct drm_device *drm_dev;
  307. void __iomem *regs;
  308. struct sti_plane plane;
  309. struct clk *clk;
  310. struct clk *clk_pix_main;
  311. struct reset_control *reset;
  312. struct notifier_block vtg_nb;
  313. bool btm_field_pending;
  314. unsigned int curr_field_count;
  315. unsigned int last_field_count;
  316. void *hqvdp_cmd;
  317. dma_addr_t hqvdp_cmd_paddr;
  318. struct sti_vtg *vtg;
  319. bool xp70_initialized;
  320. };
  321. #define to_sti_hqvdp(x) container_of(x, struct sti_hqvdp, plane)
  322. static const uint32_t hqvdp_supported_formats[] = {
  323. DRM_FORMAT_NV12,
  324. };
  325. /**
  326. * sti_hqvdp_get_free_cmd
  327. * @hqvdp: hqvdp structure
  328. *
  329. * Look for a hqvdp_cmd that is not being used (or about to be used) by the FW.
  330. *
  331. * RETURNS:
  332. * the offset of the command to be used.
  333. * -1 in error cases
  334. */
  335. static int sti_hqvdp_get_free_cmd(struct sti_hqvdp *hqvdp)
  336. {
  337. int curr_cmd, next_cmd;
  338. dma_addr_t cmd = hqvdp->hqvdp_cmd_paddr;
  339. int i;
  340. curr_cmd = readl(hqvdp->regs + HQVDP_MBX_CURRENT_CMD);
  341. next_cmd = readl(hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  342. for (i = 0; i < NB_VDP_CMD; i++) {
  343. if ((cmd != curr_cmd) && (cmd != next_cmd))
  344. return i * sizeof(struct sti_hqvdp_cmd);
  345. cmd += sizeof(struct sti_hqvdp_cmd);
  346. }
  347. return -1;
  348. }
  349. /**
  350. * sti_hqvdp_get_curr_cmd
  351. * @hqvdp: hqvdp structure
  352. *
  353. * Look for the hqvdp_cmd that is being used by the FW.
  354. *
  355. * RETURNS:
  356. * the offset of the command to be used.
  357. * -1 in error cases
  358. */
  359. static int sti_hqvdp_get_curr_cmd(struct sti_hqvdp *hqvdp)
  360. {
  361. int curr_cmd;
  362. dma_addr_t cmd = hqvdp->hqvdp_cmd_paddr;
  363. unsigned int i;
  364. curr_cmd = readl(hqvdp->regs + HQVDP_MBX_CURRENT_CMD);
  365. for (i = 0; i < NB_VDP_CMD; i++) {
  366. if (cmd == curr_cmd)
  367. return i * sizeof(struct sti_hqvdp_cmd);
  368. cmd += sizeof(struct sti_hqvdp_cmd);
  369. }
  370. return -1;
  371. }
  372. /**
  373. * sti_hqvdp_update_hvsrc
  374. * @orient: horizontal or vertical
  375. * @scale: scaling/zoom factor
  376. * @hvsrc: the structure containing the LUT coef
  377. *
  378. * Update the Y and C Lut coef, as well as the shift param
  379. *
  380. * RETURNS:
  381. * None.
  382. */
  383. static void sti_hqvdp_update_hvsrc(enum sti_hvsrc_orient orient, int scale,
  384. struct sti_hqvdp_hvsrc *hvsrc)
  385. {
  386. const int *coef_c, *coef_y;
  387. int shift_c, shift_y;
  388. /* Get the appropriate coef tables */
  389. if (scale < SCALE_MAX_FOR_LEG_LUT_F) {
  390. coef_y = coef_lut_f_y_legacy;
  391. coef_c = coef_lut_f_c_legacy;
  392. shift_y = SHIFT_LUT_F_Y_LEGACY;
  393. shift_c = SHIFT_LUT_F_C_LEGACY;
  394. } else if (scale < SCALE_MAX_FOR_LEG_LUT_E) {
  395. coef_y = coef_lut_e_y_legacy;
  396. coef_c = coef_lut_e_c_legacy;
  397. shift_y = SHIFT_LUT_E_Y_LEGACY;
  398. shift_c = SHIFT_LUT_E_C_LEGACY;
  399. } else if (scale < SCALE_MAX_FOR_LEG_LUT_D) {
  400. coef_y = coef_lut_d_y_legacy;
  401. coef_c = coef_lut_d_c_legacy;
  402. shift_y = SHIFT_LUT_D_Y_LEGACY;
  403. shift_c = SHIFT_LUT_D_C_LEGACY;
  404. } else if (scale < SCALE_MAX_FOR_LEG_LUT_C) {
  405. coef_y = coef_lut_c_y_legacy;
  406. coef_c = coef_lut_c_c_legacy;
  407. shift_y = SHIFT_LUT_C_Y_LEGACY;
  408. shift_c = SHIFT_LUT_C_C_LEGACY;
  409. } else if (scale == SCALE_MAX_FOR_LEG_LUT_C) {
  410. coef_y = coef_c = coef_lut_b;
  411. shift_y = shift_c = SHIFT_LUT_B;
  412. } else {
  413. coef_y = coef_c = coef_lut_a_legacy;
  414. shift_y = shift_c = SHIFT_LUT_A_LEGACY;
  415. }
  416. if (orient == HVSRC_HORI) {
  417. hvsrc->hori_shift = (shift_c << 16) | shift_y;
  418. memcpy(hvsrc->yh_coef, coef_y, sizeof(hvsrc->yh_coef));
  419. memcpy(hvsrc->ch_coef, coef_c, sizeof(hvsrc->ch_coef));
  420. } else {
  421. hvsrc->vert_shift = (shift_c << 16) | shift_y;
  422. memcpy(hvsrc->yv_coef, coef_y, sizeof(hvsrc->yv_coef));
  423. memcpy(hvsrc->cv_coef, coef_c, sizeof(hvsrc->cv_coef));
  424. }
  425. }
  426. /**
  427. * sti_hqvdp_check_hw_scaling
  428. * @hqvdp: hqvdp pointer
  429. * @mode: display mode with timing constraints
  430. * @src_w: source width
  431. * @src_h: source height
  432. * @dst_w: destination width
  433. * @dst_h: destination height
  434. *
  435. * Check if the HW is able to perform the scaling request
  436. * The firmware scaling limitation is "CEIL(1/Zy) <= FLOOR(LFW)" where:
  437. * Zy = OutputHeight / InputHeight
  438. * LFW = (Tx * IPClock) / (MaxNbCycles * Cp)
  439. * Tx : Total video mode horizontal resolution
  440. * IPClock : HQVDP IP clock (Mhz)
  441. * MaxNbCycles: max(InputWidth, OutputWidth)
  442. * Cp: Video mode pixel clock (Mhz)
  443. *
  444. * RETURNS:
  445. * True if the HW can scale.
  446. */
  447. static bool sti_hqvdp_check_hw_scaling(struct sti_hqvdp *hqvdp,
  448. struct drm_display_mode *mode,
  449. int src_w, int src_h,
  450. int dst_w, int dst_h)
  451. {
  452. unsigned long lfw;
  453. unsigned int inv_zy;
  454. lfw = mode->htotal * (clk_get_rate(hqvdp->clk) / 1000000);
  455. lfw /= max(src_w, dst_w) * mode->clock / 1000;
  456. inv_zy = DIV_ROUND_UP(src_h, dst_h);
  457. return (inv_zy <= lfw) ? true : false;
  458. }
  459. /**
  460. * sti_hqvdp_disable
  461. * @hqvdp: hqvdp pointer
  462. *
  463. * Disables the HQVDP plane
  464. */
  465. static void sti_hqvdp_disable(struct sti_hqvdp *hqvdp)
  466. {
  467. int i;
  468. DRM_DEBUG_DRIVER("%s\n", sti_plane_to_str(&hqvdp->plane));
  469. /* Unregister VTG Vsync callback */
  470. if (sti_vtg_unregister_client(hqvdp->vtg, &hqvdp->vtg_nb))
  471. DRM_DEBUG_DRIVER("Warning: cannot unregister VTG notifier\n");
  472. /* Set next cmd to NULL */
  473. writel(0, hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  474. for (i = 0; i < POLL_MAX_ATTEMPT; i++) {
  475. if (readl(hqvdp->regs + HQVDP_MBX_INFO_XP70)
  476. & INFO_XP70_FW_READY)
  477. break;
  478. msleep(POLL_DELAY_MS);
  479. }
  480. /* VTG can stop now */
  481. clk_disable_unprepare(hqvdp->clk_pix_main);
  482. if (i == POLL_MAX_ATTEMPT)
  483. DRM_ERROR("XP70 could not revert to idle\n");
  484. hqvdp->plane.status = STI_PLANE_DISABLED;
  485. }
  486. /**
  487. * sti_vdp_vtg_cb
  488. * @nb: notifier block
  489. * @evt: event message
  490. * @data: private data
  491. *
  492. * Handle VTG Vsync event, display pending bottom field
  493. *
  494. * RETURNS:
  495. * 0 on success.
  496. */
  497. int sti_hqvdp_vtg_cb(struct notifier_block *nb, unsigned long evt, void *data)
  498. {
  499. struct sti_hqvdp *hqvdp = container_of(nb, struct sti_hqvdp, vtg_nb);
  500. int btm_cmd_offset, top_cmd_offest;
  501. struct sti_hqvdp_cmd *btm_cmd, *top_cmd;
  502. if ((evt != VTG_TOP_FIELD_EVENT) && (evt != VTG_BOTTOM_FIELD_EVENT)) {
  503. DRM_DEBUG_DRIVER("Unknown event\n");
  504. return 0;
  505. }
  506. if (hqvdp->plane.status == STI_PLANE_FLUSHING) {
  507. /* disable need to be synchronize on vsync event */
  508. DRM_DEBUG_DRIVER("Vsync event received => disable %s\n",
  509. sti_plane_to_str(&hqvdp->plane));
  510. sti_hqvdp_disable(hqvdp);
  511. }
  512. if (hqvdp->btm_field_pending) {
  513. /* Create the btm field command from the current one */
  514. btm_cmd_offset = sti_hqvdp_get_free_cmd(hqvdp);
  515. top_cmd_offest = sti_hqvdp_get_curr_cmd(hqvdp);
  516. if ((btm_cmd_offset == -1) || (top_cmd_offest == -1)) {
  517. DRM_ERROR("Cannot get cmds, skip btm field\n");
  518. return -EBUSY;
  519. }
  520. btm_cmd = hqvdp->hqvdp_cmd + btm_cmd_offset;
  521. top_cmd = hqvdp->hqvdp_cmd + top_cmd_offest;
  522. memcpy(btm_cmd, top_cmd, sizeof(*btm_cmd));
  523. btm_cmd->top.config = TOP_CONFIG_INTER_BTM;
  524. btm_cmd->top.current_luma +=
  525. btm_cmd->top.luma_src_pitch / 2;
  526. btm_cmd->top.current_chroma +=
  527. btm_cmd->top.chroma_src_pitch / 2;
  528. /* Post the command to mailbox */
  529. writel(hqvdp->hqvdp_cmd_paddr + btm_cmd_offset,
  530. hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  531. hqvdp->curr_field_count++;
  532. hqvdp->btm_field_pending = false;
  533. dev_dbg(hqvdp->dev, "%s Posted command:0x%x\n",
  534. __func__, hqvdp->hqvdp_cmd_paddr);
  535. }
  536. return 0;
  537. }
  538. static void sti_hqvdp_init(struct sti_hqvdp *hqvdp)
  539. {
  540. int size;
  541. hqvdp->vtg_nb.notifier_call = sti_hqvdp_vtg_cb;
  542. /* Allocate memory for the VDP commands */
  543. size = NB_VDP_CMD * sizeof(struct sti_hqvdp_cmd);
  544. hqvdp->hqvdp_cmd = dma_alloc_writecombine(hqvdp->dev, size,
  545. &hqvdp->hqvdp_cmd_paddr,
  546. GFP_KERNEL | GFP_DMA);
  547. if (!hqvdp->hqvdp_cmd) {
  548. DRM_ERROR("Failed to allocate memory for VDP cmd\n");
  549. return;
  550. }
  551. memset(hqvdp->hqvdp_cmd, 0, size);
  552. }
  553. static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane,
  554. struct drm_plane_state *oldstate)
  555. {
  556. struct drm_plane_state *state = drm_plane->state;
  557. struct sti_plane *plane = to_sti_plane(drm_plane);
  558. struct sti_hqvdp *hqvdp = to_sti_hqvdp(plane);
  559. struct drm_crtc *crtc = state->crtc;
  560. struct sti_mixer *mixer = to_sti_mixer(crtc);
  561. struct drm_framebuffer *fb = state->fb;
  562. struct drm_display_mode *mode = &crtc->mode;
  563. int dst_x = state->crtc_x;
  564. int dst_y = state->crtc_y;
  565. int dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x);
  566. int dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y);
  567. /* src_x are in 16.16 format */
  568. int src_x = state->src_x >> 16;
  569. int src_y = state->src_y >> 16;
  570. int src_w = state->src_w >> 16;
  571. int src_h = state->src_h >> 16;
  572. bool first_prepare = plane->status == STI_PLANE_DISABLED ? true : false;
  573. struct drm_gem_cma_object *cma_obj;
  574. struct sti_hqvdp_cmd *cmd;
  575. int scale_h, scale_v;
  576. int cmd_offset;
  577. DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
  578. crtc->base.id, sti_mixer_to_str(mixer),
  579. drm_plane->base.id, sti_plane_to_str(plane));
  580. DRM_DEBUG_KMS("%s dst=(%dx%d)@(%d,%d) - src=(%dx%d)@(%d,%d)\n",
  581. sti_plane_to_str(plane),
  582. dst_w, dst_h, dst_x, dst_y,
  583. src_w, src_h, src_x, src_y);
  584. cmd_offset = sti_hqvdp_get_free_cmd(hqvdp);
  585. if (cmd_offset == -1) {
  586. DRM_ERROR("No available hqvdp_cmd now\n");
  587. return;
  588. }
  589. cmd = hqvdp->hqvdp_cmd + cmd_offset;
  590. if (!sti_hqvdp_check_hw_scaling(hqvdp, mode,
  591. src_w, src_h,
  592. dst_w, dst_h)) {
  593. DRM_ERROR("Scaling beyond HW capabilities\n");
  594. return;
  595. }
  596. /* Static parameters, defaulting to progressive mode */
  597. cmd->top.config = TOP_CONFIG_PROGRESSIVE;
  598. cmd->top.mem_format = TOP_MEM_FORMAT_DFLT;
  599. cmd->hvsrc.param_ctrl = HVSRC_PARAM_CTRL_DFLT;
  600. cmd->csdi.config = CSDI_CONFIG_PROG;
  601. /* VC1RE, FMD bypassed : keep everything set to 0
  602. * IQI/P2I bypassed */
  603. cmd->iqi.config = IQI_CONFIG_DFLT;
  604. cmd->iqi.con_bri = IQI_CON_BRI_DFLT;
  605. cmd->iqi.sat_gain = IQI_SAT_GAIN_DFLT;
  606. cmd->iqi.pxf_conf = IQI_PXF_CONF_DFLT;
  607. cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
  608. if (!cma_obj) {
  609. DRM_ERROR("Can't get CMA GEM object for fb\n");
  610. return;
  611. }
  612. DRM_DEBUG_DRIVER("drm FB:%d format:%.4s phys@:0x%lx\n", fb->base.id,
  613. (char *)&fb->pixel_format,
  614. (unsigned long)cma_obj->paddr);
  615. /* Buffer planes address */
  616. cmd->top.current_luma = (u32)cma_obj->paddr + fb->offsets[0];
  617. cmd->top.current_chroma = (u32)cma_obj->paddr + fb->offsets[1];
  618. /* Pitches */
  619. cmd->top.luma_processed_pitch = fb->pitches[0];
  620. cmd->top.luma_src_pitch = fb->pitches[0];
  621. cmd->top.chroma_processed_pitch = fb->pitches[1];
  622. cmd->top.chroma_src_pitch = fb->pitches[1];
  623. /* Input / output size
  624. * Align to upper even value */
  625. dst_w = ALIGN(dst_w, 2);
  626. dst_h = ALIGN(dst_h, 2);
  627. if ((src_w > MAX_WIDTH) || (src_w < MIN_WIDTH) ||
  628. (src_h > MAX_HEIGHT) || (src_h < MIN_HEIGHT) ||
  629. (dst_w > MAX_WIDTH) || (dst_w < MIN_WIDTH) ||
  630. (dst_h > MAX_HEIGHT) || (dst_h < MIN_HEIGHT)) {
  631. DRM_ERROR("Invalid in/out size %dx%d -> %dx%d\n",
  632. src_w, src_h,
  633. dst_w, dst_h);
  634. return;
  635. }
  636. cmd->top.input_viewport_size = src_h << 16 | src_w;
  637. cmd->top.input_frame_size = src_h << 16 | src_w;
  638. cmd->hvsrc.output_picture_size = dst_h << 16 | dst_w;
  639. cmd->top.input_viewport_ori = src_y << 16 | src_x;
  640. /* Handle interlaced */
  641. if (fb->flags & DRM_MODE_FB_INTERLACED) {
  642. /* Top field to display */
  643. cmd->top.config = TOP_CONFIG_INTER_TOP;
  644. /* Update pitches and vert size */
  645. cmd->top.input_frame_size = (src_h / 2) << 16 | src_w;
  646. cmd->top.luma_processed_pitch *= 2;
  647. cmd->top.luma_src_pitch *= 2;
  648. cmd->top.chroma_processed_pitch *= 2;
  649. cmd->top.chroma_src_pitch *= 2;
  650. /* Enable directional deinterlacing processing */
  651. cmd->csdi.config = CSDI_CONFIG_INTER_DIR;
  652. cmd->csdi.config2 = CSDI_CONFIG2_DFLT;
  653. cmd->csdi.dcdi_config = CSDI_DCDI_CONFIG_DFLT;
  654. }
  655. /* Update hvsrc lut coef */
  656. scale_h = SCALE_FACTOR * dst_w / src_w;
  657. sti_hqvdp_update_hvsrc(HVSRC_HORI, scale_h, &cmd->hvsrc);
  658. scale_v = SCALE_FACTOR * dst_h / src_h;
  659. sti_hqvdp_update_hvsrc(HVSRC_VERT, scale_v, &cmd->hvsrc);
  660. if (first_prepare) {
  661. /* Prevent VTG shutdown */
  662. if (clk_prepare_enable(hqvdp->clk_pix_main)) {
  663. DRM_ERROR("Failed to prepare/enable pix main clk\n");
  664. return;
  665. }
  666. /* Register VTG Vsync callback to handle bottom fields */
  667. if (sti_vtg_register_client(hqvdp->vtg,
  668. &hqvdp->vtg_nb,
  669. mixer->id)) {
  670. DRM_ERROR("Cannot register VTG notifier\n");
  671. return;
  672. }
  673. }
  674. writel(hqvdp->hqvdp_cmd_paddr + cmd_offset,
  675. hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  676. hqvdp->curr_field_count++;
  677. /* Interlaced : get ready to display the bottom field at next Vsync */
  678. if (fb->flags & DRM_MODE_FB_INTERLACED)
  679. hqvdp->btm_field_pending = true;
  680. dev_dbg(hqvdp->dev, "%s Posted command:0x%x\n",
  681. __func__, hqvdp->hqvdp_cmd_paddr + cmd_offset);
  682. plane->status = STI_PLANE_UPDATED;
  683. }
  684. static void sti_hqvdp_atomic_disable(struct drm_plane *drm_plane,
  685. struct drm_plane_state *oldstate)
  686. {
  687. struct sti_plane *plane = to_sti_plane(drm_plane);
  688. struct sti_mixer *mixer = to_sti_mixer(drm_plane->crtc);
  689. if (!drm_plane->crtc) {
  690. DRM_DEBUG_DRIVER("drm plane:%d not enabled\n",
  691. drm_plane->base.id);
  692. return;
  693. }
  694. DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n",
  695. drm_plane->crtc->base.id, sti_mixer_to_str(mixer),
  696. drm_plane->base.id, sti_plane_to_str(plane));
  697. plane->status = STI_PLANE_DISABLING;
  698. }
  699. static const struct drm_plane_helper_funcs sti_hqvdp_helpers_funcs = {
  700. .atomic_update = sti_hqvdp_atomic_update,
  701. .atomic_disable = sti_hqvdp_atomic_disable,
  702. };
  703. static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev,
  704. struct device *dev, int desc)
  705. {
  706. struct sti_hqvdp *hqvdp = dev_get_drvdata(dev);
  707. int res;
  708. hqvdp->plane.desc = desc;
  709. hqvdp->plane.status = STI_PLANE_DISABLED;
  710. sti_hqvdp_init(hqvdp);
  711. res = drm_universal_plane_init(drm_dev, &hqvdp->plane.drm_plane, 1,
  712. &sti_plane_helpers_funcs,
  713. hqvdp_supported_formats,
  714. ARRAY_SIZE(hqvdp_supported_formats),
  715. DRM_PLANE_TYPE_OVERLAY);
  716. if (res) {
  717. DRM_ERROR("Failed to initialize universal plane\n");
  718. return NULL;
  719. }
  720. drm_plane_helper_add(&hqvdp->plane.drm_plane, &sti_hqvdp_helpers_funcs);
  721. sti_plane_init_property(&hqvdp->plane, DRM_PLANE_TYPE_OVERLAY);
  722. return &hqvdp->plane.drm_plane;
  723. }
  724. static void sti_hqvdp_init_plugs(struct sti_hqvdp *hqvdp)
  725. {
  726. /* Configure Plugs (same for RD & WR) */
  727. writel(PLUG_PAGE_SIZE_256, hqvdp->regs + HQVDP_RD_PLUG_PAGE_SIZE);
  728. writel(PLUG_MIN_OPC_8, hqvdp->regs + HQVDP_RD_PLUG_MIN_OPC);
  729. writel(PLUG_MAX_OPC_64, hqvdp->regs + HQVDP_RD_PLUG_MAX_OPC);
  730. writel(PLUG_MAX_CHK_2X, hqvdp->regs + HQVDP_RD_PLUG_MAX_CHK);
  731. writel(PLUG_MAX_MSG_1X, hqvdp->regs + HQVDP_RD_PLUG_MAX_MSG);
  732. writel(PLUG_MIN_SPACE_1, hqvdp->regs + HQVDP_RD_PLUG_MIN_SPACE);
  733. writel(PLUG_CONTROL_ENABLE, hqvdp->regs + HQVDP_RD_PLUG_CONTROL);
  734. writel(PLUG_PAGE_SIZE_256, hqvdp->regs + HQVDP_WR_PLUG_PAGE_SIZE);
  735. writel(PLUG_MIN_OPC_8, hqvdp->regs + HQVDP_WR_PLUG_MIN_OPC);
  736. writel(PLUG_MAX_OPC_64, hqvdp->regs + HQVDP_WR_PLUG_MAX_OPC);
  737. writel(PLUG_MAX_CHK_2X, hqvdp->regs + HQVDP_WR_PLUG_MAX_CHK);
  738. writel(PLUG_MAX_MSG_1X, hqvdp->regs + HQVDP_WR_PLUG_MAX_MSG);
  739. writel(PLUG_MIN_SPACE_1, hqvdp->regs + HQVDP_WR_PLUG_MIN_SPACE);
  740. writel(PLUG_CONTROL_ENABLE, hqvdp->regs + HQVDP_WR_PLUG_CONTROL);
  741. }
  742. /**
  743. * sti_hqvdp_start_xp70
  744. * @firmware: firmware found
  745. * @ctxt: hqvdp structure
  746. *
  747. * Run the xP70 initialization sequence
  748. */
  749. static void sti_hqvdp_start_xp70(const struct firmware *firmware, void *ctxt)
  750. {
  751. struct sti_hqvdp *hqvdp = ctxt;
  752. u32 *fw_rd_plug, *fw_wr_plug, *fw_pmem, *fw_dmem;
  753. u8 *data;
  754. int i;
  755. struct fw_header {
  756. int rd_size;
  757. int wr_size;
  758. int pmem_size;
  759. int dmem_size;
  760. } *header;
  761. DRM_DEBUG_DRIVER("\n");
  762. if (hqvdp->xp70_initialized) {
  763. DRM_INFO("HQVDP XP70 already initialized\n");
  764. return;
  765. }
  766. /* Check firmware parts */
  767. if (!firmware) {
  768. DRM_ERROR("Firmware not available\n");
  769. return;
  770. }
  771. header = (struct fw_header *) firmware->data;
  772. if (firmware->size < sizeof(*header)) {
  773. DRM_ERROR("Invalid firmware size (%d)\n", firmware->size);
  774. goto out;
  775. }
  776. if ((sizeof(*header) + header->rd_size + header->wr_size +
  777. header->pmem_size + header->dmem_size) != firmware->size) {
  778. DRM_ERROR("Invalid fmw structure (%d+%d+%d+%d+%d != %d)\n",
  779. sizeof(*header), header->rd_size, header->wr_size,
  780. header->pmem_size, header->dmem_size,
  781. firmware->size);
  782. goto out;
  783. }
  784. data = (u8 *) firmware->data;
  785. data += sizeof(*header);
  786. fw_rd_plug = (void *) data;
  787. data += header->rd_size;
  788. fw_wr_plug = (void *) data;
  789. data += header->wr_size;
  790. fw_pmem = (void *) data;
  791. data += header->pmem_size;
  792. fw_dmem = (void *) data;
  793. /* Enable clock */
  794. if (clk_prepare_enable(hqvdp->clk))
  795. DRM_ERROR("Failed to prepare/enable HQVDP clk\n");
  796. /* Reset */
  797. writel(SW_RESET_CTRL_FULL, hqvdp->regs + HQVDP_MBX_SW_RESET_CTRL);
  798. for (i = 0; i < POLL_MAX_ATTEMPT; i++) {
  799. if (readl(hqvdp->regs + HQVDP_MBX_STARTUP_CTRL1)
  800. & STARTUP_CTRL1_RST_DONE)
  801. break;
  802. msleep(POLL_DELAY_MS);
  803. }
  804. if (i == POLL_MAX_ATTEMPT) {
  805. DRM_ERROR("Could not reset\n");
  806. goto out;
  807. }
  808. /* Init Read & Write plugs */
  809. for (i = 0; i < header->rd_size / 4; i++)
  810. writel(fw_rd_plug[i], hqvdp->regs + HQVDP_RD_PLUG + i * 4);
  811. for (i = 0; i < header->wr_size / 4; i++)
  812. writel(fw_wr_plug[i], hqvdp->regs + HQVDP_WR_PLUG + i * 4);
  813. sti_hqvdp_init_plugs(hqvdp);
  814. /* Authorize Idle Mode */
  815. writel(STARTUP_CTRL1_AUTH_IDLE, hqvdp->regs + HQVDP_MBX_STARTUP_CTRL1);
  816. /* Prevent VTG interruption during the boot */
  817. writel(SOFT_VSYNC_SW_CTRL_IRQ, hqvdp->regs + HQVDP_MBX_SOFT_VSYNC);
  818. writel(0, hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  819. /* Download PMEM & DMEM */
  820. for (i = 0; i < header->pmem_size / 4; i++)
  821. writel(fw_pmem[i], hqvdp->regs + HQVDP_PMEM + i * 4);
  822. for (i = 0; i < header->dmem_size / 4; i++)
  823. writel(fw_dmem[i], hqvdp->regs + HQVDP_DMEM + i * 4);
  824. /* Enable fetch */
  825. writel(STARTUP_CTRL2_FETCH_EN, hqvdp->regs + HQVDP_MBX_STARTUP_CTRL2);
  826. /* Wait end of boot */
  827. for (i = 0; i < POLL_MAX_ATTEMPT; i++) {
  828. if (readl(hqvdp->regs + HQVDP_MBX_INFO_XP70)
  829. & INFO_XP70_FW_READY)
  830. break;
  831. msleep(POLL_DELAY_MS);
  832. }
  833. if (i == POLL_MAX_ATTEMPT) {
  834. DRM_ERROR("Could not boot\n");
  835. goto out;
  836. }
  837. /* Launch Vsync */
  838. writel(SOFT_VSYNC_HW, hqvdp->regs + HQVDP_MBX_SOFT_VSYNC);
  839. DRM_INFO("HQVDP XP70 initialized\n");
  840. hqvdp->xp70_initialized = true;
  841. out:
  842. release_firmware(firmware);
  843. }
  844. int sti_hqvdp_bind(struct device *dev, struct device *master, void *data)
  845. {
  846. struct sti_hqvdp *hqvdp = dev_get_drvdata(dev);
  847. struct drm_device *drm_dev = data;
  848. struct drm_plane *plane;
  849. int err;
  850. DRM_DEBUG_DRIVER("\n");
  851. hqvdp->drm_dev = drm_dev;
  852. /* Request for firmware */
  853. err = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
  854. HQVDP_FMW_NAME, hqvdp->dev,
  855. GFP_KERNEL, hqvdp, sti_hqvdp_start_xp70);
  856. if (err) {
  857. DRM_ERROR("Can't get HQVDP firmware\n");
  858. return err;
  859. }
  860. /* Create HQVDP plane once xp70 is initialized */
  861. plane = sti_hqvdp_create(drm_dev, hqvdp->dev, STI_HQVDP_0);
  862. if (!plane)
  863. DRM_ERROR("Can't create HQVDP plane\n");
  864. return 0;
  865. }
  866. static void sti_hqvdp_unbind(struct device *dev,
  867. struct device *master, void *data)
  868. {
  869. /* do nothing */
  870. }
  871. static const struct component_ops sti_hqvdp_ops = {
  872. .bind = sti_hqvdp_bind,
  873. .unbind = sti_hqvdp_unbind,
  874. };
  875. static int sti_hqvdp_probe(struct platform_device *pdev)
  876. {
  877. struct device *dev = &pdev->dev;
  878. struct device_node *vtg_np;
  879. struct sti_hqvdp *hqvdp;
  880. struct resource *res;
  881. DRM_DEBUG_DRIVER("\n");
  882. hqvdp = devm_kzalloc(dev, sizeof(*hqvdp), GFP_KERNEL);
  883. if (!hqvdp) {
  884. DRM_ERROR("Failed to allocate HQVDP context\n");
  885. return -ENOMEM;
  886. }
  887. hqvdp->dev = dev;
  888. /* Get Memory resources */
  889. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  890. if (res == NULL) {
  891. DRM_ERROR("Get memory resource failed\n");
  892. return -ENXIO;
  893. }
  894. hqvdp->regs = devm_ioremap(dev, res->start, resource_size(res));
  895. if (hqvdp->regs == NULL) {
  896. DRM_ERROR("Register mapping failed\n");
  897. return -ENXIO;
  898. }
  899. /* Get clock resources */
  900. hqvdp->clk = devm_clk_get(dev, "hqvdp");
  901. hqvdp->clk_pix_main = devm_clk_get(dev, "pix_main");
  902. if (IS_ERR(hqvdp->clk) || IS_ERR(hqvdp->clk_pix_main)) {
  903. DRM_ERROR("Cannot get clocks\n");
  904. return -ENXIO;
  905. }
  906. /* Get reset resources */
  907. hqvdp->reset = devm_reset_control_get(dev, "hqvdp");
  908. if (!IS_ERR(hqvdp->reset))
  909. reset_control_deassert(hqvdp->reset);
  910. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  911. if (vtg_np)
  912. hqvdp->vtg = of_vtg_find(vtg_np);
  913. platform_set_drvdata(pdev, hqvdp);
  914. return component_add(&pdev->dev, &sti_hqvdp_ops);
  915. }
  916. static int sti_hqvdp_remove(struct platform_device *pdev)
  917. {
  918. component_del(&pdev->dev, &sti_hqvdp_ops);
  919. return 0;
  920. }
  921. static struct of_device_id hqvdp_of_match[] = {
  922. { .compatible = "st,stih407-hqvdp", },
  923. { /* end node */ }
  924. };
  925. MODULE_DEVICE_TABLE(of, hqvdp_of_match);
  926. struct platform_driver sti_hqvdp_driver = {
  927. .driver = {
  928. .name = "sti-hqvdp",
  929. .owner = THIS_MODULE,
  930. .of_match_table = hqvdp_of_match,
  931. },
  932. .probe = sti_hqvdp_probe,
  933. .remove = sti_hqvdp_remove,
  934. };
  935. module_platform_driver(sti_hqvdp_driver);
  936. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  937. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  938. MODULE_LICENSE("GPL");