dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / gpu / drm / armada / armada_drv.c
blobe660c5ca52ae73553eef75c4510ac3e896e555dd
1 /*
2 * Copyright (C) 2012 Russell King
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 #include <linux/clk.h>
9 #include <linux/component.h>
10 #include <linux/module.h>
11 #include <linux/of_graph.h>
12 #include <drm/drm_atomic_helper.h>
13 #include <drm/drm_probe_helper.h>
14 #include <drm/drm_fb_helper.h>
15 #include <drm/drm_of.h>
16 #include "armada_crtc.h"
17 #include "armada_drm.h"
18 #include "armada_gem.h"
19 #include "armada_fb.h"
20 #include "armada_hw.h"
21 #include <drm/armada_drm.h>
22 #include "armada_ioctlP.h"
24 static struct drm_ioctl_desc armada_ioctls[] = {
25 DRM_IOCTL_DEF_DRV(ARMADA_GEM_CREATE, armada_gem_create_ioctl,0),
26 DRM_IOCTL_DEF_DRV(ARMADA_GEM_MMAP, armada_gem_mmap_ioctl, 0),
27 DRM_IOCTL_DEF_DRV(ARMADA_GEM_PWRITE, armada_gem_pwrite_ioctl, 0),
30 DEFINE_DRM_GEM_FOPS(armada_drm_fops);
32 static struct drm_driver armada_drm_driver = {
33 .lastclose = drm_fb_helper_lastclose,
34 .gem_free_object_unlocked = armada_gem_free_object,
35 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
36 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
37 .gem_prime_export = armada_gem_prime_export,
38 .gem_prime_import = armada_gem_prime_import,
39 .dumb_create = armada_gem_dumb_create,
40 .gem_vm_ops = &armada_gem_vm_ops,
41 .major = 1,
42 .minor = 0,
43 .name = "armada-drm",
44 .desc = "Armada SoC DRM",
45 .date = "20120730",
46 .driver_features = DRIVER_GEM | DRIVER_MODESET |
47 DRIVER_PRIME | DRIVER_ATOMIC,
48 .ioctls = armada_ioctls,
49 .fops = &armada_drm_fops,
52 static const struct drm_mode_config_funcs armada_drm_mode_config_funcs = {
53 .fb_create = armada_fb_create,
54 .output_poll_changed = drm_fb_helper_output_poll_changed,
55 .atomic_check = drm_atomic_helper_check,
56 .atomic_commit = drm_atomic_helper_commit,
59 static int armada_drm_bind(struct device *dev)
61 struct armada_private *priv;
62 struct resource *mem = NULL;
63 int ret, n;
65 for (n = 0; ; n++) {
66 struct resource *r = platform_get_resource(to_platform_device(dev),
67 IORESOURCE_MEM, n);
68 if (!r)
69 break;
71 /* Resources above 64K are graphics memory */
72 if (resource_size(r) > SZ_64K)
73 mem = r;
74 else
75 return -EINVAL;
78 if (!mem)
79 return -ENXIO;
81 if (!devm_request_mem_region(dev, mem->start, resource_size(mem),
82 "armada-drm"))
83 return -EBUSY;
85 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
86 if (!priv)
87 return -ENOMEM;
90 * The drm_device structure must be at the start of
91 * armada_private for drm_dev_put() to work correctly.
93 BUILD_BUG_ON(offsetof(struct armada_private, drm) != 0);
95 ret = drm_dev_init(&priv->drm, &armada_drm_driver, dev);
96 if (ret) {
97 dev_err(dev, "[" DRM_NAME ":%s] drm_dev_init failed: %d\n",
98 __func__, ret);
99 kfree(priv);
100 return ret;
103 priv->drm.dev_private = priv;
105 dev_set_drvdata(dev, &priv->drm);
107 /* Mode setting support */
108 drm_mode_config_init(&priv->drm);
109 priv->drm.mode_config.min_width = 320;
110 priv->drm.mode_config.min_height = 200;
113 * With vscale enabled, the maximum width is 1920 due to the
114 * 1920 by 3 lines RAM
116 priv->drm.mode_config.max_width = 1920;
117 priv->drm.mode_config.max_height = 2048;
119 priv->drm.mode_config.preferred_depth = 24;
120 priv->drm.mode_config.funcs = &armada_drm_mode_config_funcs;
121 drm_mm_init(&priv->linear, mem->start, resource_size(mem));
122 mutex_init(&priv->linear_lock);
124 ret = component_bind_all(dev, &priv->drm);
125 if (ret)
126 goto err_kms;
128 ret = drm_vblank_init(&priv->drm, priv->drm.mode_config.num_crtc);
129 if (ret)
130 goto err_comp;
132 priv->drm.irq_enabled = true;
134 drm_mode_config_reset(&priv->drm);
136 ret = armada_fbdev_init(&priv->drm);
137 if (ret)
138 goto err_comp;
140 drm_kms_helper_poll_init(&priv->drm);
142 ret = drm_dev_register(&priv->drm, 0);
143 if (ret)
144 goto err_poll;
146 #ifdef CONFIG_DEBUG_FS
147 armada_drm_debugfs_init(priv->drm.primary);
148 #endif
150 return 0;
152 err_poll:
153 drm_kms_helper_poll_fini(&priv->drm);
154 armada_fbdev_fini(&priv->drm);
155 err_comp:
156 component_unbind_all(dev, &priv->drm);
157 err_kms:
158 drm_mode_config_cleanup(&priv->drm);
159 drm_mm_takedown(&priv->linear);
160 drm_dev_put(&priv->drm);
161 return ret;
164 static void armada_drm_unbind(struct device *dev)
166 struct drm_device *drm = dev_get_drvdata(dev);
167 struct armada_private *priv = drm->dev_private;
169 drm_kms_helper_poll_fini(&priv->drm);
170 armada_fbdev_fini(&priv->drm);
172 drm_dev_unregister(&priv->drm);
174 component_unbind_all(dev, &priv->drm);
176 drm_mode_config_cleanup(&priv->drm);
177 drm_mm_takedown(&priv->linear);
179 drm_dev_put(&priv->drm);
182 static int compare_of(struct device *dev, void *data)
184 return dev->of_node == data;
187 static int compare_dev_name(struct device *dev, void *data)
189 const char *name = data;
190 return !strcmp(dev_name(dev), name);
193 static void armada_add_endpoints(struct device *dev,
194 struct component_match **match, struct device_node *port)
196 struct device_node *ep, *remote;
198 for_each_child_of_node(port, ep) {
199 remote = of_graph_get_remote_port_parent(ep);
200 if (!remote || !of_device_is_available(remote)) {
201 of_node_put(remote);
202 continue;
203 } else if (!of_device_is_available(remote->parent)) {
204 dev_warn(dev, "parent device of %pOF is not available\n",
205 remote);
206 of_node_put(remote);
207 continue;
210 drm_of_component_match_add(dev, match, compare_of, remote);
211 of_node_put(remote);
215 static const struct component_master_ops armada_master_ops = {
216 .bind = armada_drm_bind,
217 .unbind = armada_drm_unbind,
220 static int armada_drm_probe(struct platform_device *pdev)
222 struct component_match *match = NULL;
223 struct device *dev = &pdev->dev;
224 int ret;
226 ret = drm_of_component_probe(dev, compare_dev_name, &armada_master_ops);
227 if (ret != -EINVAL)
228 return ret;
230 if (dev->platform_data) {
231 char **devices = dev->platform_data;
232 struct device_node *port;
233 struct device *d;
234 int i;
236 for (i = 0; devices[i]; i++)
237 component_match_add(dev, &match, compare_dev_name,
238 devices[i]);
240 if (i == 0) {
241 dev_err(dev, "missing 'ports' property\n");
242 return -ENODEV;
245 for (i = 0; devices[i]; i++) {
246 d = bus_find_device_by_name(&platform_bus_type, NULL,
247 devices[i]);
248 if (d && d->of_node) {
249 for_each_child_of_node(d->of_node, port)
250 armada_add_endpoints(dev, &match, port);
252 put_device(d);
256 return component_master_add_with_match(&pdev->dev, &armada_master_ops,
257 match);
260 static int armada_drm_remove(struct platform_device *pdev)
262 component_master_del(&pdev->dev, &armada_master_ops);
263 return 0;
266 static const struct platform_device_id armada_drm_platform_ids[] = {
268 .name = "armada-drm",
269 }, {
270 .name = "armada-510-drm",
272 { },
274 MODULE_DEVICE_TABLE(platform, armada_drm_platform_ids);
276 static struct platform_driver armada_drm_platform_driver = {
277 .probe = armada_drm_probe,
278 .remove = armada_drm_remove,
279 .driver = {
280 .name = "armada-drm",
282 .id_table = armada_drm_platform_ids,
285 static int __init armada_drm_init(void)
287 int ret;
289 armada_drm_driver.num_ioctls = ARRAY_SIZE(armada_ioctls);
291 ret = platform_driver_register(&armada_lcd_platform_driver);
292 if (ret)
293 return ret;
294 ret = platform_driver_register(&armada_drm_platform_driver);
295 if (ret)
296 platform_driver_unregister(&armada_lcd_platform_driver);
297 return ret;
299 module_init(armada_drm_init);
301 static void __exit armada_drm_exit(void)
303 platform_driver_unregister(&armada_drm_platform_driver);
304 platform_driver_unregister(&armada_lcd_platform_driver);
306 module_exit(armada_drm_exit);
308 MODULE_AUTHOR("Russell King <rmk+kernel@arm.linux.org.uk>");
309 MODULE_DESCRIPTION("Armada DRM Driver");
310 MODULE_LICENSE("GPL");
311 MODULE_ALIAS("platform:armada-drm");