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