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> |
| 34 | #include "i915_drv.h" |
| 35 | #include "intel_drv.h" |
| 36 | #include "intel_dsi.h" |
| 37 | #include "intel_dsi_cmd.h" |
| 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 | |
Shobhit Kumar | e9fe51c | 2013-12-10 12:14:55 +0530 | [diff] [blame] | 206 | static void band_gap_reset(struct drm_i915_private *dev_priv) |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 207 | { |
| 208 | mutex_lock(&dev_priv->dpio_lock); |
| 209 | |
Shobhit Kumar | e9fe51c | 2013-12-10 12:14:55 +0530 | [diff] [blame] | 210 | vlv_flisdsi_write(dev_priv, 0x08, 0x0001); |
| 211 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0005); |
| 212 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0025); |
| 213 | udelay(150); |
| 214 | vlv_flisdsi_write(dev_priv, 0x0F, 0x0000); |
| 215 | vlv_flisdsi_write(dev_priv, 0x08, 0x0000); |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 216 | |
| 217 | mutex_unlock(&dev_priv->dpio_lock); |
Shobhit Kumar | 4ce8c9a | 2013-08-27 15:12:24 +0300 | [diff] [blame] | 218 | } |
| 219 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 220 | static inline bool is_vid_mode(struct intel_dsi *intel_dsi) |
| 221 | { |
Shobhit Kumar | dfba2e2 | 2014-04-14 11:18:24 +0530 | [diff] [blame] | 222 | return intel_dsi->operation_mode == INTEL_DSI_VIDEO_MODE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static inline bool is_cmd_mode(struct intel_dsi *intel_dsi) |
| 226 | { |
Shobhit Kumar | dfba2e2 | 2014-04-14 11:18:24 +0530 | [diff] [blame] | 227 | return intel_dsi->operation_mode == INTEL_DSI_COMMAND_MODE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static void intel_dsi_hot_plug(struct intel_encoder *encoder) |
| 231 | { |
| 232 | DRM_DEBUG_KMS("\n"); |
| 233 | } |
| 234 | |
| 235 | static bool intel_dsi_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 236 | struct intel_crtc_state *config) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 237 | { |
| 238 | struct intel_dsi *intel_dsi = container_of(encoder, struct intel_dsi, |
| 239 | base); |
| 240 | struct intel_connector *intel_connector = intel_dsi->attached_connector; |
| 241 | 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] | 242 | struct drm_display_mode *adjusted_mode = &config->base.adjusted_mode; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 243 | |
| 244 | DRM_DEBUG_KMS("\n"); |
| 245 | |
| 246 | if (fixed_mode) |
| 247 | intel_fixed_panel_mode(fixed_mode, adjusted_mode); |
| 248 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 249 | /* DSI uses short packets for sync events, so clear mode flags for DSI */ |
| 250 | adjusted_mode->flags = 0; |
| 251 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 255 | static void intel_dsi_port_enable(struct intel_encoder *encoder) |
| 256 | { |
| 257 | struct drm_device *dev = encoder->base.dev; |
| 258 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 259 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 260 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 261 | enum port port; |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 262 | u32 temp; |
| 263 | |
Gaurav K Singh | a9da9bc | 2014-12-05 14:13:41 +0530 | [diff] [blame] | 264 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) { |
| 265 | temp = I915_READ(VLV_CHICKEN_3); |
| 266 | temp &= ~PIXEL_OVERLAP_CNT_MASK | |
| 267 | intel_dsi->pixel_overlap << |
| 268 | PIXEL_OVERLAP_CNT_SHIFT; |
| 269 | I915_WRITE(VLV_CHICKEN_3, temp); |
| 270 | } |
| 271 | |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 272 | for_each_dsi_port(port, intel_dsi->ports) { |
| 273 | temp = I915_READ(MIPI_PORT_CTRL(port)); |
| 274 | temp &= ~LANE_CONFIGURATION_MASK; |
| 275 | temp &= ~DUAL_LINK_MODE_MASK; |
| 276 | |
| 277 | if (intel_dsi->ports == ((1 << PORT_A) | (1 << PORT_C))) { |
| 278 | temp |= (intel_dsi->dual_link - 1) |
| 279 | << DUAL_LINK_MODE_SHIFT; |
| 280 | temp |= intel_crtc->pipe ? |
| 281 | LANE_CONFIGURATION_DUAL_LINK_B : |
| 282 | LANE_CONFIGURATION_DUAL_LINK_A; |
| 283 | } |
| 284 | /* assert ip_tg_enable signal */ |
| 285 | I915_WRITE(MIPI_PORT_CTRL(port), temp | DPI_ENABLE); |
| 286 | POSTING_READ(MIPI_PORT_CTRL(port)); |
| 287 | } |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void intel_dsi_port_disable(struct intel_encoder *encoder) |
| 291 | { |
| 292 | struct drm_device *dev = encoder->base.dev; |
| 293 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 294 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 295 | enum port port; |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 296 | u32 temp; |
| 297 | |
Gaurav K Singh | 369602d | 2014-12-05 14:09:28 +0530 | [diff] [blame] | 298 | for_each_dsi_port(port, intel_dsi->ports) { |
| 299 | /* de-assert ip_tg_enable signal */ |
| 300 | temp = I915_READ(MIPI_PORT_CTRL(port)); |
| 301 | I915_WRITE(MIPI_PORT_CTRL(port), temp & ~DPI_ENABLE); |
| 302 | POSTING_READ(MIPI_PORT_CTRL(port)); |
| 303 | } |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 304 | } |
| 305 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 306 | static void intel_dsi_device_ready(struct intel_encoder *encoder) |
| 307 | { |
| 308 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 309 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 310 | enum port port; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 311 | u32 val; |
| 312 | |
| 313 | DRM_DEBUG_KMS("\n"); |
| 314 | |
Shobhit Kumar | 2095f9f | 2014-04-09 13:59:30 +0530 | [diff] [blame] | 315 | mutex_lock(&dev_priv->dpio_lock); |
| 316 | /* program rcomp for compliance, reduce from 50 ohms to 45 ohms |
| 317 | * needed everytime after power gate */ |
| 318 | vlv_flisdsi_write(dev_priv, 0x04, 0x0004); |
| 319 | mutex_unlock(&dev_priv->dpio_lock); |
| 320 | |
| 321 | /* bandgap reset is needed after everytime we do power gate */ |
| 322 | band_gap_reset(dev_priv); |
| 323 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 324 | for_each_dsi_port(port, intel_dsi->ports) { |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 325 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 326 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_ENTER); |
| 327 | usleep_range(2500, 3000); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 328 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 329 | val = I915_READ(MIPI_PORT_CTRL(port)); |
Gaurav K Singh | bf344e8 | 2014-12-07 16:13:54 +0530 | [diff] [blame] | 330 | |
| 331 | /* Enable MIPI PHY transparent latch |
| 332 | * Common bit for both MIPI Port A & MIPI Port C |
| 333 | * No similar bit in MIPI Port C reg |
| 334 | */ |
| 335 | I915_WRITE(MIPI_PORT_CTRL(PORT_A), val | LP_OUTPUT_HOLD); |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 336 | usleep_range(1000, 1500); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 337 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 338 | I915_WRITE(MIPI_DEVICE_READY(port), ULPS_STATE_EXIT); |
| 339 | usleep_range(2500, 3000); |
| 340 | |
| 341 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY); |
| 342 | usleep_range(2500, 3000); |
| 343 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 344 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 345 | |
| 346 | static void intel_dsi_enable(struct intel_encoder *encoder) |
| 347 | { |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 348 | struct drm_device *dev = encoder->base.dev; |
| 349 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 350 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Jani Nikula | 4934b65 | 2015-01-22 15:01:35 +0200 | [diff] [blame] | 351 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 352 | |
| 353 | DRM_DEBUG_KMS("\n"); |
| 354 | |
Jani Nikula | 4934b65 | 2015-01-22 15:01:35 +0200 | [diff] [blame] | 355 | if (is_cmd_mode(intel_dsi)) { |
| 356 | for_each_dsi_port(port, intel_dsi->ports) |
| 357 | I915_WRITE(MIPI_MAX_RETURN_PKT_SIZE(port), 8 * 4); |
| 358 | } else { |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 359 | msleep(20); /* XXX */ |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 360 | for_each_dsi_port(port, intel_dsi->ports) |
| 361 | dpi_send_cmd(intel_dsi, TURN_ON, DPI_LP_MODE_EN, port); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 362 | msleep(100); |
| 363 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 364 | drm_panel_enable(intel_dsi->panel); |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 365 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 366 | for_each_dsi_port(port, intel_dsi->ports) |
| 367 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 368 | |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 369 | intel_dsi_port_enable(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 370 | } |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 371 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 372 | |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 373 | static void intel_dsi_pre_enable(struct intel_encoder *encoder) |
| 374 | { |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 375 | struct drm_device *dev = encoder->base.dev; |
| 376 | struct drm_i915_private *dev_priv = dev->dev_private; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 377 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 378 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 379 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 380 | enum port port; |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 381 | u32 tmp; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 382 | |
| 383 | DRM_DEBUG_KMS("\n"); |
| 384 | |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 385 | /* Disable DPOunit clock gating, can stall pipe |
| 386 | * and we need DPLL REFA always enabled */ |
| 387 | tmp = I915_READ(DPLL(pipe)); |
| 388 | tmp |= DPLL_REFA_CLK_ENABLE_VLV; |
| 389 | I915_WRITE(DPLL(pipe), tmp); |
| 390 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 391 | /* update the hw state for DPLL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 392 | intel_crtc->config->dpll_hw_state.dpll = DPLL_INTEGRATED_CLOCK_VLV | |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 393 | DPLL_REFA_CLK_ENABLE_VLV; |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 394 | |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 395 | tmp = I915_READ(DSPCLK_GATE_D); |
| 396 | tmp |= DPOUNIT_CLOCK_GATE_DISABLE; |
| 397 | I915_WRITE(DSPCLK_GATE_D, tmp); |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 398 | |
| 399 | /* put device in ready state */ |
| 400 | intel_dsi_device_ready(encoder); |
| 401 | |
Shobhit Kumar | df38e65 | 2014-04-14 11:18:26 +0530 | [diff] [blame] | 402 | msleep(intel_dsi->panel_on_delay); |
| 403 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 404 | drm_panel_prepare(intel_dsi->panel); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 405 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 406 | for_each_dsi_port(port, intel_dsi->ports) |
| 407 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 408 | |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 409 | /* Enable port in pre-enable phase itself because as per hw team |
| 410 | * recommendation, port should be enabled befor plane & pipe */ |
| 411 | intel_dsi_enable(encoder); |
| 412 | } |
| 413 | |
| 414 | static void intel_dsi_enable_nop(struct intel_encoder *encoder) |
| 415 | { |
| 416 | DRM_DEBUG_KMS("\n"); |
| 417 | |
| 418 | /* for DSI port enable has to be done before pipe |
| 419 | * and plane enable, so port enable is done in |
| 420 | * pre_enable phase itself unlike other encoders |
| 421 | */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 422 | } |
| 423 | |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 424 | static void intel_dsi_pre_disable(struct intel_encoder *encoder) |
| 425 | { |
| 426 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 427 | enum port port; |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 428 | |
| 429 | DRM_DEBUG_KMS("\n"); |
| 430 | |
| 431 | if (is_vid_mode(intel_dsi)) { |
| 432 | /* Send Shutdown command to the panel in LP mode */ |
Jani Nikula | f03e417 | 2015-01-16 14:27:16 +0200 | [diff] [blame] | 433 | for_each_dsi_port(port, intel_dsi->ports) |
| 434 | dpi_send_cmd(intel_dsi, SHUTDOWN, DPI_LP_MODE_EN, port); |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 435 | msleep(10); |
| 436 | } |
| 437 | } |
| 438 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 439 | static void intel_dsi_disable(struct intel_encoder *encoder) |
| 440 | { |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 441 | struct drm_device *dev = encoder->base.dev; |
| 442 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 443 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 444 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 445 | u32 temp; |
| 446 | |
| 447 | DRM_DEBUG_KMS("\n"); |
| 448 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 449 | if (is_vid_mode(intel_dsi)) { |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 450 | for_each_dsi_port(port, intel_dsi->ports) |
| 451 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 452 | |
Gaurav K Singh | 5505a24 | 2014-12-04 10:58:47 +0530 | [diff] [blame] | 453 | intel_dsi_port_disable(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 454 | msleep(2); |
| 455 | } |
| 456 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 457 | for_each_dsi_port(port, intel_dsi->ports) { |
| 458 | /* Panel commands can be sent when clock is in LP11 */ |
| 459 | I915_WRITE(MIPI_DEVICE_READY(port), 0x0); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 460 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 461 | temp = I915_READ(MIPI_CTRL(port)); |
| 462 | temp &= ~ESCAPE_CLOCK_DIVIDER_MASK; |
| 463 | I915_WRITE(MIPI_CTRL(port), temp | |
| 464 | intel_dsi->escape_clk_div << |
| 465 | ESCAPE_CLOCK_DIVIDER_SHIFT); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 466 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 467 | I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 468 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 469 | temp = I915_READ(MIPI_DSI_FUNC_PRG(port)); |
| 470 | temp &= ~VID_MODE_FORMAT_MASK; |
| 471 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), temp); |
Shobhit Kumar | 339023e | 2014-04-09 13:59:34 +0530 | [diff] [blame] | 472 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 473 | I915_WRITE(MIPI_DEVICE_READY(port), 0x1); |
| 474 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 475 | /* if disable packets are sent before sending shutdown packet then in |
| 476 | * some next enable sequence send turn on packet error is observed */ |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 477 | drm_panel_disable(intel_dsi->panel); |
Shobhit Kumar | 1381308 | 2014-07-12 17:17:22 +0530 | [diff] [blame] | 478 | |
Jani Nikula | 7f6a6a4 | 2015-01-16 14:27:19 +0200 | [diff] [blame] | 479 | for_each_dsi_port(port, intel_dsi->ports) |
| 480 | wait_for_dsi_fifo_empty(intel_dsi, port); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 481 | } |
| 482 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 483 | static void intel_dsi_clear_device_ready(struct intel_encoder *encoder) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 484 | { |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 485 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 486 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 487 | enum port port; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 488 | u32 val; |
| 489 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 490 | DRM_DEBUG_KMS("\n"); |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 491 | for_each_dsi_port(port, intel_dsi->ports) { |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 492 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 493 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 494 | ULPS_STATE_ENTER); |
| 495 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 496 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 497 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 498 | ULPS_STATE_EXIT); |
| 499 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 500 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 501 | I915_WRITE(MIPI_DEVICE_READY(port), DEVICE_READY | |
| 502 | ULPS_STATE_ENTER); |
| 503 | usleep_range(2000, 2500); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 504 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 505 | /* Wait till Clock lanes are in LP-00 state for MIPI Port A |
| 506 | * only. MIPI Port C has no similar bit for checking |
| 507 | */ |
| 508 | if (wait_for(((I915_READ(MIPI_PORT_CTRL(PORT_A)) & AFE_LATCHOUT) |
| 509 | == 0x00000), 30)) |
| 510 | DRM_ERROR("DSI LP not going Low\n"); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 511 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 512 | val = I915_READ(MIPI_PORT_CTRL(port)); |
| 513 | /* Disable MIPI PHY transparent latch |
| 514 | * Common bit for both MIPI Port A & MIPI Port C |
| 515 | */ |
| 516 | I915_WRITE(MIPI_PORT_CTRL(PORT_A), val & ~LP_OUTPUT_HOLD); |
| 517 | usleep_range(1000, 1500); |
Shobhit Kumar | aceb365 | 2014-07-03 16:35:41 +0530 | [diff] [blame] | 518 | |
Gaurav K Singh | 384f02a | 2014-12-05 14:22:44 +0530 | [diff] [blame] | 519 | I915_WRITE(MIPI_DEVICE_READY(port), 0x00); |
| 520 | usleep_range(2000, 2500); |
| 521 | } |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 522 | |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 523 | vlv_disable_dsi_pll(encoder); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 524 | } |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 525 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 526 | static void intel_dsi_post_disable(struct intel_encoder *encoder) |
| 527 | { |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 528 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 529 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 530 | u32 val; |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 531 | |
| 532 | DRM_DEBUG_KMS("\n"); |
| 533 | |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 534 | intel_dsi_disable(encoder); |
| 535 | |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 536 | intel_dsi_clear_device_ready(encoder); |
| 537 | |
Shobhit Kumar | 20e5bf6 | 2014-04-09 13:59:32 +0530 | [diff] [blame] | 538 | val = I915_READ(DSPCLK_GATE_D); |
| 539 | val &= ~DPOUNIT_CLOCK_GATE_DISABLE; |
| 540 | I915_WRITE(DSPCLK_GATE_D, val); |
| 541 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 542 | drm_panel_unprepare(intel_dsi->panel); |
Shobhit Kumar | df38e65 | 2014-04-14 11:18:26 +0530 | [diff] [blame] | 543 | |
| 544 | msleep(intel_dsi->panel_off_delay); |
| 545 | msleep(intel_dsi->panel_pwr_cycle_delay); |
Shobhit Kumar | 1dbd7cb | 2013-12-11 17:52:05 +0530 | [diff] [blame] | 546 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 547 | |
| 548 | static bool intel_dsi_get_hw_state(struct intel_encoder *encoder, |
| 549 | enum pipe *pipe) |
| 550 | { |
| 551 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 552 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 553 | struct drm_device *dev = encoder->base.dev; |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 554 | enum intel_display_power_domain power_domain; |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 555 | u32 dpi_enabled, func; |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 556 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 557 | |
| 558 | DRM_DEBUG_KMS("\n"); |
| 559 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 560 | power_domain = intel_display_port_power_domain(encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 561 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 562 | return false; |
| 563 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 564 | /* XXX: this only works for one DSI output */ |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 565 | for_each_dsi_port(port, intel_dsi->ports) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 566 | func = I915_READ(MIPI_DSI_FUNC_PRG(port)); |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 567 | dpi_enabled = I915_READ(MIPI_PORT_CTRL(port)) & |
| 568 | DPI_ENABLE; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 569 | |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 570 | /* Due to some hardware limitations on BYT, MIPI Port C DPI |
| 571 | * Enable bit does not get set. To check whether DSI Port C |
| 572 | * was enabled in BIOS, check the Pipe B enable bit |
| 573 | */ |
| 574 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
| 575 | (port == PORT_C)) |
| 576 | dpi_enabled = I915_READ(PIPECONF(PIPE_B)) & |
| 577 | PIPECONF_ENABLE; |
| 578 | |
| 579 | if (dpi_enabled || (func & CMD_MODE_DATA_WIDTH_MASK)) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 580 | if (I915_READ(MIPI_DEVICE_READY(port)) & DEVICE_READY) { |
Gaurav K Singh | c0beefd | 2014-12-09 10:59:20 +0530 | [diff] [blame] | 581 | *pipe = port == PORT_A ? PIPE_A : PIPE_B; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 582 | return true; |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | static void intel_dsi_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 591 | struct intel_crtc_state *pipe_config) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 592 | { |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 593 | u32 pclk; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 594 | DRM_DEBUG_KMS("\n"); |
| 595 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 596 | /* |
| 597 | * DPLL_MD is not used in case of DSI, reading will get some default value |
| 598 | * set dpll_md = 0 |
| 599 | */ |
| 600 | pipe_config->dpll_hw_state.dpll_md = 0; |
| 601 | |
| 602 | pclk = vlv_get_dsi_pclk(encoder, pipe_config->pipe_bpp); |
| 603 | if (!pclk) |
| 604 | return; |
| 605 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 606 | pipe_config->base.adjusted_mode.crtc_clock = pclk; |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 607 | pipe_config->port_clock = pclk; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 608 | } |
| 609 | |
Damien Lespiau | c19de8e | 2013-11-28 15:29:18 +0000 | [diff] [blame] | 610 | static enum drm_mode_status |
| 611 | intel_dsi_mode_valid(struct drm_connector *connector, |
| 612 | struct drm_display_mode *mode) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 613 | { |
| 614 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 615 | struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 616 | |
| 617 | DRM_DEBUG_KMS("\n"); |
| 618 | |
| 619 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) { |
| 620 | DRM_DEBUG_KMS("MODE_NO_DBLESCAN\n"); |
| 621 | return MODE_NO_DBLESCAN; |
| 622 | } |
| 623 | |
| 624 | if (fixed_mode) { |
| 625 | if (mode->hdisplay > fixed_mode->hdisplay) |
| 626 | return MODE_PANEL; |
| 627 | if (mode->vdisplay > fixed_mode->vdisplay) |
| 628 | return MODE_PANEL; |
| 629 | } |
| 630 | |
Jani Nikula | 36d21f4 | 2015-01-16 14:27:20 +0200 | [diff] [blame] | 631 | return MODE_OK; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /* return txclkesc cycles in terms of divider and duration in us */ |
| 635 | static u16 txclkesc(u32 divider, unsigned int us) |
| 636 | { |
| 637 | switch (divider) { |
| 638 | case ESCAPE_CLOCK_DIVIDER_1: |
| 639 | default: |
| 640 | return 20 * us; |
| 641 | case ESCAPE_CLOCK_DIVIDER_2: |
| 642 | return 10 * us; |
| 643 | case ESCAPE_CLOCK_DIVIDER_4: |
| 644 | return 5 * us; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /* return pixels in terms of txbyteclkhs */ |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 649 | static u16 txbyteclkhs(u16 pixels, int bpp, int lane_count, |
| 650 | u16 burst_mode_ratio) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 651 | { |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 652 | return DIV_ROUND_UP(DIV_ROUND_UP(pixels * bpp * burst_mode_ratio, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 653 | 8 * 100), lane_count); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static void set_dsi_timings(struct drm_encoder *encoder, |
| 657 | const struct drm_display_mode *mode) |
| 658 | { |
| 659 | struct drm_device *dev = encoder->dev; |
| 660 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 661 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 662 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 663 | enum port port; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 664 | unsigned int bpp = intel_crtc->config->pipe_bpp; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 665 | unsigned int lane_count = intel_dsi->lane_count; |
| 666 | |
| 667 | u16 hactive, hfp, hsync, hbp, vfp, vsync, vbp; |
| 668 | |
| 669 | hactive = mode->hdisplay; |
| 670 | hfp = mode->hsync_start - mode->hdisplay; |
| 671 | hsync = mode->hsync_end - mode->hsync_start; |
| 672 | hbp = mode->htotal - mode->hsync_end; |
| 673 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 674 | if (intel_dsi->dual_link) { |
| 675 | hactive /= 2; |
| 676 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) |
| 677 | hactive += intel_dsi->pixel_overlap; |
| 678 | hfp /= 2; |
| 679 | hsync /= 2; |
| 680 | hbp /= 2; |
| 681 | } |
| 682 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 683 | vfp = mode->vsync_start - mode->vdisplay; |
| 684 | vsync = mode->vsync_end - mode->vsync_start; |
| 685 | vbp = mode->vtotal - mode->vsync_end; |
| 686 | |
| 687 | /* horizontal values are in terms of high speed byte clock */ |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 688 | hactive = txbyteclkhs(hactive, bpp, lane_count, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 689 | intel_dsi->burst_mode_ratio); |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 690 | hfp = txbyteclkhs(hfp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
| 691 | hsync = txbyteclkhs(hsync, bpp, lane_count, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 692 | intel_dsi->burst_mode_ratio); |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 693 | hbp = txbyteclkhs(hbp, bpp, lane_count, intel_dsi->burst_mode_ratio); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 694 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 695 | for_each_dsi_port(port, intel_dsi->ports) { |
| 696 | I915_WRITE(MIPI_HACTIVE_AREA_COUNT(port), hactive); |
| 697 | I915_WRITE(MIPI_HFP_COUNT(port), hfp); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 698 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 699 | /* meaningful for video mode non-burst sync pulse mode only, |
| 700 | * can be zero for non-burst sync events and burst modes */ |
| 701 | I915_WRITE(MIPI_HSYNC_PADDING_COUNT(port), hsync); |
| 702 | I915_WRITE(MIPI_HBP_COUNT(port), hbp); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 703 | |
Gaurav K Singh | aa102d2 | 2014-12-04 10:58:54 +0530 | [diff] [blame] | 704 | /* vertical values are in terms of lines */ |
| 705 | I915_WRITE(MIPI_VFP_COUNT(port), vfp); |
| 706 | I915_WRITE(MIPI_VSYNC_PADDING_COUNT(port), vsync); |
| 707 | I915_WRITE(MIPI_VBP_COUNT(port), vbp); |
| 708 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 709 | } |
| 710 | |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 711 | static void intel_dsi_prepare(struct intel_encoder *intel_encoder) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 712 | { |
| 713 | struct drm_encoder *encoder = &intel_encoder->base; |
| 714 | struct drm_device *dev = encoder->dev; |
| 715 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 716 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 717 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
| 718 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 719 | &intel_crtc->config->base.adjusted_mode; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 720 | enum port port; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 721 | unsigned int bpp = intel_crtc->config->pipe_bpp; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 722 | u32 val, tmp; |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 723 | u16 mode_hdisplay; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 724 | |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 725 | DRM_DEBUG_KMS("pipe %c\n", pipe_name(intel_crtc->pipe)); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 726 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 727 | mode_hdisplay = adjusted_mode->hdisplay; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 728 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 729 | if (intel_dsi->dual_link) { |
| 730 | mode_hdisplay /= 2; |
| 731 | if (intel_dsi->dual_link == DSI_DUAL_LINK_FRONT_BACK) |
| 732 | mode_hdisplay += intel_dsi->pixel_overlap; |
| 733 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 734 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 735 | for_each_dsi_port(port, intel_dsi->ports) { |
| 736 | /* escape clock divider, 20MHz, shared for A and C. |
| 737 | * device ready must be off when doing this! txclkesc? */ |
| 738 | tmp = I915_READ(MIPI_CTRL(PORT_A)); |
| 739 | tmp &= ~ESCAPE_CLOCK_DIVIDER_MASK; |
| 740 | I915_WRITE(MIPI_CTRL(PORT_A), tmp | ESCAPE_CLOCK_DIVIDER_1); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 741 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 742 | /* read request priority is per pipe */ |
| 743 | tmp = I915_READ(MIPI_CTRL(port)); |
| 744 | tmp &= ~READ_REQUEST_PRIORITY_MASK; |
| 745 | I915_WRITE(MIPI_CTRL(port), tmp | READ_REQUEST_PRIORITY_HIGH); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 746 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 747 | /* XXX: why here, why like this? handling in irq handler?! */ |
| 748 | I915_WRITE(MIPI_INTR_STAT(port), 0xffffffff); |
| 749 | I915_WRITE(MIPI_INTR_EN(port), 0xffffffff); |
| 750 | |
| 751 | I915_WRITE(MIPI_DPHY_PARAM(port), intel_dsi->dphy_reg); |
| 752 | |
| 753 | I915_WRITE(MIPI_DPI_RESOLUTION(port), |
| 754 | adjusted_mode->vdisplay << VERTICAL_ADDRESS_SHIFT | |
| 755 | mode_hdisplay << HORIZONTAL_ADDRESS_SHIFT); |
| 756 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 757 | |
| 758 | set_dsi_timings(encoder, adjusted_mode); |
| 759 | |
| 760 | val = intel_dsi->lane_count << DATA_LANES_PRG_REG_SHIFT; |
| 761 | if (is_cmd_mode(intel_dsi)) { |
| 762 | val |= intel_dsi->channel << CMD_MODE_CHANNEL_NUMBER_SHIFT; |
| 763 | val |= CMD_MODE_DATA_WIDTH_8_BIT; /* XXX */ |
| 764 | } else { |
| 765 | val |= intel_dsi->channel << VID_MODE_CHANNEL_NUMBER_SHIFT; |
| 766 | |
| 767 | /* XXX: cross-check bpp vs. pixel format? */ |
| 768 | val |= intel_dsi->pixel_format; |
| 769 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 770 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 771 | tmp = 0; |
Shobhit Kumar | f1c79f1 | 2014-04-09 13:59:33 +0530 | [diff] [blame] | 772 | if (intel_dsi->eotp_pkt == 0) |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 773 | tmp |= EOT_DISABLE; |
Shobhit Kumar | f1c79f1 | 2014-04-09 13:59:33 +0530 | [diff] [blame] | 774 | if (intel_dsi->clock_stop) |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 775 | tmp |= CLOCKSTOP; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 776 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 777 | for_each_dsi_port(port, intel_dsi->ports) { |
| 778 | I915_WRITE(MIPI_DSI_FUNC_PRG(port), val); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 779 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 780 | /* timeouts for recovery. one frame IIUC. if counter expires, |
| 781 | * EOT and stop state. */ |
Shobhit Kumar | cf4dbd2 | 2014-04-14 11:18:25 +0530 | [diff] [blame] | 782 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 783 | /* |
| 784 | * In burst mode, value greater than one DPI line Time in byte |
| 785 | * clock (txbyteclkhs) To timeout this timer 1+ of the above |
| 786 | * said value is recommended. |
| 787 | * |
| 788 | * In non-burst mode, Value greater than one DPI frame time in |
| 789 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above |
| 790 | * said value is recommended. |
| 791 | * |
| 792 | * In DBI only mode, value greater than one DBI frame time in |
| 793 | * byte clock(txbyteclkhs) To timeout this timer 1+ of the above |
| 794 | * said value is recommended. |
| 795 | */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 796 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 797 | if (is_vid_mode(intel_dsi) && |
| 798 | intel_dsi->video_mode_format == VIDEO_MODE_BURST) { |
| 799 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), |
| 800 | txbyteclkhs(adjusted_mode->htotal, bpp, |
| 801 | intel_dsi->lane_count, |
| 802 | intel_dsi->burst_mode_ratio) + 1); |
| 803 | } else { |
| 804 | I915_WRITE(MIPI_HS_TX_TIMEOUT(port), |
| 805 | txbyteclkhs(adjusted_mode->vtotal * |
| 806 | adjusted_mode->htotal, |
| 807 | bpp, intel_dsi->lane_count, |
| 808 | intel_dsi->burst_mode_ratio) + 1); |
| 809 | } |
| 810 | I915_WRITE(MIPI_LP_RX_TIMEOUT(port), intel_dsi->lp_rx_timeout); |
| 811 | I915_WRITE(MIPI_TURN_AROUND_TIMEOUT(port), |
| 812 | intel_dsi->turn_arnd_val); |
| 813 | I915_WRITE(MIPI_DEVICE_RESET_TIMER(port), |
| 814 | intel_dsi->rst_timer_val); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 815 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 816 | /* dphy stuff */ |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 817 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 818 | /* in terms of low power clock */ |
| 819 | I915_WRITE(MIPI_INIT_COUNT(port), |
| 820 | txclkesc(intel_dsi->escape_clk_div, 100)); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 821 | |
Gaurav K Singh | 24ee0e6 | 2014-12-05 14:24:21 +0530 | [diff] [blame] | 822 | |
| 823 | /* recovery disables */ |
| 824 | I915_WRITE(MIPI_EOT_DISABLE(port), val); |
| 825 | |
| 826 | /* in terms of low power clock */ |
| 827 | I915_WRITE(MIPI_INIT_COUNT(port), intel_dsi->init_count); |
| 828 | |
| 829 | /* in terms of txbyteclkhs. actual high to low switch + |
| 830 | * MIPI_STOP_STATE_STALL * MIPI_LP_BYTECLK. |
| 831 | * |
| 832 | * XXX: write MIPI_STOP_STATE_STALL? |
| 833 | */ |
| 834 | I915_WRITE(MIPI_HIGH_LOW_SWITCH_COUNT(port), |
| 835 | intel_dsi->hs_to_lp_count); |
| 836 | |
| 837 | /* XXX: low power clock equivalence in terms of byte clock. |
| 838 | * the number of byte clocks occupied in one low power clock. |
| 839 | * based on txbyteclkhs and txclkesc. |
| 840 | * txclkesc time / txbyteclk time * (105 + MIPI_STOP_STATE_STALL |
| 841 | * ) / 105.??? |
| 842 | */ |
| 843 | I915_WRITE(MIPI_LP_BYTECLK(port), intel_dsi->lp_byte_clk); |
| 844 | |
| 845 | /* the bw essential for transmitting 16 long packets containing |
| 846 | * 252 bytes meant for dcs write memory command is programmed in |
| 847 | * this register in terms of byte clocks. based on dsi transfer |
| 848 | * rate and the number of lanes configured the time taken to |
| 849 | * transmit 16 long packets in a dsi stream varies. */ |
| 850 | I915_WRITE(MIPI_DBI_BW_CTRL(port), intel_dsi->bw_timer); |
| 851 | |
| 852 | I915_WRITE(MIPI_CLK_LANE_SWITCH_TIME_CNT(port), |
| 853 | intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT | |
| 854 | intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT); |
| 855 | |
| 856 | if (is_vid_mode(intel_dsi)) |
| 857 | /* Some panels might have resolution which is not a |
| 858 | * multiple of 64 like 1366 x 768. Enable RANDOM |
| 859 | * resolution support for such panels by default */ |
| 860 | I915_WRITE(MIPI_VIDEO_MODE_FORMAT(port), |
| 861 | intel_dsi->video_frmt_cfg_bits | |
| 862 | intel_dsi->video_mode_format | |
| 863 | IP_TG_CONFIG | |
| 864 | RANDOM_DPI_DISPLAY_RESOLUTION); |
| 865 | } |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 866 | } |
| 867 | |
Daniel Vetter | 07e4fb9 | 2014-04-24 23:54:59 +0200 | [diff] [blame] | 868 | static void intel_dsi_pre_pll_enable(struct intel_encoder *encoder) |
| 869 | { |
| 870 | DRM_DEBUG_KMS("\n"); |
| 871 | |
| 872 | intel_dsi_prepare(encoder); |
| 873 | |
| 874 | vlv_enable_dsi_pll(encoder); |
| 875 | } |
| 876 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 877 | static enum drm_connector_status |
| 878 | intel_dsi_detect(struct drm_connector *connector, bool force) |
| 879 | { |
Jani Nikula | 36d21f4 | 2015-01-16 14:27:20 +0200 | [diff] [blame] | 880 | return connector_status_connected; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | static int intel_dsi_get_modes(struct drm_connector *connector) |
| 884 | { |
| 885 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 886 | struct drm_display_mode *mode; |
| 887 | |
| 888 | DRM_DEBUG_KMS("\n"); |
| 889 | |
| 890 | if (!intel_connector->panel.fixed_mode) { |
| 891 | DRM_DEBUG_KMS("no fixed mode\n"); |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | mode = drm_mode_duplicate(connector->dev, |
| 896 | intel_connector->panel.fixed_mode); |
| 897 | if (!mode) { |
| 898 | DRM_DEBUG_KMS("drm_mode_duplicate failed\n"); |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | drm_mode_probed_add(connector, mode); |
| 903 | return 1; |
| 904 | } |
| 905 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 906 | static void intel_dsi_connector_destroy(struct drm_connector *connector) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 907 | { |
| 908 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 909 | |
| 910 | DRM_DEBUG_KMS("\n"); |
| 911 | intel_panel_fini(&intel_connector->panel); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 912 | drm_connector_cleanup(connector); |
| 913 | kfree(connector); |
| 914 | } |
| 915 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 916 | static void intel_dsi_encoder_destroy(struct drm_encoder *encoder) |
| 917 | { |
| 918 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(encoder); |
| 919 | |
| 920 | if (intel_dsi->panel) { |
| 921 | drm_panel_detach(intel_dsi->panel); |
| 922 | /* XXX: Logically this call belongs in the panel driver. */ |
| 923 | drm_panel_remove(intel_dsi->panel); |
| 924 | } |
| 925 | intel_encoder_destroy(encoder); |
| 926 | } |
| 927 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 928 | static const struct drm_encoder_funcs intel_dsi_funcs = { |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 929 | .destroy = intel_dsi_encoder_destroy, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 930 | }; |
| 931 | |
| 932 | static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs = { |
| 933 | .get_modes = intel_dsi_get_modes, |
| 934 | .mode_valid = intel_dsi_mode_valid, |
| 935 | .best_encoder = intel_best_encoder, |
| 936 | }; |
| 937 | |
| 938 | static const struct drm_connector_funcs intel_dsi_connector_funcs = { |
| 939 | .dpms = intel_connector_dpms, |
| 940 | .detect = intel_dsi_detect, |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 941 | .destroy = intel_dsi_connector_destroy, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 942 | .fill_modes = drm_helper_probe_single_connector_modes, |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 943 | .atomic_get_property = intel_connector_atomic_get_property, |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 944 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 945 | }; |
| 946 | |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 947 | void intel_dsi_init(struct drm_device *dev) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 948 | { |
| 949 | struct intel_dsi *intel_dsi; |
| 950 | struct intel_encoder *intel_encoder; |
| 951 | struct drm_encoder *encoder; |
| 952 | struct intel_connector *intel_connector; |
| 953 | struct drm_connector *connector; |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 954 | struct drm_display_mode *scan, *fixed_mode = NULL; |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 955 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 956 | enum port port; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 957 | unsigned int i; |
| 958 | |
| 959 | DRM_DEBUG_KMS("\n"); |
| 960 | |
Shobhit Kumar | 3e6bd01 | 2014-05-27 19:33:59 +0530 | [diff] [blame] | 961 | /* There is no detection method for MIPI so rely on VBT */ |
| 962 | if (!dev_priv->vbt.has_mipi) |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 963 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 964 | |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 965 | if (IS_VALLEYVIEW(dev)) { |
| 966 | dev_priv->mipi_mmio_base = VLV_MIPI_BASE; |
| 967 | } else { |
| 968 | DRM_ERROR("Unsupported Mipi device to reg base"); |
Christoph Jaeger | 868d665 | 2014-06-13 21:51:22 +0200 | [diff] [blame] | 969 | return; |
Shashank Sharma | b6fdd0f | 2014-05-19 20:54:03 +0530 | [diff] [blame] | 970 | } |
| 971 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 972 | intel_dsi = kzalloc(sizeof(*intel_dsi), GFP_KERNEL); |
| 973 | if (!intel_dsi) |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 974 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 975 | |
| 976 | intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL); |
| 977 | if (!intel_connector) { |
| 978 | kfree(intel_dsi); |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 979 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | intel_encoder = &intel_dsi->base; |
| 983 | encoder = &intel_encoder->base; |
| 984 | intel_dsi->attached_connector = intel_connector; |
| 985 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 986 | connector = &intel_connector->base; |
| 987 | |
| 988 | drm_encoder_init(dev, encoder, &intel_dsi_funcs, DRM_MODE_ENCODER_DSI); |
| 989 | |
| 990 | /* XXX: very likely not all of these are needed */ |
| 991 | intel_encoder->hot_plug = intel_dsi_hot_plug; |
| 992 | intel_encoder->compute_config = intel_dsi_compute_config; |
| 993 | intel_encoder->pre_pll_enable = intel_dsi_pre_pll_enable; |
| 994 | intel_encoder->pre_enable = intel_dsi_pre_enable; |
Shobhit Kumar | 2634fd7 | 2014-04-09 13:59:31 +0530 | [diff] [blame] | 995 | intel_encoder->enable = intel_dsi_enable_nop; |
Imre Deak | c315faf | 2014-05-27 19:00:09 +0300 | [diff] [blame] | 996 | intel_encoder->disable = intel_dsi_pre_disable; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 997 | intel_encoder->post_disable = intel_dsi_post_disable; |
| 998 | intel_encoder->get_hw_state = intel_dsi_get_hw_state; |
| 999 | intel_encoder->get_config = intel_dsi_get_config; |
| 1000 | |
| 1001 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 1002 | intel_connector->unregister = intel_connector_unregister; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1003 | |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1004 | /* Pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI port C */ |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 1005 | if (dev_priv->vbt.dsi.config->dual_link) { |
| 1006 | /* XXX: does dual link work on either pipe? */ |
| 1007 | intel_encoder->crtc_mask = (1 << PIPE_A); |
| 1008 | intel_dsi->ports = ((1 << PORT_A) | (1 << PORT_C)); |
| 1009 | } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIA) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1010 | intel_encoder->crtc_mask = (1 << PIPE_A); |
Jani Nikula | 17af40a | 2014-11-14 16:54:22 +0200 | [diff] [blame] | 1011 | intel_dsi->ports = (1 << PORT_A); |
| 1012 | } else if (dev_priv->vbt.dsi.port == DVO_PORT_MIPIC) { |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1013 | intel_encoder->crtc_mask = (1 << PIPE_B); |
Jani Nikula | 17af40a | 2014-11-14 16:54:22 +0200 | [diff] [blame] | 1014 | intel_dsi->ports = (1 << PORT_C); |
| 1015 | } |
Jani Nikula | e7d7cad | 2014-11-14 16:54:21 +0200 | [diff] [blame] | 1016 | |
Jani Nikula | 7e9804f | 2015-01-16 14:27:23 +0200 | [diff] [blame] | 1017 | /* Create a DSI host (and a device) for each port. */ |
| 1018 | for_each_dsi_port(port, intel_dsi->ports) { |
| 1019 | struct intel_dsi_host *host; |
| 1020 | |
| 1021 | host = intel_dsi_host_init(intel_dsi, port); |
| 1022 | if (!host) |
| 1023 | goto err; |
| 1024 | |
| 1025 | intel_dsi->dsi_hosts[port] = host; |
| 1026 | } |
| 1027 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1028 | for (i = 0; i < ARRAY_SIZE(intel_dsi_drivers); i++) { |
| 1029 | intel_dsi->panel = intel_dsi_drivers[i].init(intel_dsi, |
| 1030 | intel_dsi_drivers[i].panel_id); |
| 1031 | if (intel_dsi->panel) |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1032 | break; |
| 1033 | } |
| 1034 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1035 | if (!intel_dsi->panel) { |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1036 | DRM_DEBUG_KMS("no device found\n"); |
| 1037 | goto err; |
| 1038 | } |
| 1039 | |
| 1040 | intel_encoder->type = INTEL_OUTPUT_DSI; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 1041 | intel_encoder->cloneable = 0; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1042 | drm_connector_init(dev, connector, &intel_dsi_connector_funcs, |
| 1043 | DRM_MODE_CONNECTOR_DSI); |
| 1044 | |
| 1045 | drm_connector_helper_add(connector, &intel_dsi_connector_helper_funcs); |
| 1046 | |
| 1047 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; /*XXX*/ |
| 1048 | connector->interlace_allowed = false; |
| 1049 | connector->doublescan_allowed = false; |
| 1050 | |
| 1051 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
| 1052 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1053 | drm_connector_register(connector); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1054 | |
Jani Nikula | 593e062 | 2015-01-23 15:30:56 +0200 | [diff] [blame] | 1055 | drm_panel_attach(intel_dsi->panel, connector); |
| 1056 | |
| 1057 | mutex_lock(&dev->mode_config.mutex); |
| 1058 | drm_panel_get_modes(intel_dsi->panel); |
| 1059 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 1060 | if ((scan->type & DRM_MODE_TYPE_PREFERRED)) { |
| 1061 | fixed_mode = drm_mode_duplicate(dev, scan); |
| 1062 | break; |
| 1063 | } |
| 1064 | } |
| 1065 | mutex_unlock(&dev->mode_config.mutex); |
| 1066 | |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1067 | if (!fixed_mode) { |
| 1068 | DRM_DEBUG_KMS("no fixed mode\n"); |
| 1069 | goto err; |
| 1070 | } |
| 1071 | |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1072 | intel_panel_init(&intel_connector->panel, fixed_mode, NULL); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1073 | |
Damien Lespiau | 4328633d | 2014-05-28 12:30:56 +0100 | [diff] [blame] | 1074 | return; |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1075 | |
| 1076 | err: |
| 1077 | drm_encoder_cleanup(&intel_encoder->base); |
| 1078 | kfree(intel_dsi); |
| 1079 | kfree(intel_connector); |
Jani Nikula | 4e64649 | 2013-08-27 15:12:20 +0300 | [diff] [blame] | 1080 | } |