7c9058f0cb2bddec66225b67183ba49f432c1280
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / gpu / drm / tegra / bus.c
1 /*
2  * Copyright (C) 2013 NVIDIA Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include "drm.h"
10
11 static int drm_host1x_set_busid(struct drm_device *dev,
12                                 struct drm_master *master)
13 {
14         const char *device = dev_name(dev->dev);
15         const char *bus = dev->dev->bus->name;
16
17         master->unique_len = strlen(bus) + 1 + strlen(device);
18         master->unique_size = master->unique_len;
19
20         master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
21         if (!master->unique)
22                 return -ENOMEM;
23
24         snprintf(master->unique, master->unique_len + 1, "%s:%s", bus, device);
25
26         return 0;
27 }
28
29 static struct drm_bus drm_host1x_bus = {
30         .bus_type = DRIVER_BUS_HOST1X,
31         .set_busid = drm_host1x_set_busid,
32 };
33
34 int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device)
35 {
36         struct drm_device *drm;
37         int ret;
38
39         driver->bus = &drm_host1x_bus;
40
41         drm = drm_dev_alloc(driver, &device->dev);
42         if (!drm)
43                 return -ENOMEM;
44
45         ret = drm_dev_register(drm, 0);
46         if (ret)
47                 goto err_free;
48
49         DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name,
50                  driver->major, driver->minor, driver->patchlevel,
51                  driver->date, drm->primary->index);
52
53         return 0;
54
55 err_free:
56         drm_dev_free(drm);
57         return ret;
58 }
59
60 void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device)
61 {
62         struct tegra_drm *tegra = dev_get_drvdata(&device->dev);
63
64         drm_put_dev(tegra->drm);
65 }