Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* exynos_drm_core.c |
| 2 | * |
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * Author: |
| 5 | * Inki Dae <inki.dae@samsung.com> |
| 6 | * Joonyoung Shim <jy0922.shim@samsung.com> |
| 7 | * Seung-Woo Kim <sw0312.kim@samsung.com> |
| 8 | * |
Inki Dae | d81aecb | 2012-12-18 02:30:17 +0900 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 13 | */ |
| 14 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 15 | #include <drm/drmP.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 16 | #include "exynos_drm_drv.h" |
Sean Paul | 080be03d | 2014-02-19 21:02:55 +0900 | [diff] [blame] | 17 | #include "exynos_drm_crtc.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 18 | #include "exynos_drm_fbdev.h" |
| 19 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 20 | static LIST_HEAD(exynos_drm_subdrv_list); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 21 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 22 | int exynos_drm_subdrv_register(struct exynos_drm_subdrv *subdrv) |
| 23 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 24 | if (!subdrv) |
| 25 | return -EINVAL; |
| 26 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 27 | list_add_tail(&subdrv->list, &exynos_drm_subdrv_list); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 28 | |
| 29 | return 0; |
| 30 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 31 | |
| 32 | int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *subdrv) |
| 33 | { |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 34 | if (!subdrv) |
| 35 | return -EINVAL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 36 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 37 | list_del(&subdrv->list); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 38 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 39 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 40 | } |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 41 | |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 42 | int exynos_drm_device_subdrv_probe(struct drm_device *dev) |
| 43 | { |
| 44 | struct exynos_drm_subdrv *subdrv, *n; |
| 45 | int err; |
| 46 | |
| 47 | if (!dev) |
| 48 | return -EINVAL; |
| 49 | |
| 50 | list_for_each_entry_safe(subdrv, n, &exynos_drm_subdrv_list, list) { |
| 51 | if (subdrv->probe) { |
| 52 | subdrv->drm_dev = dev; |
| 53 | |
| 54 | /* |
| 55 | * this probe callback would be called by sub driver |
| 56 | * after setting of all resources to this sub driver, |
| 57 | * such as clock, irq and register map are done. |
| 58 | */ |
| 59 | err = subdrv->probe(dev, subdrv->dev); |
| 60 | if (err) { |
| 61 | DRM_DEBUG("exynos drm subdrv probe failed.\n"); |
| 62 | list_del(&subdrv->list); |
| 63 | continue; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 70 | |
| 71 | int exynos_drm_device_subdrv_remove(struct drm_device *dev) |
| 72 | { |
| 73 | struct exynos_drm_subdrv *subdrv; |
| 74 | |
| 75 | if (!dev) { |
| 76 | WARN(1, "Unexpected drm device unregister!\n"); |
| 77 | return -EINVAL; |
| 78 | } |
| 79 | |
| 80 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { |
| 81 | if (subdrv->remove) |
| 82 | subdrv->remove(dev, subdrv->dev); |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
Inki Dae | f37cd5e | 2014-05-09 14:25:20 +0900 | [diff] [blame] | 87 | |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 88 | int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file) |
| 89 | { |
| 90 | struct exynos_drm_subdrv *subdrv; |
| 91 | int ret; |
| 92 | |
| 93 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { |
| 94 | if (subdrv->open) { |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 95 | ret = subdrv->open(dev, subdrv->dev, file); |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 96 | if (ret) |
| 97 | goto err; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | |
| 103 | err: |
| 104 | list_for_each_entry_reverse(subdrv, &subdrv->list, list) { |
| 105 | if (subdrv->close) |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 106 | subdrv->close(dev, subdrv->dev, file); |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 107 | } |
| 108 | return ret; |
| 109 | } |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 110 | |
| 111 | void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file) |
| 112 | { |
| 113 | struct exynos_drm_subdrv *subdrv; |
| 114 | |
| 115 | list_for_each_entry(subdrv, &exynos_drm_subdrv_list, list) { |
| 116 | if (subdrv->close) |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 117 | subdrv->close(dev, subdrv->dev, file); |
Joonyoung Shim | 9084f7b | 2012-03-16 18:47:09 +0900 | [diff] [blame] | 118 | } |
| 119 | } |