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