2 * shmob_drm_crtc.c -- SH Mobile DRM CRTCs
4 * Copyright (C) 2012 Renesas Electronics 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>
22 #include <drm/drm_plane_helper.h>
24 #include <video/sh_mobile_meram.h>
26 #include "shmob_drm_backlight.h"
27 #include "shmob_drm_crtc.h"
28 #include "shmob_drm_drv.h"
29 #include "shmob_drm_kms.h"
30 #include "shmob_drm_plane.h"
31 #include "shmob_drm_regs.h"
37 /* -----------------------------------------------------------------------------
41 static int shmob_drm_clk_on(struct shmob_drm_device
*sdev
)
46 ret
= clk_prepare_enable(sdev
->clock
);
51 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
52 pm_runtime_get_sync(&sdev
->meram_dev
->pdev
->dev
);
58 static void shmob_drm_clk_off(struct shmob_drm_device
*sdev
)
61 if (sdev
->meram_dev
&& sdev
->meram_dev
->pdev
)
62 pm_runtime_put_sync(&sdev
->meram_dev
->pdev
->dev
);
65 clk_disable_unprepare(sdev
->clock
);
68 /* -----------------------------------------------------------------------------
72 static void shmob_drm_crtc_setup_geometry(struct shmob_drm_crtc
*scrtc
)
74 struct drm_crtc
*crtc
= &scrtc
->crtc
;
75 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
76 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
77 const struct drm_display_mode
*mode
= &crtc
->mode
;
81 | ((mode
->flags
& DRM_MODE_FLAG_PVSYNC
) ? 0 : LDMT1R_VPOL
)
82 | ((mode
->flags
& DRM_MODE_FLAG_PHSYNC
) ? 0 : LDMT1R_HPOL
)
83 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWPOL
) ? LDMT1R_DWPOL
: 0)
84 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DIPOL
) ? LDMT1R_DIPOL
: 0)
85 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DAPOL
) ? LDMT1R_DAPOL
: 0)
86 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_HSCNT
) ? LDMT1R_HSCNT
: 0)
87 | ((idata
->flags
& SHMOB_DRM_IFACE_FL_DWCNT
) ? LDMT1R_DWCNT
: 0);
88 lcdc_write(sdev
, LDMT1R
, value
);
90 if (idata
->interface
>= SHMOB_DRM_IFACE_SYS8A
&&
91 idata
->interface
<= SHMOB_DRM_IFACE_SYS24
) {
93 value
= (idata
->sys
.cs_setup
<< LDMT2R_CSUP_SHIFT
)
94 | (idata
->sys
.vsync_active_high
? LDMT2R_RSV
: 0)
95 | (idata
->sys
.vsync_dir_input
? LDMT2R_VSEL
: 0)
96 | (idata
->sys
.write_setup
<< LDMT2R_WCSC_SHIFT
)
97 | (idata
->sys
.write_cycle
<< LDMT2R_WCEC_SHIFT
)
98 | (idata
->sys
.write_strobe
<< LDMT2R_WCLW_SHIFT
);
99 lcdc_write(sdev
, LDMT2R
, value
);
101 value
= (idata
->sys
.read_latch
<< LDMT3R_RDLC_SHIFT
)
102 | (idata
->sys
.read_setup
<< LDMT3R_RCSC_SHIFT
)
103 | (idata
->sys
.read_cycle
<< LDMT3R_RCEC_SHIFT
)
104 | (idata
->sys
.read_strobe
<< LDMT3R_RCLW_SHIFT
);
105 lcdc_write(sdev
, LDMT3R
, value
);
108 value
= ((mode
->hdisplay
/ 8) << 16) /* HDCN */
109 | (mode
->htotal
/ 8); /* HTCN */
110 lcdc_write(sdev
, LDHCNR
, value
);
112 value
= (((mode
->hsync_end
- mode
->hsync_start
) / 8) << 16) /* HSYNW */
113 | (mode
->hsync_start
/ 8); /* HSYNP */
114 lcdc_write(sdev
, LDHSYNR
, value
);
116 value
= ((mode
->hdisplay
& 7) << 24) | ((mode
->htotal
& 7) << 16)
117 | (((mode
->hsync_end
- mode
->hsync_start
) & 7) << 8)
118 | (mode
->hsync_start
& 7);
119 lcdc_write(sdev
, LDHAJR
, value
);
121 value
= ((mode
->vdisplay
) << 16) /* VDLN */
122 | mode
->vtotal
; /* VTLN */
123 lcdc_write(sdev
, LDVLNR
, value
);
125 value
= ((mode
->vsync_end
- mode
->vsync_start
) << 16) /* VSYNW */
126 | mode
->vsync_start
; /* VSYNP */
127 lcdc_write(sdev
, LDVSYNR
, value
);
130 static void shmob_drm_crtc_start_stop(struct shmob_drm_crtc
*scrtc
, bool start
)
132 struct shmob_drm_device
*sdev
= scrtc
->crtc
.dev
->dev_private
;
135 value
= lcdc_read(sdev
, LDCNT2R
);
137 lcdc_write(sdev
, LDCNT2R
, value
| LDCNT2R_DO
);
139 lcdc_write(sdev
, LDCNT2R
, value
& ~LDCNT2R_DO
);
141 /* Wait until power is applied/stopped. */
143 value
= lcdc_read(sdev
, LDPMR
) & LDPMR_LPS
;
144 if ((start
&& value
) || (!start
&& !value
))
151 /* Stop the dot clock. */
152 lcdc_write(sdev
, LDDCKSTPR
, LDDCKSTPR_DCKSTP
);
157 * shmob_drm_crtc_start - Configure and start the LCDC
158 * @scrtc: the SH Mobile CRTC
160 * Configure and start the LCDC device. External devices (clocks, MERAM, panels,
161 * ...) are not touched by this function.
163 static void shmob_drm_crtc_start(struct shmob_drm_crtc
*scrtc
)
165 struct drm_crtc
*crtc
= &scrtc
->crtc
;
166 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
167 const struct shmob_drm_interface_data
*idata
= &sdev
->pdata
->iface
;
168 const struct shmob_drm_format_info
*format
;
169 struct drm_device
*dev
= sdev
->ddev
;
170 struct drm_plane
*plane
;
177 format
= shmob_drm_format_info(crtc
->primary
->fb
->pixel_format
);
178 if (WARN_ON(format
== NULL
))
181 /* Enable clocks before accessing the hardware. */
182 ret
= shmob_drm_clk_on(sdev
);
186 /* Reset and enable the LCDC. */
187 lcdc_write(sdev
, LDCNT2R
, lcdc_read(sdev
, LDCNT2R
) | LDCNT2R_BR
);
188 lcdc_wait_bit(sdev
, LDCNT2R
, LDCNT2R_BR
, 0);
189 lcdc_write(sdev
, LDCNT2R
, LDCNT2R_ME
);
191 /* Stop the LCDC first and disable all interrupts. */
192 shmob_drm_crtc_start_stop(scrtc
, false);
193 lcdc_write(sdev
, LDINTR
, 0);
195 /* Configure power supply, dot clocks and start them. */
196 lcdc_write(sdev
, LDPMR
, 0);
198 value
= sdev
->lddckr
;
199 if (idata
->clk_div
) {
200 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
203 lcdc_write(sdev
, LDDCKPAT1R
, 0);
204 lcdc_write(sdev
, LDDCKPAT2R
, (1 << (idata
->clk_div
/ 2)) - 1);
206 if (idata
->clk_div
== 1)
207 value
|= LDDCKR_MOSEL
;
209 value
|= idata
->clk_div
;
212 lcdc_write(sdev
, LDDCKR
, value
);
213 lcdc_write(sdev
, LDDCKSTPR
, 0);
214 lcdc_wait_bit(sdev
, LDDCKSTPR
, ~0, 0);
216 /* TODO: Setup SYS panel */
218 /* Setup geometry, format, frame buffer memory and operation mode. */
219 shmob_drm_crtc_setup_geometry(scrtc
);
221 /* TODO: Handle YUV colorspaces. Hardcode REC709 for now. */
222 lcdc_write(sdev
, LDDFR
, format
->lddfr
| LDDFR_CF1
);
223 lcdc_write(sdev
, LDMLSR
, scrtc
->line_size
);
224 lcdc_write(sdev
, LDSA1R
, scrtc
->dma
[0]);
226 lcdc_write(sdev
, LDSA2R
, scrtc
->dma
[1]);
227 lcdc_write(sdev
, LDSM1R
, 0);
229 /* Word and long word swap. */
230 switch (format
->fourcc
) {
231 case DRM_FORMAT_RGB565
:
232 case DRM_FORMAT_NV21
:
233 case DRM_FORMAT_NV61
:
234 case DRM_FORMAT_NV42
:
235 value
= LDDDSR_LS
| LDDDSR_WS
;
237 case DRM_FORMAT_RGB888
:
238 case DRM_FORMAT_NV12
:
239 case DRM_FORMAT_NV16
:
240 case DRM_FORMAT_NV24
:
241 value
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
243 case DRM_FORMAT_ARGB8888
:
248 lcdc_write(sdev
, LDDDSR
, value
);
251 drm_for_each_legacy_plane(plane
, dev
) {
252 if (plane
->crtc
== crtc
)
253 shmob_drm_plane_setup(plane
);
256 /* Enable the display output. */
257 lcdc_write(sdev
, LDCNT1R
, LDCNT1R_DE
);
259 shmob_drm_crtc_start_stop(scrtc
, true);
261 scrtc
->started
= true;
264 static void shmob_drm_crtc_stop(struct shmob_drm_crtc
*scrtc
)
266 struct drm_crtc
*crtc
= &scrtc
->crtc
;
267 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
272 /* Disable the MERAM cache. */
274 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
279 shmob_drm_crtc_start_stop(scrtc
, false);
281 /* Disable the display output. */
282 lcdc_write(sdev
, LDCNT1R
, 0);
285 shmob_drm_clk_off(sdev
);
287 scrtc
->started
= false;
290 void shmob_drm_crtc_suspend(struct shmob_drm_crtc
*scrtc
)
292 shmob_drm_crtc_stop(scrtc
);
295 void shmob_drm_crtc_resume(struct shmob_drm_crtc
*scrtc
)
297 if (scrtc
->dpms
!= DRM_MODE_DPMS_ON
)
300 shmob_drm_crtc_start(scrtc
);
303 static void shmob_drm_crtc_compute_base(struct shmob_drm_crtc
*scrtc
,
306 struct drm_crtc
*crtc
= &scrtc
->crtc
;
307 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
308 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
309 struct drm_gem_cma_object
*gem
;
312 bpp
= scrtc
->format
->yuv
? 8 : scrtc
->format
->bpp
;
313 gem
= drm_fb_cma_get_gem_obj(fb
, 0);
314 scrtc
->dma
[0] = gem
->paddr
+ fb
->offsets
[0]
315 + y
* fb
->pitches
[0] + x
* bpp
/ 8;
317 if (scrtc
->format
->yuv
) {
318 bpp
= scrtc
->format
->bpp
- 8;
319 gem
= drm_fb_cma_get_gem_obj(fb
, 1);
320 scrtc
->dma
[1] = gem
->paddr
+ fb
->offsets
[1]
321 + y
/ (bpp
== 4 ? 2 : 1) * fb
->pitches
[1]
322 + x
* (bpp
== 16 ? 2 : 1);
326 sh_mobile_meram_cache_update(sdev
->meram
, scrtc
->cache
,
327 scrtc
->dma
[0], scrtc
->dma
[1],
328 &scrtc
->dma
[0], &scrtc
->dma
[1]);
331 static void shmob_drm_crtc_update_base(struct shmob_drm_crtc
*scrtc
)
333 struct drm_crtc
*crtc
= &scrtc
->crtc
;
334 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
336 shmob_drm_crtc_compute_base(scrtc
, crtc
->x
, crtc
->y
);
338 lcdc_write_mirror(sdev
, LDSA1R
, scrtc
->dma
[0]);
339 if (scrtc
->format
->yuv
)
340 lcdc_write_mirror(sdev
, LDSA2R
, scrtc
->dma
[1]);
342 lcdc_write(sdev
, LDRCNTR
, lcdc_read(sdev
, LDRCNTR
) ^ LDRCNTR_MRS
);
345 #define to_shmob_crtc(c) container_of(c, struct shmob_drm_crtc, crtc)
347 static void shmob_drm_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
349 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
351 if (scrtc
->dpms
== mode
)
354 if (mode
== DRM_MODE_DPMS_ON
)
355 shmob_drm_crtc_start(scrtc
);
357 shmob_drm_crtc_stop(scrtc
);
362 static bool shmob_drm_crtc_mode_fixup(struct drm_crtc
*crtc
,
363 const struct drm_display_mode
*mode
,
364 struct drm_display_mode
*adjusted_mode
)
369 static void shmob_drm_crtc_mode_prepare(struct drm_crtc
*crtc
)
371 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
374 static int shmob_drm_crtc_mode_set(struct drm_crtc
*crtc
,
375 struct drm_display_mode
*mode
,
376 struct drm_display_mode
*adjusted_mode
,
378 struct drm_framebuffer
*old_fb
)
380 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
381 struct shmob_drm_device
*sdev
= crtc
->dev
->dev_private
;
382 const struct sh_mobile_meram_cfg
*mdata
= sdev
->pdata
->meram
;
383 const struct shmob_drm_format_info
*format
;
386 format
= shmob_drm_format_info(crtc
->primary
->fb
->pixel_format
);
387 if (format
== NULL
) {
388 dev_dbg(sdev
->dev
, "mode_set: unsupported format %08x\n",
389 crtc
->primary
->fb
->pixel_format
);
393 scrtc
->format
= format
;
394 scrtc
->line_size
= crtc
->primary
->fb
->pitches
[0];
397 /* Enable MERAM cache if configured. We need to de-init
398 * configured ICBs before we can re-initialize them.
401 sh_mobile_meram_cache_free(sdev
->meram
, scrtc
->cache
);
405 cache
= sh_mobile_meram_cache_alloc(sdev
->meram
, mdata
,
406 crtc
->primary
->fb
->pitches
[0],
407 adjusted_mode
->vdisplay
,
411 scrtc
->cache
= cache
;
414 shmob_drm_crtc_compute_base(scrtc
, x
, y
);
419 static void shmob_drm_crtc_mode_commit(struct drm_crtc
*crtc
)
421 shmob_drm_crtc_dpms(crtc
, DRM_MODE_DPMS_ON
);
424 static int shmob_drm_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
425 struct drm_framebuffer
*old_fb
)
427 shmob_drm_crtc_update_base(to_shmob_crtc(crtc
));
432 static const struct drm_crtc_helper_funcs crtc_helper_funcs
= {
433 .dpms
= shmob_drm_crtc_dpms
,
434 .mode_fixup
= shmob_drm_crtc_mode_fixup
,
435 .prepare
= shmob_drm_crtc_mode_prepare
,
436 .commit
= shmob_drm_crtc_mode_commit
,
437 .mode_set
= shmob_drm_crtc_mode_set
,
438 .mode_set_base
= shmob_drm_crtc_mode_set_base
,
441 void shmob_drm_crtc_cancel_page_flip(struct shmob_drm_crtc
*scrtc
,
442 struct drm_file
*file
)
444 struct drm_pending_vblank_event
*event
;
445 struct drm_device
*dev
= scrtc
->crtc
.dev
;
448 /* Destroy the pending vertical blanking event associated with the
449 * pending page flip, if any, and disable vertical blanking interrupts.
451 spin_lock_irqsave(&dev
->event_lock
, flags
);
452 event
= scrtc
->event
;
453 if (event
&& event
->base
.file_priv
== file
) {
455 event
->base
.destroy(&event
->base
);
456 drm_vblank_put(dev
, 0);
458 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
461 void shmob_drm_crtc_finish_page_flip(struct shmob_drm_crtc
*scrtc
)
463 struct drm_pending_vblank_event
*event
;
464 struct drm_device
*dev
= scrtc
->crtc
.dev
;
467 spin_lock_irqsave(&dev
->event_lock
, flags
);
468 event
= scrtc
->event
;
471 drm_send_vblank_event(dev
, 0, event
);
472 drm_vblank_put(dev
, 0);
474 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
477 static int shmob_drm_crtc_page_flip(struct drm_crtc
*crtc
,
478 struct drm_framebuffer
*fb
,
479 struct drm_pending_vblank_event
*event
,
480 uint32_t page_flip_flags
)
482 struct shmob_drm_crtc
*scrtc
= to_shmob_crtc(crtc
);
483 struct drm_device
*dev
= scrtc
->crtc
.dev
;
486 spin_lock_irqsave(&dev
->event_lock
, flags
);
487 if (scrtc
->event
!= NULL
) {
488 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
491 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
493 crtc
->primary
->fb
= fb
;
494 shmob_drm_crtc_update_base(scrtc
);
498 drm_vblank_get(dev
, 0);
499 spin_lock_irqsave(&dev
->event_lock
, flags
);
500 scrtc
->event
= event
;
501 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
507 static const struct drm_crtc_funcs crtc_funcs
= {
508 .destroy
= drm_crtc_cleanup
,
509 .set_config
= drm_crtc_helper_set_config
,
510 .page_flip
= shmob_drm_crtc_page_flip
,
513 int shmob_drm_crtc_create(struct shmob_drm_device
*sdev
)
515 struct drm_crtc
*crtc
= &sdev
->crtc
.crtc
;
518 sdev
->crtc
.dpms
= DRM_MODE_DPMS_OFF
;
520 ret
= drm_crtc_init(sdev
->ddev
, crtc
, &crtc_funcs
);
524 drm_crtc_helper_add(crtc
, &crtc_helper_funcs
);
529 /* -----------------------------------------------------------------------------
533 #define to_shmob_encoder(e) \
534 container_of(e, struct shmob_drm_encoder, encoder)
536 static void shmob_drm_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
538 struct shmob_drm_encoder
*senc
= to_shmob_encoder(encoder
);
539 struct shmob_drm_device
*sdev
= encoder
->dev
->dev_private
;
540 struct shmob_drm_connector
*scon
= &sdev
->connector
;
542 if (senc
->dpms
== mode
)
545 shmob_drm_backlight_dpms(scon
, mode
);
550 static bool shmob_drm_encoder_mode_fixup(struct drm_encoder
*encoder
,
551 const struct drm_display_mode
*mode
,
552 struct drm_display_mode
*adjusted_mode
)
554 struct drm_device
*dev
= encoder
->dev
;
555 struct shmob_drm_device
*sdev
= dev
->dev_private
;
556 struct drm_connector
*connector
= &sdev
->connector
.connector
;
557 const struct drm_display_mode
*panel_mode
;
559 if (list_empty(&connector
->modes
)) {
560 dev_dbg(dev
->dev
, "mode_fixup: empty modes list\n");
564 /* The flat panel mode is fixed, just copy it to the adjusted mode. */
565 panel_mode
= list_first_entry(&connector
->modes
,
566 struct drm_display_mode
, head
);
567 drm_mode_copy(adjusted_mode
, panel_mode
);
572 static void shmob_drm_encoder_mode_prepare(struct drm_encoder
*encoder
)
574 /* No-op, everything is handled in the CRTC code. */
577 static void shmob_drm_encoder_mode_set(struct drm_encoder
*encoder
,
578 struct drm_display_mode
*mode
,
579 struct drm_display_mode
*adjusted_mode
)
581 /* No-op, everything is handled in the CRTC code. */
584 static void shmob_drm_encoder_mode_commit(struct drm_encoder
*encoder
)
586 /* No-op, everything is handled in the CRTC code. */
589 static const struct drm_encoder_helper_funcs encoder_helper_funcs
= {
590 .dpms
= shmob_drm_encoder_dpms
,
591 .mode_fixup
= shmob_drm_encoder_mode_fixup
,
592 .prepare
= shmob_drm_encoder_mode_prepare
,
593 .commit
= shmob_drm_encoder_mode_commit
,
594 .mode_set
= shmob_drm_encoder_mode_set
,
597 static void shmob_drm_encoder_destroy(struct drm_encoder
*encoder
)
599 drm_encoder_cleanup(encoder
);
602 static const struct drm_encoder_funcs encoder_funcs
= {
603 .destroy
= shmob_drm_encoder_destroy
,
606 int shmob_drm_encoder_create(struct shmob_drm_device
*sdev
)
608 struct drm_encoder
*encoder
= &sdev
->encoder
.encoder
;
611 sdev
->encoder
.dpms
= DRM_MODE_DPMS_OFF
;
613 encoder
->possible_crtcs
= 1;
615 ret
= drm_encoder_init(sdev
->ddev
, encoder
, &encoder_funcs
,
616 DRM_MODE_ENCODER_LVDS
, NULL
);
620 drm_encoder_helper_add(encoder
, &encoder_helper_funcs
);
625 void shmob_drm_crtc_enable_vblank(struct shmob_drm_device
*sdev
, bool enable
)
630 /* Be careful not to acknowledge any pending interrupt. */
631 spin_lock_irqsave(&sdev
->irq_lock
, flags
);
632 ldintr
= lcdc_read(sdev
, LDINTR
) | LDINTR_STATUS_MASK
;
634 ldintr
|= LDINTR_VEE
;
636 ldintr
&= ~LDINTR_VEE
;
637 lcdc_write(sdev
, LDINTR
, ldintr
);
638 spin_unlock_irqrestore(&sdev
->irq_lock
, flags
);
641 /* -----------------------------------------------------------------------------
645 #define to_shmob_connector(c) \
646 container_of(c, struct shmob_drm_connector, connector)
648 static int shmob_drm_connector_get_modes(struct drm_connector
*connector
)
650 struct shmob_drm_device
*sdev
= connector
->dev
->dev_private
;
651 struct drm_display_mode
*mode
;
653 mode
= drm_mode_create(connector
->dev
);
657 mode
->type
= DRM_MODE_TYPE_PREFERRED
| DRM_MODE_TYPE_DRIVER
;
658 mode
->clock
= sdev
->pdata
->panel
.mode
.clock
;
659 mode
->hdisplay
= sdev
->pdata
->panel
.mode
.hdisplay
;
660 mode
->hsync_start
= sdev
->pdata
->panel
.mode
.hsync_start
;
661 mode
->hsync_end
= sdev
->pdata
->panel
.mode
.hsync_end
;
662 mode
->htotal
= sdev
->pdata
->panel
.mode
.htotal
;
663 mode
->vdisplay
= sdev
->pdata
->panel
.mode
.vdisplay
;
664 mode
->vsync_start
= sdev
->pdata
->panel
.mode
.vsync_start
;
665 mode
->vsync_end
= sdev
->pdata
->panel
.mode
.vsync_end
;
666 mode
->vtotal
= sdev
->pdata
->panel
.mode
.vtotal
;
667 mode
->flags
= sdev
->pdata
->panel
.mode
.flags
;
669 drm_mode_set_name(mode
);
670 drm_mode_probed_add(connector
, mode
);
672 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
673 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
678 static struct drm_encoder
*
679 shmob_drm_connector_best_encoder(struct drm_connector
*connector
)
681 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
683 return scon
->encoder
;
686 static const struct drm_connector_helper_funcs connector_helper_funcs
= {
687 .get_modes
= shmob_drm_connector_get_modes
,
688 .best_encoder
= shmob_drm_connector_best_encoder
,
691 static void shmob_drm_connector_destroy(struct drm_connector
*connector
)
693 struct shmob_drm_connector
*scon
= to_shmob_connector(connector
);
695 shmob_drm_backlight_exit(scon
);
696 drm_connector_unregister(connector
);
697 drm_connector_cleanup(connector
);
700 static enum drm_connector_status
701 shmob_drm_connector_detect(struct drm_connector
*connector
, bool force
)
703 return connector_status_connected
;
706 static const struct drm_connector_funcs connector_funcs
= {
707 .dpms
= drm_helper_connector_dpms
,
708 .detect
= shmob_drm_connector_detect
,
709 .fill_modes
= drm_helper_probe_single_connector_modes
,
710 .destroy
= shmob_drm_connector_destroy
,
713 int shmob_drm_connector_create(struct shmob_drm_device
*sdev
,
714 struct drm_encoder
*encoder
)
716 struct drm_connector
*connector
= &sdev
->connector
.connector
;
719 sdev
->connector
.encoder
= encoder
;
721 connector
->display_info
.width_mm
= sdev
->pdata
->panel
.width_mm
;
722 connector
->display_info
.height_mm
= sdev
->pdata
->panel
.height_mm
;
724 ret
= drm_connector_init(sdev
->ddev
, connector
, &connector_funcs
,
725 DRM_MODE_CONNECTOR_LVDS
);
729 drm_connector_helper_add(connector
, &connector_helper_funcs
);
730 ret
= drm_connector_register(connector
);
734 ret
= shmob_drm_backlight_init(&sdev
->connector
);
738 ret
= drm_mode_connector_attach_encoder(connector
, encoder
);
742 drm_helper_connector_dpms(connector
, DRM_MODE_DPMS_OFF
);
743 drm_object_property_set_value(&connector
->base
,
744 sdev
->ddev
->mode_config
.dpms_property
, DRM_MODE_DPMS_OFF
);
749 shmob_drm_backlight_exit(&sdev
->connector
);
751 drm_connector_unregister(connector
);
753 drm_connector_cleanup(connector
);