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