Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __SDE_KMS_H__ |
| 14 | #define __SDE_KMS_H__ |
| 15 | |
| 16 | #include "msm_drv.h" |
| 17 | #include "msm_kms.h" |
| 18 | #include "mdp/mdp_kms.h" |
| 19 | #include "sde_hw_catalog.h" |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 20 | #include "sde_hw_mdp_ctl.h" |
| 21 | #include "sde_hw_lm.h" |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 22 | #include "sde_hw_interrupts.h" |
| 23 | |
| 24 | /* |
| 25 | * struct sde_irq_callback - IRQ callback handlers |
| 26 | * @func: intr handler |
| 27 | * @arg: argument for the handler |
| 28 | */ |
| 29 | struct sde_irq_callback { |
| 30 | void (*func)(void *arg, int irq_idx); |
| 31 | void *arg; |
| 32 | }; |
| 33 | |
| 34 | /** |
| 35 | * struct sde_irq: IRQ structure contains callback registration info |
| 36 | * @total_irq: total number of irq_idx obtained from HW interrupts mapping |
| 37 | * @irq_cb_tbl: array of IRQ callbacks setting |
| 38 | * @cb_lock: callback lock |
| 39 | */ |
| 40 | struct sde_irq { |
| 41 | u32 total_irqs; |
| 42 | struct sde_irq_callback *irq_cb_tbl; |
| 43 | spinlock_t cb_lock; |
| 44 | }; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 45 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 46 | /** |
| 47 | * struct sde_hw_res_map : Default resource table identifying default |
| 48 | * hw resource map. Primarily used for forcing DSI to use CTL_0/1 |
| 49 | * and Pingpong 0/1, if the field is set to SDE_NONE means any HW |
| 50 | * intstance for that tpye is allowed as long as it is unused. |
| 51 | */ |
| 52 | struct sde_hw_res_map { |
| 53 | enum sde_intf intf; |
| 54 | enum sde_lm lm; |
| 55 | enum sde_pingpong pp; |
| 56 | enum sde_ctl ctl; |
| 57 | }; |
| 58 | |
| 59 | /* struct sde_hw_resource_manager : Resource mananger maintains the current |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 60 | * default platform config and manages shared |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 61 | * hw resources ex:ctl_path hw driver context |
| 62 | * is needed by CRTCs/PLANEs/ENCODERs |
| 63 | * @ctl : table of control path hw driver contexts allocated |
| 64 | * @mixer : list of mixer hw drivers contexts allocated |
| 65 | * @intr : pointer to hw interrupt context |
| 66 | * @res_table : pointer to default hw_res table for this platform |
| 67 | * @feature_map :BIT map for default enabled features ex:specifies if PP_SPLIT |
| 68 | * is enabled/disabled by defalt for this platform |
| 69 | */ |
| 70 | struct sde_hw_resource_manager { |
| 71 | struct sde_hw_ctl *ctl[CTL_MAX]; |
| 72 | struct sde_hw_mixer *mixer[LM_MAX]; |
| 73 | struct sde_hw_intr *intr; |
| 74 | const struct sde_hw_res_map *res_table; |
| 75 | bool feature_map; |
| 76 | }; |
| 77 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 78 | struct sde_kms { |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 79 | struct msm_kms base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 80 | struct drm_device *dev; |
| 81 | int rev; |
| 82 | struct sde_mdss_cfg *catalog; |
| 83 | |
| 84 | struct msm_mmu *mmu; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 85 | int mmu_id; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 86 | |
| 87 | /* io/register spaces: */ |
| 88 | void __iomem *mmio, *vbif; |
| 89 | |
| 90 | struct regulator *vdd; |
| 91 | struct regulator *mmagic; |
| 92 | struct regulator *venus; |
| 93 | |
| 94 | struct clk *axi_clk; |
| 95 | struct clk *ahb_clk; |
| 96 | struct clk *src_clk; |
| 97 | struct clk *core_clk; |
| 98 | struct clk *lut_clk; |
| 99 | struct clk *mmagic_clk; |
| 100 | struct clk *iommu_clk; |
| 101 | struct clk *vsync_clk; |
| 102 | |
| 103 | struct { |
| 104 | unsigned long enabled_mask; |
| 105 | struct irq_domain *domain; |
| 106 | } irqcontroller; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 107 | |
| 108 | struct sde_hw_intr *hw_intr; |
| 109 | struct sde_irq irq_obj; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 110 | struct sde_hw_resource_manager hw_res; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct vsync_info { |
| 114 | u32 frame_count; |
| 115 | u32 line_count; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #define to_sde_kms(x) container_of(x, struct sde_kms, base) |
| 119 | |
| 120 | struct sde_plane_state { |
| 121 | struct drm_plane_state base; |
| 122 | |
| 123 | /* aligned with property */ |
Clarence Ip | e78efb7 | 2016-06-24 18:35:21 -0400 | [diff] [blame^] | 124 | uint64_t property_values[PLANE_PROP_COUNT]; |
| 125 | |
| 126 | /* blob properties */ |
| 127 | struct drm_property_blob *property_blobs[PLANE_PROP_BLOBCOUNT]; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 128 | |
| 129 | /* assigned by crtc blender */ |
| 130 | enum sde_stage stage; |
| 131 | |
| 132 | /* some additional transactional status to help us know in the |
| 133 | * apply path whether we need to update SMP allocation, and |
| 134 | * whether current update is still pending: |
| 135 | */ |
| 136 | bool mode_changed : 1; |
| 137 | bool pending : 1; |
| 138 | }; |
| 139 | |
| 140 | #define to_sde_plane_state(x) \ |
| 141 | container_of(x, struct sde_plane_state, base) |
| 142 | |
| 143 | int sde_disable(struct sde_kms *sde_kms); |
| 144 | int sde_enable(struct sde_kms *sde_kms); |
| 145 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 146 | /** |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 147 | * HW resource manager functions |
| 148 | * @sde_rm_acquire_ctl_path : Allocates control path |
| 149 | * @sde_rm_get_ctl_path : returns control path driver context for already |
| 150 | * acquired ctl path |
| 151 | * @sde_rm_release_ctl_path : Frees control path driver context |
| 152 | * @sde_rm_acquire_mixer : Allocates mixer hw driver context |
| 153 | * @sde_rm_get_mixer : returns mixer context for already |
| 154 | * acquired mixer |
| 155 | * @sde_rm_release_mixer : Frees mixer hw driver context |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 156 | * @sde_rm_acquire_intr : Allocate hw intr context |
| 157 | * @sde_rm_get_intr : Returns already acquired intr context |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 158 | * @sde_rm_get_hw_res_map : Returns map for the passed INTF |
| 159 | */ |
| 160 | struct sde_hw_ctl *sde_rm_acquire_ctl_path(struct sde_kms *sde_kms, |
| 161 | enum sde_ctl idx); |
| 162 | struct sde_hw_ctl *sde_rm_get_ctl_path(struct sde_kms *sde_kms, |
| 163 | enum sde_ctl idx); |
| 164 | void sde_rm_release_ctl_path(struct sde_kms *sde_kms, |
| 165 | enum sde_ctl idx); |
| 166 | struct sde_hw_mixer *sde_rm_acquire_mixer(struct sde_kms *sde_kms, |
| 167 | enum sde_lm idx); |
| 168 | struct sde_hw_mixer *sde_rm_get_mixer(struct sde_kms *sde_kms, |
| 169 | enum sde_lm idx); |
| 170 | void sde_rm_release_mixer(struct sde_kms *sde_kms, |
| 171 | enum sde_lm idx); |
| 172 | struct sde_hw_intr *sde_rm_acquire_intr(struct sde_kms *sde_kms); |
| 173 | struct sde_hw_intr *sde_rm_get_intr(struct sde_kms *sde_kms); |
| 174 | |
| 175 | const struct sde_hw_res_map *sde_rm_get_res_map(struct sde_kms *sde_kms, |
| 176 | enum sde_intf idx); |
| 177 | |
| 178 | /** |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 179 | * IRQ functions |
| 180 | */ |
| 181 | int sde_irq_domain_init(struct sde_kms *sde_kms); |
| 182 | int sde_irq_domain_fini(struct sde_kms *sde_kms); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 183 | void sde_irq_preinstall(struct msm_kms *kms); |
| 184 | int sde_irq_postinstall(struct msm_kms *kms); |
| 185 | void sde_irq_uninstall(struct msm_kms *kms); |
| 186 | irqreturn_t sde_irq(struct msm_kms *kms); |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * sde_set_irqmask - IRQ helper function for writing IRQ mask |
| 190 | * to SDE HW interrupt register. |
| 191 | * @sde_kms: SDE handle |
| 192 | * @reg_off: SDE HW interrupt register offset |
| 193 | * @irqmask: IRQ mask |
| 194 | */ |
| 195 | void sde_set_irqmask( |
| 196 | struct sde_kms *sde_kms, |
| 197 | uint32_t reg_off, |
| 198 | uint32_t irqmask); |
| 199 | |
| 200 | /** |
| 201 | * sde_irq_idx_lookup - IRQ helper function for lookup irq_idx from HW |
| 202 | * interrupt mapping table. |
| 203 | * @sde_kms: SDE handle |
| 204 | * @intr_type: SDE HW interrupt type for lookup |
| 205 | * @instance_idx: SDE HW block instance defined in sde_hw_mdss.h |
| 206 | * @return: irq_idx or -EINVAL when fail to lookup |
| 207 | */ |
| 208 | int sde_irq_idx_lookup( |
| 209 | struct sde_kms *sde_kms, |
| 210 | enum sde_intr_type intr_type, |
| 211 | uint32_t instance_idx); |
| 212 | |
| 213 | /** |
| 214 | * sde_enable_irq - IRQ helper function for enabling one or more IRQs |
| 215 | * @sde_kms: SDE handle |
| 216 | * @irq_idxs: Array of irq index |
| 217 | * @irq_count: Number of irq_idx provided in the array |
| 218 | * @return: 0 for success enabling IRQ, otherwise failure |
| 219 | */ |
| 220 | int sde_enable_irq( |
| 221 | struct sde_kms *sde_kms, |
| 222 | int *irq_idxs, |
| 223 | uint32_t irq_count); |
| 224 | |
| 225 | /** |
| 226 | * sde_disable_irq - IRQ helper function for diabling one of more IRQs |
| 227 | * @sde_kms: SDE handle |
| 228 | * @irq_idxs: Array of irq index |
| 229 | * @irq_count: Number of irq_idx provided in the array |
| 230 | * @return: 0 for success disabling IRQ, otherwise failure |
| 231 | */ |
| 232 | int sde_disable_irq( |
| 233 | struct sde_kms *sde_kms, |
| 234 | int *irq_idxs, |
| 235 | uint32_t irq_count); |
| 236 | |
| 237 | /** |
| 238 | * sde_register_irq_callback - For registering callback function on IRQ |
| 239 | * interrupt |
| 240 | * @sde_kms: SDE handle |
| 241 | * @irq_idx: irq index |
| 242 | * @irq_cb: IRQ callback structure, containing callback function |
| 243 | * and argument. Passing NULL for irq_cb will unregister |
| 244 | * the callback for the given irq_idx |
| 245 | * @return: 0 for success registering callback, otherwise failure |
| 246 | */ |
| 247 | int sde_register_irq_callback( |
| 248 | struct sde_kms *sde_kms, |
| 249 | int irq_idx, |
| 250 | struct sde_irq_callback *irq_cb); |
| 251 | |
| 252 | /** |
| 253 | * sde_clear_all_irqs - Clearing all SDE IRQ interrupt status |
| 254 | * @sde_kms: SDE handle |
| 255 | */ |
| 256 | void sde_clear_all_irqs(struct sde_kms *sde_kms); |
| 257 | |
| 258 | /** |
| 259 | * sde_disable_all_irqs - Diabling all SDE IRQ interrupt |
| 260 | * @sde_kms: SDE handle |
| 261 | */ |
| 262 | void sde_disable_all_irqs(struct sde_kms *sde_kms); |
| 263 | |
| 264 | /** |
| 265 | * Vblank enable/disable functions |
| 266 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 267 | int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 268 | void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); |
| 269 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 270 | /** |
| 271 | * Plane functions |
| 272 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 273 | enum sde_sspp sde_plane_pipe(struct drm_plane *plane); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 274 | struct drm_plane *sde_plane_init(struct drm_device *dev, uint32_t pipe, |
| 275 | bool private_plane); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 276 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 277 | /** |
| 278 | * CRTC functions |
| 279 | */ |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 280 | int sde_crtc_vblank(struct drm_crtc *crtc, bool en); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 281 | void sde_crtc_wait_for_commit_done(struct drm_crtc *crtc); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 282 | void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 283 | struct drm_crtc *sde_crtc_init(struct drm_device *dev, |
| 284 | struct drm_encoder *encoder, |
| 285 | struct drm_plane *plane, int id); |
| 286 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 287 | /** |
| 288 | * Encoder functions and data types |
| 289 | */ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 290 | struct sde_encoder_hw_resources { |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 291 | enum sde_intf_mode intfs[INTF_MAX]; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 292 | bool pingpongs[PINGPONG_MAX]; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 293 | bool ctls[CTL_MAX]; |
| 294 | bool pingpongsplit; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 295 | }; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 296 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 297 | void sde_encoder_get_hw_resources(struct drm_encoder *encoder, |
| 298 | struct sde_encoder_hw_resources *hw_res); |
| 299 | void sde_encoder_register_vblank_callback(struct drm_encoder *drm_enc, |
| 300 | void (*cb)(void *), void *data); |
| 301 | void sde_encoders_init(struct drm_device *dev); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 302 | void sde_encoder_get_vsync_info(struct drm_encoder *encoder, |
| 303 | struct vsync_info *vsync); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 304 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 305 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 306 | |
| 307 | #endif /* __sde_kms_H__ */ |