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