1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics SA 2014
4 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
5 * Vincent Abriou <vincent.abriou@st.com>
6 * for STMicroelectronics.
10 #include <linux/component.h>
12 #include <linux/module.h>
13 #include <linux/of_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/reset.h>
16 #include <linux/seq_file.h>
18 #include <drm/drm_atomic_helper.h>
19 #include <drm/drm_debugfs.h>
20 #include <drm/drm_device.h>
21 #include <drm/drm_file.h>
22 #include <drm/drm_print.h>
29 #define TVO_CSC_MAIN_M0 0x000
30 #define TVO_CSC_MAIN_M1 0x004
31 #define TVO_CSC_MAIN_M2 0x008
32 #define TVO_CSC_MAIN_M3 0x00c
33 #define TVO_CSC_MAIN_M4 0x010
34 #define TVO_CSC_MAIN_M5 0x014
35 #define TVO_CSC_MAIN_M6 0x018
36 #define TVO_CSC_MAIN_M7 0x01c
37 #define TVO_MAIN_IN_VID_FORMAT 0x030
38 #define TVO_CSC_AUX_M0 0x100
39 #define TVO_CSC_AUX_M1 0x104
40 #define TVO_CSC_AUX_M2 0x108
41 #define TVO_CSC_AUX_M3 0x10c
42 #define TVO_CSC_AUX_M4 0x110
43 #define TVO_CSC_AUX_M5 0x114
44 #define TVO_CSC_AUX_M6 0x118
45 #define TVO_CSC_AUX_M7 0x11c
46 #define TVO_AUX_IN_VID_FORMAT 0x130
47 #define TVO_VIP_HDF 0x400
48 #define TVO_HD_SYNC_SEL 0x418
49 #define TVO_HD_DAC_CFG_OFF 0x420
50 #define TVO_VIP_HDMI 0x500
51 #define TVO_HDMI_FORCE_COLOR_0 0x504
52 #define TVO_HDMI_FORCE_COLOR_1 0x508
53 #define TVO_HDMI_CLIP_VALUE_B_CB 0x50c
54 #define TVO_HDMI_CLIP_VALUE_Y_G 0x510
55 #define TVO_HDMI_CLIP_VALUE_R_CR 0x514
56 #define TVO_HDMI_SYNC_SEL 0x518
57 #define TVO_HDMI_DFV_OBS 0x540
58 #define TVO_VIP_DVO 0x600
59 #define TVO_DVO_SYNC_SEL 0x618
60 #define TVO_DVO_CONFIG 0x620
62 #define TVO_IN_FMT_SIGNED BIT(0)
63 #define TVO_SYNC_EXT BIT(4)
65 #define TVO_VIP_REORDER_R_SHIFT 24
66 #define TVO_VIP_REORDER_G_SHIFT 20
67 #define TVO_VIP_REORDER_B_SHIFT 16
68 #define TVO_VIP_REORDER_MASK 0x3
69 #define TVO_VIP_REORDER_Y_G_SEL 0
70 #define TVO_VIP_REORDER_CB_B_SEL 1
71 #define TVO_VIP_REORDER_CR_R_SEL 2
73 #define TVO_VIP_CLIP_SHIFT 8
74 #define TVO_VIP_CLIP_MASK 0x7
75 #define TVO_VIP_CLIP_DISABLED 0
76 #define TVO_VIP_CLIP_EAV_SAV 1
77 #define TVO_VIP_CLIP_LIMITED_RANGE_RGB_Y 2
78 #define TVO_VIP_CLIP_LIMITED_RANGE_CB_CR 3
79 #define TVO_VIP_CLIP_PROG_RANGE 4
81 #define TVO_VIP_RND_SHIFT 4
82 #define TVO_VIP_RND_MASK 0x3
83 #define TVO_VIP_RND_8BIT_ROUNDED 0
84 #define TVO_VIP_RND_10BIT_ROUNDED 1
85 #define TVO_VIP_RND_12BIT_ROUNDED 2
87 #define TVO_VIP_SEL_INPUT_MASK 0xf
88 #define TVO_VIP_SEL_INPUT_MAIN 0x0
89 #define TVO_VIP_SEL_INPUT_AUX 0x8
90 #define TVO_VIP_SEL_INPUT_FORCE_COLOR 0xf
91 #define TVO_VIP_SEL_INPUT_BYPASS_MASK 0x1
92 #define TVO_VIP_SEL_INPUT_BYPASSED 1
94 #define TVO_SYNC_MAIN_VTG_SET_REF 0x00
95 #define TVO_SYNC_AUX_VTG_SET_REF 0x10
97 #define TVO_SYNC_HD_DCS_SHIFT 8
99 #define TVO_SYNC_DVO_PAD_HSYNC_SHIFT 8
100 #define TVO_SYNC_DVO_PAD_VSYNC_SHIFT 16
102 #define ENCODER_CRTC_MASK (BIT(0) | BIT(1))
104 #define TVO_MIN_HD_HEIGHT 720
106 /* enum listing the supported output data format */
107 enum sti_tvout_video_out_type {
108 STI_TVOUT_VIDEO_OUT_RGB,
109 STI_TVOUT_VIDEO_OUT_YUV,
114 struct drm_device *drm_dev;
116 struct reset_control *reset;
117 struct drm_encoder *hdmi;
118 struct drm_encoder *hda;
119 struct drm_encoder *dvo;
120 bool debugfs_registered;
123 struct sti_tvout_encoder {
124 struct drm_encoder encoder;
125 struct sti_tvout *tvout;
128 #define to_sti_tvout_encoder(x) \
129 container_of(x, struct sti_tvout_encoder, encoder)
131 #define to_sti_tvout(x) to_sti_tvout_encoder(x)->tvout
133 /* preformatter conversion matrix */
134 static const u32 rgb_to_ycbcr_601[8] = {
135 0xF927082E, 0x04C9FEAB, 0x01D30964, 0xFA95FD3D,
136 0x0000082E, 0x00002000, 0x00002000, 0x00000000
139 /* 709 RGB to YCbCr */
140 static const u32 rgb_to_ycbcr_709[8] = {
141 0xF891082F, 0x0367FF40, 0x01280B71, 0xF9B1FE20,
142 0x0000082F, 0x00002000, 0x00002000, 0x00000000
145 static u32 tvout_read(struct sti_tvout *tvout, int offset)
147 return readl(tvout->regs + offset);
150 static void tvout_write(struct sti_tvout *tvout, u32 val, int offset)
152 writel(val, tvout->regs + offset);
156 * tvout_vip_set_color_order - Set the clipping mode of a VIP
158 * @tvout: tvout structure
159 * @reg: register to set
160 * @cr_r: red chroma or red order
161 * @y_g: y or green order
162 * @cb_b: blue chroma or blue order
164 static void tvout_vip_set_color_order(struct sti_tvout *tvout, int reg,
165 u32 cr_r, u32 y_g, u32 cb_b)
167 u32 val = tvout_read(tvout, reg);
169 val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT);
170 val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT);
171 val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT);
172 val |= cr_r << TVO_VIP_REORDER_R_SHIFT;
173 val |= y_g << TVO_VIP_REORDER_G_SHIFT;
174 val |= cb_b << TVO_VIP_REORDER_B_SHIFT;
176 tvout_write(tvout, val, reg);
180 * tvout_vip_set_clip_mode - Set the clipping mode of a VIP
182 * @tvout: tvout structure
183 * @reg: register to set
184 * @range: clipping range
186 static void tvout_vip_set_clip_mode(struct sti_tvout *tvout, int reg, u32 range)
188 u32 val = tvout_read(tvout, reg);
190 val &= ~(TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT);
191 val |= range << TVO_VIP_CLIP_SHIFT;
192 tvout_write(tvout, val, reg);
196 * tvout_vip_set_rnd - Set the rounded value of a VIP
198 * @tvout: tvout structure
199 * @reg: register to set
200 * @rnd: rounded val per component
202 static void tvout_vip_set_rnd(struct sti_tvout *tvout, int reg, u32 rnd)
204 u32 val = tvout_read(tvout, reg);
206 val &= ~(TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT);
207 val |= rnd << TVO_VIP_RND_SHIFT;
208 tvout_write(tvout, val, reg);
212 * tvout_vip_set_sel_input - Select the VIP input
214 * @tvout: tvout structure
215 * @reg: register to set
216 * @main_path: main or auxiliary path
217 * @video_out: selected_input (main/aux + conv)
219 static void tvout_vip_set_sel_input(struct sti_tvout *tvout,
222 enum sti_tvout_video_out_type video_out)
225 u32 val = tvout_read(tvout, reg);
228 sel_input = TVO_VIP_SEL_INPUT_MAIN;
230 sel_input = TVO_VIP_SEL_INPUT_AUX;
233 case STI_TVOUT_VIDEO_OUT_RGB:
234 sel_input |= TVO_VIP_SEL_INPUT_BYPASSED;
236 case STI_TVOUT_VIDEO_OUT_YUV:
237 sel_input &= ~TVO_VIP_SEL_INPUT_BYPASSED;
241 /* on stih407 chip the sel_input bypass mode logic is inverted */
242 sel_input = sel_input ^ TVO_VIP_SEL_INPUT_BYPASS_MASK;
244 val &= ~TVO_VIP_SEL_INPUT_MASK;
246 tvout_write(tvout, val, reg);
250 * tvout_vip_set_in_vid_fmt - Select the input video signed or unsigned
252 * @tvout: tvout structure
253 * @reg: register to set
254 * @in_vid_fmt: used video input format
256 static void tvout_vip_set_in_vid_fmt(struct sti_tvout *tvout,
257 int reg, u32 in_vid_fmt)
259 u32 val = tvout_read(tvout, reg);
261 val &= ~TVO_IN_FMT_SIGNED;
263 tvout_write(tvout, val, reg);
267 * tvout_preformatter_set_matrix - Set preformatter matrix
269 * @tvout: tvout structure
270 * @mode: display mode structure
272 static void tvout_preformatter_set_matrix(struct sti_tvout *tvout,
273 struct drm_display_mode *mode)
276 const u32 *pf_matrix;
278 if (mode->vdisplay >= TVO_MIN_HD_HEIGHT)
279 pf_matrix = rgb_to_ycbcr_709;
281 pf_matrix = rgb_to_ycbcr_601;
283 for (i = 0; i < 8; i++) {
284 tvout_write(tvout, *(pf_matrix + i),
285 TVO_CSC_MAIN_M0 + (i * 4));
286 tvout_write(tvout, *(pf_matrix + i),
287 TVO_CSC_AUX_M0 + (i * 4));
292 * tvout_dvo_start - Start VIP block for DVO output
294 * @tvout: pointer on tvout structure
295 * @main_path: true if main path has to be used in the vip configuration
296 * else aux path is used.
298 static void tvout_dvo_start(struct sti_tvout *tvout, bool main_path)
300 u32 tvo_in_vid_format;
303 dev_dbg(tvout->dev, "%s\n", __func__);
306 DRM_DEBUG_DRIVER("main vip for DVO\n");
307 /* Select the input sync for dvo */
308 tmp = TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_DVO;
309 val = tmp << TVO_SYNC_DVO_PAD_VSYNC_SHIFT;
310 val |= tmp << TVO_SYNC_DVO_PAD_HSYNC_SHIFT;
312 tvout_write(tvout, val, TVO_DVO_SYNC_SEL);
313 tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT;
315 DRM_DEBUG_DRIVER("aux vip for DVO\n");
316 /* Select the input sync for dvo */
317 tmp = TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_DVO;
318 val = tmp << TVO_SYNC_DVO_PAD_VSYNC_SHIFT;
319 val |= tmp << TVO_SYNC_DVO_PAD_HSYNC_SHIFT;
321 tvout_write(tvout, val, TVO_DVO_SYNC_SEL);
322 tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT;
325 /* Set color channel order */
326 tvout_vip_set_color_order(tvout, TVO_VIP_DVO,
327 TVO_VIP_REORDER_CR_R_SEL,
328 TVO_VIP_REORDER_Y_G_SEL,
329 TVO_VIP_REORDER_CB_B_SEL);
331 /* Set clipping mode */
332 tvout_vip_set_clip_mode(tvout, TVO_VIP_DVO, TVO_VIP_CLIP_DISABLED);
334 /* Set round mode (rounded to 8-bit per component) */
335 tvout_vip_set_rnd(tvout, TVO_VIP_DVO, TVO_VIP_RND_8BIT_ROUNDED);
337 /* Set input video format */
338 tvout_vip_set_in_vid_fmt(tvout, tvo_in_vid_format, TVO_IN_FMT_SIGNED);
340 /* Input selection */
341 tvout_vip_set_sel_input(tvout, TVO_VIP_DVO, main_path,
342 STI_TVOUT_VIDEO_OUT_RGB);
346 * tvout_hdmi_start - Start VIP block for HDMI output
348 * @tvout: pointer on tvout structure
349 * @main_path: true if main path has to be used in the vip configuration
350 * else aux path is used.
352 static void tvout_hdmi_start(struct sti_tvout *tvout, bool main_path)
354 u32 tvo_in_vid_format;
356 dev_dbg(tvout->dev, "%s\n", __func__);
359 DRM_DEBUG_DRIVER("main vip for hdmi\n");
360 /* select the input sync for hdmi */
362 TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDMI,
364 tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT;
366 DRM_DEBUG_DRIVER("aux vip for hdmi\n");
367 /* select the input sync for hdmi */
369 TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDMI,
371 tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT;
374 /* set color channel order */
375 tvout_vip_set_color_order(tvout, TVO_VIP_HDMI,
376 TVO_VIP_REORDER_CR_R_SEL,
377 TVO_VIP_REORDER_Y_G_SEL,
378 TVO_VIP_REORDER_CB_B_SEL);
380 /* set clipping mode */
381 tvout_vip_set_clip_mode(tvout, TVO_VIP_HDMI, TVO_VIP_CLIP_DISABLED);
383 /* set round mode (rounded to 8-bit per component) */
384 tvout_vip_set_rnd(tvout, TVO_VIP_HDMI, TVO_VIP_RND_8BIT_ROUNDED);
386 /* set input video format */
387 tvout_vip_set_in_vid_fmt(tvout, tvo_in_vid_format, TVO_IN_FMT_SIGNED);
389 /* input selection */
390 tvout_vip_set_sel_input(tvout, TVO_VIP_HDMI, main_path,
391 STI_TVOUT_VIDEO_OUT_RGB);
395 * tvout_hda_start - Start HDF VIP and HD DAC
397 * @tvout: pointer on tvout structure
398 * @main_path: true if main path has to be used in the vip configuration
399 * else aux path is used.
401 static void tvout_hda_start(struct sti_tvout *tvout, bool main_path)
403 u32 tvo_in_vid_format;
406 dev_dbg(tvout->dev, "%s\n", __func__);
409 DRM_DEBUG_DRIVER("main vip for HDF\n");
410 /* Select the input sync for HD analog and HD DCS */
411 val = TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDDCS;
412 val = val << TVO_SYNC_HD_DCS_SHIFT;
413 val |= TVO_SYNC_MAIN_VTG_SET_REF | VTG_SYNC_ID_HDF;
414 tvout_write(tvout, val, TVO_HD_SYNC_SEL);
415 tvo_in_vid_format = TVO_MAIN_IN_VID_FORMAT;
417 DRM_DEBUG_DRIVER("aux vip for HDF\n");
418 /* Select the input sync for HD analog and HD DCS */
419 val = TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDDCS;
420 val = val << TVO_SYNC_HD_DCS_SHIFT;
421 val |= TVO_SYNC_AUX_VTG_SET_REF | VTG_SYNC_ID_HDF;
422 tvout_write(tvout, val, TVO_HD_SYNC_SEL);
423 tvo_in_vid_format = TVO_AUX_IN_VID_FORMAT;
426 /* set color channel order */
427 tvout_vip_set_color_order(tvout, TVO_VIP_HDF,
428 TVO_VIP_REORDER_CR_R_SEL,
429 TVO_VIP_REORDER_Y_G_SEL,
430 TVO_VIP_REORDER_CB_B_SEL);
432 /* set clipping mode */
433 tvout_vip_set_clip_mode(tvout, TVO_VIP_HDF, TVO_VIP_CLIP_DISABLED);
435 /* set round mode (rounded to 10-bit per component) */
436 tvout_vip_set_rnd(tvout, TVO_VIP_HDF, TVO_VIP_RND_10BIT_ROUNDED);
438 /* Set input video format */
439 tvout_vip_set_in_vid_fmt(tvout, tvo_in_vid_format, TVO_IN_FMT_SIGNED);
441 /* Input selection */
442 tvout_vip_set_sel_input(tvout, TVO_VIP_HDF, main_path,
443 STI_TVOUT_VIDEO_OUT_YUV);
445 /* power up HD DAC */
446 tvout_write(tvout, 0, TVO_HD_DAC_CFG_OFF);
449 #define DBGFS_DUMP(reg) seq_printf(s, "\n %-25s 0x%08X", #reg, \
450 readl(tvout->regs + reg))
452 static void tvout_dbg_vip(struct seq_file *s, int val)
454 int r, g, b, tmp, mask;
455 char *const reorder[] = {"Y_G", "Cb_B", "Cr_R"};
456 char *const clipping[] = {"No", "EAV/SAV", "Limited range RGB/Y",
457 "Limited range Cb/Cr", "decided by register"};
458 char *const round[] = {"8-bit", "10-bit", "12-bit"};
459 char *const input_sel[] = {"Main (color matrix enabled)",
460 "Main (color matrix by-passed)",
461 "", "", "", "", "", "",
462 "Aux (color matrix enabled)",
463 "Aux (color matrix by-passed)",
464 "", "", "", "", "", "Force value"};
467 mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT;
468 r = (val & mask) >> TVO_VIP_REORDER_R_SHIFT;
469 mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT;
470 g = (val & mask) >> TVO_VIP_REORDER_G_SHIFT;
471 mask = TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT;
472 b = (val & mask) >> TVO_VIP_REORDER_B_SHIFT;
473 seq_printf(s, "%-24s %s->%s %s->%s %s->%s\n", "Reorder:",
474 reorder[r], reorder[TVO_VIP_REORDER_CR_R_SEL],
475 reorder[g], reorder[TVO_VIP_REORDER_Y_G_SEL],
476 reorder[b], reorder[TVO_VIP_REORDER_CB_B_SEL]);
477 seq_puts(s, "\t\t\t\t\t");
478 mask = TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT;
479 tmp = (val & mask) >> TVO_VIP_CLIP_SHIFT;
480 seq_printf(s, "%-24s %s\n", "Clipping:", clipping[tmp]);
481 seq_puts(s, "\t\t\t\t\t");
482 mask = TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT;
483 tmp = (val & mask) >> TVO_VIP_RND_SHIFT;
484 seq_printf(s, "%-24s input data rounded to %s per component\n",
485 "Round:", round[tmp]);
486 seq_puts(s, "\t\t\t\t\t");
487 tmp = (val & TVO_VIP_SEL_INPUT_MASK);
488 seq_printf(s, "%-24s %s", "Input selection:", input_sel[tmp]);
491 static void tvout_dbg_hd_dac_cfg(struct seq_file *s, int val)
493 seq_printf(s, "\t%-24s %s", "HD DAC:",
494 val & 1 ? "disabled" : "enabled");
497 static int tvout_dbg_show(struct seq_file *s, void *data)
499 struct drm_info_node *node = s->private;
500 struct sti_tvout *tvout = (struct sti_tvout *)node->info_ent->data;
501 struct drm_crtc *crtc;
503 seq_printf(s, "TVOUT: (vaddr = 0x%p)", tvout->regs);
505 seq_puts(s, "\n\n HDMI encoder: ");
506 crtc = tvout->hdmi->crtc;
508 seq_printf(s, "connected to %s path",
509 sti_crtc_is_main(crtc) ? "main" : "aux");
510 DBGFS_DUMP(TVO_HDMI_SYNC_SEL);
511 DBGFS_DUMP(TVO_VIP_HDMI);
512 tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_HDMI));
514 seq_puts(s, "disabled");
517 seq_puts(s, "\n\n DVO encoder: ");
518 crtc = tvout->dvo->crtc;
520 seq_printf(s, "connected to %s path",
521 sti_crtc_is_main(crtc) ? "main" : "aux");
522 DBGFS_DUMP(TVO_DVO_SYNC_SEL);
523 DBGFS_DUMP(TVO_DVO_CONFIG);
524 DBGFS_DUMP(TVO_VIP_DVO);
525 tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_DVO));
527 seq_puts(s, "disabled");
530 seq_puts(s, "\n\n HDA encoder: ");
531 crtc = tvout->hda->crtc;
533 seq_printf(s, "connected to %s path",
534 sti_crtc_is_main(crtc) ? "main" : "aux");
535 DBGFS_DUMP(TVO_HD_SYNC_SEL);
536 DBGFS_DUMP(TVO_HD_DAC_CFG_OFF);
537 tvout_dbg_hd_dac_cfg(s,
538 readl(tvout->regs + TVO_HD_DAC_CFG_OFF));
539 DBGFS_DUMP(TVO_VIP_HDF);
540 tvout_dbg_vip(s, readl(tvout->regs + TVO_VIP_HDF));
542 seq_puts(s, "disabled");
545 seq_puts(s, "\n\n main path configuration");
546 DBGFS_DUMP(TVO_CSC_MAIN_M0);
547 DBGFS_DUMP(TVO_CSC_MAIN_M1);
548 DBGFS_DUMP(TVO_CSC_MAIN_M2);
549 DBGFS_DUMP(TVO_CSC_MAIN_M3);
550 DBGFS_DUMP(TVO_CSC_MAIN_M4);
551 DBGFS_DUMP(TVO_CSC_MAIN_M5);
552 DBGFS_DUMP(TVO_CSC_MAIN_M6);
553 DBGFS_DUMP(TVO_CSC_MAIN_M7);
554 DBGFS_DUMP(TVO_MAIN_IN_VID_FORMAT);
556 seq_puts(s, "\n\n auxiliary path configuration");
557 DBGFS_DUMP(TVO_CSC_AUX_M0);
558 DBGFS_DUMP(TVO_CSC_AUX_M2);
559 DBGFS_DUMP(TVO_CSC_AUX_M3);
560 DBGFS_DUMP(TVO_CSC_AUX_M4);
561 DBGFS_DUMP(TVO_CSC_AUX_M5);
562 DBGFS_DUMP(TVO_CSC_AUX_M6);
563 DBGFS_DUMP(TVO_CSC_AUX_M7);
564 DBGFS_DUMP(TVO_AUX_IN_VID_FORMAT);
569 static struct drm_info_list tvout_debugfs_files[] = {
570 { "tvout", tvout_dbg_show, 0, NULL },
573 static void tvout_debugfs_init(struct sti_tvout *tvout, struct drm_minor *minor)
577 for (i = 0; i < ARRAY_SIZE(tvout_debugfs_files); i++)
578 tvout_debugfs_files[i].data = tvout;
580 drm_debugfs_create_files(tvout_debugfs_files,
581 ARRAY_SIZE(tvout_debugfs_files),
582 minor->debugfs_root, minor);
585 static void sti_tvout_encoder_dpms(struct drm_encoder *encoder, int mode)
589 static void sti_tvout_encoder_mode_set(struct drm_encoder *encoder,
590 struct drm_display_mode *mode,
591 struct drm_display_mode *adjusted_mode)
595 static void sti_tvout_encoder_destroy(struct drm_encoder *encoder)
597 struct sti_tvout_encoder *sti_encoder = to_sti_tvout_encoder(encoder);
599 drm_encoder_cleanup(encoder);
603 static int sti_tvout_late_register(struct drm_encoder *encoder)
605 struct sti_tvout *tvout = to_sti_tvout(encoder);
607 if (tvout->debugfs_registered)
610 tvout_debugfs_init(tvout, encoder->dev->primary);
612 tvout->debugfs_registered = true;
616 static void sti_tvout_early_unregister(struct drm_encoder *encoder)
618 struct sti_tvout *tvout = to_sti_tvout(encoder);
620 if (!tvout->debugfs_registered)
623 tvout->debugfs_registered = false;
626 static const struct drm_encoder_funcs sti_tvout_encoder_funcs = {
627 .destroy = sti_tvout_encoder_destroy,
628 .late_register = sti_tvout_late_register,
629 .early_unregister = sti_tvout_early_unregister,
632 static void sti_dvo_encoder_enable(struct drm_encoder *encoder)
634 struct sti_tvout *tvout = to_sti_tvout(encoder);
636 tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode);
638 tvout_dvo_start(tvout, sti_crtc_is_main(encoder->crtc));
641 static void sti_dvo_encoder_disable(struct drm_encoder *encoder)
643 struct sti_tvout *tvout = to_sti_tvout(encoder);
645 /* Reset VIP register */
646 tvout_write(tvout, 0x0, TVO_VIP_DVO);
649 static const struct drm_encoder_helper_funcs sti_dvo_encoder_helper_funcs = {
650 .dpms = sti_tvout_encoder_dpms,
651 .mode_set = sti_tvout_encoder_mode_set,
652 .enable = sti_dvo_encoder_enable,
653 .disable = sti_dvo_encoder_disable,
656 static struct drm_encoder *
657 sti_tvout_create_dvo_encoder(struct drm_device *dev,
658 struct sti_tvout *tvout)
660 struct sti_tvout_encoder *encoder;
661 struct drm_encoder *drm_encoder;
663 encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL);
667 encoder->tvout = tvout;
669 drm_encoder = &encoder->encoder;
671 drm_encoder->possible_crtcs = ENCODER_CRTC_MASK;
673 drm_encoder_init(dev, drm_encoder,
674 &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_LVDS,
677 drm_encoder_helper_add(drm_encoder, &sti_dvo_encoder_helper_funcs);
682 static void sti_hda_encoder_enable(struct drm_encoder *encoder)
684 struct sti_tvout *tvout = to_sti_tvout(encoder);
686 tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode);
688 tvout_hda_start(tvout, sti_crtc_is_main(encoder->crtc));
691 static void sti_hda_encoder_disable(struct drm_encoder *encoder)
693 struct sti_tvout *tvout = to_sti_tvout(encoder);
695 /* reset VIP register */
696 tvout_write(tvout, 0x0, TVO_VIP_HDF);
698 /* power down HD DAC */
699 tvout_write(tvout, 1, TVO_HD_DAC_CFG_OFF);
702 static const struct drm_encoder_helper_funcs sti_hda_encoder_helper_funcs = {
703 .dpms = sti_tvout_encoder_dpms,
704 .mode_set = sti_tvout_encoder_mode_set,
705 .commit = sti_hda_encoder_enable,
706 .disable = sti_hda_encoder_disable,
709 static struct drm_encoder *sti_tvout_create_hda_encoder(struct drm_device *dev,
710 struct sti_tvout *tvout)
712 struct sti_tvout_encoder *encoder;
713 struct drm_encoder *drm_encoder;
715 encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL);
719 encoder->tvout = tvout;
721 drm_encoder = &encoder->encoder;
723 drm_encoder->possible_crtcs = ENCODER_CRTC_MASK;
725 drm_encoder_init(dev, drm_encoder,
726 &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_DAC, NULL);
728 drm_encoder_helper_add(drm_encoder, &sti_hda_encoder_helper_funcs);
733 static void sti_hdmi_encoder_enable(struct drm_encoder *encoder)
735 struct sti_tvout *tvout = to_sti_tvout(encoder);
737 tvout_preformatter_set_matrix(tvout, &encoder->crtc->mode);
739 tvout_hdmi_start(tvout, sti_crtc_is_main(encoder->crtc));
742 static void sti_hdmi_encoder_disable(struct drm_encoder *encoder)
744 struct sti_tvout *tvout = to_sti_tvout(encoder);
746 /* reset VIP register */
747 tvout_write(tvout, 0x0, TVO_VIP_HDMI);
750 static const struct drm_encoder_helper_funcs sti_hdmi_encoder_helper_funcs = {
751 .dpms = sti_tvout_encoder_dpms,
752 .mode_set = sti_tvout_encoder_mode_set,
753 .commit = sti_hdmi_encoder_enable,
754 .disable = sti_hdmi_encoder_disable,
757 static struct drm_encoder *sti_tvout_create_hdmi_encoder(struct drm_device *dev,
758 struct sti_tvout *tvout)
760 struct sti_tvout_encoder *encoder;
761 struct drm_encoder *drm_encoder;
763 encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL);
767 encoder->tvout = tvout;
769 drm_encoder = &encoder->encoder;
771 drm_encoder->possible_crtcs = ENCODER_CRTC_MASK;
773 drm_encoder_init(dev, drm_encoder,
774 &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_TMDS, NULL);
776 drm_encoder_helper_add(drm_encoder, &sti_hdmi_encoder_helper_funcs);
781 static void sti_tvout_create_encoders(struct drm_device *dev,
782 struct sti_tvout *tvout)
784 tvout->hdmi = sti_tvout_create_hdmi_encoder(dev, tvout);
785 tvout->hda = sti_tvout_create_hda_encoder(dev, tvout);
786 tvout->dvo = sti_tvout_create_dvo_encoder(dev, tvout);
788 tvout->hdmi->possible_clones = drm_encoder_mask(tvout->hdmi) |
789 drm_encoder_mask(tvout->hda) | drm_encoder_mask(tvout->dvo);
790 tvout->hda->possible_clones = drm_encoder_mask(tvout->hdmi) |
791 drm_encoder_mask(tvout->hda) | drm_encoder_mask(tvout->dvo);
792 tvout->dvo->possible_clones = drm_encoder_mask(tvout->hdmi) |
793 drm_encoder_mask(tvout->hda) | drm_encoder_mask(tvout->dvo);
796 static void sti_tvout_destroy_encoders(struct sti_tvout *tvout)
799 drm_encoder_cleanup(tvout->hdmi);
803 drm_encoder_cleanup(tvout->hda);
807 drm_encoder_cleanup(tvout->dvo);
811 static int sti_tvout_bind(struct device *dev, struct device *master, void *data)
813 struct sti_tvout *tvout = dev_get_drvdata(dev);
814 struct drm_device *drm_dev = data;
816 tvout->drm_dev = drm_dev;
818 sti_tvout_create_encoders(drm_dev, tvout);
823 static void sti_tvout_unbind(struct device *dev, struct device *master,
826 struct sti_tvout *tvout = dev_get_drvdata(dev);
828 sti_tvout_destroy_encoders(tvout);
831 static const struct component_ops sti_tvout_ops = {
832 .bind = sti_tvout_bind,
833 .unbind = sti_tvout_unbind,
836 static int sti_tvout_probe(struct platform_device *pdev)
838 struct device *dev = &pdev->dev;
839 struct device_node *node = dev->of_node;
840 struct sti_tvout *tvout;
841 struct resource *res;
843 DRM_INFO("%s\n", __func__);
848 tvout = devm_kzalloc(dev, sizeof(*tvout), GFP_KERNEL);
854 /* get memory resources */
855 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tvout-reg");
857 DRM_ERROR("Invalid glue resource\n");
860 tvout->regs = devm_ioremap(dev, res->start, resource_size(res));
864 /* get reset resources */
865 tvout->reset = devm_reset_control_get(dev, "tvout");
866 /* take tvout out of reset */
867 if (!IS_ERR(tvout->reset))
868 reset_control_deassert(tvout->reset);
870 platform_set_drvdata(pdev, tvout);
872 return component_add(dev, &sti_tvout_ops);
875 static void sti_tvout_remove(struct platform_device *pdev)
877 component_del(&pdev->dev, &sti_tvout_ops);
880 static const struct of_device_id tvout_of_match[] = {
881 { .compatible = "st,stih407-tvout", },
884 MODULE_DEVICE_TABLE(of, tvout_of_match);
886 struct platform_driver sti_tvout_driver = {
889 .owner = THIS_MODULE,
890 .of_match_table = tvout_of_match,
892 .probe = sti_tvout_probe,
893 .remove_new = sti_tvout_remove,
896 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
897 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
898 MODULE_LICENSE("GPL");