drm.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (C) 2012 Avionic Design GmbH
  3. * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/of_address.h>
  11. #include <linux/of_platform.h>
  12. #include <mach/clk.h>
  13. #include <linux/dma-mapping.h>
  14. #include <asm/dma-iommu.h>
  15. #include "drm.h"
  16. #define DRIVER_NAME "tegra"
  17. #define DRIVER_DESC "NVIDIA Tegra graphics"
  18. #define DRIVER_DATE "20120330"
  19. #define DRIVER_MAJOR 0
  20. #define DRIVER_MINOR 0
  21. #define DRIVER_PATCHLEVEL 0
  22. static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
  23. {
  24. struct device *dev = drm->dev;
  25. struct host1x *host1x;
  26. int err;
  27. host1x = dev_get_drvdata(dev);
  28. drm->dev_private = host1x;
  29. host1x->drm = drm;
  30. drm_mode_config_init(drm);
  31. err = host1x_drm_init(host1x, drm);
  32. if (err < 0)
  33. return err;
  34. err = drm_vblank_init(drm, drm->mode_config.num_crtc);
  35. if (err < 0)
  36. return err;
  37. err = tegra_drm_fb_init(drm);
  38. if (err < 0)
  39. return err;
  40. drm_kms_helper_poll_init(drm);
  41. return 0;
  42. }
  43. static int tegra_drm_unload(struct drm_device *drm)
  44. {
  45. drm_kms_helper_poll_fini(drm);
  46. tegra_drm_fb_exit(drm);
  47. drm_mode_config_cleanup(drm);
  48. return 0;
  49. }
  50. static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
  51. {
  52. return 0;
  53. }
  54. static void tegra_drm_lastclose(struct drm_device *drm)
  55. {
  56. struct host1x *host1x = drm->dev_private;
  57. drm_fbdev_cma_restore_mode(host1x->fbdev);
  58. }
  59. static struct drm_ioctl_desc tegra_drm_ioctls[] = {
  60. };
  61. static const struct file_operations tegra_drm_fops = {
  62. .owner = THIS_MODULE,
  63. .open = drm_open,
  64. .release = drm_release,
  65. .unlocked_ioctl = drm_ioctl,
  66. .mmap = drm_gem_cma_mmap,
  67. .poll = drm_poll,
  68. .fasync = drm_fasync,
  69. .read = drm_read,
  70. #ifdef CONFIG_COMPAT
  71. .compat_ioctl = drm_compat_ioctl,
  72. #endif
  73. .llseek = noop_llseek,
  74. };
  75. static struct drm_crtc *tegra_crtc_from_pipe(struct drm_device *drm, int pipe)
  76. {
  77. struct drm_crtc *crtc;
  78. list_for_each_entry(crtc, &drm->mode_config.crtc_list, head) {
  79. struct tegra_dc *dc = to_tegra_dc(crtc);
  80. if (dc->pipe == pipe)
  81. return crtc;
  82. }
  83. return NULL;
  84. }
  85. static u32 tegra_drm_get_vblank_counter(struct drm_device *dev, int crtc)
  86. {
  87. /* TODO: implement real hardware counter using syncpoints */
  88. return drm_vblank_count(dev, crtc);
  89. }
  90. static int tegra_drm_enable_vblank(struct drm_device *drm, int pipe)
  91. {
  92. struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
  93. struct tegra_dc *dc = to_tegra_dc(crtc);
  94. if (!crtc)
  95. return -ENODEV;
  96. tegra_dc_enable_vblank(dc);
  97. return 0;
  98. }
  99. static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe)
  100. {
  101. struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
  102. struct tegra_dc *dc = to_tegra_dc(crtc);
  103. if (crtc)
  104. tegra_dc_disable_vblank(dc);
  105. }
  106. static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
  107. {
  108. struct drm_crtc *crtc;
  109. list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
  110. tegra_dc_cancel_page_flip(crtc, file);
  111. }
  112. #ifdef CONFIG_DEBUG_FS
  113. static int tegra_debugfs_framebuffers(struct seq_file *s, void *data)
  114. {
  115. struct drm_info_node *node = (struct drm_info_node *)s->private;
  116. struct drm_device *drm = node->minor->dev;
  117. struct drm_framebuffer *fb;
  118. mutex_lock(&drm->mode_config.fb_lock);
  119. list_for_each_entry(fb, &drm->mode_config.fb_list, head) {
  120. seq_printf(s, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n",
  121. fb->base.id, fb->width, fb->height, fb->depth,
  122. fb->bits_per_pixel,
  123. atomic_read(&fb->refcount.refcount));
  124. }
  125. mutex_unlock(&drm->mode_config.fb_lock);
  126. return 0;
  127. }
  128. static struct drm_info_list tegra_debugfs_list[] = {
  129. { "framebuffers", tegra_debugfs_framebuffers, 0 },
  130. };
  131. static int tegra_debugfs_init(struct drm_minor *minor)
  132. {
  133. return drm_debugfs_create_files(tegra_debugfs_list,
  134. ARRAY_SIZE(tegra_debugfs_list),
  135. minor->debugfs_root, minor);
  136. }
  137. static void tegra_debugfs_cleanup(struct drm_minor *minor)
  138. {
  139. drm_debugfs_remove_files(tegra_debugfs_list,
  140. ARRAY_SIZE(tegra_debugfs_list), minor);
  141. }
  142. #endif
  143. struct drm_driver tegra_drm_driver = {
  144. .driver_features = DRIVER_BUS_PLATFORM | DRIVER_MODESET | DRIVER_GEM,
  145. .load = tegra_drm_load,
  146. .unload = tegra_drm_unload,
  147. .open = tegra_drm_open,
  148. .preclose = tegra_drm_preclose,
  149. .lastclose = tegra_drm_lastclose,
  150. .get_vblank_counter = tegra_drm_get_vblank_counter,
  151. .enable_vblank = tegra_drm_enable_vblank,
  152. .disable_vblank = tegra_drm_disable_vblank,
  153. #if defined(CONFIG_DEBUG_FS)
  154. .debugfs_init = tegra_debugfs_init,
  155. .debugfs_cleanup = tegra_debugfs_cleanup,
  156. #endif
  157. .gem_free_object = drm_gem_cma_free_object,
  158. .gem_vm_ops = &drm_gem_cma_vm_ops,
  159. .dumb_create = drm_gem_cma_dumb_create,
  160. .dumb_map_offset = drm_gem_cma_dumb_map_offset,
  161. .dumb_destroy = drm_gem_cma_dumb_destroy,
  162. .ioctls = tegra_drm_ioctls,
  163. .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls),
  164. .fops = &tegra_drm_fops,
  165. .name = DRIVER_NAME,
  166. .desc = DRIVER_DESC,
  167. .date = DRIVER_DATE,
  168. .major = DRIVER_MAJOR,
  169. .minor = DRIVER_MINOR,
  170. .patchlevel = DRIVER_PATCHLEVEL,
  171. };