Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Free Electrons |
| 4 | * Copyright (C) 2015 NextThing Co |
| 5 | * |
| 6 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/component.h> |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 10 | #include <linux/kfifo.h> |
Sam Ravnborg | 9c25a29 | 2019-07-16 08:42:06 +0200 | [diff] [blame] | 11 | #include <linux/module.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 12 | #include <linux/of_graph.h> |
Maxime Ripard | 596afb6 | 2017-02-09 17:39:18 +0100 | [diff] [blame] | 13 | #include <linux/of_reserved_mem.h> |
Sam Ravnborg | 9c25a29 | 2019-07-16 08:42:06 +0200 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 15 | |
Paul Kocialkowski | 71adf60 | 2019-04-18 15:27:25 +0200 | [diff] [blame] | 16 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | 9c25a29 | 2019-07-16 08:42:06 +0200 | [diff] [blame] | 17 | #include <drm/drm_drv.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 18 | #include <drm/drm_fb_cma_helper.h> |
Daniel Vetter | 44adece | 2016-08-10 18:52:34 +0200 | [diff] [blame] | 19 | #include <drm/drm_fb_helper.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 20 | #include <drm/drm_gem_cma_helper.h> |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 21 | #include <drm/drm_of.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 22 | #include <drm/drm_probe_helper.h> |
Sam Ravnborg | 9c25a29 | 2019-07-16 08:42:06 +0200 | [diff] [blame] | 23 | #include <drm/drm_vblank.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 24 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 25 | #include "sun4i_drv.h" |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 26 | #include "sun4i_frontend.h" |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 27 | #include "sun4i_framebuffer.h" |
Chen-Yu Tsai | b3f266e | 2017-02-23 16:05:36 +0800 | [diff] [blame] | 28 | #include "sun4i_tcon.h" |
Jernej Skrabec | ef0cf64 | 2018-06-25 14:02:48 +0200 | [diff] [blame] | 29 | #include "sun8i_tcon_top.h" |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 30 | |
Paul Kocialkowski | 31cf282 | 2018-11-23 10:25:01 +0100 | [diff] [blame] | 31 | static int drm_sun4i_gem_dumb_create(struct drm_file *file_priv, |
| 32 | struct drm_device *drm, |
| 33 | struct drm_mode_create_dumb *args) |
| 34 | { |
| 35 | /* The hardware only allows even pitches for YUV buffers. */ |
| 36 | args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), 2); |
| 37 | |
| 38 | return drm_gem_cma_dumb_create_internal(file_priv, drm, args); |
| 39 | } |
| 40 | |
Daniel Vetter | d55f7e5 | 2017-03-08 15:12:56 +0100 | [diff] [blame] | 41 | DEFINE_DRM_GEM_CMA_FOPS(sun4i_drv_fops); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 42 | |
| 43 | static struct drm_driver sun4i_drv_driver = { |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 44 | .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 45 | |
| 46 | /* Generic Operations */ |
| 47 | .fops = &sun4i_drv_fops, |
| 48 | .name = "sun4i-drm", |
| 49 | .desc = "Allwinner sun4i Display Engine", |
| 50 | .date = "20150629", |
| 51 | .major = 1, |
| 52 | .minor = 0, |
| 53 | |
| 54 | /* GEM Operations */ |
Paul Kocialkowski | ad408c7 | 2019-04-18 15:05:09 +0200 | [diff] [blame] | 55 | DRM_GEM_CMA_VMAP_DRIVER_OPS, |
Paul Kocialkowski | 31cf282 | 2018-11-23 10:25:01 +0100 | [diff] [blame] | 56 | .dumb_create = drm_sun4i_gem_dumb_create, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static int sun4i_drv_bind(struct device *dev) |
| 60 | { |
| 61 | struct drm_device *drm; |
| 62 | struct sun4i_drv *drv; |
| 63 | int ret; |
| 64 | |
| 65 | drm = drm_dev_alloc(&sun4i_drv_driver, dev); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 66 | if (IS_ERR(drm)) |
| 67 | return PTR_ERR(drm); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 68 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 69 | drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); |
| 70 | if (!drv) { |
| 71 | ret = -ENOMEM; |
| 72 | goto free_drm; |
| 73 | } |
Paul Kocialkowski | 02b92ad | 2019-04-18 15:27:26 +0200 | [diff] [blame] | 74 | |
| 75 | dev_set_drvdata(dev, drm); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 76 | drm->dev_private = drv; |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 77 | INIT_LIST_HEAD(&drv->frontend_list); |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 78 | INIT_LIST_HEAD(&drv->engine_list); |
Chen-Yu Tsai | 80a5824 | 2017-04-21 16:38:50 +0800 | [diff] [blame] | 79 | INIT_LIST_HEAD(&drv->tcon_list); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 80 | |
Maxime Ripard | 596afb6 | 2017-02-09 17:39:18 +0100 | [diff] [blame] | 81 | ret = of_reserved_mem_device_init(dev); |
| 82 | if (ret && ret != -ENODEV) { |
| 83 | dev_err(drm->dev, "Couldn't claim our memory region\n"); |
| 84 | goto free_drm; |
| 85 | } |
| 86 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 87 | drm_mode_config_init(drm); |
| 88 | |
| 89 | ret = component_bind_all(drm->dev, drm); |
| 90 | if (ret) { |
| 91 | dev_err(drm->dev, "Couldn't bind all pipelines components\n"); |
Chen-Yu Tsai | 9d56def | 2017-02-17 11:13:25 +0800 | [diff] [blame] | 92 | goto cleanup_mode_config; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Chen-Yu Tsai | 070badf | 2017-09-08 15:50:15 +0800 | [diff] [blame] | 95 | /* drm_vblank_init calls kcalloc, which can fail */ |
| 96 | ret = drm_vblank_init(drm, drm->mode_config.num_crtc); |
| 97 | if (ret) |
Christophe JAILLET | 9ca8614 | 2018-03-12 00:19:09 +0100 | [diff] [blame] | 98 | goto cleanup_mode_config; |
Chen-Yu Tsai | 070badf | 2017-09-08 15:50:15 +0800 | [diff] [blame] | 99 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 100 | drm->irq_enabled = true; |
| 101 | |
Maxime Ripard | 3d6bd90 | 2016-05-11 16:52:50 +0200 | [diff] [blame] | 102 | /* Remove early framebuffers (ie. simplefb) */ |
Michał Mirosław | a7e3fa7 | 2018-09-01 16:08:51 +0200 | [diff] [blame] | 103 | drm_fb_helper_remove_conflicting_framebuffers(NULL, "sun4i-drm-fb", false); |
Maxime Ripard | 3d6bd90 | 2016-05-11 16:52:50 +0200 | [diff] [blame] | 104 | |
Noralf Trønnes | 94ebfc0 | 2018-10-25 22:13:38 +0200 | [diff] [blame] | 105 | sun4i_framebuffer_init(drm); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 106 | |
| 107 | /* Enable connectors polling */ |
| 108 | drm_kms_helper_poll_init(drm); |
| 109 | |
| 110 | ret = drm_dev_register(drm, 0); |
| 111 | if (ret) |
Chen-Yu Tsai | 9d56def | 2017-02-17 11:13:25 +0800 | [diff] [blame] | 112 | goto finish_poll; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 113 | |
Noralf Trønnes | 94ebfc0 | 2018-10-25 22:13:38 +0200 | [diff] [blame] | 114 | drm_fbdev_generic_setup(drm, 32); |
| 115 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 116 | return 0; |
| 117 | |
Chen-Yu Tsai | 9d56def | 2017-02-17 11:13:25 +0800 | [diff] [blame] | 118 | finish_poll: |
| 119 | drm_kms_helper_poll_fini(drm); |
Chen-Yu Tsai | 9d56def | 2017-02-17 11:13:25 +0800 | [diff] [blame] | 120 | cleanup_mode_config: |
| 121 | drm_mode_config_cleanup(drm); |
Maxime Ripard | 596afb6 | 2017-02-09 17:39:18 +0100 | [diff] [blame] | 122 | of_reserved_mem_device_release(dev); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 123 | free_drm: |
Thomas Zimmermann | 4c2ae34 | 2018-07-17 10:48:14 +0200 | [diff] [blame] | 124 | drm_dev_put(drm); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | static void sun4i_drv_unbind(struct device *dev) |
| 129 | { |
| 130 | struct drm_device *drm = dev_get_drvdata(dev); |
| 131 | |
| 132 | drm_dev_unregister(drm); |
| 133 | drm_kms_helper_poll_fini(drm); |
Paul Kocialkowski | 71adf60 | 2019-04-18 15:27:25 +0200 | [diff] [blame] | 134 | drm_atomic_helper_shutdown(drm); |
Chen-Yu Tsai | 92caf9b | 2017-02-17 11:13:24 +0800 | [diff] [blame] | 135 | drm_mode_config_cleanup(drm); |
Paul Kocialkowski | f5a9ed8 | 2019-04-18 15:27:27 +0200 | [diff] [blame] | 136 | |
| 137 | component_unbind_all(dev, NULL); |
Maxime Ripard | 596afb6 | 2017-02-09 17:39:18 +0100 | [diff] [blame] | 138 | of_reserved_mem_device_release(dev); |
Paul Kocialkowski | e02bc29 | 2019-04-24 11:04:13 +0200 | [diff] [blame] | 139 | |
Thomas Zimmermann | 4c2ae34 | 2018-07-17 10:48:14 +0200 | [diff] [blame] | 140 | drm_dev_put(drm); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static const struct component_master_ops sun4i_drv_master_ops = { |
| 144 | .bind = sun4i_drv_bind, |
| 145 | .unbind = sun4i_drv_unbind, |
| 146 | }; |
| 147 | |
Maxime Ripard | 49baeb0 | 2017-05-27 18:09:32 +0200 | [diff] [blame] | 148 | static bool sun4i_drv_node_is_connector(struct device_node *node) |
| 149 | { |
| 150 | return of_device_is_compatible(node, "hdmi-connector"); |
| 151 | } |
| 152 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 153 | static bool sun4i_drv_node_is_frontend(struct device_node *node) |
| 154 | { |
Chen-Yu Tsai | 9a8187c | 2017-10-17 20:18:01 +0800 | [diff] [blame] | 155 | return of_device_is_compatible(node, "allwinner,sun4i-a10-display-frontend") || |
| 156 | of_device_is_compatible(node, "allwinner,sun5i-a13-display-frontend") || |
Chen-Yu Tsai | 49c440e | 2016-10-20 11:43:41 +0800 | [diff] [blame] | 157 | of_device_is_compatible(node, "allwinner,sun6i-a31-display-frontend") || |
Jonathan Liu | aaddb6d | 2017-10-17 20:18:02 +0800 | [diff] [blame] | 158 | of_device_is_compatible(node, "allwinner,sun7i-a20-display-frontend") || |
Chen-Yu Tsai | d0ec0a3 | 2019-01-25 11:23:09 +0800 | [diff] [blame] | 159 | of_device_is_compatible(node, "allwinner,sun8i-a23-display-frontend") || |
Chen-Yu Tsai | 3347895 | 2018-03-15 19:41:33 +0800 | [diff] [blame] | 160 | of_device_is_compatible(node, "allwinner,sun8i-a33-display-frontend") || |
| 161 | of_device_is_compatible(node, "allwinner,sun9i-a80-display-frontend"); |
| 162 | } |
| 163 | |
| 164 | static bool sun4i_drv_node_is_deu(struct device_node *node) |
| 165 | { |
| 166 | return of_device_is_compatible(node, "allwinner,sun9i-a80-deu"); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 169 | static bool sun4i_drv_node_is_supported_frontend(struct device_node *node) |
| 170 | { |
| 171 | if (IS_ENABLED(CONFIG_DRM_SUN4I_BACKEND)) |
| 172 | return !!of_match_node(sun4i_frontend_of_table, node); |
| 173 | |
| 174 | return false; |
| 175 | } |
| 176 | |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 177 | static bool sun4i_drv_node_is_tcon(struct device_node *node) |
| 178 | { |
Chen-Yu Tsai | ff71c2c | 2017-11-27 16:46:32 +0800 | [diff] [blame] | 179 | return !!of_match_node(sun4i_tcon_of_table, node); |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Jernej Skrabec | c5cf04d | 2018-06-25 14:02:49 +0200 | [diff] [blame] | 182 | static bool sun4i_drv_node_is_tcon_with_ch0(struct device_node *node) |
| 183 | { |
| 184 | const struct of_device_id *match; |
| 185 | |
| 186 | match = of_match_node(sun4i_tcon_of_table, node); |
| 187 | if (match) { |
| 188 | struct sun4i_tcon_quirks *quirks; |
| 189 | |
| 190 | quirks = (struct sun4i_tcon_quirks *)match->data; |
| 191 | |
| 192 | return quirks->has_channel_0; |
| 193 | } |
| 194 | |
| 195 | return false; |
| 196 | } |
| 197 | |
Jernej Skrabec | ef0cf64 | 2018-06-25 14:02:48 +0200 | [diff] [blame] | 198 | static bool sun4i_drv_node_is_tcon_top(struct device_node *node) |
| 199 | { |
Arnd Bergmann | 58d4d29 | 2018-07-11 16:43:10 +0200 | [diff] [blame] | 200 | return IS_ENABLED(CONFIG_DRM_SUN8I_TCON_TOP) && |
| 201 | !!of_match_node(sun8i_tcon_top_of_table, node); |
Jernej Skrabec | ef0cf64 | 2018-06-25 14:02:48 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 204 | static int compare_of(struct device *dev, void *data) |
| 205 | { |
Rob Herring | 4bf9914 | 2017-07-18 16:43:04 -0500 | [diff] [blame] | 206 | DRM_DEBUG_DRIVER("Comparing of node %pOF with %pOF\n", |
| 207 | dev->of_node, |
| 208 | data); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 209 | |
| 210 | return dev->of_node == data; |
| 211 | } |
| 212 | |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 213 | /* |
| 214 | * The encoder drivers use drm_of_find_possible_crtcs to get upstream |
| 215 | * crtcs from the device tree using of_graph. For the results to be |
| 216 | * correct, encoders must be probed/bound after _all_ crtcs have been |
| 217 | * created. The existing code uses a depth first recursive traversal |
| 218 | * of the of_graph, which means the encoders downstream of the TCON |
| 219 | * get add right after the first TCON. The second TCON or CRTC will |
| 220 | * never be properly associated with encoders connected to it. |
| 221 | * |
| 222 | * Also, in a dual display pipeline setup, both frontends can feed |
| 223 | * either backend, and both backends can feed either TCON, we want |
| 224 | * all components of the same type to be added before the next type |
| 225 | * in the pipeline. Fortunately, the pipelines are perfectly symmetric, |
| 226 | * i.e. components of the same type are at the same depth when counted |
| 227 | * from the frontend. The only exception is the third pipeline in |
| 228 | * the A80 SoC, which we do not support anyway. |
| 229 | * |
| 230 | * Hence we can use a breadth first search traversal order to add |
| 231 | * components. We do not need to check for duplicates. The component |
| 232 | * matching system handles this for us. |
| 233 | */ |
| 234 | struct endpoint_list { |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 235 | DECLARE_KFIFO(fifo, struct device_node *, 16); |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 236 | }; |
| 237 | |
Jernej Skrabec | 71f4796 | 2018-06-25 14:02:47 +0200 | [diff] [blame] | 238 | static void sun4i_drv_traverse_endpoints(struct endpoint_list *list, |
| 239 | struct device_node *node, |
| 240 | int port_id) |
| 241 | { |
| 242 | struct device_node *ep, *remote, *port; |
| 243 | |
| 244 | port = of_graph_get_port_by_id(node, port_id); |
| 245 | if (!port) { |
| 246 | DRM_DEBUG_DRIVER("No output to bind on port %d\n", port_id); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | for_each_available_child_of_node(port, ep) { |
| 251 | remote = of_graph_get_remote_port_parent(ep); |
| 252 | if (!remote) { |
| 253 | DRM_DEBUG_DRIVER("Error retrieving the output node\n"); |
| 254 | continue; |
| 255 | } |
| 256 | |
Jernej Skrabec | 71f4796 | 2018-06-25 14:02:47 +0200 | [diff] [blame] | 257 | if (sun4i_drv_node_is_tcon(node)) { |
Jernej Skrabec | ef0cf64 | 2018-06-25 14:02:48 +0200 | [diff] [blame] | 258 | /* |
| 259 | * TCON TOP is always probed before TCON. However, TCON |
| 260 | * points back to TCON TOP when it is source for HDMI. |
| 261 | * We have to skip it here to prevent infinite looping |
| 262 | * between TCON TOP and TCON. |
| 263 | */ |
| 264 | if (sun4i_drv_node_is_tcon_top(remote)) { |
| 265 | DRM_DEBUG_DRIVER("TCON output endpoint is TCON TOP... skipping\n"); |
| 266 | of_node_put(remote); |
| 267 | continue; |
| 268 | } |
| 269 | |
Jernej Skrabec | c5cf04d | 2018-06-25 14:02:49 +0200 | [diff] [blame] | 270 | /* |
| 271 | * If the node is our TCON with channel 0, the first |
| 272 | * port is used for panel or bridges, and will not be |
| 273 | * part of the component framework. |
| 274 | */ |
| 275 | if (sun4i_drv_node_is_tcon_with_ch0(node)) { |
| 276 | struct of_endpoint endpoint; |
Jernej Skrabec | 71f4796 | 2018-06-25 14:02:47 +0200 | [diff] [blame] | 277 | |
Jernej Skrabec | c5cf04d | 2018-06-25 14:02:49 +0200 | [diff] [blame] | 278 | if (of_graph_parse_endpoint(ep, &endpoint)) { |
| 279 | DRM_DEBUG_DRIVER("Couldn't parse endpoint\n"); |
| 280 | of_node_put(remote); |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | if (!endpoint.id) { |
| 285 | DRM_DEBUG_DRIVER("Endpoint is our panel... skipping\n"); |
| 286 | of_node_put(remote); |
| 287 | continue; |
| 288 | } |
Jernej Skrabec | 71f4796 | 2018-06-25 14:02:47 +0200 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | kfifo_put(&list->fifo, remote); |
| 293 | } |
| 294 | } |
| 295 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 296 | static int sun4i_drv_add_endpoints(struct device *dev, |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 297 | struct endpoint_list *list, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 298 | struct component_match **match, |
| 299 | struct device_node *node) |
| 300 | { |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 301 | int count = 0; |
| 302 | |
| 303 | /* |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 304 | * The frontend has been disabled in some of our old device |
| 305 | * trees. If we find a node that is the frontend and is |
| 306 | * disabled, we should just follow through and parse its |
| 307 | * child, but without adding it to the component list. |
| 308 | * Otherwise, we obviously want to add it to the list. |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 309 | */ |
| 310 | if (!sun4i_drv_node_is_frontend(node) && |
| 311 | !of_device_is_available(node)) |
| 312 | return 0; |
| 313 | |
Maxime Ripard | 49baeb0 | 2017-05-27 18:09:32 +0200 | [diff] [blame] | 314 | /* |
| 315 | * The connectors will be the last nodes in our pipeline, we |
| 316 | * can just bail out. |
| 317 | */ |
| 318 | if (sun4i_drv_node_is_connector(node)) |
| 319 | return 0; |
| 320 | |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 321 | /* |
| 322 | * If the device is either just a regular device, or an |
| 323 | * enabled frontend supported by the driver, we add it to our |
| 324 | * component list. |
| 325 | */ |
Chen-Yu Tsai | 3347895 | 2018-03-15 19:41:33 +0800 | [diff] [blame] | 326 | if (!(sun4i_drv_node_is_frontend(node) || |
| 327 | sun4i_drv_node_is_deu(node)) || |
Maxime Ripard | dd0421f | 2018-01-22 10:25:22 +0100 | [diff] [blame] | 328 | (sun4i_drv_node_is_supported_frontend(node) && |
| 329 | of_device_is_available(node))) { |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 330 | /* Add current component */ |
Rob Herring | 4bf9914 | 2017-07-18 16:43:04 -0500 | [diff] [blame] | 331 | DRM_DEBUG_DRIVER("Adding component %pOF\n", node); |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 332 | drm_of_component_match_add(dev, match, compare_of, node); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 333 | count++; |
| 334 | } |
| 335 | |
Jernej Skrabec | 71f4796 | 2018-06-25 14:02:47 +0200 | [diff] [blame] | 336 | /* each node has at least one output */ |
| 337 | sun4i_drv_traverse_endpoints(list, node, 1); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 338 | |
Jernej Skrabec | ef0cf64 | 2018-06-25 14:02:48 +0200 | [diff] [blame] | 339 | /* TCON TOP has second and third output */ |
| 340 | if (sun4i_drv_node_is_tcon_top(node)) { |
| 341 | sun4i_drv_traverse_endpoints(list, node, 3); |
| 342 | sun4i_drv_traverse_endpoints(list, node, 5); |
| 343 | } |
| 344 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 345 | return count; |
| 346 | } |
| 347 | |
Ondrej Jirman | 624b4b4 | 2019-10-29 12:28:46 +0100 | [diff] [blame] | 348 | #ifdef CONFIG_PM_SLEEP |
| 349 | static int sun4i_drv_drm_sys_suspend(struct device *dev) |
| 350 | { |
| 351 | struct drm_device *drm = dev_get_drvdata(dev); |
| 352 | |
| 353 | return drm_mode_config_helper_suspend(drm); |
| 354 | } |
| 355 | |
| 356 | static int sun4i_drv_drm_sys_resume(struct device *dev) |
| 357 | { |
| 358 | struct drm_device *drm = dev_get_drvdata(dev); |
| 359 | |
| 360 | return drm_mode_config_helper_resume(drm); |
| 361 | } |
| 362 | #endif |
| 363 | |
| 364 | static const struct dev_pm_ops sun4i_drv_drm_pm_ops = { |
| 365 | SET_SYSTEM_SLEEP_PM_OPS(sun4i_drv_drm_sys_suspend, |
| 366 | sun4i_drv_drm_sys_resume) |
| 367 | }; |
| 368 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 369 | static int sun4i_drv_probe(struct platform_device *pdev) |
| 370 | { |
| 371 | struct component_match *match = NULL; |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 372 | struct device_node *np = pdev->dev.of_node, *endpoint; |
| 373 | struct endpoint_list list; |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 374 | int i, ret, count = 0; |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 375 | |
| 376 | INIT_KFIFO(list.fifo); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 377 | |
| 378 | for (i = 0;; i++) { |
| 379 | struct device_node *pipeline = of_parse_phandle(np, |
| 380 | "allwinner,pipelines", |
| 381 | i); |
| 382 | if (!pipeline) |
| 383 | break; |
| 384 | |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 385 | kfifo_put(&list.fifo, pipeline); |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 386 | } |
| 387 | |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 388 | while (kfifo_get(&list.fifo, &endpoint)) { |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 389 | /* process this endpoint */ |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 390 | ret = sun4i_drv_add_endpoints(&pdev->dev, &list, &match, |
| 391 | endpoint); |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 392 | |
| 393 | /* sun4i_drv_add_endpoints can fail to allocate memory */ |
| 394 | if (ret < 0) |
Maxime Ripard | 8b11aaf | 2017-10-17 11:06:08 +0200 | [diff] [blame] | 395 | return ret; |
Chen-Yu Tsai | da82b87 | 2017-09-08 15:50:10 +0800 | [diff] [blame] | 396 | |
| 397 | count += ret; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if (count) |
| 401 | return component_master_add_with_match(&pdev->dev, |
| 402 | &sun4i_drv_master_ops, |
| 403 | match); |
| 404 | else |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int sun4i_drv_remove(struct platform_device *pdev) |
| 409 | { |
Paul Kocialkowski | f5a9ed8 | 2019-04-18 15:27:27 +0200 | [diff] [blame] | 410 | component_master_del(&pdev->dev, &sun4i_drv_master_ops); |
| 411 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static const struct of_device_id sun4i_drv_of_table[] = { |
Chen-Yu Tsai | 9a8187c | 2017-10-17 20:18:01 +0800 | [diff] [blame] | 416 | { .compatible = "allwinner,sun4i-a10-display-engine" }, |
Maxime Ripard | 110d33d | 2017-05-27 18:09:36 +0200 | [diff] [blame] | 417 | { .compatible = "allwinner,sun5i-a10s-display-engine" }, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 418 | { .compatible = "allwinner,sun5i-a13-display-engine" }, |
Chen-Yu Tsai | 49c440e | 2016-10-20 11:43:41 +0800 | [diff] [blame] | 419 | { .compatible = "allwinner,sun6i-a31-display-engine" }, |
| 420 | { .compatible = "allwinner,sun6i-a31s-display-engine" }, |
Jonathan Liu | aaddb6d | 2017-10-17 20:18:02 +0800 | [diff] [blame] | 421 | { .compatible = "allwinner,sun7i-a20-display-engine" }, |
Chen-Yu Tsai | d0ec0a3 | 2019-01-25 11:23:09 +0800 | [diff] [blame] | 422 | { .compatible = "allwinner,sun8i-a23-display-engine" }, |
Maxime Ripard | 4a408f1 | 2016-01-07 12:32:25 +0100 | [diff] [blame] | 423 | { .compatible = "allwinner,sun8i-a33-display-engine" }, |
Maxime Ripard | 2f0d7bb | 2017-12-21 12:02:34 +0100 | [diff] [blame] | 424 | { .compatible = "allwinner,sun8i-a83t-display-engine" }, |
Jernej Skrabec | 1ceb5f1 | 2018-03-01 22:34:33 +0100 | [diff] [blame] | 425 | { .compatible = "allwinner,sun8i-h3-display-engine" }, |
Chen-Yu Tsai | 3dcf0f3 | 2018-09-21 22:27:43 +0800 | [diff] [blame] | 426 | { .compatible = "allwinner,sun8i-r40-display-engine" }, |
Icenowy Zheng | 9df90c2 | 2017-05-17 22:47:21 +0800 | [diff] [blame] | 427 | { .compatible = "allwinner,sun8i-v3s-display-engine" }, |
Chen-Yu Tsai | 3347895 | 2018-03-15 19:41:33 +0800 | [diff] [blame] | 428 | { .compatible = "allwinner,sun9i-a80-display-engine" }, |
Jagan Teki | dd8bd54 | 2018-09-04 12:40:47 +0800 | [diff] [blame] | 429 | { .compatible = "allwinner,sun50i-a64-display-engine" }, |
Jernej Skrabec | 97f2930 | 2018-11-04 19:26:45 +0100 | [diff] [blame] | 430 | { .compatible = "allwinner,sun50i-h6-display-engine" }, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 431 | { } |
| 432 | }; |
| 433 | MODULE_DEVICE_TABLE(of, sun4i_drv_of_table); |
| 434 | |
| 435 | static struct platform_driver sun4i_drv_platform_driver = { |
| 436 | .probe = sun4i_drv_probe, |
| 437 | .remove = sun4i_drv_remove, |
| 438 | .driver = { |
| 439 | .name = "sun4i-drm", |
| 440 | .of_match_table = sun4i_drv_of_table, |
Ondrej Jirman | 624b4b4 | 2019-10-29 12:28:46 +0100 | [diff] [blame] | 441 | .pm = &sun4i_drv_drm_pm_ops, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 442 | }, |
| 443 | }; |
| 444 | module_platform_driver(sun4i_drv_platform_driver); |
| 445 | |
| 446 | MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>"); |
| 447 | MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); |
| 448 | MODULE_DESCRIPTION("Allwinner A10 Display Engine DRM/KMS Driver"); |
| 449 | MODULE_LICENSE("GPL"); |