Commit | Line | Data |
---|---|---|
e692da4d SH |
1 | /* |
2 | * Freescale i.MX drm driver | |
3 | * | |
4 | * Copyright (C) 2011 Sascha Hauer, Pengutronix | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | */ | |
17b5001b | 16 | #include <linux/component.h> |
e692da4d | 17 | #include <linux/device.h> |
e7d6231e RK |
18 | #include <linux/fb.h> |
19 | #include <linux/module.h> | |
655b43cc | 20 | #include <linux/of_graph.h> |
e692da4d SH |
21 | #include <linux/platform_device.h> |
22 | #include <drm/drmP.h> | |
23 | #include <drm/drm_fb_helper.h> | |
24 | #include <drm/drm_crtc_helper.h> | |
e692da4d SH |
25 | #include <drm/drm_gem_cma_helper.h> |
26 | #include <drm/drm_fb_cma_helper.h> | |
3cb9ae4f | 27 | #include <drm/drm_plane_helper.h> |
6457b971 | 28 | #include <drm/drm_of.h> |
e692da4d SH |
29 | |
30 | #include "imx-drm.h" | |
31 | ||
32 | #define MAX_CRTC 4 | |
33 | ||
655b43cc PZ |
34 | struct imx_drm_component { |
35 | struct device_node *of_node; | |
36 | struct list_head list; | |
37 | }; | |
38 | ||
e692da4d SH |
39 | struct imx_drm_device { |
40 | struct drm_device *drm; | |
887eceac | 41 | struct imx_drm_crtc *crtc[MAX_CRTC]; |
d2ab8ad9 | 42 | unsigned int pipes; |
e692da4d SH |
43 | struct drm_fbdev_cma *fbhelper; |
44 | }; | |
45 | ||
46 | struct imx_drm_crtc { | |
47 | struct drm_crtc *crtc; | |
e692da4d | 48 | struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; |
e692da4d SH |
49 | }; |
50 | ||
c1ff5a7a | 51 | #if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION) |
8acba02f RK |
52 | static int legacyfb_depth = 16; |
53 | module_param(legacyfb_depth, int, 0444); | |
c1ff5a7a | 54 | #endif |
8acba02f | 55 | |
d2ab8ad9 | 56 | unsigned int imx_drm_crtc_id(struct imx_drm_crtc *crtc) |
b8d181e4 | 57 | { |
d4b20e4d | 58 | return drm_crtc_index(crtc->crtc); |
b8d181e4 | 59 | } |
9c74360f | 60 | EXPORT_SYMBOL_GPL(imx_drm_crtc_id); |
b8d181e4 | 61 | |
e692da4d SH |
62 | static void imx_drm_driver_lastclose(struct drm_device *drm) |
63 | { | |
64 | struct imx_drm_device *imxdrm = drm->dev_private; | |
65 | ||
3f3a7280 | 66 | drm_fbdev_cma_restore_mode(imxdrm->fbhelper); |
e692da4d SH |
67 | } |
68 | ||
69 | static int imx_drm_driver_unload(struct drm_device *drm) | |
70 | { | |
71 | struct imx_drm_device *imxdrm = drm->dev_private; | |
3e68439b RK |
72 | |
73 | drm_kms_helper_poll_fini(drm); | |
e692da4d | 74 | |
8acba02f RK |
75 | if (imxdrm->fbhelper) |
76 | drm_fbdev_cma_fini(imxdrm->fbhelper); | |
8acba02f | 77 | |
17b5001b RK |
78 | component_unbind_all(drm->dev, drm); |
79 | ||
020a9ea7 | 80 | drm_vblank_cleanup(drm); |
020a9ea7 | 81 | drm_mode_config_cleanup(drm); |
e692da4d | 82 | |
bfe945c8 SG |
83 | platform_set_drvdata(drm->platformdev, NULL); |
84 | ||
e692da4d SH |
85 | return 0; |
86 | } | |
87 | ||
fdffa6f2 | 88 | static struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) |
e692da4d | 89 | { |
32266b45 | 90 | struct imx_drm_device *imxdrm = crtc->dev->dev_private; |
887eceac RK |
91 | unsigned i; |
92 | ||
93 | for (i = 0; i < MAX_CRTC; i++) | |
94 | if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) | |
95 | return imxdrm->crtc[i]; | |
e692da4d | 96 | |
e692da4d SH |
97 | return NULL; |
98 | } | |
99 | ||
2872c807 PZ |
100 | int imx_drm_set_bus_format_pins(struct drm_encoder *encoder, u32 bus_format, |
101 | int hsync_pin, int vsync_pin) | |
e692da4d | 102 | { |
e692da4d | 103 | struct imx_drm_crtc_helper_funcs *helper; |
887eceac | 104 | struct imx_drm_crtc *imx_crtc; |
e692da4d | 105 | |
f2d66aad | 106 | imx_crtc = imx_drm_find_crtc(encoder->crtc); |
887eceac RK |
107 | if (!imx_crtc) |
108 | return -EINVAL; | |
e692da4d | 109 | |
e692da4d SH |
110 | helper = &imx_crtc->imx_drm_helper_funcs; |
111 | if (helper->set_interface_pix_fmt) | |
f2d66aad | 112 | return helper->set_interface_pix_fmt(encoder->crtc, |
2872c807 | 113 | bus_format, hsync_pin, vsync_pin); |
e692da4d SH |
114 | return 0; |
115 | } | |
2872c807 | 116 | EXPORT_SYMBOL_GPL(imx_drm_set_bus_format_pins); |
2ea42608 | 117 | |
2872c807 | 118 | int imx_drm_set_bus_format(struct drm_encoder *encoder, u32 bus_format) |
2ea42608 | 119 | { |
2872c807 | 120 | return imx_drm_set_bus_format_pins(encoder, bus_format, 2, 3); |
2ea42608 | 121 | } |
2872c807 | 122 | EXPORT_SYMBOL_GPL(imx_drm_set_bus_format); |
e692da4d SH |
123 | |
124 | int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) | |
125 | { | |
d4b20e4d | 126 | return drm_crtc_vblank_get(imx_drm_crtc->crtc); |
e692da4d SH |
127 | } |
128 | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get); | |
129 | ||
130 | void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc) | |
131 | { | |
d4b20e4d | 132 | drm_crtc_vblank_put(imx_drm_crtc->crtc); |
e692da4d SH |
133 | } |
134 | EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put); | |
135 | ||
136 | void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc) | |
137 | { | |
d4b20e4d | 138 | drm_crtc_handle_vblank(imx_drm_crtc->crtc); |
e692da4d SH |
139 | } |
140 | EXPORT_SYMBOL_GPL(imx_drm_handle_vblank); | |
141 | ||
88e72717 | 142 | static int imx_drm_enable_vblank(struct drm_device *drm, unsigned int pipe) |
e692da4d SH |
143 | { |
144 | struct imx_drm_device *imxdrm = drm->dev_private; | |
88e72717 | 145 | struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[pipe]; |
e692da4d SH |
146 | int ret; |
147 | ||
e692da4d SH |
148 | if (!imx_drm_crtc) |
149 | return -EINVAL; | |
150 | ||
151 | if (!imx_drm_crtc->imx_drm_helper_funcs.enable_vblank) | |
152 | return -ENOSYS; | |
153 | ||
154 | ret = imx_drm_crtc->imx_drm_helper_funcs.enable_vblank( | |
155 | imx_drm_crtc->crtc); | |
156 | ||
157 | return ret; | |
158 | } | |
159 | ||
88e72717 | 160 | static void imx_drm_disable_vblank(struct drm_device *drm, unsigned int pipe) |
e692da4d SH |
161 | { |
162 | struct imx_drm_device *imxdrm = drm->dev_private; | |
88e72717 | 163 | struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[pipe]; |
e692da4d | 164 | |
e692da4d SH |
165 | if (!imx_drm_crtc) |
166 | return; | |
167 | ||
168 | if (!imx_drm_crtc->imx_drm_helper_funcs.disable_vblank) | |
169 | return; | |
170 | ||
171 | imx_drm_crtc->imx_drm_helper_funcs.disable_vblank(imx_drm_crtc->crtc); | |
172 | } | |
173 | ||
6ee4d7fe SH |
174 | static void imx_drm_driver_preclose(struct drm_device *drm, |
175 | struct drm_file *file) | |
176 | { | |
177 | int i; | |
178 | ||
179 | if (!file->is_master) | |
180 | return; | |
181 | ||
942325c8 RK |
182 | for (i = 0; i < MAX_CRTC; i++) |
183 | imx_drm_disable_vblank(drm, i); | |
6ee4d7fe SH |
184 | } |
185 | ||
e692da4d SH |
186 | static const struct file_operations imx_drm_driver_fops = { |
187 | .owner = THIS_MODULE, | |
188 | .open = drm_open, | |
189 | .release = drm_release, | |
190 | .unlocked_ioctl = drm_ioctl, | |
191 | .mmap = drm_gem_cma_mmap, | |
192 | .poll = drm_poll, | |
e692da4d SH |
193 | .read = drm_read, |
194 | .llseek = noop_llseek, | |
195 | }; | |
196 | ||
8a51a33b RK |
197 | void imx_drm_connector_destroy(struct drm_connector *connector) |
198 | { | |
34ea3d38 | 199 | drm_connector_unregister(connector); |
8a51a33b RK |
200 | drm_connector_cleanup(connector); |
201 | } | |
202 | EXPORT_SYMBOL_GPL(imx_drm_connector_destroy); | |
203 | ||
204 | void imx_drm_encoder_destroy(struct drm_encoder *encoder) | |
205 | { | |
206 | drm_encoder_cleanup(encoder); | |
207 | } | |
208 | EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy); | |
209 | ||
3e68439b RK |
210 | static void imx_drm_output_poll_changed(struct drm_device *drm) |
211 | { | |
3e68439b RK |
212 | struct imx_drm_device *imxdrm = drm->dev_private; |
213 | ||
214 | drm_fbdev_cma_hotplug_event(imxdrm->fbhelper); | |
3e68439b RK |
215 | } |
216 | ||
7ae847dd | 217 | static const struct drm_mode_config_funcs imx_drm_mode_config_funcs = { |
1df8b530 | 218 | .fb_create = drm_fb_cma_create, |
3e68439b | 219 | .output_poll_changed = imx_drm_output_poll_changed, |
1df8b530 RK |
220 | }; |
221 | ||
e692da4d | 222 | /* |
17b5001b RK |
223 | * Main DRM initialisation. This binds, initialises and registers |
224 | * with DRM the subcomponents of the driver. | |
e692da4d SH |
225 | */ |
226 | static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags) | |
227 | { | |
b85f2b5d | 228 | struct imx_drm_device *imxdrm; |
e355e7dd | 229 | struct drm_connector *connector; |
e692da4d SH |
230 | int ret; |
231 | ||
b85f2b5d RK |
232 | imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL); |
233 | if (!imxdrm) | |
234 | return -ENOMEM; | |
235 | ||
e692da4d SH |
236 | imxdrm->drm = drm; |
237 | ||
238 | drm->dev_private = imxdrm; | |
239 | ||
240 | /* | |
241 | * enable drm irq mode. | |
4423843c | 242 | * - with irq_enabled = true, we can use the vblank feature. |
e692da4d SH |
243 | * |
244 | * P.S. note that we wouldn't use drm irq handler but | |
245 | * just specific driver own one instead because | |
246 | * drm framework supports only one irq handler and | |
247 | * drivers can well take care of their interrupts | |
248 | */ | |
4423843c | 249 | drm->irq_enabled = true; |
e692da4d | 250 | |
1df8b530 RK |
251 | /* |
252 | * set max width and height as default value(4096x4096). | |
253 | * this value would be used to check framebuffer size limitation | |
254 | * at drm_mode_addfb(). | |
255 | */ | |
256 | drm->mode_config.min_width = 64; | |
257 | drm->mode_config.min_height = 64; | |
258 | drm->mode_config.max_width = 4096; | |
259 | drm->mode_config.max_height = 4096; | |
260 | drm->mode_config.funcs = &imx_drm_mode_config_funcs; | |
261 | ||
e692da4d | 262 | drm_mode_config_init(drm); |
e692da4d | 263 | |
020a9ea7 | 264 | ret = drm_vblank_init(drm, MAX_CRTC); |
e692da4d | 265 | if (ret) |
8007875f | 266 | goto err_kms; |
e692da4d SH |
267 | |
268 | /* | |
e7d6231e RK |
269 | * with vblank_disable_allowed = true, vblank interrupt will be |
270 | * disabled by drm timer once a current process gives up ownership | |
271 | * of vblank event. (after drm_vblank_put function is called) | |
e692da4d | 272 | */ |
020a9ea7 | 273 | drm->vblank_disable_allowed = true; |
e692da4d | 274 | |
a72f8bee | 275 | platform_set_drvdata(drm->platformdev, drm); |
8d71de61 | 276 | |
17b5001b RK |
277 | /* Now try and bind all our sub-components */ |
278 | ret = component_bind_all(drm->dev, drm); | |
279 | if (ret) | |
ccec7f62 | 280 | goto err_vblank; |
e355e7dd RK |
281 | |
282 | /* | |
283 | * All components are now added, we can publish the connector sysfs | |
284 | * entries to userspace. This will generate hotplug events and so | |
285 | * userspace will expect to be able to access DRM at this point. | |
286 | */ | |
287 | list_for_each_entry(connector, &drm->mode_config.connector_list, head) { | |
34ea3d38 | 288 | ret = drm_connector_register(connector); |
e355e7dd RK |
289 | if (ret) { |
290 | dev_err(drm->dev, | |
34ea3d38 | 291 | "[CONNECTOR:%d:%s] drm_connector_register failed: %d\n", |
e355e7dd | 292 | connector->base.id, |
4a2a450f | 293 | connector->name, ret); |
e355e7dd RK |
294 | goto err_unbind; |
295 | } | |
296 | } | |
297 | ||
8acba02f RK |
298 | /* |
299 | * All components are now initialised, so setup the fb helper. | |
300 | * The fb helper takes copies of key hardware information, so the | |
301 | * crtcs/connectors/encoders must not change after this point. | |
302 | */ | |
c1ff5a7a | 303 | #if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION) |
8acba02f RK |
304 | if (legacyfb_depth != 16 && legacyfb_depth != 32) { |
305 | dev_warn(drm->dev, "Invalid legacyfb_depth. Defaulting to 16bpp\n"); | |
306 | legacyfb_depth = 16; | |
307 | } | |
308 | imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth, | |
309 | drm->mode_config.num_crtc, MAX_CRTC); | |
310 | if (IS_ERR(imxdrm->fbhelper)) { | |
311 | ret = PTR_ERR(imxdrm->fbhelper); | |
312 | imxdrm->fbhelper = NULL; | |
313 | goto err_unbind; | |
314 | } | |
315 | #endif | |
3e68439b RK |
316 | |
317 | drm_kms_helper_poll_init(drm); | |
318 | ||
8007875f | 319 | return 0; |
a72f8bee | 320 | |
e355e7dd RK |
321 | err_unbind: |
322 | component_unbind_all(drm->dev, drm); | |
ccec7f62 | 323 | err_vblank: |
8007875f RK |
324 | drm_vblank_cleanup(drm); |
325 | err_kms: | |
8007875f | 326 | drm_mode_config_cleanup(drm); |
e692da4d SH |
327 | |
328 | return ret; | |
329 | } | |
330 | ||
e692da4d SH |
331 | /* |
332 | * imx_drm_add_crtc - add a new crtc | |
e692da4d | 333 | */ |
32266b45 | 334 | int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc, |
43895599 | 335 | struct imx_drm_crtc **new_crtc, struct drm_plane *primary_plane, |
e692da4d | 336 | const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs, |
655b43cc | 337 | struct device_node *port) |
e692da4d | 338 | { |
32266b45 | 339 | struct imx_drm_device *imxdrm = drm->dev_private; |
e692da4d | 340 | struct imx_drm_crtc *imx_drm_crtc; |
e692da4d SH |
341 | int ret; |
342 | ||
fd6040ed RK |
343 | /* |
344 | * The vblank arrays are dimensioned by MAX_CRTC - we can't | |
345 | * pass IDs greater than this to those functions. | |
346 | */ | |
e7d6231e RK |
347 | if (imxdrm->pipes >= MAX_CRTC) |
348 | return -EINVAL; | |
fd6040ed | 349 | |
e7d6231e RK |
350 | if (imxdrm->drm->open_count) |
351 | return -EBUSY; | |
e692da4d SH |
352 | |
353 | imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL); | |
e7d6231e RK |
354 | if (!imx_drm_crtc) |
355 | return -ENOMEM; | |
e692da4d SH |
356 | |
357 | imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs; | |
e692da4d | 358 | imx_drm_crtc->crtc = crtc; |
e692da4d | 359 | |
6457b971 RK |
360 | crtc->port = port; |
361 | ||
d4b20e4d | 362 | imxdrm->crtc[imxdrm->pipes++] = imx_drm_crtc; |
e692da4d SH |
363 | |
364 | *new_crtc = imx_drm_crtc; | |
365 | ||
ec9557d7 | 366 | ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256); |
e692da4d SH |
367 | if (ret) |
368 | goto err_register; | |
369 | ||
ec9557d7 RK |
370 | drm_crtc_helper_add(crtc, |
371 | imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs); | |
372 | ||
43895599 | 373 | drm_crtc_init_with_planes(drm, crtc, primary_plane, NULL, |
f9882876 | 374 | imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs, NULL); |
ec9557d7 | 375 | |
e692da4d SH |
376 | return 0; |
377 | ||
378 | err_register: | |
d4b20e4d | 379 | imxdrm->crtc[--imxdrm->pipes] = NULL; |
e692da4d | 380 | kfree(imx_drm_crtc); |
e692da4d SH |
381 | return ret; |
382 | } | |
383 | EXPORT_SYMBOL_GPL(imx_drm_add_crtc); | |
384 | ||
385 | /* | |
386 | * imx_drm_remove_crtc - remove a crtc | |
387 | */ | |
388 | int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) | |
389 | { | |
ccec7f62 | 390 | struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private; |
d4b20e4d | 391 | unsigned int pipe = drm_crtc_index(imx_drm_crtc->crtc); |
e692da4d SH |
392 | |
393 | drm_crtc_cleanup(imx_drm_crtc->crtc); | |
394 | ||
d4b20e4d | 395 | imxdrm->crtc[pipe] = NULL; |
e692da4d | 396 | |
e692da4d SH |
397 | kfree(imx_drm_crtc); |
398 | ||
399 | return 0; | |
400 | } | |
401 | EXPORT_SYMBOL_GPL(imx_drm_remove_crtc); | |
402 | ||
6457b971 RK |
403 | int imx_drm_encoder_parse_of(struct drm_device *drm, |
404 | struct drm_encoder *encoder, struct device_node *np) | |
9e2d410d | 405 | { |
6457b971 | 406 | uint32_t crtc_mask = drm_of_find_possible_crtcs(drm, np); |
9e2d410d | 407 | |
6457b971 RK |
408 | /* |
409 | * If we failed to find the CRTC(s) which this encoder is | |
410 | * supposed to be connected to, it's because the CRTC has | |
411 | * not been registered yet. Defer probing, and hope that | |
412 | * the required CRTC is added later. | |
413 | */ | |
414 | if (crtc_mask == 0) | |
415 | return -EPROBE_DEFER; | |
655b43cc | 416 | |
6457b971 | 417 | encoder->possible_crtcs = crtc_mask; |
63bc5164 | 418 | |
6457b971 RK |
419 | /* FIXME: this is the mask of outputs which can clone this output. */ |
420 | encoder->possible_clones = ~0; | |
9e2d410d RK |
421 | |
422 | return 0; | |
423 | } | |
6457b971 | 424 | EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); |
9e2d410d | 425 | |
655b43cc PZ |
426 | /* |
427 | * @node: device tree node containing encoder input ports | |
428 | * @encoder: drm_encoder | |
429 | */ | |
430 | int imx_drm_encoder_get_mux_id(struct device_node *node, | |
431 | struct drm_encoder *encoder) | |
e692da4d | 432 | { |
887eceac | 433 | struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc); |
539bb6a2 | 434 | struct device_node *ep; |
b6babdd9 | 435 | struct of_endpoint endpoint; |
655b43cc | 436 | struct device_node *port; |
b6babdd9 | 437 | int ret; |
e692da4d | 438 | |
655b43cc PZ |
439 | if (!node || !imx_crtc) |
440 | return -EINVAL; | |
441 | ||
539bb6a2 | 442 | for_each_endpoint_of_node(node, ep) { |
655b43cc PZ |
443 | port = of_graph_get_remote_port(ep); |
444 | of_node_put(port); | |
6457b971 | 445 | if (port == imx_crtc->crtc->port) { |
b6babdd9 | 446 | ret = of_graph_parse_endpoint(ep, &endpoint); |
539bb6a2 | 447 | of_node_put(ep); |
c509bdc2 | 448 | return ret ? ret : endpoint.port; |
655b43cc | 449 | } |
539bb6a2 | 450 | } |
e692da4d | 451 | |
655b43cc | 452 | return -EINVAL; |
e692da4d | 453 | } |
ea8d1583 | 454 | EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); |
e692da4d | 455 | |
baa70943 | 456 | static const struct drm_ioctl_desc imx_drm_ioctls[] = { |
e692da4d SH |
457 | /* none so far */ |
458 | }; | |
459 | ||
460 | static struct drm_driver imx_drm_driver = { | |
bd3665c9 | 461 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
e692da4d SH |
462 | .load = imx_drm_driver_load, |
463 | .unload = imx_drm_driver_unload, | |
e692da4d | 464 | .lastclose = imx_drm_driver_lastclose, |
6ee4d7fe | 465 | .preclose = imx_drm_driver_preclose, |
915b4d11 | 466 | .set_busid = drm_platform_set_busid, |
e692da4d SH |
467 | .gem_free_object = drm_gem_cma_free_object, |
468 | .gem_vm_ops = &drm_gem_cma_vm_ops, | |
469 | .dumb_create = drm_gem_cma_dumb_create, | |
470 | .dumb_map_offset = drm_gem_cma_dumb_map_offset, | |
43387b37 | 471 | .dumb_destroy = drm_gem_dumb_destroy, |
e692da4d | 472 | |
bd3665c9 PZ |
473 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
474 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, | |
475 | .gem_prime_import = drm_gem_prime_import, | |
476 | .gem_prime_export = drm_gem_prime_export, | |
477 | .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, | |
478 | .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, | |
479 | .gem_prime_vmap = drm_gem_cma_prime_vmap, | |
480 | .gem_prime_vunmap = drm_gem_cma_prime_vunmap, | |
481 | .gem_prime_mmap = drm_gem_cma_prime_mmap, | |
b44f8408 | 482 | .get_vblank_counter = drm_vblank_no_hw_counter, |
e692da4d SH |
483 | .enable_vblank = imx_drm_enable_vblank, |
484 | .disable_vblank = imx_drm_disable_vblank, | |
485 | .ioctls = imx_drm_ioctls, | |
486 | .num_ioctls = ARRAY_SIZE(imx_drm_ioctls), | |
487 | .fops = &imx_drm_driver_fops, | |
488 | .name = "imx-drm", | |
489 | .desc = "i.MX DRM graphics", | |
490 | .date = "20120507", | |
491 | .major = 1, | |
492 | .minor = 0, | |
493 | .patchlevel = 0, | |
494 | }; | |
495 | ||
17b5001b RK |
496 | static int compare_of(struct device *dev, void *data) |
497 | { | |
655b43cc | 498 | struct device_node *np = data; |
17b5001b | 499 | |
655b43cc PZ |
500 | /* Special case for LDB, one device for two channels */ |
501 | if (of_node_cmp(np->name, "lvds-channel") == 0) { | |
502 | np = of_get_parent(np); | |
503 | of_node_put(np); | |
17b5001b RK |
504 | } |
505 | ||
655b43cc PZ |
506 | return dev->of_node == np; |
507 | } | |
17b5001b | 508 | |
17b5001b RK |
509 | static int imx_drm_bind(struct device *dev) |
510 | { | |
511 | return drm_platform_init(&imx_drm_driver, to_platform_device(dev)); | |
512 | } | |
513 | ||
514 | static void imx_drm_unbind(struct device *dev) | |
515 | { | |
516 | drm_put_dev(dev_get_drvdata(dev)); | |
517 | } | |
518 | ||
519 | static const struct component_master_ops imx_drm_ops = { | |
17b5001b RK |
520 | .bind = imx_drm_bind, |
521 | .unbind = imx_drm_unbind, | |
522 | }; | |
523 | ||
e692da4d SH |
524 | static int imx_drm_platform_probe(struct platform_device *pdev) |
525 | { | |
9cace32f | 526 | int ret = drm_of_component_probe(&pdev->dev, compare_of, &imx_drm_ops); |
655b43cc | 527 | |
9cace32f LD |
528 | if (!ret) |
529 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | |
655b43cc | 530 | |
9cace32f | 531 | return ret; |
e692da4d SH |
532 | } |
533 | ||
534 | static int imx_drm_platform_remove(struct platform_device *pdev) | |
535 | { | |
17b5001b | 536 | component_master_del(&pdev->dev, &imx_drm_ops); |
e692da4d SH |
537 | return 0; |
538 | } | |
539 | ||
bfe945c8 SG |
540 | #ifdef CONFIG_PM_SLEEP |
541 | static int imx_drm_suspend(struct device *dev) | |
542 | { | |
543 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
544 | ||
545 | /* The drm_dev is NULL before .load hook is called */ | |
546 | if (drm_dev == NULL) | |
547 | return 0; | |
548 | ||
549 | drm_kms_helper_poll_disable(drm_dev); | |
550 | ||
551 | return 0; | |
552 | } | |
553 | ||
554 | static int imx_drm_resume(struct device *dev) | |
555 | { | |
556 | struct drm_device *drm_dev = dev_get_drvdata(dev); | |
557 | ||
558 | if (drm_dev == NULL) | |
559 | return 0; | |
560 | ||
561 | drm_helper_resume_force_mode(drm_dev); | |
562 | drm_kms_helper_poll_enable(drm_dev); | |
563 | ||
564 | return 0; | |
565 | } | |
566 | #endif | |
567 | ||
568 | static SIMPLE_DEV_PM_OPS(imx_drm_pm_ops, imx_drm_suspend, imx_drm_resume); | |
569 | ||
17b5001b | 570 | static const struct of_device_id imx_drm_dt_ids[] = { |
655b43cc | 571 | { .compatible = "fsl,imx-display-subsystem", }, |
17b5001b RK |
572 | { /* sentinel */ }, |
573 | }; | |
574 | MODULE_DEVICE_TABLE(of, imx_drm_dt_ids); | |
575 | ||
e692da4d SH |
576 | static struct platform_driver imx_drm_pdrv = { |
577 | .probe = imx_drm_platform_probe, | |
99c28f10 | 578 | .remove = imx_drm_platform_remove, |
e692da4d | 579 | .driver = { |
e692da4d | 580 | .name = "imx-drm", |
bfe945c8 | 581 | .pm = &imx_drm_pm_ops, |
17b5001b | 582 | .of_match_table = imx_drm_dt_ids, |
e692da4d SH |
583 | }, |
584 | }; | |
b85f2b5d | 585 | module_platform_driver(imx_drm_pdrv); |
e692da4d SH |
586 | |
587 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); | |
588 | MODULE_DESCRIPTION("i.MX drm driver core"); | |
589 | MODULE_LICENSE("GPL"); |