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