blob: c2db409bbd63d90a0504e8d9377d52ce747e11e4 [file] [log] [blame]
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001/*
2 * Copyright (C) 2012 Avionic Design GmbH
Terje Bergstromd43f81c2013-03-22 16:34:09 +02003 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00004 *
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
Thierry Reding776dc382013-10-14 14:43:22 +020010#include <linux/host1x.h>
11
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000012#include "drm.h"
Arto Merilainende2ba662013-03-22 16:34:08 +020013#include "gem.h"
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000014
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
Thierry Reding08943e62013-09-26 16:08:18 +020022struct tegra_drm_file {
23 struct list_head contexts;
24};
25
Thierry Reding776dc382013-10-14 14:43:22 +020026static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000027{
Thierry Reding776dc382013-10-14 14:43:22 +020028 struct host1x_device *device = to_host1x_device(drm->dev);
Thierry Reding386a2a72013-09-24 13:22:17 +020029 struct tegra_drm *tegra;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000030 int err;
31
Thierry Reding776dc382013-10-14 14:43:22 +020032 tegra = kzalloc(sizeof(*tegra), GFP_KERNEL);
Thierry Reding386a2a72013-09-24 13:22:17 +020033 if (!tegra)
Terje Bergstrom692e6d72013-03-22 16:34:07 +020034 return -ENOMEM;
35
Thierry Reding776dc382013-10-14 14:43:22 +020036 dev_set_drvdata(drm->dev, tegra);
Thierry Reding386a2a72013-09-24 13:22:17 +020037 mutex_init(&tegra->clients_lock);
38 INIT_LIST_HEAD(&tegra->clients);
Thierry Reding386a2a72013-09-24 13:22:17 +020039 drm->dev_private = tegra;
40 tegra->drm = drm;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000041
42 drm_mode_config_init(drm);
43
Thierry Reding776dc382013-10-14 14:43:22 +020044 err = host1x_device_init(device);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000045 if (err < 0)
46 return err;
47
Thierry Reding603f0cc2013-04-22 21:22:14 +020048 /*
49 * We don't use the drm_irq_install() helpers provided by the DRM
50 * core, so we need to set this manually in order to allow the
51 * DRM_IOCTL_WAIT_VBLANK to operate correctly.
52 */
Ville Syrjälä44238432013-10-04 14:53:37 +030053 drm->irq_enabled = true;
Thierry Reding603f0cc2013-04-22 21:22:14 +020054
Thierry Reding6e5ff992012-11-28 11:45:47 +010055 err = drm_vblank_init(drm, drm->mode_config.num_crtc);
56 if (err < 0)
57 return err;
58
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000059 err = tegra_drm_fb_init(drm);
60 if (err < 0)
61 return err;
62
63 drm_kms_helper_poll_init(drm);
64
65 return 0;
66}
67
68static int tegra_drm_unload(struct drm_device *drm)
69{
Thierry Reding776dc382013-10-14 14:43:22 +020070 struct host1x_device *device = to_host1x_device(drm->dev);
71 int err;
72
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000073 drm_kms_helper_poll_fini(drm);
74 tegra_drm_fb_exit(drm);
75
Thierry Reding776dc382013-10-14 14:43:22 +020076 err = host1x_device_exit(device);
77 if (err < 0)
78 return err;
79
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000080 drm_mode_config_cleanup(drm);
81
82 return 0;
83}
84
85static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
86{
Thierry Reding08943e62013-09-26 16:08:18 +020087 struct tegra_drm_file *fpriv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020088
89 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
90 if (!fpriv)
91 return -ENOMEM;
92
93 INIT_LIST_HEAD(&fpriv->contexts);
94 filp->driver_priv = fpriv;
95
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000096 return 0;
97}
98
Thierry Redingc88c3632013-09-26 16:08:22 +020099static void tegra_drm_context_free(struct tegra_drm_context *context)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200100{
101 context->client->ops->close_channel(context);
102 kfree(context);
103}
104
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000105static void tegra_drm_lastclose(struct drm_device *drm)
106{
Thierry Reding386a2a72013-09-24 13:22:17 +0200107 struct tegra_drm *tegra = drm->dev_private;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000108
Thierry Reding386a2a72013-09-24 13:22:17 +0200109 tegra_fbdev_restore_mode(tegra->fbdev);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000110}
111
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200112#ifdef CONFIG_DRM_TEGRA_STAGING
Thierry Redingc88c3632013-09-26 16:08:22 +0200113static struct tegra_drm_context *tegra_drm_get_context(__u64 context)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200114{
Thierry Redingc88c3632013-09-26 16:08:22 +0200115 return (struct tegra_drm_context *)(uintptr_t)context;
116}
117
118static bool tegra_drm_file_owns_context(struct tegra_drm_file *file,
119 struct tegra_drm_context *context)
120{
121 struct tegra_drm_context *ctx;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200122
123 list_for_each_entry(ctx, &file->contexts, list)
124 if (ctx == context)
125 return true;
126
127 return false;
128}
129
130static int tegra_gem_create(struct drm_device *drm, void *data,
131 struct drm_file *file)
132{
133 struct drm_tegra_gem_create *args = data;
134 struct tegra_bo *bo;
135
136 bo = tegra_bo_create_with_handle(file, drm, args->size,
137 &args->handle);
138 if (IS_ERR(bo))
139 return PTR_ERR(bo);
140
141 return 0;
142}
143
144static int tegra_gem_mmap(struct drm_device *drm, void *data,
145 struct drm_file *file)
146{
147 struct drm_tegra_gem_mmap *args = data;
148 struct drm_gem_object *gem;
149 struct tegra_bo *bo;
150
151 gem = drm_gem_object_lookup(drm, file, args->handle);
152 if (!gem)
153 return -EINVAL;
154
155 bo = to_tegra_bo(gem);
156
David Herrmann2bc7b0c2013-08-13 14:19:58 +0200157 args->offset = drm_vma_node_offset_addr(&bo->gem.vma_node);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200158
159 drm_gem_object_unreference(gem);
160
161 return 0;
162}
163
164static int tegra_syncpt_read(struct drm_device *drm, void *data,
165 struct drm_file *file)
166{
Thierry Reding776dc382013-10-14 14:43:22 +0200167 struct host1x *host = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200168 struct drm_tegra_syncpt_read *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200169 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200170
Thierry Reding776dc382013-10-14 14:43:22 +0200171 sp = host1x_syncpt_get(host, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200172 if (!sp)
173 return -EINVAL;
174
175 args->value = host1x_syncpt_read_min(sp);
176 return 0;
177}
178
179static int tegra_syncpt_incr(struct drm_device *drm, void *data,
180 struct drm_file *file)
181{
Thierry Reding776dc382013-10-14 14:43:22 +0200182 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200183 struct drm_tegra_syncpt_incr *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200184 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200185
Thierry Reding776dc382013-10-14 14:43:22 +0200186 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200187 if (!sp)
188 return -EINVAL;
189
Arto Merilainenebae30b2013-05-29 13:26:08 +0300190 return host1x_syncpt_incr(sp);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200191}
192
193static int tegra_syncpt_wait(struct drm_device *drm, void *data,
194 struct drm_file *file)
195{
Thierry Reding776dc382013-10-14 14:43:22 +0200196 struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200197 struct drm_tegra_syncpt_wait *args = data;
Thierry Reding776dc382013-10-14 14:43:22 +0200198 struct host1x_syncpt *sp;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200199
Thierry Reding776dc382013-10-14 14:43:22 +0200200 sp = host1x_syncpt_get(host1x, args->id);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200201 if (!sp)
202 return -EINVAL;
203
204 return host1x_syncpt_wait(sp, args->thresh, args->timeout,
205 &args->value);
206}
207
208static int tegra_open_channel(struct drm_device *drm, void *data,
209 struct drm_file *file)
210{
Thierry Reding08943e62013-09-26 16:08:18 +0200211 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding386a2a72013-09-24 13:22:17 +0200212 struct tegra_drm *tegra = drm->dev_private;
213 struct drm_tegra_open_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200214 struct tegra_drm_context *context;
Thierry Reding53fa7f72013-09-24 15:35:40 +0200215 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200216 int err = -ENODEV;
217
218 context = kzalloc(sizeof(*context), GFP_KERNEL);
219 if (!context)
220 return -ENOMEM;
221
Thierry Reding776dc382013-10-14 14:43:22 +0200222 list_for_each_entry(client, &tegra->clients, list)
Thierry Reding53fa7f72013-09-24 15:35:40 +0200223 if (client->base.class == args->client) {
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200224 err = client->ops->open_channel(client, context);
225 if (err)
226 break;
227
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200228 list_add(&context->list, &fpriv->contexts);
229 args->context = (uintptr_t)context;
Thierry Reding53fa7f72013-09-24 15:35:40 +0200230 context->client = client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200231 return 0;
232 }
233
234 kfree(context);
235 return err;
236}
237
238static int tegra_close_channel(struct drm_device *drm, void *data,
239 struct drm_file *file)
240{
Thierry Reding08943e62013-09-26 16:08:18 +0200241 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Reding776dc382013-10-14 14:43:22 +0200242 struct drm_tegra_close_channel *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200243 struct tegra_drm_context *context;
244
245 context = tegra_drm_get_context(args->context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200246
Thierry Reding08943e62013-09-26 16:08:18 +0200247 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200248 return -EINVAL;
249
250 list_del(&context->list);
Thierry Redingc88c3632013-09-26 16:08:22 +0200251 tegra_drm_context_free(context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200252
253 return 0;
254}
255
256static int tegra_get_syncpt(struct drm_device *drm, void *data,
257 struct drm_file *file)
258{
Thierry Reding08943e62013-09-26 16:08:18 +0200259 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200260 struct drm_tegra_get_syncpt *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200261 struct tegra_drm_context *context;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200262 struct host1x_syncpt *syncpt;
263
Thierry Redingc88c3632013-09-26 16:08:22 +0200264 context = tegra_drm_get_context(args->context);
265
Thierry Reding08943e62013-09-26 16:08:18 +0200266 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200267 return -ENODEV;
268
Thierry Reding53fa7f72013-09-24 15:35:40 +0200269 if (args->index >= context->client->base.num_syncpts)
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200270 return -EINVAL;
271
Thierry Reding53fa7f72013-09-24 15:35:40 +0200272 syncpt = context->client->base.syncpts[args->index];
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200273 args->id = host1x_syncpt_id(syncpt);
274
275 return 0;
276}
277
278static int tegra_submit(struct drm_device *drm, void *data,
279 struct drm_file *file)
280{
Thierry Reding08943e62013-09-26 16:08:18 +0200281 struct tegra_drm_file *fpriv = file->driver_priv;
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200282 struct drm_tegra_submit *args = data;
Thierry Redingc88c3632013-09-26 16:08:22 +0200283 struct tegra_drm_context *context;
284
285 context = tegra_drm_get_context(args->context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200286
Thierry Reding08943e62013-09-26 16:08:18 +0200287 if (!tegra_drm_file_owns_context(fpriv, context))
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200288 return -ENODEV;
289
290 return context->client->ops->submit(context, args, drm, file);
291}
292#endif
293
Rob Clarkbaa70942013-08-02 13:27:49 -0400294static const struct drm_ioctl_desc tegra_drm_ioctls[] = {
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200295#ifdef CONFIG_DRM_TEGRA_STAGING
296 DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE, tegra_gem_create, DRM_UNLOCKED | DRM_AUTH),
297 DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP, tegra_gem_mmap, DRM_UNLOCKED),
298 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ, tegra_syncpt_read, DRM_UNLOCKED),
299 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR, tegra_syncpt_incr, DRM_UNLOCKED),
300 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT, tegra_syncpt_wait, DRM_UNLOCKED),
301 DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL, tegra_open_channel, DRM_UNLOCKED),
302 DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL, tegra_close_channel, DRM_UNLOCKED),
303 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT, tegra_get_syncpt, DRM_UNLOCKED),
304 DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT, tegra_submit, DRM_UNLOCKED),
305#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000306};
307
308static const struct file_operations tegra_drm_fops = {
309 .owner = THIS_MODULE,
310 .open = drm_open,
311 .release = drm_release,
312 .unlocked_ioctl = drm_ioctl,
Arto Merilainende2ba662013-03-22 16:34:08 +0200313 .mmap = tegra_drm_mmap,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000314 .poll = drm_poll,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000315 .read = drm_read,
316#ifdef CONFIG_COMPAT
317 .compat_ioctl = drm_compat_ioctl,
318#endif
319 .llseek = noop_llseek,
320};
321
Thierry Reding6e5ff992012-11-28 11:45:47 +0100322static struct drm_crtc *tegra_crtc_from_pipe(struct drm_device *drm, int pipe)
323{
324 struct drm_crtc *crtc;
325
326 list_for_each_entry(crtc, &drm->mode_config.crtc_list, head) {
327 struct tegra_dc *dc = to_tegra_dc(crtc);
328
329 if (dc->pipe == pipe)
330 return crtc;
331 }
332
333 return NULL;
334}
335
336static u32 tegra_drm_get_vblank_counter(struct drm_device *dev, int crtc)
337{
338 /* TODO: implement real hardware counter using syncpoints */
339 return drm_vblank_count(dev, crtc);
340}
341
342static int tegra_drm_enable_vblank(struct drm_device *drm, int pipe)
343{
344 struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
345 struct tegra_dc *dc = to_tegra_dc(crtc);
346
347 if (!crtc)
348 return -ENODEV;
349
350 tegra_dc_enable_vblank(dc);
351
352 return 0;
353}
354
355static void tegra_drm_disable_vblank(struct drm_device *drm, int pipe)
356{
357 struct drm_crtc *crtc = tegra_crtc_from_pipe(drm, pipe);
358 struct tegra_dc *dc = to_tegra_dc(crtc);
359
360 if (crtc)
361 tegra_dc_disable_vblank(dc);
362}
363
Thierry Reding3c03c462012-11-28 12:00:18 +0100364static void tegra_drm_preclose(struct drm_device *drm, struct drm_file *file)
365{
Thierry Reding08943e62013-09-26 16:08:18 +0200366 struct tegra_drm_file *fpriv = file->driver_priv;
Thierry Redingc88c3632013-09-26 16:08:22 +0200367 struct tegra_drm_context *context, *tmp;
Thierry Reding3c03c462012-11-28 12:00:18 +0100368 struct drm_crtc *crtc;
369
370 list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
371 tegra_dc_cancel_page_flip(crtc, file);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200372
373 list_for_each_entry_safe(context, tmp, &fpriv->contexts, list)
Thierry Redingc88c3632013-09-26 16:08:22 +0200374 tegra_drm_context_free(context);
Terje Bergstromd43f81c2013-03-22 16:34:09 +0200375
376 kfree(fpriv);
Thierry Reding3c03c462012-11-28 12:00:18 +0100377}
378
Thierry Redinge450fcc2013-02-13 16:13:16 +0100379#ifdef CONFIG_DEBUG_FS
380static int tegra_debugfs_framebuffers(struct seq_file *s, void *data)
381{
382 struct drm_info_node *node = (struct drm_info_node *)s->private;
383 struct drm_device *drm = node->minor->dev;
384 struct drm_framebuffer *fb;
385
386 mutex_lock(&drm->mode_config.fb_lock);
387
388 list_for_each_entry(fb, &drm->mode_config.fb_list, head) {
389 seq_printf(s, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n",
390 fb->base.id, fb->width, fb->height, fb->depth,
391 fb->bits_per_pixel,
392 atomic_read(&fb->refcount.refcount));
393 }
394
395 mutex_unlock(&drm->mode_config.fb_lock);
396
397 return 0;
398}
399
400static struct drm_info_list tegra_debugfs_list[] = {
401 { "framebuffers", tegra_debugfs_framebuffers, 0 },
402};
403
404static int tegra_debugfs_init(struct drm_minor *minor)
405{
406 return drm_debugfs_create_files(tegra_debugfs_list,
407 ARRAY_SIZE(tegra_debugfs_list),
408 minor->debugfs_root, minor);
409}
410
411static void tegra_debugfs_cleanup(struct drm_minor *minor)
412{
413 drm_debugfs_remove_files(tegra_debugfs_list,
414 ARRAY_SIZE(tegra_debugfs_list), minor);
415}
416#endif
417
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000418struct drm_driver tegra_drm_driver = {
Laurent Pinchart604faa72013-05-29 07:44:34 +0200419 .driver_features = DRIVER_MODESET | DRIVER_GEM,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000420 .load = tegra_drm_load,
421 .unload = tegra_drm_unload,
422 .open = tegra_drm_open,
Thierry Reding3c03c462012-11-28 12:00:18 +0100423 .preclose = tegra_drm_preclose,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000424 .lastclose = tegra_drm_lastclose,
425
Thierry Reding6e5ff992012-11-28 11:45:47 +0100426 .get_vblank_counter = tegra_drm_get_vblank_counter,
427 .enable_vblank = tegra_drm_enable_vblank,
428 .disable_vblank = tegra_drm_disable_vblank,
429
Thierry Redinge450fcc2013-02-13 16:13:16 +0100430#if defined(CONFIG_DEBUG_FS)
431 .debugfs_init = tegra_debugfs_init,
432 .debugfs_cleanup = tegra_debugfs_cleanup,
433#endif
434
Arto Merilainende2ba662013-03-22 16:34:08 +0200435 .gem_free_object = tegra_bo_free_object,
436 .gem_vm_ops = &tegra_bo_vm_ops,
437 .dumb_create = tegra_bo_dumb_create,
438 .dumb_map_offset = tegra_bo_dumb_map_offset,
Daniel Vetter43387b32013-07-16 09:12:04 +0200439 .dumb_destroy = drm_gem_dumb_destroy,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000440
441 .ioctls = tegra_drm_ioctls,
442 .num_ioctls = ARRAY_SIZE(tegra_drm_ioctls),
443 .fops = &tegra_drm_fops,
444
445 .name = DRIVER_NAME,
446 .desc = DRIVER_DESC,
447 .date = DRIVER_DATE,
448 .major = DRIVER_MAJOR,
449 .minor = DRIVER_MINOR,
450 .patchlevel = DRIVER_PATCHLEVEL,
451};
Thierry Reding776dc382013-10-14 14:43:22 +0200452
453int tegra_drm_register_client(struct tegra_drm *tegra,
454 struct tegra_drm_client *client)
455{
456 mutex_lock(&tegra->clients_lock);
457 list_add_tail(&client->list, &tegra->clients);
458 mutex_unlock(&tegra->clients_lock);
459
460 return 0;
461}
462
463int tegra_drm_unregister_client(struct tegra_drm *tegra,
464 struct tegra_drm_client *client)
465{
466 mutex_lock(&tegra->clients_lock);
467 list_del_init(&client->list);
468 mutex_unlock(&tegra->clients_lock);
469
470 return 0;
471}
472
473static int host1x_drm_probe(struct host1x_device *device)
474{
475 return drm_host1x_init(&tegra_drm_driver, device);
476}
477
478static int host1x_drm_remove(struct host1x_device *device)
479{
480 drm_host1x_exit(&tegra_drm_driver, device);
481
482 return 0;
483}
484
485static const struct of_device_id host1x_drm_subdevs[] = {
486 { .compatible = "nvidia,tegra20-dc", },
487 { .compatible = "nvidia,tegra20-hdmi", },
488 { .compatible = "nvidia,tegra20-gr2d", },
489 { .compatible = "nvidia,tegra30-dc", },
490 { .compatible = "nvidia,tegra30-hdmi", },
491 { .compatible = "nvidia,tegra30-gr2d", },
492 { /* sentinel */ }
493};
494
495static struct host1x_driver host1x_drm_driver = {
496 .name = "drm",
497 .probe = host1x_drm_probe,
498 .remove = host1x_drm_remove,
499 .subdevs = host1x_drm_subdevs,
500};
501
502static int __init host1x_drm_init(void)
503{
504 int err;
505
506 err = host1x_driver_register(&host1x_drm_driver);
507 if (err < 0)
508 return err;
509
510 err = platform_driver_register(&tegra_dc_driver);
511 if (err < 0)
512 goto unregister_host1x;
513
514 err = platform_driver_register(&tegra_hdmi_driver);
515 if (err < 0)
516 goto unregister_dc;
517
518 err = platform_driver_register(&tegra_gr2d_driver);
519 if (err < 0)
520 goto unregister_hdmi;
521
522 return 0;
523
524unregister_hdmi:
525 platform_driver_unregister(&tegra_hdmi_driver);
526unregister_dc:
527 platform_driver_unregister(&tegra_dc_driver);
528unregister_host1x:
529 host1x_driver_unregister(&host1x_drm_driver);
530 return err;
531}
532module_init(host1x_drm_init);
533
534static void __exit host1x_drm_exit(void)
535{
536 platform_driver_unregister(&tegra_gr2d_driver);
537 platform_driver_unregister(&tegra_hdmi_driver);
538 platform_driver_unregister(&tegra_dc_driver);
539 host1x_driver_unregister(&host1x_drm_driver);
540}
541module_exit(host1x_drm_exit);
542
543MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
544MODULE_DESCRIPTION("NVIDIA Tegra DRM driver");
545MODULE_LICENSE("GPL v2");