2 * shmob_drm_crtc.c -- SH Mobile DRM CRTCs
4 * Copyright (C) 2012 Renesas Corporation
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/backlight.h>
15 #include <linux/clk.h>
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_crtc_helper.h>
20 #include <drm/drm_fb_cma_helper.h>
21 #include <drm/drm_gem_cma_helper.h>
23 #include <video/sh_mobile_meram.h>
25 #include "shmob_drm_backlight.h"
26 #include "shmob_drm_crtc.h"
27 #include "shmob_drm_drv.h"
28 #include "shmob_drm_kms.h"
29 #include "shmob_drm_plane.h"
30 #include "shmob_drm_regs.h"
36 /* -----------------------------------------------------------------------------
40 static int shmob_drm_clk_on(struct shmob_drm_device
*sdev
)
45 ret
= clk_prepare_enable(sdev
->clock
);
50 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
51 pm_runtime_get_sync(&sdev
->meram_dev
->pdev
->dev
);
57 static void shmob_drm_clk_off(struct shmob_drm_device
*sdev
)
60 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
61 pm_runtime_put_sync(&sdev
->meram_dev
->pdev
->dev
);
64 clk_disable_unprepare(sdev
->clock
);
67 /* -----------------------------------------------------------------------------
71 static void shmob_drm_crtc_setup_geometry(struct shmob_drm_crtc
*scrtc
)
73 struct drm_crtc
*crtc
= &scrtc
->crtc
;
74 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
75 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
76 const struct drm_display_mode
*mode
= &crtc
->mode
;
80 | ((mode
->flags
& DRM_MODE_FLAG_PVSYNC
) ? 0 : LDMT1R_VPOL
)
81 | ((mode
->flags
& DRM_MODE_FLAG_PHSYNC
) ? 0 : LDMT1R_HPOL
)
82 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWPOL
) ? LDMT1R_DWPOL
: 0)
83 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DIPOL
) ? LDMT1R_DIPOL
: 0)
84 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DAPOL
) ? LDMT1R_DAPOL
: 0)
85 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_HSCNT
) ? LDMT1R_HSCNT
: 0)
86 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWCNT
) ? LDMT1R_DWCNT
: 0);
87 lcdc_write(sdev
, LDMT1R
, value
);
89 if (idata
->interface
>= SHMOB_DRM_IFACE_SYS8A
&&
90 idata
->interface
<= SHMOB_DRM_IFACE_SYS24
) {
92 value
= (idata
->sys
.cs_setup
<< LDMT2R_CSUP_SHIFT
)
93 | (idata
->sys
.vsync_active_high
? LDMT2R_RSV
: 0)
94 | (idata
->sys
.vsync_dir_input
? LDMT2R_VSEL
: 0)
95 | (idata
->sys
.write_setup
<< LDMT2R_WCSC_SHIFT
)
96 | (idata
->sys
.write_cycle
<< LDMT2R_WCEC_SHIFT
)
97 | (idata
->sys
.write_strobe
<< LDMT2R_WCLW_SHIFT
);
98 lcdc_write(sdev
, LDMT2R
, value
);
100 value
= (idata
->sys
.read_latch
<< LDMT3R_RDLC_SHIFT
)
101 | (idata
->sys
.read_setup
<< LDMT3R_RCSC_SHIFT
)
102 | (idata
->sys
.read_cycle
<< LDMT3R_RCEC_SHIFT
)
103 | (idata
->sys
.read_strobe
<< LDMT3R_RCLW_SHIFT
);
104 lcdc_write(sdev
, LDMT3R
, value
);
107 value
= ((mode
->hdisplay
/ 8) << 16) /* HDCN */
108 | (mode
->htotal
/ 8); /* HTCN */
109 lcdc_write(sdev
, LDHCNR
, value
);
111 value
= (((mode
->hsync_end
- mode
->hsync_start
) / 8) << 16) /* HSYNW */
112 | (mode
->hsync_start
/ 8); /* HSYNP */
113 lcdc_write(sdev
, LDHSYNR
, value
);
115 value
= ((mode
->hdisplay
& 7) << 24) | ((mode
->htotal
& 7) << 16)
116 | (((mode
->hsync_end
- mode
->hsync_start
) & 7) << 8)
117 | (mode
->hsync_start
& 7);
118 lcdc_write(sdev
, LDHAJR
, value
);
120 value
= ((mode
->vdisplay
) << 16) /* VDLN */
121 | mode
->vtotal
; /* VTLN */
122 lcdc_write(sdev
, LDVLNR
, value
);
124 value
= ((mode
->vsync_end
- mode
->vsync_start
) << 16) /* VSYNW */
125 | mode
->vsync_start
; /* VSYNP */
126 lcdc_write(sdev
, LDVSYNR
, value
);
129 static void shmob_drm_crtc_start_stop(struct shmob_drm_crtc
*scrtc
, bool start
)
131 struct shmob_drm_device
*sdev
= scrtc
->crtc
.dev
->dev_private
;
134 value
= lcdc_read(sdev
, LDCNT2R
);
136 lcdc_write(sdev
, LDCNT2R
, value
| LDCNT2R_DO
);
138 lcdc_write(sdev
, LDCNT2R
, value
& ~LDCNT2R_DO
);
140 /* Wait until power is applied/stopped. */
142 value
= lcdc_read(sdev
, LDPMR
) & LDPMR_LPS
;
143 if ((start
&& value
) || (!start
&& !value
))
150 /* Stop the dot clock. */
151 lcdc_write(sdev
, LDDCKSTPR
, LDDCKSTPR_DCKSTP
);
156 * shmob_drm_crtc_start - Configure and start the LCDC
157 * @scrtc: the SH Mobile CRTC
159 * Configure and start the LCDC device. External devices (clocks, MERAM, panels,
160 * ...) are not touched by this function.
162 static void shmob_drm_crtc_start(struct shmob_drm_crtc
*scrtc
)
164 struct drm_crtc
*crtc
= &scrtc
->crtc
;
165 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
166 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
167 const struct shmob_drm_format_info
*format
;
168 struct drm_device
*dev
= sdev
->ddev
;
169 struct drm_plane
*plane
;
176 format
= shmob_drm_format_info(crtc
->fb
->pixel_format
);
177 if (WARN_ON(format
== NULL
))
180 /* Enable clocks before accessing the hardware. */
181 ret
= shmob_drm_clk_on(sdev
);
185 /* Reset and enable the LCDC. */
186 lcdc_write(sdev
, LDCNT2R
, lcdc_read(sdev
, LDCNT2R
) | LDCNT2R_BR
);
187 lcdc_wait_bit(sdev
, LDCNT2R
, LDCNT2R_BR
, 0);
188 lcdc_write(sdev
, LDCNT2R
, LDCNT2R_ME
);
190 /* Stop the LCDC first and disable all interrupts. */
191 shmob_drm_crtc_start_stop(scrtc
, false);
192 lcdc_write(sdev
, LDINTR
, 0);
194 /* Configure power supply, dot clocks and start them. */
195 lcdc_write(sdev
, LDPMR
, 0);
197 value
= sdev
->lddckr
;
198 if (idata
->clk_div
) {
199 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
202 lcdc_write(sdev
, LDDCKPAT1R
, 0);
203 lcdc_write(sdev
, LDDCKPAT2R
, (1 << (idata
->clk_div
/ 2)) - 1);
205 if (idata
->clk_div
== 1)
206 value
|= LDDCKR_MOSEL
;
208 value
|= idata
->clk_div
;
211 lcdc_write(sdev
, LDDCKR
, value
);
212 lcdc_write(sdev
, LDDCKSTPR
, 0);
213 lcdc_wait_bit(sdev
, LDDCKSTPR
, ~0, 0);
215 /* TODO: Setup SYS panel */
217 /* Setup geometry, format, frame buffer memory and operation mode. */
218 shmob_drm_crtc_setup_geometry(scrtc
);
220 /* TODO: Handle YUV colorspaces. Hardcode REC709 for now. */
221 lcdc_write(sdev
, LDDFR
, format
->lddfr
| LDDFR_CF1
);
222 lcdc_write(sdev
, LDMLSR
, scrtc
->line_size
);
223 lcdc_write(sdev
, LDSA1R
, scrtc
->dma
[0]);
225 lcdc_write(sdev
, LDSA2R
, scrtc
->dma
[1]);
226 lcdc_write(sdev
, LDSM1R
, 0);
228 /* Word and long word swap. */
229 switch (format
->fourcc
) {
230 case DRM_FORMAT_RGB565
:
231 case DRM_FORMAT_NV21
:
232 case DRM_FORMAT_NV61
:
233 case DRM_FORMAT_NV42
:
234 value
= LDDDSR_LS
| LDDDSR_WS
;
236 case DRM_FORMAT_RGB888
:
237 case DRM_FORMAT_NV12
:
238 case DRM_FORMAT_NV16
:
239 case DRM_FORMAT_NV24
:
240 value
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
242 case DRM_FORMAT_ARGB8888
:
247 lcdc_write(sdev
, LDDDSR
, value
);
250 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
251 if (plane
->crtc
== crtc
)
252 shmob_drm_plane_setup(plane
);
255 /* Enable the display output. */
256 lcdc_write(sdev
, LDCNT1R
, LDCNT1R_DE
);
258 shmob_drm_crtc_start_stop(scrtc
, true);
260 scrtc
->started
= true;
263 static void shmob_drm_crtc_stop(struct shmob_drm_crtc
*scrtc
)
265 struct drm_crtc
*crtc
= &scrtc
->crtc
;
266 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
271 /* Disable the MERAM cache. */
273 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
278 shmob_drm_crtc_start_stop(scrtc
, false);
280 /* Disable the display output. */
281 lcdc_write(sdev
, LDCNT1R
, 0);
284 shmob_drm_clk_off(sdev
);
286 scrtc
->started
= false;
289 void shmob_drm_crtc_suspend(struct shmob_drm_crtc
*scrtc
)
291 shmob_drm_crtc_stop(scrtc
);
294 void shmob_drm_crtc_resume(struct shmob_drm_crtc
*scrtc
)
296 if (scrtc
->dpms
!= DRM_MODE_DPMS_ON
)
299 shmob_drm_crtc_start(scrtc
);
302 static void shmob_drm_crtc_compute_base(struct shmob_drm_crtc
*scrtc
,
305 struct drm_crtc
*crtc
= &scrtc
->crtc
;
306 struct drm_framebuffer
*fb
= crtc
->fb
;
307 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
308 struct drm_gem_cma_object
*gem
;
311 bpp
= scrtc
->format
->yuv
? 8 : scrtc
->format
->bpp
;
312 gem
= drm_fb_cma_get_gem_obj(fb
, 0);
313 scrtc
->dma
[0] = gem
->paddr
+ fb
->offsets
[0]
314 + y
* fb
->pitches
[0] + x
* bpp
/ 8;
316 if (scrtc
->format
->yuv
) {
317 bpp
= scrtc
->format
->bpp
- 8;
318 gem
= drm_fb_cma_get_gem_obj(fb
, 1);
319 scrtc
->dma
[1] = gem
->paddr
+ fb
->offsets
[1]
320 + y
/ (bpp
== 4 ? 2 : 1) * fb
->pitches
[1]
321 + x
* (bpp
== 16 ? 2 : 1);
325 sh_mobile_meram_cache_update(sdev
->meram
, scrtc
->cache
,
326 scrtc
->dma
[0], scrtc
->dma
[1],
327 &scrtc
->dma
[0], &scrtc
->dma
[1]);
330 static void shmob_drm_crtc_update_base(struct shmob_drm_crtc
*scrtc
)
332 struct drm_crtc
*crtc
= &scrtc
->crtc
;
333 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
335 shmob_drm_crtc_compute_base(scrtc
, crtc
->x
, crtc
->y
);
337 lcdc_write_mirror(sdev
, LDSA1R
, scrtc
->dma
[0]);
338 if (scrtc
->format
->yuv
)
339 lcdc_write_mirror(sdev
, LDSA2R
, scrtc
->dma
[1]);
341 lcdc_write(sdev
, LDRCNTR
, lcdc_read(sdev
, LDRCNTR
) ^ LDRCNTR_MRS
);
344 #define to_shmob_crtc(c) container_of(c, struct shmob_drm_crtc, crtc)
346 static void shmob_drm_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
348 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
350 if (scrtc
->dpms
== mode
)
353 if (mode
== DRM_MODE_DPMS_ON
)
354 shmob_drm_crtc_start(scrtc
);
356 shmob_drm_crtc_stop(scrtc
);
361 static bool shmob_drm_crtc_mode_fixup(struct drm_crtc
*crtc
,
362 const struct drm_display_mode
*mode
,
363 struct drm_display_mode
*adjusted_mode
)
368 static void shmob_drm_crtc_mode_prepare(struct drm_crtc
*crtc
)
370 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
373 static int shmob_drm_crtc_mode_set(struct drm_crtc
*crtc
,
374 struct drm_display_mode
*mode
,
375 struct drm_display_mode
*adjusted_mode
,
377 struct drm_framebuffer
*old_fb
)
379 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
380 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
381 const struct sh_mobile_meram_cfg
*mdata
= sdev
->pdata
->meram
;
382 const struct shmob_drm_format_info
*format
;
385 format
= shmob_drm_format_info(crtc
->fb
->pixel_format
);
386 if (format
== NULL
) {
387 dev_dbg(sdev
->dev
, "mode_set: unsupported format %08x\n",
388 crtc
->fb
->pixel_format
);
392 scrtc
->format
= format
;
393 scrtc
->line_size
= crtc
->fb
->pitches
[0];
396 /* Enable MERAM cache if configured. We need to de-init
397 * configured ICBs before we can re-initialize them.
400 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
404 cache
= sh_mobile_meram_cache_alloc(sdev
->meram
, mdata
,
405 crtc
->fb
->pitches
[0],
406 adjusted_mode
->vdisplay
,
410 scrtc
->cache
= cache
;
413 shmob_drm_crtc_compute_base(scrtc
, x
, y
);
418 static void shmob_drm_crtc_mode_commit(struct drm_crtc
*crtc
)
420 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_ON
);
423 static int shmob_drm_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
424 struct drm_framebuffer
*old_fb
)
426 shmob_drm_crtc_update_base(to_shmob_crtc(crtc
));
431 static const struct drm_crtc_helper_funcs crtc_helper_funcs
= {
432 .dpms
= shmob_drm_crtc_dpms
,
433 .mode_fixup
= shmob_drm_crtc_mode_fixup
,
434 .prepare
= shmob_drm_crtc_mode_prepare
,
435 .commit
= shmob_drm_crtc_mode_commit
,
436 .mode_set
= shmob_drm_crtc_mode_set
,
437 .mode_set_base
= shmob_drm_crtc_mode_set_base
,
440 void shmob_drm_crtc_cancel_page_flip(struct shmob_drm_crtc
*scrtc
,
441 struct drm_file
*file
)
443 struct drm_pending_vblank_event
*event
;
444 struct drm_device
*dev
= scrtc
->crtc
.dev
;
447 /* Destroy the pending vertical blanking event associated with the
448 * pending page flip, if any, and disable vertical blanking interrupts.
450 spin_lock_irqsave(&dev
->event_lock
, flags
);
451 event
= scrtc
->event
;
452 if (event
&& event
->base
.file_priv
== file
) {
454 event
->base
.destroy(&event
->base
);
455 drm_vblank_put(dev
, 0);
457 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
460 void shmob_drm_crtc_finish_page_flip(struct shmob_drm_crtc
*scrtc
)
462 struct drm_pending_vblank_event
*event
;
463 struct drm_device
*dev
= scrtc
->crtc
.dev
;
466 spin_lock_irqsave(&dev
->event_lock
, flags
);
467 event
= scrtc
->event
;
470 drm_send_vblank_event(dev
, 0, event
);
471 drm_vblank_put(dev
, 0);
473 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
476 static int shmob_drm_crtc_page_flip(struct drm_crtc
*crtc
,
477 struct drm_framebuffer
*fb
,
478 struct drm_pending_vblank_event
*event
,
479 uint32_t page_flip_flags
)
481 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
482 struct drm_device
*dev
= scrtc
->crtc
.dev
;
485 spin_lock_irqsave(&dev
->event_lock
, flags
);
486 if (scrtc
->event
!= NULL
) {
487 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
490 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
493 shmob_drm_crtc_update_base(scrtc
);
497 drm_vblank_get(dev
, 0);
498 spin_lock_irqsave(&dev
->event_lock
, flags
);
499 scrtc
->event
= event
;
500 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
506 static const struct drm_crtc_funcs crtc_funcs
= {
507 .destroy
= drm_crtc_cleanup
,
508 .set_config
= drm_crtc_helper_set_config
,
509 .page_flip
= shmob_drm_crtc_page_flip
,
512 int shmob_drm_crtc_create(struct shmob_drm_device
*sdev
)
514 struct drm_crtc
*crtc
= &sdev
->crtc
.crtc
;
517 sdev
->crtc
.dpms
= DRM_MODE_DPMS_OFF
;
519 ret
= drm_crtc_init(sdev
->ddev
, crtc
, &crtc_funcs
);
523 drm_crtc_helper_add(crtc
, &crtc_helper_funcs
);
528 /* -----------------------------------------------------------------------------
532 #define to_shmob_encoder(e) \
533 container_of(e, struct shmob_drm_encoder, encoder)
535 static void shmob_drm_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
537 struct shmob_drm_encoder
*senc
= to_shmob_encoder(encoder
);
538 struct shmob_drm_device
*sdev
= encoder
->dev
->dev_private
;
539 struct shmob_drm_connector
*scon
= &sdev
->connector
;
541 if (senc
->dpms
== mode
)
544 shmob_drm_backlight_dpms(scon
, mode
);
549 static bool shmob_drm_encoder_mode_fixup(struct drm_encoder
*encoder
,
550 const struct drm_display_mode
*mode
,
551 struct drm_display_mode
*adjusted_mode
)
553 struct drm_device
*dev
= encoder
->dev
;
554 struct shmob_drm_device
*sdev
= dev
->dev_private
;
555 struct drm_connector
*connector
= &sdev
->connector
.connector
;
556 const struct drm_display_mode
*panel_mode
;
558 if (list_empty(&connector
->modes
)) {
559 dev_dbg(dev
->dev
, "mode_fixup: empty modes list\n");
563 /* The flat panel mode is fixed, just copy it to the adjusted mode. */
564 panel_mode
= list_first_entry(&connector
->modes
,
565 struct drm_display_mode
, head
);
566 drm_mode_copy(adjusted_mode
, panel_mode
);
571 static void shmob_drm_encoder_mode_prepare(struct drm_encoder
*encoder
)
573 /* No-op, everything is handled in the CRTC code. */
576 static void shmob_drm_encoder_mode_set(struct drm_encoder
*encoder
,
577 struct drm_display_mode
*mode
,
578 struct drm_display_mode
*adjusted_mode
)
580 /* No-op, everything is handled in the CRTC code. */
583 static void shmob_drm_encoder_mode_commit(struct drm_encoder
*encoder
)
585 /* No-op, everything is handled in the CRTC code. */
588 static const struct drm_encoder_helper_funcs encoder_helper_funcs
= {
589 .dpms
= shmob_drm_encoder_dpms
,
590 .mode_fixup
= shmob_drm_encoder_mode_fixup
,
591 .prepare
= shmob_drm_encoder_mode_prepare
,
592 .commit
= shmob_drm_encoder_mode_commit
,
593 .mode_set
= shmob_drm_encoder_mode_set
,
596 static void shmob_drm_encoder_destroy(struct drm_encoder
*encoder
)
598 drm_encoder_cleanup(encoder
);
601 static const struct drm_encoder_funcs encoder_funcs
= {
602 .destroy
= shmob_drm_encoder_destroy
,
605 int shmob_drm_encoder_create(struct shmob_drm_device
*sdev
)
607 struct drm_encoder
*encoder
= &sdev
->encoder
.encoder
;
610 sdev
->encoder
.dpms
= DRM_MODE_DPMS_OFF
;
612 encoder
->possible_crtcs
= 1;
614 ret
= drm_encoder_init(sdev
->ddev
, encoder
, &encoder_funcs
,
615 DRM_MODE_ENCODER_LVDS
);
619 drm_encoder_helper_add(encoder
, &encoder_helper_funcs
);
624 void shmob_drm_crtc_enable_vblank(struct shmob_drm_device
*sdev
, bool enable
)
629 /* Be careful not to acknowledge any pending interrupt. */
630 spin_lock_irqsave(&sdev
->irq_lock
, flags
);
631 ldintr
= lcdc_read(sdev
, LDINTR
) | LDINTR_STATUS_MASK
;
633 ldintr
|= LDINTR_VEE
;
635 ldintr
&= ~LDINTR_VEE
;
636 lcdc_write(sdev
, LDINTR
, ldintr
);
637 spin_unlock_irqrestore(&sdev
->irq_lock
, flags
);
640 /* -----------------------------------------------------------------------------
644 #define to_shmob_connector(c) \
645 container_of(c, struct shmob_drm_connector, connector)
647 static int shmob_drm_connector_get_modes(struct drm_connector
*connector
)
649 struct shmob_drm_device
*sdev
= connector
->dev
->dev_private
;
650 struct drm_display_mode
*mode
;
652 mode
= drm_mode_create(connector
->dev
);
656 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
657 mode
->clock
= sdev
->pdata
->panel
.mode
.clock
;
658 mode
->hdisplay
= sdev
->pdata
->panel
.mode
.hdisplay
;
659 mode
->hsync_start
= sdev
->pdata
->panel
.mode
.hsync_start
;
660 mode
->hsync_end
= sdev
->pdata
->panel
.mode
.hsync_end
;
661 mode
->htotal
= sdev
->pdata
->panel
.mode
.htotal
;
662 mode
->vdisplay
= sdev
->pdata
->panel
.mode
.vdisplay
;
663 mode
->vsync_start
= sdev
->pdata
->panel
.mode
.vsync_start
;
664 mode
->vsync_end
= sdev
->pdata
->panel
.mode
.vsync_end
;
665 mode
->vtotal
= sdev
->pdata
->panel
.mode
.vtotal
;
666 mode
->flags
= sdev
->pdata
->panel
.mode
.flags
;
668 drm_mode_set_name(mode
);
669 drm_mode_probed_add(connector
, mode
);
671 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
672 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
677 static int shmob_drm_connector_mode_valid(struct drm_connector
*connector
,
678 struct drm_display_mode
*mode
)
683 static struct drm_encoder
*
684 shmob_drm_connector_best_encoder(struct drm_connector
*connector
)
686 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
688 return scon
->encoder
;
691 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
692 .get_modes
= shmob_drm_connector_get_modes
,
693 .mode_valid
= shmob_drm_connector_mode_valid
,
694 .best_encoder
= shmob_drm_connector_best_encoder
,
697 static void shmob_drm_connector_destroy(struct drm_connector
*connector
)
699 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
701 shmob_drm_backlight_exit(scon
);
702 drm_sysfs_connector_remove(connector
);
703 drm_connector_cleanup(connector
);
706 static enum drm_connector_status
707 shmob_drm_connector_detect(struct drm_connector
*connector
, bool force
)
709 return connector_status_connected
;
712 static const struct drm_connector_funcs connector_funcs
= {
713 .dpms
= drm_helper_connector_dpms
,
714 .detect
= shmob_drm_connector_detect
,
715 .fill_modes
= drm_helper_probe_single_connector_modes
,
716 .destroy
= shmob_drm_connector_destroy
,
719 int shmob_drm_connector_create(struct shmob_drm_device
*sdev
,
720 struct drm_encoder
*encoder
)
722 struct drm_connector
*connector
= &sdev
->connector
.connector
;
725 sdev
->connector
.encoder
= encoder
;
727 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
728 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
730 ret
= drm_connector_init(sdev
->ddev
, connector
, &connector_funcs
,
731 DRM_MODE_CONNECTOR_LVDS
);
735 drm_connector_helper_add(connector
, &connector_helper_funcs
);
736 ret
= drm_sysfs_connector_add(connector
);
740 ret
= shmob_drm_backlight_init(&sdev
->connector
);
744 ret
= drm_mode_connector_attach_encoder(connector
, encoder
);
748 connector
->encoder
= encoder
;
750 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
751 drm_object_property_set_value(&connector
->base
,
752 sdev
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
757 shmob_drm_backlight_exit(&sdev
->connector
);
759 drm_sysfs_connector_remove(connector
);
761 drm_connector_cleanup(connector
);