blob: f6e2e23378d28d6bd1934377c0bc462d2ec7ee36 [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
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 Clarkedcd60c2016-03-16 12:56:12 -040019#include "msm_debugfs.h"
Rob Clarkfde5de62016-03-15 15:35:08 -040020#include "msm_fence.h"
Rob Clark7198e6b2013-07-19 12:59:32 -040021#include "msm_gpu.h"
Rob Clarkdd2da6e2013-11-30 16:12:10 -050022#include "msm_kms.h"
Rob Clarkc8afe682013-06-26 12:44:06 -040023
Rob Clarka8d854c2016-06-01 14:02:02 -040024
25/*
26 * MSM driver version:
27 * - 1.0.0 - initial interface
28 * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers
Rob Clark7a3bcc02016-09-16 18:37:44 -040029 * - 1.2.0 - adds explicit fence support for submit ioctl
Rob Clarka8d854c2016-06-01 14:02:02 -040030 */
31#define MSM_VERSION_MAJOR 1
Rob Clark7a3bcc02016-09-16 18:37:44 -040032#define MSM_VERSION_MINOR 2
Rob Clarka8d854c2016-06-01 14:02:02 -040033#define MSM_VERSION_PATCHLEVEL 0
34
Rob Clarkc8afe682013-06-26 12:44:06 -040035static void msm_fb_output_poll_changed(struct drm_device *dev)
36{
37 struct msm_drm_private *priv = dev->dev_private;
38 if (priv->fbdev)
39 drm_fb_helper_hotplug_event(priv->fbdev);
40}
41
42static const struct drm_mode_config_funcs mode_config_funcs = {
43 .fb_create = msm_framebuffer_create,
44 .output_poll_changed = msm_fb_output_poll_changed,
Daniel Vetterb4274fb2014-11-26 17:02:18 +010045 .atomic_check = msm_atomic_check,
Rob Clarkcf3a7e42014-11-08 13:21:06 -050046 .atomic_commit = msm_atomic_commit,
Rob Clarkc8afe682013-06-26 12:44:06 -040047};
48
Rob Clark871d8122013-11-16 12:56:06 -050049int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu)
Rob Clarkc8afe682013-06-26 12:44:06 -040050{
51 struct msm_drm_private *priv = dev->dev_private;
Rob Clark871d8122013-11-16 12:56:06 -050052 int idx = priv->num_mmus++;
Rob Clarkc8afe682013-06-26 12:44:06 -040053
Rob Clark871d8122013-11-16 12:56:06 -050054 if (WARN_ON(idx >= ARRAY_SIZE(priv->mmus)))
Rob Clarkc8afe682013-06-26 12:44:06 -040055 return -EINVAL;
56
Rob Clark871d8122013-11-16 12:56:06 -050057 priv->mmus[idx] = mmu;
Rob Clarkc8afe682013-06-26 12:44:06 -040058
59 return idx;
60}
61
Rob Clarkc8afe682013-06-26 12:44:06 -040062#ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
63static bool reglog = false;
64MODULE_PARM_DESC(reglog, "Enable register read/write logging");
65module_param(reglog, bool, 0600);
66#else
67#define reglog 0
68#endif
69
Archit Tanejaa9ee34b2015-07-13 12:12:07 +053070#ifdef CONFIG_DRM_FBDEV_EMULATION
Rob Clarke90dfec2015-01-30 17:05:41 -050071static bool fbdev = true;
72MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
73module_param(fbdev, bool, 0600);
74#endif
75
Rob Clark3a10ba82014-09-08 14:24:57 -040076static char *vram = "16m";
Rob Clark4313c742016-02-03 14:02:04 -050077MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
Rob Clark871d8122013-11-16 12:56:06 -050078module_param(vram, charp, 0);
79
Rob Clark060530f2014-03-03 14:19:12 -050080/*
81 * Util/helpers:
82 */
83
Rob Clarkc8afe682013-06-26 12:44:06 -040084void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
85 const char *dbgname)
86{
87 struct resource *res;
88 unsigned long size;
89 void __iomem *ptr;
90
91 if (name)
92 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
93 else
94 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
95
96 if (!res) {
97 dev_err(&pdev->dev, "failed to get memory resource: %s\n", name);
98 return ERR_PTR(-EINVAL);
99 }
100
101 size = resource_size(res);
102
103 ptr = devm_ioremap_nocache(&pdev->dev, res->start, size);
104 if (!ptr) {
105 dev_err(&pdev->dev, "failed to ioremap: %s\n", name);
106 return ERR_PTR(-ENOMEM);
107 }
108
109 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200110 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
Rob Clarkc8afe682013-06-26 12:44:06 -0400111
112 return ptr;
113}
114
115void msm_writel(u32 data, void __iomem *addr)
116{
117 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200118 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
Rob Clarkc8afe682013-06-26 12:44:06 -0400119 writel(data, addr);
120}
121
122u32 msm_readl(const void __iomem *addr)
123{
124 u32 val = readl(addr);
125 if (reglog)
Thierry Redingfc99f972015-04-09 16:39:51 +0200126 printk(KERN_ERR "IO:R %p %08x\n", addr, val);
Rob Clarkc8afe682013-06-26 12:44:06 -0400127 return val;
128}
129
Hai Li78b1d472015-07-27 13:49:45 -0400130struct vblank_event {
131 struct list_head node;
132 int crtc_id;
133 bool enable;
134};
135
136static void vblank_ctrl_worker(struct work_struct *work)
137{
138 struct msm_vblank_ctrl *vbl_ctrl = container_of(work,
139 struct msm_vblank_ctrl, work);
140 struct msm_drm_private *priv = container_of(vbl_ctrl,
141 struct msm_drm_private, vblank_ctrl);
142 struct msm_kms *kms = priv->kms;
143 struct vblank_event *vbl_ev, *tmp;
144 unsigned long flags;
145
146 spin_lock_irqsave(&vbl_ctrl->lock, flags);
147 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
148 list_del(&vbl_ev->node);
149 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
150
151 if (vbl_ev->enable)
152 kms->funcs->enable_vblank(kms,
153 priv->crtcs[vbl_ev->crtc_id]);
154 else
155 kms->funcs->disable_vblank(kms,
156 priv->crtcs[vbl_ev->crtc_id]);
157
158 kfree(vbl_ev);
159
160 spin_lock_irqsave(&vbl_ctrl->lock, flags);
161 }
162
163 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
164}
165
166static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
167 int crtc_id, bool enable)
168{
169 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
170 struct vblank_event *vbl_ev;
171 unsigned long flags;
172
173 vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC);
174 if (!vbl_ev)
175 return -ENOMEM;
176
177 vbl_ev->crtc_id = crtc_id;
178 vbl_ev->enable = enable;
179
180 spin_lock_irqsave(&vbl_ctrl->lock, flags);
181 list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list);
182 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
183
184 queue_work(priv->wq, &vbl_ctrl->work);
185
186 return 0;
187}
188
Archit Taneja2b669872016-05-02 11:05:54 +0530189static int msm_drm_uninit(struct device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400190{
Archit Taneja2b669872016-05-02 11:05:54 +0530191 struct platform_device *pdev = to_platform_device(dev);
192 struct drm_device *ddev = platform_get_drvdata(pdev);
193 struct msm_drm_private *priv = ddev->dev_private;
Rob Clarkc8afe682013-06-26 12:44:06 -0400194 struct msm_kms *kms = priv->kms;
Rob Clark7198e6b2013-07-19 12:59:32 -0400195 struct msm_gpu *gpu = priv->gpu;
Hai Li78b1d472015-07-27 13:49:45 -0400196 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
197 struct vblank_event *vbl_ev, *tmp;
198
199 /* We must cancel and cleanup any pending vblank enable/disable
200 * work before drm_irq_uninstall() to avoid work re-enabling an
201 * irq after uninstall has disabled it.
202 */
203 cancel_work_sync(&vbl_ctrl->work);
204 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
205 list_del(&vbl_ev->node);
206 kfree(vbl_ev);
207 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400208
Rob Clark68209392016-05-17 16:19:32 -0400209 msm_gem_shrinker_cleanup(ddev);
210
Archit Taneja2b669872016-05-02 11:05:54 +0530211 drm_kms_helper_poll_fini(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530212
Archit Taneja2b669872016-05-02 11:05:54 +0530213 drm_dev_unregister(ddev);
Archit Taneja8208ed92016-05-02 11:05:53 +0530214
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530215#ifdef CONFIG_DRM_FBDEV_EMULATION
216 if (fbdev && priv->fbdev)
Archit Taneja2b669872016-05-02 11:05:54 +0530217 msm_fbdev_free(ddev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530218#endif
Archit Taneja2b669872016-05-02 11:05:54 +0530219 drm_mode_config_cleanup(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400220
Archit Taneja2b669872016-05-02 11:05:54 +0530221 pm_runtime_get_sync(dev);
222 drm_irq_uninstall(ddev);
223 pm_runtime_put_sync(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400224
225 flush_workqueue(priv->wq);
226 destroy_workqueue(priv->wq);
227
Rob Clarkba00c3f2016-03-16 18:18:17 -0400228 flush_workqueue(priv->atomic_wq);
229 destroy_workqueue(priv->atomic_wq);
230
Archit Taneja16976082016-11-03 17:36:18 +0530231 if (kms && kms->funcs)
Rob Clarkc8afe682013-06-26 12:44:06 -0400232 kms->funcs->destroy(kms);
Rob Clarkc8afe682013-06-26 12:44:06 -0400233
Rob Clark7198e6b2013-07-19 12:59:32 -0400234 if (gpu) {
Archit Taneja2b669872016-05-02 11:05:54 +0530235 mutex_lock(&ddev->struct_mutex);
Rob Clark7198e6b2013-07-19 12:59:32 -0400236 gpu->funcs->pm_suspend(gpu);
Archit Taneja2b669872016-05-02 11:05:54 +0530237 mutex_unlock(&ddev->struct_mutex);
Rob Clark774449e2015-05-15 09:19:36 -0400238 gpu->funcs->destroy(gpu);
Rob Clark7198e6b2013-07-19 12:59:32 -0400239 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400240
Rob Clark871d8122013-11-16 12:56:06 -0500241 if (priv->vram.paddr) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700242 unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
Rob Clark871d8122013-11-16 12:56:06 -0500243 drm_mm_takedown(&priv->vram.mm);
Archit Taneja2b669872016-05-02 11:05:54 +0530244 dma_free_attrs(dev, priv->vram.size, NULL,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700245 priv->vram.paddr, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500246 }
247
Archit Taneja2b669872016-05-02 11:05:54 +0530248 component_unbind_all(dev, ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500249
Archit Taneja0a6030d2016-05-08 21:36:28 +0530250 msm_mdss_destroy(ddev);
251
Archit Taneja2b669872016-05-02 11:05:54 +0530252 ddev->dev_private = NULL;
253 drm_dev_unref(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400254
255 kfree(priv);
256
257 return 0;
258}
259
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700260#define KMS_MDP4 0
261#define KMS_MDP5 1
262#define KMS_SDE 2
263
Rob Clark06c0dd92013-11-30 17:51:47 -0500264static int get_mdp_ver(struct platform_device *pdev)
265{
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700266#ifdef CONFIG_OF
267 static const struct of_device_id match_types[] = { {
268 .compatible = "qcom,mdss_mdp",
269 .data = (void *)KMS_MDP5,
270 },
271 {
272 .compatible = "qcom,sde-kms",
273 .data = (void *)KMS_SDE,
274 /* end node */
275 } };
Rob Clark06c0dd92013-11-30 17:51:47 -0500276 struct device *dev = &pdev->dev;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700277 const struct of_device_id *match;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530278
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700279 match = of_match_node(match_types, dev->of_node);
280 if (match)
281 return (int)(unsigned long)match->data;
282#endif
283 return KMS_MDP4;
Rob Clark06c0dd92013-11-30 17:51:47 -0500284}
285
Rob Clark072f1f92015-03-03 15:04:25 -0500286#include <linux/of_address.h>
287
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500288static int msm_init_vram(struct drm_device *dev)
Rob Clarkc8afe682013-06-26 12:44:06 -0400289{
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500290 struct msm_drm_private *priv = dev->dev_private;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530291 struct device_node *node;
Rob Clark072f1f92015-03-03 15:04:25 -0500292 unsigned long size = 0;
293 int ret = 0;
294
Rob Clark072f1f92015-03-03 15:04:25 -0500295 /* In the device-tree world, we could have a 'memory-region'
296 * phandle, which gives us a link to our "vram". Allocating
297 * is all nicely abstracted behind the dma api, but we need
298 * to know the entire size to allocate it all in one go. There
299 * are two cases:
300 * 1) device with no IOMMU, in which case we need exclusive
301 * access to a VRAM carveout big enough for all gpu
302 * buffers
303 * 2) device with IOMMU, but where the bootloader puts up
304 * a splash screen. In this case, the VRAM carveout
305 * need only be large enough for fbdev fb. But we need
306 * exclusive access to the buffer to avoid the kernel
307 * using those pages for other purposes (which appears
308 * as corruption on screen before we have a chance to
309 * load and do initial modeset)
310 */
Rob Clark072f1f92015-03-03 15:04:25 -0500311
312 node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
313 if (node) {
314 struct resource r;
315 ret = of_address_to_resource(node, 0, &r);
Peter Chen2ca41c172016-07-04 16:49:50 +0800316 of_node_put(node);
Rob Clark072f1f92015-03-03 15:04:25 -0500317 if (ret)
318 return ret;
319 size = r.end - r.start;
Thierry Redingfc99f972015-04-09 16:39:51 +0200320 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
Rob Clarkc8afe682013-06-26 12:44:06 -0400321
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530322 /* if we have no IOMMU, then we need to use carveout allocator.
323 * Grab the entire CMA chunk carved out in early startup in
324 * mach-msm:
325 */
326 } else if (!iommu_present(&platform_bus_type)) {
Rob Clark072f1f92015-03-03 15:04:25 -0500327 DRM_INFO("using %s VRAM carveout\n", vram);
328 size = memparse(vram, NULL);
329 }
330
331 if (size) {
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700332 unsigned long attrs = 0;
Rob Clark871d8122013-11-16 12:56:06 -0500333 void *p;
334
Rob Clark871d8122013-11-16 12:56:06 -0500335 priv->vram.size = size;
336
337 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
338
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700339 attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
340 attrs |= DMA_ATTR_WRITE_COMBINE;
Rob Clark871d8122013-11-16 12:56:06 -0500341
342 /* note that for no-kernel-mapping, the vaddr returned
343 * is bogus, but non-null if allocation succeeded:
344 */
345 p = dma_alloc_attrs(dev->dev, size,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -0700346 &priv->vram.paddr, GFP_KERNEL, attrs);
Rob Clark871d8122013-11-16 12:56:06 -0500347 if (!p) {
348 dev_err(dev->dev, "failed to allocate VRAM\n");
349 priv->vram.paddr = 0;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500350 return -ENOMEM;
Rob Clark871d8122013-11-16 12:56:06 -0500351 }
352
353 dev_info(dev->dev, "VRAM: %08x->%08x\n",
354 (uint32_t)priv->vram.paddr,
355 (uint32_t)(priv->vram.paddr + size));
356 }
357
Rob Clark072f1f92015-03-03 15:04:25 -0500358 return ret;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500359}
360
Archit Taneja2b669872016-05-02 11:05:54 +0530361static int msm_drm_init(struct device *dev, struct drm_driver *drv)
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500362{
Archit Taneja2b669872016-05-02 11:05:54 +0530363 struct platform_device *pdev = to_platform_device(dev);
364 struct drm_device *ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500365 struct msm_drm_private *priv;
366 struct msm_kms *kms;
367 int ret;
368
Archit Taneja2b669872016-05-02 11:05:54 +0530369 ddev = drm_dev_alloc(drv, dev);
Tom Gundersen0f288602016-09-21 16:59:19 +0200370 if (IS_ERR(ddev)) {
Archit Taneja2b669872016-05-02 11:05:54 +0530371 dev_err(dev, "failed to allocate drm_device\n");
Tom Gundersen0f288602016-09-21 16:59:19 +0200372 return PTR_ERR(ddev);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500373 }
374
Archit Taneja2b669872016-05-02 11:05:54 +0530375 platform_set_drvdata(pdev, ddev);
376 ddev->platformdev = pdev;
377
378 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
379 if (!priv) {
380 drm_dev_unref(ddev);
381 return -ENOMEM;
382 }
383
384 ddev->dev_private = priv;
Rob Clark68209392016-05-17 16:19:32 -0400385 priv->dev = ddev;
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500386
Archit Taneja0a6030d2016-05-08 21:36:28 +0530387 ret = msm_mdss_init(ddev);
388 if (ret) {
389 kfree(priv);
390 drm_dev_unref(ddev);
391 return ret;
392 }
393
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500394 priv->wq = alloc_ordered_workqueue("msm", 0);
Rob Clarkba00c3f2016-03-16 18:18:17 -0400395 priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500396 init_waitqueue_head(&priv->pending_crtcs_event);
397
398 INIT_LIST_HEAD(&priv->inactive_list);
Hai Li78b1d472015-07-27 13:49:45 -0400399 INIT_LIST_HEAD(&priv->vblank_ctrl.event_list);
400 INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker);
401 spin_lock_init(&priv->vblank_ctrl.lock);
Rob Clark5bf9c0b2015-03-03 15:04:24 -0500402
Archit Taneja2b669872016-05-02 11:05:54 +0530403 drm_mode_config_init(ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500404
405 /* Bind all our sub-components: */
Archit Taneja2b669872016-05-02 11:05:54 +0530406 ret = component_bind_all(dev, ddev);
407 if (ret) {
Archit Taneja0a6030d2016-05-08 21:36:28 +0530408 msm_mdss_destroy(ddev);
Archit Taneja2b669872016-05-02 11:05:54 +0530409 kfree(priv);
410 drm_dev_unref(ddev);
Rob Clark060530f2014-03-03 14:19:12 -0500411 return ret;
Archit Taneja2b669872016-05-02 11:05:54 +0530412 }
Rob Clark060530f2014-03-03 14:19:12 -0500413
Archit Taneja2b669872016-05-02 11:05:54 +0530414 ret = msm_init_vram(ddev);
Rob Clark13f15562015-05-07 15:20:13 -0400415 if (ret)
416 goto fail;
417
Rob Clark68209392016-05-17 16:19:32 -0400418 msm_gem_shrinker_init(ddev);
419
Rob Clark06c0dd92013-11-30 17:51:47 -0500420 switch (get_mdp_ver(pdev)) {
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700421 case KMS_MDP4:
422 kms = mdp4_kms_init(dev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500423 break;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700424 case KMS_MDP5:
425 kms = mdp5_kms_init(dev);
426 break;
427 case KMS_SDE:
428 kms = sde_kms_init(dev);
Rob Clark06c0dd92013-11-30 17:51:47 -0500429 break;
430 default:
431 kms = ERR_PTR(-ENODEV);
432 break;
433 }
434
Rob Clarkc8afe682013-06-26 12:44:06 -0400435 if (IS_ERR(kms)) {
436 /*
437 * NOTE: once we have GPU support, having no kms should not
438 * be considered fatal.. ideally we would still support gpu
439 * and (for example) use dmabuf/prime to share buffers with
440 * imx drm driver on iMX5
441 */
Archit Taneja2b669872016-05-02 11:05:54 +0530442 dev_err(dev, "failed to load kms\n");
Thomas Meyere4826a92013-09-16 23:19:54 +0200443 ret = PTR_ERR(kms);
Rob Clarkc8afe682013-06-26 12:44:06 -0400444 goto fail;
445 }
446
Rob Clarkc8afe682013-06-26 12:44:06 -0400447 if (kms) {
Rob Clarkc8afe682013-06-26 12:44:06 -0400448 ret = kms->funcs->hw_init(kms);
449 if (ret) {
Archit Taneja2b669872016-05-02 11:05:54 +0530450 dev_err(dev, "kms hw init failed: %d\n", ret);
Rob Clarkc8afe682013-06-26 12:44:06 -0400451 goto fail;
452 }
453 }
454
Archit Taneja2b669872016-05-02 11:05:54 +0530455 ddev->mode_config.funcs = &mode_config_funcs;
Rob Clarkc8afe682013-06-26 12:44:06 -0400456
Archit Taneja2b669872016-05-02 11:05:54 +0530457 ret = drm_vblank_init(ddev, priv->num_crtcs);
Rob Clarkc8afe682013-06-26 12:44:06 -0400458 if (ret < 0) {
Archit Taneja2b669872016-05-02 11:05:54 +0530459 dev_err(dev, "failed to initialize vblank\n");
Rob Clarkc8afe682013-06-26 12:44:06 -0400460 goto fail;
461 }
462
Archit Tanejaa2b3a552016-05-18 15:06:03 +0530463 if (kms) {
464 pm_runtime_get_sync(dev);
465 ret = drm_irq_install(ddev, kms->irq);
466 pm_runtime_put_sync(dev);
467 if (ret < 0) {
468 dev_err(dev, "failed to install IRQ handler\n");
469 goto fail;
470 }
Rob Clarkc8afe682013-06-26 12:44:06 -0400471 }
472
Archit Taneja2b669872016-05-02 11:05:54 +0530473 ret = drm_dev_register(ddev, 0);
Rob Clarka7d3c952014-05-30 14:47:38 -0400474 if (ret)
475 goto fail;
476
Archit Taneja2b669872016-05-02 11:05:54 +0530477 drm_mode_config_reset(ddev);
478
479#ifdef CONFIG_DRM_FBDEV_EMULATION
480 if (fbdev)
481 priv->fbdev = msm_fbdev_init(ddev);
482#endif
483
484 ret = msm_debugfs_late_init(ddev);
485 if (ret)
486 goto fail;
487
488 drm_kms_helper_poll_init(ddev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400489
490 return 0;
491
492fail:
Archit Taneja2b669872016-05-02 11:05:54 +0530493 msm_drm_uninit(dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400494 return ret;
495}
496
Archit Taneja2b669872016-05-02 11:05:54 +0530497/*
498 * DRM operations:
499 */
500
Rob Clark7198e6b2013-07-19 12:59:32 -0400501static void load_gpu(struct drm_device *dev)
502{
Rob Clarka1ad3522014-07-11 11:59:22 -0400503 static DEFINE_MUTEX(init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400504 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400505
Rob Clarka1ad3522014-07-11 11:59:22 -0400506 mutex_lock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400507
Rob Clarke2550b72014-09-05 13:30:27 -0400508 if (!priv->gpu)
509 priv->gpu = adreno_load_gpu(dev);
Rob Clarka1ad3522014-07-11 11:59:22 -0400510
Rob Clarka1ad3522014-07-11 11:59:22 -0400511 mutex_unlock(&init_lock);
Rob Clark7198e6b2013-07-19 12:59:32 -0400512}
513
514static int msm_open(struct drm_device *dev, struct drm_file *file)
515{
516 struct msm_file_private *ctx;
517
518 /* For now, load gpu on open.. to avoid the requirement of having
519 * firmware in the initrd.
520 */
521 load_gpu(dev);
522
523 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
524 if (!ctx)
525 return -ENOMEM;
526
527 file->driver_priv = ctx;
528
529 return 0;
530}
531
Rob Clarkc8afe682013-06-26 12:44:06 -0400532static void msm_preclose(struct drm_device *dev, struct drm_file *file)
533{
534 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400535 struct msm_file_private *ctx = file->driver_priv;
Rob Clark7198e6b2013-07-19 12:59:32 -0400536
Rob Clark7198e6b2013-07-19 12:59:32 -0400537 mutex_lock(&dev->struct_mutex);
538 if (ctx == priv->lastctx)
539 priv->lastctx = NULL;
540 mutex_unlock(&dev->struct_mutex);
541
542 kfree(ctx);
Rob Clarkc8afe682013-06-26 12:44:06 -0400543}
544
545static void msm_lastclose(struct drm_device *dev)
546{
547 struct msm_drm_private *priv = dev->dev_private;
Rob Clark5ea1f752014-05-30 12:29:48 -0400548 if (priv->fbdev)
549 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400550}
551
Daniel Vettere9f0d762013-12-11 11:34:42 +0100552static irqreturn_t msm_irq(int irq, void *arg)
Rob Clarkc8afe682013-06-26 12:44:06 -0400553{
554 struct drm_device *dev = arg;
555 struct msm_drm_private *priv = dev->dev_private;
556 struct msm_kms *kms = priv->kms;
557 BUG_ON(!kms);
558 return kms->funcs->irq(kms);
559}
560
561static void msm_irq_preinstall(struct drm_device *dev)
562{
563 struct msm_drm_private *priv = dev->dev_private;
564 struct msm_kms *kms = priv->kms;
565 BUG_ON(!kms);
566 kms->funcs->irq_preinstall(kms);
567}
568
569static int msm_irq_postinstall(struct drm_device *dev)
570{
571 struct msm_drm_private *priv = dev->dev_private;
572 struct msm_kms *kms = priv->kms;
573 BUG_ON(!kms);
574 return kms->funcs->irq_postinstall(kms);
575}
576
577static void msm_irq_uninstall(struct drm_device *dev)
578{
579 struct msm_drm_private *priv = dev->dev_private;
580 struct msm_kms *kms = priv->kms;
581 BUG_ON(!kms);
582 kms->funcs->irq_uninstall(kms);
583}
584
Thierry Reding88e72712015-09-24 18:35:31 +0200585static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400586{
587 struct msm_drm_private *priv = dev->dev_private;
588 struct msm_kms *kms = priv->kms;
589 if (!kms)
590 return -ENXIO;
Thierry Reding88e72712015-09-24 18:35:31 +0200591 DBG("dev=%p, crtc=%u", dev, pipe);
592 return vblank_ctrl_queue_work(priv, pipe, true);
Rob Clarkc8afe682013-06-26 12:44:06 -0400593}
594
Thierry Reding88e72712015-09-24 18:35:31 +0200595static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
Rob Clarkc8afe682013-06-26 12:44:06 -0400596{
597 struct msm_drm_private *priv = dev->dev_private;
598 struct msm_kms *kms = priv->kms;
599 if (!kms)
600 return;
Thierry Reding88e72712015-09-24 18:35:31 +0200601 DBG("dev=%p, crtc=%u", dev, pipe);
602 vblank_ctrl_queue_work(priv, pipe, false);
Rob Clarkc8afe682013-06-26 12:44:06 -0400603}
604
605/*
Rob Clark7198e6b2013-07-19 12:59:32 -0400606 * DRM ioctls:
607 */
608
609static int msm_ioctl_get_param(struct drm_device *dev, void *data,
610 struct drm_file *file)
611{
612 struct msm_drm_private *priv = dev->dev_private;
613 struct drm_msm_param *args = data;
614 struct msm_gpu *gpu;
615
616 /* for now, we just have 3d pipe.. eventually this would need to
617 * be more clever to dispatch to appropriate gpu module:
618 */
619 if (args->pipe != MSM_PIPE_3D0)
620 return -EINVAL;
621
622 gpu = priv->gpu;
623
624 if (!gpu)
625 return -ENXIO;
626
627 return gpu->funcs->get_param(gpu, args->param, &args->value);
628}
629
630static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
631 struct drm_file *file)
632{
633 struct drm_msm_gem_new *args = data;
Rob Clark93ddb0d2014-03-03 09:42:33 -0500634
635 if (args->flags & ~MSM_BO_FLAGS) {
636 DRM_ERROR("invalid flags: %08x\n", args->flags);
637 return -EINVAL;
638 }
639
Rob Clark7198e6b2013-07-19 12:59:32 -0400640 return msm_gem_new_handle(dev, file, args->size,
641 args->flags, &args->handle);
642}
643
Rob Clark56c2da82015-05-11 11:50:03 -0400644static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
645{
646 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
647}
Rob Clark7198e6b2013-07-19 12:59:32 -0400648
649static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
650 struct drm_file *file)
651{
652 struct drm_msm_gem_cpu_prep *args = data;
653 struct drm_gem_object *obj;
Rob Clark56c2da82015-05-11 11:50:03 -0400654 ktime_t timeout = to_ktime(args->timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400655 int ret;
656
Rob Clark93ddb0d2014-03-03 09:42:33 -0500657 if (args->op & ~MSM_PREP_FLAGS) {
658 DRM_ERROR("invalid op: %08x\n", args->op);
659 return -EINVAL;
660 }
661
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100662 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400663 if (!obj)
664 return -ENOENT;
665
Rob Clark56c2da82015-05-11 11:50:03 -0400666 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400667
668 drm_gem_object_unreference_unlocked(obj);
669
670 return ret;
671}
672
673static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
674 struct drm_file *file)
675{
676 struct drm_msm_gem_cpu_fini *args = data;
677 struct drm_gem_object *obj;
678 int ret;
679
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100680 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400681 if (!obj)
682 return -ENOENT;
683
684 ret = msm_gem_cpu_fini(obj);
685
686 drm_gem_object_unreference_unlocked(obj);
687
688 return ret;
689}
690
691static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
692 struct drm_file *file)
693{
694 struct drm_msm_gem_info *args = data;
695 struct drm_gem_object *obj;
696 int ret = 0;
697
698 if (args->pad)
699 return -EINVAL;
700
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100701 obj = drm_gem_object_lookup(file, args->handle);
Rob Clark7198e6b2013-07-19 12:59:32 -0400702 if (!obj)
703 return -ENOENT;
704
705 args->offset = msm_gem_mmap_offset(obj);
706
707 drm_gem_object_unreference_unlocked(obj);
708
709 return ret;
710}
711
712static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
713 struct drm_file *file)
714{
Rob Clarkca762a82016-03-15 17:22:13 -0400715 struct msm_drm_private *priv = dev->dev_private;
Rob Clark7198e6b2013-07-19 12:59:32 -0400716 struct drm_msm_wait_fence *args = data;
Rob Clark56c2da82015-05-11 11:50:03 -0400717 ktime_t timeout = to_ktime(args->timeout);
Rob Clark93ddb0d2014-03-03 09:42:33 -0500718
719 if (args->pad) {
720 DRM_ERROR("invalid pad: %08x\n", args->pad);
721 return -EINVAL;
722 }
723
Rob Clarkca762a82016-03-15 17:22:13 -0400724 if (!priv->gpu)
725 return 0;
726
727 return msm_wait_fence(priv->gpu->fctx, args->fence, &timeout, true);
Rob Clark7198e6b2013-07-19 12:59:32 -0400728}
729
Rob Clark4cd33c42016-05-17 15:44:49 -0400730static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
731 struct drm_file *file)
732{
733 struct drm_msm_gem_madvise *args = data;
734 struct drm_gem_object *obj;
735 int ret;
736
737 switch (args->madv) {
738 case MSM_MADV_DONTNEED:
739 case MSM_MADV_WILLNEED:
740 break;
741 default:
742 return -EINVAL;
743 }
744
745 ret = mutex_lock_interruptible(&dev->struct_mutex);
746 if (ret)
747 return ret;
748
749 obj = drm_gem_object_lookup(file, args->handle);
750 if (!obj) {
751 ret = -ENOENT;
752 goto unlock;
753 }
754
755 ret = msm_gem_madvise(obj, args->madv);
756 if (ret >= 0) {
757 args->retained = ret;
758 ret = 0;
759 }
760
761 drm_gem_object_unreference(obj);
762
763unlock:
764 mutex_unlock(&dev->struct_mutex);
765 return ret;
766}
767
Rob Clark7198e6b2013-07-19 12:59:32 -0400768static const struct drm_ioctl_desc msm_ioctls[] = {
Daniel Vetterf8c47142015-09-08 13:56:30 +0200769 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW),
770 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
771 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW),
772 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
773 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
774 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW),
775 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark4cd33c42016-05-17 15:44:49 -0400776 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
Rob Clark7198e6b2013-07-19 12:59:32 -0400777};
778
Rob Clarkc8afe682013-06-26 12:44:06 -0400779static const struct vm_operations_struct vm_ops = {
780 .fault = msm_gem_fault,
781 .open = drm_gem_vm_open,
782 .close = drm_gem_vm_close,
783};
784
785static const struct file_operations fops = {
786 .owner = THIS_MODULE,
787 .open = drm_open,
788 .release = drm_release,
789 .unlocked_ioctl = drm_ioctl,
790#ifdef CONFIG_COMPAT
791 .compat_ioctl = drm_compat_ioctl,
792#endif
793 .poll = drm_poll,
794 .read = drm_read,
795 .llseek = no_llseek,
796 .mmap = msm_gem_mmap,
797};
798
799static struct drm_driver msm_driver = {
Rob Clark05b84912013-09-28 11:28:35 -0400800 .driver_features = DRIVER_HAVE_IRQ |
801 DRIVER_GEM |
802 DRIVER_PRIME |
Rob Clarkb4b15c82013-09-28 12:01:25 -0400803 DRIVER_RENDER |
Rob Clarka5436e12015-06-04 10:12:22 -0400804 DRIVER_ATOMIC |
Rob Clark05b84912013-09-28 11:28:35 -0400805 DRIVER_MODESET,
Rob Clark7198e6b2013-07-19 12:59:32 -0400806 .open = msm_open,
Rob Clarkc8afe682013-06-26 12:44:06 -0400807 .preclose = msm_preclose,
808 .lastclose = msm_lastclose,
809 .irq_handler = msm_irq,
810 .irq_preinstall = msm_irq_preinstall,
811 .irq_postinstall = msm_irq_postinstall,
812 .irq_uninstall = msm_irq_uninstall,
Ville Syrjäläb44f8402015-09-30 16:46:48 +0300813 .get_vblank_counter = drm_vblank_no_hw_counter,
Rob Clarkc8afe682013-06-26 12:44:06 -0400814 .enable_vblank = msm_enable_vblank,
815 .disable_vblank = msm_disable_vblank,
816 .gem_free_object = msm_gem_free_object,
817 .gem_vm_ops = &vm_ops,
818 .dumb_create = msm_gem_dumb_create,
819 .dumb_map_offset = msm_gem_dumb_map_offset,
Rob Clark30600a9092013-09-28 10:13:04 -0400820 .dumb_destroy = drm_gem_dumb_destroy,
Rob Clark05b84912013-09-28 11:28:35 -0400821 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
822 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
823 .gem_prime_export = drm_gem_prime_export,
824 .gem_prime_import = drm_gem_prime_import,
825 .gem_prime_pin = msm_gem_prime_pin,
826 .gem_prime_unpin = msm_gem_prime_unpin,
827 .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
828 .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
829 .gem_prime_vmap = msm_gem_prime_vmap,
830 .gem_prime_vunmap = msm_gem_prime_vunmap,
Daniel Thompson77a147e2014-11-12 11:38:14 +0000831 .gem_prime_mmap = msm_gem_prime_mmap,
Rob Clarkc8afe682013-06-26 12:44:06 -0400832#ifdef CONFIG_DEBUG_FS
833 .debugfs_init = msm_debugfs_init,
834 .debugfs_cleanup = msm_debugfs_cleanup,
835#endif
Rob Clark7198e6b2013-07-19 12:59:32 -0400836 .ioctls = msm_ioctls,
837 .num_ioctls = DRM_MSM_NUM_IOCTLS,
Rob Clarkc8afe682013-06-26 12:44:06 -0400838 .fops = &fops,
839 .name = "msm",
840 .desc = "MSM Snapdragon DRM",
841 .date = "20130625",
Rob Clarka8d854c2016-06-01 14:02:02 -0400842 .major = MSM_VERSION_MAJOR,
843 .minor = MSM_VERSION_MINOR,
844 .patchlevel = MSM_VERSION_PATCHLEVEL,
Rob Clarkc8afe682013-06-26 12:44:06 -0400845};
846
847#ifdef CONFIG_PM_SLEEP
848static int msm_pm_suspend(struct device *dev)
849{
850 struct drm_device *ddev = dev_get_drvdata(dev);
851
852 drm_kms_helper_poll_disable(ddev);
853
854 return 0;
855}
856
857static int msm_pm_resume(struct device *dev)
858{
859 struct drm_device *ddev = dev_get_drvdata(dev);
860
861 drm_kms_helper_poll_enable(ddev);
862
863 return 0;
864}
865#endif
866
867static const struct dev_pm_ops msm_pm_ops = {
868 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
869};
870
871/*
Rob Clark060530f2014-03-03 14:19:12 -0500872 * Componentized driver support:
873 */
874
Archit Tanejae9fbdaf2015-11-18 12:15:14 +0530875/*
876 * NOTE: duplication of the same code as exynos or imx (or probably any other).
877 * so probably some room for some helpers
Rob Clark060530f2014-03-03 14:19:12 -0500878 */
879static int compare_of(struct device *dev, void *data)
880{
881 return dev->of_node == data;
882}
Rob Clark41e69772013-12-15 16:23:05 -0500883
Archit Taneja812070e2016-05-19 10:38:39 +0530884/*
885 * Identify what components need to be added by parsing what remote-endpoints
886 * our MDP output ports are connected to. In the case of LVDS on MDP4, there
887 * is no external component that we need to add since LVDS is within MDP4
888 * itself.
889 */
890static int add_components_mdp(struct device *mdp_dev,
891 struct component_match **matchptr)
892{
893 struct device_node *np = mdp_dev->of_node;
894 struct device_node *ep_node;
Archit Taneja54011e22016-06-06 13:45:34 +0530895 struct device *master_dev;
896
897 /*
898 * on MDP4 based platforms, the MDP platform device is the component
899 * master that adds other display interface components to itself.
900 *
901 * on MDP5 based platforms, the MDSS platform device is the component
902 * master that adds MDP5 and other display interface components to
903 * itself.
904 */
905 if (of_device_is_compatible(np, "qcom,mdp4"))
906 master_dev = mdp_dev;
907 else
908 master_dev = mdp_dev->parent;
Archit Taneja812070e2016-05-19 10:38:39 +0530909
910 for_each_endpoint_of_node(np, ep_node) {
911 struct device_node *intf;
912 struct of_endpoint ep;
913 int ret;
914
915 ret = of_graph_parse_endpoint(ep_node, &ep);
916 if (ret) {
917 dev_err(mdp_dev, "unable to parse port endpoint\n");
918 of_node_put(ep_node);
919 return ret;
920 }
921
922 /*
923 * The LCDC/LVDS port on MDP4 is a speacial case where the
924 * remote-endpoint isn't a component that we need to add
925 */
926 if (of_device_is_compatible(np, "qcom,mdp4") &&
927 ep.port == 0) {
928 of_node_put(ep_node);
929 continue;
930 }
931
932 /*
933 * It's okay if some of the ports don't have a remote endpoint
934 * specified. It just means that the port isn't connected to
935 * any external interface.
936 */
937 intf = of_graph_get_remote_port_parent(ep_node);
938 if (!intf) {
939 of_node_put(ep_node);
940 continue;
941 }
942
Archit Taneja54011e22016-06-06 13:45:34 +0530943 component_match_add(master_dev, matchptr, compare_of, intf);
Archit Taneja812070e2016-05-19 10:38:39 +0530944
945 of_node_put(intf);
946 of_node_put(ep_node);
947 }
948
949 return 0;
950}
951
Archit Taneja54011e22016-06-06 13:45:34 +0530952static int compare_name_mdp(struct device *dev, void *data)
953{
954 return (strstr(dev_name(dev), "mdp") != NULL);
955}
956
Archit Taneja7d526fc2016-05-19 10:33:57 +0530957static int add_display_components(struct device *dev,
958 struct component_match **matchptr)
959{
Archit Taneja54011e22016-06-06 13:45:34 +0530960 struct device *mdp_dev;
961 int ret;
962
963 /*
964 * MDP5 based devices don't have a flat hierarchy. There is a top level
965 * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
966 * children devices, find the MDP5 node, and then add the interfaces
967 * to our components list.
968 */
969 if (of_device_is_compatible(dev->of_node, "qcom,mdss")) {
970 ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
971 if (ret) {
972 dev_err(dev, "failed to populate children devices\n");
973 return ret;
974 }
975
976 mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
977 if (!mdp_dev) {
978 dev_err(dev, "failed to find MDSS MDP node\n");
979 of_platform_depopulate(dev);
980 return -ENODEV;
981 }
982
983 put_device(mdp_dev);
984
985 /* add the MDP component itself */
986 component_match_add(dev, matchptr, compare_of,
987 mdp_dev->of_node);
988 } else {
989 /* MDP4 */
990 mdp_dev = dev;
991 }
992
993 ret = add_components_mdp(mdp_dev, matchptr);
994 if (ret)
995 of_platform_depopulate(dev);
996
997 return ret;
Archit Taneja7d526fc2016-05-19 10:33:57 +0530998}
999
Archit Tanejadc3ea262016-05-19 13:33:52 +05301000/*
1001 * We don't know what's the best binding to link the gpu with the drm device.
1002 * Fow now, we just hunt for all the possible gpus that we support, and add them
1003 * as components.
1004 */
1005static const struct of_device_id msm_gpu_match[] = {
1006 { .compatible = "qcom,adreno-3xx" },
1007 { .compatible = "qcom,kgsl-3d0" },
1008 { },
1009};
1010
Archit Taneja7d526fc2016-05-19 10:33:57 +05301011static int add_gpu_components(struct device *dev,
1012 struct component_match **matchptr)
1013{
Archit Tanejadc3ea262016-05-19 13:33:52 +05301014 struct device_node *np;
1015
1016 np = of_find_matching_node(NULL, msm_gpu_match);
1017 if (!np)
1018 return 0;
1019
1020 component_match_add(dev, matchptr, compare_of, np);
1021
1022 of_node_put(np);
1023
1024 return 0;
Archit Taneja7d526fc2016-05-19 10:33:57 +05301025}
1026
Russell King84448282014-04-19 11:20:42 +01001027static int msm_drm_bind(struct device *dev)
1028{
Archit Taneja2b669872016-05-02 11:05:54 +05301029 return msm_drm_init(dev, &msm_driver);
Russell King84448282014-04-19 11:20:42 +01001030}
1031
1032static void msm_drm_unbind(struct device *dev)
1033{
Archit Taneja2b669872016-05-02 11:05:54 +05301034 msm_drm_uninit(dev);
Russell King84448282014-04-19 11:20:42 +01001035}
1036
1037static const struct component_master_ops msm_drm_ops = {
1038 .bind = msm_drm_bind,
1039 .unbind = msm_drm_unbind,
1040};
1041
1042/*
1043 * Platform driver:
1044 */
1045
1046static int msm_pdev_probe(struct platform_device *pdev)
1047{
1048 struct component_match *match = NULL;
Archit Taneja7d526fc2016-05-19 10:33:57 +05301049 int ret;
Archit Tanejae9fbdaf2015-11-18 12:15:14 +05301050
Archit Taneja7d526fc2016-05-19 10:33:57 +05301051 ret = add_display_components(&pdev->dev, &match);
1052 if (ret)
1053 return ret;
1054
1055 ret = add_gpu_components(&pdev->dev, &match);
1056 if (ret)
1057 return ret;
Rob Clark060530f2014-03-03 14:19:12 -05001058
Rob Clark871d8122013-11-16 12:56:06 -05001059 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
Russell King84448282014-04-19 11:20:42 +01001060 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
Rob Clarkc8afe682013-06-26 12:44:06 -04001061}
1062
1063static int msm_pdev_remove(struct platform_device *pdev)
1064{
Rob Clark060530f2014-03-03 14:19:12 -05001065 component_master_del(&pdev->dev, &msm_drm_ops);
Archit Taneja54011e22016-06-06 13:45:34 +05301066 of_platform_depopulate(&pdev->dev);
Rob Clarkc8afe682013-06-26 12:44:06 -04001067
1068 return 0;
1069}
1070
Rob Clark06c0dd92013-11-30 17:51:47 -05001071static const struct of_device_id dt_match[] = {
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07001072 { .compatible = "qcom,mdp" }, /* mdp4 */
1073 { .compatible = "qcom,mdss_mdp" }, /* mdp5 */
1074 { .compatible = "qcom,sde-kms" }, /* sde */
Rob Clark06c0dd92013-11-30 17:51:47 -05001075 {}
1076};
1077MODULE_DEVICE_TABLE(of, dt_match);
1078
Rob Clarkc8afe682013-06-26 12:44:06 -04001079static struct platform_driver msm_platform_driver = {
1080 .probe = msm_pdev_probe,
1081 .remove = msm_pdev_remove,
1082 .driver = {
Rob Clarkc8afe682013-06-26 12:44:06 -04001083 .name = "msm",
Rob Clark06c0dd92013-11-30 17:51:47 -05001084 .of_match_table = dt_match,
Rob Clarkc8afe682013-06-26 12:44:06 -04001085 .pm = &msm_pm_ops,
1086 },
Rob Clarkc8afe682013-06-26 12:44:06 -04001087};
1088
1089static int __init msm_drm_register(void)
1090{
1091 DBG("init");
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301092 msm_mdp_register();
Hai Lid5af49c2015-03-26 19:25:17 -04001093 msm_dsi_register();
Hai Li00453982014-12-12 14:41:17 -05001094 msm_edp_register();
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001095 msm_hdmi_register();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001096 adreno_register();
Rob Clarkc8afe682013-06-26 12:44:06 -04001097 return platform_driver_register(&msm_platform_driver);
1098}
1099
1100static void __exit msm_drm_unregister(void)
1101{
1102 DBG("fini");
1103 platform_driver_unregister(&msm_platform_driver);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +01001104 msm_hdmi_unregister();
Rob Clarkbfd28b12014-09-05 13:06:37 -04001105 adreno_unregister();
Hai Li00453982014-12-12 14:41:17 -05001106 msm_edp_unregister();
Hai Lid5af49c2015-03-26 19:25:17 -04001107 msm_dsi_unregister();
Archit Taneja1dd0a0b2016-05-30 16:36:50 +05301108 msm_mdp_unregister();
Rob Clarkc8afe682013-06-26 12:44:06 -04001109}
1110
1111module_init(msm_drm_register);
1112module_exit(msm_drm_unregister);
1113
1114MODULE_AUTHOR("Rob Clark <robdclark@gmail.com");
1115MODULE_DESCRIPTION("MSM DRM Driver");
1116MODULE_LICENSE("GPL");