Benjamin Gaignard | e284257 | 2017-12-06 12:29:47 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) STMicroelectronics SA 2014 |
| 4 | * Authors: Benjamin Gaignard <benjamin.gaignard@st.com> |
| 5 | * Fabien Dessenne <fabien.dessenne@st.com> |
| 6 | * for STMicroelectronics. |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| 10 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 11 | #include <drm/drm_atomic.h> |
| 12 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | 5e2f97a | 2019-06-05 15:48:35 +0200 | [diff] [blame] | 13 | #include <drm/drm_device.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 14 | #include <drm/drm_plane_helper.h> |
Sam Ravnborg | 5e2f97a | 2019-06-05 15:48:35 +0200 | [diff] [blame] | 15 | #include <drm/drm_print.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 16 | #include <drm/drm_probe_helper.h> |
Sam Ravnborg | 5e2f97a | 2019-06-05 15:48:35 +0200 | [diff] [blame] | 17 | #include <drm/drm_vblank.h> |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 18 | |
| 19 | #include "sti_compositor.h" |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 20 | #include "sti_crtc.h" |
| 21 | #include "sti_drv.h" |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 22 | #include "sti_vid.h" |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 23 | #include "sti_vtg.h" |
| 24 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 25 | static void sti_crtc_atomic_enable(struct drm_crtc *crtc, |
Maxime Ripard | 351f950 | 2020-10-08 14:44:08 +0200 | [diff] [blame] | 26 | struct drm_atomic_state *state) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 27 | { |
| 28 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 29 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 30 | DRM_DEBUG_DRIVER("\n"); |
| 31 | |
| 32 | mixer->status = STI_MIXER_READY; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 33 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 34 | drm_crtc_vblank_on(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 37 | static void sti_crtc_atomic_disable(struct drm_crtc *crtc, |
Maxime Ripard | 351f950 | 2020-10-08 14:44:08 +0200 | [diff] [blame] | 38 | struct drm_atomic_state *state) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 39 | { |
| 40 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 41 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 42 | DRM_DEBUG_DRIVER("\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 43 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 44 | mixer->status = STI_MIXER_DISABLING; |
Benjamin Gaignard | 885054f | 2018-10-12 11:46:38 +0200 | [diff] [blame] | 45 | |
| 46 | drm_crtc_wait_one_vblank(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 49 | static int |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 50 | 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] | 51 | { |
| 52 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 53 | struct device *dev = mixer->dev; |
| 54 | struct sti_compositor *compo = dev_get_drvdata(dev); |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 55 | struct clk *compo_clk, *pix_clk; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 56 | int rate = mode->clock * 1000; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 57 | |
Shayenne Moura | 5e8345a | 2018-12-20 10:27:30 -0200 | [diff] [blame] | 58 | DRM_DEBUG_KMS("CRTC:%d (%s) mode: (%s)\n", |
| 59 | crtc->base.id, sti_mixer_to_str(mixer), mode->name); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 60 | |
Shayenne Moura | 5e8345a | 2018-12-20 10:27:30 -0200 | [diff] [blame] | 61 | DRM_DEBUG_KMS(DRM_MODE_FMT "\n", DRM_MODE_ARG(mode)); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 62 | |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 63 | if (mixer->id == STI_MIXER_MAIN) { |
| 64 | compo_clk = compo->clk_compo_main; |
| 65 | pix_clk = compo->clk_pix_main; |
| 66 | } else { |
| 67 | compo_clk = compo->clk_compo_aux; |
| 68 | pix_clk = compo->clk_pix_aux; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 69 | } |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 70 | |
| 71 | /* Prepare and enable the compo IP clock */ |
| 72 | if (clk_prepare_enable(compo_clk)) { |
| 73 | DRM_INFO("Failed to prepare/enable compositor clk\n"); |
| 74 | goto compo_error; |
| 75 | } |
| 76 | |
| 77 | /* Set rate and prepare/enable pixel clock */ |
| 78 | if (clk_set_rate(pix_clk, rate) < 0) { |
| 79 | DRM_ERROR("Cannot set rate (%dHz) for pix clk\n", rate); |
| 80 | goto pix_error; |
| 81 | } |
| 82 | if (clk_prepare_enable(pix_clk)) { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 83 | DRM_ERROR("Failed to prepare/enable pix clk\n"); |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 84 | goto pix_error; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 87 | sti_vtg_set_config(compo->vtg[mixer->id], &crtc->mode); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 88 | |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 89 | if (sti_mixer_active_video_area(mixer, &crtc->mode)) { |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 90 | DRM_ERROR("Can't set active video area\n"); |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 91 | goto mixer_error; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Benjamin Gaignard | 32e1459 | 2016-05-26 10:39:20 +0200 | [diff] [blame] | 94 | return 0; |
| 95 | |
| 96 | mixer_error: |
| 97 | clk_disable_unprepare(pix_clk); |
| 98 | pix_error: |
| 99 | clk_disable_unprepare(compo_clk); |
| 100 | compo_error: |
| 101 | return -EINVAL; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 104 | static void sti_crtc_disable(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 105 | { |
| 106 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 107 | struct device *dev = mixer->dev; |
| 108 | struct sti_compositor *compo = dev_get_drvdata(dev); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 109 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 110 | DRM_DEBUG_KMS("CRTC:%d (%s)\n", crtc->base.id, sti_mixer_to_str(mixer)); |
| 111 | |
| 112 | /* Disable Background */ |
| 113 | sti_mixer_set_background_status(mixer, false); |
| 114 | |
Benjamin Gaignard | ca614aa | 2014-12-04 11:27:45 +0100 | [diff] [blame] | 115 | drm_crtc_vblank_off(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 116 | |
| 117 | /* Disable pixel clock and compo IP clocks */ |
| 118 | if (mixer->id == STI_MIXER_MAIN) { |
| 119 | clk_disable_unprepare(compo->clk_pix_main); |
| 120 | clk_disable_unprepare(compo->clk_compo_main); |
| 121 | } else { |
| 122 | clk_disable_unprepare(compo->clk_pix_aux); |
| 123 | clk_disable_unprepare(compo->clk_compo_aux); |
| 124 | } |
| 125 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 126 | mixer->status = STI_MIXER_DISABLED; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 129 | static void |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 130 | sti_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 131 | { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 132 | sti_crtc_mode_set(crtc, &crtc->state->adjusted_mode); |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Dave Airlie | e1474e7 | 2015-08-14 10:14:23 +1000 | [diff] [blame] | 135 | static void sti_crtc_atomic_flush(struct drm_crtc *crtc, |
Maxime Ripard | f6ebe9f | 2020-10-28 13:32:22 +0100 | [diff] [blame] | 136 | struct drm_atomic_state *state) |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 137 | { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 138 | struct drm_device *drm_dev = crtc->dev; |
| 139 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 140 | struct sti_compositor *compo = dev_get_drvdata(mixer->dev); |
| 141 | struct drm_plane *p; |
Fabien DESSENNE | c62052d | 2017-01-12 17:27:36 +0100 | [diff] [blame] | 142 | struct drm_pending_vblank_event *event; |
| 143 | unsigned long flags; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 144 | |
| 145 | DRM_DEBUG_DRIVER("\n"); |
| 146 | |
| 147 | /* perform plane actions */ |
| 148 | list_for_each_entry(p, &drm_dev->mode_config.plane_list, head) { |
| 149 | struct sti_plane *plane = to_sti_plane(p); |
| 150 | |
| 151 | switch (plane->status) { |
| 152 | case STI_PLANE_UPDATED: |
Fabien Dessenne | 3bc6b01 | 2016-09-06 09:42:39 +0200 | [diff] [blame] | 153 | /* ignore update for other CRTC */ |
| 154 | if (p->state->crtc != crtc) |
| 155 | continue; |
| 156 | |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 157 | /* update planes tag as updated */ |
| 158 | DRM_DEBUG_DRIVER("update plane %s\n", |
| 159 | sti_plane_to_str(plane)); |
| 160 | |
| 161 | if (sti_mixer_set_plane_depth(mixer, plane)) { |
| 162 | DRM_ERROR("Cannot set plane %s depth\n", |
| 163 | sti_plane_to_str(plane)); |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | if (sti_mixer_set_plane_status(mixer, plane, true)) { |
| 168 | DRM_ERROR("Cannot enable plane %s at mixer\n", |
| 169 | sti_plane_to_str(plane)); |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | /* if plane is HQVDP_0 then commit the vid[0] */ |
| 174 | if (plane->desc == STI_HQVDP_0) |
| 175 | sti_vid_commit(compo->vid[0], p->state); |
| 176 | |
| 177 | plane->status = STI_PLANE_READY; |
| 178 | |
| 179 | break; |
| 180 | case STI_PLANE_DISABLING: |
| 181 | /* disabling sequence for planes tag as disabling */ |
| 182 | DRM_DEBUG_DRIVER("disable plane %s from mixer\n", |
| 183 | sti_plane_to_str(plane)); |
| 184 | |
| 185 | if (sti_mixer_set_plane_status(mixer, plane, false)) { |
| 186 | DRM_ERROR("Cannot disable plane %s at mixer\n", |
| 187 | sti_plane_to_str(plane)); |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | if (plane->desc == STI_CURSOR) |
| 192 | /* tag plane status for disabled */ |
| 193 | plane->status = STI_PLANE_DISABLED; |
| 194 | else |
| 195 | /* tag plane status for flushing */ |
| 196 | plane->status = STI_PLANE_FLUSHING; |
| 197 | |
| 198 | /* if plane is HQVDP_0 then disable the vid[0] */ |
| 199 | if (plane->desc == STI_HQVDP_0) |
| 200 | sti_vid_disable(compo->vid[0]); |
| 201 | |
| 202 | break; |
| 203 | default: |
| 204 | /* Other status case are not handled */ |
| 205 | break; |
| 206 | } |
| 207 | } |
Fabien DESSENNE | c62052d | 2017-01-12 17:27:36 +0100 | [diff] [blame] | 208 | |
| 209 | event = crtc->state->event; |
| 210 | if (event) { |
| 211 | crtc->state->event = NULL; |
| 212 | |
| 213 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
| 214 | if (drm_crtc_vblank_get(crtc) == 0) |
| 215 | drm_crtc_arm_vblank_event(crtc, event); |
| 216 | else |
| 217 | drm_crtc_send_vblank_event(crtc, event); |
| 218 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
| 219 | } |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Ville Syrjälä | c5de485 | 2015-09-02 13:44:15 +0300 | [diff] [blame] | 222 | static const struct drm_crtc_helper_funcs sti_crtc_helper_funcs = { |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 223 | .mode_set_nofb = sti_crtc_mode_set_nofb, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 224 | .atomic_flush = sti_crtc_atomic_flush, |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 225 | .atomic_enable = sti_crtc_atomic_enable, |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 226 | .atomic_disable = sti_crtc_atomic_disable, |
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; |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 249 | unsigned int pipe; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 250 | |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 251 | pipe = drm_crtc_index(crtc); |
Fabien Dessenne | ae21785 | 2016-09-06 09:42:13 +0200 | [diff] [blame] | 252 | compo = container_of(nb, struct sti_compositor, vtg_vblank_nb[pipe]); |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 253 | mixer = compo->mixer[pipe]; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 254 | |
| 255 | if ((event != VTG_TOP_FIELD_EVENT) && |
| 256 | (event != VTG_BOTTOM_FIELD_EVENT)) { |
| 257 | DRM_ERROR("unknown event: %lu\n", event); |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 261 | drm_crtc_handle_vblank(crtc); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 262 | |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 263 | if (mixer->status == STI_MIXER_DISABLING) { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 264 | struct drm_plane *p; |
| 265 | |
| 266 | /* Disable mixer only if all overlay planes (GDP and VDP) |
| 267 | * are disabled */ |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 268 | list_for_each_entry(p, &crtc->dev->mode_config.plane_list, |
| 269 | head) { |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 270 | struct sti_plane *plane = to_sti_plane(p); |
| 271 | |
| 272 | if ((plane->desc & STI_PLANE_TYPE_MASK) <= STI_VDP) |
| 273 | if (plane->status != STI_PLANE_DISABLED) |
| 274 | return 0; |
| 275 | } |
Thierry Reding | 2388693 | 2015-09-24 18:35:38 +0200 | [diff] [blame] | 276 | sti_crtc_disable(crtc); |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
Thomas Zimmermann | 87b09c6 | 2020-01-23 14:59:37 +0100 | [diff] [blame] | 282 | static int sti_crtc_enable_vblank(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 283 | { |
Thomas Zimmermann | 87b09c6 | 2020-01-23 14:59:37 +0100 | [diff] [blame] | 284 | struct drm_device *dev = crtc->dev; |
| 285 | unsigned int pipe = crtc->index; |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 286 | struct sti_private *dev_priv = dev->dev_private; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 287 | struct sti_compositor *compo = dev_priv->compo; |
Fabien Dessenne | ae21785 | 2016-09-06 09:42:13 +0200 | [diff] [blame] | 288 | struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb[pipe]; |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 289 | struct sti_vtg *vtg = compo->vtg[pipe]; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 290 | |
Vincent Abriou | 871bcdf | 2015-07-31 11:32:13 +0200 | [diff] [blame] | 291 | DRM_DEBUG_DRIVER("\n"); |
| 292 | |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 293 | if (sti_vtg_register_client(vtg, vtg_vblank_nb, crtc)) { |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 294 | DRM_ERROR("Cannot register VTG notifier\n"); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 300 | |
Thomas Zimmermann | 87b09c6 | 2020-01-23 14:59:37 +0100 | [diff] [blame] | 301 | static void sti_crtc_disable_vblank(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 302 | { |
Thomas Zimmermann | 87b09c6 | 2020-01-23 14:59:37 +0100 | [diff] [blame] | 303 | struct drm_device *drm_dev = crtc->dev; |
| 304 | unsigned int pipe = crtc->index; |
Vincent Abriou | 29d1dc6 | 2015-08-03 14:22:16 +0200 | [diff] [blame] | 305 | struct sti_private *priv = drm_dev->dev_private; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 306 | struct sti_compositor *compo = priv->compo; |
Fabien Dessenne | ae21785 | 2016-09-06 09:42:13 +0200 | [diff] [blame] | 307 | struct notifier_block *vtg_vblank_nb = &compo->vtg_vblank_nb[pipe]; |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 308 | struct sti_vtg *vtg = compo->vtg[pipe]; |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 309 | |
| 310 | DRM_DEBUG_DRIVER("\n"); |
| 311 | |
Fabien Dessenne | ffdbb82 | 2016-09-06 09:42:25 +0200 | [diff] [blame] | 312 | if (sti_vtg_unregister_client(vtg, vtg_vblank_nb)) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 313 | DRM_DEBUG_DRIVER("Warning: cannot unregister VTG notifier\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 314 | } |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 315 | |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 316 | static int sti_crtc_late_register(struct drm_crtc *crtc) |
| 317 | { |
| 318 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 319 | struct sti_compositor *compo = dev_get_drvdata(mixer->dev); |
| 320 | |
| 321 | if (drm_crtc_index(crtc) == 0) |
Wambui Karuga | 54ac836 | 2020-03-10 16:31:13 +0300 | [diff] [blame] | 322 | sti_compositor_debugfs_init(compo, crtc->dev->primary); |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Ville Syrjälä | c5de485 | 2015-09-02 13:44:15 +0300 | [diff] [blame] | 327 | static const struct drm_crtc_funcs sti_crtc_funcs = { |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 328 | .set_config = drm_atomic_helper_set_config, |
| 329 | .page_flip = drm_atomic_helper_page_flip, |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 330 | .destroy = sti_crtc_destroy, |
| 331 | .set_property = sti_crtc_set_property, |
Benjamin Gaignard | de4b00b | 2015-03-19 13:35:16 +0100 | [diff] [blame] | 332 | .reset = drm_atomic_helper_crtc_reset, |
| 333 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 334 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Benjamin Gaignard | 83af0a4 | 2016-06-21 15:09:39 +0200 | [diff] [blame] | 335 | .late_register = sti_crtc_late_register, |
Thomas Zimmermann | 87b09c6 | 2020-01-23 14:59:37 +0100 | [diff] [blame] | 336 | .enable_vblank = sti_crtc_enable_vblank, |
| 337 | .disable_vblank = sti_crtc_disable_vblank, |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 338 | }; |
| 339 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 340 | bool sti_crtc_is_main(struct drm_crtc *crtc) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 341 | { |
| 342 | struct sti_mixer *mixer = to_sti_mixer(crtc); |
| 343 | |
| 344 | if (mixer->id == STI_MIXER_MAIN) |
| 345 | return true; |
| 346 | |
| 347 | return false; |
| 348 | } |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 349 | |
Vincent Abriou | 9e1f05b | 2015-07-31 11:32:34 +0200 | [diff] [blame] | 350 | int sti_crtc_init(struct drm_device *drm_dev, struct sti_mixer *mixer, |
| 351 | struct drm_plane *primary, struct drm_plane *cursor) |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 352 | { |
| 353 | struct drm_crtc *crtc = &mixer->drm_crtc; |
| 354 | int res; |
| 355 | |
| 356 | res = drm_crtc_init_with_planes(drm_dev, crtc, primary, cursor, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 357 | &sti_crtc_funcs, NULL); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 358 | if (res) { |
Colin Ian King | 304f72e | 2018-05-02 11:10:48 +0100 | [diff] [blame] | 359 | DRM_ERROR("Can't initialize CRTC\n"); |
Benjamin Gaignard | 9bbf86f | 2014-07-31 09:39:11 +0200 | [diff] [blame] | 360 | return -EINVAL; |
| 361 | } |
| 362 | |
| 363 | drm_crtc_helper_add(crtc, &sti_crtc_helper_funcs); |
| 364 | |
| 365 | DRM_DEBUG_DRIVER("drm CRTC:%d mapped to %s\n", |
| 366 | crtc->base.id, sti_mixer_to_str(mixer)); |
| 367 | |
| 368 | return 0; |
| 369 | } |