2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/clk.h>
11 #include <linux/clk/tegra.h>
12 #include <linux/debugfs.h>
19 struct drm_plane base
;
23 static inline struct tegra_plane
*to_tegra_plane(struct drm_plane
*plane
)
25 return container_of(plane
, struct tegra_plane
, base
);
28 static int tegra_plane_update(struct drm_plane
*plane
, struct drm_crtc
*crtc
,
29 struct drm_framebuffer
*fb
, int crtc_x
,
30 int crtc_y
, unsigned int crtc_w
,
31 unsigned int crtc_h
, uint32_t src_x
,
32 uint32_t src_y
, uint32_t src_w
, uint32_t src_h
)
34 struct tegra_plane
*p
= to_tegra_plane(plane
);
35 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
36 struct tegra_dc_window window
;
39 memset(&window
, 0, sizeof(window
));
40 window
.src
.x
= src_x
>> 16;
41 window
.src
.y
= src_y
>> 16;
42 window
.src
.w
= src_w
>> 16;
43 window
.src
.h
= src_h
>> 16;
44 window
.dst
.x
= crtc_x
;
45 window
.dst
.y
= crtc_y
;
46 window
.dst
.w
= crtc_w
;
47 window
.dst
.h
= crtc_h
;
48 window
.format
= tegra_dc_format(fb
->pixel_format
);
49 window
.bits_per_pixel
= fb
->bits_per_pixel
;
50 window
.tiled
= tegra_fb_is_tiled(fb
);
52 for (i
= 0; i
< drm_format_num_planes(fb
->pixel_format
); i
++) {
53 struct tegra_bo
*bo
= tegra_fb_get_plane(fb
, i
);
55 window
.base
[i
] = bo
->paddr
+ fb
->offsets
[i
];
58 * Tegra doesn't support different strides for U and V planes
59 * so we display a warning if the user tries to display a
60 * framebuffer with such a configuration.
63 if (fb
->pitches
[i
] != window
.stride
[1])
64 DRM_ERROR("unsupported UV-plane configuration\n");
66 window
.stride
[i
] = fb
->pitches
[i
];
70 return tegra_dc_setup_window(dc
, p
->index
, &window
);
73 static int tegra_plane_disable(struct drm_plane
*plane
)
75 struct tegra_dc
*dc
= to_tegra_dc(plane
->crtc
);
76 struct tegra_plane
*p
= to_tegra_plane(plane
);
82 value
= WINDOW_A_SELECT
<< p
->index
;
83 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_WINDOW_HEADER
);
85 value
= tegra_dc_readl(dc
, DC_WIN_WIN_OPTIONS
);
87 tegra_dc_writel(dc
, value
, DC_WIN_WIN_OPTIONS
);
89 tegra_dc_writel(dc
, WIN_A_UPDATE
<< p
->index
, DC_CMD_STATE_CONTROL
);
90 tegra_dc_writel(dc
, WIN_A_ACT_REQ
<< p
->index
, DC_CMD_STATE_CONTROL
);
95 static void tegra_plane_destroy(struct drm_plane
*plane
)
97 struct tegra_plane
*p
= to_tegra_plane(plane
);
99 tegra_plane_disable(plane
);
100 drm_plane_cleanup(plane
);
104 static const struct drm_plane_funcs tegra_plane_funcs
= {
105 .update_plane
= tegra_plane_update
,
106 .disable_plane
= tegra_plane_disable
,
107 .destroy
= tegra_plane_destroy
,
110 static const uint32_t plane_formats
[] = {
119 static int tegra_dc_add_planes(struct drm_device
*drm
, struct tegra_dc
*dc
)
124 for (i
= 0; i
< 2; i
++) {
125 struct tegra_plane
*plane
;
127 plane
= kzalloc(sizeof(*plane
), GFP_KERNEL
);
131 plane
->index
= 1 + i
;
133 err
= drm_plane_init(drm
, &plane
->base
, 1 << dc
->pipe
,
134 &tegra_plane_funcs
, plane_formats
,
135 ARRAY_SIZE(plane_formats
), false);
145 static int tegra_dc_set_base(struct tegra_dc
*dc
, int x
, int y
,
146 struct drm_framebuffer
*fb
)
148 unsigned int format
= tegra_dc_format(fb
->pixel_format
);
149 struct tegra_bo
*bo
= tegra_fb_get_plane(fb
, 0);
152 tegra_dc_writel(dc
, WINDOW_A_SELECT
, DC_CMD_DISPLAY_WINDOW_HEADER
);
154 value
= fb
->offsets
[0] + y
* fb
->pitches
[0] +
155 x
* fb
->bits_per_pixel
/ 8;
157 tegra_dc_writel(dc
, bo
->paddr
+ value
, DC_WINBUF_START_ADDR
);
158 tegra_dc_writel(dc
, fb
->pitches
[0], DC_WIN_LINE_STRIDE
);
159 tegra_dc_writel(dc
, format
, DC_WIN_COLOR_DEPTH
);
161 if (tegra_fb_is_tiled(fb
)) {
162 value
= DC_WIN_BUFFER_ADDR_MODE_TILE_UV
|
163 DC_WIN_BUFFER_ADDR_MODE_TILE
;
165 value
= DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV
|
166 DC_WIN_BUFFER_ADDR_MODE_LINEAR
;
169 tegra_dc_writel(dc
, value
, DC_WIN_BUFFER_ADDR_MODE
);
171 value
= GENERAL_UPDATE
| WIN_A_UPDATE
;
172 tegra_dc_writel(dc
, value
, DC_CMD_STATE_CONTROL
);
174 value
= GENERAL_ACT_REQ
| WIN_A_ACT_REQ
;
175 tegra_dc_writel(dc
, value
, DC_CMD_STATE_CONTROL
);
180 void tegra_dc_enable_vblank(struct tegra_dc
*dc
)
182 unsigned long value
, flags
;
184 spin_lock_irqsave(&dc
->lock
, flags
);
186 value
= tegra_dc_readl(dc
, DC_CMD_INT_MASK
);
188 tegra_dc_writel(dc
, value
, DC_CMD_INT_MASK
);
190 spin_unlock_irqrestore(&dc
->lock
, flags
);
193 void tegra_dc_disable_vblank(struct tegra_dc
*dc
)
195 unsigned long value
, flags
;
197 spin_lock_irqsave(&dc
->lock
, flags
);
199 value
= tegra_dc_readl(dc
, DC_CMD_INT_MASK
);
200 value
&= ~VBLANK_INT
;
201 tegra_dc_writel(dc
, value
, DC_CMD_INT_MASK
);
203 spin_unlock_irqrestore(&dc
->lock
, flags
);
206 static void tegra_dc_finish_page_flip(struct tegra_dc
*dc
)
208 struct drm_device
*drm
= dc
->base
.dev
;
209 struct drm_crtc
*crtc
= &dc
->base
;
210 unsigned long flags
, base
;
216 bo
= tegra_fb_get_plane(crtc
->fb
, 0);
218 /* check if new start address has been latched */
219 tegra_dc_writel(dc
, READ_MUX
, DC_CMD_STATE_ACCESS
);
220 base
= tegra_dc_readl(dc
, DC_WINBUF_START_ADDR
);
221 tegra_dc_writel(dc
, 0, DC_CMD_STATE_ACCESS
);
223 if (base
== bo
->paddr
+ crtc
->fb
->offsets
[0]) {
224 spin_lock_irqsave(&drm
->event_lock
, flags
);
225 drm_send_vblank_event(drm
, dc
->pipe
, dc
->event
);
226 drm_vblank_put(drm
, dc
->pipe
);
228 spin_unlock_irqrestore(&drm
->event_lock
, flags
);
232 void tegra_dc_cancel_page_flip(struct drm_crtc
*crtc
, struct drm_file
*file
)
234 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
235 struct drm_device
*drm
= crtc
->dev
;
238 spin_lock_irqsave(&drm
->event_lock
, flags
);
240 if (dc
->event
&& dc
->event
->base
.file_priv
== file
) {
241 dc
->event
->base
.destroy(&dc
->event
->base
);
242 drm_vblank_put(drm
, dc
->pipe
);
246 spin_unlock_irqrestore(&drm
->event_lock
, flags
);
249 static int tegra_dc_page_flip(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
250 struct drm_pending_vblank_event
*event
, uint32_t page_flip_flags
)
252 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
253 struct drm_device
*drm
= crtc
->dev
;
259 event
->pipe
= dc
->pipe
;
261 drm_vblank_get(drm
, dc
->pipe
);
264 tegra_dc_set_base(dc
, 0, 0, fb
);
270 static void drm_crtc_clear(struct drm_crtc
*crtc
)
272 memset(crtc
, 0, sizeof(*crtc
));
275 static void tegra_dc_destroy(struct drm_crtc
*crtc
)
277 drm_crtc_cleanup(crtc
);
278 drm_crtc_clear(crtc
);
281 static const struct drm_crtc_funcs tegra_crtc_funcs
= {
282 .page_flip
= tegra_dc_page_flip
,
283 .set_config
= drm_crtc_helper_set_config
,
284 .destroy
= tegra_dc_destroy
,
287 static void tegra_crtc_disable(struct drm_crtc
*crtc
)
289 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
290 struct drm_device
*drm
= crtc
->dev
;
291 struct drm_plane
*plane
;
293 list_for_each_entry(plane
, &drm
->mode_config
.plane_list
, head
) {
294 if (plane
->crtc
== crtc
) {
295 tegra_plane_disable(plane
);
299 drm_framebuffer_unreference(plane
->fb
);
305 drm_vblank_off(drm
, dc
->pipe
);
308 static bool tegra_crtc_mode_fixup(struct drm_crtc
*crtc
,
309 const struct drm_display_mode
*mode
,
310 struct drm_display_mode
*adjusted
)
315 static inline u32
compute_dda_inc(unsigned int in
, unsigned int out
, bool v
,
318 fixed20_12 outf
= dfixed_init(out
);
319 fixed20_12 inf
= dfixed_init(in
);
340 outf
.full
= max_t(u32
, outf
.full
- dfixed_const(1), dfixed_const(1));
341 inf
.full
-= dfixed_const(1);
343 dda_inc
= dfixed_div(inf
, outf
);
344 dda_inc
= min_t(u32
, dda_inc
, dfixed_const(max
));
349 static inline u32
compute_initial_dda(unsigned int in
)
351 fixed20_12 inf
= dfixed_init(in
);
352 return dfixed_frac(inf
);
355 static int tegra_dc_set_timings(struct tegra_dc
*dc
,
356 struct drm_display_mode
*mode
)
358 /* TODO: For HDMI compliance, h & v ref_to_sync should be set to 1 */
359 unsigned int h_ref_to_sync
= 0;
360 unsigned int v_ref_to_sync
= 0;
363 tegra_dc_writel(dc
, 0x0, DC_DISP_DISP_TIMING_OPTIONS
);
365 value
= (v_ref_to_sync
<< 16) | h_ref_to_sync
;
366 tegra_dc_writel(dc
, value
, DC_DISP_REF_TO_SYNC
);
368 value
= ((mode
->vsync_end
- mode
->vsync_start
) << 16) |
369 ((mode
->hsync_end
- mode
->hsync_start
) << 0);
370 tegra_dc_writel(dc
, value
, DC_DISP_SYNC_WIDTH
);
372 value
= ((mode
->vtotal
- mode
->vsync_end
) << 16) |
373 ((mode
->htotal
- mode
->hsync_end
) << 0);
374 tegra_dc_writel(dc
, value
, DC_DISP_BACK_PORCH
);
376 value
= ((mode
->vsync_start
- mode
->vdisplay
) << 16) |
377 ((mode
->hsync_start
- mode
->hdisplay
) << 0);
378 tegra_dc_writel(dc
, value
, DC_DISP_FRONT_PORCH
);
380 value
= (mode
->vdisplay
<< 16) | mode
->hdisplay
;
381 tegra_dc_writel(dc
, value
, DC_DISP_ACTIVE
);
386 static int tegra_crtc_setup_clk(struct drm_crtc
*crtc
,
387 struct drm_display_mode
*mode
,
390 unsigned long pclk
= mode
->clock
* 1000, rate
;
391 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
392 struct tegra_output
*output
= NULL
;
393 struct drm_encoder
*encoder
;
396 list_for_each_entry(encoder
, &crtc
->dev
->mode_config
.encoder_list
, head
)
397 if (encoder
->crtc
== crtc
) {
398 output
= encoder_to_output(encoder
);
406 * This assumes that the display controller will divide its parent
407 * clock by 2 to generate the pixel clock.
409 err
= tegra_output_setup_clock(output
, dc
->clk
, pclk
* 2);
411 dev_err(dc
->dev
, "failed to setup clock: %ld\n", err
);
415 rate
= clk_get_rate(dc
->clk
);
416 *div
= (rate
* 2 / pclk
) - 2;
418 DRM_DEBUG_KMS("rate: %lu, div: %lu\n", rate
, *div
);
423 static bool tegra_dc_format_is_yuv(unsigned int format
, bool *planar
)
426 case WIN_COLOR_DEPTH_YCbCr422
:
427 case WIN_COLOR_DEPTH_YUV422
:
433 case WIN_COLOR_DEPTH_YCbCr420P
:
434 case WIN_COLOR_DEPTH_YUV420P
:
435 case WIN_COLOR_DEPTH_YCbCr422P
:
436 case WIN_COLOR_DEPTH_YUV422P
:
437 case WIN_COLOR_DEPTH_YCbCr422R
:
438 case WIN_COLOR_DEPTH_YUV422R
:
439 case WIN_COLOR_DEPTH_YCbCr422RA
:
440 case WIN_COLOR_DEPTH_YUV422RA
:
450 int tegra_dc_setup_window(struct tegra_dc
*dc
, unsigned int index
,
451 const struct tegra_dc_window
*window
)
453 unsigned h_offset
, v_offset
, h_size
, v_size
, h_dda
, v_dda
, bpp
;
458 * For YUV planar modes, the number of bytes per pixel takes into
459 * account only the luma component and therefore is 1.
461 yuv
= tegra_dc_format_is_yuv(window
->format
, &planar
);
463 bpp
= window
->bits_per_pixel
/ 8;
465 bpp
= planar
? 1 : 2;
467 value
= WINDOW_A_SELECT
<< index
;
468 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_WINDOW_HEADER
);
470 tegra_dc_writel(dc
, window
->format
, DC_WIN_COLOR_DEPTH
);
471 tegra_dc_writel(dc
, 0, DC_WIN_BYTE_SWAP
);
473 value
= V_POSITION(window
->dst
.y
) | H_POSITION(window
->dst
.x
);
474 tegra_dc_writel(dc
, value
, DC_WIN_POSITION
);
476 value
= V_SIZE(window
->dst
.h
) | H_SIZE(window
->dst
.w
);
477 tegra_dc_writel(dc
, value
, DC_WIN_SIZE
);
479 h_offset
= window
->src
.x
* bpp
;
480 v_offset
= window
->src
.y
;
481 h_size
= window
->src
.w
* bpp
;
482 v_size
= window
->src
.h
;
484 value
= V_PRESCALED_SIZE(v_size
) | H_PRESCALED_SIZE(h_size
);
485 tegra_dc_writel(dc
, value
, DC_WIN_PRESCALED_SIZE
);
488 * For DDA computations the number of bytes per pixel for YUV planar
489 * modes needs to take into account all Y, U and V components.
494 h_dda
= compute_dda_inc(window
->src
.w
, window
->dst
.w
, false, bpp
);
495 v_dda
= compute_dda_inc(window
->src
.h
, window
->dst
.h
, true, bpp
);
497 value
= V_DDA_INC(v_dda
) | H_DDA_INC(h_dda
);
498 tegra_dc_writel(dc
, value
, DC_WIN_DDA_INC
);
500 h_dda
= compute_initial_dda(window
->src
.x
);
501 v_dda
= compute_initial_dda(window
->src
.y
);
503 tegra_dc_writel(dc
, h_dda
, DC_WIN_H_INITIAL_DDA
);
504 tegra_dc_writel(dc
, v_dda
, DC_WIN_V_INITIAL_DDA
);
506 tegra_dc_writel(dc
, 0, DC_WIN_UV_BUF_STRIDE
);
507 tegra_dc_writel(dc
, 0, DC_WIN_BUF_STRIDE
);
509 tegra_dc_writel(dc
, window
->base
[0], DC_WINBUF_START_ADDR
);
512 tegra_dc_writel(dc
, window
->base
[1], DC_WINBUF_START_ADDR_U
);
513 tegra_dc_writel(dc
, window
->base
[2], DC_WINBUF_START_ADDR_V
);
514 value
= window
->stride
[1] << 16 | window
->stride
[0];
515 tegra_dc_writel(dc
, value
, DC_WIN_LINE_STRIDE
);
517 tegra_dc_writel(dc
, window
->stride
[0], DC_WIN_LINE_STRIDE
);
520 tegra_dc_writel(dc
, h_offset
, DC_WINBUF_ADDR_H_OFFSET
);
521 tegra_dc_writel(dc
, v_offset
, DC_WINBUF_ADDR_V_OFFSET
);
524 value
= DC_WIN_BUFFER_ADDR_MODE_TILE_UV
|
525 DC_WIN_BUFFER_ADDR_MODE_TILE
;
527 value
= DC_WIN_BUFFER_ADDR_MODE_LINEAR_UV
|
528 DC_WIN_BUFFER_ADDR_MODE_LINEAR
;
531 tegra_dc_writel(dc
, value
, DC_WIN_BUFFER_ADDR_MODE
);
536 /* setup default colorspace conversion coefficients */
537 tegra_dc_writel(dc
, 0x00f0, DC_WIN_CSC_YOF
);
538 tegra_dc_writel(dc
, 0x012a, DC_WIN_CSC_KYRGB
);
539 tegra_dc_writel(dc
, 0x0000, DC_WIN_CSC_KUR
);
540 tegra_dc_writel(dc
, 0x0198, DC_WIN_CSC_KVR
);
541 tegra_dc_writel(dc
, 0x039b, DC_WIN_CSC_KUG
);
542 tegra_dc_writel(dc
, 0x032f, DC_WIN_CSC_KVG
);
543 tegra_dc_writel(dc
, 0x0204, DC_WIN_CSC_KUB
);
544 tegra_dc_writel(dc
, 0x0000, DC_WIN_CSC_KVB
);
547 } else if (window
->bits_per_pixel
< 24) {
548 value
|= COLOR_EXPAND
;
551 tegra_dc_writel(dc
, value
, DC_WIN_WIN_OPTIONS
);
554 * Disable blending and assume Window A is the bottom-most window,
555 * Window C is the top-most window and Window B is in the middle.
557 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_NOKEY
);
558 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_1WIN
);
562 tegra_dc_writel(dc
, 0x000000, DC_WIN_BLEND_2WIN_X
);
563 tegra_dc_writel(dc
, 0x000000, DC_WIN_BLEND_2WIN_Y
);
564 tegra_dc_writel(dc
, 0x000000, DC_WIN_BLEND_3WIN_XY
);
568 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_2WIN_X
);
569 tegra_dc_writel(dc
, 0x000000, DC_WIN_BLEND_2WIN_Y
);
570 tegra_dc_writel(dc
, 0x000000, DC_WIN_BLEND_3WIN_XY
);
574 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_2WIN_X
);
575 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_2WIN_Y
);
576 tegra_dc_writel(dc
, 0xffff00, DC_WIN_BLEND_3WIN_XY
);
580 tegra_dc_writel(dc
, WIN_A_UPDATE
<< index
, DC_CMD_STATE_CONTROL
);
581 tegra_dc_writel(dc
, WIN_A_ACT_REQ
<< index
, DC_CMD_STATE_CONTROL
);
586 unsigned int tegra_dc_format(uint32_t format
)
589 case DRM_FORMAT_XBGR8888
:
590 return WIN_COLOR_DEPTH_R8G8B8A8
;
592 case DRM_FORMAT_XRGB8888
:
593 return WIN_COLOR_DEPTH_B8G8R8A8
;
595 case DRM_FORMAT_RGB565
:
596 return WIN_COLOR_DEPTH_B5G6R5
;
598 case DRM_FORMAT_UYVY
:
599 return WIN_COLOR_DEPTH_YCbCr422
;
601 case DRM_FORMAT_YUV420
:
602 return WIN_COLOR_DEPTH_YCbCr420P
;
604 case DRM_FORMAT_YUV422
:
605 return WIN_COLOR_DEPTH_YCbCr422P
;
611 WARN(1, "unsupported pixel format %u, using default\n", format
);
612 return WIN_COLOR_DEPTH_B8G8R8A8
;
615 static int tegra_crtc_mode_set(struct drm_crtc
*crtc
,
616 struct drm_display_mode
*mode
,
617 struct drm_display_mode
*adjusted
,
618 int x
, int y
, struct drm_framebuffer
*old_fb
)
620 struct tegra_bo
*bo
= tegra_fb_get_plane(crtc
->fb
, 0);
621 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
622 struct tegra_dc_window window
;
623 unsigned long div
, value
;
626 drm_vblank_pre_modeset(crtc
->dev
, dc
->pipe
);
628 err
= tegra_crtc_setup_clk(crtc
, mode
, &div
);
630 dev_err(dc
->dev
, "failed to setup clock for CRTC: %d\n", err
);
634 /* program display mode */
635 tegra_dc_set_timings(dc
, mode
);
637 value
= DE_SELECT_ACTIVE
| DE_CONTROL_NORMAL
;
638 tegra_dc_writel(dc
, value
, DC_DISP_DATA_ENABLE_OPTIONS
);
640 value
= tegra_dc_readl(dc
, DC_COM_PIN_OUTPUT_POLARITY(1));
641 value
&= ~LVS_OUTPUT_POLARITY_LOW
;
642 value
&= ~LHS_OUTPUT_POLARITY_LOW
;
643 tegra_dc_writel(dc
, value
, DC_COM_PIN_OUTPUT_POLARITY(1));
645 value
= DISP_DATA_FORMAT_DF1P1C
| DISP_ALIGNMENT_MSB
|
647 tegra_dc_writel(dc
, value
, DC_DISP_DISP_INTERFACE_CONTROL
);
649 tegra_dc_writel(dc
, 0x00010001, DC_DISP_SHIFT_CLOCK_OPTIONS
);
651 value
= SHIFT_CLK_DIVIDER(div
) | PIXEL_CLK_DIVIDER_PCD1
;
652 tegra_dc_writel(dc
, value
, DC_DISP_DISP_CLOCK_CONTROL
);
654 /* setup window parameters */
655 memset(&window
, 0, sizeof(window
));
658 window
.src
.w
= mode
->hdisplay
;
659 window
.src
.h
= mode
->vdisplay
;
662 window
.dst
.w
= mode
->hdisplay
;
663 window
.dst
.h
= mode
->vdisplay
;
664 window
.format
= tegra_dc_format(crtc
->fb
->pixel_format
);
665 window
.bits_per_pixel
= crtc
->fb
->bits_per_pixel
;
666 window
.stride
[0] = crtc
->fb
->pitches
[0];
667 window
.base
[0] = bo
->paddr
;
669 err
= tegra_dc_setup_window(dc
, 0, &window
);
671 dev_err(dc
->dev
, "failed to enable root plane\n");
676 static int tegra_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
677 struct drm_framebuffer
*old_fb
)
679 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
681 return tegra_dc_set_base(dc
, x
, y
, crtc
->fb
);
684 static void tegra_crtc_prepare(struct drm_crtc
*crtc
)
686 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
690 /* hardware initialization */
691 tegra_periph_reset_deassert(dc
->clk
);
692 usleep_range(10000, 20000);
695 syncpt
= SYNCPT_VBLANK1
;
697 syncpt
= SYNCPT_VBLANK0
;
699 /* initialize display controller */
700 tegra_dc_writel(dc
, 0x00000100, DC_CMD_GENERAL_INCR_SYNCPT_CNTRL
);
701 tegra_dc_writel(dc
, 0x100 | syncpt
, DC_CMD_CONT_SYNCPT_VSYNC
);
703 value
= WIN_A_UF_INT
| WIN_B_UF_INT
| WIN_C_UF_INT
| WIN_A_OF_INT
;
704 tegra_dc_writel(dc
, value
, DC_CMD_INT_TYPE
);
706 value
= WIN_A_UF_INT
| WIN_B_UF_INT
| WIN_C_UF_INT
|
707 WIN_A_OF_INT
| WIN_B_OF_INT
| WIN_C_OF_INT
;
708 tegra_dc_writel(dc
, value
, DC_CMD_INT_POLARITY
);
710 value
= PW0_ENABLE
| PW1_ENABLE
| PW2_ENABLE
| PW3_ENABLE
|
711 PW4_ENABLE
| PM0_ENABLE
| PM1_ENABLE
;
712 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_POWER_CONTROL
);
714 value
= tegra_dc_readl(dc
, DC_CMD_DISPLAY_COMMAND
);
715 value
|= DISP_CTRL_MODE_C_DISPLAY
;
716 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_COMMAND
);
718 /* initialize timer */
719 value
= CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(0x20) |
720 WINDOW_B_THRESHOLD(0x20) | WINDOW_C_THRESHOLD(0x20);
721 tegra_dc_writel(dc
, value
, DC_DISP_DISP_MEM_HIGH_PRIORITY
);
723 value
= CURSOR_THRESHOLD(0) | WINDOW_A_THRESHOLD(1) |
724 WINDOW_B_THRESHOLD(1) | WINDOW_C_THRESHOLD(1);
725 tegra_dc_writel(dc
, value
, DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER
);
727 value
= VBLANK_INT
| WIN_A_UF_INT
| WIN_B_UF_INT
| WIN_C_UF_INT
;
728 tegra_dc_writel(dc
, value
, DC_CMD_INT_ENABLE
);
730 value
= WIN_A_UF_INT
| WIN_B_UF_INT
| WIN_C_UF_INT
;
731 tegra_dc_writel(dc
, value
, DC_CMD_INT_MASK
);
734 static void tegra_crtc_commit(struct drm_crtc
*crtc
)
736 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
739 value
= GENERAL_UPDATE
| WIN_A_UPDATE
;
740 tegra_dc_writel(dc
, value
, DC_CMD_STATE_CONTROL
);
742 value
= GENERAL_ACT_REQ
| WIN_A_ACT_REQ
;
743 tegra_dc_writel(dc
, value
, DC_CMD_STATE_CONTROL
);
745 drm_vblank_post_modeset(crtc
->dev
, dc
->pipe
);
748 static void tegra_crtc_load_lut(struct drm_crtc
*crtc
)
752 static const struct drm_crtc_helper_funcs tegra_crtc_helper_funcs
= {
753 .disable
= tegra_crtc_disable
,
754 .mode_fixup
= tegra_crtc_mode_fixup
,
755 .mode_set
= tegra_crtc_mode_set
,
756 .mode_set_base
= tegra_crtc_mode_set_base
,
757 .prepare
= tegra_crtc_prepare
,
758 .commit
= tegra_crtc_commit
,
759 .load_lut
= tegra_crtc_load_lut
,
762 static irqreturn_t
tegra_dc_irq(int irq
, void *data
)
764 struct tegra_dc
*dc
= data
;
765 unsigned long status
;
767 status
= tegra_dc_readl(dc
, DC_CMD_INT_STATUS
);
768 tegra_dc_writel(dc
, status
, DC_CMD_INT_STATUS
);
770 if (status
& FRAME_END_INT
) {
772 dev_dbg(dc->dev, "%s(): frame end\n", __func__);
776 if (status
& VBLANK_INT
) {
778 dev_dbg(dc->dev, "%s(): vertical blank\n", __func__);
780 drm_handle_vblank(dc
->base
.dev
, dc
->pipe
);
781 tegra_dc_finish_page_flip(dc
);
784 if (status
& (WIN_A_UF_INT
| WIN_B_UF_INT
| WIN_C_UF_INT
)) {
786 dev_dbg(dc->dev, "%s(): underflow\n", __func__);
793 static int tegra_dc_show_regs(struct seq_file
*s
, void *data
)
795 struct drm_info_node
*node
= s
->private;
796 struct tegra_dc
*dc
= node
->info_ent
->data
;
798 #define DUMP_REG(name) \
799 seq_printf(s, "%-40s %#05x %08lx\n", #name, name, \
800 tegra_dc_readl(dc, name))
802 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT
);
803 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_CNTRL
);
804 DUMP_REG(DC_CMD_GENERAL_INCR_SYNCPT_ERROR
);
805 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT
);
806 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_CNTRL
);
807 DUMP_REG(DC_CMD_WIN_A_INCR_SYNCPT_ERROR
);
808 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT
);
809 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_CNTRL
);
810 DUMP_REG(DC_CMD_WIN_B_INCR_SYNCPT_ERROR
);
811 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT
);
812 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_CNTRL
);
813 DUMP_REG(DC_CMD_WIN_C_INCR_SYNCPT_ERROR
);
814 DUMP_REG(DC_CMD_CONT_SYNCPT_VSYNC
);
815 DUMP_REG(DC_CMD_DISPLAY_COMMAND_OPTION0
);
816 DUMP_REG(DC_CMD_DISPLAY_COMMAND
);
817 DUMP_REG(DC_CMD_SIGNAL_RAISE
);
818 DUMP_REG(DC_CMD_DISPLAY_POWER_CONTROL
);
819 DUMP_REG(DC_CMD_INT_STATUS
);
820 DUMP_REG(DC_CMD_INT_MASK
);
821 DUMP_REG(DC_CMD_INT_ENABLE
);
822 DUMP_REG(DC_CMD_INT_TYPE
);
823 DUMP_REG(DC_CMD_INT_POLARITY
);
824 DUMP_REG(DC_CMD_SIGNAL_RAISE1
);
825 DUMP_REG(DC_CMD_SIGNAL_RAISE2
);
826 DUMP_REG(DC_CMD_SIGNAL_RAISE3
);
827 DUMP_REG(DC_CMD_STATE_ACCESS
);
828 DUMP_REG(DC_CMD_STATE_CONTROL
);
829 DUMP_REG(DC_CMD_DISPLAY_WINDOW_HEADER
);
830 DUMP_REG(DC_CMD_REG_ACT_CONTROL
);
831 DUMP_REG(DC_COM_CRC_CONTROL
);
832 DUMP_REG(DC_COM_CRC_CHECKSUM
);
833 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(0));
834 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(1));
835 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(2));
836 DUMP_REG(DC_COM_PIN_OUTPUT_ENABLE(3));
837 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(0));
838 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(1));
839 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(2));
840 DUMP_REG(DC_COM_PIN_OUTPUT_POLARITY(3));
841 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(0));
842 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(1));
843 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(2));
844 DUMP_REG(DC_COM_PIN_OUTPUT_DATA(3));
845 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(0));
846 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(1));
847 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(2));
848 DUMP_REG(DC_COM_PIN_INPUT_ENABLE(3));
849 DUMP_REG(DC_COM_PIN_INPUT_DATA(0));
850 DUMP_REG(DC_COM_PIN_INPUT_DATA(1));
851 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(0));
852 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(1));
853 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(2));
854 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(3));
855 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(4));
856 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(5));
857 DUMP_REG(DC_COM_PIN_OUTPUT_SELECT(6));
858 DUMP_REG(DC_COM_PIN_MISC_CONTROL
);
859 DUMP_REG(DC_COM_PIN_PM0_CONTROL
);
860 DUMP_REG(DC_COM_PIN_PM0_DUTY_CYCLE
);
861 DUMP_REG(DC_COM_PIN_PM1_CONTROL
);
862 DUMP_REG(DC_COM_PIN_PM1_DUTY_CYCLE
);
863 DUMP_REG(DC_COM_SPI_CONTROL
);
864 DUMP_REG(DC_COM_SPI_START_BYTE
);
865 DUMP_REG(DC_COM_HSPI_WRITE_DATA_AB
);
866 DUMP_REG(DC_COM_HSPI_WRITE_DATA_CD
);
867 DUMP_REG(DC_COM_HSPI_CS_DC
);
868 DUMP_REG(DC_COM_SCRATCH_REGISTER_A
);
869 DUMP_REG(DC_COM_SCRATCH_REGISTER_B
);
870 DUMP_REG(DC_COM_GPIO_CTRL
);
871 DUMP_REG(DC_COM_GPIO_DEBOUNCE_COUNTER
);
872 DUMP_REG(DC_COM_CRC_CHECKSUM_LATCHED
);
873 DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS0
);
874 DUMP_REG(DC_DISP_DISP_SIGNAL_OPTIONS1
);
875 DUMP_REG(DC_DISP_DISP_WIN_OPTIONS
);
876 DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY
);
877 DUMP_REG(DC_DISP_DISP_MEM_HIGH_PRIORITY_TIMER
);
878 DUMP_REG(DC_DISP_DISP_TIMING_OPTIONS
);
879 DUMP_REG(DC_DISP_REF_TO_SYNC
);
880 DUMP_REG(DC_DISP_SYNC_WIDTH
);
881 DUMP_REG(DC_DISP_BACK_PORCH
);
882 DUMP_REG(DC_DISP_ACTIVE
);
883 DUMP_REG(DC_DISP_FRONT_PORCH
);
884 DUMP_REG(DC_DISP_H_PULSE0_CONTROL
);
885 DUMP_REG(DC_DISP_H_PULSE0_POSITION_A
);
886 DUMP_REG(DC_DISP_H_PULSE0_POSITION_B
);
887 DUMP_REG(DC_DISP_H_PULSE0_POSITION_C
);
888 DUMP_REG(DC_DISP_H_PULSE0_POSITION_D
);
889 DUMP_REG(DC_DISP_H_PULSE1_CONTROL
);
890 DUMP_REG(DC_DISP_H_PULSE1_POSITION_A
);
891 DUMP_REG(DC_DISP_H_PULSE1_POSITION_B
);
892 DUMP_REG(DC_DISP_H_PULSE1_POSITION_C
);
893 DUMP_REG(DC_DISP_H_PULSE1_POSITION_D
);
894 DUMP_REG(DC_DISP_H_PULSE2_CONTROL
);
895 DUMP_REG(DC_DISP_H_PULSE2_POSITION_A
);
896 DUMP_REG(DC_DISP_H_PULSE2_POSITION_B
);
897 DUMP_REG(DC_DISP_H_PULSE2_POSITION_C
);
898 DUMP_REG(DC_DISP_H_PULSE2_POSITION_D
);
899 DUMP_REG(DC_DISP_V_PULSE0_CONTROL
);
900 DUMP_REG(DC_DISP_V_PULSE0_POSITION_A
);
901 DUMP_REG(DC_DISP_V_PULSE0_POSITION_B
);
902 DUMP_REG(DC_DISP_V_PULSE0_POSITION_C
);
903 DUMP_REG(DC_DISP_V_PULSE1_CONTROL
);
904 DUMP_REG(DC_DISP_V_PULSE1_POSITION_A
);
905 DUMP_REG(DC_DISP_V_PULSE1_POSITION_B
);
906 DUMP_REG(DC_DISP_V_PULSE1_POSITION_C
);
907 DUMP_REG(DC_DISP_V_PULSE2_CONTROL
);
908 DUMP_REG(DC_DISP_V_PULSE2_POSITION_A
);
909 DUMP_REG(DC_DISP_V_PULSE3_CONTROL
);
910 DUMP_REG(DC_DISP_V_PULSE3_POSITION_A
);
911 DUMP_REG(DC_DISP_M0_CONTROL
);
912 DUMP_REG(DC_DISP_M1_CONTROL
);
913 DUMP_REG(DC_DISP_DI_CONTROL
);
914 DUMP_REG(DC_DISP_PP_CONTROL
);
915 DUMP_REG(DC_DISP_PP_SELECT_A
);
916 DUMP_REG(DC_DISP_PP_SELECT_B
);
917 DUMP_REG(DC_DISP_PP_SELECT_C
);
918 DUMP_REG(DC_DISP_PP_SELECT_D
);
919 DUMP_REG(DC_DISP_DISP_CLOCK_CONTROL
);
920 DUMP_REG(DC_DISP_DISP_INTERFACE_CONTROL
);
921 DUMP_REG(DC_DISP_DISP_COLOR_CONTROL
);
922 DUMP_REG(DC_DISP_SHIFT_CLOCK_OPTIONS
);
923 DUMP_REG(DC_DISP_DATA_ENABLE_OPTIONS
);
924 DUMP_REG(DC_DISP_SERIAL_INTERFACE_OPTIONS
);
925 DUMP_REG(DC_DISP_LCD_SPI_OPTIONS
);
926 DUMP_REG(DC_DISP_BORDER_COLOR
);
927 DUMP_REG(DC_DISP_COLOR_KEY0_LOWER
);
928 DUMP_REG(DC_DISP_COLOR_KEY0_UPPER
);
929 DUMP_REG(DC_DISP_COLOR_KEY1_LOWER
);
930 DUMP_REG(DC_DISP_COLOR_KEY1_UPPER
);
931 DUMP_REG(DC_DISP_CURSOR_FOREGROUND
);
932 DUMP_REG(DC_DISP_CURSOR_BACKGROUND
);
933 DUMP_REG(DC_DISP_CURSOR_START_ADDR
);
934 DUMP_REG(DC_DISP_CURSOR_START_ADDR_NS
);
935 DUMP_REG(DC_DISP_CURSOR_POSITION
);
936 DUMP_REG(DC_DISP_CURSOR_POSITION_NS
);
937 DUMP_REG(DC_DISP_INIT_SEQ_CONTROL
);
938 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_A
);
939 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_B
);
940 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_C
);
941 DUMP_REG(DC_DISP_SPI_INIT_SEQ_DATA_D
);
942 DUMP_REG(DC_DISP_DC_MCCIF_FIFOCTRL
);
943 DUMP_REG(DC_DISP_MCCIF_DISPLAY0A_HYST
);
944 DUMP_REG(DC_DISP_MCCIF_DISPLAY0B_HYST
);
945 DUMP_REG(DC_DISP_MCCIF_DISPLAY1A_HYST
);
946 DUMP_REG(DC_DISP_MCCIF_DISPLAY1B_HYST
);
947 DUMP_REG(DC_DISP_DAC_CRT_CTRL
);
948 DUMP_REG(DC_DISP_DISP_MISC_CONTROL
);
949 DUMP_REG(DC_DISP_SD_CONTROL
);
950 DUMP_REG(DC_DISP_SD_CSC_COEFF
);
951 DUMP_REG(DC_DISP_SD_LUT(0));
952 DUMP_REG(DC_DISP_SD_LUT(1));
953 DUMP_REG(DC_DISP_SD_LUT(2));
954 DUMP_REG(DC_DISP_SD_LUT(3));
955 DUMP_REG(DC_DISP_SD_LUT(4));
956 DUMP_REG(DC_DISP_SD_LUT(5));
957 DUMP_REG(DC_DISP_SD_LUT(6));
958 DUMP_REG(DC_DISP_SD_LUT(7));
959 DUMP_REG(DC_DISP_SD_LUT(8));
960 DUMP_REG(DC_DISP_SD_FLICKER_CONTROL
);
961 DUMP_REG(DC_DISP_DC_PIXEL_COUNT
);
962 DUMP_REG(DC_DISP_SD_HISTOGRAM(0));
963 DUMP_REG(DC_DISP_SD_HISTOGRAM(1));
964 DUMP_REG(DC_DISP_SD_HISTOGRAM(2));
965 DUMP_REG(DC_DISP_SD_HISTOGRAM(3));
966 DUMP_REG(DC_DISP_SD_HISTOGRAM(4));
967 DUMP_REG(DC_DISP_SD_HISTOGRAM(5));
968 DUMP_REG(DC_DISP_SD_HISTOGRAM(6));
969 DUMP_REG(DC_DISP_SD_HISTOGRAM(7));
970 DUMP_REG(DC_DISP_SD_BL_TF(0));
971 DUMP_REG(DC_DISP_SD_BL_TF(1));
972 DUMP_REG(DC_DISP_SD_BL_TF(2));
973 DUMP_REG(DC_DISP_SD_BL_TF(3));
974 DUMP_REG(DC_DISP_SD_BL_CONTROL
);
975 DUMP_REG(DC_DISP_SD_HW_K_VALUES
);
976 DUMP_REG(DC_DISP_SD_MAN_K_VALUES
);
977 DUMP_REG(DC_WIN_WIN_OPTIONS
);
978 DUMP_REG(DC_WIN_BYTE_SWAP
);
979 DUMP_REG(DC_WIN_BUFFER_CONTROL
);
980 DUMP_REG(DC_WIN_COLOR_DEPTH
);
981 DUMP_REG(DC_WIN_POSITION
);
982 DUMP_REG(DC_WIN_SIZE
);
983 DUMP_REG(DC_WIN_PRESCALED_SIZE
);
984 DUMP_REG(DC_WIN_H_INITIAL_DDA
);
985 DUMP_REG(DC_WIN_V_INITIAL_DDA
);
986 DUMP_REG(DC_WIN_DDA_INC
);
987 DUMP_REG(DC_WIN_LINE_STRIDE
);
988 DUMP_REG(DC_WIN_BUF_STRIDE
);
989 DUMP_REG(DC_WIN_UV_BUF_STRIDE
);
990 DUMP_REG(DC_WIN_BUFFER_ADDR_MODE
);
991 DUMP_REG(DC_WIN_DV_CONTROL
);
992 DUMP_REG(DC_WIN_BLEND_NOKEY
);
993 DUMP_REG(DC_WIN_BLEND_1WIN
);
994 DUMP_REG(DC_WIN_BLEND_2WIN_X
);
995 DUMP_REG(DC_WIN_BLEND_2WIN_Y
);
996 DUMP_REG(DC_WIN_BLEND_3WIN_XY
);
997 DUMP_REG(DC_WIN_HP_FETCH_CONTROL
);
998 DUMP_REG(DC_WINBUF_START_ADDR
);
999 DUMP_REG(DC_WINBUF_START_ADDR_NS
);
1000 DUMP_REG(DC_WINBUF_START_ADDR_U
);
1001 DUMP_REG(DC_WINBUF_START_ADDR_U_NS
);
1002 DUMP_REG(DC_WINBUF_START_ADDR_V
);
1003 DUMP_REG(DC_WINBUF_START_ADDR_V_NS
);
1004 DUMP_REG(DC_WINBUF_ADDR_H_OFFSET
);
1005 DUMP_REG(DC_WINBUF_ADDR_H_OFFSET_NS
);
1006 DUMP_REG(DC_WINBUF_ADDR_V_OFFSET
);
1007 DUMP_REG(DC_WINBUF_ADDR_V_OFFSET_NS
);
1008 DUMP_REG(DC_WINBUF_UFLOW_STATUS
);
1009 DUMP_REG(DC_WINBUF_AD_UFLOW_STATUS
);
1010 DUMP_REG(DC_WINBUF_BD_UFLOW_STATUS
);
1011 DUMP_REG(DC_WINBUF_CD_UFLOW_STATUS
);
1018 static struct drm_info_list debugfs_files
[] = {
1019 { "regs", tegra_dc_show_regs
, 0, NULL
},
1022 static int tegra_dc_debugfs_init(struct tegra_dc
*dc
, struct drm_minor
*minor
)
1028 name
= kasprintf(GFP_KERNEL
, "dc.%d", dc
->pipe
);
1029 dc
->debugfs
= debugfs_create_dir(name
, minor
->debugfs_root
);
1035 dc
->debugfs_files
= kmemdup(debugfs_files
, sizeof(debugfs_files
),
1037 if (!dc
->debugfs_files
) {
1042 for (i
= 0; i
< ARRAY_SIZE(debugfs_files
); i
++)
1043 dc
->debugfs_files
[i
].data
= dc
;
1045 err
= drm_debugfs_create_files(dc
->debugfs_files
,
1046 ARRAY_SIZE(debugfs_files
),
1047 dc
->debugfs
, minor
);
1056 kfree(dc
->debugfs_files
);
1057 dc
->debugfs_files
= NULL
;
1059 debugfs_remove(dc
->debugfs
);
1065 static int tegra_dc_debugfs_exit(struct tegra_dc
*dc
)
1067 drm_debugfs_remove_files(dc
->debugfs_files
, ARRAY_SIZE(debugfs_files
),
1071 kfree(dc
->debugfs_files
);
1072 dc
->debugfs_files
= NULL
;
1074 debugfs_remove(dc
->debugfs
);
1080 static int tegra_dc_init(struct host1x_client
*client
)
1082 struct tegra_drm
*tegra
= dev_get_drvdata(client
->parent
);
1083 struct tegra_dc
*dc
= host1x_client_to_dc(client
);
1086 dc
->pipe
= tegra
->drm
->mode_config
.num_crtc
;
1088 drm_crtc_init(tegra
->drm
, &dc
->base
, &tegra_crtc_funcs
);
1089 drm_mode_crtc_set_gamma_size(&dc
->base
, 256);
1090 drm_crtc_helper_add(&dc
->base
, &tegra_crtc_helper_funcs
);
1092 err
= tegra_dc_rgb_init(tegra
->drm
, dc
);
1093 if (err
< 0 && err
!= -ENODEV
) {
1094 dev_err(dc
->dev
, "failed to initialize RGB output: %d\n", err
);
1098 err
= tegra_dc_add_planes(tegra
->drm
, dc
);
1102 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1103 err
= tegra_dc_debugfs_init(dc
, tegra
->drm
->primary
);
1105 dev_err(dc
->dev
, "debugfs setup failed: %d\n", err
);
1108 err
= devm_request_irq(dc
->dev
, dc
->irq
, tegra_dc_irq
, 0,
1109 dev_name(dc
->dev
), dc
);
1111 dev_err(dc
->dev
, "failed to request IRQ#%u: %d\n", dc
->irq
,
1119 static int tegra_dc_exit(struct host1x_client
*client
)
1121 struct tegra_dc
*dc
= host1x_client_to_dc(client
);
1124 devm_free_irq(dc
->dev
, dc
->irq
, dc
);
1126 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1127 err
= tegra_dc_debugfs_exit(dc
);
1129 dev_err(dc
->dev
, "debugfs cleanup failed: %d\n", err
);
1132 err
= tegra_dc_rgb_exit(dc
);
1134 dev_err(dc
->dev
, "failed to shutdown RGB output: %d\n", err
);
1141 static const struct host1x_client_ops dc_client_ops
= {
1142 .init
= tegra_dc_init
,
1143 .exit
= tegra_dc_exit
,
1146 static int tegra_dc_probe(struct platform_device
*pdev
)
1148 struct resource
*regs
;
1149 struct tegra_dc
*dc
;
1152 dc
= devm_kzalloc(&pdev
->dev
, sizeof(*dc
), GFP_KERNEL
);
1156 spin_lock_init(&dc
->lock
);
1157 INIT_LIST_HEAD(&dc
->list
);
1158 dc
->dev
= &pdev
->dev
;
1160 dc
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
1161 if (IS_ERR(dc
->clk
)) {
1162 dev_err(&pdev
->dev
, "failed to get clock\n");
1163 return PTR_ERR(dc
->clk
);
1166 err
= clk_prepare_enable(dc
->clk
);
1170 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1171 dc
->regs
= devm_ioremap_resource(&pdev
->dev
, regs
);
1172 if (IS_ERR(dc
->regs
))
1173 return PTR_ERR(dc
->regs
);
1175 dc
->irq
= platform_get_irq(pdev
, 0);
1177 dev_err(&pdev
->dev
, "failed to get IRQ\n");
1181 INIT_LIST_HEAD(&dc
->client
.list
);
1182 dc
->client
.ops
= &dc_client_ops
;
1183 dc
->client
.dev
= &pdev
->dev
;
1185 err
= tegra_dc_rgb_probe(dc
);
1186 if (err
< 0 && err
!= -ENODEV
) {
1187 dev_err(&pdev
->dev
, "failed to probe RGB output: %d\n", err
);
1191 err
= host1x_client_register(&dc
->client
);
1193 dev_err(&pdev
->dev
, "failed to register host1x client: %d\n",
1198 platform_set_drvdata(pdev
, dc
);
1203 static int tegra_dc_remove(struct platform_device
*pdev
)
1205 struct tegra_dc
*dc
= platform_get_drvdata(pdev
);
1208 err
= host1x_client_unregister(&dc
->client
);
1210 dev_err(&pdev
->dev
, "failed to unregister host1x client: %d\n",
1215 err
= tegra_dc_rgb_remove(dc
);
1217 dev_err(&pdev
->dev
, "failed to remove RGB output: %d\n", err
);
1221 clk_disable_unprepare(dc
->clk
);
1226 static struct of_device_id tegra_dc_of_match
[] = {
1227 { .compatible
= "nvidia,tegra30-dc", },
1228 { .compatible
= "nvidia,tegra20-dc", },
1232 struct platform_driver tegra_dc_driver
= {
1235 .owner
= THIS_MODULE
,
1236 .of_match_table
= tegra_dc_of_match
,
1238 .probe
= tegra_dc_probe
,
1239 .remove
= tegra_dc_remove
,