Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) STMicroelectronics SA 2014 |
| 3 | * Author: Benjamin Gaignard <benjamin.gaignard@st.com> for STMicroelectronics. |
| 4 | * License terms: GNU General Public License (GPL), version 2 |
| 5 | */ |
| 6 | |
| 7 | #include <drm/drmP.h> |
| 8 | |
| 9 | #include <linux/component.h> |
| 10 | #include <linux/debugfs.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/of_platform.h> |
| 14 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 15 | #include <drm/drm_atomic.h> |
| 16 | #include <drm/drm_atomic_helper.h> |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 17 | #include <drm/drm_crtc_helper.h> |
| 18 | #include <drm/drm_gem_cma_helper.h> |
| 19 | #include <drm/drm_fb_cma_helper.h> |
| 20 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 21 | #include "sti_crtc.h" |
| 22 | #include "sti_drv.h" |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 23 | #include "sti_plane.h" |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 24 | |
| 25 | #define DRIVER_NAME "sti" |
| 26 | #define DRIVER_DESC "STMicroelectronics SoC DRM" |
| 27 | #define DRIVER_DATE "20140601" |
| 28 | #define DRIVER_MAJOR 1 |
| 29 | #define DRIVER_MINOR 0 |
| 30 | |
| 31 | #define STI_MAX_FB_HEIGHT 4096 |
| 32 | #define STI_MAX_FB_WIDTH 4096 |
| 33 | |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 34 | static int sti_drm_fps_get(void *data, u64 *val) |
| 35 | { |
| 36 | struct drm_device *drm_dev = data; |
| 37 | struct drm_plane *p; |
| 38 | unsigned int i = 0; |
| 39 | |
| 40 | *val = 0; |
| 41 | list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) { |
| 42 | struct sti_plane *plane = to_sti_plane(p); |
| 43 | |
| 44 | *val |= plane->fps_info.output << i; |
| 45 | i++; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int sti_drm_fps_set(void *data, u64 val) |
| 52 | { |
| 53 | struct drm_device *drm_dev = data; |
| 54 | struct drm_plane *p; |
| 55 | unsigned int i = 0; |
| 56 | |
| 57 | list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) { |
| 58 | struct sti_plane *plane = to_sti_plane(p); |
| 59 | |
| 60 | plane->fps_info.output = (val >> i) & 1; |
| 61 | i++; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | DEFINE_SIMPLE_ATTRIBUTE(sti_drm_fps_fops, |
| 68 | sti_drm_fps_get, sti_drm_fps_set, "%llu\n"); |
| 69 | |
| 70 | static int sti_drm_fps_dbg_show(struct seq_file *s, void *data) |
| 71 | { |
| 72 | struct drm_info_node *node = s->private; |
| 73 | struct drm_device *dev = node->minor->dev; |
| 74 | struct drm_plane *p; |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 75 | |
| 76 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { |
| 77 | struct sti_plane *plane = to_sti_plane(p); |
| 78 | |
| 79 | seq_printf(s, "%s%s\n", |
| 80 | plane->fps_info.fps_str, |
| 81 | plane->fps_info.fips_str); |
| 82 | } |
| 83 | |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static struct drm_info_list sti_drm_dbg_list[] = { |
| 88 | {"fps_get", sti_drm_fps_dbg_show, 0}, |
| 89 | }; |
| 90 | |
| 91 | static int sti_drm_debugfs_create(struct dentry *root, |
| 92 | struct drm_minor *minor, |
| 93 | const char *name, |
| 94 | const struct file_operations *fops) |
| 95 | { |
| 96 | struct drm_device *dev = minor->dev; |
| 97 | struct drm_info_node *node; |
| 98 | struct dentry *ent; |
| 99 | |
| 100 | ent = debugfs_create_file(name, S_IRUGO | S_IWUSR, root, dev, fops); |
| 101 | if (IS_ERR(ent)) |
| 102 | return PTR_ERR(ent); |
| 103 | |
| 104 | node = kmalloc(sizeof(*node), GFP_KERNEL); |
| 105 | if (!node) { |
| 106 | debugfs_remove(ent); |
| 107 | return -ENOMEM; |
| 108 | } |
| 109 | |
| 110 | node->minor = minor; |
| 111 | node->dent = ent; |
| 112 | node->info_ent = (void *)fops; |
| 113 | |
| 114 | mutex_lock(&minor->debugfs_lock); |
| 115 | list_add(&node->list, &minor->debugfs_list); |
| 116 | mutex_unlock(&minor->debugfs_lock); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static int sti_drm_dbg_init(struct drm_minor *minor) |
| 122 | { |
| 123 | int ret; |
| 124 | |
| 125 | ret = drm_debugfs_create_files(sti_drm_dbg_list, |
| 126 | ARRAY_SIZE(sti_drm_dbg_list), |
| 127 | minor->debugfs_root, minor); |
| 128 | if (ret) |
| 129 | goto err; |
| 130 | |
| 131 | ret = sti_drm_debugfs_create(minor->debugfs_root, minor, "fps_show", |
| 132 | &sti_drm_fps_fops); |
| 133 | if (ret) |
| 134 | goto err; |
| 135 | |
| 136 | DRM_INFO("%s: debugfs installed\n", DRIVER_NAME); |
| 137 | return 0; |
| 138 | err: |
| 139 | DRM_ERROR("%s: cannot install debugfs\n", DRIVER_NAME); |
| 140 | return ret; |
| 141 | } |
| 142 | |
Ville Syrjälä | bdfd36e | 2016-09-19 16:33:53 +0300 | [diff] [blame] | 143 | static void sti_drm_dbg_cleanup(struct drm_minor *minor) |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 144 | { |
| 145 | drm_debugfs_remove_files(sti_drm_dbg_list, |
| 146 | ARRAY_SIZE(sti_drm_dbg_list), minor); |
| 147 | |
| 148 | drm_debugfs_remove_files((struct drm_info_list *)&sti_drm_fps_fops, |
| 149 | 1, minor); |
| 150 | } |
| 151 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 152 | static void sti_atomic_schedule(struct sti_private *private, |
| 153 | struct drm_atomic_state *state) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 154 | { |
| 155 | private->commit.state = state; |
| 156 | schedule_work(&private->commit.work); |
| 157 | } |
| 158 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 159 | static void sti_atomic_complete(struct sti_private *private, |
| 160 | struct drm_atomic_state *state) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 161 | { |
| 162 | struct drm_device *drm = private->drm_dev; |
| 163 | |
| 164 | /* |
| 165 | * Everything below can be run asynchronously without the need to grab |
| 166 | * any modeset locks at all under one condition: It must be guaranteed |
| 167 | * that the asynchronous work has either been cancelled (if the driver |
| 168 | * supports it, which at least requires that the framebuffers get |
| 169 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 170 | * before the new state gets committed on the software side with |
| 171 | * drm_atomic_helper_swap_state(). |
| 172 | * |
| 173 | * This scheme allows new atomic state updates to be prepared and |
| 174 | * checked in parallel to the asynchronous completion of the previous |
| 175 | * update. Which is important since compositors need to figure out the |
| 176 | * composition of the next frame right after having submitted the |
| 177 | * current layout. |
| 178 | */ |
| 179 | |
| 180 | drm_atomic_helper_commit_modeset_disables(drm, state); |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 181 | drm_atomic_helper_commit_planes(drm, state, 0); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 182 | drm_atomic_helper_commit_modeset_enables(drm, state); |
| 183 | |
| 184 | drm_atomic_helper_wait_for_vblanks(drm, state); |
| 185 | |
| 186 | drm_atomic_helper_cleanup_planes(drm, state); |
| 187 | drm_atomic_state_free(state); |
| 188 | } |
| 189 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 190 | static void sti_atomic_work(struct work_struct *work) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 191 | { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 192 | struct sti_private *private = container_of(work, |
| 193 | struct sti_private, commit.work); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 194 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 195 | sti_atomic_complete(private, private->commit.state); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Ville Syrjälä | 38d868e | 2016-10-10 17:50:56 +0300 | [diff] [blame] | 198 | static int sti_atomic_check(struct drm_device *dev, |
| 199 | struct drm_atomic_state *state) |
| 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | ret = drm_atomic_helper_check_modeset(dev, state); |
| 204 | if (ret) |
| 205 | return ret; |
| 206 | |
| 207 | ret = drm_atomic_normalize_zpos(dev, state); |
| 208 | if (ret) |
| 209 | return ret; |
| 210 | |
| 211 | ret = drm_atomic_helper_check_planes(dev, state); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | return ret; |
| 216 | } |
| 217 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 218 | static int sti_atomic_commit(struct drm_device *drm, |
Maarten Lankhorst | ab57518 | 2016-04-26 16:11:41 +0200 | [diff] [blame] | 219 | struct drm_atomic_state *state, bool nonblock) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 220 | { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 221 | struct sti_private *private = drm->dev_private; |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 222 | int err; |
| 223 | |
| 224 | err = drm_atomic_helper_prepare_planes(drm, state); |
| 225 | if (err) |
| 226 | return err; |
| 227 | |
Maarten Lankhorst | ab57518 | 2016-04-26 16:11:41 +0200 | [diff] [blame] | 228 | /* serialize outstanding nonblocking commits */ |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 229 | mutex_lock(&private->commit.lock); |
| 230 | flush_work(&private->commit.work); |
| 231 | |
| 232 | /* |
| 233 | * This is the point of no return - everything below never fails except |
| 234 | * when the hw goes bonghits. Which means we can commit the new state on |
| 235 | * the software side now. |
| 236 | */ |
| 237 | |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 238 | drm_atomic_helper_swap_state(state, true); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 239 | |
Maarten Lankhorst | ab57518 | 2016-04-26 16:11:41 +0200 | [diff] [blame] | 240 | if (nonblock) |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 241 | sti_atomic_schedule(private, state); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 242 | else |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 243 | sti_atomic_complete(private, state); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 244 | |
| 245 | mutex_unlock(&private->commit.lock); |
| 246 | return 0; |
| 247 | } |
| 248 | |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 249 | static void sti_output_poll_changed(struct drm_device *ddev) |
| 250 | { |
| 251 | struct sti_private *private = ddev->dev_private; |
| 252 | |
| 253 | if (!ddev->mode_config.num_connector) |
| 254 | return; |
| 255 | |
| 256 | if (private->fbdev) { |
| 257 | drm_fbdev_cma_hotplug_event(private->fbdev); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | private->fbdev = drm_fbdev_cma_init(ddev, 32, |
| 262 | ddev->mode_config.num_crtc, |
| 263 | ddev->mode_config.num_connector); |
| 264 | if (IS_ERR(private->fbdev)) |
| 265 | private->fbdev = NULL; |
| 266 | } |
| 267 | |
Ville Syrjälä | c5de485 | 2015-09-02 13:44:15 +0300 | [diff] [blame] | 268 | static const struct drm_mode_config_funcs sti_mode_config_funcs = { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 269 | .fb_create = drm_fb_cma_create, |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 270 | .output_poll_changed = sti_output_poll_changed, |
Ville Syrjälä | 38d868e | 2016-10-10 17:50:56 +0300 | [diff] [blame] | 271 | .atomic_check = sti_atomic_check, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 272 | .atomic_commit = sti_atomic_commit, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 273 | }; |
| 274 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 275 | static void sti_mode_config_init(struct drm_device *dev) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 276 | { |
| 277 | dev->mode_config.min_width = 0; |
| 278 | dev->mode_config.min_height = 0; |
| 279 | |
| 280 | /* |
| 281 | * set max width and height as default value. |
| 282 | * this value would be used to check framebuffer size limitation |
| 283 | * at drm_mode_addfb(). |
| 284 | */ |
Vincent Abriou | 738be9d | 2015-10-29 14:20:27 +0100 | [diff] [blame] | 285 | dev->mode_config.max_width = STI_MAX_FB_WIDTH; |
| 286 | dev->mode_config.max_height = STI_MAX_FB_HEIGHT; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 287 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 288 | dev->mode_config.funcs = &sti_mode_config_funcs; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 291 | static const struct file_operations sti_driver_fops = { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 292 | .owner = THIS_MODULE, |
| 293 | .open = drm_open, |
| 294 | .mmap = drm_gem_cma_mmap, |
| 295 | .poll = drm_poll, |
| 296 | .read = drm_read, |
| 297 | .unlocked_ioctl = drm_ioctl, |
| 298 | #ifdef CONFIG_COMPAT |
| 299 | .compat_ioctl = drm_compat_ioctl, |
| 300 | #endif |
| 301 | .release = drm_release, |
| 302 | }; |
| 303 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 304 | static struct drm_driver sti_driver = { |
Shawn Guo | e1f96ef | 2016-08-16 15:06:08 +0800 | [diff] [blame] | 305 | .driver_features = DRIVER_MODESET | |
benjamin.gaignard@linaro.org | f29ddaf | 2016-01-07 14:30:41 +0100 | [diff] [blame] | 306 | DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC, |
Daniel Vetter | d41ec9c | 2016-05-30 19:53:11 +0200 | [diff] [blame] | 307 | .gem_free_object_unlocked = drm_gem_cma_free_object, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 308 | .gem_vm_ops = &drm_gem_cma_vm_ops, |
| 309 | .dumb_create = drm_gem_cma_dumb_create, |
| 310 | .dumb_map_offset = drm_gem_cma_dumb_map_offset, |
| 311 | .dumb_destroy = drm_gem_dumb_destroy, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 312 | .fops = &sti_driver_fops, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 313 | |
Ville Syrjälä | b44f840 | 2015-09-30 16:46:48 +0300 | [diff] [blame] | 314 | .get_vblank_counter = drm_vblank_no_hw_counter, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 315 | .enable_vblank = sti_crtc_enable_vblank, |
| 316 | .disable_vblank = sti_crtc_disable_vblank, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 317 | |
| 318 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 319 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Benjamin Gaignard | ffd157c | 2016-02-26 11:19:06 +0100 | [diff] [blame] | 320 | .gem_prime_export = drm_gem_prime_export, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 321 | .gem_prime_import = drm_gem_prime_import, |
| 322 | .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, |
| 323 | .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, |
| 324 | .gem_prime_vmap = drm_gem_cma_prime_vmap, |
| 325 | .gem_prime_vunmap = drm_gem_cma_prime_vunmap, |
| 326 | .gem_prime_mmap = drm_gem_cma_prime_mmap, |
| 327 | |
Vincent Abriou | bf8f9e4 | 2016-02-08 11:34:31 +0100 | [diff] [blame] | 328 | .debugfs_init = sti_drm_dbg_init, |
| 329 | .debugfs_cleanup = sti_drm_dbg_cleanup, |
| 330 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 331 | .name = DRIVER_NAME, |
| 332 | .desc = DRIVER_DESC, |
| 333 | .date = DRIVER_DATE, |
| 334 | .major = DRIVER_MAJOR, |
| 335 | .minor = DRIVER_MINOR, |
| 336 | }; |
| 337 | |
| 338 | static int compare_of(struct device *dev, void *data) |
| 339 | { |
| 340 | return dev->of_node == data; |
| 341 | } |
| 342 | |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 343 | static int sti_init(struct drm_device *ddev) |
| 344 | { |
| 345 | struct sti_private *private; |
| 346 | |
| 347 | private = kzalloc(sizeof(*private), GFP_KERNEL); |
| 348 | if (!private) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | ddev->dev_private = (void *)private; |
| 352 | dev_set_drvdata(ddev->dev, ddev); |
| 353 | private->drm_dev = ddev; |
| 354 | |
| 355 | mutex_init(&private->commit.lock); |
| 356 | INIT_WORK(&private->commit.work, sti_atomic_work); |
| 357 | |
| 358 | drm_mode_config_init(ddev); |
| 359 | |
| 360 | sti_mode_config_init(ddev); |
| 361 | |
| 362 | drm_kms_helper_poll_init(ddev); |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static void sti_cleanup(struct drm_device *ddev) |
| 368 | { |
| 369 | struct sti_private *private = ddev->dev_private; |
| 370 | |
| 371 | if (private->fbdev) { |
| 372 | drm_fbdev_cma_fini(private->fbdev); |
| 373 | private->fbdev = NULL; |
| 374 | } |
| 375 | |
| 376 | drm_kms_helper_poll_fini(ddev); |
| 377 | drm_vblank_cleanup(ddev); |
| 378 | kfree(private); |
| 379 | ddev->dev_private = NULL; |
| 380 | } |
| 381 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 382 | static int sti_bind(struct device *dev) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 383 | { |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 384 | struct drm_device *ddev; |
| 385 | int ret; |
| 386 | |
| 387 | ddev = drm_dev_alloc(&sti_driver, dev); |
Tom Gundersen | 0f28860 | 2016-09-21 16:59:19 +0200 | [diff] [blame] | 388 | if (IS_ERR(ddev)) |
| 389 | return PTR_ERR(ddev); |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 390 | |
| 391 | ddev->platformdev = to_platform_device(dev); |
| 392 | |
| 393 | ret = sti_init(ddev); |
| 394 | if (ret) |
| 395 | goto err_drm_dev_unref; |
| 396 | |
| 397 | ret = component_bind_all(ddev->dev, ddev); |
| 398 | if (ret) |
| 399 | goto err_cleanup; |
| 400 | |
| 401 | ret = drm_dev_register(ddev, 0); |
| 402 | if (ret) |
| 403 | goto err_register; |
| 404 | |
| 405 | drm_mode_config_reset(ddev); |
| 406 | |
| 407 | return 0; |
| 408 | |
| 409 | err_register: |
| 410 | drm_mode_config_cleanup(ddev); |
| 411 | err_cleanup: |
| 412 | sti_cleanup(ddev); |
| 413 | err_drm_dev_unref: |
| 414 | drm_dev_unref(ddev); |
| 415 | return ret; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 418 | static void sti_unbind(struct device *dev) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 419 | { |
Benjamin Gaignard | 84601db | 2016-06-21 15:09:40 +0200 | [diff] [blame] | 420 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 421 | |
| 422 | drm_dev_unregister(ddev); |
| 423 | sti_cleanup(ddev); |
| 424 | drm_dev_unref(ddev); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 425 | } |
| 426 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 427 | static const struct component_master_ops sti_ops = { |
| 428 | .bind = sti_bind, |
| 429 | .unbind = sti_unbind, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 430 | }; |
| 431 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 432 | static int sti_platform_probe(struct platform_device *pdev) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 433 | { |
| 434 | struct device *dev = &pdev->dev; |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 435 | struct device_node *node = dev->of_node; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 436 | struct device_node *child_np; |
| 437 | struct component_match *match = NULL; |
| 438 | |
| 439 | dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); |
| 440 | |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 441 | of_platform_populate(node, NULL, NULL, dev); |
| 442 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 443 | child_np = of_get_next_available_child(node, NULL); |
| 444 | |
| 445 | while (child_np) { |
| 446 | component_match_add(dev, &match, compare_of, child_np); |
| 447 | of_node_put(child_np); |
| 448 | child_np = of_get_next_available_child(node, child_np); |
| 449 | } |
| 450 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 451 | return component_master_add_with_match(dev, &sti_ops, match); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 452 | } |
| 453 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 454 | static int sti_platform_remove(struct platform_device *pdev) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 455 | { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 456 | component_master_del(&pdev->dev, &sti_ops); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 457 | of_platform_depopulate(&pdev->dev); |
Benjamin Gaignard | 53bdcf5 | 2015-07-17 12:06:11 +0200 | [diff] [blame] | 458 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 459 | return 0; |
| 460 | } |
| 461 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 462 | static const struct of_device_id sti_dt_ids[] = { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 463 | { .compatible = "st,sti-display-subsystem", }, |
| 464 | { /* end node */ }, |
| 465 | }; |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 466 | MODULE_DEVICE_TABLE(of, sti_dt_ids); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 467 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 468 | static struct platform_driver sti_platform_driver = { |
| 469 | .probe = sti_platform_probe, |
| 470 | .remove = sti_platform_remove, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 471 | .driver = { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 472 | .name = DRIVER_NAME, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 473 | .of_match_table = sti_dt_ids, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 474 | }, |
| 475 | }; |
| 476 | |
Thierry Reding | dcec16e | 2015-09-24 19:02:40 +0200 | [diff] [blame] | 477 | static struct platform_driver * const drivers[] = { |
| 478 | &sti_tvout_driver, |
| 479 | &sti_vtac_driver, |
| 480 | &sti_hqvdp_driver, |
| 481 | &sti_hdmi_driver, |
| 482 | &sti_hda_driver, |
| 483 | &sti_dvo_driver, |
| 484 | &sti_vtg_driver, |
| 485 | &sti_compositor_driver, |
| 486 | &sti_platform_driver, |
| 487 | }; |
| 488 | |
| 489 | static int sti_drm_init(void) |
| 490 | { |
| 491 | return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); |
| 492 | } |
| 493 | module_init(sti_drm_init); |
| 494 | |
| 495 | static void sti_drm_exit(void) |
| 496 | { |
| 497 | platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); |
| 498 | } |
| 499 | module_exit(sti_drm_exit); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 500 | |
| 501 | MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>"); |
| 502 | MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver"); |
| 503 | MODULE_LICENSE("GPL"); |