Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Eric Anholt <eric@anholt.net> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/i2c.h> |
| 22 | #include <linux/pm_runtime.h> |
| 23 | |
| 24 | #include <drm/drmP.h> |
| 25 | #include "psb_intel_reg.h" |
Patrik Jakobsson | fe477cc1 | 2013-07-02 17:02:22 +0200 | [diff] [blame] | 26 | #include "gma_display.h" |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 27 | #include "framebuffer.h" |
| 28 | #include "mdfld_output.h" |
| 29 | #include "mdfld_dsi_output.h" |
| 30 | |
| 31 | /* Hardcoded currently */ |
| 32 | static int ksel = KSEL_CRYSTAL_19; |
| 33 | |
| 34 | struct psb_intel_range_t { |
| 35 | int min, max; |
| 36 | }; |
| 37 | |
| 38 | struct mrst_limit_t { |
| 39 | struct psb_intel_range_t dot, m, p1; |
| 40 | }; |
| 41 | |
| 42 | struct mrst_clock_t { |
| 43 | /* derived values */ |
| 44 | int dot; |
| 45 | int m; |
| 46 | int p1; |
| 47 | }; |
| 48 | |
| 49 | #define COUNT_MAX 0x10000000 |
| 50 | |
| 51 | void mdfldWaitForPipeDisable(struct drm_device *dev, int pipe) |
| 52 | { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 53 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 54 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 55 | int count, temp; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 56 | |
| 57 | switch (pipe) { |
| 58 | case 0: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 59 | case 1: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 60 | case 2: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 61 | break; |
| 62 | default: |
| 63 | DRM_ERROR("Illegal Pipe Number.\n"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | /* FIXME JLIU7_PO */ |
Patrik Jakobsson | d1fa08f | 2013-07-10 01:20:19 +0200 | [diff] [blame] | 68 | gma_wait_for_vblank(dev); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 69 | return; |
| 70 | |
| 71 | /* Wait for for the pipe disable to take effect. */ |
| 72 | for (count = 0; count < COUNT_MAX; count++) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 73 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 74 | if ((temp & PIPEACONF_PIPE_STATE) == 0) |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void mdfldWaitForPipeEnable(struct drm_device *dev, int pipe) |
| 80 | { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 81 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 82 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 83 | int count, temp; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 84 | |
| 85 | switch (pipe) { |
| 86 | case 0: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 87 | case 1: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 88 | case 2: |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 89 | break; |
| 90 | default: |
| 91 | DRM_ERROR("Illegal Pipe Number.\n"); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | /* FIXME JLIU7_PO */ |
Patrik Jakobsson | d1fa08f | 2013-07-10 01:20:19 +0200 | [diff] [blame] | 96 | gma_wait_for_vblank(dev); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 97 | return; |
| 98 | |
| 99 | /* Wait for for the pipe enable to take effect. */ |
| 100 | for (count = 0; count < COUNT_MAX; count++) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 101 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 102 | if ((temp & PIPEACONF_PIPE_STATE) == 1) |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 107 | /** |
| 108 | * Return the pipe currently connected to the panel fitter, |
| 109 | * or -1 if the panel fitter is not present or not in use |
| 110 | */ |
| 111 | static int psb_intel_panel_fitter_pipe(struct drm_device *dev) |
| 112 | { |
| 113 | u32 pfit_control; |
| 114 | |
| 115 | pfit_control = REG_READ(PFIT_CONTROL); |
| 116 | |
| 117 | /* See if the panel fitter is in use */ |
| 118 | if ((pfit_control & PFIT_ENABLE) == 0) |
| 119 | return -1; |
| 120 | |
| 121 | /* 965 can place panel fitter on either pipe */ |
| 122 | return (pfit_control >> 29) & 0x3; |
| 123 | } |
| 124 | |
| 125 | static struct drm_device globle_dev; |
| 126 | |
| 127 | void mdfld__intel_plane_set_alpha(int enable) |
| 128 | { |
| 129 | struct drm_device *dev = &globle_dev; |
| 130 | int dspcntr_reg = DSPACNTR; |
| 131 | u32 dspcntr; |
| 132 | |
| 133 | dspcntr = REG_READ(dspcntr_reg); |
| 134 | |
| 135 | if (enable) { |
| 136 | dspcntr &= ~DISPPLANE_32BPP_NO_ALPHA; |
| 137 | dspcntr |= DISPPLANE_32BPP; |
| 138 | } else { |
| 139 | dspcntr &= ~DISPPLANE_32BPP; |
| 140 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; |
| 141 | } |
| 142 | |
| 143 | REG_WRITE(dspcntr_reg, dspcntr); |
| 144 | } |
| 145 | |
| 146 | static int check_fb(struct drm_framebuffer *fb) |
| 147 | { |
| 148 | if (!fb) |
| 149 | return 0; |
| 150 | |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 151 | switch (fb->format->cpp[0] * 8) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 152 | case 8: |
| 153 | case 16: |
| 154 | case 24: |
| 155 | case 32: |
| 156 | return 0; |
| 157 | default: |
| 158 | DRM_ERROR("Unknown color depth\n"); |
| 159 | return -EINVAL; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static int mdfld__intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
| 164 | struct drm_framebuffer *old_fb) |
| 165 | { |
| 166 | struct drm_device *dev = crtc->dev; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 167 | struct drm_psb_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 5156019 | 2016-11-18 21:52:42 +0200 | [diff] [blame] | 168 | struct drm_framebuffer *fb = crtc->primary->fb; |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 169 | struct gma_crtc *gma_crtc = to_gma_crtc(crtc); |
Ville Syrjälä | 5156019 | 2016-11-18 21:52:42 +0200 | [diff] [blame] | 170 | struct psb_framebuffer *psbfb = to_psb_fb(fb); |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 171 | int pipe = gma_crtc->pipe; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 172 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 173 | unsigned long start, offset; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 174 | u32 dspcntr; |
| 175 | int ret; |
| 176 | |
| 177 | memcpy(&globle_dev, dev, sizeof(struct drm_device)); |
| 178 | |
| 179 | dev_dbg(dev->dev, "pipe = 0x%x.\n", pipe); |
| 180 | |
| 181 | /* no fb bound */ |
Ville Syrjälä | 5156019 | 2016-11-18 21:52:42 +0200 | [diff] [blame] | 182 | if (!fb) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 183 | dev_dbg(dev->dev, "No FB bound\n"); |
| 184 | return 0; |
| 185 | } |
| 186 | |
Ville Syrjälä | 5156019 | 2016-11-18 21:52:42 +0200 | [diff] [blame] | 187 | ret = check_fb(fb); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 188 | if (ret) |
| 189 | return ret; |
| 190 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 191 | if (pipe > 2) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 192 | DRM_ERROR("Illegal Pipe Number.\n"); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | if (!gma_power_begin(dev, true)) |
| 197 | return 0; |
| 198 | |
| 199 | start = psbfb->gtt->offset; |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 200 | offset = y * fb->pitches[0] + x * fb->format->cpp[0]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 201 | |
Ville Syrjälä | 5156019 | 2016-11-18 21:52:42 +0200 | [diff] [blame] | 202 | REG_WRITE(map->stride, fb->pitches[0]); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 203 | dspcntr = REG_READ(map->cntr); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 204 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
| 205 | |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 206 | switch (fb->format->cpp[0] * 8) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 207 | case 8: |
| 208 | dspcntr |= DISPPLANE_8BPP; |
| 209 | break; |
| 210 | case 16: |
Ville Syrjälä | b00c600 | 2016-12-14 23:31:35 +0200 | [diff] [blame] | 211 | if (fb->format->depth == 15) |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 212 | dspcntr |= DISPPLANE_15_16BPP; |
| 213 | else |
| 214 | dspcntr |= DISPPLANE_16BPP; |
| 215 | break; |
| 216 | case 24: |
| 217 | case 32: |
| 218 | dspcntr |= DISPPLANE_32BPP_NO_ALPHA; |
| 219 | break; |
| 220 | } |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 221 | REG_WRITE(map->cntr, dspcntr); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 222 | |
| 223 | dev_dbg(dev->dev, "Writing base %08lX %08lX %d %d\n", |
| 224 | start, offset, x, y); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 225 | REG_WRITE(map->linoff, offset); |
| 226 | REG_READ(map->linoff); |
| 227 | REG_WRITE(map->surf, start); |
| 228 | REG_READ(map->surf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 229 | |
| 230 | gma_power_end(dev); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * Disable the pipe, plane and pll. |
| 237 | * |
| 238 | */ |
| 239 | void mdfld_disable_crtc(struct drm_device *dev, int pipe) |
| 240 | { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 241 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 242 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 243 | u32 temp; |
| 244 | |
| 245 | dev_dbg(dev->dev, "pipe = %d\n", pipe); |
| 246 | |
| 247 | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 248 | if (pipe != 1) |
| 249 | mdfld_dsi_gen_fifo_ready(dev, MIPI_GEN_FIFO_STAT_REG(pipe), |
| 250 | HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY); |
| 251 | |
| 252 | /* Disable display plane */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 253 | temp = REG_READ(map->cntr); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 254 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 255 | REG_WRITE(map->cntr, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 256 | temp & ~DISPLAY_PLANE_ENABLE); |
| 257 | /* Flush the plane changes */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 258 | REG_WRITE(map->base, REG_READ(map->base)); |
| 259 | REG_READ(map->base); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* FIXME_JLIU7 MDFLD_PO revisit */ |
| 263 | |
| 264 | /* Next, disable display pipes */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 265 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 266 | if ((temp & PIPEACONF_ENABLE) != 0) { |
| 267 | temp &= ~PIPEACONF_ENABLE; |
| 268 | temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 269 | REG_WRITE(map->conf, temp); |
| 270 | REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 271 | |
| 272 | /* Wait for for the pipe disable to take effect. */ |
| 273 | mdfldWaitForPipeDisable(dev, pipe); |
| 274 | } |
| 275 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 276 | temp = REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 277 | if (temp & DPLL_VCO_ENABLE) { |
| 278 | if ((pipe != 1 && |
| 279 | !((REG_READ(PIPEACONF) | REG_READ(PIPECCONF)) |
| 280 | & PIPEACONF_ENABLE)) || pipe == 1) { |
| 281 | temp &= ~(DPLL_VCO_ENABLE); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 282 | REG_WRITE(map->dpll, temp); |
| 283 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 284 | /* Wait for the clocks to turn off. */ |
| 285 | /* FIXME_MDFLD PO may need more delay */ |
| 286 | udelay(500); |
| 287 | |
| 288 | if (!(temp & MDFLD_PWR_GATE_EN)) { |
| 289 | /* gating power of DPLL */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 290 | REG_WRITE(map->dpll, temp | MDFLD_PWR_GATE_EN); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 291 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 292 | udelay(5000); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Sets the power management mode of the pipe and plane. |
| 301 | * |
| 302 | * This code should probably grow support for turning the cursor off and back |
| 303 | * on appropriately at the same time as we're turning the pipe off/on. |
| 304 | */ |
| 305 | static void mdfld_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 306 | { |
| 307 | struct drm_device *dev = crtc->dev; |
| 308 | struct drm_psb_private *dev_priv = dev->dev_private; |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 309 | struct gma_crtc *gma_crtc = to_gma_crtc(crtc); |
| 310 | int pipe = gma_crtc->pipe; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 311 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 312 | u32 pipeconf = dev_priv->pipeconf[pipe]; |
| 313 | u32 temp; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 314 | int timeout = 0; |
| 315 | |
| 316 | dev_dbg(dev->dev, "mode = %d, pipe = %d\n", mode, pipe); |
| 317 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 318 | /* Note: Old code uses pipe a stat for pipe b but that appears |
| 319 | to be a bug */ |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 320 | |
| 321 | if (!gma_power_begin(dev, true)) |
| 322 | return; |
| 323 | |
| 324 | /* XXX: When our outputs are all unaware of DPMS modes other than off |
| 325 | * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. |
| 326 | */ |
| 327 | switch (mode) { |
| 328 | case DRM_MODE_DPMS_ON: |
| 329 | case DRM_MODE_DPMS_STANDBY: |
| 330 | case DRM_MODE_DPMS_SUSPEND: |
| 331 | /* Enable the DPLL */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 332 | temp = REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 333 | |
| 334 | if ((temp & DPLL_VCO_ENABLE) == 0) { |
| 335 | /* When ungating power of DPLL, needs to wait 0.5us |
| 336 | before enable the VCO */ |
| 337 | if (temp & MDFLD_PWR_GATE_EN) { |
| 338 | temp &= ~MDFLD_PWR_GATE_EN; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 339 | REG_WRITE(map->dpll, temp); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 340 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 341 | udelay(500); |
| 342 | } |
| 343 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 344 | REG_WRITE(map->dpll, temp); |
| 345 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 346 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 347 | udelay(500); |
| 348 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 349 | REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE); |
| 350 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * wait for DSI PLL to lock |
| 354 | * NOTE: only need to poll status of pipe 0 and pipe 1, |
| 355 | * since both MIPI pipes share the same PLL. |
| 356 | */ |
| 357 | while ((pipe != 2) && (timeout < 20000) && |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 358 | !(REG_READ(map->conf) & PIPECONF_DSIPLL_LOCK)) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 359 | udelay(150); |
| 360 | timeout++; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /* Enable the plane */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 365 | temp = REG_READ(map->cntr); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 366 | if ((temp & DISPLAY_PLANE_ENABLE) == 0) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 367 | REG_WRITE(map->cntr, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 368 | temp | DISPLAY_PLANE_ENABLE); |
| 369 | /* Flush the plane changes */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 370 | REG_WRITE(map->base, REG_READ(map->base)); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* Enable the pipe */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 374 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 375 | if ((temp & PIPEACONF_ENABLE) == 0) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 376 | REG_WRITE(map->conf, pipeconf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 377 | |
| 378 | /* Wait for for the pipe enable to take effect. */ |
| 379 | mdfldWaitForPipeEnable(dev, pipe); |
| 380 | } |
| 381 | |
| 382 | /*workaround for sighting 3741701 Random X blank display*/ |
| 383 | /*perform w/a in video mode only on pipe A or C*/ |
| 384 | if (pipe == 0 || pipe == 2) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 385 | REG_WRITE(map->status, REG_READ(map->status)); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 386 | msleep(100); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 387 | if (PIPE_VBLANK_STATUS & REG_READ(map->status)) |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 388 | dev_dbg(dev->dev, "OK"); |
| 389 | else { |
| 390 | dev_dbg(dev->dev, "STUCK!!!!"); |
| 391 | /*shutdown controller*/ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 392 | temp = REG_READ(map->cntr); |
| 393 | REG_WRITE(map->cntr, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 394 | temp & ~DISPLAY_PLANE_ENABLE); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 395 | REG_WRITE(map->base, REG_READ(map->base)); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 396 | /*mdfld_dsi_dpi_shut_down(dev, pipe);*/ |
| 397 | REG_WRITE(0xb048, 1); |
| 398 | msleep(100); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 399 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 400 | temp &= ~PIPEACONF_ENABLE; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 401 | REG_WRITE(map->conf, temp); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 402 | msleep(100); /*wait for pipe disable*/ |
| 403 | REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 0); |
| 404 | msleep(100); |
| 405 | REG_WRITE(0xb004, REG_READ(0xb004)); |
| 406 | /* try to bring the controller back up again*/ |
| 407 | REG_WRITE(MIPI_DEVICE_READY_REG(pipe), 1); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 408 | temp = REG_READ(map->cntr); |
| 409 | REG_WRITE(map->cntr, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 410 | temp | DISPLAY_PLANE_ENABLE); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 411 | REG_WRITE(map->base, REG_READ(map->base)); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 412 | /*mdfld_dsi_dpi_turn_on(dev, pipe);*/ |
| 413 | REG_WRITE(0xb048, 2); |
| 414 | msleep(100); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 415 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 416 | temp |= PIPEACONF_ENABLE; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 417 | REG_WRITE(map->conf, temp); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Patrik Jakobsson | 6443ea1 | 2013-07-10 18:39:58 +0200 | [diff] [blame] | 421 | gma_crtc_load_lut(crtc); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 422 | |
| 423 | /* Give the overlay scaler a chance to enable |
| 424 | if it's on this pipe */ |
| 425 | /* psb_intel_crtc_dpms_video(crtc, true); TODO */ |
| 426 | |
| 427 | break; |
| 428 | case DRM_MODE_DPMS_OFF: |
| 429 | /* Give the overlay scaler a chance to disable |
| 430 | * if it's on this pipe */ |
| 431 | /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */ |
| 432 | if (pipe != 1) |
| 433 | mdfld_dsi_gen_fifo_ready(dev, |
| 434 | MIPI_GEN_FIFO_STAT_REG(pipe), |
| 435 | HS_CTRL_FIFO_EMPTY | HS_DATA_FIFO_EMPTY); |
| 436 | |
| 437 | /* Disable the VGA plane that we never use */ |
| 438 | REG_WRITE(VGACNTRL, VGA_DISP_DISABLE); |
| 439 | |
| 440 | /* Disable display plane */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 441 | temp = REG_READ(map->cntr); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 442 | if ((temp & DISPLAY_PLANE_ENABLE) != 0) { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 443 | REG_WRITE(map->cntr, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 444 | temp & ~DISPLAY_PLANE_ENABLE); |
| 445 | /* Flush the plane changes */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 446 | REG_WRITE(map->base, REG_READ(map->base)); |
| 447 | REG_READ(map->base); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* Next, disable display pipes */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 451 | temp = REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 452 | if ((temp & PIPEACONF_ENABLE) != 0) { |
| 453 | temp &= ~PIPEACONF_ENABLE; |
| 454 | temp |= PIPECONF_PLANE_OFF | PIPECONF_CURSOR_OFF; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 455 | REG_WRITE(map->conf, temp); |
| 456 | REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 457 | |
| 458 | /* Wait for for the pipe disable to take effect. */ |
| 459 | mdfldWaitForPipeDisable(dev, pipe); |
| 460 | } |
| 461 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 462 | temp = REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 463 | if (temp & DPLL_VCO_ENABLE) { |
| 464 | if ((pipe != 1 && !((REG_READ(PIPEACONF) |
| 465 | | REG_READ(PIPECCONF)) & PIPEACONF_ENABLE)) |
| 466 | || pipe == 1) { |
| 467 | temp &= ~(DPLL_VCO_ENABLE); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 468 | REG_WRITE(map->dpll, temp); |
| 469 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 470 | /* Wait for the clocks to turn off. */ |
| 471 | /* FIXME_MDFLD PO may need more delay */ |
| 472 | udelay(500); |
| 473 | } |
| 474 | } |
| 475 | break; |
| 476 | } |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 477 | gma_power_end(dev); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | #define MDFLD_LIMT_DPLL_19 0 |
| 482 | #define MDFLD_LIMT_DPLL_25 1 |
| 483 | #define MDFLD_LIMT_DPLL_83 2 |
| 484 | #define MDFLD_LIMT_DPLL_100 3 |
| 485 | #define MDFLD_LIMT_DSIPLL_19 4 |
| 486 | #define MDFLD_LIMT_DSIPLL_25 5 |
| 487 | #define MDFLD_LIMT_DSIPLL_83 6 |
| 488 | #define MDFLD_LIMT_DSIPLL_100 7 |
| 489 | |
| 490 | #define MDFLD_DOT_MIN 19750 |
| 491 | #define MDFLD_DOT_MAX 120000 |
| 492 | #define MDFLD_DPLL_M_MIN_19 113 |
| 493 | #define MDFLD_DPLL_M_MAX_19 155 |
| 494 | #define MDFLD_DPLL_P1_MIN_19 2 |
| 495 | #define MDFLD_DPLL_P1_MAX_19 10 |
| 496 | #define MDFLD_DPLL_M_MIN_25 101 |
| 497 | #define MDFLD_DPLL_M_MAX_25 130 |
| 498 | #define MDFLD_DPLL_P1_MIN_25 2 |
| 499 | #define MDFLD_DPLL_P1_MAX_25 10 |
| 500 | #define MDFLD_DPLL_M_MIN_83 64 |
| 501 | #define MDFLD_DPLL_M_MAX_83 64 |
| 502 | #define MDFLD_DPLL_P1_MIN_83 2 |
| 503 | #define MDFLD_DPLL_P1_MAX_83 2 |
| 504 | #define MDFLD_DPLL_M_MIN_100 64 |
| 505 | #define MDFLD_DPLL_M_MAX_100 64 |
| 506 | #define MDFLD_DPLL_P1_MIN_100 2 |
| 507 | #define MDFLD_DPLL_P1_MAX_100 2 |
| 508 | #define MDFLD_DSIPLL_M_MIN_19 131 |
| 509 | #define MDFLD_DSIPLL_M_MAX_19 175 |
| 510 | #define MDFLD_DSIPLL_P1_MIN_19 3 |
| 511 | #define MDFLD_DSIPLL_P1_MAX_19 8 |
| 512 | #define MDFLD_DSIPLL_M_MIN_25 97 |
| 513 | #define MDFLD_DSIPLL_M_MAX_25 140 |
| 514 | #define MDFLD_DSIPLL_P1_MIN_25 3 |
| 515 | #define MDFLD_DSIPLL_P1_MAX_25 9 |
| 516 | #define MDFLD_DSIPLL_M_MIN_83 33 |
| 517 | #define MDFLD_DSIPLL_M_MAX_83 92 |
| 518 | #define MDFLD_DSIPLL_P1_MIN_83 2 |
| 519 | #define MDFLD_DSIPLL_P1_MAX_83 3 |
| 520 | #define MDFLD_DSIPLL_M_MIN_100 97 |
| 521 | #define MDFLD_DSIPLL_M_MAX_100 140 |
| 522 | #define MDFLD_DSIPLL_P1_MIN_100 3 |
| 523 | #define MDFLD_DSIPLL_P1_MAX_100 9 |
| 524 | |
| 525 | static const struct mrst_limit_t mdfld_limits[] = { |
| 526 | { /* MDFLD_LIMT_DPLL_19 */ |
| 527 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 528 | .m = {.min = MDFLD_DPLL_M_MIN_19, .max = MDFLD_DPLL_M_MAX_19}, |
| 529 | .p1 = {.min = MDFLD_DPLL_P1_MIN_19, .max = MDFLD_DPLL_P1_MAX_19}, |
| 530 | }, |
| 531 | { /* MDFLD_LIMT_DPLL_25 */ |
| 532 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 533 | .m = {.min = MDFLD_DPLL_M_MIN_25, .max = MDFLD_DPLL_M_MAX_25}, |
| 534 | .p1 = {.min = MDFLD_DPLL_P1_MIN_25, .max = MDFLD_DPLL_P1_MAX_25}, |
| 535 | }, |
| 536 | { /* MDFLD_LIMT_DPLL_83 */ |
| 537 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 538 | .m = {.min = MDFLD_DPLL_M_MIN_83, .max = MDFLD_DPLL_M_MAX_83}, |
| 539 | .p1 = {.min = MDFLD_DPLL_P1_MIN_83, .max = MDFLD_DPLL_P1_MAX_83}, |
| 540 | }, |
| 541 | { /* MDFLD_LIMT_DPLL_100 */ |
| 542 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 543 | .m = {.min = MDFLD_DPLL_M_MIN_100, .max = MDFLD_DPLL_M_MAX_100}, |
| 544 | .p1 = {.min = MDFLD_DPLL_P1_MIN_100, .max = MDFLD_DPLL_P1_MAX_100}, |
| 545 | }, |
| 546 | { /* MDFLD_LIMT_DSIPLL_19 */ |
| 547 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 548 | .m = {.min = MDFLD_DSIPLL_M_MIN_19, .max = MDFLD_DSIPLL_M_MAX_19}, |
| 549 | .p1 = {.min = MDFLD_DSIPLL_P1_MIN_19, .max = MDFLD_DSIPLL_P1_MAX_19}, |
| 550 | }, |
| 551 | { /* MDFLD_LIMT_DSIPLL_25 */ |
| 552 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 553 | .m = {.min = MDFLD_DSIPLL_M_MIN_25, .max = MDFLD_DSIPLL_M_MAX_25}, |
| 554 | .p1 = {.min = MDFLD_DSIPLL_P1_MIN_25, .max = MDFLD_DSIPLL_P1_MAX_25}, |
| 555 | }, |
| 556 | { /* MDFLD_LIMT_DSIPLL_83 */ |
| 557 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 558 | .m = {.min = MDFLD_DSIPLL_M_MIN_83, .max = MDFLD_DSIPLL_M_MAX_83}, |
| 559 | .p1 = {.min = MDFLD_DSIPLL_P1_MIN_83, .max = MDFLD_DSIPLL_P1_MAX_83}, |
| 560 | }, |
| 561 | { /* MDFLD_LIMT_DSIPLL_100 */ |
| 562 | .dot = {.min = MDFLD_DOT_MIN, .max = MDFLD_DOT_MAX}, |
| 563 | .m = {.min = MDFLD_DSIPLL_M_MIN_100, .max = MDFLD_DSIPLL_M_MAX_100}, |
| 564 | .p1 = {.min = MDFLD_DSIPLL_P1_MIN_100, .max = MDFLD_DSIPLL_P1_MAX_100}, |
| 565 | }, |
| 566 | }; |
| 567 | |
| 568 | #define MDFLD_M_MIN 21 |
| 569 | #define MDFLD_M_MAX 180 |
| 570 | static const u32 mdfld_m_converts[] = { |
| 571 | /* M configuration table from 9-bit LFSR table */ |
| 572 | 224, 368, 440, 220, 366, 439, 219, 365, 182, 347, /* 21 - 30 */ |
| 573 | 173, 342, 171, 85, 298, 149, 74, 37, 18, 265, /* 31 - 40 */ |
| 574 | 388, 194, 353, 432, 216, 108, 310, 155, 333, 166, /* 41 - 50 */ |
| 575 | 83, 41, 276, 138, 325, 162, 337, 168, 340, 170, /* 51 - 60 */ |
| 576 | 341, 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 61 - 70 */ |
| 577 | 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */ |
| 578 | 106, 53, 282, 397, 354, 227, 113, 56, 284, 142, /* 81 - 90 */ |
| 579 | 71, 35, 273, 136, 324, 418, 465, 488, 500, 506, /* 91 - 100 */ |
| 580 | 253, 126, 63, 287, 399, 455, 483, 241, 376, 444, /* 101 - 110 */ |
| 581 | 478, 495, 503, 251, 381, 446, 479, 239, 375, 443, /* 111 - 120 */ |
| 582 | 477, 238, 119, 315, 157, 78, 295, 147, 329, 420, /* 121 - 130 */ |
| 583 | 210, 105, 308, 154, 77, 38, 275, 137, 68, 290, /* 131 - 140 */ |
| 584 | 145, 328, 164, 82, 297, 404, 458, 485, 498, 249, /* 141 - 150 */ |
| 585 | 380, 190, 351, 431, 471, 235, 117, 314, 413, 206, /* 151 - 160 */ |
| 586 | 103, 51, 25, 12, 262, 387, 193, 96, 48, 280, /* 161 - 170 */ |
| 587 | 396, 198, 99, 305, 152, 76, 294, 403, 457, 228, /* 171 - 180 */ |
| 588 | }; |
| 589 | |
| 590 | static const struct mrst_limit_t *mdfld_limit(struct drm_crtc *crtc) |
| 591 | { |
| 592 | const struct mrst_limit_t *limit = NULL; |
| 593 | struct drm_device *dev = crtc->dev; |
| 594 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 595 | |
Patrik Jakobsson | fe477cc1 | 2013-07-02 17:02:22 +0200 | [diff] [blame] | 596 | if (gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI) |
| 597 | || gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI2)) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 598 | if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) |
| 599 | limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_19]; |
| 600 | else if (ksel == KSEL_BYPASS_25) |
| 601 | limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_25]; |
| 602 | else if ((ksel == KSEL_BYPASS_83_100) && |
| 603 | (dev_priv->core_freq == 166)) |
| 604 | limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_83]; |
| 605 | else if ((ksel == KSEL_BYPASS_83_100) && |
| 606 | (dev_priv->core_freq == 100 || |
| 607 | dev_priv->core_freq == 200)) |
| 608 | limit = &mdfld_limits[MDFLD_LIMT_DSIPLL_100]; |
Patrik Jakobsson | fe477cc1 | 2013-07-02 17:02:22 +0200 | [diff] [blame] | 609 | } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 610 | if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) |
| 611 | limit = &mdfld_limits[MDFLD_LIMT_DPLL_19]; |
| 612 | else if (ksel == KSEL_BYPASS_25) |
| 613 | limit = &mdfld_limits[MDFLD_LIMT_DPLL_25]; |
| 614 | else if ((ksel == KSEL_BYPASS_83_100) && |
| 615 | (dev_priv->core_freq == 166)) |
| 616 | limit = &mdfld_limits[MDFLD_LIMT_DPLL_83]; |
| 617 | else if ((ksel == KSEL_BYPASS_83_100) && |
| 618 | (dev_priv->core_freq == 100 || |
| 619 | dev_priv->core_freq == 200)) |
| 620 | limit = &mdfld_limits[MDFLD_LIMT_DPLL_100]; |
| 621 | } else { |
| 622 | limit = NULL; |
| 623 | dev_dbg(dev->dev, "mdfld_limit Wrong display type.\n"); |
| 624 | } |
| 625 | |
| 626 | return limit; |
| 627 | } |
| 628 | |
| 629 | /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */ |
| 630 | static void mdfld_clock(int refclk, struct mrst_clock_t *clock) |
| 631 | { |
| 632 | clock->dot = (refclk * clock->m) / clock->p1; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Returns a set of divisors for the desired target clock with the given refclk, |
| 637 | * or FALSE. Divisor values are the actual divisors for |
| 638 | */ |
| 639 | static bool |
| 640 | mdfldFindBestPLL(struct drm_crtc *crtc, int target, int refclk, |
| 641 | struct mrst_clock_t *best_clock) |
| 642 | { |
| 643 | struct mrst_clock_t clock; |
| 644 | const struct mrst_limit_t *limit = mdfld_limit(crtc); |
| 645 | int err = target; |
| 646 | |
| 647 | memset(best_clock, 0, sizeof(*best_clock)); |
| 648 | |
| 649 | for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) { |
| 650 | for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max; |
| 651 | clock.p1++) { |
| 652 | int this_err; |
| 653 | |
| 654 | mdfld_clock(refclk, &clock); |
| 655 | |
| 656 | this_err = abs(clock.dot - target); |
| 657 | if (this_err < err) { |
| 658 | *best_clock = clock; |
| 659 | err = this_err; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | return err != target; |
| 664 | } |
| 665 | |
| 666 | static int mdfld_crtc_mode_set(struct drm_crtc *crtc, |
| 667 | struct drm_display_mode *mode, |
| 668 | struct drm_display_mode *adjusted_mode, |
| 669 | int x, int y, |
| 670 | struct drm_framebuffer *old_fb) |
| 671 | { |
| 672 | struct drm_device *dev = crtc->dev; |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 673 | struct gma_crtc *gma_crtc = to_gma_crtc(crtc); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 674 | struct drm_psb_private *dev_priv = dev->dev_private; |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 675 | int pipe = gma_crtc->pipe; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 676 | const struct psb_offset *map = &dev_priv->regmap[pipe]; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 677 | int refclk = 0; |
| 678 | int clk_n = 0, clk_p2 = 0, clk_byte = 1, clk = 0, m_conv = 0, |
| 679 | clk_tmp = 0; |
| 680 | struct mrst_clock_t clock; |
| 681 | bool ok; |
| 682 | u32 dpll = 0, fp = 0; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 683 | bool is_mipi = false, is_mipi2 = false, is_hdmi = false; |
| 684 | struct drm_mode_config *mode_config = &dev->mode_config; |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 685 | struct gma_encoder *gma_encoder = NULL; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 686 | uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN; |
| 687 | struct drm_encoder *encoder; |
| 688 | struct drm_connector *connector; |
| 689 | int timeout = 0; |
| 690 | int ret; |
| 691 | |
| 692 | dev_dbg(dev->dev, "pipe = 0x%x\n", pipe); |
| 693 | |
| 694 | #if 0 |
| 695 | if (pipe == 1) { |
| 696 | if (!gma_power_begin(dev, true)) |
| 697 | return 0; |
| 698 | android_hdmi_crtc_mode_set(crtc, mode, adjusted_mode, |
| 699 | x, y, old_fb); |
| 700 | goto mrst_crtc_mode_set_exit; |
| 701 | } |
| 702 | #endif |
| 703 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 704 | ret = check_fb(crtc->primary->fb); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 705 | if (ret) |
| 706 | return ret; |
| 707 | |
| 708 | dev_dbg(dev->dev, "adjusted_hdisplay = %d\n", |
| 709 | adjusted_mode->hdisplay); |
| 710 | dev_dbg(dev->dev, "adjusted_vdisplay = %d\n", |
| 711 | adjusted_mode->vdisplay); |
| 712 | dev_dbg(dev->dev, "adjusted_hsync_start = %d\n", |
| 713 | adjusted_mode->hsync_start); |
| 714 | dev_dbg(dev->dev, "adjusted_hsync_end = %d\n", |
| 715 | adjusted_mode->hsync_end); |
| 716 | dev_dbg(dev->dev, "adjusted_htotal = %d\n", |
| 717 | adjusted_mode->htotal); |
| 718 | dev_dbg(dev->dev, "adjusted_vsync_start = %d\n", |
| 719 | adjusted_mode->vsync_start); |
| 720 | dev_dbg(dev->dev, "adjusted_vsync_end = %d\n", |
| 721 | adjusted_mode->vsync_end); |
| 722 | dev_dbg(dev->dev, "adjusted_vtotal = %d\n", |
| 723 | adjusted_mode->vtotal); |
| 724 | dev_dbg(dev->dev, "adjusted_clock = %d\n", |
| 725 | adjusted_mode->clock); |
| 726 | dev_dbg(dev->dev, "hdisplay = %d\n", |
| 727 | mode->hdisplay); |
| 728 | dev_dbg(dev->dev, "vdisplay = %d\n", |
| 729 | mode->vdisplay); |
| 730 | |
| 731 | if (!gma_power_begin(dev, true)) |
| 732 | return 0; |
| 733 | |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 734 | memcpy(&gma_crtc->saved_mode, mode, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 735 | sizeof(struct drm_display_mode)); |
Patrik Jakobsson | 6306865 | 2013-07-22 01:31:23 +0200 | [diff] [blame] | 736 | memcpy(&gma_crtc->saved_adjusted_mode, adjusted_mode, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 737 | sizeof(struct drm_display_mode)); |
| 738 | |
| 739 | list_for_each_entry(connector, &mode_config->connector_list, head) { |
| 740 | if (!connector) |
| 741 | continue; |
| 742 | |
| 743 | encoder = connector->encoder; |
| 744 | |
| 745 | if (!encoder) |
| 746 | continue; |
| 747 | |
| 748 | if (encoder->crtc != crtc) |
| 749 | continue; |
| 750 | |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 751 | gma_encoder = gma_attached_encoder(connector); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 752 | |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 753 | switch (gma_encoder->type) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 754 | case INTEL_OUTPUT_MIPI: |
| 755 | is_mipi = true; |
| 756 | break; |
| 757 | case INTEL_OUTPUT_MIPI2: |
| 758 | is_mipi2 = true; |
| 759 | break; |
| 760 | case INTEL_OUTPUT_HDMI: |
| 761 | is_hdmi = true; |
| 762 | break; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /* Disable the VGA plane that we never use */ |
| 767 | REG_WRITE(VGACNTRL, VGA_DISP_DISABLE); |
| 768 | |
| 769 | /* Disable the panel fitter if it was on our pipe */ |
| 770 | if (psb_intel_panel_fitter_pipe(dev) == pipe) |
| 771 | REG_WRITE(PFIT_CONTROL, 0); |
| 772 | |
| 773 | /* pipesrc and dspsize control the size that is scaled from, |
| 774 | * which should always be the user's requested size. |
| 775 | */ |
| 776 | if (pipe == 1) { |
| 777 | /* FIXME: To make HDMI display with 864x480 (TPO), 480x864 |
| 778 | * (PYR) or 480x854 (TMD), set the sprite width/height and |
| 779 | * souce image size registers with the adjusted mode for |
| 780 | * pipe B. |
| 781 | */ |
| 782 | |
| 783 | /* |
| 784 | * The defined sprite rectangle must always be completely |
| 785 | * contained within the displayable area of the screen image |
| 786 | * (frame buffer). |
| 787 | */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 788 | REG_WRITE(map->size, ((min(mode->crtc_vdisplay, adjusted_mode->crtc_vdisplay) - 1) << 16) |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 789 | | (min(mode->crtc_hdisplay, adjusted_mode->crtc_hdisplay) - 1)); |
| 790 | /* Set the CRTC with encoder mode. */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 791 | REG_WRITE(map->src, ((mode->crtc_hdisplay - 1) << 16) |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 792 | | (mode->crtc_vdisplay - 1)); |
| 793 | } else { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 794 | REG_WRITE(map->size, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 795 | ((mode->crtc_vdisplay - 1) << 16) | |
| 796 | (mode->crtc_hdisplay - 1)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 797 | REG_WRITE(map->src, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 798 | ((mode->crtc_hdisplay - 1) << 16) | |
| 799 | (mode->crtc_vdisplay - 1)); |
| 800 | } |
| 801 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 802 | REG_WRITE(map->pos, 0); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 803 | |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 804 | if (gma_encoder) |
Rob Clark | a69ac9e | 2012-10-11 20:38:23 -0500 | [diff] [blame] | 805 | drm_object_property_get_value(&connector->base, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 806 | dev->mode_config.scaling_mode_property, &scalingType); |
| 807 | |
| 808 | if (scalingType == DRM_MODE_SCALE_NO_SCALE) { |
| 809 | /* Medfield doesn't have register support for centering so we |
| 810 | * need to mess with the h/vblank and h/vsync start and ends |
| 811 | * to get centering |
| 812 | */ |
| 813 | int offsetX = 0, offsetY = 0; |
| 814 | |
| 815 | offsetX = (adjusted_mode->crtc_hdisplay - |
| 816 | mode->crtc_hdisplay) / 2; |
| 817 | offsetY = (adjusted_mode->crtc_vdisplay - |
| 818 | mode->crtc_vdisplay) / 2; |
| 819 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 820 | REG_WRITE(map->htotal, (mode->crtc_hdisplay - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 821 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 822 | REG_WRITE(map->vtotal, (mode->crtc_vdisplay - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 823 | ((adjusted_mode->crtc_vtotal - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 824 | REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 825 | offsetX - 1) | |
| 826 | ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 827 | REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 828 | offsetX - 1) | |
| 829 | ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 830 | REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 831 | offsetY - 1) | |
| 832 | ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 833 | REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 834 | offsetY - 1) | |
| 835 | ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16)); |
| 836 | } else { |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 837 | REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 838 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 839 | REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 840 | ((adjusted_mode->crtc_vtotal - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 841 | REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 842 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 843 | REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 844 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 845 | REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 846 | ((adjusted_mode->crtc_vblank_end - 1) << 16)); |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 847 | REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) | |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 848 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 849 | } |
| 850 | |
| 851 | /* Flush the plane changes */ |
| 852 | { |
Jani Nikula | 45fe734 | 2015-03-11 11:51:01 +0200 | [diff] [blame] | 853 | const struct drm_crtc_helper_funcs *crtc_funcs = |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 854 | crtc->helper_private; |
| 855 | crtc_funcs->mode_set_base(crtc, x, y, old_fb); |
| 856 | } |
| 857 | |
| 858 | /* setup pipeconf */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 859 | dev_priv->pipeconf[pipe] = PIPEACONF_ENABLE; /* FIXME_JLIU7 REG_READ(pipeconf_reg); */ |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 860 | |
| 861 | /* Set up the display plane register */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 862 | dev_priv->dspcntr[pipe] = REG_READ(map->cntr); |
| 863 | dev_priv->dspcntr[pipe] |= pipe << DISPPLANE_SEL_PIPE_POS; |
| 864 | dev_priv->dspcntr[pipe] |= DISPLAY_PLANE_ENABLE; |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 865 | |
| 866 | if (is_mipi2) |
| 867 | goto mrst_crtc_mode_set_exit; |
| 868 | clk = adjusted_mode->clock; |
| 869 | |
| 870 | if (is_hdmi) { |
| 871 | if ((ksel == KSEL_CRYSTAL_19) || (ksel == KSEL_BYPASS_19)) { |
| 872 | refclk = 19200; |
| 873 | |
| 874 | if (is_mipi || is_mipi2) |
| 875 | clk_n = 1, clk_p2 = 8; |
| 876 | else if (is_hdmi) |
| 877 | clk_n = 1, clk_p2 = 10; |
| 878 | } else if (ksel == KSEL_BYPASS_25) { |
| 879 | refclk = 25000; |
| 880 | |
| 881 | if (is_mipi || is_mipi2) |
| 882 | clk_n = 1, clk_p2 = 8; |
| 883 | else if (is_hdmi) |
| 884 | clk_n = 1, clk_p2 = 10; |
| 885 | } else if ((ksel == KSEL_BYPASS_83_100) && |
| 886 | dev_priv->core_freq == 166) { |
| 887 | refclk = 83000; |
| 888 | |
| 889 | if (is_mipi || is_mipi2) |
| 890 | clk_n = 4, clk_p2 = 8; |
| 891 | else if (is_hdmi) |
| 892 | clk_n = 4, clk_p2 = 10; |
| 893 | } else if ((ksel == KSEL_BYPASS_83_100) && |
| 894 | (dev_priv->core_freq == 100 || |
| 895 | dev_priv->core_freq == 200)) { |
| 896 | refclk = 100000; |
| 897 | if (is_mipi || is_mipi2) |
| 898 | clk_n = 4, clk_p2 = 8; |
| 899 | else if (is_hdmi) |
| 900 | clk_n = 4, clk_p2 = 10; |
| 901 | } |
| 902 | |
| 903 | if (is_mipi) |
| 904 | clk_byte = dev_priv->bpp / 8; |
| 905 | else if (is_mipi2) |
| 906 | clk_byte = dev_priv->bpp2 / 8; |
| 907 | |
| 908 | clk_tmp = clk * clk_n * clk_p2 * clk_byte; |
| 909 | |
| 910 | dev_dbg(dev->dev, "clk = %d, clk_n = %d, clk_p2 = %d.\n", |
| 911 | clk, clk_n, clk_p2); |
| 912 | dev_dbg(dev->dev, "adjusted_mode->clock = %d, clk_tmp = %d.\n", |
| 913 | adjusted_mode->clock, clk_tmp); |
| 914 | |
| 915 | ok = mdfldFindBestPLL(crtc, clk_tmp, refclk, &clock); |
| 916 | |
| 917 | if (!ok) { |
| 918 | DRM_ERROR |
| 919 | ("mdfldFindBestPLL fail in mdfld_crtc_mode_set.\n"); |
| 920 | } else { |
| 921 | m_conv = mdfld_m_converts[(clock.m - MDFLD_M_MIN)]; |
| 922 | |
| 923 | dev_dbg(dev->dev, "dot clock = %d," |
| 924 | "m = %d, p1 = %d, m_conv = %d.\n", |
| 925 | clock.dot, clock.m, |
| 926 | clock.p1, m_conv); |
| 927 | } |
| 928 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 929 | dpll = REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 930 | |
| 931 | if (dpll & DPLL_VCO_ENABLE) { |
| 932 | dpll &= ~DPLL_VCO_ENABLE; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 933 | REG_WRITE(map->dpll, dpll); |
| 934 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 935 | |
| 936 | /* FIXME jliu7 check the DPLL lock bit PIPEACONF[29] */ |
| 937 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 938 | udelay(500); |
| 939 | |
| 940 | /* reset M1, N1 & P1 */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 941 | REG_WRITE(map->fp0, 0); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 942 | dpll &= ~MDFLD_P1_MASK; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 943 | REG_WRITE(map->dpll, dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 944 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 945 | udelay(500); |
| 946 | } |
| 947 | |
| 948 | /* When ungating power of DPLL, needs to wait 0.5us before |
| 949 | * enable the VCO */ |
| 950 | if (dpll & MDFLD_PWR_GATE_EN) { |
| 951 | dpll &= ~MDFLD_PWR_GATE_EN; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 952 | REG_WRITE(map->dpll, dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 953 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 954 | udelay(500); |
| 955 | } |
| 956 | dpll = 0; |
| 957 | |
| 958 | #if 0 /* FIXME revisit later */ |
| 959 | if (ksel == KSEL_CRYSTAL_19 || ksel == KSEL_BYPASS_19 || |
| 960 | ksel == KSEL_BYPASS_25) |
| 961 | dpll &= ~MDFLD_INPUT_REF_SEL; |
| 962 | else if (ksel == KSEL_BYPASS_83_100) |
| 963 | dpll |= MDFLD_INPUT_REF_SEL; |
| 964 | #endif /* FIXME revisit later */ |
| 965 | |
| 966 | if (is_hdmi) |
| 967 | dpll |= MDFLD_VCO_SEL; |
| 968 | |
| 969 | fp = (clk_n / 2) << 16; |
| 970 | fp |= m_conv; |
| 971 | |
| 972 | /* compute bitmask from p1 value */ |
| 973 | dpll |= (1 << (clock.p1 - 2)) << 17; |
| 974 | |
| 975 | #if 0 /* 1080p30 & 720p */ |
| 976 | dpll = 0x00050000; |
| 977 | fp = 0x000001be; |
| 978 | #endif |
| 979 | #if 0 /* 480p */ |
| 980 | dpll = 0x02010000; |
| 981 | fp = 0x000000d2; |
| 982 | #endif |
| 983 | } else { |
| 984 | #if 0 /*DBI_TPO_480x864*/ |
| 985 | dpll = 0x00020000; |
| 986 | fp = 0x00000156; |
| 987 | #endif /* DBI_TPO_480x864 */ /* get from spec. */ |
| 988 | |
| 989 | dpll = 0x00800000; |
| 990 | fp = 0x000000c1; |
| 991 | } |
| 992 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 993 | REG_WRITE(map->fp0, fp); |
| 994 | REG_WRITE(map->dpll, dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 995 | /* FIXME_MDFLD PO - change 500 to 1 after PO */ |
| 996 | udelay(500); |
| 997 | |
| 998 | dpll |= DPLL_VCO_ENABLE; |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 999 | REG_WRITE(map->dpll, dpll); |
| 1000 | REG_READ(map->dpll); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* wait for DSI PLL to lock */ |
| 1003 | while (timeout < 20000 && |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 1004 | !(REG_READ(map->conf) & PIPECONF_DSIPLL_LOCK)) { |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1005 | udelay(150); |
| 1006 | timeout++; |
| 1007 | } |
| 1008 | |
| 1009 | if (is_mipi) |
| 1010 | goto mrst_crtc_mode_set_exit; |
| 1011 | |
| 1012 | dev_dbg(dev->dev, "is_mipi = 0x%x\n", is_mipi); |
| 1013 | |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 1014 | REG_WRITE(map->conf, dev_priv->pipeconf[pipe]); |
| 1015 | REG_READ(map->conf); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1016 | |
| 1017 | /* Wait for for the pipe enable to take effect. */ |
Alan Cox | 213a843 | 2012-05-11 11:31:22 +0100 | [diff] [blame] | 1018 | REG_WRITE(map->cntr, dev_priv->dspcntr[pipe]); |
Patrik Jakobsson | d1fa08f | 2013-07-10 01:20:19 +0200 | [diff] [blame] | 1019 | gma_wait_for_vblank(dev); |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1020 | |
| 1021 | mrst_crtc_mode_set_exit: |
| 1022 | |
| 1023 | gma_power_end(dev); |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | const struct drm_crtc_helper_funcs mdfld_helper_funcs = { |
| 1029 | .dpms = mdfld_crtc_dpms, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1030 | .mode_set = mdfld_crtc_mode_set, |
| 1031 | .mode_set_base = mdfld__intel_pipe_set_base, |
Patrik Jakobsson | d903b61 | 2013-07-10 22:04:20 +0200 | [diff] [blame] | 1032 | .prepare = gma_crtc_prepare, |
| 1033 | .commit = gma_crtc_commit, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 1034 | }; |