sti_hqvdp.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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_init_plugs(struct sti_hqvdp *hqvdp)
  554. {
  555. /* Configure Plugs (same for RD & WR) */
  556. writel(PLUG_PAGE_SIZE_256, hqvdp->regs + HQVDP_RD_PLUG_PAGE_SIZE);
  557. writel(PLUG_MIN_OPC_8, hqvdp->regs + HQVDP_RD_PLUG_MIN_OPC);
  558. writel(PLUG_MAX_OPC_64, hqvdp->regs + HQVDP_RD_PLUG_MAX_OPC);
  559. writel(PLUG_MAX_CHK_2X, hqvdp->regs + HQVDP_RD_PLUG_MAX_CHK);
  560. writel(PLUG_MAX_MSG_1X, hqvdp->regs + HQVDP_RD_PLUG_MAX_MSG);
  561. writel(PLUG_MIN_SPACE_1, hqvdp->regs + HQVDP_RD_PLUG_MIN_SPACE);
  562. writel(PLUG_CONTROL_ENABLE, hqvdp->regs + HQVDP_RD_PLUG_CONTROL);
  563. writel(PLUG_PAGE_SIZE_256, hqvdp->regs + HQVDP_WR_PLUG_PAGE_SIZE);
  564. writel(PLUG_MIN_OPC_8, hqvdp->regs + HQVDP_WR_PLUG_MIN_OPC);
  565. writel(PLUG_MAX_OPC_64, hqvdp->regs + HQVDP_WR_PLUG_MAX_OPC);
  566. writel(PLUG_MAX_CHK_2X, hqvdp->regs + HQVDP_WR_PLUG_MAX_CHK);
  567. writel(PLUG_MAX_MSG_1X, hqvdp->regs + HQVDP_WR_PLUG_MAX_MSG);
  568. writel(PLUG_MIN_SPACE_1, hqvdp->regs + HQVDP_WR_PLUG_MIN_SPACE);
  569. writel(PLUG_CONTROL_ENABLE, hqvdp->regs + HQVDP_WR_PLUG_CONTROL);
  570. }
  571. /**
  572. * sti_hqvdp_start_xp70
  573. * @hqvdp: hqvdp pointer
  574. *
  575. * Run the xP70 initialization sequence
  576. */
  577. static void sti_hqvdp_start_xp70(struct sti_hqvdp *hqvdp)
  578. {
  579. const struct firmware *firmware;
  580. u32 *fw_rd_plug, *fw_wr_plug, *fw_pmem, *fw_dmem;
  581. u8 *data;
  582. int i;
  583. struct fw_header {
  584. int rd_size;
  585. int wr_size;
  586. int pmem_size;
  587. int dmem_size;
  588. } *header;
  589. DRM_DEBUG_DRIVER("\n");
  590. if (hqvdp->xp70_initialized) {
  591. DRM_INFO("HQVDP XP70 already initialized\n");
  592. return;
  593. }
  594. /* Request firmware */
  595. if (request_firmware(&firmware, HQVDP_FMW_NAME, hqvdp->dev)) {
  596. DRM_ERROR("Can't get HQVDP firmware\n");
  597. return;
  598. }
  599. /* Check firmware parts */
  600. if (!firmware) {
  601. DRM_ERROR("Firmware not available\n");
  602. return;
  603. }
  604. header = (struct fw_header *)firmware->data;
  605. if (firmware->size < sizeof(*header)) {
  606. DRM_ERROR("Invalid firmware size (%d)\n", firmware->size);
  607. goto out;
  608. }
  609. if ((sizeof(*header) + header->rd_size + header->wr_size +
  610. header->pmem_size + header->dmem_size) != firmware->size) {
  611. DRM_ERROR("Invalid fmw structure (%d+%d+%d+%d+%d != %d)\n",
  612. sizeof(*header), header->rd_size, header->wr_size,
  613. header->pmem_size, header->dmem_size,
  614. firmware->size);
  615. goto out;
  616. }
  617. data = (u8 *)firmware->data;
  618. data += sizeof(*header);
  619. fw_rd_plug = (void *)data;
  620. data += header->rd_size;
  621. fw_wr_plug = (void *)data;
  622. data += header->wr_size;
  623. fw_pmem = (void *)data;
  624. data += header->pmem_size;
  625. fw_dmem = (void *)data;
  626. /* Enable clock */
  627. if (clk_prepare_enable(hqvdp->clk))
  628. DRM_ERROR("Failed to prepare/enable HQVDP clk\n");
  629. /* Reset */
  630. writel(SW_RESET_CTRL_FULL, hqvdp->regs + HQVDP_MBX_SW_RESET_CTRL);
  631. for (i = 0; i < POLL_MAX_ATTEMPT; i++) {
  632. if (readl(hqvdp->regs + HQVDP_MBX_STARTUP_CTRL1)
  633. & STARTUP_CTRL1_RST_DONE)
  634. break;
  635. msleep(POLL_DELAY_MS);
  636. }
  637. if (i == POLL_MAX_ATTEMPT) {
  638. DRM_ERROR("Could not reset\n");
  639. goto out;
  640. }
  641. /* Init Read & Write plugs */
  642. for (i = 0; i < header->rd_size / 4; i++)
  643. writel(fw_rd_plug[i], hqvdp->regs + HQVDP_RD_PLUG + i * 4);
  644. for (i = 0; i < header->wr_size / 4; i++)
  645. writel(fw_wr_plug[i], hqvdp->regs + HQVDP_WR_PLUG + i * 4);
  646. sti_hqvdp_init_plugs(hqvdp);
  647. /* Authorize Idle Mode */
  648. writel(STARTUP_CTRL1_AUTH_IDLE, hqvdp->regs + HQVDP_MBX_STARTUP_CTRL1);
  649. /* Prevent VTG interruption during the boot */
  650. writel(SOFT_VSYNC_SW_CTRL_IRQ, hqvdp->regs + HQVDP_MBX_SOFT_VSYNC);
  651. writel(0, hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  652. /* Download PMEM & DMEM */
  653. for (i = 0; i < header->pmem_size / 4; i++)
  654. writel(fw_pmem[i], hqvdp->regs + HQVDP_PMEM + i * 4);
  655. for (i = 0; i < header->dmem_size / 4; i++)
  656. writel(fw_dmem[i], hqvdp->regs + HQVDP_DMEM + i * 4);
  657. /* Enable fetch */
  658. writel(STARTUP_CTRL2_FETCH_EN, hqvdp->regs + HQVDP_MBX_STARTUP_CTRL2);
  659. /* Wait end of boot */
  660. for (i = 0; i < POLL_MAX_ATTEMPT; i++) {
  661. if (readl(hqvdp->regs + HQVDP_MBX_INFO_XP70)
  662. & INFO_XP70_FW_READY)
  663. break;
  664. msleep(POLL_DELAY_MS);
  665. }
  666. if (i == POLL_MAX_ATTEMPT) {
  667. DRM_ERROR("Could not boot\n");
  668. goto out;
  669. }
  670. /* Launch Vsync */
  671. writel(SOFT_VSYNC_HW, hqvdp->regs + HQVDP_MBX_SOFT_VSYNC);
  672. DRM_INFO("HQVDP XP70 initialized\n");
  673. hqvdp->xp70_initialized = true;
  674. out:
  675. release_firmware(firmware);
  676. }
  677. static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane,
  678. struct drm_plane_state *oldstate)
  679. {
  680. struct drm_plane_state *state = drm_plane->state;
  681. struct sti_plane *plane = to_sti_plane(drm_plane);
  682. struct sti_hqvdp *hqvdp = to_sti_hqvdp(plane);
  683. struct drm_crtc *crtc = state->crtc;
  684. struct sti_mixer *mixer = to_sti_mixer(crtc);
  685. struct drm_framebuffer *fb = state->fb;
  686. struct drm_display_mode *mode = &crtc->mode;
  687. int dst_x = state->crtc_x;
  688. int dst_y = state->crtc_y;
  689. int dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x);
  690. int dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y);
  691. /* src_x are in 16.16 format */
  692. int src_x = state->src_x >> 16;
  693. int src_y = state->src_y >> 16;
  694. int src_w = state->src_w >> 16;
  695. int src_h = state->src_h >> 16;
  696. bool first_prepare = plane->status == STI_PLANE_DISABLED ? true : false;
  697. struct drm_gem_cma_object *cma_obj;
  698. struct sti_hqvdp_cmd *cmd;
  699. int scale_h, scale_v;
  700. int cmd_offset;
  701. DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
  702. crtc->base.id, sti_mixer_to_str(mixer),
  703. drm_plane->base.id, sti_plane_to_str(plane));
  704. DRM_DEBUG_KMS("%s dst=(%dx%d)@(%d,%d) - src=(%dx%d)@(%d,%d)\n",
  705. sti_plane_to_str(plane),
  706. dst_w, dst_h, dst_x, dst_y,
  707. src_w, src_h, src_x, src_y);
  708. cmd_offset = sti_hqvdp_get_free_cmd(hqvdp);
  709. if (cmd_offset == -1) {
  710. DRM_ERROR("No available hqvdp_cmd now\n");
  711. return;
  712. }
  713. cmd = hqvdp->hqvdp_cmd + cmd_offset;
  714. if (!sti_hqvdp_check_hw_scaling(hqvdp, mode,
  715. src_w, src_h,
  716. dst_w, dst_h)) {
  717. DRM_ERROR("Scaling beyond HW capabilities\n");
  718. return;
  719. }
  720. /* Static parameters, defaulting to progressive mode */
  721. cmd->top.config = TOP_CONFIG_PROGRESSIVE;
  722. cmd->top.mem_format = TOP_MEM_FORMAT_DFLT;
  723. cmd->hvsrc.param_ctrl = HVSRC_PARAM_CTRL_DFLT;
  724. cmd->csdi.config = CSDI_CONFIG_PROG;
  725. /* VC1RE, FMD bypassed : keep everything set to 0
  726. * IQI/P2I bypassed */
  727. cmd->iqi.config = IQI_CONFIG_DFLT;
  728. cmd->iqi.con_bri = IQI_CON_BRI_DFLT;
  729. cmd->iqi.sat_gain = IQI_SAT_GAIN_DFLT;
  730. cmd->iqi.pxf_conf = IQI_PXF_CONF_DFLT;
  731. cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
  732. if (!cma_obj) {
  733. DRM_ERROR("Can't get CMA GEM object for fb\n");
  734. return;
  735. }
  736. DRM_DEBUG_DRIVER("drm FB:%d format:%.4s phys@:0x%lx\n", fb->base.id,
  737. (char *)&fb->pixel_format,
  738. (unsigned long)cma_obj->paddr);
  739. /* Buffer planes address */
  740. cmd->top.current_luma = (u32)cma_obj->paddr + fb->offsets[0];
  741. cmd->top.current_chroma = (u32)cma_obj->paddr + fb->offsets[1];
  742. /* Pitches */
  743. cmd->top.luma_processed_pitch = fb->pitches[0];
  744. cmd->top.luma_src_pitch = fb->pitches[0];
  745. cmd->top.chroma_processed_pitch = fb->pitches[1];
  746. cmd->top.chroma_src_pitch = fb->pitches[1];
  747. /* Input / output size
  748. * Align to upper even value */
  749. dst_w = ALIGN(dst_w, 2);
  750. dst_h = ALIGN(dst_h, 2);
  751. if ((src_w > MAX_WIDTH) || (src_w < MIN_WIDTH) ||
  752. (src_h > MAX_HEIGHT) || (src_h < MIN_HEIGHT) ||
  753. (dst_w > MAX_WIDTH) || (dst_w < MIN_WIDTH) ||
  754. (dst_h > MAX_HEIGHT) || (dst_h < MIN_HEIGHT)) {
  755. DRM_ERROR("Invalid in/out size %dx%d -> %dx%d\n",
  756. src_w, src_h,
  757. dst_w, dst_h);
  758. return;
  759. }
  760. cmd->top.input_viewport_size = src_h << 16 | src_w;
  761. cmd->top.input_frame_size = src_h << 16 | src_w;
  762. cmd->hvsrc.output_picture_size = dst_h << 16 | dst_w;
  763. cmd->top.input_viewport_ori = src_y << 16 | src_x;
  764. /* Handle interlaced */
  765. if (fb->flags & DRM_MODE_FB_INTERLACED) {
  766. /* Top field to display */
  767. cmd->top.config = TOP_CONFIG_INTER_TOP;
  768. /* Update pitches and vert size */
  769. cmd->top.input_frame_size = (src_h / 2) << 16 | src_w;
  770. cmd->top.luma_processed_pitch *= 2;
  771. cmd->top.luma_src_pitch *= 2;
  772. cmd->top.chroma_processed_pitch *= 2;
  773. cmd->top.chroma_src_pitch *= 2;
  774. /* Enable directional deinterlacing processing */
  775. cmd->csdi.config = CSDI_CONFIG_INTER_DIR;
  776. cmd->csdi.config2 = CSDI_CONFIG2_DFLT;
  777. cmd->csdi.dcdi_config = CSDI_DCDI_CONFIG_DFLT;
  778. }
  779. /* Update hvsrc lut coef */
  780. scale_h = SCALE_FACTOR * dst_w / src_w;
  781. sti_hqvdp_update_hvsrc(HVSRC_HORI, scale_h, &cmd->hvsrc);
  782. scale_v = SCALE_FACTOR * dst_h / src_h;
  783. sti_hqvdp_update_hvsrc(HVSRC_VERT, scale_v, &cmd->hvsrc);
  784. if (first_prepare) {
  785. /* Start HQVDP XP70 coprocessor */
  786. sti_hqvdp_start_xp70(hqvdp);
  787. /* Prevent VTG shutdown */
  788. if (clk_prepare_enable(hqvdp->clk_pix_main)) {
  789. DRM_ERROR("Failed to prepare/enable pix main clk\n");
  790. return;
  791. }
  792. /* Register VTG Vsync callback to handle bottom fields */
  793. if (sti_vtg_register_client(hqvdp->vtg,
  794. &hqvdp->vtg_nb,
  795. crtc)) {
  796. DRM_ERROR("Cannot register VTG notifier\n");
  797. return;
  798. }
  799. }
  800. writel(hqvdp->hqvdp_cmd_paddr + cmd_offset,
  801. hqvdp->regs + HQVDP_MBX_NEXT_CMD);
  802. hqvdp->curr_field_count++;
  803. /* Interlaced : get ready to display the bottom field at next Vsync */
  804. if (fb->flags & DRM_MODE_FB_INTERLACED)
  805. hqvdp->btm_field_pending = true;
  806. dev_dbg(hqvdp->dev, "%s Posted command:0x%x\n",
  807. __func__, hqvdp->hqvdp_cmd_paddr + cmd_offset);
  808. plane->status = STI_PLANE_UPDATED;
  809. }
  810. static void sti_hqvdp_atomic_disable(struct drm_plane *drm_plane,
  811. struct drm_plane_state *oldstate)
  812. {
  813. struct sti_plane *plane = to_sti_plane(drm_plane);
  814. struct sti_mixer *mixer = to_sti_mixer(drm_plane->crtc);
  815. if (!drm_plane->crtc) {
  816. DRM_DEBUG_DRIVER("drm plane:%d not enabled\n",
  817. drm_plane->base.id);
  818. return;
  819. }
  820. DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n",
  821. drm_plane->crtc->base.id, sti_mixer_to_str(mixer),
  822. drm_plane->base.id, sti_plane_to_str(plane));
  823. plane->status = STI_PLANE_DISABLING;
  824. }
  825. static const struct drm_plane_helper_funcs sti_hqvdp_helpers_funcs = {
  826. .atomic_update = sti_hqvdp_atomic_update,
  827. .atomic_disable = sti_hqvdp_atomic_disable,
  828. };
  829. static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev,
  830. struct device *dev, int desc)
  831. {
  832. struct sti_hqvdp *hqvdp = dev_get_drvdata(dev);
  833. int res;
  834. hqvdp->plane.desc = desc;
  835. hqvdp->plane.status = STI_PLANE_DISABLED;
  836. sti_hqvdp_init(hqvdp);
  837. res = drm_universal_plane_init(drm_dev, &hqvdp->plane.drm_plane, 1,
  838. &sti_plane_helpers_funcs,
  839. hqvdp_supported_formats,
  840. ARRAY_SIZE(hqvdp_supported_formats),
  841. DRM_PLANE_TYPE_OVERLAY);
  842. if (res) {
  843. DRM_ERROR("Failed to initialize universal plane\n");
  844. return NULL;
  845. }
  846. drm_plane_helper_add(&hqvdp->plane.drm_plane, &sti_hqvdp_helpers_funcs);
  847. sti_plane_init_property(&hqvdp->plane, DRM_PLANE_TYPE_OVERLAY);
  848. return &hqvdp->plane.drm_plane;
  849. }
  850. int sti_hqvdp_bind(struct device *dev, struct device *master, void *data)
  851. {
  852. struct sti_hqvdp *hqvdp = dev_get_drvdata(dev);
  853. struct drm_device *drm_dev = data;
  854. struct drm_plane *plane;
  855. DRM_DEBUG_DRIVER("\n");
  856. hqvdp->drm_dev = drm_dev;
  857. /* Create HQVDP plane once xp70 is initialized */
  858. plane = sti_hqvdp_create(drm_dev, hqvdp->dev, STI_HQVDP_0);
  859. if (!plane)
  860. DRM_ERROR("Can't create HQVDP plane\n");
  861. return 0;
  862. }
  863. static void sti_hqvdp_unbind(struct device *dev,
  864. struct device *master, void *data)
  865. {
  866. /* do nothing */
  867. }
  868. static const struct component_ops sti_hqvdp_ops = {
  869. .bind = sti_hqvdp_bind,
  870. .unbind = sti_hqvdp_unbind,
  871. };
  872. static int sti_hqvdp_probe(struct platform_device *pdev)
  873. {
  874. struct device *dev = &pdev->dev;
  875. struct device_node *vtg_np;
  876. struct sti_hqvdp *hqvdp;
  877. struct resource *res;
  878. DRM_DEBUG_DRIVER("\n");
  879. hqvdp = devm_kzalloc(dev, sizeof(*hqvdp), GFP_KERNEL);
  880. if (!hqvdp) {
  881. DRM_ERROR("Failed to allocate HQVDP context\n");
  882. return -ENOMEM;
  883. }
  884. hqvdp->dev = dev;
  885. /* Get Memory resources */
  886. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  887. if (res == NULL) {
  888. DRM_ERROR("Get memory resource failed\n");
  889. return -ENXIO;
  890. }
  891. hqvdp->regs = devm_ioremap(dev, res->start, resource_size(res));
  892. if (hqvdp->regs == NULL) {
  893. DRM_ERROR("Register mapping failed\n");
  894. return -ENXIO;
  895. }
  896. /* Get clock resources */
  897. hqvdp->clk = devm_clk_get(dev, "hqvdp");
  898. hqvdp->clk_pix_main = devm_clk_get(dev, "pix_main");
  899. if (IS_ERR(hqvdp->clk) || IS_ERR(hqvdp->clk_pix_main)) {
  900. DRM_ERROR("Cannot get clocks\n");
  901. return -ENXIO;
  902. }
  903. /* Get reset resources */
  904. hqvdp->reset = devm_reset_control_get(dev, "hqvdp");
  905. if (!IS_ERR(hqvdp->reset))
  906. reset_control_deassert(hqvdp->reset);
  907. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  908. if (vtg_np)
  909. hqvdp->vtg = of_vtg_find(vtg_np);
  910. platform_set_drvdata(pdev, hqvdp);
  911. return component_add(&pdev->dev, &sti_hqvdp_ops);
  912. }
  913. static int sti_hqvdp_remove(struct platform_device *pdev)
  914. {
  915. component_del(&pdev->dev, &sti_hqvdp_ops);
  916. return 0;
  917. }
  918. static struct of_device_id hqvdp_of_match[] = {
  919. { .compatible = "st,stih407-hqvdp", },
  920. { /* end node */ }
  921. };
  922. MODULE_DEVICE_TABLE(of, hqvdp_of_match);
  923. struct platform_driver sti_hqvdp_driver = {
  924. .driver = {
  925. .name = "sti-hqvdp",
  926. .owner = THIS_MODULE,
  927. .of_match_table = hqvdp_of_match,
  928. },
  929. .probe = sti_hqvdp_probe,
  930. .remove = sti_hqvdp_remove,
  931. };
  932. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  933. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  934. MODULE_LICENSE("GPL");