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 void shmob_drm_clk_on(struct shmob_drm_device
*sdev
)
43 clk_enable(sdev
->clock
);
45 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
46 pm_runtime_get_sync(&sdev
->meram_dev
->pdev
->dev
);
50 static void shmob_drm_clk_off(struct shmob_drm_device
*sdev
)
53 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
54 pm_runtime_put_sync(&sdev
->meram_dev
->pdev
->dev
);
57 clk_disable(sdev
->clock
);
60 /* -----------------------------------------------------------------------------
64 static void shmob_drm_crtc_setup_geometry(struct shmob_drm_crtc
*scrtc
)
66 struct drm_crtc
*crtc
= &scrtc
->crtc
;
67 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
68 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
69 const struct drm_display_mode
*mode
= &crtc
->mode
;
73 | ((mode
->flags
& DRM_MODE_FLAG_PVSYNC
) ? 0 : LDMT1R_VPOL
)
74 | ((mode
->flags
& DRM_MODE_FLAG_PHSYNC
) ? 0 : LDMT1R_HPOL
)
75 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWPOL
) ? LDMT1R_DWPOL
: 0)
76 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DIPOL
) ? LDMT1R_DIPOL
: 0)
77 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DAPOL
) ? LDMT1R_DAPOL
: 0)
78 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_HSCNT
) ? LDMT1R_HSCNT
: 0)
79 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWCNT
) ? LDMT1R_DWCNT
: 0);
80 lcdc_write(sdev
, LDMT1R
, value
);
82 if (idata
->interface
>= SHMOB_DRM_IFACE_SYS8A
&&
83 idata
->interface
<= SHMOB_DRM_IFACE_SYS24
) {
85 value
= (idata
->sys
.cs_setup
<< LDMT2R_CSUP_SHIFT
)
86 | (idata
->sys
.vsync_active_high
? LDMT2R_RSV
: 0)
87 | (idata
->sys
.vsync_dir_input
? LDMT2R_VSEL
: 0)
88 | (idata
->sys
.write_setup
<< LDMT2R_WCSC_SHIFT
)
89 | (idata
->sys
.write_cycle
<< LDMT2R_WCEC_SHIFT
)
90 | (idata
->sys
.write_strobe
<< LDMT2R_WCLW_SHIFT
);
91 lcdc_write(sdev
, LDMT2R
, value
);
93 value
= (idata
->sys
.read_latch
<< LDMT3R_RDLC_SHIFT
)
94 | (idata
->sys
.read_setup
<< LDMT3R_RCSC_SHIFT
)
95 | (idata
->sys
.read_cycle
<< LDMT3R_RCEC_SHIFT
)
96 | (idata
->sys
.read_strobe
<< LDMT3R_RCLW_SHIFT
);
97 lcdc_write(sdev
, LDMT3R
, value
);
100 value
= ((mode
->hdisplay
/ 8) << 16) /* HDCN */
101 | (mode
->htotal
/ 8); /* HTCN */
102 lcdc_write(sdev
, LDHCNR
, value
);
104 value
= (((mode
->hsync_end
- mode
->hsync_start
) / 8) << 16) /* HSYNW */
105 | (mode
->hsync_start
/ 8); /* HSYNP */
106 lcdc_write(sdev
, LDHSYNR
, value
);
108 value
= ((mode
->hdisplay
& 7) << 24) | ((mode
->htotal
& 7) << 16)
109 | (((mode
->hsync_end
- mode
->hsync_start
) & 7) << 8)
110 | (mode
->hsync_start
& 7);
111 lcdc_write(sdev
, LDHAJR
, value
);
113 value
= ((mode
->vdisplay
) << 16) /* VDLN */
114 | mode
->vtotal
; /* VTLN */
115 lcdc_write(sdev
, LDVLNR
, value
);
117 value
= ((mode
->vsync_end
- mode
->vsync_start
) << 16) /* VSYNW */
118 | mode
->vsync_start
; /* VSYNP */
119 lcdc_write(sdev
, LDVSYNR
, value
);
122 static void shmob_drm_crtc_start_stop(struct shmob_drm_crtc
*scrtc
, bool start
)
124 struct shmob_drm_device
*sdev
= scrtc
->crtc
.dev
->dev_private
;
127 value
= lcdc_read(sdev
, LDCNT2R
);
129 lcdc_write(sdev
, LDCNT2R
, value
| LDCNT2R_DO
);
131 lcdc_write(sdev
, LDCNT2R
, value
& ~LDCNT2R_DO
);
133 /* Wait until power is applied/stopped. */
135 value
= lcdc_read(sdev
, LDPMR
) & LDPMR_LPS
;
136 if ((start
&& value
) || (!start
&& !value
))
143 /* Stop the dot clock. */
144 lcdc_write(sdev
, LDDCKSTPR
, LDDCKSTPR_DCKSTP
);
149 * shmob_drm_crtc_start - Configure and start the LCDC
150 * @scrtc: the SH Mobile CRTC
152 * Configure and start the LCDC device. External devices (clocks, MERAM, panels,
153 * ...) are not touched by this function.
155 static void shmob_drm_crtc_start(struct shmob_drm_crtc
*scrtc
)
157 struct drm_crtc
*crtc
= &scrtc
->crtc
;
158 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
159 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
160 const struct shmob_drm_format_info
*format
;
161 struct drm_device
*dev
= sdev
->ddev
;
162 struct drm_plane
*plane
;
168 format
= shmob_drm_format_info(crtc
->fb
->pixel_format
);
169 if (WARN_ON(format
== NULL
))
172 /* Enable clocks before accessing the hardware. */
173 shmob_drm_clk_on(sdev
);
175 /* Reset and enable the LCDC. */
176 lcdc_write(sdev
, LDCNT2R
, lcdc_read(sdev
, LDCNT2R
) | LDCNT2R_BR
);
177 lcdc_wait_bit(sdev
, LDCNT2R
, LDCNT2R_BR
, 0);
178 lcdc_write(sdev
, LDCNT2R
, LDCNT2R_ME
);
180 /* Stop the LCDC first and disable all interrupts. */
181 shmob_drm_crtc_start_stop(scrtc
, false);
182 lcdc_write(sdev
, LDINTR
, 0);
184 /* Configure power supply, dot clocks and start them. */
185 lcdc_write(sdev
, LDPMR
, 0);
187 value
= sdev
->lddckr
;
188 if (idata
->clk_div
) {
189 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
192 lcdc_write(sdev
, LDDCKPAT1R
, 0);
193 lcdc_write(sdev
, LDDCKPAT2R
, (1 << (idata
->clk_div
/ 2)) - 1);
195 if (idata
->clk_div
== 1)
196 value
|= LDDCKR_MOSEL
;
198 value
|= idata
->clk_div
;
201 lcdc_write(sdev
, LDDCKR
, value
);
202 lcdc_write(sdev
, LDDCKSTPR
, 0);
203 lcdc_wait_bit(sdev
, LDDCKSTPR
, ~0, 0);
205 /* TODO: Setup SYS panel */
207 /* Setup geometry, format, frame buffer memory and operation mode. */
208 shmob_drm_crtc_setup_geometry(scrtc
);
210 /* TODO: Handle YUV colorspaces. Hardcode REC709 for now. */
211 lcdc_write(sdev
, LDDFR
, format
->lddfr
| LDDFR_CF1
);
212 lcdc_write(sdev
, LDMLSR
, scrtc
->line_size
);
213 lcdc_write(sdev
, LDSA1R
, scrtc
->dma
[0]);
215 lcdc_write(sdev
, LDSA2R
, scrtc
->dma
[1]);
216 lcdc_write(sdev
, LDSM1R
, 0);
218 /* Word and long word swap. */
219 switch (format
->fourcc
) {
220 case DRM_FORMAT_RGB565
:
221 case DRM_FORMAT_NV21
:
222 case DRM_FORMAT_NV61
:
223 case DRM_FORMAT_NV42
:
224 value
= LDDDSR_LS
| LDDDSR_WS
;
226 case DRM_FORMAT_RGB888
:
227 case DRM_FORMAT_NV12
:
228 case DRM_FORMAT_NV16
:
229 case DRM_FORMAT_NV24
:
230 value
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
232 case DRM_FORMAT_ARGB8888
:
237 lcdc_write(sdev
, LDDDSR
, value
);
240 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
241 if (plane
->crtc
== crtc
)
242 shmob_drm_plane_setup(plane
);
245 /* Enable the display output. */
246 lcdc_write(sdev
, LDCNT1R
, LDCNT1R_DE
);
248 shmob_drm_crtc_start_stop(scrtc
, true);
250 scrtc
->started
= true;
253 static void shmob_drm_crtc_stop(struct shmob_drm_crtc
*scrtc
)
255 struct drm_crtc
*crtc
= &scrtc
->crtc
;
256 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
261 /* Disable the MERAM cache. */
263 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
268 shmob_drm_crtc_start_stop(scrtc
, false);
270 /* Disable the display output. */
271 lcdc_write(sdev
, LDCNT1R
, 0);
274 shmob_drm_clk_off(sdev
);
276 scrtc
->started
= false;
279 void shmob_drm_crtc_suspend(struct shmob_drm_crtc
*scrtc
)
281 shmob_drm_crtc_stop(scrtc
);
284 void shmob_drm_crtc_resume(struct shmob_drm_crtc
*scrtc
)
286 if (scrtc
->dpms
!= DRM_MODE_DPMS_ON
)
289 shmob_drm_crtc_start(scrtc
);
292 static void shmob_drm_crtc_compute_base(struct shmob_drm_crtc
*scrtc
,
295 struct drm_crtc
*crtc
= &scrtc
->crtc
;
296 struct drm_framebuffer
*fb
= crtc
->fb
;
297 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
298 struct drm_gem_cma_object
*gem
;
301 bpp
= scrtc
->format
->yuv
? 8 : scrtc
->format
->bpp
;
302 gem
= drm_fb_cma_get_gem_obj(fb
, 0);
303 scrtc
->dma
[0] = gem
->paddr
+ fb
->offsets
[0]
304 + y
* fb
->pitches
[0] + x
* bpp
/ 8;
306 if (scrtc
->format
->yuv
) {
307 bpp
= scrtc
->format
->bpp
- 8;
308 gem
= drm_fb_cma_get_gem_obj(fb
, 1);
309 scrtc
->dma
[1] = gem
->paddr
+ fb
->offsets
[1]
310 + y
/ (bpp
== 4 ? 2 : 1) * fb
->pitches
[1]
311 + x
* (bpp
== 16 ? 2 : 1);
315 sh_mobile_meram_cache_update(sdev
->meram
, scrtc
->cache
,
316 scrtc
->dma
[0], scrtc
->dma
[1],
317 &scrtc
->dma
[0], &scrtc
->dma
[1]);
320 static void shmob_drm_crtc_update_base(struct shmob_drm_crtc
*scrtc
)
322 struct drm_crtc
*crtc
= &scrtc
->crtc
;
323 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
325 shmob_drm_crtc_compute_base(scrtc
, crtc
->x
, crtc
->y
);
327 lcdc_write_mirror(sdev
, LDSA1R
, scrtc
->dma
[0]);
328 if (scrtc
->format
->yuv
)
329 lcdc_write_mirror(sdev
, LDSA2R
, scrtc
->dma
[1]);
331 lcdc_write(sdev
, LDRCNTR
, lcdc_read(sdev
, LDRCNTR
) ^ LDRCNTR_MRS
);
334 #define to_shmob_crtc(c) container_of(c, struct shmob_drm_crtc, crtc)
336 static void shmob_drm_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
338 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
340 if (scrtc
->dpms
== mode
)
343 if (mode
== DRM_MODE_DPMS_ON
)
344 shmob_drm_crtc_start(scrtc
);
346 shmob_drm_crtc_stop(scrtc
);
351 static bool shmob_drm_crtc_mode_fixup(struct drm_crtc
*crtc
,
352 const struct drm_display_mode
*mode
,
353 struct drm_display_mode
*adjusted_mode
)
358 static void shmob_drm_crtc_mode_prepare(struct drm_crtc
*crtc
)
360 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
363 static int shmob_drm_crtc_mode_set(struct drm_crtc
*crtc
,
364 struct drm_display_mode
*mode
,
365 struct drm_display_mode
*adjusted_mode
,
367 struct drm_framebuffer
*old_fb
)
369 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
370 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
371 const struct sh_mobile_meram_cfg
*mdata
= sdev
->pdata
->meram
;
372 const struct shmob_drm_format_info
*format
;
375 format
= shmob_drm_format_info(crtc
->fb
->pixel_format
);
376 if (format
== NULL
) {
377 dev_dbg(sdev
->dev
, "mode_set: unsupported format %08x\n",
378 crtc
->fb
->pixel_format
);
382 scrtc
->format
= format
;
383 scrtc
->line_size
= crtc
->fb
->pitches
[0];
386 /* Enable MERAM cache if configured. We need to de-init
387 * configured ICBs before we can re-initialize them.
390 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
394 cache
= sh_mobile_meram_cache_alloc(sdev
->meram
, mdata
,
395 crtc
->fb
->pitches
[0],
396 adjusted_mode
->vdisplay
,
400 scrtc
->cache
= cache
;
403 shmob_drm_crtc_compute_base(scrtc
, x
, y
);
408 static void shmob_drm_crtc_mode_commit(struct drm_crtc
*crtc
)
410 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_ON
);
413 static int shmob_drm_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
414 struct drm_framebuffer
*old_fb
)
416 shmob_drm_crtc_update_base(to_shmob_crtc(crtc
));
421 static const struct drm_crtc_helper_funcs crtc_helper_funcs
= {
422 .dpms
= shmob_drm_crtc_dpms
,
423 .mode_fixup
= shmob_drm_crtc_mode_fixup
,
424 .prepare
= shmob_drm_crtc_mode_prepare
,
425 .commit
= shmob_drm_crtc_mode_commit
,
426 .mode_set
= shmob_drm_crtc_mode_set
,
427 .mode_set_base
= shmob_drm_crtc_mode_set_base
,
430 void shmob_drm_crtc_cancel_page_flip(struct shmob_drm_crtc
*scrtc
,
431 struct drm_file
*file
)
433 struct drm_pending_vblank_event
*event
;
434 struct drm_device
*dev
= scrtc
->crtc
.dev
;
437 /* Destroy the pending vertical blanking event associated with the
438 * pending page flip, if any, and disable vertical blanking interrupts.
440 spin_lock_irqsave(&dev
->event_lock
, flags
);
441 event
= scrtc
->event
;
442 if (event
&& event
->base
.file_priv
== file
) {
444 event
->base
.destroy(&event
->base
);
445 drm_vblank_put(dev
, 0);
447 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
450 void shmob_drm_crtc_finish_page_flip(struct shmob_drm_crtc
*scrtc
)
452 struct drm_pending_vblank_event
*event
;
453 struct drm_device
*dev
= scrtc
->crtc
.dev
;
456 spin_lock_irqsave(&dev
->event_lock
, flags
);
457 event
= scrtc
->event
;
460 drm_send_vblank_event(dev
, 0, event
);
461 drm_vblank_put(dev
, 0);
463 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
466 static int shmob_drm_crtc_page_flip(struct drm_crtc
*crtc
,
467 struct drm_framebuffer
*fb
,
468 struct drm_pending_vblank_event
*event
,
469 uint32_t page_flip_flags
)
471 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
472 struct drm_device
*dev
= scrtc
->crtc
.dev
;
475 spin_lock_irqsave(&dev
->event_lock
, flags
);
476 if (scrtc
->event
!= NULL
) {
477 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
480 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
483 shmob_drm_crtc_update_base(scrtc
);
487 drm_vblank_get(dev
, 0);
488 spin_lock_irqsave(&dev
->event_lock
, flags
);
489 scrtc
->event
= event
;
490 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
496 static const struct drm_crtc_funcs crtc_funcs
= {
497 .destroy
= drm_crtc_cleanup
,
498 .set_config
= drm_crtc_helper_set_config
,
499 .page_flip
= shmob_drm_crtc_page_flip
,
502 int shmob_drm_crtc_create(struct shmob_drm_device
*sdev
)
504 struct drm_crtc
*crtc
= &sdev
->crtc
.crtc
;
507 sdev
->crtc
.dpms
= DRM_MODE_DPMS_OFF
;
509 ret
= drm_crtc_init(sdev
->ddev
, crtc
, &crtc_funcs
);
513 drm_crtc_helper_add(crtc
, &crtc_helper_funcs
);
518 /* -----------------------------------------------------------------------------
522 #define to_shmob_encoder(e) \
523 container_of(e, struct shmob_drm_encoder, encoder)
525 static void shmob_drm_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
527 struct shmob_drm_encoder
*senc
= to_shmob_encoder(encoder
);
528 struct shmob_drm_device
*sdev
= encoder
->dev
->dev_private
;
529 struct shmob_drm_connector
*scon
= &sdev
->connector
;
531 if (senc
->dpms
== mode
)
534 shmob_drm_backlight_dpms(scon
, mode
);
539 static bool shmob_drm_encoder_mode_fixup(struct drm_encoder
*encoder
,
540 const struct drm_display_mode
*mode
,
541 struct drm_display_mode
*adjusted_mode
)
543 struct drm_device
*dev
= encoder
->dev
;
544 struct shmob_drm_device
*sdev
= dev
->dev_private
;
545 struct drm_connector
*connector
= &sdev
->connector
.connector
;
546 const struct drm_display_mode
*panel_mode
;
548 if (list_empty(&connector
->modes
)) {
549 dev_dbg(dev
->dev
, "mode_fixup: empty modes list\n");
553 /* The flat panel mode is fixed, just copy it to the adjusted mode. */
554 panel_mode
= list_first_entry(&connector
->modes
,
555 struct drm_display_mode
, head
);
556 drm_mode_copy(adjusted_mode
, panel_mode
);
561 static void shmob_drm_encoder_mode_prepare(struct drm_encoder
*encoder
)
563 /* No-op, everything is handled in the CRTC code. */
566 static void shmob_drm_encoder_mode_set(struct drm_encoder
*encoder
,
567 struct drm_display_mode
*mode
,
568 struct drm_display_mode
*adjusted_mode
)
570 /* No-op, everything is handled in the CRTC code. */
573 static void shmob_drm_encoder_mode_commit(struct drm_encoder
*encoder
)
575 /* No-op, everything is handled in the CRTC code. */
578 static const struct drm_encoder_helper_funcs encoder_helper_funcs
= {
579 .dpms
= shmob_drm_encoder_dpms
,
580 .mode_fixup
= shmob_drm_encoder_mode_fixup
,
581 .prepare
= shmob_drm_encoder_mode_prepare
,
582 .commit
= shmob_drm_encoder_mode_commit
,
583 .mode_set
= shmob_drm_encoder_mode_set
,
586 static void shmob_drm_encoder_destroy(struct drm_encoder
*encoder
)
588 drm_encoder_cleanup(encoder
);
591 static const struct drm_encoder_funcs encoder_funcs
= {
592 .destroy
= shmob_drm_encoder_destroy
,
595 int shmob_drm_encoder_create(struct shmob_drm_device
*sdev
)
597 struct drm_encoder
*encoder
= &sdev
->encoder
.encoder
;
600 sdev
->encoder
.dpms
= DRM_MODE_DPMS_OFF
;
602 encoder
->possible_crtcs
= 1;
604 ret
= drm_encoder_init(sdev
->ddev
, encoder
, &encoder_funcs
,
605 DRM_MODE_ENCODER_LVDS
);
609 drm_encoder_helper_add(encoder
, &encoder_helper_funcs
);
614 void shmob_drm_crtc_enable_vblank(struct shmob_drm_device
*sdev
, bool enable
)
619 /* Be careful not to acknowledge any pending interrupt. */
620 spin_lock_irqsave(&sdev
->irq_lock
, flags
);
621 ldintr
= lcdc_read(sdev
, LDINTR
) | LDINTR_STATUS_MASK
;
623 ldintr
|= LDINTR_VEE
;
625 ldintr
&= ~LDINTR_VEE
;
626 lcdc_write(sdev
, LDINTR
, ldintr
);
627 spin_unlock_irqrestore(&sdev
->irq_lock
, flags
);
630 /* -----------------------------------------------------------------------------
634 #define to_shmob_connector(c) \
635 container_of(c, struct shmob_drm_connector, connector)
637 static int shmob_drm_connector_get_modes(struct drm_connector
*connector
)
639 struct shmob_drm_device
*sdev
= connector
->dev
->dev_private
;
640 struct drm_display_mode
*mode
;
642 mode
= drm_mode_create(connector
->dev
);
646 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
647 mode
->clock
= sdev
->pdata
->panel
.mode
.clock
;
648 mode
->hdisplay
= sdev
->pdata
->panel
.mode
.hdisplay
;
649 mode
->hsync_start
= sdev
->pdata
->panel
.mode
.hsync_start
;
650 mode
->hsync_end
= sdev
->pdata
->panel
.mode
.hsync_end
;
651 mode
->htotal
= sdev
->pdata
->panel
.mode
.htotal
;
652 mode
->vdisplay
= sdev
->pdata
->panel
.mode
.vdisplay
;
653 mode
->vsync_start
= sdev
->pdata
->panel
.mode
.vsync_start
;
654 mode
->vsync_end
= sdev
->pdata
->panel
.mode
.vsync_end
;
655 mode
->vtotal
= sdev
->pdata
->panel
.mode
.vtotal
;
656 mode
->flags
= sdev
->pdata
->panel
.mode
.flags
;
658 drm_mode_set_name(mode
);
659 drm_mode_probed_add(connector
, mode
);
661 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
662 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
667 static int shmob_drm_connector_mode_valid(struct drm_connector
*connector
,
668 struct drm_display_mode
*mode
)
673 static struct drm_encoder
*
674 shmob_drm_connector_best_encoder(struct drm_connector
*connector
)
676 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
678 return scon
->encoder
;
681 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
682 .get_modes
= shmob_drm_connector_get_modes
,
683 .mode_valid
= shmob_drm_connector_mode_valid
,
684 .best_encoder
= shmob_drm_connector_best_encoder
,
687 static void shmob_drm_connector_destroy(struct drm_connector
*connector
)
689 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
691 shmob_drm_backlight_exit(scon
);
692 drm_sysfs_connector_remove(connector
);
693 drm_connector_cleanup(connector
);
696 static enum drm_connector_status
697 shmob_drm_connector_detect(struct drm_connector
*connector
, bool force
)
699 return connector_status_connected
;
702 static const struct drm_connector_funcs connector_funcs
= {
703 .dpms
= drm_helper_connector_dpms
,
704 .detect
= shmob_drm_connector_detect
,
705 .fill_modes
= drm_helper_probe_single_connector_modes
,
706 .destroy
= shmob_drm_connector_destroy
,
709 int shmob_drm_connector_create(struct shmob_drm_device
*sdev
,
710 struct drm_encoder
*encoder
)
712 struct drm_connector
*connector
= &sdev
->connector
.connector
;
715 sdev
->connector
.encoder
= encoder
;
717 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
718 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
720 ret
= drm_connector_init(sdev
->ddev
, connector
, &connector_funcs
,
721 DRM_MODE_CONNECTOR_LVDS
);
725 drm_connector_helper_add(connector
, &connector_helper_funcs
);
726 ret
= drm_sysfs_connector_add(connector
);
730 ret
= shmob_drm_backlight_init(&sdev
->connector
);
734 ret
= drm_mode_connector_attach_encoder(connector
, encoder
);
738 connector
->encoder
= encoder
;
740 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
741 drm_object_property_set_value(&connector
->base
,
742 sdev
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
747 shmob_drm_backlight_exit(&sdev
->connector
);
749 drm_sysfs_connector_remove(connector
);
751 drm_connector_cleanup(connector
);