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