Lloyd Atkinson | ab3dd30 | 2017-02-13 10:44:55 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -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 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 14 | #include "msm_drv.h" |
Dhaval Patel | 959fdab | 2017-08-25 15:15:39 -0700 | [diff] [blame] | 15 | #include "sde_dbg.h" |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 16 | |
| 17 | #include "sde_kms.h" |
| 18 | #include "sde_connector.h" |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 19 | #include "sde_encoder.h" |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 20 | #include <linux/backlight.h> |
| 21 | #include "dsi_drm.h" |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 22 | #include "dsi_display.h" |
Veera Sundaram Sankaran | db43e28 | 2017-09-19 18:32:52 -0700 | [diff] [blame] | 23 | #include "sde_crtc.h" |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 24 | #include "sde_rm.h" |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 25 | |
| 26 | #define BL_NODE_NAME_SIZE 32 |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 27 | |
Lloyd Atkinson | 7738220 | 2017-02-01 14:59:43 -0500 | [diff] [blame] | 28 | /* Autorefresh will occur after FRAME_CNT frames. Large values are unlikely */ |
| 29 | #define AUTOREFRESH_MAX_FRAME_CNT 6 |
| 30 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 31 | #define SDE_DEBUG_CONN(c, fmt, ...) SDE_DEBUG("conn%d " fmt,\ |
| 32 | (c) ? (c)->base.base.id : -1, ##__VA_ARGS__) |
| 33 | |
| 34 | #define SDE_ERROR_CONN(c, fmt, ...) SDE_ERROR("conn%d " fmt,\ |
| 35 | (c) ? (c)->base.base.id : -1, ##__VA_ARGS__) |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 36 | static u32 dither_matrix[DITHER_MATRIX_SZ] = { |
| 37 | 15, 7, 13, 5, 3, 11, 1, 9, 12, 4, 14, 6, 0, 8, 2, 10 |
| 38 | }; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 39 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 40 | static const struct drm_prop_enum_list e_topology_name[] = { |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 41 | {SDE_RM_TOPOLOGY_NONE, "sde_none"}, |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 42 | {SDE_RM_TOPOLOGY_SINGLEPIPE, "sde_singlepipe"}, |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 43 | {SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, "sde_singlepipe_dsc"}, |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 44 | {SDE_RM_TOPOLOGY_DUALPIPE, "sde_dualpipe"}, |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 45 | {SDE_RM_TOPOLOGY_DUALPIPE_DSC, "sde_dualpipe_dsc"}, |
| 46 | {SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, "sde_dualpipemerge"}, |
| 47 | {SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, "sde_dualpipemerge_dsc"}, |
| 48 | {SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, "sde_dualpipe_dscmerge"}, |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 49 | {SDE_RM_TOPOLOGY_PPSPLIT, "sde_ppsplit"}, |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 50 | }; |
| 51 | static const struct drm_prop_enum_list e_topology_control[] = { |
| 52 | {SDE_RM_TOPCTL_RESERVE_LOCK, "reserve_lock"}, |
| 53 | {SDE_RM_TOPCTL_RESERVE_CLEAR, "reserve_clear"}, |
| 54 | {SDE_RM_TOPCTL_DSPP, "dspp"}, |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 55 | }; |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 56 | static const struct drm_prop_enum_list e_power_mode[] = { |
| 57 | {SDE_MODE_DPMS_ON, "ON"}, |
| 58 | {SDE_MODE_DPMS_LP1, "LP1"}, |
| 59 | {SDE_MODE_DPMS_LP2, "LP2"}, |
| 60 | {SDE_MODE_DPMS_OFF, "OFF"}, |
| 61 | }; |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 62 | |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 63 | static int sde_backlight_device_update_status(struct backlight_device *bd) |
| 64 | { |
| 65 | int brightness; |
| 66 | struct dsi_display *display; |
| 67 | struct sde_connector *c_conn; |
| 68 | int bl_lvl; |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 69 | struct drm_event event; |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 70 | |
| 71 | brightness = bd->props.brightness; |
| 72 | |
| 73 | if ((bd->props.power != FB_BLANK_UNBLANK) || |
| 74 | (bd->props.state & BL_CORE_FBBLANK) || |
| 75 | (bd->props.state & BL_CORE_SUSPENDED)) |
| 76 | brightness = 0; |
| 77 | |
| 78 | c_conn = bl_get_data(bd); |
| 79 | display = (struct dsi_display *) c_conn->display; |
| 80 | if (brightness > display->panel->bl_config.bl_max_level) |
| 81 | brightness = display->panel->bl_config.bl_max_level; |
| 82 | |
| 83 | /* map UI brightness into driver backlight level with rounding */ |
| 84 | bl_lvl = mult_frac(brightness, display->panel->bl_config.bl_max_level, |
| 85 | display->panel->bl_config.brightness_max_level); |
| 86 | |
| 87 | if (!bl_lvl && brightness) |
| 88 | bl_lvl = 1; |
| 89 | |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 90 | if (c_conn->ops.set_backlight) { |
| 91 | event.type = DRM_EVENT_SYS_BACKLIGHT; |
| 92 | event.length = sizeof(u32); |
Benjamin Chan | 34a92c7 | 2017-06-28 11:01:18 -0400 | [diff] [blame] | 93 | msm_mode_object_event_notify(&c_conn->base.base, |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 94 | c_conn->base.dev, &event, (u8 *)&brightness); |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 95 | c_conn->ops.set_backlight(c_conn->display, bl_lvl); |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 96 | } |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static int sde_backlight_device_get_brightness(struct backlight_device *bd) |
| 102 | { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static const struct backlight_ops sde_backlight_device_ops = { |
| 107 | .update_status = sde_backlight_device_update_status, |
| 108 | .get_brightness = sde_backlight_device_get_brightness, |
| 109 | }; |
| 110 | |
Shashank Babu Chinta Venkata | 06c428e | 2017-04-17 13:52:28 -0700 | [diff] [blame] | 111 | static int sde_backlight_setup(struct sde_connector *c_conn, |
| 112 | struct drm_device *dev) |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 113 | { |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 114 | struct backlight_properties props; |
| 115 | struct dsi_display *display; |
| 116 | struct dsi_backlight_config *bl_config; |
| 117 | static int display_count; |
| 118 | char bl_node_name[BL_NODE_NAME_SIZE]; |
| 119 | |
Shashank Babu Chinta Venkata | 06c428e | 2017-04-17 13:52:28 -0700 | [diff] [blame] | 120 | if (!c_conn || !dev || !dev->dev) { |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 121 | SDE_ERROR("invalid param\n"); |
| 122 | return -EINVAL; |
| 123 | } else if (c_conn->connector_type != DRM_MODE_CONNECTOR_DSI) { |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | memset(&props, 0, sizeof(props)); |
| 128 | props.type = BACKLIGHT_RAW; |
| 129 | props.power = FB_BLANK_UNBLANK; |
| 130 | |
| 131 | display = (struct dsi_display *) c_conn->display; |
| 132 | bl_config = &display->panel->bl_config; |
| 133 | props.max_brightness = bl_config->brightness_max_level; |
| 134 | props.brightness = bl_config->brightness_max_level; |
| 135 | snprintf(bl_node_name, BL_NODE_NAME_SIZE, "panel%u-backlight", |
| 136 | display_count); |
Dhaval Patel | 959fdab | 2017-08-25 15:15:39 -0700 | [diff] [blame] | 137 | c_conn->bl_device = backlight_device_register(bl_node_name, dev->dev, |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 138 | c_conn, &sde_backlight_device_ops, &props); |
Dhaval Patel | 959fdab | 2017-08-25 15:15:39 -0700 | [diff] [blame] | 139 | if (IS_ERR_OR_NULL(c_conn->bl_device)) { |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 140 | SDE_ERROR("Failed to register backlight: %ld\n", |
Dhaval Patel | 959fdab | 2017-08-25 15:15:39 -0700 | [diff] [blame] | 141 | PTR_ERR(c_conn->bl_device)); |
| 142 | c_conn->bl_device = NULL; |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 143 | return -ENODEV; |
| 144 | } |
| 145 | display_count++; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 150 | int sde_connector_trigger_event(void *drm_connector, |
| 151 | uint32_t event_idx, uint32_t instance_idx, |
| 152 | uint32_t data0, uint32_t data1, |
| 153 | uint32_t data2, uint32_t data3) |
| 154 | { |
| 155 | struct sde_connector *c_conn; |
| 156 | unsigned long irq_flags; |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 157 | int (*cb_func)(uint32_t event_idx, |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 158 | uint32_t instance_idx, void *usr, |
| 159 | uint32_t data0, uint32_t data1, |
| 160 | uint32_t data2, uint32_t data3); |
| 161 | void *usr; |
| 162 | int rc = 0; |
| 163 | |
| 164 | /* |
| 165 | * This function may potentially be called from an ISR context, so |
| 166 | * avoid excessive logging/etc. |
| 167 | */ |
| 168 | if (!drm_connector) |
| 169 | return -EINVAL; |
| 170 | else if (event_idx >= SDE_CONN_EVENT_COUNT) |
| 171 | return -EINVAL; |
| 172 | c_conn = to_sde_connector(drm_connector); |
| 173 | |
| 174 | spin_lock_irqsave(&c_conn->event_lock, irq_flags); |
| 175 | cb_func = c_conn->event_table[event_idx].cb_func; |
| 176 | usr = c_conn->event_table[event_idx].usr; |
| 177 | spin_unlock_irqrestore(&c_conn->event_lock, irq_flags); |
| 178 | |
| 179 | if (cb_func) |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 180 | rc = cb_func(event_idx, instance_idx, usr, |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 181 | data0, data1, data2, data3); |
| 182 | else |
| 183 | rc = -EAGAIN; |
| 184 | |
| 185 | return rc; |
| 186 | } |
| 187 | |
| 188 | int sde_connector_register_event(struct drm_connector *connector, |
| 189 | uint32_t event_idx, |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 190 | int (*cb_func)(uint32_t event_idx, |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 191 | uint32_t instance_idx, void *usr, |
| 192 | uint32_t data0, uint32_t data1, |
| 193 | uint32_t data2, uint32_t data3), |
| 194 | void *usr) |
| 195 | { |
| 196 | struct sde_connector *c_conn; |
| 197 | unsigned long irq_flags; |
| 198 | |
| 199 | if (!connector) { |
| 200 | SDE_ERROR("invalid connector\n"); |
| 201 | return -EINVAL; |
| 202 | } else if (event_idx >= SDE_CONN_EVENT_COUNT) { |
| 203 | SDE_ERROR("conn%d, invalid event %d\n", |
| 204 | connector->base.id, event_idx); |
| 205 | return -EINVAL; |
| 206 | } |
| 207 | c_conn = to_sde_connector(connector); |
| 208 | |
| 209 | spin_lock_irqsave(&c_conn->event_lock, irq_flags); |
| 210 | c_conn->event_table[event_idx].cb_func = cb_func; |
| 211 | c_conn->event_table[event_idx].usr = usr; |
| 212 | spin_unlock_irqrestore(&c_conn->event_lock, irq_flags); |
| 213 | |
| 214 | /* optionally notify display of event registration */ |
| 215 | if (c_conn->ops.enable_event && c_conn->display) |
| 216 | c_conn->ops.enable_event(connector, event_idx, |
| 217 | cb_func != NULL, c_conn->display); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | void sde_connector_unregister_event(struct drm_connector *connector, |
| 222 | uint32_t event_idx) |
| 223 | { |
| 224 | (void)sde_connector_register_event(connector, event_idx, 0, 0); |
| 225 | } |
| 226 | |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 227 | static int _sde_connector_get_default_dither_cfg_v1( |
| 228 | struct sde_connector *c_conn, void *cfg) |
| 229 | { |
| 230 | struct drm_msm_dither *dither_cfg = (struct drm_msm_dither *)cfg; |
| 231 | enum dsi_pixel_format dst_format = DSI_PIXEL_FORMAT_MAX; |
| 232 | |
| 233 | if (!c_conn || !cfg) { |
| 234 | SDE_ERROR("invalid argument(s), c_conn %pK, cfg %pK\n", |
| 235 | c_conn, cfg); |
| 236 | return -EINVAL; |
| 237 | } |
| 238 | |
| 239 | if (!c_conn->ops.get_dst_format) { |
Ping Li | e0cfec2e | 2017-07-13 15:28:15 -0700 | [diff] [blame] | 240 | SDE_DEBUG("get_dst_format is unavailable\n"); |
| 241 | return 0; |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | dst_format = c_conn->ops.get_dst_format(c_conn->display); |
| 245 | switch (dst_format) { |
| 246 | case DSI_PIXEL_FORMAT_RGB888: |
| 247 | dither_cfg->c0_bitdepth = 8; |
| 248 | dither_cfg->c1_bitdepth = 8; |
| 249 | dither_cfg->c2_bitdepth = 8; |
| 250 | dither_cfg->c3_bitdepth = 8; |
| 251 | break; |
| 252 | case DSI_PIXEL_FORMAT_RGB666: |
| 253 | case DSI_PIXEL_FORMAT_RGB666_LOOSE: |
| 254 | dither_cfg->c0_bitdepth = 6; |
| 255 | dither_cfg->c1_bitdepth = 6; |
| 256 | dither_cfg->c2_bitdepth = 6; |
| 257 | dither_cfg->c3_bitdepth = 6; |
| 258 | break; |
| 259 | default: |
| 260 | SDE_DEBUG("no default dither config for dst_format %d\n", |
| 261 | dst_format); |
| 262 | return -ENODATA; |
| 263 | } |
| 264 | |
| 265 | memcpy(&dither_cfg->matrix, dither_matrix, |
| 266 | sizeof(u32) * DITHER_MATRIX_SZ); |
| 267 | dither_cfg->temporal_en = 0; |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static void _sde_connector_install_dither_property(struct drm_device *dev, |
| 272 | struct sde_kms *sde_kms, struct sde_connector *c_conn) |
| 273 | { |
| 274 | char prop_name[DRM_PROP_NAME_LEN]; |
| 275 | struct sde_mdss_cfg *catalog = NULL; |
| 276 | struct drm_property_blob *blob_ptr; |
| 277 | void *cfg; |
| 278 | int ret = 0; |
| 279 | u32 version = 0, len = 0; |
| 280 | bool defalut_dither_needed = false; |
| 281 | |
| 282 | if (!dev || !sde_kms || !c_conn) { |
| 283 | SDE_ERROR("invld args (s), dev %pK, sde_kms %pK, c_conn %pK\n", |
| 284 | dev, sde_kms, c_conn); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | catalog = sde_kms->catalog; |
| 289 | version = SDE_COLOR_PROCESS_MAJOR( |
| 290 | catalog->pingpong[0].sblk->dither.version); |
| 291 | snprintf(prop_name, ARRAY_SIZE(prop_name), "%s%d", |
| 292 | "SDE_PP_DITHER_V", version); |
| 293 | switch (version) { |
| 294 | case 1: |
| 295 | msm_property_install_blob(&c_conn->property_info, prop_name, |
| 296 | DRM_MODE_PROP_BLOB, |
| 297 | CONNECTOR_PROP_PP_DITHER); |
| 298 | len = sizeof(struct drm_msm_dither); |
| 299 | cfg = kzalloc(len, GFP_KERNEL); |
| 300 | if (!cfg) |
| 301 | return; |
| 302 | |
| 303 | ret = _sde_connector_get_default_dither_cfg_v1(c_conn, cfg); |
| 304 | if (!ret) |
| 305 | defalut_dither_needed = true; |
| 306 | break; |
| 307 | default: |
| 308 | SDE_ERROR("unsupported dither version %d\n", version); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | if (defalut_dither_needed) { |
| 313 | blob_ptr = drm_property_create_blob(dev, len, cfg); |
| 314 | if (IS_ERR_OR_NULL(blob_ptr)) |
| 315 | goto exit; |
| 316 | c_conn->blob_dither = blob_ptr; |
| 317 | } |
| 318 | exit: |
| 319 | kfree(cfg); |
| 320 | } |
| 321 | |
| 322 | int sde_connector_get_dither_cfg(struct drm_connector *conn, |
| 323 | struct drm_connector_state *state, void **cfg, |
| 324 | size_t *len) |
| 325 | { |
| 326 | struct sde_connector *c_conn = NULL; |
| 327 | struct sde_connector_state *c_state = NULL; |
| 328 | size_t dither_sz = 0; |
| 329 | |
| 330 | if (!conn || !state || !(*cfg)) |
| 331 | return -EINVAL; |
| 332 | |
| 333 | c_conn = to_sde_connector(conn); |
| 334 | c_state = to_sde_connector_state(state); |
| 335 | |
| 336 | /* try to get user config data first */ |
| 337 | *cfg = msm_property_get_blob(&c_conn->property_info, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 338 | &c_state->property_state, |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 339 | &dither_sz, |
| 340 | CONNECTOR_PROP_PP_DITHER); |
| 341 | /* if user config data doesn't exist, use default dither blob */ |
| 342 | if (*cfg == NULL && c_conn->blob_dither) { |
| 343 | *cfg = &c_conn->blob_dither->data; |
| 344 | dither_sz = c_conn->blob_dither->length; |
| 345 | } |
| 346 | *len = dither_sz; |
| 347 | return 0; |
| 348 | } |
| 349 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 350 | int sde_connector_get_mode_info(struct drm_connector_state *conn_state, |
| 351 | struct msm_mode_info *mode_info) |
| 352 | { |
| 353 | struct sde_connector_state *sde_conn_state = NULL; |
| 354 | |
| 355 | if (!conn_state || !mode_info) { |
| 356 | SDE_ERROR("Invalid arguments\n"); |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | |
| 360 | sde_conn_state = to_sde_connector_state(conn_state); |
| 361 | memcpy(mode_info, &sde_conn_state->mode_info, |
| 362 | sizeof(sde_conn_state->mode_info)); |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 367 | static int sde_connector_handle_disp_recovery(uint32_t event_idx, |
| 368 | uint32_t instance_idx, void *usr, |
| 369 | uint32_t data0, uint32_t data1, |
| 370 | uint32_t data2, uint32_t data3) |
| 371 | { |
| 372 | struct sde_connector *c_conn = usr; |
| 373 | int rc = 0; |
| 374 | |
| 375 | if (!c_conn) |
| 376 | return -EINVAL; |
| 377 | |
| 378 | rc = sde_kms_handle_recovery(c_conn->encoder); |
| 379 | |
| 380 | return rc; |
| 381 | } |
| 382 | |
Clarence Ip | cb3afd4 | 2016-07-15 16:25:34 -0400 | [diff] [blame] | 383 | int sde_connector_get_info(struct drm_connector *connector, |
| 384 | struct msm_display_info *info) |
| 385 | { |
| 386 | struct sde_connector *c_conn; |
| 387 | |
| 388 | if (!connector || !info) { |
| 389 | SDE_ERROR("invalid argument(s), conn %pK, info %pK\n", |
| 390 | connector, info); |
| 391 | return -EINVAL; |
| 392 | } |
| 393 | |
| 394 | c_conn = to_sde_connector(connector); |
| 395 | |
| 396 | if (!c_conn->display || !c_conn->ops.get_info) { |
| 397 | SDE_ERROR("display info not supported for %pK\n", |
| 398 | c_conn->display); |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | |
| 402 | return c_conn->ops.get_info(info, c_conn->display); |
| 403 | } |
| 404 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 405 | void sde_connector_schedule_status_work(struct drm_connector *connector, |
| 406 | bool en) |
| 407 | { |
| 408 | struct sde_connector *c_conn; |
| 409 | struct msm_display_info info; |
| 410 | |
| 411 | c_conn = to_sde_connector(connector); |
| 412 | if (!c_conn) |
| 413 | return; |
| 414 | |
| 415 | sde_connector_get_info(connector, &info); |
| 416 | if (c_conn->ops.check_status && |
| 417 | (info.capabilities & MSM_DISPLAY_ESD_ENABLED)) { |
| 418 | if (en) |
| 419 | /* Schedule ESD status check */ |
| 420 | schedule_delayed_work(&c_conn->status_work, |
| 421 | msecs_to_jiffies(STATUS_CHECK_INTERVAL_MS)); |
| 422 | else |
| 423 | /* Cancel any pending ESD status check */ |
| 424 | cancel_delayed_work_sync(&c_conn->status_work); |
| 425 | } |
| 426 | } |
| 427 | |
Clarence Ip | 458a5d0 | 2017-11-27 18:15:16 -0500 | [diff] [blame] | 428 | void sde_connector_helper_bridge_disable(struct drm_connector *connector) |
| 429 | { |
| 430 | int rc; |
| 431 | |
| 432 | if (!connector) |
| 433 | return; |
| 434 | |
| 435 | /* trigger a final connector pre-kickoff for power mode updates */ |
| 436 | rc = sde_connector_pre_kickoff(connector); |
| 437 | if (rc) |
| 438 | SDE_ERROR("conn %d final pre kickoff failed %d\n", |
| 439 | connector->base.id, rc); |
| 440 | } |
| 441 | |
Clarence Ip | 380b8dc | 2017-07-27 18:16:13 -0400 | [diff] [blame] | 442 | static int _sde_connector_update_power_locked(struct sde_connector *c_conn) |
| 443 | { |
| 444 | struct drm_connector *connector; |
| 445 | void *display; |
| 446 | int (*set_power)(struct drm_connector *, int, void *); |
| 447 | int mode, rc = 0; |
| 448 | |
| 449 | if (!c_conn) |
| 450 | return -EINVAL; |
| 451 | connector = &c_conn->base; |
| 452 | |
| 453 | switch (c_conn->dpms_mode) { |
| 454 | case DRM_MODE_DPMS_ON: |
| 455 | mode = c_conn->lp_mode; |
| 456 | break; |
| 457 | case DRM_MODE_DPMS_STANDBY: |
| 458 | mode = SDE_MODE_DPMS_STANDBY; |
| 459 | break; |
| 460 | case DRM_MODE_DPMS_SUSPEND: |
| 461 | mode = SDE_MODE_DPMS_SUSPEND; |
| 462 | break; |
| 463 | case DRM_MODE_DPMS_OFF: |
| 464 | mode = SDE_MODE_DPMS_OFF; |
| 465 | break; |
| 466 | default: |
| 467 | mode = c_conn->lp_mode; |
| 468 | SDE_ERROR("conn %d dpms set to unrecognized mode %d\n", |
| 469 | connector->base.id, mode); |
| 470 | break; |
| 471 | } |
| 472 | |
| 473 | SDE_EVT32(connector->base.id, c_conn->dpms_mode, c_conn->lp_mode, mode); |
| 474 | SDE_DEBUG("conn %d - dpms %d, lp %d, panel %d\n", connector->base.id, |
| 475 | c_conn->dpms_mode, c_conn->lp_mode, mode); |
| 476 | |
| 477 | if (mode != c_conn->last_panel_power_mode && c_conn->ops.set_power) { |
| 478 | display = c_conn->display; |
| 479 | set_power = c_conn->ops.set_power; |
| 480 | |
| 481 | mutex_unlock(&c_conn->lock); |
| 482 | rc = set_power(connector, mode, display); |
| 483 | mutex_lock(&c_conn->lock); |
| 484 | } |
| 485 | c_conn->last_panel_power_mode = mode; |
| 486 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 487 | if (mode != SDE_MODE_DPMS_ON) |
| 488 | sde_connector_schedule_status_work(connector, false); |
| 489 | |
Clarence Ip | 380b8dc | 2017-07-27 18:16:13 -0400 | [diff] [blame] | 490 | return rc; |
| 491 | } |
| 492 | |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 493 | static int _sde_connector_update_bl_scale(struct sde_connector *c_conn) |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 494 | { |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 495 | struct dsi_display *dsi_display; |
| 496 | struct dsi_backlight_config *bl_config; |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 497 | int rc = 0; |
| 498 | |
| 499 | if (!c_conn) { |
| 500 | SDE_ERROR("Invalid params sde_connector null\n"); |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 504 | dsi_display = c_conn->display; |
| 505 | if (!dsi_display || !dsi_display->panel) { |
| 506 | SDE_ERROR("Invalid params(s) dsi_display %pK, panel %pK\n", |
| 507 | dsi_display, |
| 508 | ((dsi_display) ? dsi_display->panel : NULL)); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | |
| 512 | bl_config = &dsi_display->panel->bl_config; |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 513 | |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 514 | if (c_conn->bl_scale > MAX_BL_SCALE_LEVEL) |
| 515 | bl_config->bl_scale = MAX_BL_SCALE_LEVEL; |
| 516 | else |
| 517 | bl_config->bl_scale = c_conn->bl_scale; |
| 518 | |
| 519 | if (c_conn->bl_scale_ad > MAX_AD_BL_SCALE_LEVEL) |
| 520 | bl_config->bl_scale_ad = MAX_AD_BL_SCALE_LEVEL; |
| 521 | else |
| 522 | bl_config->bl_scale_ad = c_conn->bl_scale_ad; |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 523 | |
| 524 | SDE_DEBUG("bl_scale = %u, bl_scale_ad = %u, bl_level = %u\n", |
| 525 | bl_config->bl_scale, bl_config->bl_scale_ad, |
| 526 | bl_config->bl_level); |
| 527 | rc = c_conn->ops.set_backlight(dsi_display, bl_config->bl_level); |
| 528 | |
| 529 | return rc; |
| 530 | } |
| 531 | |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 532 | int sde_connector_pre_kickoff(struct drm_connector *connector) |
| 533 | { |
| 534 | struct sde_connector *c_conn; |
| 535 | struct sde_connector_state *c_state; |
| 536 | struct msm_display_kickoff_params params; |
Clarence Ip | 380b8dc | 2017-07-27 18:16:13 -0400 | [diff] [blame] | 537 | int idx, rc; |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 538 | |
| 539 | if (!connector) { |
| 540 | SDE_ERROR("invalid argument\n"); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | |
| 544 | c_conn = to_sde_connector(connector); |
| 545 | c_state = to_sde_connector_state(connector->state); |
| 546 | |
| 547 | if (!c_conn->display) { |
| 548 | SDE_ERROR("invalid argument\n"); |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | |
Clarence Ip | 380b8dc | 2017-07-27 18:16:13 -0400 | [diff] [blame] | 552 | while ((idx = msm_property_pop_dirty(&c_conn->property_info, |
| 553 | &c_state->property_state)) >= 0) { |
| 554 | switch (idx) { |
| 555 | case CONNECTOR_PROP_LP: |
| 556 | mutex_lock(&c_conn->lock); |
| 557 | c_conn->lp_mode = sde_connector_get_property( |
| 558 | connector->state, CONNECTOR_PROP_LP); |
| 559 | _sde_connector_update_power_locked(c_conn); |
| 560 | mutex_unlock(&c_conn->lock); |
| 561 | break; |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 562 | case CONNECTOR_PROP_BL_SCALE: |
| 563 | case CONNECTOR_PROP_AD_BL_SCALE: |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 564 | _sde_connector_update_bl_scale(c_conn); |
Xu Yang | 7c42a70 | 2017-10-17 10:50:17 +0800 | [diff] [blame] | 565 | break; |
Clarence Ip | 380b8dc | 2017-07-27 18:16:13 -0400 | [diff] [blame] | 566 | default: |
| 567 | /* nothing to do for most properties */ |
| 568 | break; |
| 569 | } |
| 570 | } |
| 571 | |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 572 | /* Special handling for postproc properties */ |
| 573 | if (c_conn->bl_scale_dirty) { |
| 574 | _sde_connector_update_bl_scale(c_conn); |
| 575 | c_conn->bl_scale_dirty = false; |
| 576 | } |
| 577 | |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 578 | if (!c_conn->ops.pre_kickoff) |
| 579 | return 0; |
| 580 | |
| 581 | params.rois = &c_state->rois; |
Ajay Singh Parmar | e927aa4 | 2017-11-01 00:33:20 -0700 | [diff] [blame] | 582 | params.hdr_meta = &c_state->hdr_meta; |
Lloyd Atkinson | 05d7551 | 2017-01-17 14:45:51 -0500 | [diff] [blame] | 583 | |
| 584 | SDE_EVT32_VERBOSE(connector->base.id); |
| 585 | |
| 586 | rc = c_conn->ops.pre_kickoff(connector, c_conn->display, ¶ms); |
| 587 | |
| 588 | return rc; |
| 589 | } |
| 590 | |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 591 | int sde_connector_clk_ctrl(struct drm_connector *connector, bool enable) |
Veera Sundaram Sankaran | bb2bf9a | 2017-03-29 18:56:47 -0700 | [diff] [blame] | 592 | { |
| 593 | struct sde_connector *c_conn; |
| 594 | struct dsi_display *display; |
| 595 | u32 state = enable ? DSI_CLK_ON : DSI_CLK_OFF; |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 596 | int rc = 0; |
Veera Sundaram Sankaran | bb2bf9a | 2017-03-29 18:56:47 -0700 | [diff] [blame] | 597 | |
| 598 | if (!connector) { |
| 599 | SDE_ERROR("invalid connector\n"); |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 600 | return -EINVAL; |
Veera Sundaram Sankaran | bb2bf9a | 2017-03-29 18:56:47 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | c_conn = to_sde_connector(connector); |
| 604 | display = (struct dsi_display *) c_conn->display; |
| 605 | |
| 606 | if (display && c_conn->ops.clk_ctrl) |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 607 | rc = c_conn->ops.clk_ctrl(display->mdp_clk_handle, |
Veera Sundaram Sankaran | bb2bf9a | 2017-03-29 18:56:47 -0700 | [diff] [blame] | 608 | DSI_ALL_CLKS, state); |
Alan Kwong | 1124f1f | 2017-11-10 18:14:39 -0500 | [diff] [blame] | 609 | |
| 610 | return rc; |
Veera Sundaram Sankaran | bb2bf9a | 2017-03-29 18:56:47 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 613 | static void sde_connector_destroy(struct drm_connector *connector) |
| 614 | { |
| 615 | struct sde_connector *c_conn; |
| 616 | |
| 617 | if (!connector) { |
| 618 | SDE_ERROR("invalid connector\n"); |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | c_conn = to_sde_connector(connector); |
| 623 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 624 | /* cancel if any pending esd work */ |
| 625 | sde_connector_schedule_status_work(connector, false); |
| 626 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 627 | if (c_conn->ops.put_modes) |
| 628 | c_conn->ops.put_modes(connector, c_conn->display); |
| 629 | |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 630 | if (c_conn->blob_caps) |
| 631 | drm_property_unreference_blob(c_conn->blob_caps); |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 632 | if (c_conn->blob_hdr) |
| 633 | drm_property_unreference_blob(c_conn->blob_hdr); |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 634 | if (c_conn->blob_dither) |
| 635 | drm_property_unreference_blob(c_conn->blob_dither); |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 636 | if (c_conn->blob_mode_info) |
| 637 | drm_property_unreference_blob(c_conn->blob_mode_info); |
Ajay Singh Parmar | 4dabdfc | 2017-11-09 16:54:25 -0800 | [diff] [blame] | 638 | if (c_conn->blob_ext_hdr) |
| 639 | drm_property_unreference_blob(c_conn->blob_ext_hdr); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 640 | msm_property_destroy(&c_conn->property_info); |
| 641 | |
Dhaval Patel | 959fdab | 2017-08-25 15:15:39 -0700 | [diff] [blame] | 642 | if (c_conn->bl_device) |
| 643 | backlight_device_unregister(c_conn->bl_device); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 644 | drm_connector_unregister(connector); |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 645 | mutex_destroy(&c_conn->lock); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 646 | sde_fence_deinit(&c_conn->retire_fence); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 647 | drm_connector_cleanup(connector); |
| 648 | kfree(c_conn); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * _sde_connector_destroy_fb - clean up connector state's out_fb buffer |
| 653 | * @c_conn: Pointer to sde connector structure |
| 654 | * @c_state: Pointer to sde connector state structure |
| 655 | */ |
| 656 | static void _sde_connector_destroy_fb(struct sde_connector *c_conn, |
| 657 | struct sde_connector_state *c_state) |
| 658 | { |
| 659 | if (!c_state || !c_state->out_fb) { |
| 660 | SDE_ERROR("invalid state %pK\n", c_state); |
| 661 | return; |
| 662 | } |
| 663 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 664 | drm_framebuffer_unreference(c_state->out_fb); |
| 665 | c_state->out_fb = NULL; |
| 666 | |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 667 | if (c_conn) |
| 668 | c_state->property_values[CONNECTOR_PROP_OUT_FB].value = |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 669 | msm_property_get_default(&c_conn->property_info, |
| 670 | CONNECTOR_PROP_OUT_FB); |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 671 | else |
| 672 | c_state->property_values[CONNECTOR_PROP_OUT_FB].value = ~0; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void sde_connector_atomic_destroy_state(struct drm_connector *connector, |
| 676 | struct drm_connector_state *state) |
| 677 | { |
| 678 | struct sde_connector *c_conn = NULL; |
| 679 | struct sde_connector_state *c_state = NULL; |
| 680 | |
| 681 | if (!state) { |
| 682 | SDE_ERROR("invalid state\n"); |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * The base DRM framework currently always passes in a NULL |
| 688 | * connector pointer. This is not correct, but attempt to |
| 689 | * handle that case as much as possible. |
| 690 | */ |
| 691 | if (connector) |
| 692 | c_conn = to_sde_connector(connector); |
| 693 | c_state = to_sde_connector_state(state); |
| 694 | |
| 695 | if (c_state->out_fb) |
| 696 | _sde_connector_destroy_fb(c_conn, c_state); |
| 697 | |
Clarence Ip | b2c4fd6 | 2017-09-21 17:28:38 -0400 | [diff] [blame] | 698 | __drm_atomic_helper_connector_destroy_state(&c_state->base); |
| 699 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 700 | if (!c_conn) { |
| 701 | kfree(c_state); |
| 702 | } else { |
| 703 | /* destroy value helper */ |
| 704 | msm_property_destroy_state(&c_conn->property_info, c_state, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 705 | &c_state->property_state); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
| 709 | static void sde_connector_atomic_reset(struct drm_connector *connector) |
| 710 | { |
| 711 | struct sde_connector *c_conn; |
| 712 | struct sde_connector_state *c_state; |
| 713 | |
| 714 | if (!connector) { |
| 715 | SDE_ERROR("invalid connector\n"); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | c_conn = to_sde_connector(connector); |
| 720 | |
Veera Sundaram Sankaran | db43e28 | 2017-09-19 18:32:52 -0700 | [diff] [blame] | 721 | if (connector->state && |
| 722 | !sde_crtc_is_reset_required(connector->state->crtc)) { |
| 723 | SDE_DEBUG_CONN(c_conn, "avoid reset for connector\n"); |
| 724 | return; |
| 725 | } |
| 726 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 727 | if (connector->state) { |
| 728 | sde_connector_atomic_destroy_state(connector, connector->state); |
| 729 | connector->state = 0; |
| 730 | } |
| 731 | |
| 732 | c_state = msm_property_alloc_state(&c_conn->property_info); |
| 733 | if (!c_state) { |
| 734 | SDE_ERROR("state alloc failed\n"); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | /* reset value helper, zero out state structure and reset properties */ |
| 739 | msm_property_reset_state(&c_conn->property_info, c_state, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 740 | &c_state->property_state, |
| 741 | c_state->property_values); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 742 | |
Clarence Ip | b2c4fd6 | 2017-09-21 17:28:38 -0400 | [diff] [blame] | 743 | __drm_atomic_helper_connector_reset(connector, &c_state->base); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static struct drm_connector_state * |
| 747 | sde_connector_atomic_duplicate_state(struct drm_connector *connector) |
| 748 | { |
| 749 | struct sde_connector *c_conn; |
| 750 | struct sde_connector_state *c_state, *c_oldstate; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 751 | |
| 752 | if (!connector || !connector->state) { |
| 753 | SDE_ERROR("invalid connector %pK\n", connector); |
| 754 | return NULL; |
| 755 | } |
| 756 | |
| 757 | c_conn = to_sde_connector(connector); |
| 758 | c_oldstate = to_sde_connector_state(connector->state); |
| 759 | c_state = msm_property_alloc_state(&c_conn->property_info); |
| 760 | if (!c_state) { |
| 761 | SDE_ERROR("state alloc failed\n"); |
| 762 | return NULL; |
| 763 | } |
| 764 | |
| 765 | /* duplicate value helper */ |
| 766 | msm_property_duplicate_state(&c_conn->property_info, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 767 | c_oldstate, c_state, |
| 768 | &c_state->property_state, c_state->property_values); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 769 | |
Clarence Ip | b2c4fd6 | 2017-09-21 17:28:38 -0400 | [diff] [blame] | 770 | __drm_atomic_helper_connector_duplicate_state(connector, |
| 771 | &c_state->base); |
| 772 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 773 | /* additional handling for drm framebuffer objects */ |
Alan Kwong | 03b8984 | 2017-08-17 16:32:45 -0400 | [diff] [blame] | 774 | if (c_state->out_fb) |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 775 | drm_framebuffer_reference(c_state->out_fb); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 776 | |
| 777 | return &c_state->base; |
| 778 | } |
| 779 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 780 | int sde_connector_roi_v1_check_roi(struct drm_connector_state *conn_state) |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 781 | { |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 782 | const struct msm_roi_alignment *align = NULL; |
| 783 | struct sde_connector *c_conn = NULL; |
| 784 | struct msm_mode_info mode_info; |
| 785 | struct sde_connector_state *c_state; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 786 | int i, w, h; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 787 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 788 | if (!conn_state) |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 789 | return -EINVAL; |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 790 | |
| 791 | memset(&mode_info, 0, sizeof(mode_info)); |
| 792 | |
| 793 | c_state = to_sde_connector_state(conn_state); |
| 794 | c_conn = to_sde_connector(conn_state->connector); |
| 795 | |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 796 | memcpy(&mode_info, &c_state->mode_info, sizeof(c_state->mode_info)); |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 797 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 798 | if (!mode_info.roi_caps.enabled) |
| 799 | return 0; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 800 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 801 | if (c_state->rois.num_rects > mode_info.roi_caps.num_roi) { |
| 802 | SDE_ERROR_CONN(c_conn, "too many rects specified: %d > %d\n", |
| 803 | c_state->rois.num_rects, |
| 804 | mode_info.roi_caps.num_roi); |
| 805 | return -E2BIG; |
| 806 | }; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 807 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 808 | align = &mode_info.roi_caps.align; |
| 809 | for (i = 0; i < c_state->rois.num_rects; ++i) { |
| 810 | struct drm_clip_rect *roi_conn; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 811 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 812 | roi_conn = &c_state->rois.roi[i]; |
| 813 | w = roi_conn->x2 - roi_conn->x1; |
| 814 | h = roi_conn->y2 - roi_conn->y1; |
| 815 | |
Lloyd Atkinson | 5ca13aa | 2017-10-26 18:12:20 -0400 | [diff] [blame] | 816 | SDE_EVT32_VERBOSE(DRMID(&c_conn->base), |
| 817 | roi_conn->x1, roi_conn->y1, |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 818 | roi_conn->x2, roi_conn->y2); |
| 819 | |
| 820 | if (w <= 0 || h <= 0) { |
| 821 | SDE_ERROR_CONN(c_conn, "invalid conn roi w %d h %d\n", |
| 822 | w, h); |
| 823 | return -EINVAL; |
| 824 | } |
| 825 | |
| 826 | if (w < align->min_width || w % align->width_pix_align) { |
| 827 | SDE_ERROR_CONN(c_conn, |
| 828 | "invalid conn roi width %d min %d align %d\n", |
| 829 | w, align->min_width, |
| 830 | align->width_pix_align); |
| 831 | return -EINVAL; |
| 832 | } |
| 833 | |
| 834 | if (h < align->min_height || h % align->height_pix_align) { |
| 835 | SDE_ERROR_CONN(c_conn, |
| 836 | "invalid conn roi height %d min %d align %d\n", |
| 837 | h, align->min_height, |
| 838 | align->height_pix_align); |
| 839 | return -EINVAL; |
| 840 | } |
| 841 | |
| 842 | if (roi_conn->x1 % align->xstart_pix_align) { |
| 843 | SDE_ERROR_CONN(c_conn, |
| 844 | "invalid conn roi x1 %d align %d\n", |
| 845 | roi_conn->x1, align->xstart_pix_align); |
| 846 | return -EINVAL; |
| 847 | } |
| 848 | |
| 849 | if (roi_conn->y1 % align->ystart_pix_align) { |
| 850 | SDE_ERROR_CONN(c_conn, |
| 851 | "invalid conn roi y1 %d align %d\n", |
| 852 | roi_conn->y1, align->ystart_pix_align); |
| 853 | return -EINVAL; |
| 854 | } |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int _sde_connector_set_roi_v1( |
| 861 | struct sde_connector *c_conn, |
| 862 | struct sde_connector_state *c_state, |
| 863 | void *usr_ptr) |
| 864 | { |
| 865 | struct sde_drm_roi_v1 roi_v1; |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 866 | int i; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 867 | |
| 868 | if (!c_conn || !c_state) { |
| 869 | SDE_ERROR("invalid args\n"); |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 873 | memset(&c_state->rois, 0, sizeof(c_state->rois)); |
| 874 | |
| 875 | if (!usr_ptr) { |
| 876 | SDE_DEBUG_CONN(c_conn, "rois cleared\n"); |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | if (copy_from_user(&roi_v1, usr_ptr, sizeof(roi_v1))) { |
| 881 | SDE_ERROR_CONN(c_conn, "failed to copy roi_v1 data\n"); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | SDE_DEBUG_CONN(c_conn, "num_rects %d\n", roi_v1.num_rects); |
| 886 | |
| 887 | if (roi_v1.num_rects == 0) { |
| 888 | SDE_DEBUG_CONN(c_conn, "rois cleared\n"); |
| 889 | return 0; |
| 890 | } |
| 891 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 892 | if (roi_v1.num_rects > SDE_MAX_ROI_V1) { |
| 893 | SDE_ERROR_CONN(c_conn, "num roi rects more than supported: %d", |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 894 | roi_v1.num_rects); |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | c_state->rois.num_rects = roi_v1.num_rects; |
| 899 | for (i = 0; i < roi_v1.num_rects; ++i) { |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 900 | c_state->rois.roi[i] = roi_v1.roi[i]; |
Lloyd Atkinson | ab5e2b6 | 2017-05-09 13:06:51 -0400 | [diff] [blame] | 901 | SDE_DEBUG_CONN(c_conn, "roi%d: roi (%d,%d) (%d,%d)\n", i, |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 902 | c_state->rois.roi[i].x1, |
| 903 | c_state->rois.roi[i].y1, |
| 904 | c_state->rois.roi[i].x2, |
| 905 | c_state->rois.roi[i].y2); |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Ajay Singh Parmar | e927aa4 | 2017-11-01 00:33:20 -0700 | [diff] [blame] | 911 | static int _sde_connector_set_ext_hdr_info( |
| 912 | struct sde_connector *c_conn, |
| 913 | struct sde_connector_state *c_state, |
| 914 | void *usr_ptr) |
| 915 | { |
| 916 | struct drm_connector *connector; |
| 917 | struct drm_msm_ext_hdr_metadata *hdr_meta; |
| 918 | int i; |
| 919 | |
| 920 | if (!c_conn || !c_state) { |
| 921 | SDE_ERROR_CONN(c_conn, "invalid args\n"); |
| 922 | return -EINVAL; |
| 923 | } |
| 924 | |
| 925 | connector = &c_conn->base; |
| 926 | |
| 927 | if (!connector->hdr_supported) { |
| 928 | SDE_ERROR_CONN(c_conn, "sink doesn't support HDR\n"); |
| 929 | return -ENOTSUPP; |
| 930 | } |
| 931 | |
| 932 | memset(&c_state->hdr_meta, 0, sizeof(c_state->hdr_meta)); |
| 933 | |
| 934 | if (!usr_ptr) { |
| 935 | SDE_DEBUG_CONN(c_conn, "hdr metadata cleared\n"); |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | if (copy_from_user(&c_state->hdr_meta, |
| 940 | (void __user *)usr_ptr, |
| 941 | sizeof(*hdr_meta))) { |
| 942 | SDE_ERROR_CONN(c_conn, "failed to copy hdr metadata\n"); |
| 943 | return -EFAULT; |
| 944 | } |
| 945 | |
| 946 | hdr_meta = &c_state->hdr_meta; |
| 947 | |
| 948 | SDE_DEBUG_CONN(c_conn, "hdr_state %d\n", hdr_meta->hdr_state); |
| 949 | SDE_DEBUG_CONN(c_conn, "hdr_supported %d\n", hdr_meta->hdr_supported); |
| 950 | SDE_DEBUG_CONN(c_conn, "eotf %d\n", hdr_meta->eotf); |
| 951 | SDE_DEBUG_CONN(c_conn, "white_point_x %d\n", hdr_meta->white_point_x); |
| 952 | SDE_DEBUG_CONN(c_conn, "white_point_y %d\n", hdr_meta->white_point_y); |
| 953 | SDE_DEBUG_CONN(c_conn, "max_luminance %d\n", hdr_meta->max_luminance); |
| 954 | SDE_DEBUG_CONN(c_conn, "max_content_light_level %d\n", |
| 955 | hdr_meta->max_content_light_level); |
| 956 | SDE_DEBUG_CONN(c_conn, "max_average_light_level %d\n", |
| 957 | hdr_meta->max_average_light_level); |
| 958 | |
| 959 | for (i = 0; i < HDR_PRIMARIES_COUNT; i++) { |
| 960 | SDE_DEBUG_CONN(c_conn, "display_primaries_x [%d]\n", |
| 961 | hdr_meta->display_primaries_x[i]); |
| 962 | SDE_DEBUG_CONN(c_conn, "display_primaries_y [%d]\n", |
| 963 | hdr_meta->display_primaries_y[i]); |
| 964 | } |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 969 | static int sde_connector_atomic_set_property(struct drm_connector *connector, |
| 970 | struct drm_connector_state *state, |
| 971 | struct drm_property *property, |
| 972 | uint64_t val) |
| 973 | { |
| 974 | struct sde_connector *c_conn; |
| 975 | struct sde_connector_state *c_state; |
| 976 | int idx, rc; |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 977 | uint64_t fence_fd; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 978 | |
| 979 | if (!connector || !state || !property) { |
| 980 | SDE_ERROR("invalid argument(s), conn %pK, state %pK, prp %pK\n", |
| 981 | connector, state, property); |
| 982 | return -EINVAL; |
| 983 | } |
| 984 | |
| 985 | c_conn = to_sde_connector(connector); |
| 986 | c_state = to_sde_connector_state(state); |
| 987 | |
| 988 | /* generic property handling */ |
| 989 | rc = msm_property_atomic_set(&c_conn->property_info, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 990 | &c_state->property_state, property, val); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 991 | if (rc) |
| 992 | goto end; |
| 993 | |
| 994 | /* connector-specific property handling */ |
| 995 | idx = msm_property_index(&c_conn->property_info, property); |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 996 | switch (idx) { |
| 997 | case CONNECTOR_PROP_OUT_FB: |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 998 | /* clear old fb, if present */ |
| 999 | if (c_state->out_fb) |
| 1000 | _sde_connector_destroy_fb(c_conn, c_state); |
| 1001 | |
| 1002 | /* convert fb val to drm framebuffer and prepare it */ |
| 1003 | c_state->out_fb = |
| 1004 | drm_framebuffer_lookup(connector->dev, val); |
Alan Kwong | ae1b114 | 2017-03-05 16:07:10 -0800 | [diff] [blame] | 1005 | if (!c_state->out_fb && val) { |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1006 | SDE_ERROR("failed to look up fb %lld\n", val); |
| 1007 | rc = -EFAULT; |
Alan Kwong | ae1b114 | 2017-03-05 16:07:10 -0800 | [diff] [blame] | 1008 | } else if (!c_state->out_fb && !val) { |
| 1009 | SDE_DEBUG("cleared fb_id\n"); |
| 1010 | rc = 0; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1011 | } else { |
Alan Kwong | 578cdaf | 2017-01-28 17:25:43 -0800 | [diff] [blame] | 1012 | msm_framebuffer_set_kmap(c_state->out_fb, |
| 1013 | c_conn->fb_kmap); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1014 | } |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1015 | break; |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1016 | case CONNECTOR_PROP_RETIRE_FENCE: |
Dhaval Patel | adbac6f | 2017-11-16 17:16:18 -0800 | [diff] [blame] | 1017 | if (!val) |
| 1018 | goto end; |
| 1019 | |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1020 | rc = sde_fence_create(&c_conn->retire_fence, &fence_fd, 0); |
| 1021 | if (rc) { |
| 1022 | SDE_ERROR("fence create failed rc:%d\n", rc); |
| 1023 | goto end; |
| 1024 | } |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 1025 | |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1026 | rc = copy_to_user((uint64_t __user *)val, &fence_fd, |
| 1027 | sizeof(uint64_t)); |
| 1028 | if (rc) { |
| 1029 | SDE_ERROR("copy to user failed rc:%d\n", rc); |
| 1030 | /* fence will be released with timeline update */ |
| 1031 | put_unused_fd(fence_fd); |
| 1032 | rc = -EFAULT; |
| 1033 | goto end; |
| 1034 | } |
| 1035 | break; |
| 1036 | case CONNECTOR_PROP_ROI_V1: |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1037 | rc = _sde_connector_set_roi_v1(c_conn, c_state, (void *)val); |
| 1038 | if (rc) |
| 1039 | SDE_ERROR_CONN(c_conn, "invalid roi_v1, rc: %d\n", rc); |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1040 | break; |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 1041 | /* CONNECTOR_PROP_BL_SCALE and CONNECTOR_PROP_AD_BL_SCALE are |
| 1042 | * color-processing properties. These two properties require |
| 1043 | * special handling since they don't quite fit the current standard |
| 1044 | * atomic set property framework. |
| 1045 | */ |
| 1046 | case CONNECTOR_PROP_BL_SCALE: |
| 1047 | c_conn->bl_scale = val; |
| 1048 | c_conn->bl_scale_dirty = true; |
| 1049 | break; |
| 1050 | case CONNECTOR_PROP_AD_BL_SCALE: |
| 1051 | c_conn->bl_scale_ad = val; |
| 1052 | c_conn->bl_scale_dirty = true; |
| 1053 | break; |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1054 | default: |
| 1055 | break; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
Ajay Singh Parmar | e927aa4 | 2017-11-01 00:33:20 -0700 | [diff] [blame] | 1058 | if (idx == CONNECTOR_PROP_HDR_METADATA) { |
| 1059 | rc = _sde_connector_set_ext_hdr_info(c_conn, |
| 1060 | c_state, (void *)val); |
| 1061 | if (rc) |
| 1062 | SDE_ERROR_CONN(c_conn, "cannot set hdr info %d\n", rc); |
| 1063 | } |
| 1064 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1065 | /* check for custom property handling */ |
| 1066 | if (!rc && c_conn->ops.set_property) { |
| 1067 | rc = c_conn->ops.set_property(connector, |
| 1068 | state, |
| 1069 | idx, |
| 1070 | val, |
| 1071 | c_conn->display); |
| 1072 | |
| 1073 | /* potentially clean up out_fb if rc != 0 */ |
| 1074 | if ((idx == CONNECTOR_PROP_OUT_FB) && rc) |
| 1075 | _sde_connector_destroy_fb(c_conn, c_state); |
| 1076 | } |
| 1077 | end: |
| 1078 | return rc; |
| 1079 | } |
| 1080 | |
| 1081 | static int sde_connector_set_property(struct drm_connector *connector, |
| 1082 | struct drm_property *property, |
| 1083 | uint64_t val) |
| 1084 | { |
| 1085 | if (!connector) { |
| 1086 | SDE_ERROR("invalid connector\n"); |
| 1087 | return -EINVAL; |
| 1088 | } |
| 1089 | |
| 1090 | return sde_connector_atomic_set_property(connector, |
| 1091 | connector->state, property, val); |
| 1092 | } |
| 1093 | |
| 1094 | static int sde_connector_atomic_get_property(struct drm_connector *connector, |
| 1095 | const struct drm_connector_state *state, |
| 1096 | struct drm_property *property, |
| 1097 | uint64_t *val) |
| 1098 | { |
| 1099 | struct sde_connector *c_conn; |
| 1100 | struct sde_connector_state *c_state; |
| 1101 | int idx, rc = -EINVAL; |
| 1102 | |
| 1103 | if (!connector || !state) { |
| 1104 | SDE_ERROR("invalid argument(s), conn %pK, state %pK\n", |
| 1105 | connector, state); |
| 1106 | return -EINVAL; |
| 1107 | } |
| 1108 | |
| 1109 | c_conn = to_sde_connector(connector); |
| 1110 | c_state = to_sde_connector_state(state); |
| 1111 | |
| 1112 | idx = msm_property_index(&c_conn->property_info, property); |
Dhaval Patel | 1f5a5a2 | 2017-11-06 23:06:09 -0800 | [diff] [blame] | 1113 | if (idx == CONNECTOR_PROP_RETIRE_FENCE) { |
| 1114 | *val = ~0; |
| 1115 | rc = 0; |
| 1116 | } else { |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1117 | /* get cached property value */ |
| 1118 | rc = msm_property_atomic_get(&c_conn->property_info, |
Clarence Ip | 4a2955d | 2017-07-04 18:04:33 -0400 | [diff] [blame] | 1119 | &c_state->property_state, property, val); |
Dhaval Patel | 1f5a5a2 | 2017-11-06 23:06:09 -0800 | [diff] [blame] | 1120 | } |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1121 | |
| 1122 | /* allow for custom override */ |
| 1123 | if (c_conn->ops.get_property) |
| 1124 | rc = c_conn->ops.get_property(connector, |
| 1125 | (struct drm_connector_state *)state, |
| 1126 | idx, |
| 1127 | val, |
| 1128 | c_conn->display); |
| 1129 | return rc; |
| 1130 | } |
| 1131 | |
Dhaval Patel | 2a3c37a | 2017-10-25 12:30:36 -0700 | [diff] [blame] | 1132 | void sde_conn_timeline_status(struct drm_connector *conn) |
| 1133 | { |
| 1134 | struct sde_connector *c_conn; |
| 1135 | |
| 1136 | if (!conn) { |
| 1137 | SDE_ERROR("invalid connector\n"); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | c_conn = to_sde_connector(conn); |
| 1142 | sde_fence_timeline_status(&c_conn->retire_fence, &conn->base); |
| 1143 | } |
| 1144 | |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1145 | void sde_connector_prepare_fence(struct drm_connector *connector) |
| 1146 | { |
| 1147 | if (!connector) { |
| 1148 | SDE_ERROR("invalid connector\n"); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | sde_fence_prepare(&to_sde_connector(connector)->retire_fence); |
| 1153 | } |
| 1154 | |
Veera Sundaram Sankaran | 675ff62 | 2017-06-21 21:44:46 -0700 | [diff] [blame] | 1155 | void sde_connector_complete_commit(struct drm_connector *connector, |
| 1156 | ktime_t ts) |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1157 | { |
| 1158 | if (!connector) { |
| 1159 | SDE_ERROR("invalid connector\n"); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | /* signal connector's retire fence */ |
Dhaval Patel | fd8f774 | 2017-08-10 13:11:22 -0700 | [diff] [blame] | 1164 | sde_fence_signal(&to_sde_connector(connector)->retire_fence, ts, false); |
| 1165 | } |
| 1166 | |
| 1167 | void sde_connector_commit_reset(struct drm_connector *connector, ktime_t ts) |
| 1168 | { |
| 1169 | if (!connector) { |
| 1170 | SDE_ERROR("invalid connector\n"); |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | /* signal connector's retire fence */ |
| 1175 | sde_fence_signal(&to_sde_connector(connector)->retire_fence, ts, true); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Srikanth Rajagopalan | 30384d1 | 2017-06-08 15:23:31 -0700 | [diff] [blame] | 1178 | static void sde_connector_update_hdr_props(struct drm_connector *connector) |
| 1179 | { |
| 1180 | struct sde_connector *c_conn = to_sde_connector(connector); |
| 1181 | struct drm_msm_ext_hdr_properties hdr = {}; |
| 1182 | |
| 1183 | hdr.hdr_supported = connector->hdr_supported; |
| 1184 | |
| 1185 | if (hdr.hdr_supported) { |
| 1186 | hdr.hdr_eotf = connector->hdr_eotf; |
| 1187 | hdr.hdr_metadata_type_one = connector->hdr_metadata_type_one; |
| 1188 | hdr.hdr_max_luminance = connector->hdr_max_luminance; |
| 1189 | hdr.hdr_avg_luminance = connector->hdr_avg_luminance; |
| 1190 | hdr.hdr_min_luminance = connector->hdr_min_luminance; |
| 1191 | |
| 1192 | msm_property_set_blob(&c_conn->property_info, |
| 1193 | &c_conn->blob_ext_hdr, |
| 1194 | &hdr, |
| 1195 | sizeof(hdr), |
| 1196 | CONNECTOR_PROP_EXT_HDR_INFO); |
| 1197 | |
| 1198 | } |
| 1199 | } |
| 1200 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1201 | static enum drm_connector_status |
| 1202 | sde_connector_detect(struct drm_connector *connector, bool force) |
| 1203 | { |
| 1204 | enum drm_connector_status status = connector_status_unknown; |
| 1205 | struct sde_connector *c_conn; |
| 1206 | |
| 1207 | if (!connector) { |
| 1208 | SDE_ERROR("invalid connector\n"); |
| 1209 | return status; |
| 1210 | } |
| 1211 | |
| 1212 | c_conn = to_sde_connector(connector); |
| 1213 | |
| 1214 | if (c_conn->ops.detect) |
| 1215 | status = c_conn->ops.detect(connector, |
| 1216 | force, |
| 1217 | c_conn->display); |
| 1218 | |
| 1219 | return status; |
| 1220 | } |
| 1221 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1222 | static int sde_connector_dpms(struct drm_connector *connector, |
| 1223 | int mode) |
| 1224 | { |
| 1225 | struct sde_connector *c_conn; |
| 1226 | |
| 1227 | if (!connector) { |
| 1228 | SDE_ERROR("invalid connector\n"); |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | c_conn = to_sde_connector(connector); |
| 1232 | |
| 1233 | /* validate incoming dpms request */ |
| 1234 | switch (mode) { |
| 1235 | case DRM_MODE_DPMS_ON: |
| 1236 | case DRM_MODE_DPMS_STANDBY: |
| 1237 | case DRM_MODE_DPMS_SUSPEND: |
| 1238 | case DRM_MODE_DPMS_OFF: |
| 1239 | SDE_DEBUG("conn %d dpms set to %d\n", connector->base.id, mode); |
| 1240 | break; |
| 1241 | default: |
| 1242 | SDE_ERROR("conn %d dpms set to unrecognized mode %d\n", |
| 1243 | connector->base.id, mode); |
| 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | mutex_lock(&c_conn->lock); |
| 1248 | c_conn->dpms_mode = mode; |
| 1249 | _sde_connector_update_power_locked(c_conn); |
| 1250 | mutex_unlock(&c_conn->lock); |
| 1251 | |
| 1252 | /* use helper for boilerplate handling */ |
| 1253 | return drm_atomic_helper_connector_dpms(connector, mode); |
| 1254 | } |
| 1255 | |
| 1256 | int sde_connector_get_dpms(struct drm_connector *connector) |
| 1257 | { |
| 1258 | struct sde_connector *c_conn; |
| 1259 | int rc; |
| 1260 | |
| 1261 | if (!connector) { |
| 1262 | SDE_DEBUG("invalid connector\n"); |
| 1263 | return DRM_MODE_DPMS_OFF; |
| 1264 | } |
| 1265 | |
| 1266 | c_conn = to_sde_connector(connector); |
| 1267 | |
| 1268 | mutex_lock(&c_conn->lock); |
| 1269 | rc = c_conn->dpms_mode; |
| 1270 | mutex_unlock(&c_conn->lock); |
| 1271 | |
| 1272 | return rc; |
| 1273 | } |
| 1274 | |
Clarence Ip | d86f6e4 | 2017-08-08 18:31:00 -0400 | [diff] [blame] | 1275 | int sde_connector_set_property_for_commit(struct drm_connector *connector, |
| 1276 | struct drm_atomic_state *atomic_state, |
| 1277 | uint32_t property_idx, uint64_t value) |
| 1278 | { |
| 1279 | struct drm_connector_state *state; |
| 1280 | struct drm_property *property; |
| 1281 | struct sde_connector *c_conn; |
| 1282 | |
| 1283 | if (!connector || !atomic_state) { |
| 1284 | SDE_ERROR("invalid argument(s), conn %d, state %d\n", |
| 1285 | connector != NULL, atomic_state != NULL); |
| 1286 | return -EINVAL; |
| 1287 | } |
| 1288 | |
| 1289 | c_conn = to_sde_connector(connector); |
| 1290 | property = msm_property_index_to_drm_property( |
| 1291 | &c_conn->property_info, property_idx); |
| 1292 | if (!property) { |
| 1293 | SDE_ERROR("invalid property index %d\n", property_idx); |
| 1294 | return -EINVAL; |
| 1295 | } |
| 1296 | |
| 1297 | state = drm_atomic_get_connector_state(atomic_state, connector); |
| 1298 | if (IS_ERR_OR_NULL(state)) { |
| 1299 | SDE_ERROR("failed to get conn %d state\n", |
| 1300 | connector->base.id); |
| 1301 | return -EINVAL; |
| 1302 | } |
| 1303 | |
| 1304 | return drm_atomic_connector_set_property( |
| 1305 | connector, state, property, value); |
| 1306 | } |
| 1307 | |
Lloyd Atkinson | e08229c | 2017-10-02 17:53:30 -0400 | [diff] [blame] | 1308 | int sde_connector_helper_reset_custom_properties( |
| 1309 | struct drm_connector *connector, |
| 1310 | struct drm_connector_state *connector_state) |
| 1311 | { |
| 1312 | struct sde_connector *c_conn; |
| 1313 | struct sde_connector_state *c_state; |
| 1314 | struct drm_property *drm_prop; |
| 1315 | enum msm_mdp_conn_property prop_idx; |
| 1316 | |
| 1317 | if (!connector || !connector_state) { |
| 1318 | SDE_ERROR("invalid params\n"); |
| 1319 | return -EINVAL; |
| 1320 | } |
| 1321 | |
| 1322 | c_conn = to_sde_connector(connector); |
| 1323 | c_state = to_sde_connector_state(connector_state); |
| 1324 | |
| 1325 | for (prop_idx = 0; prop_idx < CONNECTOR_PROP_COUNT; prop_idx++) { |
| 1326 | uint64_t val = c_state->property_values[prop_idx].value; |
| 1327 | uint64_t def; |
| 1328 | int ret; |
| 1329 | |
| 1330 | drm_prop = msm_property_index_to_drm_property( |
| 1331 | &c_conn->property_info, prop_idx); |
| 1332 | if (!drm_prop) { |
| 1333 | /* not all props will be installed, based on caps */ |
| 1334 | SDE_DEBUG_CONN(c_conn, "invalid property index %d\n", |
| 1335 | prop_idx); |
| 1336 | continue; |
| 1337 | } |
| 1338 | |
| 1339 | def = msm_property_get_default(&c_conn->property_info, |
| 1340 | prop_idx); |
| 1341 | if (val == def) |
| 1342 | continue; |
| 1343 | |
| 1344 | SDE_DEBUG_CONN(c_conn, "set prop %s idx %d from %llu to %llu\n", |
| 1345 | drm_prop->name, prop_idx, val, def); |
| 1346 | |
| 1347 | ret = drm_atomic_connector_set_property(connector, |
| 1348 | connector_state, drm_prop, def); |
| 1349 | if (ret) { |
| 1350 | SDE_ERROR_CONN(c_conn, |
| 1351 | "set property failed, idx %d ret %d\n", |
| 1352 | prop_idx, ret); |
| 1353 | continue; |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
Alan Kwong | 578cdaf | 2017-01-28 17:25:43 -0800 | [diff] [blame] | 1360 | #ifdef CONFIG_DEBUG_FS |
| 1361 | /** |
| 1362 | * sde_connector_init_debugfs - initialize connector debugfs |
| 1363 | * @connector: Pointer to drm connector |
| 1364 | */ |
| 1365 | static int sde_connector_init_debugfs(struct drm_connector *connector) |
| 1366 | { |
| 1367 | struct sde_connector *sde_connector; |
Sandeep Panda | f2274d1 | 2017-09-08 19:52:33 +0530 | [diff] [blame] | 1368 | struct msm_display_info info; |
Alan Kwong | 578cdaf | 2017-01-28 17:25:43 -0800 | [diff] [blame] | 1369 | |
| 1370 | if (!connector || !connector->debugfs_entry) { |
| 1371 | SDE_ERROR("invalid connector\n"); |
| 1372 | return -EINVAL; |
| 1373 | } |
| 1374 | |
| 1375 | sde_connector = to_sde_connector(connector); |
| 1376 | |
Sandeep Panda | f2274d1 | 2017-09-08 19:52:33 +0530 | [diff] [blame] | 1377 | sde_connector_get_info(connector, &info); |
| 1378 | if (sde_connector->ops.check_status && |
| 1379 | (info.capabilities & MSM_DISPLAY_ESD_ENABLED)) |
| 1380 | debugfs_create_u32("force_panel_dead", 0600, |
| 1381 | connector->debugfs_entry, |
| 1382 | &sde_connector->force_panel_dead); |
| 1383 | |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 1384 | if (!debugfs_create_bool("fb_kmap", 0600, connector->debugfs_entry, |
Alan Kwong | 578cdaf | 2017-01-28 17:25:43 -0800 | [diff] [blame] | 1385 | &sde_connector->fb_kmap)) { |
| 1386 | SDE_ERROR("failed to create connector fb_kmap\n"); |
| 1387 | return -ENOMEM; |
| 1388 | } |
| 1389 | |
| 1390 | return 0; |
| 1391 | } |
| 1392 | #else |
| 1393 | static int sde_connector_init_debugfs(struct drm_connector *connector) |
| 1394 | { |
| 1395 | return 0; |
| 1396 | } |
| 1397 | #endif |
| 1398 | |
| 1399 | static int sde_connector_late_register(struct drm_connector *connector) |
| 1400 | { |
| 1401 | return sde_connector_init_debugfs(connector); |
| 1402 | } |
| 1403 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1404 | static void sde_connector_early_unregister(struct drm_connector *connector) |
| 1405 | { |
| 1406 | /* debugfs under connector->debugfs are deleted by drm_debugfs */ |
| 1407 | } |
| 1408 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1409 | static int sde_connector_fill_modes(struct drm_connector *connector, |
| 1410 | uint32_t max_width, uint32_t max_height) |
| 1411 | { |
| 1412 | int rc, mode_count = 0; |
| 1413 | struct sde_connector *sde_conn = NULL; |
| 1414 | |
| 1415 | sde_conn = to_sde_connector(connector); |
| 1416 | if (!sde_conn) { |
| 1417 | SDE_ERROR("invalid arguments\n"); |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | mode_count = drm_helper_probe_single_connector_modes(connector, |
| 1422 | max_width, max_height); |
| 1423 | |
| 1424 | rc = sde_connector_set_blob_data(connector, |
| 1425 | connector->state, |
| 1426 | CONNECTOR_PROP_MODE_INFO); |
| 1427 | if (rc) { |
| 1428 | SDE_ERROR_CONN(sde_conn, |
| 1429 | "failed to setup mode info prop, rc = %d\n", rc); |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
| 1433 | return mode_count; |
| 1434 | } |
| 1435 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1436 | static const struct drm_connector_funcs sde_connector_ops = { |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1437 | .dpms = sde_connector_dpms, |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1438 | .reset = sde_connector_atomic_reset, |
| 1439 | .detect = sde_connector_detect, |
| 1440 | .destroy = sde_connector_destroy, |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1441 | .fill_modes = sde_connector_fill_modes, |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1442 | .atomic_duplicate_state = sde_connector_atomic_duplicate_state, |
| 1443 | .atomic_destroy_state = sde_connector_atomic_destroy_state, |
| 1444 | .atomic_set_property = sde_connector_atomic_set_property, |
| 1445 | .atomic_get_property = sde_connector_atomic_get_property, |
| 1446 | .set_property = sde_connector_set_property, |
Alan Kwong | 578cdaf | 2017-01-28 17:25:43 -0800 | [diff] [blame] | 1447 | .late_register = sde_connector_late_register, |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 1448 | .early_unregister = sde_connector_early_unregister, |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1449 | }; |
| 1450 | |
| 1451 | static int sde_connector_get_modes(struct drm_connector *connector) |
| 1452 | { |
| 1453 | struct sde_connector *c_conn; |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1454 | int mode_count = 0; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1455 | |
| 1456 | if (!connector) { |
| 1457 | SDE_ERROR("invalid connector\n"); |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | c_conn = to_sde_connector(connector); |
| 1462 | if (!c_conn->ops.get_modes) { |
| 1463 | SDE_DEBUG("missing get_modes callback\n"); |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1467 | mode_count = c_conn->ops.get_modes(connector, c_conn->display); |
| 1468 | if (!mode_count) { |
| 1469 | SDE_ERROR_CONN(c_conn, "failed to get modes\n"); |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | sde_connector_update_hdr_props(connector); |
| 1474 | |
| 1475 | return mode_count; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static enum drm_mode_status |
| 1479 | sde_connector_mode_valid(struct drm_connector *connector, |
| 1480 | struct drm_display_mode *mode) |
| 1481 | { |
| 1482 | struct sde_connector *c_conn; |
| 1483 | |
| 1484 | if (!connector || !mode) { |
| 1485 | SDE_ERROR("invalid argument(s), conn %pK, mode %pK\n", |
| 1486 | connector, mode); |
| 1487 | return MODE_ERROR; |
| 1488 | } |
| 1489 | |
| 1490 | c_conn = to_sde_connector(connector); |
| 1491 | |
| 1492 | if (c_conn->ops.mode_valid) |
| 1493 | return c_conn->ops.mode_valid(connector, mode, c_conn->display); |
| 1494 | |
| 1495 | /* assume all modes okay by default */ |
| 1496 | return MODE_OK; |
| 1497 | } |
| 1498 | |
| 1499 | static struct drm_encoder * |
| 1500 | sde_connector_best_encoder(struct drm_connector *connector) |
| 1501 | { |
| 1502 | struct sde_connector *c_conn = to_sde_connector(connector); |
| 1503 | |
| 1504 | if (!connector) { |
| 1505 | SDE_ERROR("invalid connector\n"); |
| 1506 | return NULL; |
| 1507 | } |
| 1508 | |
| 1509 | /* |
| 1510 | * This is true for now, revisit this code when multiple encoders are |
| 1511 | * supported. |
| 1512 | */ |
| 1513 | return c_conn->encoder; |
| 1514 | } |
| 1515 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1516 | static void sde_connector_check_status_work(struct work_struct *work) |
| 1517 | { |
| 1518 | struct sde_connector *conn; |
| 1519 | struct drm_event event; |
| 1520 | int rc = 0; |
| 1521 | bool panel_dead = false; |
| 1522 | |
| 1523 | conn = container_of(to_delayed_work(work), |
| 1524 | struct sde_connector, status_work); |
| 1525 | if (!conn) { |
| 1526 | SDE_ERROR("not able to get connector object\n"); |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | mutex_lock(&conn->lock); |
| 1531 | if (!conn->ops.check_status || |
| 1532 | (conn->dpms_mode != DRM_MODE_DPMS_ON)) { |
| 1533 | SDE_DEBUG("dpms mode: %d\n", conn->dpms_mode); |
| 1534 | mutex_unlock(&conn->lock); |
| 1535 | return; |
| 1536 | } |
| 1537 | |
| 1538 | rc = conn->ops.check_status(conn->display); |
| 1539 | mutex_unlock(&conn->lock); |
Sandeep Panda | f2274d1 | 2017-09-08 19:52:33 +0530 | [diff] [blame] | 1540 | |
| 1541 | if (conn->force_panel_dead) { |
| 1542 | conn->force_panel_dead--; |
| 1543 | if (!conn->force_panel_dead) |
| 1544 | goto status_dead; |
| 1545 | } |
| 1546 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1547 | if (rc > 0) { |
| 1548 | SDE_DEBUG("esd check status success conn_id: %d enc_id: %d\n", |
| 1549 | conn->base.base.id, conn->encoder->base.id); |
| 1550 | schedule_delayed_work(&conn->status_work, |
| 1551 | msecs_to_jiffies(STATUS_CHECK_INTERVAL_MS)); |
Sandeep Panda | f2274d1 | 2017-09-08 19:52:33 +0530 | [diff] [blame] | 1552 | return; |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1553 | } |
Sandeep Panda | f2274d1 | 2017-09-08 19:52:33 +0530 | [diff] [blame] | 1554 | |
| 1555 | status_dead: |
| 1556 | SDE_EVT32(rc, SDE_EVTLOG_ERROR); |
| 1557 | SDE_ERROR("esd check failed report PANEL_DEAD conn_id: %d enc_id: %d\n", |
| 1558 | conn->base.base.id, conn->encoder->base.id); |
| 1559 | panel_dead = true; |
| 1560 | event.type = DRM_EVENT_PANEL_DEAD; |
| 1561 | event.length = sizeof(u32); |
| 1562 | msm_mode_object_event_notify(&conn->base.base, |
| 1563 | conn->base.dev, &event, (u8 *)&panel_dead); |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1564 | } |
| 1565 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1566 | static const struct drm_connector_helper_funcs sde_connector_helper_ops = { |
| 1567 | .get_modes = sde_connector_get_modes, |
| 1568 | .mode_valid = sde_connector_mode_valid, |
| 1569 | .best_encoder = sde_connector_best_encoder, |
| 1570 | }; |
| 1571 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1572 | static int sde_connector_populate_mode_info(struct drm_connector *conn, |
| 1573 | struct sde_kms_info *info) |
| 1574 | { |
| 1575 | struct msm_drm_private *priv; |
| 1576 | struct sde_kms *sde_kms; |
| 1577 | struct sde_connector *c_conn = NULL; |
| 1578 | struct drm_display_mode *mode; |
| 1579 | struct msm_mode_info mode_info; |
| 1580 | int rc = 0; |
| 1581 | |
| 1582 | if (!conn || !conn->dev || !conn->dev->dev_private) { |
| 1583 | SDE_ERROR("invalid arguments\n"); |
| 1584 | return -EINVAL; |
| 1585 | } |
| 1586 | |
| 1587 | priv = conn->dev->dev_private; |
| 1588 | sde_kms = to_sde_kms(priv->kms); |
| 1589 | |
| 1590 | c_conn = to_sde_connector(conn); |
| 1591 | if (!c_conn->ops.get_mode_info) { |
| 1592 | SDE_ERROR_CONN(c_conn, "get_mode_info not defined\n"); |
| 1593 | return -EINVAL; |
| 1594 | } |
| 1595 | |
| 1596 | list_for_each_entry(mode, &conn->modes, head) { |
| 1597 | int topology_idx = 0; |
| 1598 | |
| 1599 | memset(&mode_info, 0, sizeof(mode_info)); |
| 1600 | |
| 1601 | rc = c_conn->ops.get_mode_info(mode, &mode_info, |
| 1602 | sde_kms->catalog->max_mixer_width, |
| 1603 | c_conn->display); |
| 1604 | if (rc) { |
| 1605 | SDE_ERROR_CONN(c_conn, |
| 1606 | "failed to get mode info for mode %s\n", |
| 1607 | mode->name); |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
| 1611 | sde_kms_info_add_keystr(info, "mode_name", mode->name); |
| 1612 | |
| 1613 | topology_idx = (int)sde_rm_get_topology_name( |
| 1614 | mode_info.topology); |
| 1615 | if (topology_idx < SDE_RM_TOPOLOGY_MAX) { |
| 1616 | sde_kms_info_add_keystr(info, "topology", |
| 1617 | e_topology_name[topology_idx].name); |
| 1618 | } else { |
| 1619 | SDE_ERROR_CONN(c_conn, "invalid topology\n"); |
| 1620 | continue; |
| 1621 | } |
| 1622 | |
| 1623 | if (!mode_info.roi_caps.num_roi) |
| 1624 | continue; |
| 1625 | |
| 1626 | sde_kms_info_add_keyint(info, "partial_update_num_roi", |
| 1627 | mode_info.roi_caps.num_roi); |
| 1628 | sde_kms_info_add_keyint(info, "partial_update_xstart", |
| 1629 | mode_info.roi_caps.align.xstart_pix_align); |
| 1630 | sde_kms_info_add_keyint(info, "partial_update_walign", |
| 1631 | mode_info.roi_caps.align.width_pix_align); |
| 1632 | sde_kms_info_add_keyint(info, "partial_update_wmin", |
| 1633 | mode_info.roi_caps.align.min_width); |
| 1634 | sde_kms_info_add_keyint(info, "partial_update_ystart", |
| 1635 | mode_info.roi_caps.align.ystart_pix_align); |
| 1636 | sde_kms_info_add_keyint(info, "partial_update_halign", |
| 1637 | mode_info.roi_caps.align.height_pix_align); |
| 1638 | sde_kms_info_add_keyint(info, "partial_update_hmin", |
| 1639 | mode_info.roi_caps.align.min_height); |
| 1640 | sde_kms_info_add_keyint(info, "partial_update_roimerge", |
| 1641 | mode_info.roi_caps.merge_rois); |
| 1642 | } |
| 1643 | |
| 1644 | return rc; |
| 1645 | } |
| 1646 | |
| 1647 | int sde_connector_set_blob_data(struct drm_connector *conn, |
| 1648 | struct drm_connector_state *state, |
| 1649 | enum msm_mdp_conn_property prop_id) |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1650 | { |
| 1651 | struct sde_kms_info *info; |
| 1652 | struct sde_connector *c_conn = NULL; |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1653 | struct sde_connector_state *sde_conn_state = NULL; |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1654 | struct msm_mode_info mode_info; |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1655 | struct drm_property_blob *blob = NULL; |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1656 | int rc = 0; |
| 1657 | |
| 1658 | c_conn = to_sde_connector(conn); |
Jeykumar Sankaran | 905ba33 | 2017-10-19 10:45:02 -0700 | [diff] [blame] | 1659 | if (!c_conn) { |
| 1660 | SDE_ERROR("invalid argument\n"); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1661 | return -EINVAL; |
| 1662 | } |
| 1663 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1664 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 1665 | if (!info) |
| 1666 | return -ENOMEM; |
| 1667 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1668 | sde_kms_info_reset(info); |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1669 | |
| 1670 | switch (prop_id) { |
| 1671 | case CONNECTOR_PROP_SDE_INFO: |
| 1672 | memset(&mode_info, 0, sizeof(mode_info)); |
| 1673 | |
| 1674 | if (state) { |
| 1675 | sde_conn_state = to_sde_connector_state(state); |
| 1676 | memcpy(&mode_info, &sde_conn_state->mode_info, |
| 1677 | sizeof(sde_conn_state->mode_info)); |
| 1678 | } else { |
| 1679 | /** |
| 1680 | * connector state is assigned only on first |
| 1681 | * atomic_commit. But this function is allowed to be |
| 1682 | * invoked during probe/init sequence. So not throwing |
| 1683 | * an error. |
| 1684 | */ |
| 1685 | SDE_DEBUG_CONN(c_conn, "invalid connector state\n"); |
| 1686 | } |
| 1687 | |
Alan Kwong | 769fba9 | 2017-11-13 16:50:36 -0500 | [diff] [blame] | 1688 | if (c_conn->ops.set_info_blob) { |
| 1689 | rc = c_conn->ops.set_info_blob(conn, info, |
| 1690 | c_conn->display, &mode_info); |
| 1691 | if (rc) { |
| 1692 | SDE_ERROR_CONN(c_conn, |
| 1693 | "set_info_blob failed, %d\n", |
| 1694 | rc); |
| 1695 | goto exit; |
| 1696 | } |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | blob = c_conn->blob_caps; |
| 1700 | break; |
| 1701 | case CONNECTOR_PROP_MODE_INFO: |
| 1702 | rc = sde_connector_populate_mode_info(conn, info); |
| 1703 | if (rc) { |
| 1704 | SDE_ERROR_CONN(c_conn, |
| 1705 | "mode info population failed, %d\n", |
| 1706 | rc); |
| 1707 | goto exit; |
| 1708 | } |
| 1709 | blob = c_conn->blob_mode_info; |
| 1710 | break; |
| 1711 | default: |
| 1712 | SDE_ERROR_CONN(c_conn, "invalid prop_id: %d\n", prop_id); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1713 | goto exit; |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1714 | }; |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1715 | |
| 1716 | msm_property_set_blob(&c_conn->property_info, |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1717 | &blob, |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1718 | SDE_KMS_INFO_DATA(info), |
| 1719 | SDE_KMS_INFO_DATALEN(info), |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1720 | prop_id); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1721 | exit: |
| 1722 | kfree(info); |
| 1723 | |
| 1724 | return rc; |
| 1725 | } |
| 1726 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1727 | struct drm_connector *sde_connector_init(struct drm_device *dev, |
| 1728 | struct drm_encoder *encoder, |
| 1729 | struct drm_panel *panel, |
| 1730 | void *display, |
| 1731 | const struct sde_connector_ops *ops, |
| 1732 | int connector_poll, |
| 1733 | int connector_type) |
| 1734 | { |
| 1735 | struct msm_drm_private *priv; |
| 1736 | struct sde_kms *sde_kms; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1737 | struct sde_connector *c_conn = NULL; |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 1738 | struct dsi_display *dsi_display; |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1739 | struct msm_display_info display_info; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1740 | int rc; |
| 1741 | |
| 1742 | if (!dev || !dev->dev_private || !encoder) { |
| 1743 | SDE_ERROR("invalid argument(s), dev %pK, enc %pK\n", |
| 1744 | dev, encoder); |
| 1745 | return ERR_PTR(-EINVAL); |
| 1746 | } |
| 1747 | |
| 1748 | priv = dev->dev_private; |
| 1749 | if (!priv->kms) { |
| 1750 | SDE_ERROR("invalid kms reference\n"); |
| 1751 | return ERR_PTR(-EINVAL); |
| 1752 | } |
| 1753 | |
| 1754 | c_conn = kzalloc(sizeof(*c_conn), GFP_KERNEL); |
| 1755 | if (!c_conn) { |
| 1756 | SDE_ERROR("failed to alloc sde connector\n"); |
| 1757 | return ERR_PTR(-ENOMEM); |
| 1758 | } |
| 1759 | |
Jeykumar Sankaran | 36af6a6 | 2017-08-03 14:21:58 -0700 | [diff] [blame] | 1760 | memset(&display_info, 0, sizeof(display_info)); |
| 1761 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1762 | rc = drm_connector_init(dev, |
| 1763 | &c_conn->base, |
| 1764 | &sde_connector_ops, |
| 1765 | connector_type); |
| 1766 | if (rc) |
| 1767 | goto error_free_conn; |
| 1768 | |
Clarence Ip | a18d483 | 2017-03-13 12:35:44 -0700 | [diff] [blame] | 1769 | spin_lock_init(&c_conn->event_lock); |
| 1770 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1771 | c_conn->connector_type = connector_type; |
| 1772 | c_conn->encoder = encoder; |
| 1773 | c_conn->panel = panel; |
| 1774 | c_conn->display = display; |
| 1775 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1776 | c_conn->dpms_mode = DRM_MODE_DPMS_ON; |
| 1777 | c_conn->lp_mode = 0; |
| 1778 | c_conn->last_panel_power_mode = SDE_MODE_DPMS_ON; |
| 1779 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1780 | sde_kms = to_sde_kms(priv->kms); |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 1781 | if (sde_kms->vbif[VBIF_NRT]) { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1782 | c_conn->aspace[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 1783 | sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_UNSECURE]; |
| 1784 | c_conn->aspace[SDE_IOMMU_DOMAIN_SECURE] = |
| 1785 | sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_SECURE]; |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 1786 | } else { |
Jordan Crouse | d8e9652 | 2017-02-13 10:14:16 -0700 | [diff] [blame] | 1787 | c_conn->aspace[SDE_IOMMU_DOMAIN_UNSECURE] = |
| 1788 | sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE]; |
| 1789 | c_conn->aspace[SDE_IOMMU_DOMAIN_SECURE] = |
| 1790 | sde_kms->aspace[MSM_SMMU_DOMAIN_SECURE]; |
Alan Kwong | dfa8c08 | 2016-07-29 04:10:00 -0400 | [diff] [blame] | 1791 | } |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1792 | |
| 1793 | if (ops) |
| 1794 | c_conn->ops = *ops; |
| 1795 | |
| 1796 | c_conn->base.helper_private = &sde_connector_helper_ops; |
| 1797 | c_conn->base.polled = connector_poll; |
| 1798 | c_conn->base.interlace_allowed = 0; |
| 1799 | c_conn->base.doublescan_allowed = 0; |
| 1800 | |
| 1801 | snprintf(c_conn->name, |
| 1802 | SDE_CONNECTOR_NAME_SIZE, |
| 1803 | "conn%u", |
| 1804 | c_conn->base.base.id); |
| 1805 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1806 | rc = sde_fence_init(&c_conn->retire_fence, c_conn->name, |
| 1807 | c_conn->base.base.id); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1808 | if (rc) { |
| 1809 | SDE_ERROR("failed to init fence, %d\n", rc); |
| 1810 | goto error_cleanup_conn; |
| 1811 | } |
| 1812 | |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1813 | mutex_init(&c_conn->lock); |
| 1814 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1815 | rc = drm_mode_connector_attach_encoder(&c_conn->base, encoder); |
| 1816 | if (rc) { |
| 1817 | SDE_ERROR("failed to attach encoder to connector, %d\n", rc); |
Lloyd Atkinson | ab3dd30 | 2017-02-13 10:44:55 -0800 | [diff] [blame] | 1818 | goto error_cleanup_fence; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
Shashank Babu Chinta Venkata | 06c428e | 2017-04-17 13:52:28 -0700 | [diff] [blame] | 1821 | rc = sde_backlight_setup(c_conn, dev); |
Dhaval Patel | 7cdd666 | 2017-03-08 13:10:37 -0800 | [diff] [blame] | 1822 | if (rc) { |
| 1823 | SDE_ERROR("failed to setup backlight, rc=%d\n", rc); |
| 1824 | goto error_cleanup_fence; |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 1825 | } |
| 1826 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1827 | /* create properties */ |
| 1828 | msm_property_init(&c_conn->property_info, &c_conn->base.base, dev, |
| 1829 | priv->conn_property, c_conn->property_data, |
| 1830 | CONNECTOR_PROP_COUNT, CONNECTOR_PROP_BLOBCOUNT, |
| 1831 | sizeof(struct sde_connector_state)); |
| 1832 | |
Alan Kwong | 769fba9 | 2017-11-13 16:50:36 -0500 | [diff] [blame] | 1833 | if (c_conn->ops.post_init) { |
| 1834 | rc = c_conn->ops.post_init(&c_conn->base, display); |
| 1835 | if (rc) { |
| 1836 | SDE_ERROR("post-init failed, %d\n", rc); |
| 1837 | goto error_cleanup_fence; |
| 1838 | } |
| 1839 | } |
| 1840 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1841 | msm_property_install_blob(&c_conn->property_info, |
| 1842 | "capabilities", |
| 1843 | DRM_MODE_PROP_IMMUTABLE, |
| 1844 | CONNECTOR_PROP_SDE_INFO); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1845 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1846 | rc = sde_connector_set_blob_data(&c_conn->base, |
| 1847 | NULL, |
| 1848 | CONNECTOR_PROP_SDE_INFO); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1849 | if (rc) { |
| 1850 | SDE_ERROR_CONN(c_conn, |
| 1851 | "failed to setup connector info, rc = %d\n", rc); |
| 1852 | goto error_cleanup_fence; |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1855 | msm_property_install_blob(&c_conn->property_info, |
| 1856 | "mode_properties", |
| 1857 | DRM_MODE_PROP_IMMUTABLE, |
| 1858 | CONNECTOR_PROP_MODE_INFO); |
| 1859 | |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 1860 | if (connector_type == DRM_MODE_CONNECTOR_DSI) { |
| 1861 | dsi_display = (struct dsi_display *)(display); |
| 1862 | if (dsi_display && dsi_display->panel && |
| 1863 | dsi_display->panel->hdr_props.hdr_enabled == true) { |
| 1864 | msm_property_install_blob(&c_conn->property_info, |
| 1865 | "hdr_properties", |
| 1866 | DRM_MODE_PROP_IMMUTABLE, |
| 1867 | CONNECTOR_PROP_HDR_INFO); |
| 1868 | |
| 1869 | msm_property_set_blob(&c_conn->property_info, |
| 1870 | &c_conn->blob_hdr, |
| 1871 | &dsi_display->panel->hdr_props, |
| 1872 | sizeof(dsi_display->panel->hdr_props), |
| 1873 | CONNECTOR_PROP_HDR_INFO); |
| 1874 | } |
| 1875 | } |
| 1876 | |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1877 | rc = sde_connector_get_info(&c_conn->base, &display_info); |
| 1878 | if (!rc && (connector_type == DRM_MODE_CONNECTOR_DSI) && |
| 1879 | (display_info.capabilities & MSM_DISPLAY_CAP_VID_MODE)) |
| 1880 | sde_connector_register_event(&c_conn->base, |
| 1881 | SDE_CONN_EVENT_VID_FIFO_OVERFLOW, |
| 1882 | sde_connector_handle_disp_recovery, |
| 1883 | c_conn); |
| 1884 | |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1885 | msm_property_install_volatile_range( |
Sandeep Panda | 11b20d8 | 2017-06-19 12:57:27 +0530 | [diff] [blame] | 1886 | &c_conn->property_info, "sde_drm_roi_v1", 0x0, |
| 1887 | 0, ~0, 0, CONNECTOR_PROP_ROI_V1); |
Jeykumar Sankaran | 736d79d | 2017-10-05 17:44:24 -0700 | [diff] [blame] | 1888 | |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 1889 | /* install PP_DITHER properties */ |
| 1890 | _sde_connector_install_dither_property(dev, sde_kms, c_conn); |
Lloyd Atkinson | 8ba4703 | 2017-03-22 17:13:32 -0400 | [diff] [blame] | 1891 | |
Srikanth Rajagopalan | 30384d1 | 2017-06-08 15:23:31 -0700 | [diff] [blame] | 1892 | if (connector_type == DRM_MODE_CONNECTOR_DisplayPort) { |
Ajay Singh Parmar | 4dabdfc | 2017-11-09 16:54:25 -0800 | [diff] [blame] | 1893 | struct drm_msm_ext_hdr_properties hdr = {0}; |
| 1894 | |
Srikanth Rajagopalan | 30384d1 | 2017-06-08 15:23:31 -0700 | [diff] [blame] | 1895 | msm_property_install_blob(&c_conn->property_info, |
| 1896 | "ext_hdr_properties", |
| 1897 | DRM_MODE_PROP_IMMUTABLE, |
| 1898 | CONNECTOR_PROP_EXT_HDR_INFO); |
Ajay Singh Parmar | 4dabdfc | 2017-11-09 16:54:25 -0800 | [diff] [blame] | 1899 | |
| 1900 | /* set default values to avoid reading uninitialized data */ |
| 1901 | msm_property_set_blob(&c_conn->property_info, |
| 1902 | &c_conn->blob_ext_hdr, |
| 1903 | &hdr, |
| 1904 | sizeof(hdr), |
| 1905 | CONNECTOR_PROP_EXT_HDR_INFO); |
Srikanth Rajagopalan | 30384d1 | 2017-06-08 15:23:31 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Ajay Singh Parmar | e927aa4 | 2017-11-01 00:33:20 -0700 | [diff] [blame] | 1908 | msm_property_install_volatile_range(&c_conn->property_info, |
| 1909 | "hdr_metadata", 0x0, 0, ~0, 0, CONNECTOR_PROP_HDR_METADATA); |
| 1910 | |
Dhaval Patel | b24b2d6 | 2017-11-03 18:10:26 -0700 | [diff] [blame] | 1911 | msm_property_install_volatile_range(&c_conn->property_info, |
| 1912 | "RETIRE_FENCE", 0x0, 0, ~0, 0, CONNECTOR_PROP_RETIRE_FENCE); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1913 | |
Lloyd Atkinson | 7738220 | 2017-02-01 14:59:43 -0500 | [diff] [blame] | 1914 | msm_property_install_range(&c_conn->property_info, "autorefresh", |
| 1915 | 0x0, 0, AUTOREFRESH_MAX_FRAME_CNT, 0, |
| 1916 | CONNECTOR_PROP_AUTOREFRESH); |
| 1917 | |
Xu Yang | d566d22 | 2017-05-19 17:18:12 +0800 | [diff] [blame] | 1918 | msm_property_install_range(&c_conn->property_info, "bl_scale", |
| 1919 | 0x0, 0, MAX_BL_SCALE_LEVEL, MAX_BL_SCALE_LEVEL, |
| 1920 | CONNECTOR_PROP_BL_SCALE); |
| 1921 | |
| 1922 | msm_property_install_range(&c_conn->property_info, "ad_bl_scale", |
| 1923 | 0x0, 0, MAX_AD_BL_SCALE_LEVEL, MAX_AD_BL_SCALE_LEVEL, |
| 1924 | CONNECTOR_PROP_AD_BL_SCALE); |
| 1925 | |
Xu Yang | 9237731 | 2017-11-23 13:48:08 +0800 | [diff] [blame] | 1926 | c_conn->bl_scale_dirty = false; |
| 1927 | c_conn->bl_scale = MAX_BL_SCALE_LEVEL; |
| 1928 | c_conn->bl_scale_ad = MAX_AD_BL_SCALE_LEVEL; |
| 1929 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 1930 | /* enum/bitmask properties */ |
| 1931 | msm_property_install_enum(&c_conn->property_info, "topology_name", |
| 1932 | DRM_MODE_PROP_IMMUTABLE, 0, e_topology_name, |
| 1933 | ARRAY_SIZE(e_topology_name), |
| 1934 | CONNECTOR_PROP_TOPOLOGY_NAME); |
| 1935 | msm_property_install_enum(&c_conn->property_info, "topology_control", |
| 1936 | 0, 1, e_topology_control, |
| 1937 | ARRAY_SIZE(e_topology_control), |
| 1938 | CONNECTOR_PROP_TOPOLOGY_CONTROL); |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1939 | msm_property_install_enum(&c_conn->property_info, "LP", |
| 1940 | 0, 0, e_power_mode, |
| 1941 | ARRAY_SIZE(e_power_mode), |
| 1942 | CONNECTOR_PROP_LP); |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 1943 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1944 | rc = msm_property_install_get_status(&c_conn->property_info); |
| 1945 | if (rc) { |
| 1946 | SDE_ERROR("failed to create one or more properties\n"); |
| 1947 | goto error_destroy_property; |
| 1948 | } |
| 1949 | |
Lloyd Atkinson | b619197 | 2016-08-10 18:31:46 -0400 | [diff] [blame] | 1950 | SDE_DEBUG("connector %d attach encoder %d\n", |
| 1951 | c_conn->base.base.id, encoder->base.id); |
| 1952 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1953 | priv->connectors[priv->num_connectors++] = &c_conn->base; |
| 1954 | |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1955 | INIT_DELAYED_WORK(&c_conn->status_work, |
| 1956 | sde_connector_check_status_work); |
| 1957 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1958 | return &c_conn->base; |
| 1959 | |
| 1960 | error_destroy_property: |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1961 | if (c_conn->blob_caps) |
| 1962 | drm_property_unreference_blob(c_conn->blob_caps); |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 1963 | if (c_conn->blob_hdr) |
| 1964 | drm_property_unreference_blob(c_conn->blob_hdr); |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 1965 | if (c_conn->blob_dither) |
| 1966 | drm_property_unreference_blob(c_conn->blob_dither); |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 1967 | if (c_conn->blob_mode_info) |
| 1968 | drm_property_unreference_blob(c_conn->blob_mode_info); |
Ajay Singh Parmar | 4dabdfc | 2017-11-09 16:54:25 -0800 | [diff] [blame] | 1969 | if (c_conn->blob_ext_hdr) |
| 1970 | drm_property_unreference_blob(c_conn->blob_ext_hdr); |
Ping Li | 8430ee1 | 2017-02-24 14:14:44 -0800 | [diff] [blame] | 1971 | |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1972 | msm_property_destroy(&c_conn->property_info); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1973 | error_cleanup_fence: |
Clarence Ip | 90b282d | 2017-05-04 10:00:32 -0700 | [diff] [blame] | 1974 | mutex_destroy(&c_conn->lock); |
Clarence Ip | e59fb3f | 2016-07-26 13:39:59 -0400 | [diff] [blame] | 1975 | sde_fence_deinit(&c_conn->retire_fence); |
Clarence Ip | dd8021c | 2016-07-20 16:39:47 -0400 | [diff] [blame] | 1976 | error_cleanup_conn: |
| 1977 | drm_connector_cleanup(&c_conn->base); |
| 1978 | error_free_conn: |
| 1979 | kfree(c_conn); |
| 1980 | |
| 1981 | return ERR_PTR(rc); |
| 1982 | } |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 1983 | |
| 1984 | int sde_connector_register_custom_event(struct sde_kms *kms, |
| 1985 | struct drm_connector *conn_drm, u32 event, bool val) |
| 1986 | { |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 1987 | int ret = -EINVAL; |
| 1988 | |
| 1989 | switch (event) { |
| 1990 | case DRM_EVENT_SYS_BACKLIGHT: |
| 1991 | ret = 0; |
| 1992 | break; |
Sandeep Panda | 98d6ab2 | 2017-09-05 08:03:16 +0530 | [diff] [blame] | 1993 | case DRM_EVENT_PANEL_DEAD: |
| 1994 | ret = 0; |
| 1995 | break; |
Gopikrishnaiah Anandan | 84b4f67 | 2017-04-26 10:28:51 -0700 | [diff] [blame] | 1996 | default: |
| 1997 | break; |
| 1998 | } |
| 1999 | return ret; |
Gopikrishnaiah Anandan | de2c81b | 2017-03-15 12:41:29 -0700 | [diff] [blame] | 2000 | } |