include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / staging / gma500 / framebuffer.c
blobebfde13ec18fe7a39bbbad173a913297e07cbd6d
1 /**************************************************************************
2 * Copyright (c) 2007-2011, Intel Corporation.
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 **************************************************************************/
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/mm.h>
25 #include <linux/tty.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
28 #include <linux/fb.h>
29 #include <linux/init.h>
30 #include <linux/console.h>
32 #include <drm/drmP.h>
33 #include <drm/drm.h>
34 #include <drm/drm_crtc.h>
36 #include "psb_drv.h"
37 #include "psb_intel_reg.h"
38 #include "psb_intel_drv.h"
39 #include "framebuffer.h"
41 #include "mdfld_output.h"
43 static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb);
44 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
45 struct drm_file *file_priv,
46 unsigned int *handle);
48 static const struct drm_framebuffer_funcs psb_fb_funcs = {
49 .destroy = psb_user_framebuffer_destroy,
50 .create_handle = psb_user_framebuffer_create_handle,
53 #define CMAP_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16)
55 static int psbfb_setcolreg(unsigned regno, unsigned red, unsigned green,
56 unsigned blue, unsigned transp,
57 struct fb_info *info)
59 struct psb_fbdev *fbdev = info->par;
60 struct drm_framebuffer *fb = fbdev->psb_fb_helper.fb;
61 uint32_t v;
63 if (!fb)
64 return -ENOMEM;
66 if (regno > 255)
67 return 1;
69 red = CMAP_TOHW(red, info->var.red.length);
70 blue = CMAP_TOHW(blue, info->var.blue.length);
71 green = CMAP_TOHW(green, info->var.green.length);
72 transp = CMAP_TOHW(transp, info->var.transp.length);
74 v = (red << info->var.red.offset) |
75 (green << info->var.green.offset) |
76 (blue << info->var.blue.offset) |
77 (transp << info->var.transp.offset);
79 if (regno < 16) {
80 switch (fb->bits_per_pixel) {
81 case 16:
82 ((uint32_t *) info->pseudo_palette)[regno] = v;
83 break;
84 case 24:
85 case 32:
86 ((uint32_t *) info->pseudo_palette)[regno] = v;
87 break;
91 return 0;
95 void psbfb_suspend(struct drm_device *dev)
97 struct drm_framebuffer *fb = 0;
98 struct psb_framebuffer *psbfb = to_psb_fb(fb);
100 console_lock();
101 mutex_lock(&dev->mode_config.mutex);
102 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
103 struct fb_info *info = psbfb->fbdev;
104 fb_set_suspend(info, 1);
105 drm_fb_helper_blank(FB_BLANK_POWERDOWN, info);
107 mutex_unlock(&dev->mode_config.mutex);
108 console_unlock();
111 void psbfb_resume(struct drm_device *dev)
113 struct drm_framebuffer *fb = 0;
114 struct psb_framebuffer *psbfb = to_psb_fb(fb);
116 console_lock();
117 mutex_lock(&dev->mode_config.mutex);
118 list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
119 struct fb_info *info = psbfb->fbdev;
120 fb_set_suspend(info, 0);
121 drm_fb_helper_blank(FB_BLANK_UNBLANK, info);
123 mutex_unlock(&dev->mode_config.mutex);
124 console_unlock();
125 drm_helper_disable_unused_functions(dev);
128 static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
130 struct psb_framebuffer *psbfb = vma->vm_private_data;
131 struct drm_device *dev = psbfb->base.dev;
132 struct drm_psb_private *dev_priv = dev->dev_private;
133 int page_num;
134 int i;
135 unsigned long address;
136 int ret;
137 unsigned long pfn;
138 /* FIXME: assumes fb at stolen base which may not be true */
139 unsigned long phys_addr = (unsigned long)dev_priv->stolen_base;
141 page_num = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
142 address = (unsigned long)vmf->virtual_address;
144 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
146 for (i = 0; i < page_num; i++) {
147 pfn = (phys_addr >> PAGE_SHIFT);
149 ret = vm_insert_mixed(vma, address, pfn);
150 if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
151 break;
152 else if (unlikely(ret != 0)) {
153 ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
154 return ret;
156 address += PAGE_SIZE;
157 phys_addr += PAGE_SIZE;
159 return VM_FAULT_NOPAGE;
162 static void psbfb_vm_open(struct vm_area_struct *vma)
166 static void psbfb_vm_close(struct vm_area_struct *vma)
170 static struct vm_operations_struct psbfb_vm_ops = {
171 .fault = psbfb_vm_fault,
172 .open = psbfb_vm_open,
173 .close = psbfb_vm_close
176 static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
178 struct psb_fbdev *fbdev = info->par;
179 struct psb_framebuffer *psbfb = &fbdev->pfb;
181 if (vma->vm_pgoff != 0)
182 return -EINVAL;
183 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
184 return -EINVAL;
186 if (!psbfb->addr_space)
187 psbfb->addr_space = vma->vm_file->f_mapping;
189 * If this is a GEM object then info->screen_base is the virtual
190 * kernel remapping of the object. FIXME: Review if this is
191 * suitable for our mmap work
193 vma->vm_ops = &psbfb_vm_ops;
194 vma->vm_private_data = (void *)psbfb;
195 vma->vm_flags |= VM_RESERVED | VM_IO |
196 VM_MIXEDMAP | VM_DONTEXPAND;
197 return 0;
200 static int psbfb_ioctl(struct fb_info *info, unsigned int cmd,
201 unsigned long arg)
203 return -ENOTTY;
206 static struct fb_ops psbfb_ops = {
207 .owner = THIS_MODULE,
208 .fb_check_var = drm_fb_helper_check_var,
209 .fb_set_par = drm_fb_helper_set_par,
210 .fb_blank = drm_fb_helper_blank,
211 .fb_setcolreg = psbfb_setcolreg,
212 .fb_fillrect = cfb_fillrect,
213 .fb_copyarea = psbfb_copyarea,
214 .fb_imageblit = cfb_imageblit,
215 .fb_mmap = psbfb_mmap,
216 .fb_sync = psbfb_sync,
217 .fb_ioctl = psbfb_ioctl,
220 static struct fb_ops psbfb_unaccel_ops = {
221 .owner = THIS_MODULE,
222 .fb_check_var = drm_fb_helper_check_var,
223 .fb_set_par = drm_fb_helper_set_par,
224 .fb_blank = drm_fb_helper_blank,
225 .fb_setcolreg = psbfb_setcolreg,
226 .fb_fillrect = cfb_fillrect,
227 .fb_copyarea = cfb_copyarea,
228 .fb_imageblit = cfb_imageblit,
229 .fb_mmap = psbfb_mmap,
230 .fb_ioctl = psbfb_ioctl,
234 * psb_framebuffer_init - initialize a framebuffer
235 * @dev: our DRM device
236 * @fb: framebuffer to set up
237 * @mode_cmd: mode description
238 * @gt: backing object
240 * Configure and fill in the boilerplate for our frame buffer. Return
241 * 0 on success or an error code if we fail.
243 static int psb_framebuffer_init(struct drm_device *dev,
244 struct psb_framebuffer *fb,
245 struct drm_mode_fb_cmd *mode_cmd,
246 struct gtt_range *gt)
248 int ret;
250 if (mode_cmd->pitch & 63)
251 return -EINVAL;
252 switch (mode_cmd->bpp) {
253 case 8:
254 case 16:
255 case 24:
256 case 32:
257 break;
258 default:
259 return -EINVAL;
261 ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs);
262 if (ret) {
263 dev_err(dev->dev, "framebuffer init failed: %d\n", ret);
264 return ret;
266 drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
267 fb->gtt = gt;
268 return 0;
272 * psb_framebuffer_create - create a framebuffer backed by gt
273 * @dev: our DRM device
274 * @mode_cmd: the description of the requested mode
275 * @gt: the backing object
277 * Create a framebuffer object backed by the gt, and fill in the
278 * boilerplate required
280 * TODO: review object references
283 static struct drm_framebuffer *psb_framebuffer_create
284 (struct drm_device *dev,
285 struct drm_mode_fb_cmd *mode_cmd,
286 struct gtt_range *gt)
288 struct psb_framebuffer *fb;
289 int ret;
291 fb = kzalloc(sizeof(*fb), GFP_KERNEL);
292 if (!fb)
293 return ERR_PTR(-ENOMEM);
295 ret = psb_framebuffer_init(dev, fb, mode_cmd, gt);
296 if (ret) {
297 kfree(fb);
298 return ERR_PTR(ret);
300 return &fb->base;
304 * psbfb_alloc - allocate frame buffer memory
305 * @dev: the DRM device
306 * @aligned_size: space needed
308 * Allocate the frame buffer. In the usual case we get a GTT range that
309 * is stolen memory backed and life is simple. If there isn't sufficient
310 * stolen memory or the system has no stolen memory we allocate a range
311 * and back it with a GEM object.
313 * In this case the GEM object has no handle.
315 * FIXME: console speed up - allocate twice the space if room and use
316 * hardware scrolling for acceleration.
318 static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size)
320 struct gtt_range *backing;
321 /* Begin by trying to use stolen memory backing */
322 backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1);
323 if (backing) {
324 if (drm_gem_private_object_init(dev,
325 &backing->gem, aligned_size) == 0)
326 return backing;
327 psb_gtt_free_range(dev, backing);
329 /* Next try using GEM host memory */
330 backing = psb_gtt_alloc_range(dev, aligned_size, "fb(gem)", 0);
331 if (backing == NULL)
332 return NULL;
334 /* Now back it with an object */
335 if (drm_gem_object_init(dev, &backing->gem, aligned_size) != 0) {
336 psb_gtt_free_range(dev, backing);
337 return NULL;
339 return backing;
343 * psbfb_create - create a framebuffer
344 * @fbdev: the framebuffer device
345 * @sizes: specification of the layout
347 * Create a framebuffer to the specifications provided
349 static int psbfb_create(struct psb_fbdev *fbdev,
350 struct drm_fb_helper_surface_size *sizes)
352 struct drm_device *dev = fbdev->psb_fb_helper.dev;
353 struct drm_psb_private *dev_priv = dev->dev_private;
354 struct fb_info *info;
355 struct drm_framebuffer *fb;
356 struct psb_framebuffer *psbfb = &fbdev->pfb;
357 struct drm_mode_fb_cmd mode_cmd;
358 struct device *device = &dev->pdev->dev;
359 int size;
360 int ret;
361 struct gtt_range *backing;
363 mode_cmd.width = sizes->surface_width;
364 mode_cmd.height = sizes->surface_height;
365 mode_cmd.bpp = sizes->surface_bpp;
367 /* No 24bit packed */
368 if (mode_cmd.bpp == 24)
369 mode_cmd.bpp = 32;
371 /* HW requires pitch to be 64 byte aligned */
372 mode_cmd.pitch = ALIGN(mode_cmd.width * ((mode_cmd.bpp + 7) / 8), 64);
373 mode_cmd.depth = sizes->surface_depth;
375 size = mode_cmd.pitch * mode_cmd.height;
376 size = ALIGN(size, PAGE_SIZE);
378 /* Allocate the framebuffer in the GTT with stolen page backing */
379 backing = psbfb_alloc(dev, size);
380 if (backing == NULL)
381 return -ENOMEM;
383 mutex_lock(&dev->struct_mutex);
385 info = framebuffer_alloc(0, device);
386 if (!info) {
387 ret = -ENOMEM;
388 goto out_err1;
390 info->par = fbdev;
392 ret = psb_framebuffer_init(dev, psbfb, &mode_cmd, backing);
393 if (ret)
394 goto out_unref;
396 fb = &psbfb->base;
397 psbfb->fbdev = info;
399 fbdev->psb_fb_helper.fb = fb;
400 fbdev->psb_fb_helper.fbdev = info;
402 strcpy(info->fix.id, "psbfb");
404 info->flags = FBINFO_DEFAULT;
405 /* No 2D engine */
406 if (!dev_priv->ops->accel_2d)
407 info->fbops = &psbfb_unaccel_ops;
408 else
409 info->fbops = &psbfb_ops;
411 ret = fb_alloc_cmap(&info->cmap, 256, 0);
412 if (ret) {
413 ret = -ENOMEM;
414 goto out_unref;
417 info->fix.smem_start = dev->mode_config.fb_base;
418 info->fix.smem_len = size;
420 if (backing->stolen) {
421 /* Accessed stolen memory directly */
422 info->screen_base = (char *)dev_priv->vram_addr +
423 backing->offset;
424 } else {
425 /* Pin the pages into the GTT and create a mapping to them */
426 psb_gtt_pin(backing);
427 info->screen_base = vm_map_ram(backing->pages, backing->npage,
428 -1, PAGE_KERNEL);
429 if (info->screen_base == NULL) {
430 psb_gtt_unpin(backing);
431 ret = -ENOMEM;
432 goto out_unref;
434 psbfb->vm_map = 1;
436 info->screen_size = size;
438 if (dev_priv->gtt.stolen_size) {
439 info->apertures = alloc_apertures(1);
440 if (!info->apertures) {
441 ret = -ENOMEM;
442 goto out_unref;
444 info->apertures->ranges[0].base = dev->mode_config.fb_base;
445 info->apertures->ranges[0].size = dev_priv->gtt.stolen_size;
448 drm_fb_helper_fill_fix(info, fb->pitch, fb->depth);
449 drm_fb_helper_fill_var(info, &fbdev->psb_fb_helper,
450 sizes->fb_width, sizes->fb_height);
452 info->fix.mmio_start = pci_resource_start(dev->pdev, 0);
453 info->fix.mmio_len = pci_resource_len(dev->pdev, 0);
455 info->pixmap.size = 64 * 1024;
456 info->pixmap.buf_align = 8;
457 info->pixmap.access_align = 32;
458 info->pixmap.flags = FB_PIXMAP_SYSTEM;
459 info->pixmap.scan_align = 1;
461 dev_info(dev->dev, "allocated %dx%d fb\n",
462 psbfb->base.width, psbfb->base.height);
464 mutex_unlock(&dev->struct_mutex);
465 return 0;
466 out_unref:
467 if (backing->stolen)
468 psb_gtt_free_range(dev, backing);
469 else {
470 if (psbfb->vm_map)
471 vm_unmap_ram(info->screen_base, backing->npage);
472 drm_gem_object_unreference(&backing->gem);
474 out_err1:
475 mutex_unlock(&dev->struct_mutex);
476 psb_gtt_free_range(dev, backing);
477 return ret;
481 * psb_user_framebuffer_create - create framebuffer
482 * @dev: our DRM device
483 * @filp: client file
484 * @cmd: mode request
486 * Create a new framebuffer backed by a userspace GEM object
488 static struct drm_framebuffer *psb_user_framebuffer_create
489 (struct drm_device *dev, struct drm_file *filp,
490 struct drm_mode_fb_cmd *cmd)
492 struct gtt_range *r;
493 struct drm_gem_object *obj;
496 * Find the GEM object and thus the gtt range object that is
497 * to back this space
499 obj = drm_gem_object_lookup(dev, filp, cmd->handle);
500 if (obj == NULL)
501 return ERR_PTR(-ENOENT);
503 /* Let the core code do all the work */
504 r = container_of(obj, struct gtt_range, gem);
505 return psb_framebuffer_create(dev, cmd, r);
508 static void psbfb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
509 u16 blue, int regno)
513 static void psbfb_gamma_get(struct drm_crtc *crtc, u16 *red,
514 u16 *green, u16 *blue, int regno)
518 static int psbfb_probe(struct drm_fb_helper *helper,
519 struct drm_fb_helper_surface_size *sizes)
521 struct psb_fbdev *psb_fbdev = (struct psb_fbdev *)helper;
522 int new_fb = 0;
523 int ret;
525 if (!helper->fb) {
526 ret = psbfb_create(psb_fbdev, sizes);
527 if (ret)
528 return ret;
529 new_fb = 1;
531 return new_fb;
534 struct drm_fb_helper_funcs psb_fb_helper_funcs = {
535 .gamma_set = psbfb_gamma_set,
536 .gamma_get = psbfb_gamma_get,
537 .fb_probe = psbfb_probe,
540 int psb_fbdev_destroy(struct drm_device *dev, struct psb_fbdev *fbdev)
542 struct fb_info *info;
543 struct psb_framebuffer *psbfb = &fbdev->pfb;
545 if (fbdev->psb_fb_helper.fbdev) {
546 info = fbdev->psb_fb_helper.fbdev;
548 /* If this is our base framebuffer then kill any virtual map
549 for the framebuffer layer and unpin it */
550 if (psbfb->vm_map) {
551 vm_unmap_ram(info->screen_base, psbfb->gtt->npage);
552 psb_gtt_unpin(psbfb->gtt);
554 unregister_framebuffer(info);
555 if (info->cmap.len)
556 fb_dealloc_cmap(&info->cmap);
557 framebuffer_release(info);
559 drm_fb_helper_fini(&fbdev->psb_fb_helper);
560 drm_framebuffer_cleanup(&psbfb->base);
562 if (psbfb->gtt)
563 drm_gem_object_unreference(&psbfb->gtt->gem);
564 return 0;
567 int psb_fbdev_init(struct drm_device *dev)
569 struct psb_fbdev *fbdev;
570 struct drm_psb_private *dev_priv = dev->dev_private;
572 fbdev = kzalloc(sizeof(struct psb_fbdev), GFP_KERNEL);
573 if (!fbdev) {
574 dev_err(dev->dev, "no memory\n");
575 return -ENOMEM;
578 dev_priv->fbdev = fbdev;
579 fbdev->psb_fb_helper.funcs = &psb_fb_helper_funcs;
581 drm_fb_helper_init(dev, &fbdev->psb_fb_helper, dev_priv->ops->crtcs,
582 INTELFB_CONN_LIMIT);
584 drm_fb_helper_single_add_all_connectors(&fbdev->psb_fb_helper);
585 drm_fb_helper_initial_config(&fbdev->psb_fb_helper, 32);
586 return 0;
589 void psb_fbdev_fini(struct drm_device *dev)
591 struct drm_psb_private *dev_priv = dev->dev_private;
593 if (!dev_priv->fbdev)
594 return;
596 psb_fbdev_destroy(dev, dev_priv->fbdev);
597 kfree(dev_priv->fbdev);
598 dev_priv->fbdev = NULL;
601 static void psbfb_output_poll_changed(struct drm_device *dev)
603 struct drm_psb_private *dev_priv = dev->dev_private;
604 struct psb_fbdev *fbdev = (struct psb_fbdev *)dev_priv->fbdev;
605 drm_fb_helper_hotplug_event(&fbdev->psb_fb_helper);
609 * psb_user_framebuffer_create_handle - add hamdle to a framebuffer
610 * @fb: framebuffer
611 * @file_priv: our DRM file
612 * @handle: returned handle
614 * Our framebuffer object is a GTT range which also contains a GEM
615 * object. We need to turn it into a handle for userspace. GEM will do
616 * the work for us
618 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
619 struct drm_file *file_priv,
620 unsigned int *handle)
622 struct psb_framebuffer *psbfb = to_psb_fb(fb);
623 struct gtt_range *r = psbfb->gtt;
624 return drm_gem_handle_create(file_priv, &r->gem, handle);
628 * psb_user_framebuffer_destroy - destruct user created fb
629 * @fb: framebuffer
631 * User framebuffers are backed by GEM objects so all we have to do is
632 * clean up a bit and drop the reference, GEM will handle the fallout
634 static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb)
636 struct psb_framebuffer *psbfb = to_psb_fb(fb);
637 struct gtt_range *r = psbfb->gtt;
638 struct drm_device *dev = fb->dev;
639 struct drm_psb_private *dev_priv = dev->dev_private;
640 struct psb_fbdev *fbdev = dev_priv->fbdev;
641 struct drm_crtc *crtc;
642 int reset = 0;
644 /* Should never get stolen memory for a user fb */
645 WARN_ON(r->stolen);
647 /* Check if we are erroneously live */
648 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
649 if (crtc->fb == fb)
650 reset = 1;
652 if (reset)
654 * Now force a sane response before we permit the DRM CRTC
655 * layer to do stupid things like blank the display. Instead
656 * we reset this framebuffer as if the user had forced a reset.
657 * We must do this before the cleanup so that the DRM layer
658 * doesn't get a chance to stick its oar in where it isn't
659 * wanted.
661 drm_fb_helper_restore_fbdev_mode(&fbdev->psb_fb_helper);
663 /* Let DRM do its clean up */
664 drm_framebuffer_cleanup(fb);
665 /* We are no longer using the resource in GEM */
666 drm_gem_object_unreference_unlocked(&r->gem);
667 kfree(fb);
670 static const struct drm_mode_config_funcs psb_mode_funcs = {
671 .fb_create = psb_user_framebuffer_create,
672 .output_poll_changed = psbfb_output_poll_changed,
675 static int psb_create_backlight_property(struct drm_device *dev)
677 struct drm_psb_private *dev_priv = dev->dev_private;
678 struct drm_property *backlight;
680 if (dev_priv->backlight_property)
681 return 0;
683 backlight = drm_property_create(dev, DRM_MODE_PROP_RANGE,
684 "backlight", 2);
685 backlight->values[0] = 0;
686 backlight->values[1] = 100;
688 dev_priv->backlight_property = backlight;
690 return 0;
693 static void psb_setup_outputs(struct drm_device *dev)
695 struct drm_psb_private *dev_priv = dev->dev_private;
696 struct drm_connector *connector;
698 drm_mode_create_scaling_mode_property(dev);
699 psb_create_backlight_property(dev);
701 dev_priv->ops->output_init(dev);
703 list_for_each_entry(connector, &dev->mode_config.connector_list,
704 head) {
705 struct psb_intel_output *psb_intel_output =
706 to_psb_intel_output(connector);
707 struct drm_encoder *encoder = &psb_intel_output->enc;
708 int crtc_mask = 0, clone_mask = 0;
710 /* valid crtcs */
711 switch (psb_intel_output->type) {
712 case INTEL_OUTPUT_ANALOG:
713 crtc_mask = (1 << 0);
714 clone_mask = (1 << INTEL_OUTPUT_ANALOG);
715 break;
716 case INTEL_OUTPUT_SDVO:
717 crtc_mask = ((1 << 0) | (1 << 1));
718 clone_mask = (1 << INTEL_OUTPUT_SDVO);
719 break;
720 case INTEL_OUTPUT_LVDS:
721 if (IS_MRST(dev))
722 crtc_mask = (1 << 0);
723 else
724 crtc_mask = (1 << 1);
725 clone_mask = (1 << INTEL_OUTPUT_LVDS);
726 break;
727 case INTEL_OUTPUT_MIPI:
728 crtc_mask = (1 << 0);
729 clone_mask = (1 << INTEL_OUTPUT_MIPI);
730 break;
731 case INTEL_OUTPUT_MIPI2:
732 crtc_mask = (1 << 2);
733 clone_mask = (1 << INTEL_OUTPUT_MIPI2);
734 break;
735 case INTEL_OUTPUT_HDMI:
736 if (IS_MFLD(dev))
737 crtc_mask = (1 << 1);
738 else /* FIXME: review Oaktrail */
739 crtc_mask = (1 << 0); /* Cedarview */
740 clone_mask = (1 << INTEL_OUTPUT_HDMI);
741 break;
743 encoder->possible_crtcs = crtc_mask;
744 encoder->possible_clones =
745 psb_intel_connector_clones(dev, clone_mask);
749 void psb_modeset_init(struct drm_device *dev)
751 struct drm_psb_private *dev_priv =
752 (struct drm_psb_private *) dev->dev_private;
753 struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
754 int i;
756 drm_mode_config_init(dev);
758 dev->mode_config.min_width = 0;
759 dev->mode_config.min_height = 0;
761 dev->mode_config.funcs = (void *) &psb_mode_funcs;
763 /* set memory base */
764 /* MRST and PSB should use BAR 2*/
765 pci_read_config_dword(dev->pdev, PSB_BSM, (u32 *)
766 &(dev->mode_config.fb_base));
768 /* num pipes is 2 for PSB but 1 for Mrst */
769 for (i = 0; i < dev_priv->num_pipe; i++)
770 psb_intel_crtc_init(dev, i, mode_dev);
772 dev->mode_config.max_width = 2048;
773 dev->mode_config.max_height = 2048;
775 psb_setup_outputs(dev);
778 void psb_modeset_cleanup(struct drm_device *dev)
780 mutex_lock(&dev->struct_mutex);
782 drm_kms_helper_poll_fini(dev);
783 psb_fbdev_fini(dev);
784 drm_mode_config_cleanup(dev);
786 mutex_unlock(&dev->struct_mutex);