Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Author: Jani Nikula <jani.nikula@intel.com> |
| 24 | */ |
| 25 | |
| 26 | #include <drm/drmP.h> |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 27 | #include <drm/drm_atomic_helper.h> |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 28 | #include <drm/drm_crtc.h> |
| 29 | #include <drm/drm_edid.h> |
| 30 | #include <drm/i915_drm.h> |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 31 | #include <drm/drm_panel.h> |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 32 | #include <drm/drm_mipi_dsi.h> |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 33 | #include <linux/slab.h> |
Shobhit Kumar | fc45e82 | 2015-06-26 14:32:09 +0530 | [diff] [blame] | 34 | #include <linux/gpio/consumer.h> |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 35 | #include "i915_drv.h" |
| 36 | #include "intel_drv.h" |
| 37 | #include "intel_dsi.h" |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 38 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 39 | static const struct { |
| 40 | u16 panel_id; |
| 41 | struct drm_panel * (*init)(struct intel_dsi *intel_dsi, u16 panel_id); |
| 42 | } intel_dsi_drivers[] = { |
Shobhit Kumar | 2ab8b45 | 2014-05-23 21:35:27 +0530 | [diff] [blame] | 43 | { |
| 44 | .panel_id = MIPI_DSI_GENERIC_PANEL_ID, |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 45 | .init = vbt_panel_init, |
Shobhit Kumar | 2ab8b45 | 2014-05-23 21:35:27 +0530 | [diff] [blame] | 46 | }, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 47 | }; |
| 48 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 49 | static void wait_for_dsi_fifo_empty(struct intel_dsi *intel_dsi, enum port port) |
Jani Nikula | 3b1808b | 2015-01-16 14:27:18 +0200 | [diff] [blame] | 50 | { |
| 51 | struct drm_encoder *encoder = &intel_dsi->base.base; |
| 52 | struct drm_device *dev = encoder->dev; |
| 53 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 3b1808b | 2015-01-16 14:27:18 +0200 | [diff] [blame] | 54 | u32 mask; |
| 55 | |
| 56 | mask = LP_CTRL_FIFO_EMPTY | HS_CTRL_FIFO_EMPTY | |
| 57 | LP_DATA_FIFO_EMPTY | HS_DATA_FIFO_EMPTY; |
| 58 | |
| 59 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & mask) == mask, 100)) |
| 60 | DRM_ERROR("DPI FIFOs are not empty\n"); |
| 61 | } |
| 62 | |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 63 | static void write_data(struct drm_i915_private *dev_priv, u32 reg, |
| 64 | const u8 *data, u32 len) |
| 65 | { |
| 66 | u32 i, j; |
| 67 | |
| 68 | for (i = 0; i < len; i += 4) { |
| 69 | u32 val = 0; |
| 70 | |
| 71 | for (j = 0; j < min_t(u32, len - i, 4); j++) |
| 72 | val |= *data++ << 8 * j; |
| 73 | |
| 74 | I915_WRITE(reg, val); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | static void read_data(struct drm_i915_private *dev_priv, u32 reg, |
| 79 | u8 *data, u32 len) |
| 80 | { |
| 81 | u32 i, j; |
| 82 | |
| 83 | for (i = 0; i < len; i += 4) { |
| 84 | u32 val = I915_READ(reg); |
| 85 | |
| 86 | for (j = 0; j < min_t(u32, len - i, 4); j++) |
| 87 | *data++ = val >> 8 * j; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static ssize_t intel_dsi_host_transfer(struct mipi_dsi_host *host, |
| 92 | const struct mipi_dsi_msg *msg) |
| 93 | { |
| 94 | struct intel_dsi_host *intel_dsi_host = to_intel_dsi_host(host); |
| 95 | struct drm_device *dev = intel_dsi_host->intel_dsi->base.base.dev; |
| 96 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 97 | enum port port = intel_dsi_host->port; |
| 98 | struct mipi_dsi_packet packet; |
| 99 | ssize_t ret; |
| 100 | const u8 *header, *data; |
| 101 | u32 data_reg, data_mask, ctrl_reg, ctrl_mask; |
| 102 | |
| 103 | ret = mipi_dsi_create_packet(&packet, msg); |
| 104 | if (ret < 0) |
| 105 | return ret; |
| 106 | |
| 107 | header = packet.header; |
| 108 | data = packet.payload; |
| 109 | |
| 110 | if (msg->flags & MIPI_DSI_MSG_USE_LPM) { |
| 111 | data_reg = MIPI_LP_GEN_DATA(port); |
| 112 | data_mask = LP_DATA_FIFO_FULL; |
| 113 | ctrl_reg = MIPI_LP_GEN_CTRL(port); |
| 114 | ctrl_mask = LP_CTRL_FIFO_FULL; |
| 115 | } else { |
| 116 | data_reg = MIPI_HS_GEN_DATA(port); |
| 117 | data_mask = HS_DATA_FIFO_FULL; |
| 118 | ctrl_reg = MIPI_HS_GEN_CTRL(port); |
| 119 | ctrl_mask = HS_CTRL_FIFO_FULL; |
| 120 | } |
| 121 | |
| 122 | /* note: this is never true for reads */ |
| 123 | if (packet.payload_length) { |
| 124 | |
| 125 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & data_mask) == 0, 50)) |
| 126 | DRM_ERROR("Timeout waiting for HS/LP DATA FIFO !full\n"); |
| 127 | |
| 128 | write_data(dev_priv, data_reg, packet.payload, |
| 129 | packet.payload_length); |
| 130 | } |
| 131 | |
| 132 | if (msg->rx_len) { |
| 133 | I915_WRITE(MIPI_INTR_STAT(port), GEN_READ_DATA_AVAIL); |
| 134 | } |
| 135 | |
| 136 | if (wait_for((I915_READ(MIPI_GEN_FIFO_STAT(port)) & ctrl_mask) == 0, 50)) { |
| 137 | DRM_ERROR("Timeout waiting for HS/LP CTRL FIFO !full\n"); |
| 138 | } |
| 139 | |
| 140 | I915_WRITE(ctrl_reg, header[2] << 16 | header[1] << 8 | header[0]); |
| 141 | |
| 142 | /* ->rx_len is set only for reads */ |
| 143 | if (msg->rx_len) { |
| 144 | data_mask = GEN_READ_DATA_AVAIL; |
| 145 | if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & data_mask) == data_mask, 50)) |
| 146 | DRM_ERROR("Timeout waiting for read data.\n"); |
| 147 | |
| 148 | read_data(dev_priv, data_reg, msg->rx_buf, msg->rx_len); |
| 149 | } |
| 150 | |
| 151 | /* XXX: fix for reads and writes */ |
| 152 | return 4 + packet.payload_length; |
| 153 | } |
| 154 | |
| 155 | static int intel_dsi_host_attach(struct mipi_dsi_host *host, |
| 156 | struct mipi_dsi_device *dsi) |
| 157 | { |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static int intel_dsi_host_detach(struct mipi_dsi_host *host, |
| 162 | struct mipi_dsi_device *dsi) |
| 163 | { |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static const struct mipi_dsi_host_ops intel_dsi_host_ops = { |
| 168 | .attach = intel_dsi_host_attach, |
| 169 | .detach = intel_dsi_host_detach, |
| 170 | .transfer = intel_dsi_host_transfer, |
| 171 | }; |
| 172 | |
| 173 | static struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi, |
| 174 | enum port port) |
| 175 | { |
| 176 | struct intel_dsi_host *host; |
| 177 | struct mipi_dsi_device *device; |
| 178 | |
| 179 | host = kzalloc(sizeof(*host), GFP_KERNEL); |
| 180 | if (!host) |
| 181 | return NULL; |
| 182 | |
| 183 | host->base.ops = &intel_dsi_host_ops; |
| 184 | host->intel_dsi = intel_dsi; |
| 185 | host->port = port; |
| 186 | |
| 187 | /* |
| 188 | * We should call mipi_dsi_host_register(&host->base) here, but we don't |
| 189 | * have a host->dev, and we don't have OF stuff either. So just use the |
| 190 | * dsi framework as a library and hope for the best. Create the dsi |
| 191 | * devices by ourselves here too. Need to be careful though, because we |
| 192 | * don't initialize any of the driver model devices here. |
| 193 | */ |
| 194 | device = kzalloc(sizeof(*device), GFP_KERNEL); |
| 195 | if (!device) { |
| 196 | kfree(host); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | device->host = &host->base; |
| 201 | host->device = device; |
| 202 | |
| 203 | return host; |
| 204 | } |
| 205 | |
Jani Nikula | a2581a9 | 2015-01-16 14:27:26 +0200 | [diff] [blame] | 206 | /* |
| 207 | * send a video mode command |
| 208 | * |
| 209 | * XXX: commands with data in MIPI_DPI_DATA? |
| 210 | */ |
| 211 | static int dpi_send_cmd(struct intel_dsi *intel_dsi, u32 cmd, bool hs, |
| 212 | enum port port) |
| 213 | { |
| 214 | struct drm_encoder *encoder = &intel_dsi->base.base; |
| 215 | struct drm_device *dev = encoder->dev; |
| 216 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 217 | u32 mask; |
| 218 | |
| 219 | /* XXX: pipe, hs */ |
| 220 | if (hs) |
| 221 | cmd &= ~DPI_LP_MODE; |
| 222 | else |
| 223 | cmd |= DPI_LP_MODE; |
| 224 | |
| 225 | /* clear bit */ |
| 226 | I915_WRITE(MIPI_INTR_STAT(port), SPL_PKT_SENT_INTERRUPT); |
| 227 | |
| 228 | /* XXX: old code skips write if control unchanged */ |
| 229 | if (cmd == I915_READ(MIPI_DPI_CONTROL(port))) |
| 230 | DRM_ERROR("Same special packet %02x twice in a row.\n", cmd); |
| 231 | |
| 232 | I915_WRITE(MIPI_DPI_CONTROL(port), cmd); |
| 233 | |
| 234 | mask = SPL_PKT_SENT_INTERRUPT; |
| 235 | if (wait_for((I915_READ(MIPI_INTR_STAT(port)) & mask) == mask, 100)) |
| 236 | DRM_ERROR("Video mode command 0x%08x send failed.\n", cmd); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
Shobhit Kumar | e9fe51c | 2013-12-10 12:14:55 +0530 | [diff] [blame] | 241 | static void band_gap_reset(struct drm_i915_private *dev_priv) |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 242 | { |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 243 | mutex_lock(&dev_priv->sb_lock); |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 244 | |
Shobhit Kumar | e9fe51c | 2013-12-10 12:14:55 +0530 | [diff] [blame] | 245 | vlv_flisdsi_write(dev_priv, 0x08, 0x0001); |
| 246 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0005); |
| 247 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0025); |
| 248 | udelay(150); |
| 249 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0000); |
| 250 | vlv_flisdsi_write(dev_priv, 0x08, 0x0000); |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 251 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 252 | mutex_unlock(&dev_priv->sb_lock); |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 253 | } |
| 254 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 255 | static inline bool is_vid_mode(struct intel_dsi *intel_dsi) |
| 256 | { |
Shobhit Kumar | dfba2e2 | 2014-04-14 11:18:24 +0530 | [diff] [blame] | 257 | return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static inline bool is_cmd_mode(struct intel_dsi *intel_dsi) |
| 261 | { |
Shobhit Kumar | dfba2e2 | 2014-04-14 11:18:24 +0530 | [diff] [blame] | 262 | return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 263 | } |
| 264 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 265 | static bool intel_dsi_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 266 | struct intel_crtc_state *config) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 267 | { |
| 268 | struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, |
| 269 | base); |
| 270 | struct intel_connector *intel_connector = intel_dsi->attached_connector; |
| 271 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 272 | struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 273 | |
| 274 | DRM_DEBUG_KMS("\n"); |
| 275 | |
| 276 | if (fixed_mode) |
| 277 | intel_fixed_panel_mode(fixed_mode, adjusted_mode); |
| 278 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 279 | /* DSI uses short packets for sync events, so clear mode flags for DSI */ |
| 280 | adjusted_mode->flags = 0; |
| 281 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 282 | return true; |
| 283 | } |
| 284 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 285 | static void bxt_dsi_device_ready(struct intel_encoder *encoder) |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 286 | { |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 287 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 288 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 289 | enum port port; |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 290 | u32 val; |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 291 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 292 | DRM_DEBUG_KMS("\n"); |
Gaurav K Singh | a9da9bc | 2014-12-05 14:13:41 +0530 | [diff] [blame] | 293 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 294 | /* Exit Low power state in 4 steps*/ |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 295 | for_each_dsi_port(port, intel_dsi->ports) { |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 296 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 297 | /* 1. Enable MIPI PHY transparent latch */ |
| 298 | val = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 299 | I915_WRITE(BXT_MIPI_PORT_CTRL(port), val | LP_OUTPUT_HOLD); |
| 300 | usleep_range(2000, 2500); |
| 301 | |
| 302 | /* 2. Enter ULPS */ |
| 303 | val = I915_READ(MIPI_DEVICE_READY(port)); |
| 304 | val &= ~ULPS_STATE_MASK; |
| 305 | val |= (ULPS_STATE_ENTER | DEVICE_READY); |
| 306 | I915_WRITE(MIPI_DEVICE_READY(port), val); |
| 307 | usleep_range(2, 3); |
| 308 | |
| 309 | /* 3. Exit ULPS */ |
| 310 | val = I915_READ(MIPI_DEVICE_READY(port)); |
| 311 | val &= ~ULPS_STATE_MASK; |
| 312 | val |= (ULPS_STATE_EXIT | DEVICE_READY); |
| 313 | I915_WRITE(MIPI_DEVICE_READY(port), val); |
| 314 | usleep_range(1000, 1500); |
| 315 | |
| 316 | /* Clear ULPS and set device ready */ |
| 317 | val = I915_READ(MIPI_DEVICE_READY(port)); |
| 318 | val &= ~ULPS_STATE_MASK; |
| 319 | val |= DEVICE_READY; |
| 320 | I915_WRITE(MIPI_DEVICE_READY(port), val); |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 321 | } |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 322 | } |
| 323 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 324 | static void vlv_dsi_device_ready(struct intel_encoder *encoder) |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 325 | { |
| 326 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 327 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 328 | enum port port; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 329 | u32 val; |
| 330 | |
| 331 | DRM_DEBUG_KMS("\n"); |
| 332 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 333 | mutex_lock(&dev_priv->sb_lock); |
Shobhit Kumar | 2095f9f | 2014-04-09 13:59:30 +0530 | [diff] [blame] | 334 | /* program rcomp for compliance, reduce from 50 ohms to 45 ohms |
| 335 | * needed everytime after power gate */ |
| 336 | vlv_flisdsi_write(dev_priv, 0x04, 0x0004); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 337 | mutex_unlock(&dev_priv->sb_lock); |
Shobhit Kumar | 2095f9f | 2014-04-09 13:59:30 +0530 | [diff] [blame] | 338 | |
| 339 | /* bandgap reset is needed after everytime we do power gate */ |
| 340 | band_gap_reset(dev_priv); |
| 341 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 342 | for_each_dsi_port(port, intel_dsi->ports) { |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 343 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 344 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER); |
| 345 | usleep_range(2500, 3000); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 346 | |
Gaurav K Singh | bf344e8 | 2014-12-07 16:13:54 +0530 | [diff] [blame] | 347 | /* Enable MIPI PHY transparent latch |
| 348 | * Common bit for both MIPI Port A & MIPI Port C |
| 349 | * No similar bit in MIPI Port C reg |
| 350 | */ |
Shobhit Kumar | 4ba7d93 | 2015-02-05 17:08:45 +0530 | [diff] [blame] | 351 | val = I915_READ(MIPI_PORT_CTRL(PORT_A)); |
Gaurav K Singh | bf344e8 | 2014-12-07 16:13:54 +0530 | [diff] [blame] | 352 | I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD); |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 353 | usleep_range(1000, 1500); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 354 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 355 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT); |
| 356 | usleep_range(2500, 3000); |
| 357 | |
| 358 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY); |
| 359 | usleep_range(2500, 3000); |
| 360 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 361 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 362 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 363 | static void intel_dsi_device_ready(struct intel_encoder *encoder) |
| 364 | { |
| 365 | struct drm_device *dev = encoder->base.dev; |
| 366 | |
| 367 | if (IS_VALLEYVIEW(dev)) |
| 368 | vlv_dsi_device_ready(encoder); |
| 369 | else if (IS_BROXTON(dev)) |
| 370 | bxt_dsi_device_ready(encoder); |
| 371 | } |
| 372 | |
| 373 | static void intel_dsi_port_enable(struct intel_encoder *encoder) |
| 374 | { |
| 375 | struct drm_device *dev = encoder->base.dev; |
| 376 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 377 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 378 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 379 | enum port port; |
| 380 | u32 temp; |
| 381 | u32 port_ctrl; |
| 382 | |
| 383 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { |
| 384 | temp = I915_READ(VLV_CHICKEN_3); |
| 385 | temp &= ~PIXEL_OVERLAP_CNT_MASK | |
| 386 | intel_dsi->pixel_overlap << |
| 387 | PIXEL_OVERLAP_CNT_SHIFT; |
| 388 | I915_WRITE(VLV_CHICKEN_3, temp); |
| 389 | } |
| 390 | |
| 391 | for_each_dsi_port(port, intel_dsi->ports) { |
| 392 | port_ctrl = IS_BROXTON(dev) ? BXT_MIPI_PORT_CTRL(port) : |
| 393 | MIPI_PORT_CTRL(port); |
| 394 | |
| 395 | temp = I915_READ(port_ctrl); |
| 396 | |
| 397 | temp &= ~LANE_CONFIGURATION_MASK; |
| 398 | temp &= ~DUAL_LINK_MODE_MASK; |
| 399 | |
| 400 | if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) { |
| 401 | temp |= (intel_dsi->dual_link - 1) |
| 402 | << DUAL_LINK_MODE_SHIFT; |
| 403 | temp |= intel_crtc->pipe ? |
| 404 | LANE_CONFIGURATION_DUAL_LINK_B : |
| 405 | LANE_CONFIGURATION_DUAL_LINK_A; |
| 406 | } |
| 407 | /* assert ip_tg_enable signal */ |
| 408 | I915_WRITE(port_ctrl, temp | DPI_ENABLE); |
| 409 | POSTING_READ(port_ctrl); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | static void intel_dsi_port_disable(struct intel_encoder *encoder) |
| 414 | { |
| 415 | struct drm_device *dev = encoder->base.dev; |
| 416 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 417 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 418 | enum port port; |
| 419 | u32 temp; |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 420 | u32 port_ctrl; |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 421 | |
| 422 | for_each_dsi_port(port, intel_dsi->ports) { |
| 423 | /* de-assert ip_tg_enable signal */ |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 424 | port_ctrl = IS_BROXTON(dev) ? BXT_MIPI_PORT_CTRL(port) : |
| 425 | MIPI_PORT_CTRL(port); |
| 426 | temp = I915_READ(port_ctrl); |
| 427 | I915_WRITE(port_ctrl, temp & ~DPI_ENABLE); |
| 428 | POSTING_READ(port_ctrl); |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 432 | static void intel_dsi_enable(struct intel_encoder *encoder) |
| 433 | { |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 434 | struct drm_device *dev = encoder->base.dev; |
| 435 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 436 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Jani Nikula | 4934b65 | 2015-01-22 15:01:35 +0200 | [diff] [blame] | 437 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 438 | |
| 439 | DRM_DEBUG_KMS("\n"); |
| 440 | |
Jani Nikula | 4934b65 | 2015-01-22 15:01:35 +0200 | [diff] [blame] | 441 | if (is_cmd_mode(intel_dsi)) { |
| 442 | for_each_dsi_port(port, intel_dsi->ports) |
| 443 | I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4); |
| 444 | } else { |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 445 | msleep(20); /* XXX */ |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 446 | for_each_dsi_port(port, intel_dsi->ports) |
Jani Nikula | a2581a9 | 2015-01-16 14:27:26 +0200 | [diff] [blame] | 447 | dpi_send_cmd(intel_dsi, TURN_ON, false, port); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 448 | msleep(100); |
| 449 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 450 | drm_panel_enable(intel_dsi->panel); |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 451 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 452 | for_each_dsi_port(port, intel_dsi->ports) |
| 453 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 454 | |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 455 | intel_dsi_port_enable(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 456 | } |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 457 | |
| 458 | intel_panel_enable_backlight(intel_dsi->attached_connector); |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 459 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 460 | |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 461 | static void intel_dsi_pre_enable(struct intel_encoder *encoder) |
| 462 | { |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 463 | struct drm_device *dev = encoder->base.dev; |
| 464 | struct drm_i915_private *dev_priv = dev->dev_private; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 465 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 466 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 467 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 468 | enum port port; |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 469 | u32 tmp; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 470 | |
| 471 | DRM_DEBUG_KMS("\n"); |
| 472 | |
Shobhit Kumar | fc45e82 | 2015-06-26 14:32:09 +0530 | [diff] [blame] | 473 | /* Panel Enable over CRC PMIC */ |
| 474 | if (intel_dsi->gpio_panel) |
| 475 | gpiod_set_value_cansleep(intel_dsi->gpio_panel, 1); |
| 476 | |
| 477 | msleep(intel_dsi->panel_on_delay); |
| 478 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 479 | if (IS_VALLEYVIEW(dev)) { |
| 480 | /* |
| 481 | * Disable DPOunit clock gating, can stall pipe |
| 482 | * and we need DPLL REFA always enabled |
| 483 | */ |
| 484 | tmp = I915_READ(DPLL(pipe)); |
| 485 | tmp |= DPLL_REF_CLK_ENABLE_VLV; |
| 486 | I915_WRITE(DPLL(pipe), tmp); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 487 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 488 | /* update the hw state for DPLL */ |
| 489 | intel_crtc->config->dpll_hw_state.dpll = |
| 490 | DPLL_INTEGRATED_REF_CLK_VLV | |
| 491 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 492 | |
Shashank Sharma | 37ab081 | 2015-09-01 19:41:42 +0530 | [diff] [blame] | 493 | tmp = I915_READ(DSPCLK_GATE_D); |
| 494 | tmp |= DPOUNIT_CLOCK_GATE_DISABLE; |
| 495 | I915_WRITE(DSPCLK_GATE_D, tmp); |
| 496 | } |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 497 | |
| 498 | /* put device in ready state */ |
| 499 | intel_dsi_device_ready(encoder); |
| 500 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 501 | drm_panel_prepare(intel_dsi->panel); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 502 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 503 | for_each_dsi_port(port, intel_dsi->ports) |
| 504 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 505 | |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 506 | /* Enable port in pre-enable phase itself because as per hw team |
| 507 | * recommendation, port should be enabled befor plane & pipe */ |
| 508 | intel_dsi_enable(encoder); |
| 509 | } |
| 510 | |
| 511 | static void intel_dsi_enable_nop(struct intel_encoder *encoder) |
| 512 | { |
| 513 | DRM_DEBUG_KMS("\n"); |
| 514 | |
| 515 | /* for DSI port enable has to be done before pipe |
| 516 | * and plane enable, so port enable is done in |
| 517 | * pre_enable phase itself unlike other encoders |
| 518 | */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 519 | } |
| 520 | |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 521 | static void intel_dsi_pre_disable(struct intel_encoder *encoder) |
| 522 | { |
| 523 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 524 | enum port port; |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 525 | |
| 526 | DRM_DEBUG_KMS("\n"); |
| 527 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 528 | intel_panel_disable_backlight(intel_dsi->attached_connector); |
| 529 | |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 530 | if (is_vid_mode(intel_dsi)) { |
| 531 | /* Send Shutdown command to the panel in LP mode */ |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 532 | for_each_dsi_port(port, intel_dsi->ports) |
Jani Nikula | a2581a9 | 2015-01-16 14:27:26 +0200 | [diff] [blame] | 533 | dpi_send_cmd(intel_dsi, SHUTDOWN, false, port); |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 534 | msleep(10); |
| 535 | } |
| 536 | } |
| 537 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 538 | static void intel_dsi_disable(struct intel_encoder *encoder) |
| 539 | { |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 540 | struct drm_device *dev = encoder->base.dev; |
| 541 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 542 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 543 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 544 | u32 temp; |
| 545 | |
| 546 | DRM_DEBUG_KMS("\n"); |
| 547 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 548 | if (is_vid_mode(intel_dsi)) { |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 549 | for_each_dsi_port(port, intel_dsi->ports) |
| 550 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 551 | |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 552 | intel_dsi_port_disable(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 553 | msleep(2); |
| 554 | } |
| 555 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 556 | for_each_dsi_port(port, intel_dsi->ports) { |
| 557 | /* Panel commands can be sent when clock is in LP11 */ |
| 558 | I915_WRITE(MIPI_DEVICE_READY(port), 0x0); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 559 | |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 560 | intel_dsi_reset_clocks(encoder, port); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 561 | I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 562 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 563 | temp = I915_READ(MIPI_DSI_FUNC_PRG(port)); |
| 564 | temp &= ~VID_MODE_FORMAT_MASK; |
| 565 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 566 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 567 | I915_WRITE(MIPI_DEVICE_READY(port), 0x1); |
| 568 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 569 | /* if disable packets are sent before sending shutdown packet then in |
| 570 | * some next enable sequence send turn on packet error is observed */ |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 571 | drm_panel_disable(intel_dsi->panel); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 572 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 573 | for_each_dsi_port(port, intel_dsi->ports) |
| 574 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 575 | } |
| 576 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 577 | static void intel_dsi_clear_device_ready(struct intel_encoder *encoder) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 578 | { |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 579 | struct drm_device *dev = encoder->base.dev; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 580 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 581 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 582 | enum port port; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 583 | u32 val; |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 584 | u32 port_ctrl = 0; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 585 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 586 | DRM_DEBUG_KMS("\n"); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 587 | for_each_dsi_port(port, intel_dsi->ports) { |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 588 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 589 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 590 | ULPS_STATE_ENTER); |
| 591 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 592 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 593 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 594 | ULPS_STATE_EXIT); |
| 595 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 596 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 597 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 598 | ULPS_STATE_ENTER); |
| 599 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 600 | |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 601 | if (IS_BROXTON(dev)) |
| 602 | port_ctrl = BXT_MIPI_PORT_CTRL(port); |
| 603 | else if (IS_VALLEYVIEW(dev)) |
| 604 | /* Common bit for both MIPI Port A & MIPI Port C */ |
| 605 | port_ctrl = MIPI_PORT_CTRL(PORT_A); |
| 606 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 607 | /* Wait till Clock lanes are in LP-00 state for MIPI Port A |
| 608 | * only. MIPI Port C has no similar bit for checking |
| 609 | */ |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 610 | if (wait_for(((I915_READ(port_ctrl) & AFE_LATCHOUT) |
| 611 | == 0x00000), 30)) |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 612 | DRM_ERROR("DSI LP not going Low\n"); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 613 | |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame^] | 614 | /* Disable MIPI PHY transparent latch */ |
| 615 | val = I915_READ(port_ctrl); |
| 616 | I915_WRITE(port_ctrl, val & ~LP_OUTPUT_HOLD); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 617 | usleep_range(1000, 1500); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 618 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 619 | I915_WRITE(MIPI_DEVICE_READY(port), 0x00); |
| 620 | usleep_range(2000, 2500); |
| 621 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 622 | |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 623 | intel_disable_dsi_pll(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 624 | } |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 625 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 626 | static void intel_dsi_post_disable(struct intel_encoder *encoder) |
| 627 | { |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 628 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 629 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 630 | u32 val; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 631 | |
| 632 | DRM_DEBUG_KMS("\n"); |
| 633 | |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 634 | intel_dsi_disable(encoder); |
| 635 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 636 | intel_dsi_clear_device_ready(encoder); |
| 637 | |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 638 | val = I915_READ(DSPCLK_GATE_D); |
| 639 | val &= ~DPOUNIT_CLOCK_GATE_DISABLE; |
| 640 | I915_WRITE(DSPCLK_GATE_D, val); |
| 641 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 642 | drm_panel_unprepare(intel_dsi->panel); |
Shobhit Kumar | df38e65 | 2014-04-14 11:18:26 +0530 | [diff] [blame] | 643 | |
| 644 | msleep(intel_dsi->panel_off_delay); |
| 645 | msleep(intel_dsi->panel_pwr_cycle_delay); |
Shobhit Kumar | fc45e82 | 2015-06-26 14:32:09 +0530 | [diff] [blame] | 646 | |
| 647 | /* Panel Disable over CRC PMIC */ |
| 648 | if (intel_dsi->gpio_panel) |
| 649 | gpiod_set_value_cansleep(intel_dsi->gpio_panel, 0); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 650 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 651 | |
| 652 | static bool intel_dsi_get_hw_state(struct intel_encoder *encoder, |
| 653 | enum pipe *pipe) |
| 654 | { |
| 655 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 656 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 657 | struct drm_device *dev = encoder->base.dev; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 658 | enum intel_display_power_domain power_domain; |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 659 | u32 dpi_enabled, func; |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 660 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 661 | |
| 662 | DRM_DEBUG_KMS("\n"); |
| 663 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 664 | power_domain = intel_display_port_power_domain(encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 665 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 666 | return false; |
| 667 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 668 | /* XXX: this only works for one DSI output */ |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 669 | for_each_dsi_port(port, intel_dsi->ports) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 670 | func = I915_READ(MIPI_DSI_FUNC_PRG(port)); |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 671 | dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) & |
| 672 | DPI_ENABLE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 673 | |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 674 | /* Due to some hardware limitations on BYT, MIPI Port C DPI |
| 675 | * Enable bit does not get set. To check whether DSI Port C |
| 676 | * was enabled in BIOS, check the Pipe B enable bit |
| 677 | */ |
| 678 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
| 679 | (port == PORT_C)) |
| 680 | dpi_enabled = I915_READ(PIPECONF(PIPE_B)) & |
| 681 | PIPECONF_ENABLE; |
| 682 | |
| 683 | if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 684 | if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) { |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 685 | *pipe = port == PORT_A ? PIPE_A : PIPE_B; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 686 | return true; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | static void intel_dsi_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 695 | struct intel_crtc_state *pipe_config) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 696 | { |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 697 | u32 pclk; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 698 | DRM_DEBUG_KMS("\n"); |
| 699 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 700 | /* |
| 701 | * DPLL_MD is not used in case of DSI, reading will get some default value |
| 702 | * set dpll_md = 0 |
| 703 | */ |
| 704 | pipe_config->dpll_hw_state.dpll_md = 0; |
| 705 | |
| 706 | pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp); |
| 707 | if (!pclk) |
| 708 | return; |
| 709 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 710 | pipe_config->base.adjusted_mode.crtc_clock = pclk; |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 711 | pipe_config->port_clock = pclk; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 712 | } |
| 713 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 714 | static enum drm_mode_status |
| 715 | intel_dsi_mode_valid(struct drm_connector *connector, |
| 716 | struct drm_display_mode *mode) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 717 | { |
| 718 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 719 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Mika Kahola | 759a1e9 | 2015-08-18 14:37:01 +0300 | [diff] [blame] | 720 | int max_dotclk = to_i915(connector->dev)->max_dotclk_freq; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 721 | |
| 722 | DRM_DEBUG_KMS("\n"); |
| 723 | |
| 724 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) { |
| 725 | DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n"); |
| 726 | return MODE_NO_DBLESCAN; |
| 727 | } |
| 728 | |
| 729 | if (fixed_mode) { |
| 730 | if (mode->hdisplay > fixed_mode->hdisplay) |
| 731 | return MODE_PANEL; |
| 732 | if (mode->vdisplay > fixed_mode->vdisplay) |
| 733 | return MODE_PANEL; |
Mika Kahola | 759a1e9 | 2015-08-18 14:37:01 +0300 | [diff] [blame] | 734 | if (fixed_mode->clock > max_dotclk) |
| 735 | return MODE_CLOCK_HIGH; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 736 | } |
| 737 | |
Jani Nikula | 36d21f4 | 2015-01-16 14:27:20 +0200 | [diff] [blame] | 738 | return MODE_OK; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* return txclkesc cycles in terms of divider and duration in us */ |
| 742 | static u16 txclkesc(u32 divider, unsigned int us) |
| 743 | { |
| 744 | switch (divider) { |
| 745 | case ESCAPE_CLOCK_DIVIDER_1: |
| 746 | default: |
| 747 | return 20 * us; |
| 748 | case ESCAPE_CLOCK_DIVIDER_2: |
| 749 | return 10 * us; |
| 750 | case ESCAPE_CLOCK_DIVIDER_4: |
| 751 | return 5 * us; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /* return pixels in terms of txbyteclkhs */ |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 756 | static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count, |
| 757 | u16 burst_mode_ratio) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 758 | { |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 759 | return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 760 | 8 * 100), lane_count); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static void set_dsi_timings(struct drm_encoder *encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 764 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 765 | { |
| 766 | struct drm_device *dev = encoder->dev; |
| 767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 768 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 769 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 770 | enum port port; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 771 | unsigned int bpp = intel_crtc->config->pipe_bpp; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 772 | unsigned int lane_count = intel_dsi->lane_count; |
| 773 | |
| 774 | u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp; |
| 775 | |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 776 | hactive = adjusted_mode->crtc_hdisplay; |
| 777 | hfp = adjusted_mode->crtc_hsync_start - adjusted_mode->crtc_hdisplay; |
| 778 | hsync = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start; |
| 779 | hbp = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_end; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 780 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 781 | if (intel_dsi->dual_link) { |
| 782 | hactive /= 2; |
| 783 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) |
| 784 | hactive += intel_dsi->pixel_overlap; |
| 785 | hfp /= 2; |
| 786 | hsync /= 2; |
| 787 | hbp /= 2; |
| 788 | } |
| 789 | |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 790 | vfp = adjusted_mode->crtc_vsync_start - adjusted_mode->crtc_vdisplay; |
| 791 | vsync = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start; |
| 792 | vbp = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_end; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 793 | |
| 794 | /* horizontal values are in terms of high speed byte clock */ |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 795 | hactive = txbyteclkhs(hactive, bpp, lane_count, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 796 | intel_dsi->burst_mode_ratio); |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 797 | hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
| 798 | hsync = txbyteclkhs(hsync, bpp, lane_count, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 799 | intel_dsi->burst_mode_ratio); |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 800 | hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 801 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 802 | for_each_dsi_port(port, intel_dsi->ports) { |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 803 | if (IS_BROXTON(dev)) { |
| 804 | /* |
| 805 | * Program hdisplay and vdisplay on MIPI transcoder. |
| 806 | * This is different from calculated hactive and |
| 807 | * vactive, as they are calculated per channel basis, |
| 808 | * whereas these values should be based on resolution. |
| 809 | */ |
| 810 | I915_WRITE(BXT_MIPI_TRANS_HACTIVE(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 811 | adjusted_mode->crtc_hdisplay); |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 812 | I915_WRITE(BXT_MIPI_TRANS_VACTIVE(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 813 | adjusted_mode->crtc_vdisplay); |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 814 | I915_WRITE(BXT_MIPI_TRANS_VTOTAL(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 815 | adjusted_mode->crtc_vtotal); |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 816 | } |
| 817 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 818 | I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive); |
| 819 | I915_WRITE(MIPI_HFP_COUNT(port), hfp); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 820 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 821 | /* meaningful for video mode non-burst sync pulse mode only, |
| 822 | * can be zero for non-burst sync events and burst modes */ |
| 823 | I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync); |
| 824 | I915_WRITE(MIPI_HBP_COUNT(port), hbp); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 825 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 826 | /* vertical values are in terms of lines */ |
| 827 | I915_WRITE(MIPI_VFP_COUNT(port), vfp); |
| 828 | I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync); |
| 829 | I915_WRITE(MIPI_VBP_COUNT(port), vbp); |
| 830 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 831 | } |
| 832 | |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 833 | static void intel_dsi_prepare(struct intel_encoder *intel_encoder) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 834 | { |
| 835 | struct drm_encoder *encoder = &intel_encoder->base; |
| 836 | struct drm_device *dev = encoder->dev; |
| 837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 838 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 839 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 840 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 841 | enum port port; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 842 | unsigned int bpp = intel_crtc->config->pipe_bpp; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 843 | u32 val, tmp; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 844 | u16 mode_hdisplay; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 845 | |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 846 | DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe)); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 847 | |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 848 | mode_hdisplay = adjusted_mode->crtc_hdisplay; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 849 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 850 | if (intel_dsi->dual_link) { |
| 851 | mode_hdisplay /= 2; |
| 852 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) |
| 853 | mode_hdisplay += intel_dsi->pixel_overlap; |
| 854 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 855 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 856 | for_each_dsi_port(port, intel_dsi->ports) { |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 857 | if (IS_VALLEYVIEW(dev)) { |
| 858 | /* |
| 859 | * escape clock divider, 20MHz, shared for A and C. |
| 860 | * device ready must be off when doing this! txclkesc? |
| 861 | */ |
| 862 | tmp = I915_READ(MIPI_CTRL(PORT_A)); |
| 863 | tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK; |
| 864 | I915_WRITE(MIPI_CTRL(PORT_A), tmp | |
| 865 | ESCAPE_CLOCK_DIVIDER_1); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 866 | |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 867 | /* read request priority is per pipe */ |
| 868 | tmp = I915_READ(MIPI_CTRL(port)); |
| 869 | tmp &= ~READ_REQUEST_PRIORITY_MASK; |
| 870 | I915_WRITE(MIPI_CTRL(port), tmp | |
| 871 | READ_REQUEST_PRIORITY_HIGH); |
| 872 | } else if (IS_BROXTON(dev)) { |
| 873 | /* |
| 874 | * FIXME: |
| 875 | * BXT can connect any PIPE to any MIPI port. |
| 876 | * Select the pipe based on the MIPI port read from |
| 877 | * VBT for now. Pick PIPE A for MIPI port A and C |
| 878 | * for port C. |
| 879 | */ |
| 880 | tmp = I915_READ(MIPI_CTRL(port)); |
| 881 | tmp &= ~BXT_PIPE_SELECT_MASK; |
| 882 | |
| 883 | if (port == PORT_A) |
| 884 | tmp |= BXT_PIPE_SELECT_A; |
| 885 | else if (port == PORT_C) |
| 886 | tmp |= BXT_PIPE_SELECT_C; |
| 887 | |
| 888 | I915_WRITE(MIPI_CTRL(port), tmp); |
| 889 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 890 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 891 | /* XXX: why here, why like this? handling in irq handler?! */ |
| 892 | I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff); |
| 893 | I915_WRITE(MIPI_INTR_EN(port), 0xffffffff); |
| 894 | |
| 895 | I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg); |
| 896 | |
| 897 | I915_WRITE(MIPI_DPI_RESOLUTION(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 898 | adjusted_mode->crtc_vdisplay << VERTICAL_ADDRESS_SHIFT | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 899 | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT); |
| 900 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 901 | |
| 902 | set_dsi_timings(encoder, adjusted_mode); |
| 903 | |
| 904 | val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT; |
| 905 | if (is_cmd_mode(intel_dsi)) { |
| 906 | val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT; |
| 907 | val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */ |
| 908 | } else { |
| 909 | val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT; |
| 910 | |
| 911 | /* XXX: cross-check bpp vs. pixel format? */ |
| 912 | val |= intel_dsi->pixel_format; |
| 913 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 914 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 915 | tmp = 0; |
Shobhit Kumar | f1c79f1 | 2014-04-09 13:59:33 +0530 | [diff] [blame] | 916 | if (intel_dsi->eotp_pkt == 0) |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 917 | tmp |= EOT_DISABLE; |
Shobhit Kumar | f1c79f1 | 2014-04-09 13:59:33 +0530 | [diff] [blame] | 918 | if (intel_dsi->clock_stop) |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 919 | tmp |= CLOCKSTOP; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 920 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 921 | for_each_dsi_port(port, intel_dsi->ports) { |
| 922 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), val); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 923 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 924 | /* timeouts for recovery. one frame IIUC. if counter expires, |
| 925 | * EOT and stop state. */ |
Shobhit Kumar | cf4dbd2 | 2014-04-14 11:18:25 +0530 | [diff] [blame] | 926 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 927 | /* |
| 928 | * In burst mode, value greater than one DPI line Time in byte |
| 929 | * clock (txbyteclkhs) To timeout this timer 1+ of the above |
| 930 | * said value is recommended. |
| 931 | * |
| 932 | * In non-burst mode, Value greater than one DPI frame time in |
| 933 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above |
| 934 | * said value is recommended. |
| 935 | * |
| 936 | * In DBI only mode, value greater than one DBI frame time in |
| 937 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above |
| 938 | * said value is recommended. |
| 939 | */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 940 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 941 | if (is_vid_mode(intel_dsi) && |
| 942 | intel_dsi->video_mode_format == VIDEO_MODE_BURST) { |
| 943 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 944 | txbyteclkhs(adjusted_mode->crtc_htotal, bpp, |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 945 | intel_dsi->lane_count, |
| 946 | intel_dsi->burst_mode_ratio) + 1); |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 947 | } else { |
| 948 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 949 | txbyteclkhs(adjusted_mode->crtc_vtotal * |
| 950 | adjusted_mode->crtc_htotal, |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 951 | bpp, intel_dsi->lane_count, |
| 952 | intel_dsi->burst_mode_ratio) + 1); |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 953 | } |
| 954 | I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout); |
| 955 | I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), |
| 956 | intel_dsi->turn_arnd_val); |
| 957 | I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), |
| 958 | intel_dsi->rst_timer_val); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 959 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 960 | /* dphy stuff */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 961 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 962 | /* in terms of low power clock */ |
| 963 | I915_WRITE(MIPI_INIT_COUNT(port), |
| 964 | txclkesc(intel_dsi->escape_clk_div, 100)); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 965 | |
Shashank Sharma | d2e08c0 | 2015-09-01 19:41:40 +0530 | [diff] [blame] | 966 | if (IS_BROXTON(dev) && (!intel_dsi->dual_link)) { |
| 967 | /* |
| 968 | * BXT spec says write MIPI_INIT_COUNT for |
| 969 | * both the ports, even if only one is |
| 970 | * getting used. So write the other port |
| 971 | * if not in dual link mode. |
| 972 | */ |
| 973 | I915_WRITE(MIPI_INIT_COUNT(port == |
| 974 | PORT_A ? PORT_C : PORT_A), |
| 975 | intel_dsi->init_count); |
| 976 | } |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 977 | |
| 978 | /* recovery disables */ |
Shobhit Kumar | 87c54d0 | 2015-02-03 12:17:35 +0530 | [diff] [blame] | 979 | I915_WRITE(MIPI_EOT_DISABLE(port), tmp); |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 980 | |
| 981 | /* in terms of low power clock */ |
| 982 | I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count); |
| 983 | |
| 984 | /* in terms of txbyteclkhs. actual high to low switch + |
| 985 | * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK. |
| 986 | * |
| 987 | * XXX: write MIPI_STOP_STATE_STALL? |
| 988 | */ |
| 989 | I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port), |
| 990 | intel_dsi->hs_to_lp_count); |
| 991 | |
| 992 | /* XXX: low power clock equivalence in terms of byte clock. |
| 993 | * the number of byte clocks occupied in one low power clock. |
| 994 | * based on txbyteclkhs and txclkesc. |
| 995 | * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL |
| 996 | * ) / 105.??? |
| 997 | */ |
| 998 | I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk); |
| 999 | |
| 1000 | /* the bw essential for transmitting 16 long packets containing |
| 1001 | * 252 bytes meant for dcs write memory command is programmed in |
| 1002 | * this register in terms of byte clocks. based on dsi transfer |
| 1003 | * rate and the number of lanes configured the time taken to |
| 1004 | * transmit 16 long packets in a dsi stream varies. */ |
| 1005 | I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer); |
| 1006 | |
| 1007 | I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port), |
| 1008 | intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | |
| 1009 | intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT); |
| 1010 | |
| 1011 | if (is_vid_mode(intel_dsi)) |
| 1012 | /* Some panels might have resolution which is not a |
| 1013 | * multiple of 64 like 1366 x 768. Enable RANDOM |
| 1014 | * resolution support for such panels by default */ |
| 1015 | I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port), |
| 1016 | intel_dsi->video_frmt_cfg_bits | |
| 1017 | intel_dsi->video_mode_format | |
| 1018 | IP_TG_CONFIG | |
| 1019 | RANDOM_DPI_DISPLAY_RESOLUTION); |
| 1020 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1021 | } |
| 1022 | |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 1023 | static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder) |
| 1024 | { |
| 1025 | DRM_DEBUG_KMS("\n"); |
| 1026 | |
| 1027 | intel_dsi_prepare(encoder); |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 1028 | intel_enable_dsi_pll(encoder); |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 1029 | |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 1030 | } |
| 1031 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1032 | static enum drm_connector_status |
| 1033 | intel_dsi_detect(struct drm_connector *connector, bool force) |
| 1034 | { |
Jani Nikula | 36d21f4 | 2015-01-16 14:27:20 +0200 | [diff] [blame] | 1035 | return connector_status_connected; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | static int intel_dsi_get_modes(struct drm_connector *connector) |
| 1039 | { |
| 1040 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 1041 | struct drm_display_mode *mode; |
| 1042 | |
| 1043 | DRM_DEBUG_KMS("\n"); |
| 1044 | |
| 1045 | if (!intel_connector->panel.fixed_mode) { |
| 1046 | DRM_DEBUG_KMS("no fixed mode\n"); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | mode = drm_mode_duplicate(connector->dev, |
| 1051 | intel_connector->panel.fixed_mode); |
| 1052 | if (!mode) { |
| 1053 | DRM_DEBUG_KMS("drm_mode_duplicate failed\n"); |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | drm_mode_probed_add(connector, mode); |
| 1058 | return 1; |
| 1059 | } |
| 1060 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1061 | static void intel_dsi_connector_destroy(struct drm_connector *connector) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1062 | { |
| 1063 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 1064 | |
| 1065 | DRM_DEBUG_KMS("\n"); |
| 1066 | intel_panel_fini(&intel_connector->panel); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1067 | drm_connector_cleanup(connector); |
| 1068 | kfree(connector); |
| 1069 | } |
| 1070 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1071 | static void intel_dsi_encoder_destroy(struct drm_encoder *encoder) |
| 1072 | { |
| 1073 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
| 1074 | |
| 1075 | if (intel_dsi->panel) { |
| 1076 | drm_panel_detach(intel_dsi->panel); |
| 1077 | /* XXX: Logically this call belongs in the panel driver. */ |
| 1078 | drm_panel_remove(intel_dsi->panel); |
| 1079 | } |
Shobhit Kumar | fc45e82 | 2015-06-26 14:32:09 +0530 | [diff] [blame] | 1080 | |
| 1081 | /* dispose of the gpios */ |
| 1082 | if (intel_dsi->gpio_panel) |
| 1083 | gpiod_put(intel_dsi->gpio_panel); |
| 1084 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1085 | intel_encoder_destroy(encoder); |
| 1086 | } |
| 1087 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1088 | static const struct drm_encoder_funcs intel_dsi_funcs = { |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1089 | .destroy = intel_dsi_encoder_destroy, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1090 | }; |
| 1091 | |
| 1092 | static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = { |
| 1093 | .get_modes = intel_dsi_get_modes, |
| 1094 | .mode_valid = intel_dsi_mode_valid, |
| 1095 | .best_encoder = intel_best_encoder, |
| 1096 | }; |
| 1097 | |
| 1098 | static const struct drm_connector_funcs intel_dsi_connector_funcs = { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 1099 | .dpms = drm_atomic_helper_connector_dpms, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1100 | .detect = intel_dsi_detect, |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1101 | .destroy = intel_dsi_connector_destroy, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1102 | .fill_modes = drm_helper_probe_single_connector_modes, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 1103 | .atomic_get_property = intel_connector_atomic_get_property, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 1104 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Ander Conselvan de Oliveira | 9896972 | 2015-03-20 16:18:06 +0200 | [diff] [blame] | 1105 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1106 | }; |
| 1107 | |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1108 | void intel_dsi_init(struct drm_device *dev) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1109 | { |
| 1110 | struct intel_dsi *intel_dsi; |
| 1111 | struct intel_encoder *intel_encoder; |
| 1112 | struct drm_encoder *encoder; |
| 1113 | struct intel_connector *intel_connector; |
| 1114 | struct drm_connector *connector; |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1115 | struct drm_display_mode *scan, *fixed_mode = NULL; |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 1116 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 1117 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1118 | unsigned int i; |
| 1119 | |
| 1120 | DRM_DEBUG_KMS("\n"); |
| 1121 | |
Shobhit Kumar | 3e6bd01 | 2014-05-27 19:33:59 +0530 | [diff] [blame] | 1122 | /* There is no detection method for MIPI so rely on VBT */ |
| 1123 | if (!dev_priv->vbt.has_mipi) |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1124 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1125 | |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 1126 | if (IS_VALLEYVIEW(dev)) { |
| 1127 | dev_priv->mipi_mmio_base = VLV_MIPI_BASE; |
| 1128 | } else { |
| 1129 | DRM_ERROR("Unsupported Mipi device to reg base"); |
Christoph Jaeger | 868d665 | 2014-06-13 21:51:22 +0200 | [diff] [blame] | 1130 | return; |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 1131 | } |
| 1132 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1133 | intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); |
| 1134 | if (!intel_dsi) |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1135 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1136 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 1137 | intel_connector = intel_connector_alloc(); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1138 | if (!intel_connector) { |
| 1139 | kfree(intel_dsi); |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1140 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | intel_encoder = &intel_dsi->base; |
| 1144 | encoder = &intel_encoder->base; |
| 1145 | intel_dsi->attached_connector = intel_connector; |
| 1146 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1147 | connector = &intel_connector->base; |
| 1148 | |
| 1149 | drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI); |
| 1150 | |
| 1151 | /* XXX: very likely not all of these are needed */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1152 | intel_encoder->compute_config = intel_dsi_compute_config; |
| 1153 | intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable; |
| 1154 | intel_encoder->pre_enable = intel_dsi_pre_enable; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 1155 | intel_encoder->enable = intel_dsi_enable_nop; |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 1156 | intel_encoder->disable = intel_dsi_pre_disable; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1157 | intel_encoder->post_disable = intel_dsi_post_disable; |
| 1158 | intel_encoder->get_hw_state = intel_dsi_get_hw_state; |
| 1159 | intel_encoder->get_config = intel_dsi_get_config; |
| 1160 | |
| 1161 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 1162 | intel_connector->unregister = intel_connector_unregister; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1163 | |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1164 | /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */ |
Gaurav K Singh | 8242578 | 2015-08-03 15:45:32 +0530 | [diff] [blame] | 1165 | if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1166 | intel_encoder->crtc_mask = (1 << PIPE_A); |
Jani Nikula | 17af40a | 2014-11-14 16:54:22 +0200 | [diff] [blame] | 1167 | intel_dsi->ports = (1 << PORT_A); |
| 1168 | } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1169 | intel_encoder->crtc_mask = (1 << PIPE_B); |
Jani Nikula | 17af40a | 2014-11-14 16:54:22 +0200 | [diff] [blame] | 1170 | intel_dsi->ports = (1 << PORT_C); |
| 1171 | } |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1172 | |
Gaurav K Singh | 8242578 | 2015-08-03 15:45:32 +0530 | [diff] [blame] | 1173 | if (dev_priv->vbt.dsi.config->dual_link) |
| 1174 | intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C)); |
| 1175 | |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 1176 | /* Create a DSI host (and a device) for each port. */ |
| 1177 | for_each_dsi_port(port, intel_dsi->ports) { |
| 1178 | struct intel_dsi_host *host; |
| 1179 | |
| 1180 | host = intel_dsi_host_init(intel_dsi, port); |
| 1181 | if (!host) |
| 1182 | goto err; |
| 1183 | |
| 1184 | intel_dsi->dsi_hosts[port] = host; |
| 1185 | } |
| 1186 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1187 | for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) { |
| 1188 | intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi, |
| 1189 | intel_dsi_drivers[i].panel_id); |
| 1190 | if (intel_dsi->panel) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1191 | break; |
| 1192 | } |
| 1193 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1194 | if (!intel_dsi->panel) { |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1195 | DRM_DEBUG_KMS("no device found\n"); |
| 1196 | goto err; |
| 1197 | } |
| 1198 | |
Shobhit Kumar | fc45e82 | 2015-06-26 14:32:09 +0530 | [diff] [blame] | 1199 | /* |
| 1200 | * In case of BYT with CRC PMIC, we need to use GPIO for |
| 1201 | * Panel control. |
| 1202 | */ |
| 1203 | if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) { |
| 1204 | intel_dsi->gpio_panel = |
| 1205 | gpiod_get(dev->dev, "panel", GPIOD_OUT_HIGH); |
| 1206 | |
| 1207 | if (IS_ERR(intel_dsi->gpio_panel)) { |
| 1208 | DRM_ERROR("Failed to own gpio for panel control\n"); |
| 1209 | intel_dsi->gpio_panel = NULL; |
| 1210 | } |
| 1211 | } |
| 1212 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1213 | intel_encoder->type = INTEL_OUTPUT_DSI; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 1214 | intel_encoder->cloneable = 0; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1215 | drm_connector_init(dev, connector, &intel_dsi_connector_funcs, |
| 1216 | DRM_MODE_CONNECTOR_DSI); |
| 1217 | |
| 1218 | drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs); |
| 1219 | |
| 1220 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/ |
| 1221 | connector->interlace_allowed = false; |
| 1222 | connector->doublescan_allowed = false; |
| 1223 | |
| 1224 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
| 1225 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1226 | drm_connector_register(connector); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1227 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1228 | drm_panel_attach(intel_dsi->panel, connector); |
| 1229 | |
| 1230 | mutex_lock(&dev->mode_config.mutex); |
| 1231 | drm_panel_get_modes(intel_dsi->panel); |
| 1232 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 1233 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 1234 | fixed_mode = drm_mode_duplicate(dev, scan); |
| 1235 | break; |
| 1236 | } |
| 1237 | } |
| 1238 | mutex_unlock(&dev->mode_config.mutex); |
| 1239 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1240 | if (!fixed_mode) { |
| 1241 | DRM_DEBUG_KMS("no fixed mode\n"); |
| 1242 | goto err; |
| 1243 | } |
| 1244 | |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1245 | intel_panel_init(&intel_connector->panel, fixed_mode, NULL); |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1246 | intel_panel_setup_backlight(connector, INVALID_PIPE); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1247 | |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1248 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1249 | |
| 1250 | err: |
| 1251 | drm_encoder_cleanup(&intel_encoder->base); |
| 1252 | kfree(intel_dsi); |
| 1253 | kfree(intel_connector); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1254 | } |