Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 1 | /* |
Rob Clark | 8bb0daf | 2013-02-11 12:43:09 -0500 | [diff] [blame] | 2 | * drivers/gpu/drm/omapdrm/omap_drv.c |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 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" |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 24 | #include "omap_dmm_tiler.h" |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 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 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 33 | static int num_crtc = CONFIG_DRM_OMAP_NUM_CRTCS; |
| 34 | |
| 35 | MODULE_PARM_DESC(num_crtc, "Number of overlays to use as CRTCs"); |
| 36 | module_param(num_crtc, int, 0600); |
| 37 | |
| 38 | /* |
| 39 | * mode config funcs |
| 40 | */ |
| 41 | |
| 42 | /* Notes about mapping DSS and DRM entities: |
| 43 | * CRTC: overlay |
| 44 | * encoder: manager.. with some extension to allow one primary CRTC |
| 45 | * and zero or more video CRTC's to be mapped to one encoder? |
| 46 | * connector: dssdev.. manager can be attached/detached from different |
| 47 | * devices |
| 48 | */ |
| 49 | |
| 50 | static void omap_fb_output_poll_changed(struct drm_device *dev) |
| 51 | { |
| 52 | struct omap_drm_private *priv = dev->dev_private; |
| 53 | DBG("dev=%p", dev); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 54 | if (priv->fbdev) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 55 | drm_fb_helper_hotplug_event(priv->fbdev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 58 | static const struct drm_mode_config_funcs omap_mode_config_funcs = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 59 | .fb_create = omap_framebuffer_create, |
| 60 | .output_poll_changed = omap_fb_output_poll_changed, |
| 61 | }; |
| 62 | |
| 63 | static int get_connector_type(struct omap_dss_device *dssdev) |
| 64 | { |
| 65 | switch (dssdev->type) { |
| 66 | case OMAP_DISPLAY_TYPE_HDMI: |
| 67 | return DRM_MODE_CONNECTOR_HDMIA; |
| 68 | case OMAP_DISPLAY_TYPE_DPI: |
| 69 | if (!strcmp(dssdev->name, "dvi")) |
| 70 | return DRM_MODE_CONNECTOR_DVID; |
| 71 | /* fallthrough */ |
| 72 | default: |
| 73 | return DRM_MODE_CONNECTOR_Unknown; |
| 74 | } |
| 75 | } |
| 76 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 77 | static bool channel_used(struct drm_device *dev, enum omap_channel channel) |
| 78 | { |
| 79 | struct omap_drm_private *priv = dev->dev_private; |
| 80 | int i; |
| 81 | |
| 82 | for (i = 0; i < priv->num_crtcs; i++) { |
| 83 | struct drm_crtc *crtc = priv->crtcs[i]; |
| 84 | |
| 85 | if (omap_crtc_channel(crtc) == channel) |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 92 | static int omap_modeset_init(struct drm_device *dev) |
| 93 | { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 94 | struct omap_drm_private *priv = dev->dev_private; |
| 95 | struct omap_dss_device *dssdev = NULL; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 96 | int num_ovls = dss_feat_get_num_ovls(); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 97 | int num_mgrs = dss_feat_get_num_mgrs(); |
| 98 | int num_crtcs; |
| 99 | int i, id = 0; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 100 | |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame^] | 101 | omap_crtc_pre_init(); |
| 102 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 103 | drm_mode_config_init(dev); |
| 104 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 105 | omap_drm_irq_install(dev); |
Andy Gross | 71e8831 | 2011-12-05 19:19:21 -0600 | [diff] [blame] | 106 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 107 | /* |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 108 | * We usually don't want to create a CRTC for each manager, at least |
| 109 | * not until we have a way to expose private planes to userspace. |
| 110 | * Otherwise there would not be enough video pipes left for drm planes. |
| 111 | * We use the num_crtc argument to limit the number of crtcs we create. |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 112 | */ |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 113 | num_crtcs = min3(num_crtc, num_mgrs, num_ovls); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 114 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 115 | dssdev = NULL; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 116 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 117 | for_each_dss_dev(dssdev) { |
| 118 | struct drm_connector *connector; |
| 119 | struct drm_encoder *encoder; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 120 | enum omap_channel channel; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 121 | |
| 122 | if (!dssdev->driver) { |
| 123 | dev_warn(dev->dev, "%s has no driver.. skipping it\n", |
| 124 | dssdev->name); |
Archit Taneja | 581382e | 2013-03-26 19:15:18 +0530 | [diff] [blame] | 125 | continue; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (!(dssdev->driver->get_timings || |
| 129 | dssdev->driver->read_edid)) { |
| 130 | dev_warn(dev->dev, "%s driver does not support " |
| 131 | "get_timings or read_edid.. skipping it!\n", |
| 132 | dssdev->name); |
Archit Taneja | 581382e | 2013-03-26 19:15:18 +0530 | [diff] [blame] | 133 | continue; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | encoder = omap_encoder_init(dev, dssdev); |
| 137 | |
| 138 | if (!encoder) { |
| 139 | dev_err(dev->dev, "could not create encoder: %s\n", |
| 140 | dssdev->name); |
| 141 | return -ENOMEM; |
| 142 | } |
| 143 | |
| 144 | connector = omap_connector_init(dev, |
| 145 | get_connector_type(dssdev), dssdev, encoder); |
| 146 | |
| 147 | if (!connector) { |
| 148 | dev_err(dev->dev, "could not create connector: %s\n", |
| 149 | dssdev->name); |
| 150 | return -ENOMEM; |
| 151 | } |
| 152 | |
| 153 | BUG_ON(priv->num_encoders >= ARRAY_SIZE(priv->encoders)); |
| 154 | BUG_ON(priv->num_connectors >= ARRAY_SIZE(priv->connectors)); |
| 155 | |
| 156 | priv->encoders[priv->num_encoders++] = encoder; |
| 157 | priv->connectors[priv->num_connectors++] = connector; |
| 158 | |
| 159 | drm_mode_connector_attach_encoder(connector, encoder); |
| 160 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 161 | /* |
| 162 | * if we have reached the limit of the crtcs we are allowed to |
| 163 | * create, let's not try to look for a crtc for this |
| 164 | * panel/encoder and onwards, we will, of course, populate the |
| 165 | * the possible_crtcs field for all the encoders with the final |
| 166 | * set of crtcs we create |
| 167 | */ |
| 168 | if (id == num_crtcs) |
| 169 | continue; |
| 170 | |
| 171 | /* |
| 172 | * get the recommended DISPC channel for this encoder. For now, |
| 173 | * we only try to get create a crtc out of the recommended, the |
| 174 | * other possible channels to which the encoder can connect are |
| 175 | * not considered. |
| 176 | */ |
| 177 | channel = dssdev->output->dispc_channel; |
| 178 | |
| 179 | /* |
| 180 | * if this channel hasn't already been taken by a previously |
| 181 | * allocated crtc, we create a new crtc for it |
| 182 | */ |
| 183 | if (!channel_used(dev, channel)) { |
| 184 | struct drm_plane *plane; |
| 185 | struct drm_crtc *crtc; |
| 186 | |
| 187 | plane = omap_plane_init(dev, id, true); |
| 188 | crtc = omap_crtc_init(dev, plane, channel, id); |
| 189 | |
| 190 | BUG_ON(priv->num_crtcs >= ARRAY_SIZE(priv->crtcs)); |
| 191 | priv->crtcs[id] = crtc; |
| 192 | priv->num_crtcs++; |
| 193 | |
| 194 | priv->planes[id] = plane; |
| 195 | priv->num_planes++; |
| 196 | |
| 197 | id++; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * we have allocated crtcs according to the need of the panels/encoders, |
| 203 | * adding more crtcs here if needed |
| 204 | */ |
| 205 | for (; id < num_crtcs; id++) { |
| 206 | |
| 207 | /* find a free manager for this crtc */ |
| 208 | for (i = 0; i < num_mgrs; i++) { |
| 209 | if (!channel_used(dev, i)) { |
| 210 | struct drm_plane *plane; |
| 211 | struct drm_crtc *crtc; |
| 212 | |
| 213 | plane = omap_plane_init(dev, id, true); |
| 214 | crtc = omap_crtc_init(dev, plane, i, id); |
| 215 | |
| 216 | BUG_ON(priv->num_crtcs >= |
| 217 | ARRAY_SIZE(priv->crtcs)); |
| 218 | |
| 219 | priv->crtcs[id] = crtc; |
| 220 | priv->num_crtcs++; |
| 221 | |
| 222 | priv->planes[id] = plane; |
| 223 | priv->num_planes++; |
| 224 | |
| 225 | break; |
| 226 | } else { |
| 227 | continue; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (i == num_mgrs) { |
| 232 | /* this shouldn't really happen */ |
| 233 | dev_err(dev->dev, "no managers left for crtc\n"); |
| 234 | return -ENOMEM; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Create normal planes for the remaining overlays: |
| 240 | */ |
| 241 | for (; id < num_ovls; id++) { |
| 242 | struct drm_plane *plane = omap_plane_init(dev, id, false); |
| 243 | |
| 244 | BUG_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)); |
| 245 | priv->planes[priv->num_planes++] = plane; |
| 246 | } |
| 247 | |
| 248 | for (i = 0; i < priv->num_encoders; i++) { |
| 249 | struct drm_encoder *encoder = priv->encoders[i]; |
| 250 | struct omap_dss_device *dssdev = |
| 251 | omap_encoder_get_dssdev(encoder); |
Tomi Valkeinen | be8e8e1 | 2013-04-23 15:35:35 +0300 | [diff] [blame] | 252 | struct omap_dss_output *output; |
| 253 | |
| 254 | output = omapdss_find_output_from_display(dssdev); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 255 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 256 | /* figure out which crtc's we can connect the encoder to: */ |
| 257 | encoder->possible_crtcs = 0; |
| 258 | for (id = 0; id < priv->num_crtcs; id++) { |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 259 | struct drm_crtc *crtc = priv->crtcs[id]; |
| 260 | enum omap_channel crtc_channel; |
| 261 | enum omap_dss_output_id supported_outputs; |
| 262 | |
| 263 | crtc_channel = omap_crtc_channel(crtc); |
| 264 | supported_outputs = |
| 265 | dss_feat_get_supported_outputs(crtc_channel); |
| 266 | |
Tomi Valkeinen | be8e8e1 | 2013-04-23 15:35:35 +0300 | [diff] [blame] | 267 | if (supported_outputs & output->id) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 268 | encoder->possible_crtcs |= (1 << id); |
| 269 | } |
| 270 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 271 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 272 | DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n", |
| 273 | priv->num_planes, priv->num_crtcs, priv->num_encoders, |
| 274 | priv->num_connectors); |
| 275 | |
Rob Clark | 6b8ca4c | 2012-01-08 19:37:37 -0600 | [diff] [blame] | 276 | dev->mode_config.min_width = 32; |
| 277 | dev->mode_config.min_height = 32; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 278 | |
| 279 | /* note: eventually will need some cpu_is_omapXYZ() type stuff here |
| 280 | * to fill in these limits properly on different OMAP generations.. |
| 281 | */ |
| 282 | dev->mode_config.max_width = 2048; |
| 283 | dev->mode_config.max_height = 2048; |
| 284 | |
| 285 | dev->mode_config.funcs = &omap_mode_config_funcs; |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static void omap_modeset_free(struct drm_device *dev) |
| 291 | { |
| 292 | drm_mode_config_cleanup(dev); |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * drm ioctl funcs |
| 297 | */ |
| 298 | |
| 299 | |
| 300 | static int ioctl_get_param(struct drm_device *dev, void *data, |
| 301 | struct drm_file *file_priv) |
| 302 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 303 | struct omap_drm_private *priv = dev->dev_private; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 304 | struct drm_omap_param *args = data; |
| 305 | |
| 306 | DBG("%p: param=%llu", dev, args->param); |
| 307 | |
| 308 | switch (args->param) { |
| 309 | case OMAP_PARAM_CHIPSET_ID: |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 310 | args->value = priv->omaprev; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 311 | break; |
| 312 | default: |
| 313 | DBG("unknown parameter %lld", args->param); |
| 314 | return -EINVAL; |
| 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static int ioctl_set_param(struct drm_device *dev, void *data, |
| 321 | struct drm_file *file_priv) |
| 322 | { |
| 323 | struct drm_omap_param *args = data; |
| 324 | |
| 325 | switch (args->param) { |
| 326 | default: |
| 327 | DBG("unknown parameter %lld", args->param); |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int ioctl_gem_new(struct drm_device *dev, void *data, |
| 335 | struct drm_file *file_priv) |
| 336 | { |
| 337 | struct drm_omap_gem_new *args = data; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 338 | VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 339 | args->size.bytes, args->flags); |
| 340 | return omap_gem_new_handle(dev, file_priv, args->size, |
| 341 | args->flags, &args->handle); |
| 342 | } |
| 343 | |
| 344 | static int ioctl_gem_cpu_prep(struct drm_device *dev, void *data, |
| 345 | struct drm_file *file_priv) |
| 346 | { |
| 347 | struct drm_omap_gem_cpu_prep *args = data; |
| 348 | struct drm_gem_object *obj; |
| 349 | int ret; |
| 350 | |
| 351 | VERB("%p:%p: handle=%d, op=%x", dev, file_priv, args->handle, args->op); |
| 352 | |
| 353 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 354 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 355 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 356 | |
| 357 | ret = omap_gem_op_sync(obj, args->op); |
| 358 | |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 359 | if (!ret) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 360 | ret = omap_gem_op_start(obj, args->op); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 361 | |
| 362 | drm_gem_object_unreference_unlocked(obj); |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | static int ioctl_gem_cpu_fini(struct drm_device *dev, void *data, |
| 368 | struct drm_file *file_priv) |
| 369 | { |
| 370 | struct drm_omap_gem_cpu_fini *args = data; |
| 371 | struct drm_gem_object *obj; |
| 372 | int ret; |
| 373 | |
| 374 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
| 375 | |
| 376 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 377 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 378 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 379 | |
| 380 | /* XXX flushy, flushy */ |
| 381 | ret = 0; |
| 382 | |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 383 | if (!ret) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 384 | ret = omap_gem_op_finish(obj, args->op); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 385 | |
| 386 | drm_gem_object_unreference_unlocked(obj); |
| 387 | |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | static int ioctl_gem_info(struct drm_device *dev, void *data, |
| 392 | struct drm_file *file_priv) |
| 393 | { |
| 394 | struct drm_omap_gem_info *args = data; |
| 395 | struct drm_gem_object *obj; |
| 396 | int ret = 0; |
| 397 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 398 | VERB("%p:%p: handle=%d", dev, file_priv, args->handle); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 399 | |
| 400 | obj = drm_gem_object_lookup(dev, file_priv, args->handle); |
YAMANE Toshiaki | c7f904b | 2012-11-14 19:30:38 +0900 | [diff] [blame] | 401 | if (!obj) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 402 | return -ENOENT; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 403 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 404 | args->size = omap_gem_mmap_size(obj); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 405 | args->offset = omap_gem_mmap_offset(obj); |
| 406 | |
| 407 | drm_gem_object_unreference_unlocked(obj); |
| 408 | |
| 409 | return ret; |
| 410 | } |
| 411 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 412 | static struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 413 | DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param, DRM_UNLOCKED|DRM_AUTH), |
| 414 | DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 415 | DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new, DRM_UNLOCKED|DRM_AUTH), |
| 416 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, ioctl_gem_cpu_prep, DRM_UNLOCKED|DRM_AUTH), |
| 417 | DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, ioctl_gem_cpu_fini, DRM_UNLOCKED|DRM_AUTH), |
| 418 | DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info, DRM_UNLOCKED|DRM_AUTH), |
| 419 | }; |
| 420 | |
| 421 | /* |
| 422 | * drm driver funcs |
| 423 | */ |
| 424 | |
| 425 | /** |
| 426 | * load - setup chip and create an initial config |
| 427 | * @dev: DRM device |
| 428 | * @flags: startup flags |
| 429 | * |
| 430 | * The driver load routine has to do several things: |
| 431 | * - initialize the memory manager |
| 432 | * - allocate initial config memory |
| 433 | * - setup the DRM framebuffer with the allocated memory |
| 434 | */ |
| 435 | static int dev_load(struct drm_device *dev, unsigned long flags) |
| 436 | { |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 437 | struct omap_drm_platform_data *pdata = dev->dev->platform_data; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 438 | struct omap_drm_private *priv; |
| 439 | int ret; |
| 440 | |
| 441 | DBG("load: dev=%p", dev); |
| 442 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 443 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Joe Perches | 78110bb | 2013-02-11 09:41:29 -0800 | [diff] [blame] | 444 | if (!priv) |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 445 | return -ENOMEM; |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 446 | |
Rob Clark | 5e3b087 | 2012-10-29 09:31:12 +0100 | [diff] [blame] | 447 | priv->omaprev = pdata->omaprev; |
| 448 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 449 | dev->dev_private = priv; |
| 450 | |
Tejun Heo | 4619cdb | 2012-08-22 16:49:44 -0700 | [diff] [blame] | 451 | priv->wq = alloc_ordered_workqueue("omapdrm", 0); |
Rob Clark | 5609f7f | 2012-03-05 10:48:32 -0600 | [diff] [blame] | 452 | |
Rob Clark | f6b6036 | 2012-03-05 10:48:36 -0600 | [diff] [blame] | 453 | INIT_LIST_HEAD(&priv->obj_list); |
| 454 | |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 455 | omap_gem_init(dev); |
| 456 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 457 | ret = omap_modeset_init(dev); |
| 458 | if (ret) { |
| 459 | dev_err(dev->dev, "omap_modeset_init failed: ret=%d\n", ret); |
| 460 | dev->dev_private = NULL; |
| 461 | kfree(priv); |
| 462 | return ret; |
| 463 | } |
| 464 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 465 | ret = drm_vblank_init(dev, priv->num_crtcs); |
| 466 | if (ret) |
| 467 | dev_warn(dev->dev, "could not init vblank\n"); |
| 468 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 469 | priv->fbdev = omap_fbdev_init(dev); |
| 470 | if (!priv->fbdev) { |
| 471 | dev_warn(dev->dev, "omap_fbdev_init failed\n"); |
| 472 | /* well, limp along without an fbdev.. maybe X11 will work? */ |
| 473 | } |
| 474 | |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 475 | /* store off drm_device for use in pm ops */ |
| 476 | dev_set_drvdata(dev->dev, dev); |
| 477 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 478 | drm_kms_helper_poll_init(dev); |
| 479 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | static int dev_unload(struct drm_device *dev) |
| 484 | { |
Rob Clark | 5609f7f | 2012-03-05 10:48:32 -0600 | [diff] [blame] | 485 | struct omap_drm_private *priv = dev->dev_private; |
| 486 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 487 | DBG("unload: dev=%p", dev); |
| 488 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 489 | drm_kms_helper_poll_fini(dev); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 490 | drm_vblank_cleanup(dev); |
| 491 | omap_drm_irq_uninstall(dev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 492 | |
| 493 | omap_fbdev_free(dev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 494 | omap_modeset_free(dev); |
Rob Clark | f7f9f45 | 2011-12-05 19:19:22 -0600 | [diff] [blame] | 495 | omap_gem_deinit(dev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 496 | |
Rob Clark | 5609f7f | 2012-03-05 10:48:32 -0600 | [diff] [blame] | 497 | flush_workqueue(priv->wq); |
| 498 | destroy_workqueue(priv->wq); |
| 499 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 500 | kfree(dev->dev_private); |
| 501 | dev->dev_private = NULL; |
| 502 | |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 503 | dev_set_drvdata(dev->dev, NULL); |
| 504 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int dev_open(struct drm_device *dev, struct drm_file *file) |
| 509 | { |
| 510 | file->driver_priv = NULL; |
| 511 | |
| 512 | DBG("open: dev=%p, file=%p", dev, file); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | static int dev_firstopen(struct drm_device *dev) |
| 518 | { |
| 519 | DBG("firstopen: dev=%p", dev); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * lastclose - clean up after all DRM clients have exited |
| 525 | * @dev: DRM device |
| 526 | * |
| 527 | * Take care of cleaning up after all DRM clients have exited. In the |
| 528 | * mode setting case, we want to restore the kernel's initial mode (just |
| 529 | * in case the last client left us in a bad state). |
| 530 | */ |
| 531 | static void dev_lastclose(struct drm_device *dev) |
| 532 | { |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 533 | int i; |
| 534 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 535 | /* we don't support vga-switcheroo.. so just make sure the fbdev |
| 536 | * mode is active |
| 537 | */ |
| 538 | struct omap_drm_private *priv = dev->dev_private; |
| 539 | int ret; |
| 540 | |
| 541 | DBG("lastclose: dev=%p", dev); |
| 542 | |
Rob Clark | c2a6a55 | 2012-10-25 17:14:13 -0500 | [diff] [blame] | 543 | if (priv->rotation_prop) { |
| 544 | /* need to restore default rotation state.. not sure |
| 545 | * if there is a cleaner way to restore properties to |
| 546 | * default state? Maybe a flag that properties should |
| 547 | * automatically be restored to default state on |
| 548 | * lastclose? |
| 549 | */ |
| 550 | for (i = 0; i < priv->num_crtcs; i++) { |
| 551 | drm_object_property_set_value(&priv->crtcs[i]->base, |
| 552 | priv->rotation_prop, 0); |
| 553 | } |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 554 | |
Rob Clark | c2a6a55 | 2012-10-25 17:14:13 -0500 | [diff] [blame] | 555 | for (i = 0; i < priv->num_planes; i++) { |
| 556 | drm_object_property_set_value(&priv->planes[i]->base, |
| 557 | priv->rotation_prop, 0); |
| 558 | } |
Rob Clark | 3c810c6 | 2012-08-15 15:18:01 -0500 | [diff] [blame] | 559 | } |
| 560 | |
Daniel Vetter | d5d2636 | 2013-01-20 15:50:41 +0100 | [diff] [blame] | 561 | drm_modeset_lock_all(dev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 562 | ret = drm_fb_helper_restore_fbdev_mode(priv->fbdev); |
Daniel Vetter | d5d2636 | 2013-01-20 15:50:41 +0100 | [diff] [blame] | 563 | drm_modeset_unlock_all(dev); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 564 | if (ret) |
| 565 | DBG("failed to restore crtc mode"); |
| 566 | } |
| 567 | |
| 568 | static void dev_preclose(struct drm_device *dev, struct drm_file *file) |
| 569 | { |
| 570 | DBG("preclose: dev=%p", dev); |
| 571 | } |
| 572 | |
| 573 | static void dev_postclose(struct drm_device *dev, struct drm_file *file) |
| 574 | { |
| 575 | DBG("postclose: dev=%p, file=%p", dev, file); |
| 576 | } |
| 577 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 578 | static const struct vm_operations_struct omap_gem_vm_ops = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 579 | .fault = omap_gem_fault, |
| 580 | .open = drm_gem_vm_open, |
| 581 | .close = drm_gem_vm_close, |
| 582 | }; |
| 583 | |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 584 | static const struct file_operations omapdriver_fops = { |
| 585 | .owner = THIS_MODULE, |
| 586 | .open = drm_open, |
| 587 | .unlocked_ioctl = drm_ioctl, |
| 588 | .release = drm_release, |
| 589 | .mmap = omap_gem_mmap, |
| 590 | .poll = drm_poll, |
| 591 | .fasync = drm_fasync, |
| 592 | .read = drm_read, |
| 593 | .llseek = noop_llseek, |
| 594 | }; |
| 595 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 596 | static struct drm_driver omap_drm_driver = { |
| 597 | .driver_features = |
Rob Clark | 6ad11bc | 2012-04-10 13:19:55 -0500 | [diff] [blame] | 598 | DRIVER_HAVE_IRQ | DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 599 | .load = dev_load, |
| 600 | .unload = dev_unload, |
| 601 | .open = dev_open, |
| 602 | .firstopen = dev_firstopen, |
| 603 | .lastclose = dev_lastclose, |
| 604 | .preclose = dev_preclose, |
| 605 | .postclose = dev_postclose, |
| 606 | .get_vblank_counter = drm_vblank_count, |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 607 | .enable_vblank = omap_irq_enable_vblank, |
| 608 | .disable_vblank = omap_irq_disable_vblank, |
| 609 | .irq_preinstall = omap_irq_preinstall, |
| 610 | .irq_postinstall = omap_irq_postinstall, |
| 611 | .irq_uninstall = omap_irq_uninstall, |
| 612 | .irq_handler = omap_irq_handler, |
Andy Gross | 6169a148 | 2011-12-15 21:05:17 -0600 | [diff] [blame] | 613 | #ifdef CONFIG_DEBUG_FS |
| 614 | .debugfs_init = omap_debugfs_init, |
| 615 | .debugfs_cleanup = omap_debugfs_cleanup, |
| 616 | #endif |
Rob Clark | 6ad11bc | 2012-04-10 13:19:55 -0500 | [diff] [blame] | 617 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
Rob Clark | 3080b83 | 2012-05-17 02:37:26 -0600 | [diff] [blame] | 618 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Rob Clark | 6ad11bc | 2012-04-10 13:19:55 -0500 | [diff] [blame] | 619 | .gem_prime_export = omap_gem_prime_export, |
Rob Clark | 3080b83 | 2012-05-17 02:37:26 -0600 | [diff] [blame] | 620 | .gem_prime_import = omap_gem_prime_import, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 621 | .gem_init_object = omap_gem_init_object, |
| 622 | .gem_free_object = omap_gem_free_object, |
| 623 | .gem_vm_ops = &omap_gem_vm_ops, |
| 624 | .dumb_create = omap_gem_dumb_create, |
| 625 | .dumb_map_offset = omap_gem_dumb_map_offset, |
| 626 | .dumb_destroy = omap_gem_dumb_destroy, |
| 627 | .ioctls = ioctls, |
| 628 | .num_ioctls = DRM_OMAP_NUM_IOCTLS, |
Rob Clark | ff4f387 | 2012-01-16 12:51:14 -0600 | [diff] [blame] | 629 | .fops = &omapdriver_fops, |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 630 | .name = DRIVER_NAME, |
| 631 | .desc = DRIVER_DESC, |
| 632 | .date = DRIVER_DATE, |
| 633 | .major = DRIVER_MAJOR, |
| 634 | .minor = DRIVER_MINOR, |
| 635 | .patchlevel = DRIVER_PATCHLEVEL, |
| 636 | }; |
| 637 | |
| 638 | static int pdev_suspend(struct platform_device *pDevice, pm_message_t state) |
| 639 | { |
| 640 | DBG(""); |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static int pdev_resume(struct platform_device *device) |
| 645 | { |
| 646 | DBG(""); |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | static void pdev_shutdown(struct platform_device *device) |
| 651 | { |
| 652 | DBG(""); |
| 653 | } |
| 654 | |
| 655 | static int pdev_probe(struct platform_device *device) |
| 656 | { |
Tomi Valkeinen | 591a0ac | 2013-05-23 12:07:50 +0300 | [diff] [blame] | 657 | if (omapdss_is_initialized() == false) |
| 658 | return -EPROBE_DEFER; |
| 659 | |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 660 | DBG("%s", device->name); |
| 661 | return drm_platform_init(&omap_drm_driver, device); |
| 662 | } |
| 663 | |
| 664 | static int pdev_remove(struct platform_device *device) |
| 665 | { |
| 666 | DBG(""); |
| 667 | drm_platform_exit(&omap_drm_driver, device); |
Andy Gross | 5c13779 | 2012-03-05 10:48:39 -0600 | [diff] [blame] | 668 | |
| 669 | platform_driver_unregister(&omap_dmm_driver); |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 670 | return 0; |
| 671 | } |
| 672 | |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 673 | #ifdef CONFIG_PM |
| 674 | static const struct dev_pm_ops omapdrm_pm_ops = { |
| 675 | .resume = omap_gem_resume, |
| 676 | }; |
| 677 | #endif |
| 678 | |
Tomi Valkeinen | 6717cd2 | 2013-04-10 10:44:00 +0300 | [diff] [blame] | 679 | static struct platform_driver pdev = { |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 680 | .driver = { |
| 681 | .name = DRIVER_NAME, |
| 682 | .owner = THIS_MODULE, |
Andy Gross | e78edba | 2012-12-19 14:53:37 -0600 | [diff] [blame] | 683 | #ifdef CONFIG_PM |
| 684 | .pm = &omapdrm_pm_ops, |
| 685 | #endif |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 686 | }, |
| 687 | .probe = pdev_probe, |
| 688 | .remove = pdev_remove, |
| 689 | .suspend = pdev_suspend, |
| 690 | .resume = pdev_resume, |
| 691 | .shutdown = pdev_shutdown, |
| 692 | }; |
| 693 | |
| 694 | static int __init omap_drm_init(void) |
| 695 | { |
| 696 | DBG("init"); |
Rob Clark | be0775a | 2012-04-05 10:34:56 -0500 | [diff] [blame] | 697 | if (platform_driver_register(&omap_dmm_driver)) { |
| 698 | /* we can continue on without DMM.. so not fatal */ |
| 699 | dev_err(NULL, "DMM registration failed\n"); |
| 700 | } |
Rob Clark | cd5351f | 2011-11-12 12:09:40 -0600 | [diff] [blame] | 701 | return platform_driver_register(&pdev); |
| 702 | } |
| 703 | |
| 704 | static void __exit omap_drm_fini(void) |
| 705 | { |
| 706 | DBG("fini"); |
| 707 | platform_driver_unregister(&pdev); |
| 708 | } |
| 709 | |
| 710 | /* need late_initcall() so we load after dss_driver's are loaded */ |
| 711 | late_initcall(omap_drm_init); |
| 712 | module_exit(omap_drm_fini); |
| 713 | |
| 714 | MODULE_AUTHOR("Rob Clark <rob@ti.com>"); |
| 715 | MODULE_DESCRIPTION("OMAP DRM Display Driver"); |
| 716 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 717 | MODULE_LICENSE("GPL v2"); |