x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / gpu / drm / shmobile / shmob_drm_crtc.c
blob54bad98e9477589742eb21fecb10fd30f560f209
1 /*
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>
17 #include <drm/drmP.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"
33 * TODO: panel support
36 /* -----------------------------------------------------------------------------
37 * Clock management
40 static void shmob_drm_clk_on(struct shmob_drm_device *sdev)
42 if (sdev->clock)
43 clk_enable(sdev->clock);
44 #if 0
45 if (sdev->meram_dev && sdev->meram_dev->pdev)
46 pm_runtime_get_sync(&sdev->meram_dev->pdev->dev);
47 #endif
50 static void shmob_drm_clk_off(struct shmob_drm_device *sdev)
52 #if 0
53 if (sdev->meram_dev && sdev->meram_dev->pdev)
54 pm_runtime_put_sync(&sdev->meram_dev->pdev->dev);
55 #endif
56 if (sdev->clock)
57 clk_disable(sdev->clock);
60 /* -----------------------------------------------------------------------------
61 * CRTC
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;
70 u32 value;
72 value = sdev->ldmt1r
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) {
84 /* Setup SYS bus. */
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;
125 u32 value;
127 value = lcdc_read(sdev, LDCNT2R);
128 if (start)
129 lcdc_write(sdev, LDCNT2R, value | LDCNT2R_DO);
130 else
131 lcdc_write(sdev, LDCNT2R, value & ~LDCNT2R_DO);
133 /* Wait until power is applied/stopped. */
134 while (1) {
135 value = lcdc_read(sdev, LDPMR) & LDPMR_LPS;
136 if ((start && value) || (!start && !value))
137 break;
139 cpu_relax();
142 if (!start) {
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;
163 u32 value;
165 if (scrtc->started)
166 return;
168 format = shmob_drm_format_info(crtc->fb->pixel_format);
169 if (WARN_ON(format == NULL))
170 return;
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
190 * denominator.
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;
197 else
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]);
214 if (format->yuv)
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;
225 break;
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;
231 break;
232 case DRM_FORMAT_ARGB8888:
233 default:
234 value = LDDDSR_LS;
235 break;
237 lcdc_write(sdev, LDDDSR, value);
239 /* Setup planes. */
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;
258 if (!scrtc->started)
259 return;
261 /* Disable the MERAM cache. */
262 if (scrtc->cache) {
263 sh_mobile_meram_cache_free(sdev->meram, scrtc->cache);
264 scrtc->cache = NULL;
267 /* Stop the LCDC. */
268 shmob_drm_crtc_start_stop(scrtc, false);
270 /* Disable the display output. */
271 lcdc_write(sdev, LDCNT1R, 0);
273 /* Stop clocks. */
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)
287 return;
289 shmob_drm_crtc_start(scrtc);
292 static void shmob_drm_crtc_compute_base(struct shmob_drm_crtc *scrtc,
293 int x, int y)
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;
299 unsigned int bpp;
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);
314 if (scrtc->cache)
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)
341 return;
343 if (mode == DRM_MODE_DPMS_ON)
344 shmob_drm_crtc_start(scrtc);
345 else
346 shmob_drm_crtc_stop(scrtc);
348 scrtc->dpms = mode;
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)
355 return true;
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,
366 int x, int y,
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;
373 void *cache;
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);
379 return -EINVAL;
382 scrtc->format = format;
383 scrtc->line_size = crtc->fb->pitches[0];
385 if (sdev->meram) {
386 /* Enable MERAM cache if configured. We need to de-init
387 * configured ICBs before we can re-initialize them.
389 if (scrtc->cache) {
390 sh_mobile_meram_cache_free(sdev->meram, scrtc->cache);
391 scrtc->cache = NULL;
394 cache = sh_mobile_meram_cache_alloc(sdev->meram, mdata,
395 crtc->fb->pitches[0],
396 adjusted_mode->vdisplay,
397 format->meram,
398 &scrtc->line_size);
399 if (!IS_ERR(cache))
400 scrtc->cache = cache;
403 shmob_drm_crtc_compute_base(scrtc, x, y);
405 return 0;
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));
418 return 0;
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;
435 unsigned long flags;
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) {
443 scrtc->event = NULL;
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;
454 unsigned long flags;
456 spin_lock_irqsave(&dev->event_lock, flags);
457 event = scrtc->event;
458 scrtc->event = NULL;
459 if (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;
473 unsigned long flags;
475 spin_lock_irqsave(&dev->event_lock, flags);
476 if (scrtc->event != NULL) {
477 spin_unlock_irqrestore(&dev->event_lock, flags);
478 return -EBUSY;
480 spin_unlock_irqrestore(&dev->event_lock, flags);
482 crtc->fb = fb;
483 shmob_drm_crtc_update_base(scrtc);
485 if (event) {
486 event->pipe = 0;
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);
493 return 0;
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;
505 int ret;
507 sdev->crtc.dpms = DRM_MODE_DPMS_OFF;
509 ret = drm_crtc_init(sdev->ddev, crtc, &crtc_funcs);
510 if (ret < 0)
511 return ret;
513 drm_crtc_helper_add(crtc, &crtc_helper_funcs);
515 return 0;
518 /* -----------------------------------------------------------------------------
519 * Encoder
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)
532 return;
534 shmob_drm_backlight_dpms(scon, mode);
536 senc->dpms = 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");
550 return false;
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);
558 return true;
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;
598 int ret;
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);
606 if (ret < 0)
607 return ret;
609 drm_encoder_helper_add(encoder, &encoder_helper_funcs);
611 return 0;
614 void shmob_drm_crtc_enable_vblank(struct shmob_drm_device *sdev, bool enable)
616 unsigned long flags;
617 u32 ldintr;
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;
622 if (enable)
623 ldintr |= LDINTR_VEE;
624 else
625 ldintr &= ~LDINTR_VEE;
626 lcdc_write(sdev, LDINTR, ldintr);
627 spin_unlock_irqrestore(&sdev->irq_lock, flags);
630 /* -----------------------------------------------------------------------------
631 * Connector
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);
643 if (mode == NULL)
644 return 0;
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;
664 return 1;
667 static int shmob_drm_connector_mode_valid(struct drm_connector *connector,
668 struct drm_display_mode *mode)
670 return MODE_OK;
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;
713 int ret;
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);
722 if (ret < 0)
723 return ret;
725 drm_connector_helper_add(connector, &connector_helper_funcs);
726 ret = drm_sysfs_connector_add(connector);
727 if (ret < 0)
728 goto err_cleanup;
730 ret = shmob_drm_backlight_init(&sdev->connector);
731 if (ret < 0)
732 goto err_sysfs;
734 ret = drm_mode_connector_attach_encoder(connector, encoder);
735 if (ret < 0)
736 goto err_backlight;
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);
744 return 0;
746 err_backlight:
747 shmob_drm_backlight_exit(&sdev->connector);
748 err_sysfs:
749 drm_sysfs_connector_remove(connector);
750 err_cleanup:
751 drm_connector_cleanup(connector);
752 return ret;