| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2009 Nokia Corporation |
|---|
| 3 | 4 | * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Some code and ideas taken from drivers/video/omap/ driver |
|---|
| 6 | 7 | * by Imre Deak. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 9 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 10 | | - * the Free Software Foundation. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 13 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 14 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 15 | | - * more details. |
|---|
| 16 | | - * |
|---|
| 17 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 18 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 19 | 8 | */ |
|---|
| 20 | 9 | |
|---|
| 21 | 10 | #define DSS_SUBSYS_NAME "DISPLAY" |
|---|
| 22 | 11 | |
|---|
| 23 | 12 | #include <linux/kernel.h> |
|---|
| 24 | | -#include <linux/module.h> |
|---|
| 25 | | -#include <linux/jiffies.h> |
|---|
| 26 | | -#include <linux/platform_device.h> |
|---|
| 27 | 13 | #include <linux/of.h> |
|---|
| 14 | + |
|---|
| 15 | +#include <drm/drm_connector.h> |
|---|
| 16 | +#include <drm/drm_modes.h> |
|---|
| 28 | 17 | |
|---|
| 29 | 18 | #include "omapdss.h" |
|---|
| 30 | 19 | |
|---|
| 31 | | -static void omapdss_default_get_timings(struct omap_dss_device *dssdev, |
|---|
| 32 | | - struct videomode *vm) |
|---|
| 33 | | -{ |
|---|
| 34 | | - *vm = dssdev->panel.vm; |
|---|
| 35 | | -} |
|---|
| 36 | | - |
|---|
| 37 | | -static LIST_HEAD(panel_list); |
|---|
| 38 | | -static DEFINE_MUTEX(panel_list_mutex); |
|---|
| 39 | 20 | static int disp_num_counter; |
|---|
| 40 | 21 | |
|---|
| 41 | | -int omapdss_register_display(struct omap_dss_device *dssdev) |
|---|
| 22 | +void omapdss_display_init(struct omap_dss_device *dssdev) |
|---|
| 42 | 23 | { |
|---|
| 43 | | - struct omap_dss_driver *drv = dssdev->driver; |
|---|
| 44 | | - struct list_head *cur; |
|---|
| 45 | 24 | int id; |
|---|
| 46 | 25 | |
|---|
| 47 | 26 | /* |
|---|
| .. | .. |
|---|
| 52 | 31 | if (id < 0) |
|---|
| 53 | 32 | id = disp_num_counter++; |
|---|
| 54 | 33 | |
|---|
| 55 | | - snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id); |
|---|
| 56 | | - |
|---|
| 57 | 34 | /* Use 'label' property for name, if it exists */ |
|---|
| 58 | 35 | of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name); |
|---|
| 59 | 36 | |
|---|
| 60 | 37 | if (dssdev->name == NULL) |
|---|
| 61 | | - dssdev->name = dssdev->alias; |
|---|
| 62 | | - |
|---|
| 63 | | - if (drv && drv->get_timings == NULL) |
|---|
| 64 | | - drv->get_timings = omapdss_default_get_timings; |
|---|
| 65 | | - |
|---|
| 66 | | - mutex_lock(&panel_list_mutex); |
|---|
| 67 | | - list_for_each(cur, &panel_list) { |
|---|
| 68 | | - struct omap_dss_device *ldev = list_entry(cur, |
|---|
| 69 | | - struct omap_dss_device, |
|---|
| 70 | | - panel_list); |
|---|
| 71 | | - if (strcmp(ldev->alias, dssdev->alias) > 0) |
|---|
| 72 | | - break; |
|---|
| 73 | | - } |
|---|
| 74 | | - list_add_tail(&dssdev->panel_list, cur); |
|---|
| 75 | | - mutex_unlock(&panel_list_mutex); |
|---|
| 76 | | - return 0; |
|---|
| 38 | + dssdev->name = devm_kasprintf(dssdev->dev, GFP_KERNEL, |
|---|
| 39 | + "display%u", id); |
|---|
| 77 | 40 | } |
|---|
| 78 | | -EXPORT_SYMBOL(omapdss_register_display); |
|---|
| 41 | +EXPORT_SYMBOL_GPL(omapdss_display_init); |
|---|
| 79 | 42 | |
|---|
| 80 | | -void omapdss_unregister_display(struct omap_dss_device *dssdev) |
|---|
| 43 | +int omapdss_display_get_modes(struct drm_connector *connector, |
|---|
| 44 | + const struct videomode *vm) |
|---|
| 81 | 45 | { |
|---|
| 82 | | - mutex_lock(&panel_list_mutex); |
|---|
| 83 | | - list_del(&dssdev->panel_list); |
|---|
| 84 | | - mutex_unlock(&panel_list_mutex); |
|---|
| 46 | + struct drm_display_mode *mode; |
|---|
| 47 | + |
|---|
| 48 | + mode = drm_mode_create(connector->dev); |
|---|
| 49 | + if (!mode) |
|---|
| 50 | + return 0; |
|---|
| 51 | + |
|---|
| 52 | + drm_display_mode_from_videomode(vm, mode); |
|---|
| 53 | + |
|---|
| 54 | + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; |
|---|
| 55 | + drm_mode_set_name(mode); |
|---|
| 56 | + drm_mode_probed_add(connector, mode); |
|---|
| 57 | + |
|---|
| 58 | + return 1; |
|---|
| 85 | 59 | } |
|---|
| 86 | | -EXPORT_SYMBOL(omapdss_unregister_display); |
|---|
| 87 | | - |
|---|
| 88 | | -bool omapdss_component_is_display(struct device_node *node) |
|---|
| 89 | | -{ |
|---|
| 90 | | - struct omap_dss_device *dssdev; |
|---|
| 91 | | - bool found = false; |
|---|
| 92 | | - |
|---|
| 93 | | - mutex_lock(&panel_list_mutex); |
|---|
| 94 | | - list_for_each_entry(dssdev, &panel_list, panel_list) { |
|---|
| 95 | | - if (dssdev->dev->of_node == node) { |
|---|
| 96 | | - found = true; |
|---|
| 97 | | - goto out; |
|---|
| 98 | | - } |
|---|
| 99 | | - } |
|---|
| 100 | | -out: |
|---|
| 101 | | - mutex_unlock(&panel_list_mutex); |
|---|
| 102 | | - return found; |
|---|
| 103 | | -} |
|---|
| 104 | | -EXPORT_SYMBOL(omapdss_component_is_display); |
|---|
| 105 | | - |
|---|
| 106 | | -struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev) |
|---|
| 107 | | -{ |
|---|
| 108 | | - if (!try_module_get(dssdev->owner)) |
|---|
| 109 | | - return NULL; |
|---|
| 110 | | - |
|---|
| 111 | | - if (get_device(dssdev->dev) == NULL) { |
|---|
| 112 | | - module_put(dssdev->owner); |
|---|
| 113 | | - return NULL; |
|---|
| 114 | | - } |
|---|
| 115 | | - |
|---|
| 116 | | - return dssdev; |
|---|
| 117 | | -} |
|---|
| 118 | | -EXPORT_SYMBOL(omap_dss_get_device); |
|---|
| 119 | | - |
|---|
| 120 | | -void omap_dss_put_device(struct omap_dss_device *dssdev) |
|---|
| 121 | | -{ |
|---|
| 122 | | - put_device(dssdev->dev); |
|---|
| 123 | | - module_put(dssdev->owner); |
|---|
| 124 | | -} |
|---|
| 125 | | -EXPORT_SYMBOL(omap_dss_put_device); |
|---|
| 126 | | - |
|---|
| 127 | | -/* |
|---|
| 128 | | - * ref count of the found device is incremented. |
|---|
| 129 | | - * ref count of from-device is decremented. |
|---|
| 130 | | - */ |
|---|
| 131 | | -struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from) |
|---|
| 132 | | -{ |
|---|
| 133 | | - struct list_head *l; |
|---|
| 134 | | - struct omap_dss_device *dssdev; |
|---|
| 135 | | - |
|---|
| 136 | | - mutex_lock(&panel_list_mutex); |
|---|
| 137 | | - |
|---|
| 138 | | - if (list_empty(&panel_list)) { |
|---|
| 139 | | - dssdev = NULL; |
|---|
| 140 | | - goto out; |
|---|
| 141 | | - } |
|---|
| 142 | | - |
|---|
| 143 | | - if (from == NULL) { |
|---|
| 144 | | - dssdev = list_first_entry(&panel_list, struct omap_dss_device, |
|---|
| 145 | | - panel_list); |
|---|
| 146 | | - omap_dss_get_device(dssdev); |
|---|
| 147 | | - goto out; |
|---|
| 148 | | - } |
|---|
| 149 | | - |
|---|
| 150 | | - omap_dss_put_device(from); |
|---|
| 151 | | - |
|---|
| 152 | | - list_for_each(l, &panel_list) { |
|---|
| 153 | | - dssdev = list_entry(l, struct omap_dss_device, panel_list); |
|---|
| 154 | | - if (dssdev == from) { |
|---|
| 155 | | - if (list_is_last(l, &panel_list)) { |
|---|
| 156 | | - dssdev = NULL; |
|---|
| 157 | | - goto out; |
|---|
| 158 | | - } |
|---|
| 159 | | - |
|---|
| 160 | | - dssdev = list_entry(l->next, struct omap_dss_device, |
|---|
| 161 | | - panel_list); |
|---|
| 162 | | - omap_dss_get_device(dssdev); |
|---|
| 163 | | - goto out; |
|---|
| 164 | | - } |
|---|
| 165 | | - } |
|---|
| 166 | | - |
|---|
| 167 | | - WARN(1, "'from' dssdev not found\n"); |
|---|
| 168 | | - |
|---|
| 169 | | - dssdev = NULL; |
|---|
| 170 | | -out: |
|---|
| 171 | | - mutex_unlock(&panel_list_mutex); |
|---|
| 172 | | - return dssdev; |
|---|
| 173 | | -} |
|---|
| 174 | | -EXPORT_SYMBOL(omap_dss_get_next_device); |
|---|
| 60 | +EXPORT_SYMBOL_GPL(omapdss_display_get_modes); |
|---|