Commit | Line | Data |
---|---|---|
cd5351f4 RC |
1 | /* |
2 | * drivers/staging/omapdrm/omap_drv.c | |
3 | * | |
4 | * Copyright (C) 2011 Texas Instruments | |
5 | * Author: Rob Clark <rob@ti.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License version 2 as published by | |
9 | * the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along with | |
17 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "omap_drv.h" | |
21 | ||
22 | #include "drm_crtc_helper.h" | |
23 | #include "drm_fb_helper.h" | |
5c137797 | 24 | #include "omap_dmm_tiler.h" |
cd5351f4 RC |
25 | |
26 | #define DRIVER_NAME MODULE_NAME | |
27 | #define DRIVER_DESC "OMAP DRM" | |
28 | #define DRIVER_DATE "20110917" | |
29 | #define DRIVER_MAJOR 1 | |
30 | #define DRIVER_MINOR 0 | |
31 | #define DRIVER_PATCHLEVEL 0 | |
32 | ||
33 | struct drm_device *drm_device; | |
34 | ||
35 | static int num_crtc = CONFIG_DRM_OMAP_NUM_CRTCS; | |
36 | ||
37 | MODULE_PARM_DESC(num_crtc, "Number of overlays to use as CRTCs"); | |
38 | module_param(num_crtc, int, 0600); | |
39 | ||
40 | /* | |
41 | * mode config funcs | |
42 | */ | |
43 | ||
44 | /* Notes about mapping DSS and DRM entities: | |
45 | * CRTC: overlay | |
46 | * encoder: manager.. with some extension to allow one primary CRTC | |
47 | * and zero or more video CRTC's to be mapped to one encoder? | |
48 | * connector: dssdev.. manager can be attached/detached from different | |
49 | * devices | |
50 | */ | |
51 | ||
52 | static void omap_fb_output_poll_changed(struct drm_device *dev) | |
53 | { | |
54 | struct omap_drm_private *priv = dev->dev_private; | |
55 | DBG("dev=%p", dev); | |
56 | if (priv->fbdev) { | |
57 | drm_fb_helper_hotplug_event(priv->fbdev); | |
58 | } | |
59 | } | |
60 | ||
e6ecefaa | 61 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
cd5351f4 RC |
62 | .fb_create = omap_framebuffer_create, |
63 | .output_poll_changed = omap_fb_output_poll_changed, | |
64 | }; | |
65 | ||
66 | static int get_connector_type(struct omap_dss_device *dssdev) | |
67 | { | |
68 | switch (dssdev->type) { | |
69 | case OMAP_DISPLAY_TYPE_HDMI: | |
70 | return DRM_MODE_CONNECTOR_HDMIA; | |
71 | case OMAP_DISPLAY_TYPE_DPI: | |
72 | if (!strcmp(dssdev->name, "dvi")) | |
73 | return DRM_MODE_CONNECTOR_DVID; | |
74 | /* fallthrough */ | |
75 | default: | |
76 | return DRM_MODE_CONNECTOR_Unknown; | |
77 | } | |
78 | } | |
79 | ||
80 | #if 0 /* enable when dss2 supports hotplug */ | |
81 | static int omap_drm_notifier(struct notifier_block *nb, | |
82 | unsigned long evt, void *arg) | |
83 | { | |
84 | switch (evt) { | |
85 | case OMAP_DSS_SIZE_CHANGE: | |
86 | case OMAP_DSS_HOTPLUG_CONNECT: | |
87 | case OMAP_DSS_HOTPLUG_DISCONNECT: { | |
88 | struct drm_device *dev = drm_device; | |
89 | DBG("hotplug event: evt=%d, dev=%p", evt, dev); | |
90 | if (dev) { | |
91 | drm_sysfs_hotplug_event(dev); | |
92 | } | |
93 | return NOTIFY_OK; | |
94 | } | |
95 | default: /* don't care about other events for now */ | |
96 | return NOTIFY_DONE; | |
97 | } | |
98 | } | |
99 | #endif | |
100 | ||
101 | static void dump_video_chains(void) | |
102 | { | |
103 | int i; | |
104 | ||
105 | DBG("dumping video chains: "); | |
106 | for (i = 0; i < omap_dss_get_num_overlays(); i++) { | |
107 | struct omap_overlay *ovl = omap_dss_get_overlay(i); | |
108 | struct omap_overlay_manager *mgr = ovl->manager; | |
23e2aa64 AT |
109 | struct omap_dss_device *dssdev = mgr ? |
110 | mgr->get_device(mgr) : NULL; | |
cd5351f4 RC |
111 | if (dssdev) { |
112 | DBG("%d: %s -> %s -> %s", i, ovl->name, mgr->name, | |
113 | dssdev->name); | |
114 | } else if (mgr) { | |
115 | DBG("%d: %s -> %s", i, ovl->name, mgr->name); | |
116 | } else { | |
117 | DBG("%d: %s", i, ovl->name); | |
118 | } | |
119 | } | |
120 | } | |
121 | ||
122 | /* create encoders for each manager */ | |
123 | static int create_encoder(struct drm_device *dev, | |
124 | struct omap_overlay_manager *mgr) | |
125 | { | |
126 | struct omap_drm_private *priv = dev->dev_private; | |
127 | struct drm_encoder *encoder = omap_encoder_init(dev, mgr); | |
128 | ||
129 | if (!encoder) { | |
130 | dev_err(dev->dev, "could not create encoder: %s\n", | |
131 | mgr->name); | |
132 | return -ENOMEM; | |
133 | } | |
134 | ||
135 | BUG_ON(priv->num_encoders >= ARRAY_SIZE(priv->encoders)); | |
136 | ||
137 | priv->encoders[priv->num_encoders++] = encoder; | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
142 | /* create connectors for each display device */ | |
143 | static int create_connector(struct drm_device *dev, | |
144 | struct omap_dss_device *dssdev) | |
145 | { | |
146 | struct omap_drm_private *priv = dev->dev_private; | |
147 | static struct notifier_block *notifier; | |
148 | struct drm_connector *connector; | |
149 | int j; | |
150 | ||
151 | if (!dssdev->driver) { | |
152 | dev_warn(dev->dev, "%s has no driver.. skipping it\n", | |
153 | dssdev->name); | |
154 | return 0; | |
155 | } | |
156 | ||
157 | if (!(dssdev->driver->get_timings || | |
158 | dssdev->driver->read_edid)) { | |
159 | dev_warn(dev->dev, "%s driver does not support " | |
160 | "get_timings or read_edid.. skipping it!\n", | |
161 | dssdev->name); | |
162 | return 0; | |
163 | } | |
164 | ||
165 | connector = omap_connector_init(dev, | |
166 | get_connector_type(dssdev), dssdev); | |
167 | ||
168 | if (!connector) { | |
169 | dev_err(dev->dev, "could not create connector: %s\n", | |
170 | dssdev->name); | |
171 | return -ENOMEM; | |
172 | } | |
173 | ||
174 | BUG_ON(priv->num_connectors >= ARRAY_SIZE(priv->connectors)); | |
175 | ||
176 | priv->connectors[priv->num_connectors++] = connector; | |
177 | ||
178 | #if 0 /* enable when dss2 supports hotplug */ | |
179 | notifier = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); | |
180 | notifier->notifier_call = omap_drm_notifier; | |
181 | omap_dss_add_notify(dssdev, notifier); | |
182 | #else | |
183 | notifier = NULL; | |
184 | #endif | |
185 | ||
186 | for (j = 0; j < priv->num_encoders; j++) { | |
187 | struct omap_overlay_manager *mgr = | |
188 | omap_encoder_get_manager(priv->encoders[j]); | |
23e2aa64 | 189 | if (mgr->get_device(mgr) == dssdev) { |
cd5351f4 RC |
190 | drm_mode_connector_attach_encoder(connector, |
191 | priv->encoders[j]); | |
192 | } | |
193 | } | |
194 | ||
195 | return 0; | |
196 | } | |
197 | ||
198 | /* create up to max_overlays CRTCs mapping to overlays.. by default, | |
199 | * connect the overlays to different managers/encoders, giving priority | |
200 | * to encoders connected to connectors with a detected connection | |
201 | */ | |
202 | static int create_crtc(struct drm_device *dev, struct omap_overlay *ovl, | |
203 | int *j, unsigned int connected_connectors) | |
204 | { | |
205 | struct omap_drm_private *priv = dev->dev_private; | |
206 | struct omap_overlay_manager *mgr = NULL; | |
207 | struct drm_crtc *crtc; | |
208 | ||
cd5351f4 RC |
209 | /* find next best connector, ones with detected connection first |
210 | */ | |
211 | while (*j < priv->num_connectors && !mgr) { | |
212 | if (connected_connectors & (1 << *j)) { | |
213 | struct drm_encoder *encoder = | |
214 | omap_connector_attached_encoder( | |
215 | priv->connectors[*j]); | |
216 | if (encoder) { | |
217 | mgr = omap_encoder_get_manager(encoder); | |
218 | } | |
219 | } | |
220 | (*j)++; | |
221 | } | |
222 | ||
223 | /* if we couldn't find another connected connector, lets start | |
224 | * looking at the unconnected connectors: | |
225 | * | |
226 | * note: it might not be immediately apparent, but thanks to | |
227 | * the !mgr check in both this loop and the one above, the only | |
228 | * way to enter this loop is with *j == priv->num_connectors, | |
229 | * so idx can never go negative. | |
230 | */ | |
231 | while (*j < 2 * priv->num_connectors && !mgr) { | |
232 | int idx = *j - priv->num_connectors; | |
233 | if (!(connected_connectors & (1 << idx))) { | |
234 | struct drm_encoder *encoder = | |
235 | omap_connector_attached_encoder( | |
236 | priv->connectors[idx]); | |
237 | if (encoder) { | |
238 | mgr = omap_encoder_get_manager(encoder); | |
239 | } | |
240 | } | |
241 | (*j)++; | |
242 | } | |
243 | ||
cd5351f4 RC |
244 | crtc = omap_crtc_init(dev, ovl, priv->num_crtcs); |
245 | ||
246 | if (!crtc) { | |
247 | dev_err(dev->dev, "could not create CRTC: %s\n", | |
248 | ovl->name); | |
249 | return -ENOMEM; | |
250 | } | |
251 | ||
252 | BUG_ON(priv->num_crtcs >= ARRAY_SIZE(priv->crtcs)); | |
253 | ||
254 | priv->crtcs[priv->num_crtcs++] = crtc; | |
255 | ||
256 | return 0; | |
257 | } | |
258 | ||
bb5c2d9a RC |
259 | static int create_plane(struct drm_device *dev, struct omap_overlay *ovl, |
260 | unsigned int possible_crtcs) | |
261 | { | |
262 | struct omap_drm_private *priv = dev->dev_private; | |
263 | struct drm_plane *plane = | |
264 | omap_plane_init(dev, ovl, possible_crtcs, false); | |
265 | ||
266 | if (!plane) { | |
267 | dev_err(dev->dev, "could not create plane: %s\n", | |
268 | ovl->name); | |
269 | return -ENOMEM; | |
270 | } | |
271 | ||
272 | BUG_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)); | |
273 | ||
274 | priv->planes[priv->num_planes++] = plane; | |
275 | ||
276 | return 0; | |
277 | } | |
278 | ||
cd5351f4 RC |
279 | static int match_dev_name(struct omap_dss_device *dssdev, void *data) |
280 | { | |
281 | return !strcmp(dssdev->name, data); | |
282 | } | |
283 | ||
284 | static unsigned int detect_connectors(struct drm_device *dev) | |
285 | { | |
286 | struct omap_drm_private *priv = dev->dev_private; | |
287 | unsigned int connected_connectors = 0; | |
288 | int i; | |
289 | ||
290 | for (i = 0; i < priv->num_connectors; i++) { | |
291 | struct drm_connector *connector = priv->connectors[i]; | |
292 | if (omap_connector_detect(connector, true) == | |
293 | connector_status_connected) { | |
294 | connected_connectors |= (1 << i); | |
295 | } | |
296 | } | |
297 | ||
298 | return connected_connectors; | |
299 | } | |
300 | ||
301 | static int omap_modeset_init(struct drm_device *dev) | |
302 | { | |
303 | const struct omap_drm_platform_data *pdata = dev->dev->platform_data; | |
71e8831f | 304 | struct omap_kms_platform_data *kms_pdata = NULL; |
cd5351f4 RC |
305 | struct omap_drm_private *priv = dev->dev_private; |
306 | struct omap_dss_device *dssdev = NULL; | |
307 | int i, j; | |
308 | unsigned int connected_connectors = 0; | |
309 | ||
310 | drm_mode_config_init(dev); | |
311 | ||
71e8831f AG |
312 | if (pdata && pdata->kms_pdata) { |
313 | kms_pdata = pdata->kms_pdata; | |
314 | ||
cd5351f4 RC |
315 | /* if platform data is provided by the board file, use it to |
316 | * control which overlays, managers, and devices we own. | |
317 | */ | |
71e8831f | 318 | for (i = 0; i < kms_pdata->mgr_cnt; i++) { |
cd5351f4 | 319 | struct omap_overlay_manager *mgr = |
71e8831f AG |
320 | omap_dss_get_overlay_manager( |
321 | kms_pdata->mgr_ids[i]); | |
cd5351f4 RC |
322 | create_encoder(dev, mgr); |
323 | } | |
324 | ||
71e8831f | 325 | for (i = 0; i < kms_pdata->dev_cnt; i++) { |
cd5351f4 RC |
326 | struct omap_dss_device *dssdev = |
327 | omap_dss_find_device( | |
71e8831f AG |
328 | (void *)kms_pdata->dev_names[i], |
329 | match_dev_name); | |
cd5351f4 RC |
330 | if (!dssdev) { |
331 | dev_warn(dev->dev, "no such dssdev: %s\n", | |
71e8831f | 332 | kms_pdata->dev_names[i]); |
cd5351f4 RC |
333 | continue; |
334 | } | |
335 | create_connector(dev, dssdev); | |
336 | } | |
337 | ||
338 | connected_connectors = detect_connectors(dev); | |
339 | ||
340 | j = 0; | |
71e8831f | 341 | for (i = 0; i < kms_pdata->ovl_cnt; i++) { |
cd5351f4 | 342 | struct omap_overlay *ovl = |
71e8831f | 343 | omap_dss_get_overlay(kms_pdata->ovl_ids[i]); |
cd5351f4 RC |
344 | create_crtc(dev, ovl, &j, connected_connectors); |
345 | } | |
bb5c2d9a RC |
346 | |
347 | for (i = 0; i < kms_pdata->pln_cnt; i++) { | |
348 | struct omap_overlay *ovl = | |
349 | omap_dss_get_overlay(kms_pdata->pln_ids[i]); | |
350 | create_plane(dev, ovl, (1 << priv->num_crtcs) - 1); | |
351 | } | |
cd5351f4 RC |
352 | } else { |
353 | /* otherwise just grab up to CONFIG_DRM_OMAP_NUM_CRTCS and try | |
354 | * to make educated guesses about everything else | |
355 | */ | |
356 | int max_overlays = min(omap_dss_get_num_overlays(), num_crtc); | |
357 | ||
358 | for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) { | |
359 | create_encoder(dev, omap_dss_get_overlay_manager(i)); | |
360 | } | |
361 | ||
362 | for_each_dss_dev(dssdev) { | |
363 | create_connector(dev, dssdev); | |
364 | } | |
365 | ||
366 | connected_connectors = detect_connectors(dev); | |
367 | ||
368 | j = 0; | |
369 | for (i = 0; i < max_overlays; i++) { | |
370 | create_crtc(dev, omap_dss_get_overlay(i), | |
371 | &j, connected_connectors); | |
372 | } | |
bb5c2d9a RC |
373 | |
374 | /* use any remaining overlays as drm planes */ | |
375 | for (; i < omap_dss_get_num_overlays(); i++) { | |
376 | struct omap_overlay *ovl = omap_dss_get_overlay(i); | |
377 | create_plane(dev, ovl, (1 << priv->num_crtcs) - 1); | |
378 | } | |
cd5351f4 RC |
379 | } |
380 | ||
381 | /* for now keep the mapping of CRTCs and encoders static.. */ | |
382 | for (i = 0; i < priv->num_encoders; i++) { | |
383 | struct drm_encoder *encoder = priv->encoders[i]; | |
384 | struct omap_overlay_manager *mgr = | |
385 | omap_encoder_get_manager(encoder); | |
386 | ||
bb5c2d9a | 387 | encoder->possible_crtcs = (1 << priv->num_crtcs) - 1; |
cd5351f4 RC |
388 | |
389 | DBG("%s: possible_crtcs=%08x", mgr->name, | |
390 | encoder->possible_crtcs); | |
391 | } | |
392 | ||
393 | dump_video_chains(); | |
394 | ||
6b8ca4cf RC |
395 | dev->mode_config.min_width = 32; |
396 | dev->mode_config.min_height = 32; | |
cd5351f4 RC |
397 | |
398 | /* note: eventually will need some cpu_is_omapXYZ() type stuff here | |
399 | * to fill in these limits properly on different OMAP generations.. | |
400 | */ | |
401 | dev->mode_config.max_width = 2048; | |
402 | dev->mode_config.max_height = 2048; | |
403 | ||
404 | dev->mode_config.funcs = &omap_mode_config_funcs; | |
405 | ||
406 | return 0; | |
407 | } | |
408 | ||
409 | static void omap_modeset_free(struct drm_device *dev) | |
410 | { | |
411 | drm_mode_config_cleanup(dev); | |
412 | } | |
413 | ||
414 | /* | |
415 | * drm ioctl funcs | |
416 | */ | |
417 | ||
418 | ||
419 | static int ioctl_get_param(struct drm_device *dev, void *data, | |
420 | struct drm_file *file_priv) | |
421 | { | |
422 | struct drm_omap_param *args = data; | |
423 | ||
424 | DBG("%p: param=%llu", dev, args->param); | |
425 | ||
426 | switch (args->param) { | |
427 | case OMAP_PARAM_CHIPSET_ID: | |
428 | args->value = GET_OMAP_TYPE; | |
429 | break; | |
430 | default: | |
431 | DBG("unknown parameter %lld", args->param); | |
432 | return -EINVAL; | |
433 | } | |
434 | ||
435 | return 0; | |
436 | } | |
437 | ||
438 | static int ioctl_set_param(struct drm_device *dev, void *data, | |
439 | struct drm_file *file_priv) | |
440 | { | |
441 | struct drm_omap_param *args = data; | |
442 | ||
443 | switch (args->param) { | |
444 | default: | |
445 | DBG("unknown parameter %lld", args->param); | |
446 | return -EINVAL; | |
447 | } | |
448 | ||
449 | return 0; | |
450 | } | |
451 | ||
452 | static int ioctl_gem_new(struct drm_device *dev, void *data, | |
453 | struct drm_file *file_priv) | |
454 | { | |
455 | struct drm_omap_gem_new *args = data; | |
456 | DBG("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, | |
457 | args->size.bytes, args->flags); | |
458 | return omap_gem_new_handle(dev, file_priv, args->size, | |
459 | args->flags, &args->handle); | |
460 | } | |
461 | ||
462 | static int ioctl_gem_cpu_prep(struct drm_device *dev, void *data, | |
463 | struct drm_file *file_priv) | |
464 | { | |
465 | struct drm_omap_gem_cpu_prep *args = data; | |
466 | struct drm_gem_object *obj; | |
467 | int ret; | |
468 | ||
469 | VERB("%p:%p: handle=%d, op=%x", dev, file_priv, args->handle, args->op); | |
470 | ||
471 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); | |
472 | if (!obj) { | |
473 | return -ENOENT; | |
474 | } | |
475 | ||
476 | ret = omap_gem_op_sync(obj, args->op); | |
477 | ||
478 | if (!ret) { | |
479 | ret = omap_gem_op_start(obj, args->op); | |
480 | } | |
481 | ||
482 | drm_gem_object_unreference_unlocked(obj); | |
483 | ||
484 | return ret; | |
485 | } | |
486 | ||
487 | static int ioctl_gem_cpu_fini(struct drm_device *dev, void *data, | |
488 | struct drm_file *file_priv) | |
489 | { | |
490 | struct drm_omap_gem_cpu_fini *args = data; | |
491 | struct drm_gem_object *obj; | |
492 | int ret; | |
493 | ||
494 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); | |
495 | ||
496 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); | |
497 | if (!obj) { | |
498 | return -ENOENT; | |
499 | } | |
500 | ||
501 | /* XXX flushy, flushy */ | |
502 | ret = 0; | |
503 | ||
504 | if (!ret) { | |
505 | ret = omap_gem_op_finish(obj, args->op); | |
506 | } | |
507 | ||
508 | drm_gem_object_unreference_unlocked(obj); | |
509 | ||
510 | return ret; | |
511 | } | |
512 | ||
513 | static int ioctl_gem_info(struct drm_device *dev, void *data, | |
514 | struct drm_file *file_priv) | |
515 | { | |
516 | struct drm_omap_gem_info *args = data; | |
517 | struct drm_gem_object *obj; | |
518 | int ret = 0; | |
519 | ||
520 | DBG("%p:%p: handle=%d", dev, file_priv, args->handle); | |
521 | ||
522 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); | |
523 | if (!obj) { | |
524 | return -ENOENT; | |
525 | } | |
526 | ||
f7f9f453 | 527 | args->size = omap_gem_mmap_size(obj); |
cd5351f4 RC |
528 | args->offset = omap_gem_mmap_offset(obj); |
529 | ||
530 | drm_gem_object_unreference_unlocked(obj); | |
531 | ||
532 | return ret; | |
533 | } | |
534 | ||
535 | struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = { | |
536 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, DRM_UNLOCKED|DRM_AUTH), | |
537 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), | |
538 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, DRM_UNLOCKED|DRM_AUTH), | |
539 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, ioctl_gem_cpu_prep, DRM_UNLOCKED|DRM_AUTH), | |
540 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, ioctl_gem_cpu_fini, DRM_UNLOCKED|DRM_AUTH), | |
541 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, DRM_UNLOCKED|DRM_AUTH), | |
542 | }; | |
543 | ||
544 | /* | |
545 | * drm driver funcs | |
546 | */ | |
547 | ||
548 | /** | |
549 | * load - setup chip and create an initial config | |
550 | * @dev: DRM device | |
551 | * @flags: startup flags | |
552 | * | |
553 | * The driver load routine has to do several things: | |
554 | * - initialize the memory manager | |
555 | * - allocate initial config memory | |
556 | * - setup the DRM framebuffer with the allocated memory | |
557 | */ | |
558 | static int dev_load(struct drm_device *dev, unsigned long flags) | |
559 | { | |
560 | struct omap_drm_private *priv; | |
561 | int ret; | |
562 | ||
563 | DBG("load: dev=%p", dev); | |
564 | ||
565 | drm_device = dev; | |
566 | ||
567 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | |
568 | if (!priv) { | |
569 | dev_err(dev->dev, "could not allocate priv\n"); | |
570 | return -ENOMEM; | |
571 | } | |
572 | ||
573 | dev->dev_private = priv; | |
574 | ||
4619cdbc | 575 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
5609f7fe | 576 | |
f6b6036e RC |
577 | INIT_LIST_HEAD(&priv->obj_list); |
578 | ||
f7f9f453 RC |
579 | omap_gem_init(dev); |
580 | ||
cd5351f4 RC |
581 | ret = omap_modeset_init(dev); |
582 | if (ret) { | |
583 | dev_err(dev->dev, "omap_modeset_init failed: ret=%d\n", ret); | |
584 | dev->dev_private = NULL; | |
585 | kfree(priv); | |
586 | return ret; | |
587 | } | |
588 | ||
589 | priv->fbdev = omap_fbdev_init(dev); | |
590 | if (!priv->fbdev) { | |
591 | dev_warn(dev->dev, "omap_fbdev_init failed\n"); | |
592 | /* well, limp along without an fbdev.. maybe X11 will work? */ | |
593 | } | |
594 | ||
595 | drm_kms_helper_poll_init(dev); | |
596 | ||
597 | ret = drm_vblank_init(dev, priv->num_crtcs); | |
598 | if (ret) { | |
599 | dev_warn(dev->dev, "could not init vblank\n"); | |
600 | } | |
601 | ||
602 | return 0; | |
603 | } | |
604 | ||
605 | static int dev_unload(struct drm_device *dev) | |
606 | { | |
5609f7fe RC |
607 | struct omap_drm_private *priv = dev->dev_private; |
608 | ||
cd5351f4 RC |
609 | DBG("unload: dev=%p", dev); |
610 | ||
611 | drm_vblank_cleanup(dev); | |
612 | drm_kms_helper_poll_fini(dev); | |
613 | ||
614 | omap_fbdev_free(dev); | |
cd5351f4 | 615 | omap_modeset_free(dev); |
f7f9f453 | 616 | omap_gem_deinit(dev); |
cd5351f4 | 617 | |
5609f7fe RC |
618 | flush_workqueue(priv->wq); |
619 | destroy_workqueue(priv->wq); | |
620 | ||
cd5351f4 RC |
621 | kfree(dev->dev_private); |
622 | dev->dev_private = NULL; | |
623 | ||
624 | return 0; | |
625 | } | |
626 | ||
627 | static int dev_open(struct drm_device *dev, struct drm_file *file) | |
628 | { | |
629 | file->driver_priv = NULL; | |
630 | ||
631 | DBG("open: dev=%p, file=%p", dev, file); | |
632 | ||
633 | return 0; | |
634 | } | |
635 | ||
636 | static int dev_firstopen(struct drm_device *dev) | |
637 | { | |
638 | DBG("firstopen: dev=%p", dev); | |
639 | return 0; | |
640 | } | |
641 | ||
642 | /** | |
643 | * lastclose - clean up after all DRM clients have exited | |
644 | * @dev: DRM device | |
645 | * | |
646 | * Take care of cleaning up after all DRM clients have exited. In the | |
647 | * mode setting case, we want to restore the kernel's initial mode (just | |
648 | * in case the last client left us in a bad state). | |
649 | */ | |
650 | static void dev_lastclose(struct drm_device *dev) | |
651 | { | |
3c810c61 RC |
652 | int i; |
653 | ||
cd5351f4 RC |
654 | /* we don't support vga-switcheroo.. so just make sure the fbdev |
655 | * mode is active | |
656 | */ | |
657 | struct omap_drm_private *priv = dev->dev_private; | |
658 | int ret; | |
659 | ||
660 | DBG("lastclose: dev=%p", dev); | |
661 | ||
3c810c61 RC |
662 | /* need to restore default rotation state.. not sure if there is |
663 | * a cleaner way to restore properties to default state? Maybe | |
664 | * a flag that properties should automatically be restored to | |
665 | * default state on lastclose? | |
666 | */ | |
667 | for (i = 0; i < priv->num_crtcs; i++) { | |
668 | drm_object_property_set_value(&priv->crtcs[i]->base, | |
669 | priv->rotation_prop, 0); | |
670 | } | |
671 | ||
672 | for (i = 0; i < priv->num_planes; i++) { | |
673 | drm_object_property_set_value(&priv->planes[i]->base, | |
674 | priv->rotation_prop, 0); | |
675 | } | |
676 | ||
cd5351f4 RC |
677 | ret = drm_fb_helper_restore_fbdev_mode(priv->fbdev); |
678 | if (ret) | |
679 | DBG("failed to restore crtc mode"); | |
680 | } | |
681 | ||
682 | static void dev_preclose(struct drm_device *dev, struct drm_file *file) | |
683 | { | |
684 | DBG("preclose: dev=%p", dev); | |
685 | } | |
686 | ||
687 | static void dev_postclose(struct drm_device *dev, struct drm_file *file) | |
688 | { | |
689 | DBG("postclose: dev=%p, file=%p", dev, file); | |
690 | } | |
691 | ||
692 | /** | |
693 | * enable_vblank - enable vblank interrupt events | |
694 | * @dev: DRM device | |
695 | * @crtc: which irq to enable | |
696 | * | |
697 | * Enable vblank interrupts for @crtc. If the device doesn't have | |
698 | * a hardware vblank counter, this routine should be a no-op, since | |
699 | * interrupts will have to stay on to keep the count accurate. | |
700 | * | |
701 | * RETURNS | |
702 | * Zero on success, appropriate errno if the given @crtc's vblank | |
703 | * interrupt cannot be enabled. | |
704 | */ | |
705 | static int dev_enable_vblank(struct drm_device *dev, int crtc) | |
706 | { | |
707 | DBG("enable_vblank: dev=%p, crtc=%d", dev, crtc); | |
708 | return 0; | |
709 | } | |
710 | ||
711 | /** | |
712 | * disable_vblank - disable vblank interrupt events | |
713 | * @dev: DRM device | |
714 | * @crtc: which irq to enable | |
715 | * | |
716 | * Disable vblank interrupts for @crtc. If the device doesn't have | |
717 | * a hardware vblank counter, this routine should be a no-op, since | |
718 | * interrupts will have to stay on to keep the count accurate. | |
719 | */ | |
720 | static void dev_disable_vblank(struct drm_device *dev, int crtc) | |
721 | { | |
722 | DBG("disable_vblank: dev=%p, crtc=%d", dev, crtc); | |
723 | } | |
724 | ||
725 | static irqreturn_t dev_irq_handler(DRM_IRQ_ARGS) | |
726 | { | |
727 | return IRQ_HANDLED; | |
728 | } | |
729 | ||
730 | static void dev_irq_preinstall(struct drm_device *dev) | |
731 | { | |
732 | DBG("irq_preinstall: dev=%p", dev); | |
733 | } | |
734 | ||
735 | static int dev_irq_postinstall(struct drm_device *dev) | |
736 | { | |
737 | DBG("irq_postinstall: dev=%p", dev); | |
738 | return 0; | |
739 | } | |
740 | ||
741 | static void dev_irq_uninstall(struct drm_device *dev) | |
742 | { | |
743 | DBG("irq_uninstall: dev=%p", dev); | |
744 | } | |
745 | ||
78b68556 | 746 | static const struct vm_operations_struct omap_gem_vm_ops = { |
cd5351f4 RC |
747 | .fault = omap_gem_fault, |
748 | .open = drm_gem_vm_open, | |
749 | .close = drm_gem_vm_close, | |
750 | }; | |
751 | ||
ff4f3876 RC |
752 | static const struct file_operations omapdriver_fops = { |
753 | .owner = THIS_MODULE, | |
754 | .open = drm_open, | |
755 | .unlocked_ioctl = drm_ioctl, | |
756 | .release = drm_release, | |
757 | .mmap = omap_gem_mmap, | |
758 | .poll = drm_poll, | |
759 | .fasync = drm_fasync, | |
760 | .read = drm_read, | |
761 | .llseek = noop_llseek, | |
762 | }; | |
763 | ||
cd5351f4 RC |
764 | static struct drm_driver omap_drm_driver = { |
765 | .driver_features = | |
6ad11bc3 | 766 | DRIVER_HAVE_IRQ | DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
cd5351f4 RC |
767 | .load = dev_load, |
768 | .unload = dev_unload, | |
769 | .open = dev_open, | |
770 | .firstopen = dev_firstopen, | |
771 | .lastclose = dev_lastclose, | |
772 | .preclose = dev_preclose, | |
773 | .postclose = dev_postclose, | |
774 | .get_vblank_counter = drm_vblank_count, | |
775 | .enable_vblank = dev_enable_vblank, | |
776 | .disable_vblank = dev_disable_vblank, | |
777 | .irq_preinstall = dev_irq_preinstall, | |
778 | .irq_postinstall = dev_irq_postinstall, | |
779 | .irq_uninstall = dev_irq_uninstall, | |
780 | .irq_handler = dev_irq_handler, | |
6169a148 AG |
781 | #ifdef CONFIG_DEBUG_FS |
782 | .debugfs_init = omap_debugfs_init, | |
783 | .debugfs_cleanup = omap_debugfs_cleanup, | |
784 | #endif | |
6ad11bc3 | 785 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
3080b838 | 786 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
6ad11bc3 | 787 | .gem_prime_export = omap_gem_prime_export, |
3080b838 | 788 | .gem_prime_import = omap_gem_prime_import, |
cd5351f4 RC |
789 | .gem_init_object = omap_gem_init_object, |
790 | .gem_free_object = omap_gem_free_object, | |
791 | .gem_vm_ops = &omap_gem_vm_ops, | |
792 | .dumb_create = omap_gem_dumb_create, | |
793 | .dumb_map_offset = omap_gem_dumb_map_offset, | |
794 | .dumb_destroy = omap_gem_dumb_destroy, | |
795 | .ioctls = ioctls, | |
796 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, | |
ff4f3876 | 797 | .fops = &omapdriver_fops, |
cd5351f4 RC |
798 | .name = DRIVER_NAME, |
799 | .desc = DRIVER_DESC, | |
800 | .date = DRIVER_DATE, | |
801 | .major = DRIVER_MAJOR, | |
802 | .minor = DRIVER_MINOR, | |
803 | .patchlevel = DRIVER_PATCHLEVEL, | |
804 | }; | |
805 | ||
806 | static int pdev_suspend(struct platform_device *pDevice, pm_message_t state) | |
807 | { | |
808 | DBG(""); | |
809 | return 0; | |
810 | } | |
811 | ||
812 | static int pdev_resume(struct platform_device *device) | |
813 | { | |
814 | DBG(""); | |
815 | return 0; | |
816 | } | |
817 | ||
818 | static void pdev_shutdown(struct platform_device *device) | |
819 | { | |
820 | DBG(""); | |
821 | } | |
822 | ||
823 | static int pdev_probe(struct platform_device *device) | |
824 | { | |
825 | DBG("%s", device->name); | |
826 | return drm_platform_init(&omap_drm_driver, device); | |
827 | } | |
828 | ||
829 | static int pdev_remove(struct platform_device *device) | |
830 | { | |
831 | DBG(""); | |
832 | drm_platform_exit(&omap_drm_driver, device); | |
5c137797 AG |
833 | |
834 | platform_driver_unregister(&omap_dmm_driver); | |
cd5351f4 RC |
835 | return 0; |
836 | } | |
837 | ||
838 | struct platform_driver pdev = { | |
839 | .driver = { | |
840 | .name = DRIVER_NAME, | |
841 | .owner = THIS_MODULE, | |
842 | }, | |
843 | .probe = pdev_probe, | |
844 | .remove = pdev_remove, | |
845 | .suspend = pdev_suspend, | |
846 | .resume = pdev_resume, | |
847 | .shutdown = pdev_shutdown, | |
848 | }; | |
849 | ||
850 | static int __init omap_drm_init(void) | |
851 | { | |
852 | DBG("init"); | |
be0775ac RC |
853 | if (platform_driver_register(&omap_dmm_driver)) { |
854 | /* we can continue on without DMM.. so not fatal */ | |
855 | dev_err(NULL, "DMM registration failed\n"); | |
856 | } | |
cd5351f4 RC |
857 | return platform_driver_register(&pdev); |
858 | } | |
859 | ||
860 | static void __exit omap_drm_fini(void) | |
861 | { | |
862 | DBG("fini"); | |
863 | platform_driver_unregister(&pdev); | |
864 | } | |
865 | ||
866 | /* need late_initcall() so we load after dss_driver's are loaded */ | |
867 | late_initcall(omap_drm_init); | |
868 | module_exit(omap_drm_fini); | |
869 | ||
870 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); | |
871 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); | |
872 | MODULE_ALIAS("platform:" DRIVER_NAME); | |
873 | MODULE_LICENSE("GPL v2"); |