Jeykumar Sankaran | ce08ec9 | 2017-04-14 14:59:55 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 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_WB_H__ |
| 14 | #define __SDE_WB_H__ |
| 15 | |
| 16 | #include <linux/platform_device.h> |
| 17 | |
| 18 | #include "msm_kms.h" |
| 19 | #include "sde_kms.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 20 | #include "sde_connector.h" |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * struct sde_wb_device - Writeback device context |
| 24 | * @drm_dev: Pointer to controlling DRM device |
| 25 | * @index: Index of hardware instance from device tree |
| 26 | * @wb_idx: Writeback identifier of enum sde_wb |
| 27 | * @wb_cfg: Writeback configuration catalog |
| 28 | * @name: Name of writeback device from device tree |
| 29 | * @display_type: Display type from device tree |
| 30 | * @wb_list List of all writeback devices |
| 31 | * @wb_lock Serialization lock for writeback context structure |
| 32 | * @connector: Connector associated with writeback device |
| 33 | * @encoder: Encoder associated with writeback device |
Jeykumar Sankaran | ce08ec9 | 2017-04-14 14:59:55 -0700 | [diff] [blame] | 34 | * @max_mixer_width: Max width supported by SDE LM HW block |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 35 | * @count_modes: Length of writeback connector modes array |
| 36 | * @modes: Writeback connector modes array |
| 37 | */ |
| 38 | struct sde_wb_device { |
| 39 | struct drm_device *drm_dev; |
| 40 | |
| 41 | u32 index; |
| 42 | u32 wb_idx; |
| 43 | struct sde_wb_cfg *wb_cfg; |
| 44 | const char *name; |
| 45 | |
| 46 | struct list_head wb_list; |
| 47 | struct mutex wb_lock; |
| 48 | |
| 49 | struct drm_connector *connector; |
| 50 | struct drm_encoder *encoder; |
| 51 | |
| 52 | enum drm_connector_status detect_status; |
Jeykumar Sankaran | ce08ec9 | 2017-04-14 14:59:55 -0700 | [diff] [blame] | 53 | u32 max_mixer_width; |
| 54 | |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 55 | u32 count_modes; |
| 56 | struct drm_mode_modeinfo *modes; |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * sde_wb_get_index - get device index of the given writeback device |
| 61 | * @wb_dev: Pointer to writeback device |
| 62 | * Returns: Index of hardware instance |
| 63 | */ |
| 64 | static inline |
| 65 | int sde_wb_get_index(struct sde_wb_device *wb_dev) |
| 66 | { |
| 67 | return wb_dev ? wb_dev->index : -1; |
| 68 | } |
| 69 | |
| 70 | #ifdef CONFIG_DRM_SDE_WB |
| 71 | /** |
| 72 | * sde_wb_get_output_fb - get framebuffer in current atomic state |
| 73 | * @wb_dev: Pointer to writeback device |
| 74 | * Returns: Pointer to framebuffer |
| 75 | */ |
| 76 | struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev); |
| 77 | |
| 78 | /** |
| 79 | * sde_wb_get_output_roi - get region-of-interest in current atomic state |
| 80 | * @wb_dev: Pointer to writeback device |
| 81 | * @roi: Pointer to region of interest |
| 82 | * Returns: 0 if success; error code otherwise |
| 83 | */ |
| 84 | int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi); |
| 85 | |
| 86 | /** |
| 87 | * sde_wb_get_num_of_displays - get total number of writeback devices |
| 88 | * Returns: Number of writeback devices |
| 89 | */ |
| 90 | u32 sde_wb_get_num_of_displays(void); |
| 91 | |
| 92 | /** |
| 93 | * wb_display_get_displays - returns pointers for supported display devices |
| 94 | * @display_array: Pointer to display array to be filled |
| 95 | * @max_display_count: Size of display_array |
| 96 | * @Returns: Number of display entries filled |
| 97 | */ |
| 98 | int wb_display_get_displays(void **display_array, u32 max_display_count); |
| 99 | |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 100 | void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active); |
| 101 | bool sde_wb_is_active(struct sde_wb_device *wb_dev); |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * sde_wb_drm_init - perform DRM initialization |
| 105 | * @wb_dev: Pointer to writeback device |
| 106 | * @encoder: Pointer to associated encoder |
| 107 | * Returns: 0 if success; error code otherwise |
| 108 | */ |
| 109 | int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder); |
| 110 | |
| 111 | /** |
| 112 | * sde_wb_drm_deinit - perform DRM de-initialization |
| 113 | * @wb_dev: Pointer to writeback device |
| 114 | * Returns: 0 if success; error code otherwise |
| 115 | */ |
| 116 | int sde_wb_drm_deinit(struct sde_wb_device *wb_dev); |
| 117 | |
| 118 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 119 | * sde_wb_config - setup connection status and available drm modes of the |
| 120 | * given writeback connector |
| 121 | * @drm_dev: Pointer to DRM device |
| 122 | * @data: Pointer to writeback configuration |
| 123 | * @file_priv: Pointer file private data |
| 124 | * Returns: 0 if success; error code otherwise |
| 125 | * |
| 126 | * This function will initiate hot-plug detection event. |
| 127 | */ |
| 128 | int sde_wb_config(struct drm_device *drm_dev, void *data, |
| 129 | struct drm_file *file_priv); |
| 130 | |
| 131 | /** |
| 132 | * sde_wb_connector_post_init - perform writeback specific initialization |
| 133 | * @connector: Pointer to drm connector structure |
| 134 | * @info: Pointer to connector info |
| 135 | * @display: Pointer to private display structure |
| 136 | * Returns: Zero on success |
| 137 | */ |
| 138 | int sde_wb_connector_post_init(struct drm_connector *connector, |
| 139 | void *info, |
| 140 | void *display); |
| 141 | |
| 142 | /** |
| 143 | * sde_wb_connector_detect - perform writeback connection status detection |
| 144 | * @connector: Pointer to connector |
| 145 | * @force: Indicate force detection |
| 146 | * @display: Pointer to writeback device |
| 147 | * Returns: connector status |
| 148 | */ |
| 149 | enum drm_connector_status |
| 150 | sde_wb_connector_detect(struct drm_connector *connector, |
| 151 | bool force, |
| 152 | void *display); |
| 153 | |
| 154 | /** |
| 155 | * sde_wb_connector_get_modes - get display modes of connector |
| 156 | * @connector: Pointer to connector |
| 157 | * @display: Pointer to writeback device |
| 158 | * Returns: Number of modes |
| 159 | * |
| 160 | * If display modes are not specified in writeback configuration IOCTL, this |
| 161 | * function will install default EDID modes up to maximum resolution support. |
| 162 | */ |
| 163 | int sde_wb_connector_get_modes(struct drm_connector *connector, void *display); |
| 164 | |
| 165 | /** |
| 166 | * sde_wb_connector_set_property - set atomic connector property |
| 167 | * @connector: Pointer to drm connector structure |
| 168 | * @state: Pointer to drm connector state structure |
| 169 | * @property_index: DRM property index |
| 170 | * @value: Incoming property value |
| 171 | * @display: Pointer to private display structure |
| 172 | * Returns: Zero on success |
| 173 | */ |
| 174 | int sde_wb_connector_set_property(struct drm_connector *connector, |
| 175 | struct drm_connector_state *state, |
| 176 | int property_index, |
| 177 | uint64_t value, |
| 178 | void *display); |
| 179 | |
| 180 | /** |
| 181 | * sde_wb_get_info - retrieve writeback 'display' information |
| 182 | * @info: Pointer to display info structure |
| 183 | * @display: Pointer to private display structure |
| 184 | * Returns: Zero on success |
| 185 | */ |
| 186 | int sde_wb_get_info(struct msm_display_info *info, void *display); |
| 187 | |
| 188 | /** |
Jeykumar Sankaran | ce08ec9 | 2017-04-14 14:59:55 -0700 | [diff] [blame] | 189 | * sde_wb_get_topology - retrieve current topology for the mode selected |
| 190 | * @drm_mode: Display mode set for the display |
| 191 | * @topology: Out parameter. Topology for the mode. |
| 192 | * @max_mixer_width: max width supported by HW layer mixer |
| 193 | * Returns: zero on success |
| 194 | */ |
| 195 | int sde_wb_get_topology(const struct drm_display_mode *drm_mode, |
| 196 | struct msm_display_topology *topology, |
| 197 | u32 max_mixer_width); |
| 198 | |
| 199 | /** |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 200 | * sde_wb_connector_get_wb - retrieve writeback device of the given connector |
| 201 | * @connector: Pointer to drm connector |
| 202 | * Returns: Pointer to writeback device on success; NULL otherwise |
| 203 | */ |
| 204 | static inline |
| 205 | struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector) |
| 206 | { |
| 207 | if (!connector || |
| 208 | (connector->connector_type != DRM_MODE_CONNECTOR_VIRTUAL)) { |
| 209 | SDE_ERROR("invalid params\n"); |
| 210 | return NULL; |
| 211 | } |
| 212 | |
| 213 | return sde_connector_get_display(connector); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * sde_wb_connector_state_get_output_fb - get framebuffer of given state |
| 218 | * @state: Pointer to connector state |
| 219 | * Returns: Pointer to framebuffer |
| 220 | */ |
| 221 | struct drm_framebuffer * |
| 222 | sde_wb_connector_state_get_output_fb(struct drm_connector_state *state); |
| 223 | |
| 224 | /** |
| 225 | * sde_wb_connector_state_get_output_roi - get roi from given atomic state |
| 226 | * @state: Pointer to atomic state |
| 227 | * @roi: Pointer to region of interest |
| 228 | * Returns: 0 if success; error code otherwise |
| 229 | */ |
| 230 | int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state, |
| 231 | struct sde_rect *roi); |
| 232 | |
| 233 | #else |
| 234 | static inline |
| 235 | struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev) |
| 236 | { |
| 237 | return NULL; |
| 238 | } |
| 239 | static inline |
| 240 | int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
| 244 | static inline |
| 245 | u32 sde_wb_get_num_of_displays(void) |
| 246 | { |
| 247 | return 0; |
| 248 | } |
| 249 | static inline |
| 250 | int wb_display_get_displays(void **display_array, u32 max_display_count) |
| 251 | { |
| 252 | return 0; |
| 253 | } |
| 254 | static inline |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 255 | void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 256 | { |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 257 | } |
| 258 | static inline |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 259 | bool sde_wb_is_active(struct sde_wb_device *wb_dev) |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 260 | { |
Clarence Ip | 3649f8b | 2016-10-31 09:59:44 -0400 | [diff] [blame] | 261 | return false; |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 262 | } |
| 263 | static inline |
| 264 | int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder) |
| 265 | { |
| 266 | return 0; |
| 267 | } |
| 268 | static inline |
| 269 | int sde_wb_drm_deinit(struct sde_wb_device *wb_dev) |
| 270 | { |
| 271 | return 0; |
| 272 | } |
| 273 | static inline |
Alan Kwong | bb27c09 | 2016-07-20 16:41:25 -0400 | [diff] [blame] | 274 | int sde_wb_config(struct drm_device *drm_dev, void *data, |
| 275 | struct drm_file *file_priv) |
| 276 | { |
| 277 | return 0; |
| 278 | } |
| 279 | static inline |
| 280 | int sde_wb_connector_post_init(struct drm_connector *connector, |
| 281 | void *info, |
| 282 | void *display) |
| 283 | { |
| 284 | return 0; |
| 285 | } |
| 286 | static inline |
| 287 | enum drm_connector_status |
| 288 | sde_wb_connector_detect(struct drm_connector *connector, |
| 289 | bool force, |
| 290 | void *display) |
| 291 | { |
| 292 | return connector_status_disconnected; |
| 293 | } |
| 294 | static inline |
| 295 | int sde_wb_connector_get_modes(struct drm_connector *connector, void *display) |
| 296 | { |
| 297 | return -EINVAL; |
| 298 | } |
| 299 | static inline |
| 300 | int sde_wb_connector_set_property(struct drm_connector *connector, |
| 301 | struct drm_connector_state *state, |
| 302 | int property_index, |
| 303 | uint64_t value, |
| 304 | void *display) |
| 305 | { |
| 306 | return 0; |
| 307 | } |
| 308 | static inline |
| 309 | int sde_wb_get_info(struct msm_display_info *info, void *display) |
| 310 | { |
| 311 | return 0; |
| 312 | } |
| 313 | static inline |
| 314 | struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector) |
| 315 | { |
| 316 | return NULL; |
| 317 | } |
| 318 | |
| 319 | static inline |
| 320 | struct drm_framebuffer * |
| 321 | sde_wb_connector_state_get_output_fb(struct drm_connector_state *state) |
| 322 | { |
| 323 | return NULL; |
| 324 | } |
| 325 | |
| 326 | static inline |
| 327 | int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state, |
| 328 | struct sde_rect *roi) |
| 329 | { |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | #endif |
| 334 | #endif /* __SDE_WB_H__ */ |
| 335 | |