Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Red Hat |
| 3 | * Author: Rob Clark <robdclark@gmail.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that 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. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "msm_drv.h" |
Rob Clark | edcd60c | 2016-03-16 12:56:12 -0400 | [diff] [blame] | 19 | #include "msm_debugfs.h" |
Rob Clark | fde5de6 | 2016-03-15 15:35:08 -0400 | [diff] [blame] | 20 | #include "msm_fence.h" |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 21 | #include "msm_gpu.h" |
Rob Clark | dd2da6e | 2013-11-30 16:12:10 -0500 | [diff] [blame] | 22 | #include "msm_kms.h" |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 23 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 24 | static void msm_fb_output_poll_changed(struct drm_device *dev) |
| 25 | { |
| 26 | struct msm_drm_private *priv = dev->dev_private; |
| 27 | if (priv->fbdev) |
| 28 | drm_fb_helper_hotplug_event(priv->fbdev); |
| 29 | } |
| 30 | |
| 31 | static const struct drm_mode_config_funcs mode_config_funcs = { |
| 32 | .fb_create = msm_framebuffer_create, |
| 33 | .output_poll_changed = msm_fb_output_poll_changed, |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 34 | .atomic_check = msm_atomic_check, |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 35 | .atomic_commit = msm_atomic_commit, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 38 | int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 39 | { |
| 40 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 41 | int idx = priv->num_mmus++; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 42 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 43 | if (WARN_ON(idx >= ARRAY_SIZE(priv->mmus))) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 44 | return -EINVAL; |
| 45 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 46 | priv->mmus[idx] = mmu; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 47 | |
| 48 | return idx; |
| 49 | } |
| 50 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 51 | #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING |
| 52 | static bool reglog = false; |
| 53 | MODULE_PARM_DESC(reglog, "Enable register read/write logging"); |
| 54 | module_param(reglog, bool, 0600); |
| 55 | #else |
| 56 | #define reglog 0 |
| 57 | #endif |
| 58 | |
Archit Taneja | a9ee34b | 2015-07-13 12:12:07 +0530 | [diff] [blame] | 59 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Rob Clark | e90dfec | 2015-01-30 17:05:41 -0500 | [diff] [blame] | 60 | static bool fbdev = true; |
| 61 | MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer"); |
| 62 | module_param(fbdev, bool, 0600); |
| 63 | #endif |
| 64 | |
Rob Clark | 3a10ba8 | 2014-09-08 14:24:57 -0400 | [diff] [blame] | 65 | static char *vram = "16m"; |
Rob Clark | 4313c744 | 2016-02-03 14:02:04 -0500 | [diff] [blame] | 66 | MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)"); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 67 | module_param(vram, charp, 0); |
| 68 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 69 | /* |
| 70 | * Util/helpers: |
| 71 | */ |
| 72 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 73 | void __iomem *msm_ioremap(struct platform_device *pdev, const char *name, |
| 74 | const char *dbgname) |
| 75 | { |
| 76 | struct resource *res; |
| 77 | unsigned long size; |
| 78 | void __iomem *ptr; |
| 79 | |
| 80 | if (name) |
| 81 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); |
| 82 | else |
| 83 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 84 | |
| 85 | if (!res) { |
| 86 | dev_err(&pdev->dev, "failed to get memory resource: %s\n", name); |
| 87 | return ERR_PTR(-EINVAL); |
| 88 | } |
| 89 | |
| 90 | size = resource_size(res); |
| 91 | |
| 92 | ptr = devm_ioremap_nocache(&pdev->dev, res->start, size); |
| 93 | if (!ptr) { |
| 94 | dev_err(&pdev->dev, "failed to ioremap: %s\n", name); |
| 95 | return ERR_PTR(-ENOMEM); |
| 96 | } |
| 97 | |
| 98 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 99 | printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 100 | |
| 101 | return ptr; |
| 102 | } |
| 103 | |
| 104 | void msm_writel(u32 data, void __iomem *addr) |
| 105 | { |
| 106 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 107 | printk(KERN_DEBUG "IO:W %p %08x\n", addr, data); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 108 | writel(data, addr); |
| 109 | } |
| 110 | |
| 111 | u32 msm_readl(const void __iomem *addr) |
| 112 | { |
| 113 | u32 val = readl(addr); |
| 114 | if (reglog) |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 115 | printk(KERN_ERR "IO:R %p %08x\n", addr, val); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 116 | return val; |
| 117 | } |
| 118 | |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 119 | struct vblank_event { |
| 120 | struct list_head node; |
| 121 | int crtc_id; |
| 122 | bool enable; |
| 123 | }; |
| 124 | |
| 125 | static void vblank_ctrl_worker(struct work_struct *work) |
| 126 | { |
| 127 | struct msm_vblank_ctrl *vbl_ctrl = container_of(work, |
| 128 | struct msm_vblank_ctrl, work); |
| 129 | struct msm_drm_private *priv = container_of(vbl_ctrl, |
| 130 | struct msm_drm_private, vblank_ctrl); |
| 131 | struct msm_kms *kms = priv->kms; |
| 132 | struct vblank_event *vbl_ev, *tmp; |
| 133 | unsigned long flags; |
| 134 | |
| 135 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 136 | list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) { |
| 137 | list_del(&vbl_ev->node); |
| 138 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 139 | |
| 140 | if (vbl_ev->enable) |
| 141 | kms->funcs->enable_vblank(kms, |
| 142 | priv->crtcs[vbl_ev->crtc_id]); |
| 143 | else |
| 144 | kms->funcs->disable_vblank(kms, |
| 145 | priv->crtcs[vbl_ev->crtc_id]); |
| 146 | |
| 147 | kfree(vbl_ev); |
| 148 | |
| 149 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 150 | } |
| 151 | |
| 152 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 153 | } |
| 154 | |
| 155 | static int vblank_ctrl_queue_work(struct msm_drm_private *priv, |
| 156 | int crtc_id, bool enable) |
| 157 | { |
| 158 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 159 | struct vblank_event *vbl_ev; |
| 160 | unsigned long flags; |
| 161 | |
| 162 | vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC); |
| 163 | if (!vbl_ev) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | vbl_ev->crtc_id = crtc_id; |
| 167 | vbl_ev->enable = enable; |
| 168 | |
| 169 | spin_lock_irqsave(&vbl_ctrl->lock, flags); |
| 170 | list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list); |
| 171 | spin_unlock_irqrestore(&vbl_ctrl->lock, flags); |
| 172 | |
| 173 | queue_work(priv->wq, &vbl_ctrl->work); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 178 | /* |
| 179 | * DRM operations: |
| 180 | */ |
| 181 | |
| 182 | static int msm_unload(struct drm_device *dev) |
| 183 | { |
| 184 | struct msm_drm_private *priv = dev->dev_private; |
| 185 | struct msm_kms *kms = priv->kms; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 186 | struct msm_gpu *gpu = priv->gpu; |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 187 | struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl; |
| 188 | struct vblank_event *vbl_ev, *tmp; |
| 189 | |
| 190 | /* We must cancel and cleanup any pending vblank enable/disable |
| 191 | * work before drm_irq_uninstall() to avoid work re-enabling an |
| 192 | * irq after uninstall has disabled it. |
| 193 | */ |
| 194 | cancel_work_sync(&vbl_ctrl->work); |
| 195 | list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) { |
| 196 | list_del(&vbl_ev->node); |
| 197 | kfree(vbl_ev); |
| 198 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 199 | |
| 200 | drm_kms_helper_poll_fini(dev); |
Archit Taneja | 1aaa57f | 2016-02-25 11:19:45 +0530 | [diff] [blame] | 201 | |
| 202 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
| 203 | if (fbdev && priv->fbdev) |
| 204 | msm_fbdev_free(dev); |
| 205 | #endif |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 206 | drm_mode_config_cleanup(dev); |
| 207 | drm_vblank_cleanup(dev); |
| 208 | |
| 209 | pm_runtime_get_sync(dev->dev); |
| 210 | drm_irq_uninstall(dev); |
| 211 | pm_runtime_put_sync(dev->dev); |
| 212 | |
| 213 | flush_workqueue(priv->wq); |
| 214 | destroy_workqueue(priv->wq); |
| 215 | |
| 216 | if (kms) { |
| 217 | pm_runtime_disable(dev->dev); |
| 218 | kms->funcs->destroy(kms); |
| 219 | } |
| 220 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 221 | if (gpu) { |
| 222 | mutex_lock(&dev->struct_mutex); |
| 223 | gpu->funcs->pm_suspend(gpu); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 224 | mutex_unlock(&dev->struct_mutex); |
Rob Clark | 774449e | 2015-05-15 09:19:36 -0400 | [diff] [blame] | 225 | gpu->funcs->destroy(gpu); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 226 | } |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 227 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 228 | if (priv->vram.paddr) { |
| 229 | DEFINE_DMA_ATTRS(attrs); |
| 230 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); |
| 231 | drm_mm_takedown(&priv->vram.mm); |
| 232 | dma_free_attrs(dev->dev, priv->vram.size, NULL, |
| 233 | priv->vram.paddr, &attrs); |
| 234 | } |
| 235 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 236 | component_unbind_all(dev->dev, dev); |
| 237 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 238 | dev->dev_private = NULL; |
| 239 | |
| 240 | kfree(priv); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 245 | static int get_mdp_ver(struct platform_device *pdev) |
| 246 | { |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 247 | struct device *dev = &pdev->dev; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 248 | |
| 249 | return (int) (unsigned long) of_device_get_match_data(dev); |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 252 | #include <linux/of_address.h> |
| 253 | |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 254 | static int msm_init_vram(struct drm_device *dev) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 255 | { |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 256 | struct msm_drm_private *priv = dev->dev_private; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 257 | struct device_node *node; |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 258 | unsigned long size = 0; |
| 259 | int ret = 0; |
| 260 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 261 | /* In the device-tree world, we could have a 'memory-region' |
| 262 | * phandle, which gives us a link to our "vram". Allocating |
| 263 | * is all nicely abstracted behind the dma api, but we need |
| 264 | * to know the entire size to allocate it all in one go. There |
| 265 | * are two cases: |
| 266 | * 1) device with no IOMMU, in which case we need exclusive |
| 267 | * access to a VRAM carveout big enough for all gpu |
| 268 | * buffers |
| 269 | * 2) device with IOMMU, but where the bootloader puts up |
| 270 | * a splash screen. In this case, the VRAM carveout |
| 271 | * need only be large enough for fbdev fb. But we need |
| 272 | * exclusive access to the buffer to avoid the kernel |
| 273 | * using those pages for other purposes (which appears |
| 274 | * as corruption on screen before we have a chance to |
| 275 | * load and do initial modeset) |
| 276 | */ |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 277 | |
| 278 | node = of_parse_phandle(dev->dev->of_node, "memory-region", 0); |
| 279 | if (node) { |
| 280 | struct resource r; |
| 281 | ret = of_address_to_resource(node, 0, &r); |
| 282 | if (ret) |
| 283 | return ret; |
| 284 | size = r.end - r.start; |
Thierry Reding | fc99f97 | 2015-04-09 16:39:51 +0200 | [diff] [blame] | 285 | DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 286 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 287 | /* if we have no IOMMU, then we need to use carveout allocator. |
| 288 | * Grab the entire CMA chunk carved out in early startup in |
| 289 | * mach-msm: |
| 290 | */ |
| 291 | } else if (!iommu_present(&platform_bus_type)) { |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 292 | DRM_INFO("using %s VRAM carveout\n", vram); |
| 293 | size = memparse(vram, NULL); |
| 294 | } |
| 295 | |
| 296 | if (size) { |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 297 | DEFINE_DMA_ATTRS(attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 298 | void *p; |
| 299 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 300 | priv->vram.size = size; |
| 301 | |
| 302 | drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1); |
| 303 | |
| 304 | dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs); |
| 305 | dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs); |
| 306 | |
| 307 | /* note that for no-kernel-mapping, the vaddr returned |
| 308 | * is bogus, but non-null if allocation succeeded: |
| 309 | */ |
| 310 | p = dma_alloc_attrs(dev->dev, size, |
Rob Clark | 543d301 | 2014-06-02 07:25:56 -0400 | [diff] [blame] | 311 | &priv->vram.paddr, GFP_KERNEL, &attrs); |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 312 | if (!p) { |
| 313 | dev_err(dev->dev, "failed to allocate VRAM\n"); |
| 314 | priv->vram.paddr = 0; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 315 | return -ENOMEM; |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | dev_info(dev->dev, "VRAM: %08x->%08x\n", |
| 319 | (uint32_t)priv->vram.paddr, |
| 320 | (uint32_t)(priv->vram.paddr + size)); |
| 321 | } |
| 322 | |
Rob Clark | 072f1f9 | 2015-03-03 15:04:25 -0500 | [diff] [blame] | 323 | return ret; |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static int msm_load(struct drm_device *dev, unsigned long flags) |
| 327 | { |
| 328 | struct platform_device *pdev = dev->platformdev; |
| 329 | struct msm_drm_private *priv; |
| 330 | struct msm_kms *kms; |
| 331 | int ret; |
| 332 | |
| 333 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 334 | if (!priv) { |
| 335 | dev_err(dev->dev, "failed to allocate private data\n"); |
| 336 | return -ENOMEM; |
| 337 | } |
| 338 | |
| 339 | dev->dev_private = priv; |
| 340 | |
| 341 | priv->wq = alloc_ordered_workqueue("msm", 0); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 342 | init_waitqueue_head(&priv->pending_crtcs_event); |
| 343 | |
| 344 | INIT_LIST_HEAD(&priv->inactive_list); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 345 | INIT_LIST_HEAD(&priv->vblank_ctrl.event_list); |
| 346 | INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker); |
| 347 | spin_lock_init(&priv->vblank_ctrl.lock); |
Rob Clark | 5bf9c0b | 2015-03-03 15:04:24 -0500 | [diff] [blame] | 348 | |
| 349 | drm_mode_config_init(dev); |
| 350 | |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 351 | platform_set_drvdata(pdev, dev); |
| 352 | |
| 353 | /* Bind all our sub-components: */ |
| 354 | ret = component_bind_all(dev->dev, dev); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | |
Rob Clark | 13f1556 | 2015-05-07 15:20:13 -0400 | [diff] [blame] | 358 | ret = msm_init_vram(dev); |
| 359 | if (ret) |
| 360 | goto fail; |
| 361 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 362 | switch (get_mdp_ver(pdev)) { |
| 363 | case 4: |
| 364 | kms = mdp4_kms_init(dev); |
| 365 | break; |
| 366 | case 5: |
| 367 | kms = mdp5_kms_init(dev); |
| 368 | break; |
| 369 | default: |
| 370 | kms = ERR_PTR(-ENODEV); |
| 371 | break; |
| 372 | } |
| 373 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 374 | if (IS_ERR(kms)) { |
| 375 | /* |
| 376 | * NOTE: once we have GPU support, having no kms should not |
| 377 | * be considered fatal.. ideally we would still support gpu |
| 378 | * and (for example) use dmabuf/prime to share buffers with |
| 379 | * imx drm driver on iMX5 |
| 380 | */ |
| 381 | dev_err(dev->dev, "failed to load kms\n"); |
Thomas Meyer | e4826a9 | 2013-09-16 23:19:54 +0200 | [diff] [blame] | 382 | ret = PTR_ERR(kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 383 | goto fail; |
| 384 | } |
| 385 | |
| 386 | priv->kms = kms; |
| 387 | |
| 388 | if (kms) { |
| 389 | pm_runtime_enable(dev->dev); |
| 390 | ret = kms->funcs->hw_init(kms); |
| 391 | if (ret) { |
| 392 | dev_err(dev->dev, "kms hw init failed: %d\n", ret); |
| 393 | goto fail; |
| 394 | } |
| 395 | } |
| 396 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 397 | dev->mode_config.funcs = &mode_config_funcs; |
| 398 | |
Rob Clark | d65bd0e | 2014-08-06 07:43:12 -0400 | [diff] [blame] | 399 | ret = drm_vblank_init(dev, priv->num_crtcs); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 400 | if (ret < 0) { |
| 401 | dev_err(dev->dev, "failed to initialize vblank\n"); |
| 402 | goto fail; |
| 403 | } |
| 404 | |
| 405 | pm_runtime_get_sync(dev->dev); |
Daniel Vetter | bb0f1b5 | 2013-11-03 21:09:27 +0100 | [diff] [blame] | 406 | ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0)); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 407 | pm_runtime_put_sync(dev->dev); |
| 408 | if (ret < 0) { |
| 409 | dev_err(dev->dev, "failed to install IRQ handler\n"); |
| 410 | goto fail; |
| 411 | } |
| 412 | |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 413 | drm_mode_config_reset(dev); |
| 414 | |
Archit Taneja | a9ee34b | 2015-07-13 12:12:07 +0530 | [diff] [blame] | 415 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Rob Clark | e90dfec | 2015-01-30 17:05:41 -0500 | [diff] [blame] | 416 | if (fbdev) |
| 417 | priv->fbdev = msm_fbdev_init(dev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 418 | #endif |
| 419 | |
Rob Clark | a7d3c95 | 2014-05-30 14:47:38 -0400 | [diff] [blame] | 420 | ret = msm_debugfs_late_init(dev); |
| 421 | if (ret) |
| 422 | goto fail; |
| 423 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 424 | drm_kms_helper_poll_init(dev); |
| 425 | |
| 426 | return 0; |
| 427 | |
| 428 | fail: |
| 429 | msm_unload(dev); |
| 430 | return ret; |
| 431 | } |
| 432 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 433 | static void load_gpu(struct drm_device *dev) |
| 434 | { |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 435 | static DEFINE_MUTEX(init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 436 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 437 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 438 | mutex_lock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 439 | |
Rob Clark | e2550b7 | 2014-09-05 13:30:27 -0400 | [diff] [blame] | 440 | if (!priv->gpu) |
| 441 | priv->gpu = adreno_load_gpu(dev); |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 442 | |
Rob Clark | a1ad352 | 2014-07-11 11:59:22 -0400 | [diff] [blame] | 443 | mutex_unlock(&init_lock); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static int msm_open(struct drm_device *dev, struct drm_file *file) |
| 447 | { |
| 448 | struct msm_file_private *ctx; |
| 449 | |
| 450 | /* For now, load gpu on open.. to avoid the requirement of having |
| 451 | * firmware in the initrd. |
| 452 | */ |
| 453 | load_gpu(dev); |
| 454 | |
| 455 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 456 | if (!ctx) |
| 457 | return -ENOMEM; |
| 458 | |
| 459 | file->driver_priv = ctx; |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 464 | static void msm_preclose(struct drm_device *dev, struct drm_file *file) |
| 465 | { |
| 466 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 467 | struct msm_file_private *ctx = file->driver_priv; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 468 | struct msm_kms *kms = priv->kms; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 469 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 470 | mutex_lock(&dev->struct_mutex); |
| 471 | if (ctx == priv->lastctx) |
| 472 | priv->lastctx = NULL; |
| 473 | mutex_unlock(&dev->struct_mutex); |
| 474 | |
| 475 | kfree(ctx); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void msm_lastclose(struct drm_device *dev) |
| 479 | { |
| 480 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 481 | if (priv->fbdev) |
| 482 | drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 485 | static irqreturn_t msm_irq(int irq, void *arg) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 486 | { |
| 487 | struct drm_device *dev = arg; |
| 488 | struct msm_drm_private *priv = dev->dev_private; |
| 489 | struct msm_kms *kms = priv->kms; |
| 490 | BUG_ON(!kms); |
| 491 | return kms->funcs->irq(kms); |
| 492 | } |
| 493 | |
| 494 | static void msm_irq_preinstall(struct drm_device *dev) |
| 495 | { |
| 496 | struct msm_drm_private *priv = dev->dev_private; |
| 497 | struct msm_kms *kms = priv->kms; |
| 498 | BUG_ON(!kms); |
| 499 | kms->funcs->irq_preinstall(kms); |
| 500 | } |
| 501 | |
| 502 | static int msm_irq_postinstall(struct drm_device *dev) |
| 503 | { |
| 504 | struct msm_drm_private *priv = dev->dev_private; |
| 505 | struct msm_kms *kms = priv->kms; |
| 506 | BUG_ON(!kms); |
| 507 | return kms->funcs->irq_postinstall(kms); |
| 508 | } |
| 509 | |
| 510 | static void msm_irq_uninstall(struct drm_device *dev) |
| 511 | { |
| 512 | struct msm_drm_private *priv = dev->dev_private; |
| 513 | struct msm_kms *kms = priv->kms; |
| 514 | BUG_ON(!kms); |
| 515 | kms->funcs->irq_uninstall(kms); |
| 516 | } |
| 517 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 518 | static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 519 | { |
| 520 | struct msm_drm_private *priv = dev->dev_private; |
| 521 | struct msm_kms *kms = priv->kms; |
| 522 | if (!kms) |
| 523 | return -ENXIO; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 524 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 525 | return vblank_ctrl_queue_work(priv, pipe, true); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 526 | } |
| 527 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 528 | static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 529 | { |
| 530 | struct msm_drm_private *priv = dev->dev_private; |
| 531 | struct msm_kms *kms = priv->kms; |
| 532 | if (!kms) |
| 533 | return; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 534 | DBG("dev=%p, crtc=%u", dev, pipe); |
| 535 | vblank_ctrl_queue_work(priv, pipe, false); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /* |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 539 | * DRM ioctls: |
| 540 | */ |
| 541 | |
| 542 | static int msm_ioctl_get_param(struct drm_device *dev, void *data, |
| 543 | struct drm_file *file) |
| 544 | { |
| 545 | struct msm_drm_private *priv = dev->dev_private; |
| 546 | struct drm_msm_param *args = data; |
| 547 | struct msm_gpu *gpu; |
| 548 | |
| 549 | /* for now, we just have 3d pipe.. eventually this would need to |
| 550 | * be more clever to dispatch to appropriate gpu module: |
| 551 | */ |
| 552 | if (args->pipe != MSM_PIPE_3D0) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | gpu = priv->gpu; |
| 556 | |
| 557 | if (!gpu) |
| 558 | return -ENXIO; |
| 559 | |
| 560 | return gpu->funcs->get_param(gpu, args->param, &args->value); |
| 561 | } |
| 562 | |
| 563 | static int msm_ioctl_gem_new(struct drm_device *dev, void *data, |
| 564 | struct drm_file *file) |
| 565 | { |
| 566 | struct drm_msm_gem_new *args = data; |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 567 | |
| 568 | if (args->flags & ~MSM_BO_FLAGS) { |
| 569 | DRM_ERROR("invalid flags: %08x\n", args->flags); |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 573 | return msm_gem_new_handle(dev, file, args->size, |
| 574 | args->flags, &args->handle); |
| 575 | } |
| 576 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 577 | static inline ktime_t to_ktime(struct drm_msm_timespec timeout) |
| 578 | { |
| 579 | return ktime_set(timeout.tv_sec, timeout.tv_nsec); |
| 580 | } |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 581 | |
| 582 | static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data, |
| 583 | struct drm_file *file) |
| 584 | { |
| 585 | struct drm_msm_gem_cpu_prep *args = data; |
| 586 | struct drm_gem_object *obj; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 587 | ktime_t timeout = to_ktime(args->timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 588 | int ret; |
| 589 | |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 590 | if (args->op & ~MSM_PREP_FLAGS) { |
| 591 | DRM_ERROR("invalid op: %08x\n", args->op); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 595 | obj = drm_gem_object_lookup(dev, file, args->handle); |
| 596 | if (!obj) |
| 597 | return -ENOENT; |
| 598 | |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 599 | ret = msm_gem_cpu_prep(obj, args->op, &timeout); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 600 | |
| 601 | drm_gem_object_unreference_unlocked(obj); |
| 602 | |
| 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data, |
| 607 | struct drm_file *file) |
| 608 | { |
| 609 | struct drm_msm_gem_cpu_fini *args = data; |
| 610 | struct drm_gem_object *obj; |
| 611 | int ret; |
| 612 | |
| 613 | obj = drm_gem_object_lookup(dev, file, args->handle); |
| 614 | if (!obj) |
| 615 | return -ENOENT; |
| 616 | |
| 617 | ret = msm_gem_cpu_fini(obj); |
| 618 | |
| 619 | drm_gem_object_unreference_unlocked(obj); |
| 620 | |
| 621 | return ret; |
| 622 | } |
| 623 | |
| 624 | static int msm_ioctl_gem_info(struct drm_device *dev, void *data, |
| 625 | struct drm_file *file) |
| 626 | { |
| 627 | struct drm_msm_gem_info *args = data; |
| 628 | struct drm_gem_object *obj; |
| 629 | int ret = 0; |
| 630 | |
| 631 | if (args->pad) |
| 632 | return -EINVAL; |
| 633 | |
| 634 | obj = drm_gem_object_lookup(dev, file, args->handle); |
| 635 | if (!obj) |
| 636 | return -ENOENT; |
| 637 | |
| 638 | args->offset = msm_gem_mmap_offset(obj); |
| 639 | |
| 640 | drm_gem_object_unreference_unlocked(obj); |
| 641 | |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | static int msm_ioctl_wait_fence(struct drm_device *dev, void *data, |
| 646 | struct drm_file *file) |
| 647 | { |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame^] | 648 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 649 | struct drm_msm_wait_fence *args = data; |
Rob Clark | 56c2da8 | 2015-05-11 11:50:03 -0400 | [diff] [blame] | 650 | ktime_t timeout = to_ktime(args->timeout); |
Rob Clark | 93ddb0d | 2014-03-03 09:42:33 -0500 | [diff] [blame] | 651 | |
| 652 | if (args->pad) { |
| 653 | DRM_ERROR("invalid pad: %08x\n", args->pad); |
| 654 | return -EINVAL; |
| 655 | } |
| 656 | |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame^] | 657 | if (!priv->gpu) |
| 658 | return 0; |
| 659 | |
| 660 | return msm_wait_fence(priv->gpu->fctx, args->fence, &timeout, true); |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static const struct drm_ioctl_desc msm_ioctls[] = { |
Daniel Vetter | f8c4714 | 2015-09-08 13:56:30 +0200 | [diff] [blame] | 664 | DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW), |
| 665 | DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW), |
| 666 | DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW), |
| 667 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW), |
| 668 | DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW), |
| 669 | DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW), |
| 670 | DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW), |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 671 | }; |
| 672 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 673 | static const struct vm_operations_struct vm_ops = { |
| 674 | .fault = msm_gem_fault, |
| 675 | .open = drm_gem_vm_open, |
| 676 | .close = drm_gem_vm_close, |
| 677 | }; |
| 678 | |
| 679 | static const struct file_operations fops = { |
| 680 | .owner = THIS_MODULE, |
| 681 | .open = drm_open, |
| 682 | .release = drm_release, |
| 683 | .unlocked_ioctl = drm_ioctl, |
| 684 | #ifdef CONFIG_COMPAT |
| 685 | .compat_ioctl = drm_compat_ioctl, |
| 686 | #endif |
| 687 | .poll = drm_poll, |
| 688 | .read = drm_read, |
| 689 | .llseek = no_llseek, |
| 690 | .mmap = msm_gem_mmap, |
| 691 | }; |
| 692 | |
| 693 | static struct drm_driver msm_driver = { |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 694 | .driver_features = DRIVER_HAVE_IRQ | |
| 695 | DRIVER_GEM | |
| 696 | DRIVER_PRIME | |
Rob Clark | b4b15c8 | 2013-09-28 12:01:25 -0400 | [diff] [blame] | 697 | DRIVER_RENDER | |
Rob Clark | a5436e1 | 2015-06-04 10:12:22 -0400 | [diff] [blame] | 698 | DRIVER_ATOMIC | |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 699 | DRIVER_MODESET, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 700 | .load = msm_load, |
| 701 | .unload = msm_unload, |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 702 | .open = msm_open, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 703 | .preclose = msm_preclose, |
| 704 | .lastclose = msm_lastclose, |
David Herrmann | 915b4d1 | 2014-08-29 12:12:43 +0200 | [diff] [blame] | 705 | .set_busid = drm_platform_set_busid, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 706 | .irq_handler = msm_irq, |
| 707 | .irq_preinstall = msm_irq_preinstall, |
| 708 | .irq_postinstall = msm_irq_postinstall, |
| 709 | .irq_uninstall = msm_irq_uninstall, |
Ville Syrjälä | b44f840 | 2015-09-30 16:46:48 +0300 | [diff] [blame] | 710 | .get_vblank_counter = drm_vblank_no_hw_counter, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 711 | .enable_vblank = msm_enable_vblank, |
| 712 | .disable_vblank = msm_disable_vblank, |
| 713 | .gem_free_object = msm_gem_free_object, |
| 714 | .gem_vm_ops = &vm_ops, |
| 715 | .dumb_create = msm_gem_dumb_create, |
| 716 | .dumb_map_offset = msm_gem_dumb_map_offset, |
Rob Clark | 30600a9 | 2013-09-28 10:13:04 -0400 | [diff] [blame] | 717 | .dumb_destroy = drm_gem_dumb_destroy, |
Rob Clark | 05b8491 | 2013-09-28 11:28:35 -0400 | [diff] [blame] | 718 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 719 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 720 | .gem_prime_export = drm_gem_prime_export, |
| 721 | .gem_prime_import = drm_gem_prime_import, |
| 722 | .gem_prime_pin = msm_gem_prime_pin, |
| 723 | .gem_prime_unpin = msm_gem_prime_unpin, |
| 724 | .gem_prime_get_sg_table = msm_gem_prime_get_sg_table, |
| 725 | .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, |
| 726 | .gem_prime_vmap = msm_gem_prime_vmap, |
| 727 | .gem_prime_vunmap = msm_gem_prime_vunmap, |
Daniel Thompson | 77a147e | 2014-11-12 11:38:14 +0000 | [diff] [blame] | 728 | .gem_prime_mmap = msm_gem_prime_mmap, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 729 | #ifdef CONFIG_DEBUG_FS |
| 730 | .debugfs_init = msm_debugfs_init, |
| 731 | .debugfs_cleanup = msm_debugfs_cleanup, |
| 732 | #endif |
Rob Clark | 7198e6b | 2013-07-19 12:59:32 -0400 | [diff] [blame] | 733 | .ioctls = msm_ioctls, |
| 734 | .num_ioctls = DRM_MSM_NUM_IOCTLS, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 735 | .fops = &fops, |
| 736 | .name = "msm", |
| 737 | .desc = "MSM Snapdragon DRM", |
| 738 | .date = "20130625", |
| 739 | .major = 1, |
| 740 | .minor = 0, |
| 741 | }; |
| 742 | |
| 743 | #ifdef CONFIG_PM_SLEEP |
| 744 | static int msm_pm_suspend(struct device *dev) |
| 745 | { |
| 746 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 747 | |
| 748 | drm_kms_helper_poll_disable(ddev); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static int msm_pm_resume(struct device *dev) |
| 754 | { |
| 755 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 756 | |
| 757 | drm_kms_helper_poll_enable(ddev); |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | #endif |
| 762 | |
| 763 | static const struct dev_pm_ops msm_pm_ops = { |
| 764 | SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume) |
| 765 | }; |
| 766 | |
| 767 | /* |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 768 | * Componentized driver support: |
| 769 | */ |
| 770 | |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 771 | /* |
| 772 | * NOTE: duplication of the same code as exynos or imx (or probably any other). |
| 773 | * so probably some room for some helpers |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 774 | */ |
| 775 | static int compare_of(struct device *dev, void *data) |
| 776 | { |
| 777 | return dev->of_node == data; |
| 778 | } |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 779 | |
| 780 | static int add_components(struct device *dev, struct component_match **matchptr, |
| 781 | const char *name) |
| 782 | { |
| 783 | struct device_node *np = dev->of_node; |
| 784 | unsigned i; |
| 785 | |
| 786 | for (i = 0; ; i++) { |
| 787 | struct device_node *node; |
| 788 | |
| 789 | node = of_parse_phandle(np, name, i); |
| 790 | if (!node) |
| 791 | break; |
| 792 | |
| 793 | component_match_add(dev, matchptr, compare_of, node); |
| 794 | } |
| 795 | |
| 796 | return 0; |
| 797 | } |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 798 | |
| 799 | static int msm_drm_bind(struct device *dev) |
| 800 | { |
| 801 | return drm_platform_init(&msm_driver, to_platform_device(dev)); |
| 802 | } |
| 803 | |
| 804 | static void msm_drm_unbind(struct device *dev) |
| 805 | { |
| 806 | drm_put_dev(platform_get_drvdata(to_platform_device(dev))); |
| 807 | } |
| 808 | |
| 809 | static const struct component_master_ops msm_drm_ops = { |
| 810 | .bind = msm_drm_bind, |
| 811 | .unbind = msm_drm_unbind, |
| 812 | }; |
| 813 | |
| 814 | /* |
| 815 | * Platform driver: |
| 816 | */ |
| 817 | |
| 818 | static int msm_pdev_probe(struct platform_device *pdev) |
| 819 | { |
| 820 | struct component_match *match = NULL; |
Archit Taneja | e9fbdaf | 2015-11-18 12:15:14 +0530 | [diff] [blame] | 821 | |
Rob Clark | 41e6977 | 2013-12-15 16:23:05 -0500 | [diff] [blame] | 822 | add_components(&pdev->dev, &match, "connectors"); |
| 823 | add_components(&pdev->dev, &match, "gpus"); |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 824 | |
Rob Clark | 871d812 | 2013-11-16 12:56:06 -0500 | [diff] [blame] | 825 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
Russell King | 8444828 | 2014-04-19 11:20:42 +0100 | [diff] [blame] | 826 | return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | static int msm_pdev_remove(struct platform_device *pdev) |
| 830 | { |
Rob Clark | 060530f | 2014-03-03 14:19:12 -0500 | [diff] [blame] | 831 | component_master_del(&pdev->dev, &msm_drm_ops); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static const struct platform_device_id msm_id[] = { |
| 837 | { "mdp", 0 }, |
| 838 | { } |
| 839 | }; |
| 840 | |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 841 | static const struct of_device_id dt_match[] = { |
Archit Taneja | d4fc72e | 2015-11-18 12:28:39 +0530 | [diff] [blame] | 842 | { .compatible = "qcom,mdp4", .data = (void *) 4 }, /* mdp4 */ |
| 843 | { .compatible = "qcom,mdp5", .data = (void *) 5 }, /* mdp5 */ |
| 844 | /* to support downstream DT files */ |
| 845 | { .compatible = "qcom,mdss_mdp", .data = (void *) 5 }, /* mdp5 */ |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 846 | {} |
| 847 | }; |
| 848 | MODULE_DEVICE_TABLE(of, dt_match); |
| 849 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 850 | static struct platform_driver msm_platform_driver = { |
| 851 | .probe = msm_pdev_probe, |
| 852 | .remove = msm_pdev_remove, |
| 853 | .driver = { |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 854 | .name = "msm", |
Rob Clark | 06c0dd9 | 2013-11-30 17:51:47 -0500 | [diff] [blame] | 855 | .of_match_table = dt_match, |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 856 | .pm = &msm_pm_ops, |
| 857 | }, |
| 858 | .id_table = msm_id, |
| 859 | }; |
| 860 | |
| 861 | static int __init msm_drm_register(void) |
| 862 | { |
| 863 | DBG("init"); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 864 | msm_dsi_register(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 865 | msm_edp_register(); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 866 | msm_hdmi_register(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 867 | adreno_register(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 868 | return platform_driver_register(&msm_platform_driver); |
| 869 | } |
| 870 | |
| 871 | static void __exit msm_drm_unregister(void) |
| 872 | { |
| 873 | DBG("fini"); |
| 874 | platform_driver_unregister(&msm_platform_driver); |
Arnd Bergmann | fcda50c | 2016-02-22 22:08:35 +0100 | [diff] [blame] | 875 | msm_hdmi_unregister(); |
Rob Clark | bfd28b1 | 2014-09-05 13:06:37 -0400 | [diff] [blame] | 876 | adreno_unregister(); |
Hai Li | 0045398 | 2014-12-12 14:41:17 -0500 | [diff] [blame] | 877 | msm_edp_unregister(); |
Hai Li | d5af49c | 2015-03-26 19:25:17 -0400 | [diff] [blame] | 878 | msm_dsi_unregister(); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | module_init(msm_drm_register); |
| 882 | module_exit(msm_drm_unregister); |
| 883 | |
| 884 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 885 | MODULE_DESCRIPTION("MSM DRM Driver"); |
| 886 | MODULE_LICENSE("GPL"); |