Thierry Reding | 776dc38 | 2013-10-14 14:43:22 +0200 | [diff] [blame] | 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 *driver = dev->driver->name; |
| 16 | const char *bus = dev->dev->bus->name; |
| 17 | int length; |
| 18 | |
| 19 | master->unique_len = strlen(bus) + 1 + strlen(device); |
| 20 | master->unique_size = master->unique_len; |
| 21 | |
| 22 | master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL); |
| 23 | if (!master->unique) |
| 24 | return -ENOMEM; |
| 25 | |
| 26 | snprintf(master->unique, master->unique_len + 1, "%s:%s", bus, device); |
| 27 | |
| 28 | length = strlen(driver) + 1 + master->unique_len; |
| 29 | |
| 30 | dev->devname = kmalloc(length + 1, GFP_KERNEL); |
| 31 | if (!dev->devname) |
| 32 | return -ENOMEM; |
| 33 | |
| 34 | snprintf(dev->devname, length + 1, "%s@%s", driver, master->unique); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static struct drm_bus drm_host1x_bus = { |
| 40 | .bus_type = DRIVER_BUS_HOST1X, |
| 41 | .set_busid = drm_host1x_set_busid, |
| 42 | }; |
| 43 | |
| 44 | int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device) |
| 45 | { |
| 46 | struct drm_device *drm; |
| 47 | int ret; |
| 48 | |
| 49 | INIT_LIST_HEAD(&driver->device_list); |
| 50 | driver->bus = &drm_host1x_bus; |
| 51 | |
| 52 | drm = drm_dev_alloc(driver, &device->dev); |
| 53 | if (!drm) |
| 54 | return -ENOMEM; |
| 55 | |
| 56 | ret = drm_dev_register(drm, 0); |
| 57 | if (ret) |
| 58 | goto err_free; |
| 59 | |
| 60 | DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name, |
| 61 | driver->major, driver->minor, driver->patchlevel, |
| 62 | driver->date, drm->primary->index); |
| 63 | |
| 64 | return 0; |
| 65 | |
| 66 | err_free: |
| 67 | drm_dev_free(drm); |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device) |
| 72 | { |
| 73 | struct tegra_drm *tegra = dev_get_drvdata(&device->dev); |
| 74 | |
| 75 | drm_put_dev(tegra->drm); |
| 76 | } |