drm.c 5.0 KB

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