Thomas Gleixner | c51669e | 2019-05-31 01:09:37 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2010 Matt Turner. |
| 4 | * Copyright 2012 Red Hat |
| 5 | * |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 6 | * Authors: Matthew Garrett |
| 7 | * Matt Turner |
| 8 | * Dave Airlie |
| 9 | */ |
| 10 | |
| 11 | #include <linux/delay.h> |
Thomas Zimmermann | 09daa2e | 2019-12-03 11:04:00 +0100 | [diff] [blame] | 12 | #include <linux/pci.h> |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 13 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 14 | #include <drm/drm_crtc_helper.h> |
Sam Ravnborg | 9f39780 | 2019-06-23 12:35:42 +0200 | [diff] [blame] | 15 | #include <drm/drm_fourcc.h> |
Thomas Zimmermann | 5635b7c | 2020-05-07 11:03:13 +0200 | [diff] [blame] | 16 | #include <drm/drm_gem_framebuffer_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 17 | #include <drm/drm_plane_helper.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 18 | #include <drm/drm_probe_helper.h> |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 19 | #include <drm/drm_simple_kms_helper.h> |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 20 | |
| 21 | #include "mgag200_drv.h" |
| 22 | |
| 23 | #define MGAG200_LUT_SIZE 256 |
| 24 | |
| 25 | /* |
| 26 | * This file contains setup code for the CRTC. |
| 27 | */ |
| 28 | |
| 29 | static void mga_crtc_load_lut(struct drm_crtc *crtc) |
| 30 | { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 31 | struct drm_device *dev = crtc->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 32 | struct mga_device *mdev = to_mga_device(dev); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 33 | struct drm_framebuffer *fb = crtc->primary->fb; |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 34 | u16 *r_ptr, *g_ptr, *b_ptr; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 35 | int i; |
| 36 | |
| 37 | if (!crtc->enabled) |
| 38 | return; |
| 39 | |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 40 | r_ptr = crtc->gamma_store; |
| 41 | g_ptr = r_ptr + crtc->gamma_size; |
| 42 | b_ptr = g_ptr + crtc->gamma_size; |
| 43 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 44 | WREG8(DAC_INDEX + MGA1064_INDEX, 0); |
| 45 | |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 46 | if (fb && fb->format->cpp[0] * 8 == 16) { |
Ville Syrjälä | b00c600 | 2016-12-14 23:31:35 +0200 | [diff] [blame] | 47 | int inc = (fb->format->depth == 15) ? 8 : 4; |
Egbert Eich | de7500e | 2013-07-17 15:07:27 +0200 | [diff] [blame] | 48 | u8 r, b; |
| 49 | for (i = 0; i < MGAG200_LUT_SIZE; i += inc) { |
Ville Syrjälä | b00c600 | 2016-12-14 23:31:35 +0200 | [diff] [blame] | 50 | if (fb->format->depth == 16) { |
Egbert Eich | de7500e | 2013-07-17 15:07:27 +0200 | [diff] [blame] | 51 | if (i > (MGAG200_LUT_SIZE >> 1)) { |
| 52 | r = b = 0; |
| 53 | } else { |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 54 | r = *r_ptr++ >> 8; |
| 55 | b = *b_ptr++ >> 8; |
| 56 | r_ptr++; |
| 57 | b_ptr++; |
Egbert Eich | de7500e | 2013-07-17 15:07:27 +0200 | [diff] [blame] | 58 | } |
| 59 | } else { |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 60 | r = *r_ptr++ >> 8; |
| 61 | b = *b_ptr++ >> 8; |
Egbert Eich | de7500e | 2013-07-17 15:07:27 +0200 | [diff] [blame] | 62 | } |
| 63 | /* VGA registers */ |
| 64 | WREG8(DAC_INDEX + MGA1064_COL_PAL, r); |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 65 | WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8); |
Egbert Eich | de7500e | 2013-07-17 15:07:27 +0200 | [diff] [blame] | 66 | WREG8(DAC_INDEX + MGA1064_COL_PAL, b); |
| 67 | } |
| 68 | return; |
| 69 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 70 | for (i = 0; i < MGAG200_LUT_SIZE; i++) { |
| 71 | /* VGA registers */ |
Peter Rosin | 9ed85e1 | 2017-07-13 18:25:34 +0200 | [diff] [blame] | 72 | WREG8(DAC_INDEX + MGA1064_COL_PAL, *r_ptr++ >> 8); |
| 73 | WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8); |
| 74 | WREG8(DAC_INDEX + MGA1064_COL_PAL, *b_ptr++ >> 8); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | static inline void mga_wait_vsync(struct mga_device *mdev) |
| 79 | { |
Christopher Harvey | 3cdc0e8 | 2013-05-06 15:56:17 +0000 | [diff] [blame] | 80 | unsigned long timeout = jiffies + HZ/10; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 81 | unsigned int status = 0; |
| 82 | |
| 83 | do { |
| 84 | status = RREG32(MGAREG_Status); |
Christopher Harvey | 3cdc0e8 | 2013-05-06 15:56:17 +0000 | [diff] [blame] | 85 | } while ((status & 0x08) && time_before(jiffies, timeout)); |
| 86 | timeout = jiffies + HZ/10; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 87 | status = 0; |
| 88 | do { |
| 89 | status = RREG32(MGAREG_Status); |
Christopher Harvey | 3cdc0e8 | 2013-05-06 15:56:17 +0000 | [diff] [blame] | 90 | } while (!(status & 0x08) && time_before(jiffies, timeout)); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void mga_wait_busy(struct mga_device *mdev) |
| 94 | { |
Christopher Harvey | 3cdc0e8 | 2013-05-06 15:56:17 +0000 | [diff] [blame] | 95 | unsigned long timeout = jiffies + HZ; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 96 | unsigned int status = 0; |
| 97 | do { |
| 98 | status = RREG8(MGAREG_Status + 2); |
Christopher Harvey | 3cdc0e8 | 2013-05-06 15:56:17 +0000 | [diff] [blame] | 99 | } while ((status & 0x01) && time_before(jiffies, timeout)); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 102 | #define P_ARRAY_SIZE 9 |
| 103 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 104 | static int mga_g200se_set_plls(struct mga_device *mdev, long clock) |
| 105 | { |
| 106 | unsigned int vcomax, vcomin, pllreffreq; |
| 107 | unsigned int delta, tmpdelta, permitteddelta; |
| 108 | unsigned int testp, testm, testn; |
| 109 | unsigned int p, m, n; |
| 110 | unsigned int computed; |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 111 | unsigned int pvalues_e4[P_ARRAY_SIZE] = {16, 14, 12, 10, 8, 6, 4, 2, 1}; |
| 112 | unsigned int fvv; |
| 113 | unsigned int i; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 114 | |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 115 | if (mdev->unique_rev_id <= 0x03) { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 116 | |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 117 | m = n = p = 0; |
| 118 | vcomax = 320000; |
| 119 | vcomin = 160000; |
| 120 | pllreffreq = 25000; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 121 | |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 122 | delta = 0xffffffff; |
| 123 | permitteddelta = clock * 5 / 1000; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 124 | |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 125 | for (testp = 8; testp > 0; testp /= 2) { |
| 126 | if (clock * testp > vcomax) |
| 127 | continue; |
| 128 | if (clock * testp < vcomin) |
| 129 | continue; |
| 130 | |
| 131 | for (testn = 17; testn < 256; testn++) { |
| 132 | for (testm = 1; testm < 32; testm++) { |
| 133 | computed = (pllreffreq * testn) / |
| 134 | (testm * testp); |
| 135 | if (computed > clock) |
| 136 | tmpdelta = computed - clock; |
| 137 | else |
| 138 | tmpdelta = clock - computed; |
| 139 | if (tmpdelta < delta) { |
| 140 | delta = tmpdelta; |
| 141 | m = testm - 1; |
| 142 | n = testn - 1; |
| 143 | p = testp - 1; |
| 144 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | } |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 148 | } else { |
| 149 | |
| 150 | |
| 151 | m = n = p = 0; |
| 152 | vcomax = 1600000; |
| 153 | vcomin = 800000; |
| 154 | pllreffreq = 25000; |
| 155 | |
| 156 | if (clock < 25000) |
| 157 | clock = 25000; |
| 158 | |
| 159 | clock = clock * 2; |
| 160 | |
| 161 | delta = 0xFFFFFFFF; |
| 162 | /* Permited delta is 0.5% as VESA Specification */ |
| 163 | permitteddelta = clock * 5 / 1000; |
| 164 | |
| 165 | for (i = 0 ; i < P_ARRAY_SIZE ; i++) { |
| 166 | testp = pvalues_e4[i]; |
| 167 | |
| 168 | if ((clock * testp) > vcomax) |
| 169 | continue; |
| 170 | if ((clock * testp) < vcomin) |
| 171 | continue; |
| 172 | |
| 173 | for (testn = 50; testn <= 256; testn++) { |
| 174 | for (testm = 1; testm <= 32; testm++) { |
| 175 | computed = (pllreffreq * testn) / |
| 176 | (testm * testp); |
| 177 | if (computed > clock) |
| 178 | tmpdelta = computed - clock; |
| 179 | else |
| 180 | tmpdelta = clock - computed; |
| 181 | |
| 182 | if (tmpdelta < delta) { |
| 183 | delta = tmpdelta; |
| 184 | m = testm - 1; |
| 185 | n = testn - 1; |
| 186 | p = testp - 1; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Mathieu Larouche | d3922b6 | 2016-05-27 15:12:50 -0400 | [diff] [blame] | 192 | fvv = pllreffreq * (n + 1) / (m + 1); |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 193 | fvv = (fvv - 800000) / 50000; |
| 194 | |
| 195 | if (fvv > 15) |
| 196 | fvv = 15; |
| 197 | |
| 198 | p |= (fvv << 4); |
| 199 | m |= 0x80; |
| 200 | |
| 201 | clock = clock / 2; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (delta > permitteddelta) { |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 205 | pr_warn("PLL delta too large\n"); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 206 | return 1; |
| 207 | } |
| 208 | |
| 209 | WREG_DAC(MGA1064_PIX_PLLC_M, m); |
| 210 | WREG_DAC(MGA1064_PIX_PLLC_N, n); |
| 211 | WREG_DAC(MGA1064_PIX_PLLC_P, p); |
Mathieu Larouche | d3922b6 | 2016-05-27 15:12:50 -0400 | [diff] [blame] | 212 | |
| 213 | if (mdev->unique_rev_id >= 0x04) { |
| 214 | WREG_DAC(0x1a, 0x09); |
| 215 | msleep(20); |
| 216 | WREG_DAC(0x1a, 0x01); |
| 217 | |
| 218 | } |
| 219 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | static int mga_g200wb_set_plls(struct mga_device *mdev, long clock) |
| 224 | { |
| 225 | unsigned int vcomax, vcomin, pllreffreq; |
Sudip Mukherjee | 546aee5 | 2015-07-01 17:12:45 +0530 | [diff] [blame] | 226 | unsigned int delta, tmpdelta; |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 227 | unsigned int testp, testm, testn, testp2; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 228 | unsigned int p, m, n; |
| 229 | unsigned int computed; |
| 230 | int i, j, tmpcount, vcount; |
| 231 | bool pll_locked = false; |
| 232 | u8 tmp; |
| 233 | |
| 234 | m = n = p = 0; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 235 | |
| 236 | delta = 0xffffffff; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 237 | |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 238 | if (mdev->type == G200_EW3) { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 239 | |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 240 | vcomax = 800000; |
| 241 | vcomin = 400000; |
| 242 | pllreffreq = 25000; |
| 243 | |
| 244 | for (testp = 1; testp < 8; testp++) { |
| 245 | for (testp2 = 1; testp2 < 8; testp2++) { |
| 246 | if (testp < testp2) |
| 247 | continue; |
| 248 | if ((clock * testp * testp2) > vcomax) |
| 249 | continue; |
| 250 | if ((clock * testp * testp2) < vcomin) |
| 251 | continue; |
| 252 | for (testm = 1; testm < 26; testm++) { |
| 253 | for (testn = 32; testn < 2048 ; testn++) { |
| 254 | computed = (pllreffreq * testn) / |
| 255 | (testm * testp * testp2); |
| 256 | if (computed > clock) |
| 257 | tmpdelta = computed - clock; |
| 258 | else |
| 259 | tmpdelta = clock - computed; |
| 260 | if (tmpdelta < delta) { |
| 261 | delta = tmpdelta; |
| 262 | m = ((testn & 0x100) >> 1) | |
| 263 | (testm); |
| 264 | n = (testn & 0xFF); |
| 265 | p = ((testn & 0x600) >> 3) | |
| 266 | (testp2 << 3) | |
| 267 | (testp); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } else { |
| 274 | |
| 275 | vcomax = 550000; |
| 276 | vcomin = 150000; |
| 277 | pllreffreq = 48000; |
| 278 | |
| 279 | for (testp = 1; testp < 9; testp++) { |
| 280 | if (clock * testp > vcomax) |
| 281 | continue; |
| 282 | if (clock * testp < vcomin) |
| 283 | continue; |
| 284 | |
| 285 | for (testm = 1; testm < 17; testm++) { |
| 286 | for (testn = 1; testn < 151; testn++) { |
| 287 | computed = (pllreffreq * testn) / |
| 288 | (testm * testp); |
| 289 | if (computed > clock) |
| 290 | tmpdelta = computed - clock; |
| 291 | else |
| 292 | tmpdelta = clock - computed; |
| 293 | if (tmpdelta < delta) { |
| 294 | delta = tmpdelta; |
| 295 | n = testn - 1; |
| 296 | m = (testm - 1) | |
| 297 | ((n >> 1) & 0x80); |
| 298 | p = testp - 1; |
| 299 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | for (i = 0; i <= 32 && pll_locked == false; i++) { |
| 306 | if (i > 0) { |
| 307 | WREG8(MGAREG_CRTC_INDEX, 0x1e); |
| 308 | tmp = RREG8(MGAREG_CRTC_DATA); |
| 309 | if (tmp < 0xff) |
| 310 | WREG8(MGAREG_CRTC_DATA, tmp+1); |
| 311 | } |
| 312 | |
| 313 | /* set pixclkdis to 1 */ |
| 314 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 315 | tmp = RREG8(DAC_DATA); |
| 316 | tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 317 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 318 | |
| 319 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL); |
| 320 | tmp = RREG8(DAC_DATA); |
| 321 | tmp |= MGA1064_REMHEADCTL_CLKDIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 322 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 323 | |
| 324 | /* select PLL Set C */ |
| 325 | tmp = RREG8(MGAREG_MEM_MISC_READ); |
| 326 | tmp |= 0x3 << 2; |
| 327 | WREG8(MGAREG_MEM_MISC_WRITE, tmp); |
| 328 | |
| 329 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 330 | tmp = RREG8(DAC_DATA); |
| 331 | tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN | 0x80; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 332 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 333 | |
| 334 | udelay(500); |
| 335 | |
| 336 | /* reset the PLL */ |
| 337 | WREG8(DAC_INDEX, MGA1064_VREF_CTL); |
| 338 | tmp = RREG8(DAC_DATA); |
| 339 | tmp &= ~0x04; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 340 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 341 | |
| 342 | udelay(50); |
| 343 | |
| 344 | /* program pixel pll register */ |
| 345 | WREG_DAC(MGA1064_WB_PIX_PLLC_N, n); |
| 346 | WREG_DAC(MGA1064_WB_PIX_PLLC_M, m); |
| 347 | WREG_DAC(MGA1064_WB_PIX_PLLC_P, p); |
| 348 | |
| 349 | udelay(50); |
| 350 | |
| 351 | /* turn pll on */ |
| 352 | WREG8(DAC_INDEX, MGA1064_VREF_CTL); |
| 353 | tmp = RREG8(DAC_DATA); |
| 354 | tmp |= 0x04; |
| 355 | WREG_DAC(MGA1064_VREF_CTL, tmp); |
| 356 | |
| 357 | udelay(500); |
| 358 | |
| 359 | /* select the pixel pll */ |
| 360 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 361 | tmp = RREG8(DAC_DATA); |
| 362 | tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK; |
| 363 | tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 364 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 365 | |
| 366 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL); |
| 367 | tmp = RREG8(DAC_DATA); |
| 368 | tmp &= ~MGA1064_REMHEADCTL_CLKSL_MSK; |
| 369 | tmp |= MGA1064_REMHEADCTL_CLKSL_PLL; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 370 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 371 | |
| 372 | /* reset dotclock rate bit */ |
| 373 | WREG8(MGAREG_SEQ_INDEX, 1); |
| 374 | tmp = RREG8(MGAREG_SEQ_DATA); |
| 375 | tmp &= ~0x8; |
| 376 | WREG8(MGAREG_SEQ_DATA, tmp); |
| 377 | |
| 378 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 379 | tmp = RREG8(DAC_DATA); |
| 380 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 381 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 382 | |
| 383 | vcount = RREG8(MGAREG_VCOUNT); |
| 384 | |
| 385 | for (j = 0; j < 30 && pll_locked == false; j++) { |
| 386 | tmpcount = RREG8(MGAREG_VCOUNT); |
| 387 | if (tmpcount < vcount) |
| 388 | vcount = 0; |
| 389 | if ((tmpcount - vcount) > 2) |
| 390 | pll_locked = true; |
| 391 | else |
| 392 | udelay(5); |
| 393 | } |
| 394 | } |
| 395 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL); |
| 396 | tmp = RREG8(DAC_DATA); |
| 397 | tmp &= ~MGA1064_REMHEADCTL_CLKDIS; |
| 398 | WREG_DAC(MGA1064_REMHEADCTL, tmp); |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int mga_g200ev_set_plls(struct mga_device *mdev, long clock) |
| 403 | { |
| 404 | unsigned int vcomax, vcomin, pllreffreq; |
Sudip Mukherjee | 546aee5 | 2015-07-01 17:12:45 +0530 | [diff] [blame] | 405 | unsigned int delta, tmpdelta; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 406 | unsigned int testp, testm, testn; |
| 407 | unsigned int p, m, n; |
| 408 | unsigned int computed; |
| 409 | u8 tmp; |
| 410 | |
| 411 | m = n = p = 0; |
| 412 | vcomax = 550000; |
| 413 | vcomin = 150000; |
| 414 | pllreffreq = 50000; |
| 415 | |
| 416 | delta = 0xffffffff; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 417 | |
| 418 | for (testp = 16; testp > 0; testp--) { |
| 419 | if (clock * testp > vcomax) |
| 420 | continue; |
| 421 | if (clock * testp < vcomin) |
| 422 | continue; |
| 423 | |
| 424 | for (testn = 1; testn < 257; testn++) { |
| 425 | for (testm = 1; testm < 17; testm++) { |
| 426 | computed = (pllreffreq * testn) / |
| 427 | (testm * testp); |
| 428 | if (computed > clock) |
| 429 | tmpdelta = computed - clock; |
| 430 | else |
| 431 | tmpdelta = clock - computed; |
| 432 | if (tmpdelta < delta) { |
| 433 | delta = tmpdelta; |
| 434 | n = testn - 1; |
| 435 | m = testm - 1; |
| 436 | p = testp - 1; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 443 | tmp = RREG8(DAC_DATA); |
| 444 | tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 445 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 446 | |
| 447 | tmp = RREG8(MGAREG_MEM_MISC_READ); |
| 448 | tmp |= 0x3 << 2; |
| 449 | WREG8(MGAREG_MEM_MISC_WRITE, tmp); |
| 450 | |
| 451 | WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT); |
| 452 | tmp = RREG8(DAC_DATA); |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 453 | WREG8(DAC_DATA, tmp & ~0x40); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 454 | |
| 455 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 456 | tmp = RREG8(DAC_DATA); |
| 457 | tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 458 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 459 | |
| 460 | WREG_DAC(MGA1064_EV_PIX_PLLC_M, m); |
| 461 | WREG_DAC(MGA1064_EV_PIX_PLLC_N, n); |
| 462 | WREG_DAC(MGA1064_EV_PIX_PLLC_P, p); |
| 463 | |
| 464 | udelay(50); |
| 465 | |
| 466 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 467 | tmp = RREG8(DAC_DATA); |
| 468 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 469 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 470 | |
| 471 | udelay(500); |
| 472 | |
| 473 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 474 | tmp = RREG8(DAC_DATA); |
| 475 | tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK; |
| 476 | tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 477 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 478 | |
| 479 | WREG8(DAC_INDEX, MGA1064_PIX_PLL_STAT); |
| 480 | tmp = RREG8(DAC_DATA); |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 481 | WREG8(DAC_DATA, tmp | 0x40); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 482 | |
| 483 | tmp = RREG8(MGAREG_MEM_MISC_READ); |
| 484 | tmp |= (0x3 << 2); |
| 485 | WREG8(MGAREG_MEM_MISC_WRITE, tmp); |
| 486 | |
| 487 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 488 | tmp = RREG8(DAC_DATA); |
| 489 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 490 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static int mga_g200eh_set_plls(struct mga_device *mdev, long clock) |
| 496 | { |
| 497 | unsigned int vcomax, vcomin, pllreffreq; |
Sudip Mukherjee | 546aee5 | 2015-07-01 17:12:45 +0530 | [diff] [blame] | 498 | unsigned int delta, tmpdelta; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 499 | unsigned int testp, testm, testn; |
| 500 | unsigned int p, m, n; |
| 501 | unsigned int computed; |
| 502 | int i, j, tmpcount, vcount; |
| 503 | u8 tmp; |
| 504 | bool pll_locked = false; |
| 505 | |
| 506 | m = n = p = 0; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 507 | |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 508 | if (mdev->type == G200_EH3) { |
| 509 | vcomax = 3000000; |
| 510 | vcomin = 1500000; |
| 511 | pllreffreq = 25000; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 512 | |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 513 | delta = 0xffffffff; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 514 | |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 515 | testp = 0; |
| 516 | |
| 517 | for (testm = 150; testm >= 6; testm--) { |
| 518 | if (clock * testm > vcomax) |
| 519 | continue; |
| 520 | if (clock * testm < vcomin) |
| 521 | continue; |
| 522 | for (testn = 120; testn >= 60; testn--) { |
| 523 | computed = (pllreffreq * testn) / testm; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 524 | if (computed > clock) |
| 525 | tmpdelta = computed - clock; |
| 526 | else |
| 527 | tmpdelta = clock - computed; |
| 528 | if (tmpdelta < delta) { |
| 529 | delta = tmpdelta; |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 530 | n = testn; |
| 531 | m = testm; |
| 532 | p = testp; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 533 | } |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 534 | if (delta == 0) |
| 535 | break; |
| 536 | } |
| 537 | if (delta == 0) |
| 538 | break; |
| 539 | } |
| 540 | } else { |
| 541 | |
| 542 | vcomax = 800000; |
| 543 | vcomin = 400000; |
| 544 | pllreffreq = 33333; |
| 545 | |
| 546 | delta = 0xffffffff; |
| 547 | |
| 548 | for (testp = 16; testp > 0; testp >>= 1) { |
| 549 | if (clock * testp > vcomax) |
| 550 | continue; |
| 551 | if (clock * testp < vcomin) |
| 552 | continue; |
| 553 | |
| 554 | for (testm = 1; testm < 33; testm++) { |
| 555 | for (testn = 17; testn < 257; testn++) { |
| 556 | computed = (pllreffreq * testn) / |
| 557 | (testm * testp); |
| 558 | if (computed > clock) |
| 559 | tmpdelta = computed - clock; |
| 560 | else |
| 561 | tmpdelta = clock - computed; |
| 562 | if (tmpdelta < delta) { |
| 563 | delta = tmpdelta; |
| 564 | n = testn - 1; |
| 565 | m = (testm - 1); |
| 566 | p = testp - 1; |
| 567 | } |
| 568 | if ((clock * testp) >= 600000) |
| 569 | p |= 0x80; |
| 570 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | } |
| 574 | for (i = 0; i <= 32 && pll_locked == false; i++) { |
| 575 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 576 | tmp = RREG8(DAC_DATA); |
| 577 | tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 578 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 579 | |
| 580 | tmp = RREG8(MGAREG_MEM_MISC_READ); |
| 581 | tmp |= 0x3 << 2; |
| 582 | WREG8(MGAREG_MEM_MISC_WRITE, tmp); |
| 583 | |
| 584 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 585 | tmp = RREG8(DAC_DATA); |
| 586 | tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 587 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 588 | |
| 589 | udelay(500); |
| 590 | |
| 591 | WREG_DAC(MGA1064_EH_PIX_PLLC_M, m); |
| 592 | WREG_DAC(MGA1064_EH_PIX_PLLC_N, n); |
| 593 | WREG_DAC(MGA1064_EH_PIX_PLLC_P, p); |
| 594 | |
| 595 | udelay(500); |
| 596 | |
| 597 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 598 | tmp = RREG8(DAC_DATA); |
| 599 | tmp &= ~MGA1064_PIX_CLK_CTL_SEL_MSK; |
| 600 | tmp |= MGA1064_PIX_CLK_CTL_SEL_PLL; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 601 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 602 | |
| 603 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 604 | tmp = RREG8(DAC_DATA); |
| 605 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS; |
| 606 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_POW_DOWN; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 607 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 608 | |
| 609 | vcount = RREG8(MGAREG_VCOUNT); |
| 610 | |
| 611 | for (j = 0; j < 30 && pll_locked == false; j++) { |
| 612 | tmpcount = RREG8(MGAREG_VCOUNT); |
| 613 | if (tmpcount < vcount) |
| 614 | vcount = 0; |
| 615 | if ((tmpcount - vcount) > 2) |
| 616 | pll_locked = true; |
| 617 | else |
| 618 | udelay(5); |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static int mga_g200er_set_plls(struct mga_device *mdev, long clock) |
| 626 | { |
| 627 | unsigned int vcomax, vcomin, pllreffreq; |
| 628 | unsigned int delta, tmpdelta; |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 629 | int testr, testn, testm, testo; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 630 | unsigned int p, m, n; |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 631 | unsigned int computed, vco; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 632 | int tmp; |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 633 | const unsigned int m_div_val[] = { 1, 2, 4, 8 }; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 634 | |
| 635 | m = n = p = 0; |
| 636 | vcomax = 1488000; |
| 637 | vcomin = 1056000; |
| 638 | pllreffreq = 48000; |
| 639 | |
| 640 | delta = 0xffffffff; |
| 641 | |
| 642 | for (testr = 0; testr < 4; testr++) { |
| 643 | if (delta == 0) |
| 644 | break; |
| 645 | for (testn = 5; testn < 129; testn++) { |
| 646 | if (delta == 0) |
| 647 | break; |
| 648 | for (testm = 3; testm >= 0; testm--) { |
| 649 | if (delta == 0) |
| 650 | break; |
| 651 | for (testo = 5; testo < 33; testo++) { |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 652 | vco = pllreffreq * (testn + 1) / |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 653 | (testr + 1); |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 654 | if (vco < vcomin) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 655 | continue; |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 656 | if (vco > vcomax) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 657 | continue; |
Dave Airlie | 9830605 | 2012-08-09 15:00:15 +1000 | [diff] [blame] | 658 | computed = vco / (m_div_val[testm] * (testo + 1)); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 659 | if (computed > clock) |
| 660 | tmpdelta = computed - clock; |
| 661 | else |
| 662 | tmpdelta = clock - computed; |
| 663 | if (tmpdelta < delta) { |
| 664 | delta = tmpdelta; |
| 665 | m = testm | (testo << 3); |
| 666 | n = testn; |
| 667 | p = testr | (testr << 3); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 675 | tmp = RREG8(DAC_DATA); |
| 676 | tmp |= MGA1064_PIX_CLK_CTL_CLK_DIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 677 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 678 | |
| 679 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL); |
| 680 | tmp = RREG8(DAC_DATA); |
| 681 | tmp |= MGA1064_REMHEADCTL_CLKDIS; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 682 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 683 | |
| 684 | tmp = RREG8(MGAREG_MEM_MISC_READ); |
| 685 | tmp |= (0x3<<2) | 0xc0; |
| 686 | WREG8(MGAREG_MEM_MISC_WRITE, tmp); |
| 687 | |
| 688 | WREG8(DAC_INDEX, MGA1064_PIX_CLK_CTL); |
| 689 | tmp = RREG8(DAC_DATA); |
| 690 | tmp &= ~MGA1064_PIX_CLK_CTL_CLK_DIS; |
| 691 | tmp |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN; |
Christopher Harvey | fb70a66 | 2013-04-12 22:24:05 +0000 | [diff] [blame] | 692 | WREG8(DAC_DATA, tmp); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 693 | |
| 694 | udelay(500); |
| 695 | |
| 696 | WREG_DAC(MGA1064_ER_PIX_PLLC_N, n); |
| 697 | WREG_DAC(MGA1064_ER_PIX_PLLC_M, m); |
| 698 | WREG_DAC(MGA1064_ER_PIX_PLLC_P, p); |
| 699 | |
| 700 | udelay(50); |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int mga_crtc_set_plls(struct mga_device *mdev, long clock) |
| 706 | { |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 707 | u8 misc; |
| 708 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 709 | switch(mdev->type) { |
| 710 | case G200_SE_A: |
| 711 | case G200_SE_B: |
| 712 | return mga_g200se_set_plls(mdev, clock); |
| 713 | break; |
| 714 | case G200_WB: |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 715 | case G200_EW3: |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 716 | return mga_g200wb_set_plls(mdev, clock); |
| 717 | break; |
| 718 | case G200_EV: |
| 719 | return mga_g200ev_set_plls(mdev, clock); |
| 720 | break; |
| 721 | case G200_EH: |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 722 | case G200_EH3: |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 723 | return mga_g200eh_set_plls(mdev, clock); |
| 724 | break; |
| 725 | case G200_ER: |
| 726 | return mga_g200er_set_plls(mdev, clock); |
| 727 | break; |
| 728 | } |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 729 | |
| 730 | misc = RREG8(MGA_MISC_IN); |
| 731 | misc &= ~MGAREG_MISC_CLK_SEL_MASK; |
| 732 | misc |= MGAREG_MISC_CLK_SEL_MGA_MSK; |
| 733 | WREG8(MGA_MISC_OUT, misc); |
| 734 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static void mga_g200wb_prepare(struct drm_crtc *crtc) |
| 739 | { |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 740 | struct mga_device *mdev = to_mga_device(crtc->dev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 741 | u8 tmp; |
| 742 | int iter_max; |
| 743 | |
| 744 | /* 1- The first step is to warn the BMC of an upcoming mode change. |
| 745 | * We are putting the misc<0> to output.*/ |
| 746 | |
| 747 | WREG8(DAC_INDEX, MGA1064_GEN_IO_CTL); |
| 748 | tmp = RREG8(DAC_DATA); |
| 749 | tmp |= 0x10; |
| 750 | WREG_DAC(MGA1064_GEN_IO_CTL, tmp); |
| 751 | |
| 752 | /* we are putting a 1 on the misc<0> line */ |
| 753 | WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA); |
| 754 | tmp = RREG8(DAC_DATA); |
| 755 | tmp |= 0x10; |
| 756 | WREG_DAC(MGA1064_GEN_IO_DATA, tmp); |
| 757 | |
| 758 | /* 2- Second step to mask and further scan request |
| 759 | * This will be done by asserting the remfreqmsk bit (XSPAREREG<7>) |
| 760 | */ |
| 761 | WREG8(DAC_INDEX, MGA1064_SPAREREG); |
| 762 | tmp = RREG8(DAC_DATA); |
| 763 | tmp |= 0x80; |
| 764 | WREG_DAC(MGA1064_SPAREREG, tmp); |
| 765 | |
| 766 | /* 3a- the third step is to verifu if there is an active scan |
| 767 | * We are searching for a 0 on remhsyncsts <XSPAREREG<0>) |
| 768 | */ |
| 769 | iter_max = 300; |
| 770 | while (!(tmp & 0x1) && iter_max) { |
| 771 | WREG8(DAC_INDEX, MGA1064_SPAREREG); |
| 772 | tmp = RREG8(DAC_DATA); |
| 773 | udelay(1000); |
| 774 | iter_max--; |
| 775 | } |
| 776 | |
| 777 | /* 3b- this step occurs only if the remove is actually scanning |
| 778 | * we are waiting for the end of the frame which is a 1 on |
| 779 | * remvsyncsts (XSPAREREG<1>) |
| 780 | */ |
| 781 | if (iter_max) { |
| 782 | iter_max = 300; |
| 783 | while ((tmp & 0x2) && iter_max) { |
| 784 | WREG8(DAC_INDEX, MGA1064_SPAREREG); |
| 785 | tmp = RREG8(DAC_DATA); |
| 786 | udelay(1000); |
| 787 | iter_max--; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | static void mga_g200wb_commit(struct drm_crtc *crtc) |
| 793 | { |
| 794 | u8 tmp; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 795 | struct mga_device *mdev = to_mga_device(crtc->dev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 796 | |
| 797 | /* 1- The first step is to ensure that the vrsten and hrsten are set */ |
| 798 | WREG8(MGAREG_CRTCEXT_INDEX, 1); |
| 799 | tmp = RREG8(MGAREG_CRTCEXT_DATA); |
| 800 | WREG8(MGAREG_CRTCEXT_DATA, tmp | 0x88); |
| 801 | |
| 802 | /* 2- second step is to assert the rstlvl2 */ |
| 803 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL2); |
| 804 | tmp = RREG8(DAC_DATA); |
| 805 | tmp |= 0x8; |
| 806 | WREG8(DAC_DATA, tmp); |
| 807 | |
| 808 | /* wait 10 us */ |
| 809 | udelay(10); |
| 810 | |
| 811 | /* 3- deassert rstlvl2 */ |
| 812 | tmp &= ~0x08; |
| 813 | WREG8(DAC_INDEX, MGA1064_REMHEADCTL2); |
| 814 | WREG8(DAC_DATA, tmp); |
| 815 | |
| 816 | /* 4- remove mask of scan request */ |
| 817 | WREG8(DAC_INDEX, MGA1064_SPAREREG); |
| 818 | tmp = RREG8(DAC_DATA); |
| 819 | tmp &= ~0x80; |
| 820 | WREG8(DAC_DATA, tmp); |
| 821 | |
| 822 | /* 5- put back a 0 on the misc<0> line */ |
| 823 | WREG8(DAC_INDEX, MGA1064_GEN_IO_DATA); |
| 824 | tmp = RREG8(DAC_DATA); |
| 825 | tmp &= ~0x10; |
| 826 | WREG_DAC(MGA1064_GEN_IO_DATA, tmp); |
| 827 | } |
| 828 | |
Christopher Harvey | 9f1d036 | 2013-05-08 19:10:38 +0000 | [diff] [blame] | 829 | /* |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 830 | * This is how the framebuffer base address is stored in g200 cards: |
| 831 | * * Assume @offset is the gpu_addr variable of the framebuffer object |
| 832 | * * Then addr is the number of _pixels_ (not bytes) from the start of |
| 833 | * VRAM to the first pixel we want to display. (divided by 2 for 32bit |
| 834 | * framebuffers) |
| 835 | * * addr is stored in the CRTCEXT0, CRTCC and CRTCD registers |
| 836 | * addr<20> -> CRTCEXT0<6> |
| 837 | * addr<19-16> -> CRTCEXT0<3-0> |
| 838 | * addr<15-8> -> CRTCC<7-0> |
| 839 | * addr<7-0> -> CRTCD<7-0> |
| 840 | * |
| 841 | * CRTCEXT0 has to be programmed last to trigger an update and make the |
| 842 | * new addr variable take effect. |
Christopher Harvey | 9f1d036 | 2013-05-08 19:10:38 +0000 | [diff] [blame] | 843 | */ |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 844 | static void mgag200_set_startadd(struct mga_device *mdev, |
| 845 | unsigned long offset) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 846 | { |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 847 | struct drm_device *dev = mdev->dev; |
| 848 | u32 startadd; |
| 849 | u8 crtcc, crtcd, crtcext0; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 850 | |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 851 | startadd = offset / 8; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 852 | |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 853 | /* |
| 854 | * Can't store addresses any higher than that, but we also |
| 855 | * don't have more than 16 MiB of memory, so it should be fine. |
| 856 | */ |
| 857 | drm_WARN_ON(dev, startadd > 0x1fffff); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 858 | |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 859 | RREG_ECRT(0x00, crtcext0); |
| 860 | |
| 861 | crtcc = (startadd >> 8) & 0xff; |
| 862 | crtcd = startadd & 0xff; |
| 863 | crtcext0 &= 0xb0; |
| 864 | crtcext0 |= ((startadd >> 14) & BIT(6)) | |
| 865 | ((startadd >> 16) & 0x0f); |
| 866 | |
| 867 | WREG_CRT(0x0c, crtcc); |
| 868 | WREG_CRT(0x0d, crtcd); |
| 869 | WREG_ECRT(0x00, crtcext0); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 872 | static int mga_crtc_do_set_base(struct mga_device *mdev, |
| 873 | const struct drm_framebuffer *fb, |
| 874 | const struct drm_framebuffer *old_fb) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 875 | { |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 876 | struct drm_gem_vram_object *gbo; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 877 | int ret; |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 878 | s64 gpu_addr; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 879 | |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 880 | if (old_fb) { |
| 881 | gbo = drm_gem_vram_of_gem(old_fb->obj[0]); |
Thomas Zimmermann | 81da87f | 2019-05-21 13:08:29 +0200 | [diff] [blame] | 882 | drm_gem_vram_unpin(gbo); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 885 | gbo = drm_gem_vram_of_gem(fb->obj[0]); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 886 | |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 887 | ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM); |
| 888 | if (ret) |
Thomas Zimmermann | 5b24f71 | 2019-05-16 18:27:46 +0200 | [diff] [blame] | 889 | return ret; |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 890 | gpu_addr = drm_gem_vram_offset(gbo); |
| 891 | if (gpu_addr < 0) { |
| 892 | ret = (int)gpu_addr; |
| 893 | goto err_drm_gem_vram_unpin; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 894 | } |
| 895 | |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 896 | mgag200_set_startadd(mdev, (unsigned long)gpu_addr); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 897 | |
| 898 | return 0; |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 899 | |
| 900 | err_drm_gem_vram_unpin: |
| 901 | drm_gem_vram_unpin(gbo); |
Thomas Zimmermann | ebb04eb | 2019-05-08 10:26:24 +0200 | [diff] [blame] | 902 | return ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static int mga_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
| 906 | struct drm_framebuffer *old_fb) |
| 907 | { |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 908 | struct drm_device *dev = crtc->dev; |
| 909 | struct mga_device *mdev = dev->dev_private; |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 910 | struct drm_framebuffer *fb = crtc->primary->fb; |
Thomas Zimmermann | d623768 | 2020-05-15 10:32:20 +0200 | [diff] [blame] | 911 | unsigned int count; |
| 912 | |
| 913 | do { } while (RREG8(0x1fda) & 0x08); |
| 914 | do { } while (!(RREG8(0x1fda) & 0x08)); |
| 915 | |
| 916 | count = RREG8(MGAREG_VCOUNT) + 2; |
| 917 | do { } while (RREG8(MGAREG_VCOUNT) < count); |
| 918 | |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 919 | return mga_crtc_do_set_base(mdev, fb, old_fb); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 920 | } |
| 921 | |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 922 | static void mgag200_set_mode_regs(struct mga_device *mdev, |
| 923 | const struct drm_display_mode *mode) |
| 924 | { |
| 925 | unsigned int hdisplay, hsyncstart, hsyncend, htotal; |
| 926 | unsigned int vdisplay, vsyncstart, vsyncend, vtotal; |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 927 | u8 misc, crtcext1, crtcext2, crtcext5; |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 928 | |
| 929 | hdisplay = mode->hdisplay / 8 - 1; |
| 930 | hsyncstart = mode->hsync_start / 8 - 1; |
| 931 | hsyncend = mode->hsync_end / 8 - 1; |
| 932 | htotal = mode->htotal / 8 - 1; |
| 933 | |
| 934 | /* Work around hardware quirk */ |
| 935 | if ((htotal & 0x07) == 0x06 || (htotal & 0x07) == 0x04) |
| 936 | htotal++; |
| 937 | |
| 938 | vdisplay = mode->vdisplay - 1; |
| 939 | vsyncstart = mode->vsync_start - 1; |
| 940 | vsyncend = mode->vsync_end - 1; |
| 941 | vtotal = mode->vtotal - 2; |
| 942 | |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 943 | misc = RREG8(MGA_MISC_IN); |
| 944 | |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 945 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 946 | misc |= MGAREG_MISC_HSYNCPOL; |
| 947 | else |
| 948 | misc &= ~MGAREG_MISC_HSYNCPOL; |
| 949 | |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 950 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 951 | misc |= MGAREG_MISC_VSYNCPOL; |
| 952 | else |
| 953 | misc &= ~MGAREG_MISC_VSYNCPOL; |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 954 | |
| 955 | crtcext1 = (((htotal - 4) & 0x100) >> 8) | |
| 956 | ((hdisplay & 0x100) >> 7) | |
| 957 | ((hsyncstart & 0x100) >> 6) | |
| 958 | (htotal & 0x40); |
| 959 | if (mdev->type == G200_WB || mdev->type == G200_EW3) |
| 960 | crtcext1 |= BIT(7) | /* vrsten */ |
| 961 | BIT(3); /* hrsten */ |
| 962 | |
| 963 | crtcext2 = ((vtotal & 0xc00) >> 10) | |
| 964 | ((vdisplay & 0x400) >> 8) | |
| 965 | ((vdisplay & 0xc00) >> 7) | |
| 966 | ((vsyncstart & 0xc00) >> 5) | |
| 967 | ((vdisplay & 0x400) >> 3); |
| 968 | crtcext5 = 0x00; |
| 969 | |
| 970 | WREG_CRT(0, htotal - 4); |
| 971 | WREG_CRT(1, hdisplay); |
| 972 | WREG_CRT(2, hdisplay); |
| 973 | WREG_CRT(3, (htotal & 0x1F) | 0x80); |
| 974 | WREG_CRT(4, hsyncstart); |
| 975 | WREG_CRT(5, ((htotal & 0x20) << 2) | (hsyncend & 0x1F)); |
| 976 | WREG_CRT(6, vtotal & 0xFF); |
| 977 | WREG_CRT(7, ((vtotal & 0x100) >> 8) | |
| 978 | ((vdisplay & 0x100) >> 7) | |
| 979 | ((vsyncstart & 0x100) >> 6) | |
| 980 | ((vdisplay & 0x100) >> 5) | |
| 981 | ((vdisplay & 0x100) >> 4) | /* linecomp */ |
| 982 | ((vtotal & 0x200) >> 4) | |
| 983 | ((vdisplay & 0x200) >> 3) | |
| 984 | ((vsyncstart & 0x200) >> 2)); |
| 985 | WREG_CRT(9, ((vdisplay & 0x200) >> 4) | |
| 986 | ((vdisplay & 0x200) >> 3)); |
| 987 | WREG_CRT(16, vsyncstart & 0xFF); |
| 988 | WREG_CRT(17, (vsyncend & 0x0F) | 0x20); |
| 989 | WREG_CRT(18, vdisplay & 0xFF); |
| 990 | WREG_CRT(20, 0); |
| 991 | WREG_CRT(21, vdisplay & 0xFF); |
| 992 | WREG_CRT(22, (vtotal + 1) & 0xFF); |
| 993 | WREG_CRT(23, 0xc3); |
| 994 | WREG_CRT(24, vdisplay & 0xFF); |
| 995 | |
| 996 | WREG_ECRT(0x01, crtcext1); |
| 997 | WREG_ECRT(0x02, crtcext2); |
| 998 | WREG_ECRT(0x05, crtcext5); |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 999 | |
| 1000 | WREG8(MGA_MISC_OUT, misc); |
| 1001 | |
| 1002 | mga_crtc_set_plls(mdev, mode->clock); |
Thomas Zimmermann | a6edae0 | 2020-05-15 10:32:22 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
Thomas Zimmermann | 72a03a3 | 2020-05-15 10:32:25 +0200 | [diff] [blame] | 1005 | static u8 mgag200_get_bpp_shift(struct mga_device *mdev, |
| 1006 | const struct drm_format_info *format) |
| 1007 | { |
| 1008 | return mdev->bpp_shifts[format->cpp[0] - 1]; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * Calculates the HW offset value from the framebuffer's pitch. The |
| 1013 | * offset is a multiple of the pixel size and depends on the display |
| 1014 | * format. |
| 1015 | */ |
| 1016 | static u32 mgag200_calculate_offset(struct mga_device *mdev, |
| 1017 | const struct drm_framebuffer *fb) |
| 1018 | { |
| 1019 | u32 offset = fb->pitches[0] / fb->format->cpp[0]; |
| 1020 | u8 bppshift = mgag200_get_bpp_shift(mdev, fb->format); |
| 1021 | |
| 1022 | if (fb->format->cpp[0] * 8 == 24) |
| 1023 | offset = (offset * 3) >> (4 - bppshift); |
| 1024 | else |
| 1025 | offset = offset >> (4 - bppshift); |
| 1026 | |
| 1027 | return offset; |
| 1028 | } |
| 1029 | |
| 1030 | static void mgag200_set_offset(struct mga_device *mdev, |
| 1031 | const struct drm_framebuffer *fb) |
| 1032 | { |
| 1033 | u8 crtc13, crtcext0; |
| 1034 | u32 offset = mgag200_calculate_offset(mdev, fb); |
| 1035 | |
| 1036 | RREG_ECRT(0, crtcext0); |
| 1037 | |
| 1038 | crtc13 = offset & 0xff; |
| 1039 | |
| 1040 | crtcext0 &= ~MGAREG_CRTCEXT0_OFFSET_MASK; |
| 1041 | crtcext0 |= (offset >> 4) & MGAREG_CRTCEXT0_OFFSET_MASK; |
| 1042 | |
| 1043 | WREG_CRT(0x13, crtc13); |
| 1044 | WREG_ECRT(0x00, crtcext0); |
| 1045 | } |
| 1046 | |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1047 | static void mgag200_set_format_regs(struct mga_device *mdev, |
| 1048 | const struct drm_framebuffer *fb) |
| 1049 | { |
| 1050 | struct drm_device *dev = mdev->dev; |
| 1051 | const struct drm_format_info *format = fb->format; |
| 1052 | unsigned int bpp, bppshift, scale; |
| 1053 | u8 crtcext3, xmulctrl; |
| 1054 | |
| 1055 | bpp = format->cpp[0] * 8; |
| 1056 | |
| 1057 | bppshift = mgag200_get_bpp_shift(mdev, format); |
| 1058 | switch (bpp) { |
| 1059 | case 24: |
| 1060 | scale = ((1 << bppshift) * 3) - 1; |
| 1061 | break; |
| 1062 | default: |
| 1063 | scale = (1 << bppshift) - 1; |
| 1064 | break; |
| 1065 | } |
| 1066 | |
| 1067 | RREG_ECRT(3, crtcext3); |
| 1068 | |
| 1069 | switch (bpp) { |
| 1070 | case 8: |
| 1071 | xmulctrl = MGA1064_MUL_CTL_8bits; |
| 1072 | break; |
| 1073 | case 16: |
| 1074 | if (format->depth == 15) |
| 1075 | xmulctrl = MGA1064_MUL_CTL_15bits; |
| 1076 | else |
| 1077 | xmulctrl = MGA1064_MUL_CTL_16bits; |
| 1078 | break; |
| 1079 | case 24: |
| 1080 | xmulctrl = MGA1064_MUL_CTL_24bits; |
| 1081 | break; |
| 1082 | case 32: |
| 1083 | xmulctrl = MGA1064_MUL_CTL_32_24bits; |
| 1084 | break; |
| 1085 | default: |
| 1086 | /* BUG: We should have caught this problem already. */ |
| 1087 | drm_WARN_ON(dev, "invalid format depth\n"); |
| 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | crtcext3 &= ~GENMASK(2, 0); |
| 1092 | crtcext3 |= scale; |
| 1093 | |
| 1094 | WREG_DAC(MGA1064_MUL_CTL, xmulctrl); |
| 1095 | |
| 1096 | WREG_GFX(0, 0x00); |
| 1097 | WREG_GFX(1, 0x00); |
| 1098 | WREG_GFX(2, 0x00); |
| 1099 | WREG_GFX(3, 0x00); |
| 1100 | WREG_GFX(4, 0x00); |
| 1101 | WREG_GFX(5, 0x40); |
| 1102 | WREG_GFX(6, 0x05); |
| 1103 | WREG_GFX(7, 0x0f); |
| 1104 | WREG_GFX(8, 0x0f); |
| 1105 | |
| 1106 | WREG_ECRT(3, crtcext3); |
| 1107 | } |
| 1108 | |
Thomas Zimmermann | 2e5ccbb | 2020-05-15 10:32:27 +0200 | [diff] [blame] | 1109 | static void mgag200_g200er_reset_tagfifo(struct mga_device *mdev) |
| 1110 | { |
| 1111 | static uint32_t RESET_FLAG = 0x00200000; /* undocumented magic value */ |
| 1112 | u8 seq1; |
| 1113 | u32 memctl; |
| 1114 | |
| 1115 | /* screen off */ |
| 1116 | RREG_SEQ(0x01, seq1); |
| 1117 | seq1 |= MGAREG_SEQ1_SCROFF; |
| 1118 | WREG_SEQ(0x01, seq1); |
| 1119 | |
| 1120 | memctl = RREG32(MGAREG_MEMCTL); |
| 1121 | |
| 1122 | memctl |= RESET_FLAG; |
| 1123 | WREG32(MGAREG_MEMCTL, memctl); |
| 1124 | |
| 1125 | udelay(1000); |
| 1126 | |
| 1127 | memctl &= ~RESET_FLAG; |
| 1128 | WREG32(MGAREG_MEMCTL, memctl); |
| 1129 | |
| 1130 | /* screen on */ |
| 1131 | RREG_SEQ(0x01, seq1); |
| 1132 | seq1 &= ~MGAREG_SEQ1_SCROFF; |
| 1133 | WREG_SEQ(0x01, seq1); |
| 1134 | } |
| 1135 | |
Thomas Zimmermann | 7fc1ae5 | 2020-05-15 10:32:28 +0200 | [diff] [blame^] | 1136 | static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev, |
| 1137 | const struct drm_display_mode *mode, |
| 1138 | const struct drm_framebuffer *fb) |
| 1139 | { |
| 1140 | unsigned int hiprilvl; |
| 1141 | u8 crtcext6; |
| 1142 | |
| 1143 | if (mdev->unique_rev_id >= 0x04) { |
| 1144 | hiprilvl = 0; |
| 1145 | } else if (mdev->unique_rev_id >= 0x02) { |
| 1146 | unsigned int bpp; |
| 1147 | unsigned long mb; |
| 1148 | |
| 1149 | if (fb->format->cpp[0] * 8 > 16) |
| 1150 | bpp = 32; |
| 1151 | else if (fb->format->cpp[0] * 8 > 8) |
| 1152 | bpp = 16; |
| 1153 | else |
| 1154 | bpp = 8; |
| 1155 | |
| 1156 | mb = (mode->clock * bpp) / 1000; |
| 1157 | if (mb > 3100) |
| 1158 | hiprilvl = 0; |
| 1159 | else if (mb > 2600) |
| 1160 | hiprilvl = 1; |
| 1161 | else if (mb > 1900) |
| 1162 | hiprilvl = 2; |
| 1163 | else if (mb > 1160) |
| 1164 | hiprilvl = 3; |
| 1165 | else if (mb > 440) |
| 1166 | hiprilvl = 4; |
| 1167 | else |
| 1168 | hiprilvl = 5; |
| 1169 | |
| 1170 | } else if (mdev->unique_rev_id >= 0x01) { |
| 1171 | hiprilvl = 3; |
| 1172 | } else { |
| 1173 | hiprilvl = 4; |
| 1174 | } |
| 1175 | |
| 1176 | crtcext6 = hiprilvl; /* implicitly sets maxhipri to 0 */ |
| 1177 | |
| 1178 | WREG_ECRT(0x06, crtcext6); |
| 1179 | } |
| 1180 | |
| 1181 | static void mgag200_g200ev_set_hiprilvl(struct mga_device *mdev) |
| 1182 | { |
| 1183 | WREG_ECRT(0x06, 0x00); |
| 1184 | } |
| 1185 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1186 | static int mga_crtc_mode_set(struct drm_crtc *crtc, |
| 1187 | struct drm_display_mode *mode, |
| 1188 | struct drm_display_mode *adjusted_mode, |
| 1189 | int x, int y, struct drm_framebuffer *old_fb) |
| 1190 | { |
| 1191 | struct drm_device *dev = crtc->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 1192 | struct mga_device *mdev = to_mga_device(dev); |
Ville Syrjälä | 7295275 | 2016-11-18 21:52:40 +0200 | [diff] [blame] | 1193 | const struct drm_framebuffer *fb = crtc->primary->fb; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1194 | int option = 0, option2 = 0; |
| 1195 | int i; |
| 1196 | unsigned char misc = 0; |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1197 | u8 crtcext3, crtcext4; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1198 | |
| 1199 | static unsigned char dacvalue[] = { |
| 1200 | /* 0x00: */ 0, 0, 0, 0, 0, 0, 0x00, 0, |
| 1201 | /* 0x08: */ 0, 0, 0, 0, 0, 0, 0, 0, |
| 1202 | /* 0x10: */ 0, 0, 0, 0, 0, 0, 0, 0, |
| 1203 | /* 0x18: */ 0x00, 0, 0xC9, 0xFF, 0xBF, 0x20, 0x1F, 0x20, |
| 1204 | /* 0x20: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1205 | /* 0x28: */ 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0x40, |
| 1206 | /* 0x30: */ 0x00, 0xB0, 0x00, 0xC2, 0x34, 0x14, 0x02, 0x83, |
| 1207 | /* 0x38: */ 0x00, 0x93, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3A, |
| 1208 | /* 0x40: */ 0, 0, 0, 0, 0, 0, 0, 0, |
| 1209 | /* 0x48: */ 0, 0, 0, 0, 0, 0, 0, 0 |
| 1210 | }; |
| 1211 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1212 | switch (mdev->type) { |
| 1213 | case G200_SE_A: |
| 1214 | case G200_SE_B: |
| 1215 | dacvalue[MGA1064_VREF_CTL] = 0x03; |
| 1216 | dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL; |
| 1217 | dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_DAC_EN | |
| 1218 | MGA1064_MISC_CTL_VGA8 | |
| 1219 | MGA1064_MISC_CTL_DAC_RAM_CS; |
| 1220 | if (mdev->has_sdram) |
| 1221 | option = 0x40049120; |
| 1222 | else |
| 1223 | option = 0x4004d120; |
| 1224 | option2 = 0x00008000; |
| 1225 | break; |
| 1226 | case G200_WB: |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 1227 | case G200_EW3: |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1228 | dacvalue[MGA1064_VREF_CTL] = 0x07; |
| 1229 | option = 0x41049120; |
| 1230 | option2 = 0x0000b000; |
| 1231 | break; |
| 1232 | case G200_EV: |
| 1233 | dacvalue[MGA1064_PIX_CLK_CTL] = MGA1064_PIX_CLK_CTL_SEL_PLL; |
| 1234 | dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 | |
| 1235 | MGA1064_MISC_CTL_DAC_RAM_CS; |
| 1236 | option = 0x00000120; |
| 1237 | option2 = 0x0000b000; |
| 1238 | break; |
| 1239 | case G200_EH: |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 1240 | case G200_EH3: |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1241 | dacvalue[MGA1064_MISC_CTL] = MGA1064_MISC_CTL_VGA8 | |
| 1242 | MGA1064_MISC_CTL_DAC_RAM_CS; |
| 1243 | option = 0x00000120; |
| 1244 | option2 = 0x0000b000; |
| 1245 | break; |
| 1246 | case G200_ER: |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1247 | break; |
| 1248 | } |
| 1249 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1250 | for (i = 0; i < sizeof(dacvalue); i++) { |
Christopher Harvey | 9d8aa55 | 2013-04-12 20:42:19 +0000 | [diff] [blame] | 1251 | if ((i <= 0x17) || |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1252 | (i == 0x1b) || |
| 1253 | (i == 0x1c) || |
| 1254 | ((i >= 0x1f) && (i <= 0x29)) || |
| 1255 | ((i >= 0x30) && (i <= 0x37))) |
| 1256 | continue; |
| 1257 | if (IS_G200_SE(mdev) && |
| 1258 | ((i == 0x2c) || (i == 0x2d) || (i == 0x2e))) |
| 1259 | continue; |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 1260 | if ((mdev->type == G200_EV || |
| 1261 | mdev->type == G200_WB || |
| 1262 | mdev->type == G200_EH || |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 1263 | mdev->type == G200_EW3 || |
| 1264 | mdev->type == G200_EH3) && |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1265 | (i >= 0x44) && (i <= 0x4e)) |
| 1266 | continue; |
| 1267 | |
| 1268 | WREG_DAC(i, dacvalue[i]); |
| 1269 | } |
| 1270 | |
Christopher Harvey | 1812a3d | 2013-04-05 10:51:15 -0400 | [diff] [blame] | 1271 | if (mdev->type == G200_ER) |
| 1272 | WREG_DAC(0x90, 0); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1273 | |
| 1274 | if (option) |
| 1275 | pci_write_config_dword(dev->pdev, PCI_MGA_OPTION, option); |
| 1276 | if (option2) |
| 1277 | pci_write_config_dword(dev->pdev, PCI_MGA_OPTION2, option2); |
| 1278 | |
| 1279 | WREG_SEQ(2, 0xf); |
| 1280 | WREG_SEQ(3, 0); |
| 1281 | WREG_SEQ(4, 0xe); |
| 1282 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1283 | WREG_CRT(10, 0); |
| 1284 | WREG_CRT(11, 0); |
| 1285 | WREG_CRT(12, 0); |
| 1286 | WREG_CRT(13, 0); |
| 1287 | WREG_CRT(14, 0); |
| 1288 | WREG_CRT(15, 0); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1289 | |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1290 | RREG_ECRT(0x03, crtcext3); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1291 | |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1292 | crtcext3 |= BIT(7); /* enable MGA mode */ |
| 1293 | crtcext4 = 0x00; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1294 | |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1295 | WREG_ECRT(0x03, crtcext3); |
| 1296 | WREG_ECRT(0x04, crtcext4); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1297 | |
| 1298 | if (mdev->type == G200_ER) |
Christopher Harvey | 1812a3d | 2013-04-05 10:51:15 -0400 | [diff] [blame] | 1299 | WREG_ECRT(0x24, 0x5); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1300 | |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 1301 | if (mdev->type == G200_EW3) |
| 1302 | WREG_ECRT(0x34, 0x5); |
| 1303 | |
Thomas Zimmermann | db05f8d | 2020-05-15 10:32:23 +0200 | [diff] [blame] | 1304 | misc = RREG8(MGA_MISC_IN); |
| 1305 | misc |= MGAREG_MISC_IOADSEL | |
| 1306 | MGAREG_MISC_RAMMAPEN | |
| 1307 | MGAREG_MISC_HIGH_PG_SEL; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1308 | WREG8(MGA_MISC_OUT, misc); |
| 1309 | |
Thomas Zimmermann | 836d536 | 2020-05-15 10:32:26 +0200 | [diff] [blame] | 1310 | mgag200_set_format_regs(mdev, fb); |
Thomas Zimmermann | fb724f1 | 2020-05-15 10:32:21 +0200 | [diff] [blame] | 1311 | mga_crtc_do_set_base(mdev, fb, old_fb); |
Thomas Zimmermann | 72a03a3 | 2020-05-15 10:32:25 +0200 | [diff] [blame] | 1312 | mgag200_set_offset(mdev, fb); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1313 | |
Thomas Zimmermann | ddb8d05 | 2020-05-15 10:32:24 +0200 | [diff] [blame] | 1314 | mgag200_set_mode_regs(mdev, mode); |
| 1315 | |
Thomas Zimmermann | 2e5ccbb | 2020-05-15 10:32:27 +0200 | [diff] [blame] | 1316 | if (mdev->type == G200_ER) |
| 1317 | mgag200_g200er_reset_tagfifo(mdev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1318 | |
Thomas Zimmermann | 7fc1ae5 | 2020-05-15 10:32:28 +0200 | [diff] [blame^] | 1319 | if (IS_G200_SE(mdev)) |
| 1320 | mgag200_g200se_set_hiprilvl(mdev, mode, fb); |
| 1321 | else if (mdev->type == G200_EV) |
| 1322 | mgag200_g200ev_set_hiprilvl(mdev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1323 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | #if 0 /* code from mjg to attempt D3 on crtc dpms off - revisit later */ |
| 1328 | static int mga_suspend(struct drm_crtc *crtc) |
| 1329 | { |
| 1330 | struct mga_crtc *mga_crtc = to_mga_crtc(crtc); |
| 1331 | struct drm_device *dev = crtc->dev; |
| 1332 | struct mga_device *mdev = dev->dev_private; |
| 1333 | struct pci_dev *pdev = dev->pdev; |
| 1334 | int option; |
| 1335 | |
| 1336 | if (mdev->suspended) |
| 1337 | return 0; |
| 1338 | |
| 1339 | WREG_SEQ(1, 0x20); |
| 1340 | WREG_ECRT(1, 0x30); |
| 1341 | /* Disable the pixel clock */ |
| 1342 | WREG_DAC(0x1a, 0x05); |
| 1343 | /* Power down the DAC */ |
| 1344 | WREG_DAC(0x1e, 0x18); |
| 1345 | /* Power down the pixel PLL */ |
| 1346 | WREG_DAC(0x1a, 0x0d); |
| 1347 | |
| 1348 | /* Disable PLLs and clocks */ |
| 1349 | pci_read_config_dword(pdev, PCI_MGA_OPTION, &option); |
| 1350 | option &= ~(0x1F8024); |
| 1351 | pci_write_config_dword(pdev, PCI_MGA_OPTION, option); |
| 1352 | pci_set_power_state(pdev, PCI_D3hot); |
| 1353 | pci_disable_device(pdev); |
| 1354 | |
| 1355 | mdev->suspended = true; |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static int mga_resume(struct drm_crtc *crtc) |
| 1361 | { |
| 1362 | struct mga_crtc *mga_crtc = to_mga_crtc(crtc); |
| 1363 | struct drm_device *dev = crtc->dev; |
| 1364 | struct mga_device *mdev = dev->dev_private; |
| 1365 | struct pci_dev *pdev = dev->pdev; |
| 1366 | int option; |
| 1367 | |
| 1368 | if (!mdev->suspended) |
| 1369 | return 0; |
| 1370 | |
| 1371 | pci_set_power_state(pdev, PCI_D0); |
| 1372 | pci_enable_device(pdev); |
| 1373 | |
| 1374 | /* Disable sysclk */ |
| 1375 | pci_read_config_dword(pdev, PCI_MGA_OPTION, &option); |
| 1376 | option &= ~(0x4); |
| 1377 | pci_write_config_dword(pdev, PCI_MGA_OPTION, option); |
| 1378 | |
| 1379 | mdev->suspended = false; |
| 1380 | |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | #endif |
| 1385 | |
| 1386 | static void mga_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 1387 | { |
| 1388 | struct drm_device *dev = crtc->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 1389 | struct mga_device *mdev = to_mga_device(dev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1390 | u8 seq1 = 0, crtcext1 = 0; |
| 1391 | |
| 1392 | switch (mode) { |
| 1393 | case DRM_MODE_DPMS_ON: |
| 1394 | seq1 = 0; |
| 1395 | crtcext1 = 0; |
| 1396 | mga_crtc_load_lut(crtc); |
| 1397 | break; |
| 1398 | case DRM_MODE_DPMS_STANDBY: |
| 1399 | seq1 = 0x20; |
| 1400 | crtcext1 = 0x10; |
| 1401 | break; |
| 1402 | case DRM_MODE_DPMS_SUSPEND: |
| 1403 | seq1 = 0x20; |
| 1404 | crtcext1 = 0x20; |
| 1405 | break; |
| 1406 | case DRM_MODE_DPMS_OFF: |
| 1407 | seq1 = 0x20; |
| 1408 | crtcext1 = 0x30; |
| 1409 | break; |
| 1410 | } |
| 1411 | |
| 1412 | #if 0 |
| 1413 | if (mode == DRM_MODE_DPMS_OFF) { |
| 1414 | mga_suspend(crtc); |
| 1415 | } |
| 1416 | #endif |
| 1417 | WREG8(MGAREG_SEQ_INDEX, 0x01); |
| 1418 | seq1 |= RREG8(MGAREG_SEQ_DATA) & ~0x20; |
| 1419 | mga_wait_vsync(mdev); |
| 1420 | mga_wait_busy(mdev); |
| 1421 | WREG8(MGAREG_SEQ_DATA, seq1); |
| 1422 | msleep(20); |
| 1423 | WREG8(MGAREG_CRTCEXT_INDEX, 0x01); |
| 1424 | crtcext1 |= RREG8(MGAREG_CRTCEXT_DATA) & ~0x30; |
| 1425 | WREG8(MGAREG_CRTCEXT_DATA, crtcext1); |
| 1426 | |
| 1427 | #if 0 |
| 1428 | if (mode == DRM_MODE_DPMS_ON && mdev->suspended == true) { |
| 1429 | mga_resume(crtc); |
| 1430 | drm_helper_resume_force_mode(dev); |
| 1431 | } |
| 1432 | #endif |
| 1433 | } |
| 1434 | |
| 1435 | /* |
| 1436 | * This is called before a mode is programmed. A typical use might be to |
| 1437 | * enable DPMS during the programming to avoid seeing intermediate stages, |
| 1438 | * but that's not relevant to us |
| 1439 | */ |
| 1440 | static void mga_crtc_prepare(struct drm_crtc *crtc) |
| 1441 | { |
| 1442 | struct drm_device *dev = crtc->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 1443 | struct mga_device *mdev = to_mga_device(dev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1444 | u8 tmp; |
| 1445 | |
| 1446 | /* mga_resume(crtc);*/ |
| 1447 | |
| 1448 | WREG8(MGAREG_CRTC_INDEX, 0x11); |
| 1449 | tmp = RREG8(MGAREG_CRTC_DATA); |
| 1450 | WREG_CRT(0x11, tmp | 0x80); |
| 1451 | |
| 1452 | if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) { |
| 1453 | WREG_SEQ(0, 1); |
| 1454 | msleep(50); |
| 1455 | WREG_SEQ(1, 0x20); |
| 1456 | msleep(20); |
| 1457 | } else { |
| 1458 | WREG8(MGAREG_SEQ_INDEX, 0x1); |
| 1459 | tmp = RREG8(MGAREG_SEQ_DATA); |
| 1460 | |
| 1461 | /* start sync reset */ |
| 1462 | WREG_SEQ(0, 1); |
| 1463 | WREG_SEQ(1, tmp | 0x20); |
| 1464 | } |
| 1465 | |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 1466 | if (mdev->type == G200_WB || mdev->type == G200_EW3) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1467 | mga_g200wb_prepare(crtc); |
| 1468 | |
| 1469 | WREG_CRT(17, 0); |
| 1470 | } |
| 1471 | |
| 1472 | /* |
| 1473 | * This is called after a mode is programmed. It should reverse anything done |
| 1474 | * by the prepare function |
| 1475 | */ |
| 1476 | static void mga_crtc_commit(struct drm_crtc *crtc) |
| 1477 | { |
| 1478 | struct drm_device *dev = crtc->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 1479 | struct mga_device *mdev = to_mga_device(dev); |
Jani Nikula | d584ff8 | 2015-03-11 11:51:00 +0200 | [diff] [blame] | 1480 | const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1481 | u8 tmp; |
| 1482 | |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 1483 | if (mdev->type == G200_WB || mdev->type == G200_EW3) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1484 | mga_g200wb_commit(crtc); |
| 1485 | |
| 1486 | if (mdev->type == G200_SE_A || mdev->type == G200_SE_B) { |
| 1487 | msleep(50); |
| 1488 | WREG_SEQ(1, 0x0); |
| 1489 | msleep(20); |
| 1490 | WREG_SEQ(0, 0x3); |
| 1491 | } else { |
| 1492 | WREG8(MGAREG_SEQ_INDEX, 0x1); |
| 1493 | tmp = RREG8(MGAREG_SEQ_DATA); |
| 1494 | |
| 1495 | tmp &= ~0x20; |
| 1496 | WREG_SEQ(0x1, tmp); |
| 1497 | WREG_SEQ(0, 3); |
| 1498 | } |
| 1499 | crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); |
| 1500 | } |
| 1501 | |
| 1502 | /* |
| 1503 | * The core can pass us a set of gamma values to program. We actually only |
| 1504 | * use this for 8-bit mode so can't perform smooth fades on deeper modes, |
| 1505 | * but it's a requirement that we provide the function |
| 1506 | */ |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 1507 | static int mga_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
Daniel Vetter | 6d124ff | 2017-04-03 10:33:01 +0200 | [diff] [blame] | 1508 | u16 *blue, uint32_t size, |
| 1509 | struct drm_modeset_acquire_ctx *ctx) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1510 | { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1511 | mga_crtc_load_lut(crtc); |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 1512 | |
| 1513 | return 0; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /* Simple cleanup function */ |
| 1517 | static void mga_crtc_destroy(struct drm_crtc *crtc) |
| 1518 | { |
| 1519 | struct mga_crtc *mga_crtc = to_mga_crtc(crtc); |
| 1520 | |
| 1521 | drm_crtc_cleanup(crtc); |
| 1522 | kfree(mga_crtc); |
| 1523 | } |
| 1524 | |
Egbert Eich | 64c2907 | 2013-07-17 15:07:22 +0200 | [diff] [blame] | 1525 | static void mga_crtc_disable(struct drm_crtc *crtc) |
| 1526 | { |
Egbert Eich | 64c2907 | 2013-07-17 15:07:22 +0200 | [diff] [blame] | 1527 | DRM_DEBUG_KMS("\n"); |
| 1528 | mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1529 | if (crtc->primary->fb) { |
Thomas Zimmermann | 5d17718 | 2019-06-27 10:09:09 +0200 | [diff] [blame] | 1530 | struct drm_framebuffer *fb = crtc->primary->fb; |
| 1531 | struct drm_gem_vram_object *gbo = |
| 1532 | drm_gem_vram_of_gem(fb->obj[0]); |
Thomas Zimmermann | 81da87f | 2019-05-21 13:08:29 +0200 | [diff] [blame] | 1533 | drm_gem_vram_unpin(gbo); |
Egbert Eich | 64c2907 | 2013-07-17 15:07:22 +0200 | [diff] [blame] | 1534 | } |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1535 | crtc->primary->fb = NULL; |
Egbert Eich | 64c2907 | 2013-07-17 15:07:22 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1538 | /* These provide the minimum set of functions required to handle a CRTC */ |
| 1539 | static const struct drm_crtc_funcs mga_crtc_funcs = { |
| 1540 | .gamma_set = mga_crtc_gamma_set, |
| 1541 | .set_config = drm_crtc_helper_set_config, |
| 1542 | .destroy = mga_crtc_destroy, |
| 1543 | }; |
| 1544 | |
| 1545 | static const struct drm_crtc_helper_funcs mga_helper_funcs = { |
Egbert Eich | 64c2907 | 2013-07-17 15:07:22 +0200 | [diff] [blame] | 1546 | .disable = mga_crtc_disable, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1547 | .dpms = mga_crtc_dpms, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1548 | .mode_set = mga_crtc_mode_set, |
| 1549 | .mode_set_base = mga_crtc_mode_set_base, |
| 1550 | .prepare = mga_crtc_prepare, |
| 1551 | .commit = mga_crtc_commit, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1552 | }; |
| 1553 | |
| 1554 | /* CRTC setup */ |
Christopher Harvey | f1998fe | 2013-02-20 09:34:22 -0500 | [diff] [blame] | 1555 | static void mga_crtc_init(struct mga_device *mdev) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1556 | { |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1557 | struct drm_device *dev = mdev->dev; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1558 | struct mga_crtc *mga_crtc; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1559 | |
| 1560 | mga_crtc = kzalloc(sizeof(struct mga_crtc) + |
| 1561 | (MGAG200FB_CONN_LIMIT * sizeof(struct drm_connector *)), |
| 1562 | GFP_KERNEL); |
| 1563 | |
| 1564 | if (mga_crtc == NULL) |
| 1565 | return; |
| 1566 | |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1567 | drm_crtc_init(dev, &mga_crtc->base, &mga_crtc_funcs); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1568 | |
| 1569 | drm_mode_crtc_set_gamma_size(&mga_crtc->base, MGAG200_LUT_SIZE); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1570 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1571 | drm_crtc_helper_add(&mga_crtc->base, &mga_helper_funcs); |
| 1572 | } |
| 1573 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1574 | /* |
| 1575 | * Connector |
| 1576 | */ |
| 1577 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1578 | static int mga_vga_get_modes(struct drm_connector *connector) |
| 1579 | { |
| 1580 | struct mga_connector *mga_connector = to_mga_connector(connector); |
| 1581 | struct edid *edid; |
| 1582 | int ret = 0; |
| 1583 | |
| 1584 | edid = drm_get_edid(connector, &mga_connector->i2c->adapter); |
| 1585 | if (edid) { |
Daniel Vetter | c555f02 | 2018-07-09 10:40:06 +0200 | [diff] [blame] | 1586 | drm_connector_update_edid_property(connector, edid); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1587 | ret = drm_add_edid_modes(connector, edid); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1588 | kfree(edid); |
| 1589 | } |
| 1590 | return ret; |
| 1591 | } |
| 1592 | |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1593 | static uint32_t mga_vga_calculate_mode_bandwidth(struct drm_display_mode *mode, |
| 1594 | int bits_per_pixel) |
| 1595 | { |
| 1596 | uint32_t total_area, divisor; |
Nicolas Pitre | c24ca5b | 2015-11-03 23:09:58 -0500 | [diff] [blame] | 1597 | uint64_t active_area, pixels_per_second, bandwidth; |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1598 | uint64_t bytes_per_pixel = (bits_per_pixel + 7) / 8; |
| 1599 | |
| 1600 | divisor = 1024; |
| 1601 | |
| 1602 | if (!mode->htotal || !mode->vtotal || !mode->clock) |
| 1603 | return 0; |
| 1604 | |
| 1605 | active_area = mode->hdisplay * mode->vdisplay; |
| 1606 | total_area = mode->htotal * mode->vtotal; |
| 1607 | |
| 1608 | pixels_per_second = active_area * mode->clock * 1000; |
| 1609 | do_div(pixels_per_second, total_area); |
| 1610 | |
| 1611 | bandwidth = pixels_per_second * bytes_per_pixel * 100; |
| 1612 | do_div(bandwidth, divisor); |
| 1613 | |
| 1614 | return (uint32_t)(bandwidth); |
| 1615 | } |
| 1616 | |
| 1617 | #define MODE_BANDWIDTH MODE_BAD |
| 1618 | |
Luc Van Oostenryck | c69e52d | 2018-04-24 15:15:06 +0200 | [diff] [blame] | 1619 | static enum drm_mode_status mga_vga_mode_valid(struct drm_connector *connector, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1620 | struct drm_display_mode *mode) |
| 1621 | { |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1622 | struct drm_device *dev = connector->dev; |
Thomas Zimmermann | 8d8ff2a | 2020-05-07 11:03:10 +0200 | [diff] [blame] | 1623 | struct mga_device *mdev = to_mga_device(dev); |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1624 | int bpp = 32; |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1625 | |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1626 | if (IS_G200_SE(mdev)) { |
| 1627 | if (mdev->unique_rev_id == 0x01) { |
| 1628 | if (mode->hdisplay > 1600) |
| 1629 | return MODE_VIRTUAL_X; |
| 1630 | if (mode->vdisplay > 1200) |
| 1631 | return MODE_VIRTUAL_Y; |
| 1632 | if (mga_vga_calculate_mode_bandwidth(mode, bpp) |
| 1633 | > (24400 * 1024)) |
| 1634 | return MODE_BANDWIDTH; |
Mathieu Larouche | e829d7e | 2015-08-21 09:24:13 -0400 | [diff] [blame] | 1635 | } else if (mdev->unique_rev_id == 0x02) { |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1636 | if (mode->hdisplay > 1920) |
| 1637 | return MODE_VIRTUAL_X; |
| 1638 | if (mode->vdisplay > 1200) |
| 1639 | return MODE_VIRTUAL_Y; |
| 1640 | if (mga_vga_calculate_mode_bandwidth(mode, bpp) |
| 1641 | > (30100 * 1024)) |
| 1642 | return MODE_BANDWIDTH; |
Mathieu Larouche | 0cbb738 | 2017-06-14 10:39:42 -0400 | [diff] [blame] | 1643 | } else { |
| 1644 | if (mga_vga_calculate_mode_bandwidth(mode, bpp) |
| 1645 | > (55000 * 1024)) |
| 1646 | return MODE_BANDWIDTH; |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1647 | } |
| 1648 | } else if (mdev->type == G200_WB) { |
| 1649 | if (mode->hdisplay > 1280) |
| 1650 | return MODE_VIRTUAL_X; |
| 1651 | if (mode->vdisplay > 1024) |
| 1652 | return MODE_VIRTUAL_Y; |
Dan Carpenter | 9eb8d7a | 2018-01-25 17:26:55 +0300 | [diff] [blame] | 1653 | if (mga_vga_calculate_mode_bandwidth(mode, bpp) > |
| 1654 | (31877 * 1024)) |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1655 | return MODE_BANDWIDTH; |
| 1656 | } else if (mdev->type == G200_EV && |
| 1657 | (mga_vga_calculate_mode_bandwidth(mode, bpp) |
| 1658 | > (32700 * 1024))) { |
| 1659 | return MODE_BANDWIDTH; |
Dave Airlie | ec22b4a | 2014-02-05 14:13:56 +1000 | [diff] [blame] | 1660 | } else if (mdev->type == G200_EH && |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1661 | (mga_vga_calculate_mode_bandwidth(mode, bpp) |
| 1662 | > (37500 * 1024))) { |
| 1663 | return MODE_BANDWIDTH; |
Dave Airlie | ec22b4a | 2014-02-05 14:13:56 +1000 | [diff] [blame] | 1664 | } else if (mdev->type == G200_ER && |
Julia Lemire | abbee62 | 2013-06-27 13:38:59 -0400 | [diff] [blame] | 1665 | (mga_vga_calculate_mode_bandwidth(mode, |
| 1666 | bpp) > (55000 * 1024))) { |
| 1667 | return MODE_BANDWIDTH; |
| 1668 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1669 | |
Adam Jackson | 2516108 | 2015-06-15 16:16:15 -0400 | [diff] [blame] | 1670 | if ((mode->hdisplay % 8) != 0 || (mode->hsync_start % 8) != 0 || |
| 1671 | (mode->hsync_end % 8) != 0 || (mode->htotal % 8) != 0) { |
| 1672 | return MODE_H_ILLEGAL; |
| 1673 | } |
| 1674 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1675 | if (mode->crtc_hdisplay > 2048 || mode->crtc_hsync_start > 4096 || |
| 1676 | mode->crtc_hsync_end > 4096 || mode->crtc_htotal > 4096 || |
| 1677 | mode->crtc_vdisplay > 2048 || mode->crtc_vsync_start > 4096 || |
| 1678 | mode->crtc_vsync_end > 4096 || mode->crtc_vtotal > 4096) { |
| 1679 | return MODE_BAD; |
| 1680 | } |
| 1681 | |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1682 | /* Validate the mode input by the user */ |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1683 | if (connector->cmdline_mode.specified) { |
| 1684 | if (connector->cmdline_mode.bpp_specified) |
| 1685 | bpp = connector->cmdline_mode.bpp; |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1686 | } |
| 1687 | |
Thomas Zimmermann | 2c51a66 | 2019-09-27 11:13:00 +0200 | [diff] [blame] | 1688 | if ((mode->hdisplay * mode->vdisplay * (bpp/8)) > mdev->vram_fb_available) { |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1689 | if (connector->cmdline_mode.specified) |
| 1690 | connector->cmdline_mode.specified = false; |
Christopher Harvey | 0ba5317 | 2013-02-26 10:55:44 -0500 | [diff] [blame] | 1691 | return MODE_BAD; |
| 1692 | } |
| 1693 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1694 | return MODE_OK; |
| 1695 | } |
| 1696 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1697 | static void mga_connector_destroy(struct drm_connector *connector) |
| 1698 | { |
| 1699 | struct mga_connector *mga_connector = to_mga_connector(connector); |
| 1700 | mgag200_i2c_destroy(mga_connector->i2c); |
| 1701 | drm_connector_cleanup(connector); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Ville Syrjälä | 71cb749 | 2015-12-15 12:21:10 +0100 | [diff] [blame] | 1704 | static const struct drm_connector_helper_funcs mga_vga_connector_helper_funcs = { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1705 | .get_modes = mga_vga_get_modes, |
| 1706 | .mode_valid = mga_vga_mode_valid, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1707 | }; |
| 1708 | |
Ville Syrjälä | 71cb749 | 2015-12-15 12:21:10 +0100 | [diff] [blame] | 1709 | static const struct drm_connector_funcs mga_vga_connector_funcs = { |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1710 | .dpms = drm_helper_connector_dpms, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1711 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 1712 | .destroy = mga_connector_destroy, |
| 1713 | }; |
| 1714 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1715 | static int mgag200_vga_connector_init(struct mga_device *mdev) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1716 | { |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1717 | struct drm_device *dev = mdev->dev; |
| 1718 | struct mga_connector *mconnector = &mdev->connector; |
| 1719 | struct drm_connector *connector = &mconnector->base; |
| 1720 | struct mga_i2c_chan *i2c; |
| 1721 | int ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1722 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1723 | i2c = mgag200_i2c_create(dev); |
| 1724 | if (!i2c) |
| 1725 | drm_warn(dev, "failed to add DDC bus\n"); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1726 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1727 | ret = drm_connector_init_with_ddc(dev, connector, |
| 1728 | &mga_vga_connector_funcs, |
| 1729 | DRM_MODE_CONNECTOR_VGA, |
| 1730 | &i2c->adapter); |
| 1731 | if (ret) |
| 1732 | goto err_mgag200_i2c_destroy; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1733 | drm_connector_helper_add(connector, &mga_vga_connector_helper_funcs); |
| 1734 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1735 | mconnector->i2c = i2c; |
Egbert Eich | 3d5a1c5 | 2013-07-17 15:07:25 +0200 | [diff] [blame] | 1736 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1737 | return 0; |
| 1738 | |
| 1739 | err_mgag200_i2c_destroy: |
| 1740 | mgag200_i2c_destroy(i2c); |
| 1741 | return ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1742 | } |
| 1743 | |
Thomas Zimmermann | 5635b7c | 2020-05-07 11:03:13 +0200 | [diff] [blame] | 1744 | static const struct drm_mode_config_funcs mgag200_mode_config_funcs = { |
| 1745 | .fb_create = drm_gem_fb_create |
| 1746 | }; |
| 1747 | |
| 1748 | static unsigned int mgag200_preferred_depth(struct mga_device *mdev) |
| 1749 | { |
| 1750 | if (IS_G200_SE(mdev) && mdev->vram_fb_available < (2048*1024)) |
| 1751 | return 16; |
| 1752 | else |
| 1753 | return 32; |
| 1754 | } |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1755 | |
| 1756 | int mgag200_modeset_init(struct mga_device *mdev) |
| 1757 | { |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1758 | struct drm_device *dev = mdev->dev; |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 1759 | struct drm_encoder *encoder = &mdev->encoder; |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1760 | struct drm_connector *connector = &mdev->connector.base; |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 1761 | int ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1762 | |
Thomas Zimmermann | 5635b7c | 2020-05-07 11:03:13 +0200 | [diff] [blame] | 1763 | mdev->bpp_shifts[0] = 0; |
| 1764 | mdev->bpp_shifts[1] = 1; |
| 1765 | mdev->bpp_shifts[2] = 0; |
| 1766 | mdev->bpp_shifts[3] = 2; |
| 1767 | |
| 1768 | ret = drmm_mode_config_init(dev); |
| 1769 | if (ret) { |
| 1770 | drm_err(dev, "drmm_mode_config_init() failed, error %d\n", |
| 1771 | ret); |
| 1772 | return ret; |
| 1773 | } |
| 1774 | |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1775 | dev->mode_config.max_width = MGAG200_MAX_FB_WIDTH; |
| 1776 | dev->mode_config.max_height = MGAG200_MAX_FB_HEIGHT; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1777 | |
Thomas Zimmermann | 5635b7c | 2020-05-07 11:03:13 +0200 | [diff] [blame] | 1778 | dev->mode_config.preferred_depth = mgag200_preferred_depth(mdev); |
| 1779 | dev->mode_config.prefer_shadow = 1; |
| 1780 | |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1781 | dev->mode_config.fb_base = mdev->mc.vram_base; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1782 | |
Thomas Zimmermann | 5635b7c | 2020-05-07 11:03:13 +0200 | [diff] [blame] | 1783 | dev->mode_config.funcs = &mgag200_mode_config_funcs; |
| 1784 | |
Christopher Harvey | f1998fe | 2013-02-20 09:34:22 -0500 | [diff] [blame] | 1785 | mga_crtc_init(mdev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1786 | |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1787 | ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_DAC); |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 1788 | if (ret) { |
Thomas Zimmermann | ed5877b | 2020-05-07 11:03:11 +0200 | [diff] [blame] | 1789 | drm_err(dev, |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 1790 | "drm_simple_encoder_init() failed, error %d\n", |
| 1791 | ret); |
| 1792 | return ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1793 | } |
Thomas Zimmermann | 03e44ad | 2020-02-28 09:18:27 +0100 | [diff] [blame] | 1794 | encoder->possible_crtcs = 0x1; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1795 | |
Thomas Zimmermann | 81a15b9 | 2020-05-07 11:03:15 +0200 | [diff] [blame] | 1796 | ret = mgag200_vga_connector_init(mdev); |
| 1797 | if (ret) { |
| 1798 | drm_err(dev, |
| 1799 | "mgag200_vga_connector_init() failed, error %d\n", |
| 1800 | ret); |
| 1801 | return ret; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1802 | } |
| 1803 | |
Daniel Vetter | cde4c44 | 2018-07-09 10:40:07 +0200 | [diff] [blame] | 1804 | drm_connector_attach_encoder(connector, encoder); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1805 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 1806 | return 0; |
| 1807 | } |