Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) STMicroelectronics SA 2014 |
| 3 | * Authors: Benjamin Gaignard <benjamin.gaignard@st.com> |
| 4 | * Fabien Dessenne <fabien.dessenne@st.com> |
| 5 | * for STMicroelectronics. |
| 6 | * License terms: GNU General Public License (GPL), version 2 |
| 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| 10 | |
| 11 | #include <drm/drmP.h> |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 12 | #include <drm/drm_atomic.h> |
| 13 | #include <drm/drm_atomic_helper.h> |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 14 | #include <drm/drm_crtc_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 15 | #include <drm/drm_plane_helper.h> |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 16 | |
| 17 | #include "sti_compositor.h" |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 18 | #include "sti_crtc.h" |
| 19 | #include "sti_drv.h" |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 20 | #include "sti_vid.h" |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 21 | #include "sti_vtg.h" |
| 22 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 23 | static void sti_crtc_enable(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 24 | { |
| 25 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 26 | struct device *dev = mixer->dev; |
| 27 | struct sti_compositor *compo = dev_get_drvdata(dev); |
| 28 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 29 | DRM_DEBUG_DRIVER("\n"); |
| 30 | |
| 31 | mixer->status = STI_MIXER_READY; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 32 | |
| 33 | /* Prepare and enable the compo IP clock */ |
| 34 | if (mixer->id == STI_MIXER_MAIN) { |
| 35 | if (clk_prepare_enable(compo->clk_compo_main)) |
| 36 | DRM_INFO("Failed to prepare/enable compo_main clk\n"); |
| 37 | } else { |
| 38 | if (clk_prepare_enable(compo->clk_compo_aux)) |
| 39 | DRM_INFO("Failed to prepare/enable compo_aux clk\n"); |
| 40 | } |
Benjamin Gaignard | 2f7d0e82c | 2014-12-04 11:17:32 +0100 | [diff] [blame] | 41 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 42 | drm_crtc_vblank_on(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 45 | static void sti_crtc_disabling(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 46 | { |
| 47 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 48 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 49 | DRM_DEBUG_DRIVER("\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 50 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 51 | mixer->status = STI_MIXER_DISABLING; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 52 | } |
| 53 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 54 | static bool sti_crtc_mode_fixup(struct drm_crtc *crtc, |
| 55 | const struct drm_display_mode *mode, |
| 56 | struct drm_display_mode *adjusted_mode) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 57 | { |
| 58 | /* accept the provided drm_display_mode, do not fix it up */ |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | static int |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 63 | sti_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 64 | { |
| 65 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 66 | struct device *dev = mixer->dev; |
| 67 | struct sti_compositor *compo = dev_get_drvdata(dev); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 68 | struct clk *clk; |
| 69 | int rate = mode->clock * 1000; |
| 70 | int res; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 71 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 72 | DRM_DEBUG_KMS("CRTC:%d (%s) mode:%d (%s)\n", |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 73 | crtc->base.id, sti_mixer_to_str(mixer), |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 74 | mode->base.id, mode->name); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 75 | |
| 76 | DRM_DEBUG_KMS("%d %d %d %d %d %d %d %d %d %d 0x%x 0x%x\n", |
| 77 | mode->vrefresh, mode->clock, |
| 78 | mode->hdisplay, |
| 79 | mode->hsync_start, mode->hsync_end, |
| 80 | mode->htotal, |
| 81 | mode->vdisplay, |
| 82 | mode->vsync_start, mode->vsync_end, |
| 83 | mode->vtotal, mode->type, mode->flags); |
| 84 | |
| 85 | /* Set rate and prepare/enable pixel clock */ |
| 86 | if (mixer->id == STI_MIXER_MAIN) |
| 87 | clk = compo->clk_pix_main; |
| 88 | else |
| 89 | clk = compo->clk_pix_aux; |
| 90 | |
| 91 | res = clk_set_rate(clk, rate); |
| 92 | if (res < 0) { |
| 93 | DRM_ERROR("Cannot set rate (%dHz) for pix clk\n", rate); |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | if (clk_prepare_enable(clk)) { |
| 97 | DRM_ERROR("Failed to prepare/enable pix clk\n"); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
| 101 | sti_vtg_set_config(mixer->id == STI_MIXER_MAIN ? |
| 102 | compo->vtg_main : compo->vtg_aux, &crtc->mode); |
| 103 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 104 | res = sti_mixer_active_video_area(mixer, &crtc->mode); |
| 105 | if (res) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 106 | DRM_ERROR("Can't set active video area\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 107 | return -EINVAL; |
| 108 | } |
| 109 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 110 | return res; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 113 | static void sti_crtc_disable(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 114 | { |
| 115 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 116 | struct device *dev = mixer->dev; |
| 117 | struct sti_compositor *compo = dev_get_drvdata(dev); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 118 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 119 | DRM_DEBUG_KMS("CRTC:%d (%s)\n", crtc->base.id, sti_mixer_to_str(mixer)); |
| 120 | |
| 121 | /* Disable Background */ |
| 122 | sti_mixer_set_background_status(mixer, false); |
| 123 | |
Benjamin Gaignard | ca614aa | 2014-12-04 11:27:45 +0100 | [diff] [blame] | 124 | drm_crtc_vblank_off(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 125 | |
| 126 | /* Disable pixel clock and compo IP clocks */ |
| 127 | if (mixer->id == STI_MIXER_MAIN) { |
| 128 | clk_disable_unprepare(compo->clk_pix_main); |
| 129 | clk_disable_unprepare(compo->clk_compo_main); |
| 130 | } else { |
| 131 | clk_disable_unprepare(compo->clk_pix_aux); |
| 132 | clk_disable_unprepare(compo->clk_compo_aux); |
| 133 | } |
| 134 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 135 | mixer->status = STI_MIXER_DISABLED; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 138 | static void |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 139 | sti_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 140 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 141 | sti_crtc_enable(crtc); |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 142 | sti_crtc_mode_set(crtc, &crtc->state->adjusted_mode); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 145 | static void sti_crtc_atomic_begin(struct drm_crtc *crtc) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 146 | { |
| 147 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 148 | |
| 149 | if (crtc->state->event) { |
| 150 | crtc->state->event->pipe = drm_crtc_index(crtc); |
| 151 | |
| 152 | WARN_ON(drm_crtc_vblank_get(crtc) != 0); |
| 153 | |
| 154 | mixer->pending_event = crtc->state->event; |
| 155 | crtc->state->event = NULL; |
| 156 | } |
| 157 | } |
| 158 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 159 | static void sti_crtc_atomic_flush(struct drm_crtc *crtc) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 160 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 161 | struct drm_device *drm_dev = crtc->dev; |
| 162 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 163 | struct sti_compositor *compo = dev_get_drvdata(mixer->dev); |
| 164 | struct drm_plane *p; |
| 165 | |
| 166 | DRM_DEBUG_DRIVER("\n"); |
| 167 | |
| 168 | /* perform plane actions */ |
| 169 | list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) { |
| 170 | struct sti_plane *plane = to_sti_plane(p); |
| 171 | |
| 172 | switch (plane->status) { |
| 173 | case STI_PLANE_UPDATED: |
| 174 | /* update planes tag as updated */ |
| 175 | DRM_DEBUG_DRIVER("update plane %s\n", |
| 176 | sti_plane_to_str(plane)); |
| 177 | |
| 178 | if (sti_mixer_set_plane_depth(mixer, plane)) { |
| 179 | DRM_ERROR("Cannot set plane %s depth\n", |
| 180 | sti_plane_to_str(plane)); |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | if (sti_mixer_set_plane_status(mixer, plane, true)) { |
| 185 | DRM_ERROR("Cannot enable plane %s at mixer\n", |
| 186 | sti_plane_to_str(plane)); |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | /* if plane is HQVDP_0 then commit the vid[0] */ |
| 191 | if (plane->desc == STI_HQVDP_0) |
| 192 | sti_vid_commit(compo->vid[0], p->state); |
| 193 | |
| 194 | plane->status = STI_PLANE_READY; |
| 195 | |
| 196 | break; |
| 197 | case STI_PLANE_DISABLING: |
| 198 | /* disabling sequence for planes tag as disabling */ |
| 199 | DRM_DEBUG_DRIVER("disable plane %s from mixer\n", |
| 200 | sti_plane_to_str(plane)); |
| 201 | |
| 202 | if (sti_mixer_set_plane_status(mixer, plane, false)) { |
| 203 | DRM_ERROR("Cannot disable plane %s at mixer\n", |
| 204 | sti_plane_to_str(plane)); |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | if (plane->desc == STI_CURSOR) |
| 209 | /* tag plane status for disabled */ |
| 210 | plane->status = STI_PLANE_DISABLED; |
| 211 | else |
| 212 | /* tag plane status for flushing */ |
| 213 | plane->status = STI_PLANE_FLUSHING; |
| 214 | |
| 215 | /* if plane is HQVDP_0 then disable the vid[0] */ |
| 216 | if (plane->desc == STI_HQVDP_0) |
| 217 | sti_vid_disable(compo->vid[0]); |
| 218 | |
| 219 | break; |
| 220 | default: |
| 221 | /* Other status case are not handled */ |
| 222 | break; |
| 223 | } |
| 224 | } |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 227 | static struct drm_crtc_helper_funcs sti_crtc_helper_funcs = { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 228 | .enable = sti_crtc_enable, |
| 229 | .disable = sti_crtc_disabling, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 230 | .mode_fixup = sti_crtc_mode_fixup, |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 231 | .mode_set = drm_helper_crtc_mode_set, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 232 | .mode_set_nofb = sti_crtc_mode_set_nofb, |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 233 | .mode_set_base = drm_helper_crtc_mode_set_base, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 234 | .atomic_begin = sti_crtc_atomic_begin, |
| 235 | .atomic_flush = sti_crtc_atomic_flush, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 236 | }; |
| 237 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 238 | static void sti_crtc_destroy(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 239 | { |
| 240 | DRM_DEBUG_KMS("\n"); |
| 241 | drm_crtc_cleanup(crtc); |
| 242 | } |
| 243 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 244 | static int sti_crtc_set_property(struct drm_crtc *crtc, |
| 245 | struct drm_property *property, |
| 246 | uint64_t val) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 247 | { |
| 248 | DRM_DEBUG_KMS("\n"); |
| 249 | return 0; |
| 250 | } |
| 251 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 252 | int sti_crtc_vblank_cb(struct notifier_block *nb, |
| 253 | unsigned long event, void *data) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 254 | { |
| 255 | struct drm_device *drm_dev; |
| 256 | struct sti_compositor *compo = |
| 257 | container_of(nb, struct sti_compositor, vtg_vblank_nb); |
| 258 | int *crtc = data; |
| 259 | unsigned long flags; |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 260 | struct sti_private *priv; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 261 | |
| 262 | drm_dev = compo->mixer[*crtc]->drm_crtc.dev; |
| 263 | priv = drm_dev->dev_private; |
| 264 | |
| 265 | if ((event != VTG_TOP_FIELD_EVENT) && |
| 266 | (event != VTG_BOTTOM_FIELD_EVENT)) { |
| 267 | DRM_ERROR("unknown event: %lu\n", event); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | drm_handle_vblank(drm_dev, *crtc); |
| 272 | |
| 273 | spin_lock_irqsave(&drm_dev->event_lock, flags); |
| 274 | if (compo->mixer[*crtc]->pending_event) { |
| 275 | drm_send_vblank_event(drm_dev, -1, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 276 | compo->mixer[*crtc]->pending_event); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 277 | drm_vblank_put(drm_dev, *crtc); |
| 278 | compo->mixer[*crtc]->pending_event = NULL; |
| 279 | } |
| 280 | spin_unlock_irqrestore(&drm_dev->event_lock, flags); |
| 281 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 282 | if (compo->mixer[*crtc]->status == STI_MIXER_DISABLING) { |
| 283 | struct drm_plane *p; |
| 284 | |
| 285 | /* Disable mixer only if all overlay planes (GDP and VDP) |
| 286 | * are disabled */ |
| 287 | list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) { |
| 288 | struct sti_plane *plane = to_sti_plane(p); |
| 289 | |
| 290 | if ((plane->desc & STI_PLANE_TYPE_MASK) <= STI_VDP) |
| 291 | if (plane->status != STI_PLANE_DISABLED) |
| 292 | return 0; |
| 293 | } |
| 294 | sti_crtc_disable(&compo->mixer[*crtc]->drm_crtc); |
| 295 | } |
| 296 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 300 | int sti_crtc_enable_vblank(struct drm_device *dev, int crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 301 | { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 302 | struct sti_private *dev_priv = dev->dev_private; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 303 | struct sti_compositor *compo = dev_priv->compo; |
| 304 | struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb; |
| 305 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 306 | DRM_DEBUG_DRIVER("\n"); |
| 307 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 308 | if (sti_vtg_register_client(crtc == STI_MIXER_MAIN ? |
| 309 | compo->vtg_main : compo->vtg_aux, |
| 310 | vtg_vblank_nb, crtc)) { |
| 311 | DRM_ERROR("Cannot register VTG notifier\n"); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | |
| 315 | return 0; |
| 316 | } |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 317 | EXPORT_SYMBOL(sti_crtc_enable_vblank); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 318 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 319 | void sti_crtc_disable_vblank(struct drm_device *drm_dev, int crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 320 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 321 | struct sti_private *priv = drm_dev->dev_private; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 322 | struct sti_compositor *compo = priv->compo; |
| 323 | struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 324 | |
| 325 | DRM_DEBUG_DRIVER("\n"); |
| 326 | |
| 327 | if (sti_vtg_unregister_client(crtc == STI_MIXER_MAIN ? |
| 328 | compo->vtg_main : compo->vtg_aux, vtg_vblank_nb)) |
| 329 | DRM_DEBUG_DRIVER("Warning: cannot unregister VTG notifier\n"); |
| 330 | |
| 331 | /* free the resources of the pending requests */ |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 332 | if (compo->mixer[crtc]->pending_event) { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame^] | 333 | drm_vblank_put(drm_dev, crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 334 | compo->mixer[crtc]->pending_event = NULL; |
| 335 | } |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 336 | } |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 337 | EXPORT_SYMBOL(sti_crtc_disable_vblank); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 338 | |
| 339 | static struct drm_crtc_funcs sti_crtc_funcs = { |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 340 | .set_config = drm_atomic_helper_set_config, |
| 341 | .page_flip = drm_atomic_helper_page_flip, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 342 | .destroy = sti_crtc_destroy, |
| 343 | .set_property = sti_crtc_set_property, |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 344 | .reset = drm_atomic_helper_crtc_reset, |
| 345 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 346 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 349 | bool sti_crtc_is_main(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 350 | { |
| 351 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 352 | |
| 353 | if (mixer->id == STI_MIXER_MAIN) |
| 354 | return true; |
| 355 | |
| 356 | return false; |
| 357 | } |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 358 | EXPORT_SYMBOL(sti_crtc_is_main); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 359 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 360 | int sti_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer, |
| 361 | struct drm_plane *primary, struct drm_plane *cursor) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 362 | { |
| 363 | struct drm_crtc *crtc = &mixer->drm_crtc; |
| 364 | int res; |
| 365 | |
| 366 | res = drm_crtc_init_with_planes(drm_dev, crtc, primary, cursor, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 367 | &sti_crtc_funcs); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 368 | if (res) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 369 | DRM_ERROR("Can't initialze CRTC\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 370 | return -EINVAL; |
| 371 | } |
| 372 | |
| 373 | drm_crtc_helper_add(crtc, &sti_crtc_helper_funcs); |
| 374 | |
| 375 | DRM_DEBUG_DRIVER("drm CRTC:%d mapped to %s\n", |
| 376 | crtc->base.id, sti_mixer_to_str(mixer)); |
| 377 | |
| 378 | return 0; |
| 379 | } |