.. | .. |
---|
27 | 27 | /* |
---|
28 | 28 | * Authors: Dave Airlie <airlied@redhat.com> |
---|
29 | 29 | */ |
---|
| 30 | + |
---|
30 | 31 | #include <linux/export.h> |
---|
31 | | -#include <drm/drmP.h> |
---|
| 32 | +#include <linux/pci.h> |
---|
| 33 | + |
---|
| 34 | +#include <drm/drm_atomic.h> |
---|
| 35 | +#include <drm/drm_atomic_helper.h> |
---|
| 36 | +#include <drm/drm_atomic_state_helper.h> |
---|
32 | 37 | #include <drm/drm_crtc.h> |
---|
33 | 38 | #include <drm/drm_crtc_helper.h> |
---|
| 39 | +#include <drm/drm_fourcc.h> |
---|
| 40 | +#include <drm/drm_gem_framebuffer_helper.h> |
---|
| 41 | +#include <drm/drm_gem_vram_helper.h> |
---|
34 | 42 | #include <drm/drm_plane_helper.h> |
---|
35 | | -#include "ast_drv.h" |
---|
| 43 | +#include <drm/drm_probe_helper.h> |
---|
| 44 | +#include <drm/drm_simple_kms_helper.h> |
---|
36 | 45 | |
---|
| 46 | +#include "ast_drv.h" |
---|
37 | 47 | #include "ast_tables.h" |
---|
38 | 48 | |
---|
39 | 49 | static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev); |
---|
40 | 50 | static void ast_i2c_destroy(struct ast_i2c_chan *i2c); |
---|
41 | | -static int ast_cursor_set(struct drm_crtc *crtc, |
---|
42 | | - struct drm_file *file_priv, |
---|
43 | | - uint32_t handle, |
---|
44 | | - uint32_t width, |
---|
45 | | - uint32_t height); |
---|
46 | | -static int ast_cursor_move(struct drm_crtc *crtc, |
---|
47 | | - int x, int y); |
---|
48 | 51 | |
---|
49 | 52 | static inline void ast_load_palette_index(struct ast_private *ast, |
---|
50 | 53 | u8 index, u8 red, u8 green, |
---|
.. | .. |
---|
60 | 63 | ast_io_read8(ast, AST_IO_SEQ_PORT); |
---|
61 | 64 | } |
---|
62 | 65 | |
---|
63 | | -static void ast_crtc_load_lut(struct drm_crtc *crtc) |
---|
| 66 | +static void ast_crtc_load_lut(struct ast_private *ast, struct drm_crtc *crtc) |
---|
64 | 67 | { |
---|
65 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
66 | 68 | u16 *r, *g, *b; |
---|
67 | 69 | int i; |
---|
68 | 70 | |
---|
.. | .. |
---|
77 | 79 | ast_load_palette_index(ast, i, *r++ >> 8, *g++ >> 8, *b++ >> 8); |
---|
78 | 80 | } |
---|
79 | 81 | |
---|
80 | | -static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, struct drm_display_mode *mode, |
---|
| 82 | +static bool ast_get_vbios_mode_info(const struct drm_format_info *format, |
---|
| 83 | + const struct drm_display_mode *mode, |
---|
81 | 84 | struct drm_display_mode *adjusted_mode, |
---|
82 | 85 | struct ast_vbios_mode_info *vbios_mode) |
---|
83 | 86 | { |
---|
84 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
85 | | - const struct drm_framebuffer *fb = crtc->primary->fb; |
---|
86 | | - u32 refresh_rate_index = 0, mode_id, color_index, refresh_rate; |
---|
| 87 | + u32 refresh_rate_index = 0, refresh_rate; |
---|
87 | 88 | const struct ast_vbios_enhtable *best = NULL; |
---|
88 | 89 | u32 hborder, vborder; |
---|
89 | 90 | bool check_sync; |
---|
90 | 91 | |
---|
91 | | - switch (fb->format->cpp[0] * 8) { |
---|
| 92 | + switch (format->cpp[0] * 8) { |
---|
92 | 93 | case 8: |
---|
93 | 94 | vbios_mode->std_table = &vbios_stdtable[VGAModeIndex]; |
---|
94 | | - color_index = VGAModeIndex - 1; |
---|
95 | 95 | break; |
---|
96 | 96 | case 16: |
---|
97 | 97 | vbios_mode->std_table = &vbios_stdtable[HiCModeIndex]; |
---|
98 | | - color_index = HiCModeIndex; |
---|
99 | 98 | break; |
---|
100 | 99 | case 24: |
---|
101 | 100 | case 32: |
---|
102 | 101 | vbios_mode->std_table = &vbios_stdtable[TrueCModeIndex]; |
---|
103 | | - color_index = TrueCModeIndex; |
---|
104 | 102 | break; |
---|
105 | 103 | default: |
---|
106 | 104 | return false; |
---|
107 | 105 | } |
---|
108 | 106 | |
---|
109 | | - switch (crtc->mode.crtc_hdisplay) { |
---|
| 107 | + switch (mode->crtc_hdisplay) { |
---|
110 | 108 | case 640: |
---|
111 | 109 | vbios_mode->enh_table = &res_640x480[refresh_rate_index]; |
---|
112 | 110 | break; |
---|
.. | .. |
---|
117 | 115 | vbios_mode->enh_table = &res_1024x768[refresh_rate_index]; |
---|
118 | 116 | break; |
---|
119 | 117 | case 1280: |
---|
120 | | - if (crtc->mode.crtc_vdisplay == 800) |
---|
| 118 | + if (mode->crtc_vdisplay == 800) |
---|
121 | 119 | vbios_mode->enh_table = &res_1280x800[refresh_rate_index]; |
---|
122 | 120 | else |
---|
123 | 121 | vbios_mode->enh_table = &res_1280x1024[refresh_rate_index]; |
---|
.. | .. |
---|
129 | 127 | vbios_mode->enh_table = &res_1440x900[refresh_rate_index]; |
---|
130 | 128 | break; |
---|
131 | 129 | case 1600: |
---|
132 | | - if (crtc->mode.crtc_vdisplay == 900) |
---|
| 130 | + if (mode->crtc_vdisplay == 900) |
---|
133 | 131 | vbios_mode->enh_table = &res_1600x900[refresh_rate_index]; |
---|
134 | 132 | else |
---|
135 | 133 | vbios_mode->enh_table = &res_1600x1200[refresh_rate_index]; |
---|
.. | .. |
---|
138 | 136 | vbios_mode->enh_table = &res_1680x1050[refresh_rate_index]; |
---|
139 | 137 | break; |
---|
140 | 138 | case 1920: |
---|
141 | | - if (crtc->mode.crtc_vdisplay == 1080) |
---|
| 139 | + if (mode->crtc_vdisplay == 1080) |
---|
142 | 140 | vbios_mode->enh_table = &res_1920x1080[refresh_rate_index]; |
---|
143 | 141 | else |
---|
144 | 142 | vbios_mode->enh_table = &res_1920x1200[refresh_rate_index]; |
---|
.. | .. |
---|
149 | 147 | |
---|
150 | 148 | refresh_rate = drm_mode_vrefresh(mode); |
---|
151 | 149 | check_sync = vbios_mode->enh_table->flags & WideScreenMode; |
---|
152 | | - do { |
---|
| 150 | + |
---|
| 151 | + while (1) { |
---|
153 | 152 | const struct ast_vbios_enhtable *loop = vbios_mode->enh_table; |
---|
154 | 153 | |
---|
155 | 154 | while (loop->refresh_rate != 0xff) { |
---|
.. | .. |
---|
173 | 172 | if (best || !check_sync) |
---|
174 | 173 | break; |
---|
175 | 174 | check_sync = 0; |
---|
176 | | - } while (1); |
---|
| 175 | + } |
---|
| 176 | + |
---|
177 | 177 | if (best) |
---|
178 | 178 | vbios_mode->enh_table = best; |
---|
179 | 179 | |
---|
.. | .. |
---|
198 | 198 | vbios_mode->enh_table->vfp + |
---|
199 | 199 | vbios_mode->enh_table->vsync); |
---|
200 | 200 | |
---|
| 201 | + return true; |
---|
| 202 | +} |
---|
| 203 | + |
---|
| 204 | +static void ast_set_vbios_color_reg(struct ast_private *ast, |
---|
| 205 | + const struct drm_format_info *format, |
---|
| 206 | + const struct ast_vbios_mode_info *vbios_mode) |
---|
| 207 | +{ |
---|
| 208 | + u32 color_index; |
---|
| 209 | + |
---|
| 210 | + switch (format->cpp[0]) { |
---|
| 211 | + case 1: |
---|
| 212 | + color_index = VGAModeIndex - 1; |
---|
| 213 | + break; |
---|
| 214 | + case 2: |
---|
| 215 | + color_index = HiCModeIndex; |
---|
| 216 | + break; |
---|
| 217 | + case 3: |
---|
| 218 | + case 4: |
---|
| 219 | + color_index = TrueCModeIndex; |
---|
| 220 | + break; |
---|
| 221 | + default: |
---|
| 222 | + return; |
---|
| 223 | + } |
---|
| 224 | + |
---|
| 225 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8c, (u8)((color_index & 0x0f) << 4)); |
---|
| 226 | + |
---|
| 227 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0x00); |
---|
| 228 | + |
---|
| 229 | + if (vbios_mode->enh_table->flags & NewModeInfo) { |
---|
| 230 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8); |
---|
| 231 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, format->cpp[0] * 8); |
---|
| 232 | + } |
---|
| 233 | +} |
---|
| 234 | + |
---|
| 235 | +static void ast_set_vbios_mode_reg(struct ast_private *ast, |
---|
| 236 | + const struct drm_display_mode *adjusted_mode, |
---|
| 237 | + const struct ast_vbios_mode_info *vbios_mode) |
---|
| 238 | +{ |
---|
| 239 | + u32 refresh_rate_index, mode_id; |
---|
| 240 | + |
---|
201 | 241 | refresh_rate_index = vbios_mode->enh_table->refresh_rate_index; |
---|
202 | 242 | mode_id = vbios_mode->enh_table->mode_id; |
---|
203 | 243 | |
---|
204 | | - if (ast->chip == AST1180) { |
---|
205 | | - /* TODO 1180 */ |
---|
206 | | - } else { |
---|
207 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8c, (u8)((color_index & 0xf) << 4)); |
---|
208 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8d, refresh_rate_index & 0xff); |
---|
209 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8e, mode_id & 0xff); |
---|
| 244 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8d, refresh_rate_index & 0xff); |
---|
| 245 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8e, mode_id & 0xff); |
---|
210 | 246 | |
---|
211 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0x00); |
---|
212 | | - if (vbios_mode->enh_table->flags & NewModeInfo) { |
---|
213 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8); |
---|
214 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, |
---|
215 | | - fb->format->cpp[0] * 8); |
---|
216 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x93, adjusted_mode->clock / 1000); |
---|
217 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x94, adjusted_mode->crtc_hdisplay); |
---|
218 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x95, adjusted_mode->crtc_hdisplay >> 8); |
---|
| 247 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0x00); |
---|
219 | 248 | |
---|
220 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x96, adjusted_mode->crtc_vdisplay); |
---|
221 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x97, adjusted_mode->crtc_vdisplay >> 8); |
---|
222 | | - } |
---|
| 249 | + if (vbios_mode->enh_table->flags & NewModeInfo) { |
---|
| 250 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8); |
---|
| 251 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x93, adjusted_mode->clock / 1000); |
---|
| 252 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x94, adjusted_mode->crtc_hdisplay); |
---|
| 253 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x95, adjusted_mode->crtc_hdisplay >> 8); |
---|
| 254 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x96, adjusted_mode->crtc_vdisplay); |
---|
| 255 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x97, adjusted_mode->crtc_vdisplay >> 8); |
---|
223 | 256 | } |
---|
224 | | - |
---|
225 | | - return true; |
---|
226 | | - |
---|
227 | | - |
---|
228 | 257 | } |
---|
229 | | -static void ast_set_std_reg(struct drm_crtc *crtc, struct drm_display_mode *mode, |
---|
| 258 | + |
---|
| 259 | +static void ast_set_std_reg(struct ast_private *ast, |
---|
| 260 | + struct drm_display_mode *mode, |
---|
230 | 261 | struct ast_vbios_mode_info *vbios_mode) |
---|
231 | 262 | { |
---|
232 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
233 | 263 | const struct ast_vbios_stdtable *stdtable; |
---|
234 | 264 | u32 i; |
---|
235 | 265 | u8 jreg; |
---|
.. | .. |
---|
239 | 269 | jreg = stdtable->misc; |
---|
240 | 270 | ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, jreg); |
---|
241 | 271 | |
---|
242 | | - /* Set SEQ */ |
---|
| 272 | + /* Set SEQ; except Screen Disable field */ |
---|
243 | 273 | ast_set_index_reg(ast, AST_IO_SEQ_PORT, 0x00, 0x03); |
---|
244 | | - for (i = 0; i < 4; i++) { |
---|
| 274 | + ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x01, 0xdf, stdtable->seq[0]); |
---|
| 275 | + for (i = 1; i < 4; i++) { |
---|
245 | 276 | jreg = stdtable->seq[i]; |
---|
246 | | - if (!i) |
---|
247 | | - jreg |= 0x20; |
---|
248 | 277 | ast_set_index_reg(ast, AST_IO_SEQ_PORT, (i + 1) , jreg); |
---|
249 | 278 | } |
---|
250 | 279 | |
---|
251 | | - /* Set CRTC */ |
---|
| 280 | + /* Set CRTC; except base address and offset */ |
---|
252 | 281 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x7f, 0x00); |
---|
253 | | - for (i = 0; i < 25; i++) |
---|
| 282 | + for (i = 0; i < 12; i++) |
---|
| 283 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, stdtable->crtc[i]); |
---|
| 284 | + for (i = 14; i < 19; i++) |
---|
| 285 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, stdtable->crtc[i]); |
---|
| 286 | + for (i = 20; i < 25; i++) |
---|
254 | 287 | ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, stdtable->crtc[i]); |
---|
255 | 288 | |
---|
256 | 289 | /* set AR */ |
---|
.. | .. |
---|
271 | 304 | ast_set_index_reg(ast, AST_IO_GR_PORT, i, stdtable->gr[i]); |
---|
272 | 305 | } |
---|
273 | 306 | |
---|
274 | | -static void ast_set_crtc_reg(struct drm_crtc *crtc, struct drm_display_mode *mode, |
---|
| 307 | +static void ast_set_crtc_reg(struct ast_private *ast, |
---|
| 308 | + struct drm_display_mode *mode, |
---|
275 | 309 | struct ast_vbios_mode_info *vbios_mode) |
---|
276 | 310 | { |
---|
277 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
278 | 311 | u8 jreg05 = 0, jreg07 = 0, jreg09 = 0, jregAC = 0, jregAD = 0, jregAE = 0; |
---|
279 | 312 | u16 temp, precache = 0; |
---|
280 | 313 | |
---|
.. | .. |
---|
380 | 413 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x7f, 0x80); |
---|
381 | 414 | } |
---|
382 | 415 | |
---|
383 | | -static void ast_set_offset_reg(struct drm_crtc *crtc) |
---|
| 416 | +static void ast_set_offset_reg(struct ast_private *ast, |
---|
| 417 | + struct drm_framebuffer *fb) |
---|
384 | 418 | { |
---|
385 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
386 | | - const struct drm_framebuffer *fb = crtc->primary->fb; |
---|
387 | | - |
---|
388 | 419 | u16 offset; |
---|
389 | 420 | |
---|
390 | 421 | offset = fb->pitches[0] >> 3; |
---|
.. | .. |
---|
392 | 423 | ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xb0, (offset >> 8) & 0x3f); |
---|
393 | 424 | } |
---|
394 | 425 | |
---|
395 | | -static void ast_set_dclk_reg(struct drm_device *dev, struct drm_display_mode *mode, |
---|
| 426 | +static void ast_set_dclk_reg(struct ast_private *ast, |
---|
| 427 | + struct drm_display_mode *mode, |
---|
396 | 428 | struct ast_vbios_mode_info *vbios_mode) |
---|
397 | 429 | { |
---|
398 | | - struct ast_private *ast = dev->dev_private; |
---|
399 | 430 | const struct ast_vbios_dclk_info *clk_info; |
---|
400 | 431 | |
---|
401 | 432 | if (ast->chip == AST2500) |
---|
.. | .. |
---|
410 | 441 | ((clk_info->param3 & 0x3) << 4)); |
---|
411 | 442 | } |
---|
412 | 443 | |
---|
413 | | -static void ast_set_ext_reg(struct drm_crtc *crtc, struct drm_display_mode *mode, |
---|
414 | | - struct ast_vbios_mode_info *vbios_mode) |
---|
| 444 | +static void ast_set_color_reg(struct ast_private *ast, |
---|
| 445 | + const struct drm_format_info *format) |
---|
415 | 446 | { |
---|
416 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
417 | | - const struct drm_framebuffer *fb = crtc->primary->fb; |
---|
418 | 447 | u8 jregA0 = 0, jregA3 = 0, jregA8 = 0; |
---|
419 | 448 | |
---|
420 | | - switch (fb->format->cpp[0] * 8) { |
---|
| 449 | + switch (format->cpp[0] * 8) { |
---|
421 | 450 | case 8: |
---|
422 | 451 | jregA0 = 0x70; |
---|
423 | 452 | jregA3 = 0x01; |
---|
.. | .. |
---|
439 | 468 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa0, 0x8f, jregA0); |
---|
440 | 469 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xf0, jregA3); |
---|
441 | 470 | ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa8, 0xfd, jregA8); |
---|
| 471 | +} |
---|
442 | 472 | |
---|
| 473 | +static void ast_set_crtthd_reg(struct ast_private *ast) |
---|
| 474 | +{ |
---|
443 | 475 | /* Set Threshold */ |
---|
444 | 476 | if (ast->chip == AST2300 || ast->chip == AST2400 || |
---|
445 | 477 | ast->chip == AST2500) { |
---|
.. | .. |
---|
457 | 489 | } |
---|
458 | 490 | } |
---|
459 | 491 | |
---|
460 | | -static void ast_set_sync_reg(struct drm_device *dev, struct drm_display_mode *mode, |
---|
461 | | - struct ast_vbios_mode_info *vbios_mode) |
---|
| 492 | +static void ast_set_sync_reg(struct ast_private *ast, |
---|
| 493 | + struct drm_display_mode *mode, |
---|
| 494 | + struct ast_vbios_mode_info *vbios_mode) |
---|
462 | 495 | { |
---|
463 | | - struct ast_private *ast = dev->dev_private; |
---|
464 | 496 | u8 jreg; |
---|
465 | 497 | |
---|
466 | 498 | jreg = ast_io_read8(ast, AST_IO_MISC_PORT_READ); |
---|
.. | .. |
---|
470 | 502 | ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, jreg); |
---|
471 | 503 | } |
---|
472 | 504 | |
---|
473 | | -static bool ast_set_dac_reg(struct drm_crtc *crtc, struct drm_display_mode *mode, |
---|
474 | | - struct ast_vbios_mode_info *vbios_mode) |
---|
| 505 | +static void ast_set_start_address_crt1(struct ast_private *ast, |
---|
| 506 | + unsigned offset) |
---|
475 | 507 | { |
---|
476 | | - const struct drm_framebuffer *fb = crtc->primary->fb; |
---|
477 | | - |
---|
478 | | - switch (fb->format->cpp[0] * 8) { |
---|
479 | | - case 8: |
---|
480 | | - break; |
---|
481 | | - default: |
---|
482 | | - return false; |
---|
483 | | - } |
---|
484 | | - return true; |
---|
485 | | -} |
---|
486 | | - |
---|
487 | | -static void ast_set_start_address_crt1(struct drm_crtc *crtc, unsigned offset) |
---|
488 | | -{ |
---|
489 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
490 | 508 | u32 addr; |
---|
491 | 509 | |
---|
492 | 510 | addr = offset >> 2; |
---|
.. | .. |
---|
496 | 514 | |
---|
497 | 515 | } |
---|
498 | 516 | |
---|
| 517 | +static void ast_wait_for_vretrace(struct ast_private *ast) |
---|
| 518 | +{ |
---|
| 519 | + unsigned long timeout = jiffies + HZ; |
---|
| 520 | + u8 vgair1; |
---|
| 521 | + |
---|
| 522 | + do { |
---|
| 523 | + vgair1 = ast_io_read8(ast, AST_IO_INPUT_STATUS1_READ); |
---|
| 524 | + } while (!(vgair1 & AST_IO_VGAIR1_VREFRESH) && time_before(jiffies, timeout)); |
---|
| 525 | +} |
---|
| 526 | + |
---|
| 527 | +/* |
---|
| 528 | + * Primary plane |
---|
| 529 | + */ |
---|
| 530 | + |
---|
| 531 | +static const uint32_t ast_primary_plane_formats[] = { |
---|
| 532 | + DRM_FORMAT_XRGB8888, |
---|
| 533 | + DRM_FORMAT_RGB565, |
---|
| 534 | + DRM_FORMAT_C8, |
---|
| 535 | +}; |
---|
| 536 | + |
---|
| 537 | +static int ast_primary_plane_helper_atomic_check(struct drm_plane *plane, |
---|
| 538 | + struct drm_plane_state *state) |
---|
| 539 | +{ |
---|
| 540 | + struct drm_crtc_state *crtc_state; |
---|
| 541 | + struct ast_crtc_state *ast_crtc_state; |
---|
| 542 | + int ret; |
---|
| 543 | + |
---|
| 544 | + if (!state->crtc) |
---|
| 545 | + return 0; |
---|
| 546 | + |
---|
| 547 | + crtc_state = drm_atomic_get_new_crtc_state(state->state, state->crtc); |
---|
| 548 | + |
---|
| 549 | + ret = drm_atomic_helper_check_plane_state(state, crtc_state, |
---|
| 550 | + DRM_PLANE_HELPER_NO_SCALING, |
---|
| 551 | + DRM_PLANE_HELPER_NO_SCALING, |
---|
| 552 | + false, true); |
---|
| 553 | + if (ret) |
---|
| 554 | + return ret; |
---|
| 555 | + |
---|
| 556 | + if (!state->visible) |
---|
| 557 | + return 0; |
---|
| 558 | + |
---|
| 559 | + ast_crtc_state = to_ast_crtc_state(crtc_state); |
---|
| 560 | + |
---|
| 561 | + ast_crtc_state->format = state->fb->format; |
---|
| 562 | + |
---|
| 563 | + return 0; |
---|
| 564 | +} |
---|
| 565 | + |
---|
| 566 | +static void |
---|
| 567 | +ast_primary_plane_helper_atomic_update(struct drm_plane *plane, |
---|
| 568 | + struct drm_plane_state *old_state) |
---|
| 569 | +{ |
---|
| 570 | + struct drm_device *dev = plane->dev; |
---|
| 571 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 572 | + struct drm_plane_state *state = plane->state; |
---|
| 573 | + struct drm_gem_vram_object *gbo; |
---|
| 574 | + s64 gpu_addr; |
---|
| 575 | + struct drm_framebuffer *fb = state->fb; |
---|
| 576 | + struct drm_framebuffer *old_fb = old_state->fb; |
---|
| 577 | + |
---|
| 578 | + if (!old_fb || (fb->format != old_fb->format)) { |
---|
| 579 | + struct drm_crtc_state *crtc_state = state->crtc->state; |
---|
| 580 | + struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state); |
---|
| 581 | + struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info; |
---|
| 582 | + |
---|
| 583 | + ast_set_color_reg(ast, fb->format); |
---|
| 584 | + ast_set_vbios_color_reg(ast, fb->format, vbios_mode_info); |
---|
| 585 | + } |
---|
| 586 | + |
---|
| 587 | + gbo = drm_gem_vram_of_gem(fb->obj[0]); |
---|
| 588 | + gpu_addr = drm_gem_vram_offset(gbo); |
---|
| 589 | + if (drm_WARN_ON_ONCE(dev, gpu_addr < 0)) |
---|
| 590 | + return; /* Bug: we didn't pin the BO to VRAM in prepare_fb. */ |
---|
| 591 | + |
---|
| 592 | + ast_set_offset_reg(ast, fb); |
---|
| 593 | + ast_set_start_address_crt1(ast, (u32)gpu_addr); |
---|
| 594 | + |
---|
| 595 | + ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0x00); |
---|
| 596 | +} |
---|
| 597 | + |
---|
| 598 | +static void |
---|
| 599 | +ast_primary_plane_helper_atomic_disable(struct drm_plane *plane, |
---|
| 600 | + struct drm_plane_state *old_state) |
---|
| 601 | +{ |
---|
| 602 | + struct ast_private *ast = to_ast_private(plane->dev); |
---|
| 603 | + |
---|
| 604 | + ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0x20); |
---|
| 605 | +} |
---|
| 606 | + |
---|
| 607 | +static const struct drm_plane_helper_funcs ast_primary_plane_helper_funcs = { |
---|
| 608 | + .prepare_fb = drm_gem_vram_plane_helper_prepare_fb, |
---|
| 609 | + .cleanup_fb = drm_gem_vram_plane_helper_cleanup_fb, |
---|
| 610 | + .atomic_check = ast_primary_plane_helper_atomic_check, |
---|
| 611 | + .atomic_update = ast_primary_plane_helper_atomic_update, |
---|
| 612 | + .atomic_disable = ast_primary_plane_helper_atomic_disable, |
---|
| 613 | +}; |
---|
| 614 | + |
---|
| 615 | +static const struct drm_plane_funcs ast_primary_plane_funcs = { |
---|
| 616 | + .update_plane = drm_atomic_helper_update_plane, |
---|
| 617 | + .disable_plane = drm_atomic_helper_disable_plane, |
---|
| 618 | + .destroy = drm_plane_cleanup, |
---|
| 619 | + .reset = drm_atomic_helper_plane_reset, |
---|
| 620 | + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
---|
| 621 | + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
---|
| 622 | +}; |
---|
| 623 | + |
---|
| 624 | +/* |
---|
| 625 | + * Cursor plane |
---|
| 626 | + */ |
---|
| 627 | + |
---|
| 628 | +static const uint32_t ast_cursor_plane_formats[] = { |
---|
| 629 | + DRM_FORMAT_ARGB8888, |
---|
| 630 | +}; |
---|
| 631 | + |
---|
| 632 | +static int |
---|
| 633 | +ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane, |
---|
| 634 | + struct drm_plane_state *new_state) |
---|
| 635 | +{ |
---|
| 636 | + struct drm_framebuffer *fb = new_state->fb; |
---|
| 637 | + struct drm_crtc *crtc = new_state->crtc; |
---|
| 638 | + struct ast_private *ast; |
---|
| 639 | + int ret; |
---|
| 640 | + |
---|
| 641 | + if (!crtc || !fb) |
---|
| 642 | + return 0; |
---|
| 643 | + |
---|
| 644 | + ast = to_ast_private(plane->dev); |
---|
| 645 | + |
---|
| 646 | + ret = ast_cursor_blit(ast, fb); |
---|
| 647 | + if (ret) |
---|
| 648 | + return ret; |
---|
| 649 | + |
---|
| 650 | + return 0; |
---|
| 651 | +} |
---|
| 652 | + |
---|
| 653 | +static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane, |
---|
| 654 | + struct drm_plane_state *state) |
---|
| 655 | +{ |
---|
| 656 | + struct drm_framebuffer *fb = state->fb; |
---|
| 657 | + struct drm_crtc_state *crtc_state; |
---|
| 658 | + int ret; |
---|
| 659 | + |
---|
| 660 | + if (!state->crtc) |
---|
| 661 | + return 0; |
---|
| 662 | + |
---|
| 663 | + crtc_state = drm_atomic_get_new_crtc_state(state->state, state->crtc); |
---|
| 664 | + |
---|
| 665 | + ret = drm_atomic_helper_check_plane_state(state, crtc_state, |
---|
| 666 | + DRM_PLANE_HELPER_NO_SCALING, |
---|
| 667 | + DRM_PLANE_HELPER_NO_SCALING, |
---|
| 668 | + true, true); |
---|
| 669 | + if (ret) |
---|
| 670 | + return ret; |
---|
| 671 | + |
---|
| 672 | + if (!state->visible) |
---|
| 673 | + return 0; |
---|
| 674 | + |
---|
| 675 | + if (fb->width > AST_MAX_HWC_WIDTH || fb->height > AST_MAX_HWC_HEIGHT) |
---|
| 676 | + return -EINVAL; |
---|
| 677 | + |
---|
| 678 | + return 0; |
---|
| 679 | +} |
---|
| 680 | + |
---|
| 681 | +static void |
---|
| 682 | +ast_cursor_plane_helper_atomic_update(struct drm_plane *plane, |
---|
| 683 | + struct drm_plane_state *old_state) |
---|
| 684 | +{ |
---|
| 685 | + struct drm_plane_state *state = plane->state; |
---|
| 686 | + struct drm_framebuffer *fb = state->fb; |
---|
| 687 | + struct ast_private *ast = to_ast_private(plane->dev); |
---|
| 688 | + unsigned int offset_x, offset_y; |
---|
| 689 | + |
---|
| 690 | + offset_x = AST_MAX_HWC_WIDTH - fb->width; |
---|
| 691 | + offset_y = AST_MAX_HWC_HEIGHT - fb->height; |
---|
| 692 | + |
---|
| 693 | + if (state->fb != old_state->fb) { |
---|
| 694 | + /* A new cursor image was installed. */ |
---|
| 695 | + ast_cursor_page_flip(ast); |
---|
| 696 | + } |
---|
| 697 | + |
---|
| 698 | + ast_cursor_show(ast, state->crtc_x, state->crtc_y, |
---|
| 699 | + offset_x, offset_y); |
---|
| 700 | +} |
---|
| 701 | + |
---|
| 702 | +static void |
---|
| 703 | +ast_cursor_plane_helper_atomic_disable(struct drm_plane *plane, |
---|
| 704 | + struct drm_plane_state *old_state) |
---|
| 705 | +{ |
---|
| 706 | + struct ast_private *ast = to_ast_private(plane->dev); |
---|
| 707 | + |
---|
| 708 | + ast_cursor_hide(ast); |
---|
| 709 | +} |
---|
| 710 | + |
---|
| 711 | +static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = { |
---|
| 712 | + .prepare_fb = ast_cursor_plane_helper_prepare_fb, |
---|
| 713 | + .cleanup_fb = NULL, /* not required for cursor plane */ |
---|
| 714 | + .atomic_check = ast_cursor_plane_helper_atomic_check, |
---|
| 715 | + .atomic_update = ast_cursor_plane_helper_atomic_update, |
---|
| 716 | + .atomic_disable = ast_cursor_plane_helper_atomic_disable, |
---|
| 717 | +}; |
---|
| 718 | + |
---|
| 719 | +static const struct drm_plane_funcs ast_cursor_plane_funcs = { |
---|
| 720 | + .update_plane = drm_atomic_helper_update_plane, |
---|
| 721 | + .disable_plane = drm_atomic_helper_disable_plane, |
---|
| 722 | + .destroy = drm_plane_cleanup, |
---|
| 723 | + .reset = drm_atomic_helper_plane_reset, |
---|
| 724 | + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
---|
| 725 | + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
---|
| 726 | +}; |
---|
| 727 | + |
---|
| 728 | +/* |
---|
| 729 | + * CRTC |
---|
| 730 | + */ |
---|
| 731 | + |
---|
499 | 732 | static void ast_crtc_dpms(struct drm_crtc *crtc, int mode) |
---|
500 | 733 | { |
---|
501 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
| 734 | + struct ast_private *ast = to_ast_private(crtc->dev); |
---|
502 | 735 | |
---|
503 | | - if (ast->chip == AST1180) |
---|
504 | | - return; |
---|
505 | | - |
---|
| 736 | + /* TODO: Maybe control display signal generation with |
---|
| 737 | + * Sync Enable (bit CR17.7). |
---|
| 738 | + */ |
---|
506 | 739 | switch (mode) { |
---|
507 | 740 | case DRM_MODE_DPMS_ON: |
---|
508 | 741 | case DRM_MODE_DPMS_STANDBY: |
---|
509 | 742 | case DRM_MODE_DPMS_SUSPEND: |
---|
510 | | - ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0); |
---|
511 | 743 | if (ast->tx_chip_type == AST_TX_DP501) |
---|
512 | 744 | ast_set_dp501_video_output(crtc->dev, 1); |
---|
513 | | - ast_crtc_load_lut(crtc); |
---|
514 | 745 | break; |
---|
515 | 746 | case DRM_MODE_DPMS_OFF: |
---|
516 | 747 | if (ast->tx_chip_type == AST_TX_DP501) |
---|
517 | 748 | ast_set_dp501_video_output(crtc->dev, 0); |
---|
518 | | - ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0x20); |
---|
519 | 749 | break; |
---|
520 | 750 | } |
---|
521 | 751 | } |
---|
522 | 752 | |
---|
523 | | -/* ast is different - we will force move buffers out of VRAM */ |
---|
524 | | -static int ast_crtc_do_set_base(struct drm_crtc *crtc, |
---|
525 | | - struct drm_framebuffer *fb, |
---|
526 | | - int x, int y, int atomic) |
---|
527 | | -{ |
---|
528 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
529 | | - struct drm_gem_object *obj; |
---|
530 | | - struct ast_framebuffer *ast_fb; |
---|
531 | | - struct ast_bo *bo; |
---|
532 | | - int ret; |
---|
533 | | - u64 gpu_addr; |
---|
534 | | - |
---|
535 | | - /* push the previous fb to system ram */ |
---|
536 | | - if (!atomic && fb) { |
---|
537 | | - ast_fb = to_ast_framebuffer(fb); |
---|
538 | | - obj = ast_fb->obj; |
---|
539 | | - bo = gem_to_ast_bo(obj); |
---|
540 | | - ret = ast_bo_reserve(bo, false); |
---|
541 | | - if (ret) |
---|
542 | | - return ret; |
---|
543 | | - ast_bo_push_sysram(bo); |
---|
544 | | - ast_bo_unreserve(bo); |
---|
545 | | - } |
---|
546 | | - |
---|
547 | | - ast_fb = to_ast_framebuffer(crtc->primary->fb); |
---|
548 | | - obj = ast_fb->obj; |
---|
549 | | - bo = gem_to_ast_bo(obj); |
---|
550 | | - |
---|
551 | | - ret = ast_bo_reserve(bo, false); |
---|
552 | | - if (ret) |
---|
553 | | - return ret; |
---|
554 | | - |
---|
555 | | - ret = ast_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); |
---|
556 | | - if (ret) { |
---|
557 | | - ast_bo_unreserve(bo); |
---|
558 | | - return ret; |
---|
559 | | - } |
---|
560 | | - |
---|
561 | | - if (&ast->fbdev->afb == ast_fb) { |
---|
562 | | - /* if pushing console in kmap it */ |
---|
563 | | - ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); |
---|
564 | | - if (ret) |
---|
565 | | - DRM_ERROR("failed to kmap fbcon\n"); |
---|
566 | | - else |
---|
567 | | - ast_fbdev_set_base(ast, gpu_addr); |
---|
568 | | - } |
---|
569 | | - ast_bo_unreserve(bo); |
---|
570 | | - |
---|
571 | | - ast_set_offset_reg(crtc); |
---|
572 | | - ast_set_start_address_crt1(crtc, (u32)gpu_addr); |
---|
573 | | - |
---|
574 | | - return 0; |
---|
575 | | -} |
---|
576 | | - |
---|
577 | | -static int ast_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
---|
578 | | - struct drm_framebuffer *old_fb) |
---|
579 | | -{ |
---|
580 | | - return ast_crtc_do_set_base(crtc, old_fb, x, y, 0); |
---|
581 | | -} |
---|
582 | | - |
---|
583 | | -static int ast_crtc_mode_set(struct drm_crtc *crtc, |
---|
584 | | - struct drm_display_mode *mode, |
---|
585 | | - struct drm_display_mode *adjusted_mode, |
---|
586 | | - int x, int y, |
---|
587 | | - struct drm_framebuffer *old_fb) |
---|
| 753 | +static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, |
---|
| 754 | + struct drm_crtc_state *state) |
---|
588 | 755 | { |
---|
589 | 756 | struct drm_device *dev = crtc->dev; |
---|
590 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
591 | | - struct ast_vbios_mode_info vbios_mode; |
---|
592 | | - bool ret; |
---|
593 | | - if (ast->chip == AST1180) { |
---|
594 | | - DRM_ERROR("AST 1180 modesetting not supported\n"); |
---|
| 757 | + struct ast_crtc_state *ast_state; |
---|
| 758 | + const struct drm_format_info *format; |
---|
| 759 | + bool succ; |
---|
| 760 | + |
---|
| 761 | + if (!state->enable) |
---|
| 762 | + return 0; /* no mode checks if CRTC is being disabled */ |
---|
| 763 | + |
---|
| 764 | + ast_state = to_ast_crtc_state(state); |
---|
| 765 | + |
---|
| 766 | + format = ast_state->format; |
---|
| 767 | + if (drm_WARN_ON_ONCE(dev, !format)) |
---|
| 768 | + return -EINVAL; /* BUG: We didn't set format in primary check(). */ |
---|
| 769 | + |
---|
| 770 | + succ = ast_get_vbios_mode_info(format, &state->mode, |
---|
| 771 | + &state->adjusted_mode, |
---|
| 772 | + &ast_state->vbios_mode_info); |
---|
| 773 | + if (!succ) |
---|
595 | 774 | return -EINVAL; |
---|
596 | | - } |
---|
597 | | - |
---|
598 | | - ret = ast_get_vbios_mode_info(crtc, mode, adjusted_mode, &vbios_mode); |
---|
599 | | - if (ret == false) |
---|
600 | | - return -EINVAL; |
---|
601 | | - ast_open_key(ast); |
---|
602 | | - |
---|
603 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x06); |
---|
604 | | - |
---|
605 | | - ast_set_std_reg(crtc, adjusted_mode, &vbios_mode); |
---|
606 | | - ast_set_crtc_reg(crtc, adjusted_mode, &vbios_mode); |
---|
607 | | - ast_set_offset_reg(crtc); |
---|
608 | | - ast_set_dclk_reg(dev, adjusted_mode, &vbios_mode); |
---|
609 | | - ast_set_ext_reg(crtc, adjusted_mode, &vbios_mode); |
---|
610 | | - ast_set_sync_reg(dev, adjusted_mode, &vbios_mode); |
---|
611 | | - ast_set_dac_reg(crtc, adjusted_mode, &vbios_mode); |
---|
612 | | - |
---|
613 | | - ast_crtc_mode_set_base(crtc, x, y, old_fb); |
---|
614 | 775 | |
---|
615 | 776 | return 0; |
---|
616 | 777 | } |
---|
617 | 778 | |
---|
618 | | -static void ast_crtc_disable(struct drm_crtc *crtc) |
---|
| 779 | +static void |
---|
| 780 | +ast_crtc_helper_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) |
---|
619 | 781 | { |
---|
620 | | - int ret; |
---|
| 782 | + struct ast_private *ast = to_ast_private(crtc->dev); |
---|
| 783 | + struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc->state); |
---|
| 784 | + struct ast_crtc_state *old_ast_crtc_state = to_ast_crtc_state(old_crtc_state); |
---|
621 | 785 | |
---|
622 | | - DRM_DEBUG_KMS("\n"); |
---|
| 786 | + /* |
---|
| 787 | + * The gamma LUT has to be reloaded after changing the primary |
---|
| 788 | + * plane's color format. |
---|
| 789 | + */ |
---|
| 790 | + if (old_ast_crtc_state->format != ast_crtc_state->format) |
---|
| 791 | + ast_crtc_load_lut(ast, crtc); |
---|
| 792 | +} |
---|
| 793 | + |
---|
| 794 | +static void |
---|
| 795 | +ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, |
---|
| 796 | + struct drm_crtc_state *old_crtc_state) |
---|
| 797 | +{ |
---|
| 798 | + struct drm_device *dev = crtc->dev; |
---|
| 799 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 800 | + struct drm_crtc_state *crtc_state = crtc->state; |
---|
| 801 | + struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state); |
---|
| 802 | + struct ast_vbios_mode_info *vbios_mode_info = |
---|
| 803 | + &ast_crtc_state->vbios_mode_info; |
---|
| 804 | + struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; |
---|
| 805 | + |
---|
| 806 | + ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info); |
---|
| 807 | + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x06); |
---|
| 808 | + ast_set_std_reg(ast, adjusted_mode, vbios_mode_info); |
---|
| 809 | + ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info); |
---|
| 810 | + ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info); |
---|
| 811 | + ast_set_crtthd_reg(ast); |
---|
| 812 | + ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info); |
---|
| 813 | + |
---|
| 814 | + ast_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
---|
| 815 | +} |
---|
| 816 | + |
---|
| 817 | +static void |
---|
| 818 | +ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, |
---|
| 819 | + struct drm_crtc_state *old_crtc_state) |
---|
| 820 | +{ |
---|
| 821 | + struct drm_device *dev = crtc->dev; |
---|
| 822 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 823 | + |
---|
623 | 824 | ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
---|
624 | | - if (crtc->primary->fb) { |
---|
625 | | - struct ast_framebuffer *ast_fb = to_ast_framebuffer(crtc->primary->fb); |
---|
626 | | - struct drm_gem_object *obj = ast_fb->obj; |
---|
627 | | - struct ast_bo *bo = gem_to_ast_bo(obj); |
---|
628 | 825 | |
---|
629 | | - ret = ast_bo_reserve(bo, false); |
---|
630 | | - if (ret) |
---|
631 | | - return; |
---|
| 826 | + /* |
---|
| 827 | + * HW cursors require the underlying primary plane and CRTC to |
---|
| 828 | + * display a valid mode and image. This is not the case during |
---|
| 829 | + * full modeset operations. So we temporarily disable any active |
---|
| 830 | + * plane, including the HW cursor. Each plane's atomic_update() |
---|
| 831 | + * helper will re-enable it if necessary. |
---|
| 832 | + * |
---|
| 833 | + * We only do this during *full* modesets. It does not affect |
---|
| 834 | + * simple pageflips on the planes. |
---|
| 835 | + */ |
---|
| 836 | + drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false); |
---|
632 | 837 | |
---|
633 | | - ast_bo_push_sysram(bo); |
---|
634 | | - ast_bo_unreserve(bo); |
---|
635 | | - } |
---|
636 | | - crtc->primary->fb = NULL; |
---|
| 838 | + /* |
---|
| 839 | + * Ensure that no scanout takes place before reprogramming mode |
---|
| 840 | + * and format registers. |
---|
| 841 | + */ |
---|
| 842 | + ast_wait_for_vretrace(ast); |
---|
637 | 843 | } |
---|
638 | | - |
---|
639 | | -static void ast_crtc_prepare(struct drm_crtc *crtc) |
---|
640 | | -{ |
---|
641 | | - |
---|
642 | | -} |
---|
643 | | - |
---|
644 | | -static void ast_crtc_commit(struct drm_crtc *crtc) |
---|
645 | | -{ |
---|
646 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
647 | | - ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0); |
---|
648 | | - ast_crtc_load_lut(crtc); |
---|
649 | | -} |
---|
650 | | - |
---|
651 | 844 | |
---|
652 | 845 | static const struct drm_crtc_helper_funcs ast_crtc_helper_funcs = { |
---|
653 | | - .dpms = ast_crtc_dpms, |
---|
654 | | - .mode_set = ast_crtc_mode_set, |
---|
655 | | - .mode_set_base = ast_crtc_mode_set_base, |
---|
656 | | - .disable = ast_crtc_disable, |
---|
657 | | - .prepare = ast_crtc_prepare, |
---|
658 | | - .commit = ast_crtc_commit, |
---|
659 | | - |
---|
| 846 | + .atomic_check = ast_crtc_helper_atomic_check, |
---|
| 847 | + .atomic_flush = ast_crtc_helper_atomic_flush, |
---|
| 848 | + .atomic_enable = ast_crtc_helper_atomic_enable, |
---|
| 849 | + .atomic_disable = ast_crtc_helper_atomic_disable, |
---|
660 | 850 | }; |
---|
661 | 851 | |
---|
662 | 852 | static void ast_crtc_reset(struct drm_crtc *crtc) |
---|
663 | 853 | { |
---|
| 854 | + struct ast_crtc_state *ast_state = |
---|
| 855 | + kzalloc(sizeof(*ast_state), GFP_KERNEL); |
---|
664 | 856 | |
---|
| 857 | + if (crtc->state) |
---|
| 858 | + crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
---|
| 859 | + |
---|
| 860 | + if (ast_state) |
---|
| 861 | + __drm_atomic_helper_crtc_reset(crtc, &ast_state->base); |
---|
| 862 | + else |
---|
| 863 | + __drm_atomic_helper_crtc_reset(crtc, NULL); |
---|
665 | 864 | } |
---|
666 | 865 | |
---|
667 | | -static int ast_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
---|
668 | | - u16 *blue, uint32_t size, |
---|
669 | | - struct drm_modeset_acquire_ctx *ctx) |
---|
| 866 | +static struct drm_crtc_state * |
---|
| 867 | +ast_crtc_atomic_duplicate_state(struct drm_crtc *crtc) |
---|
670 | 868 | { |
---|
671 | | - ast_crtc_load_lut(crtc); |
---|
| 869 | + struct ast_crtc_state *new_ast_state, *ast_state; |
---|
| 870 | + struct drm_device *dev = crtc->dev; |
---|
672 | 871 | |
---|
673 | | - return 0; |
---|
| 872 | + if (drm_WARN_ON(dev, !crtc->state)) |
---|
| 873 | + return NULL; |
---|
| 874 | + |
---|
| 875 | + new_ast_state = kmalloc(sizeof(*new_ast_state), GFP_KERNEL); |
---|
| 876 | + if (!new_ast_state) |
---|
| 877 | + return NULL; |
---|
| 878 | + __drm_atomic_helper_crtc_duplicate_state(crtc, &new_ast_state->base); |
---|
| 879 | + |
---|
| 880 | + ast_state = to_ast_crtc_state(crtc->state); |
---|
| 881 | + |
---|
| 882 | + new_ast_state->format = ast_state->format; |
---|
| 883 | + memcpy(&new_ast_state->vbios_mode_info, &ast_state->vbios_mode_info, |
---|
| 884 | + sizeof(new_ast_state->vbios_mode_info)); |
---|
| 885 | + |
---|
| 886 | + return &new_ast_state->base; |
---|
674 | 887 | } |
---|
675 | 888 | |
---|
676 | | - |
---|
677 | | -static void ast_crtc_destroy(struct drm_crtc *crtc) |
---|
| 889 | +static void ast_crtc_atomic_destroy_state(struct drm_crtc *crtc, |
---|
| 890 | + struct drm_crtc_state *state) |
---|
678 | 891 | { |
---|
679 | | - drm_crtc_cleanup(crtc); |
---|
680 | | - kfree(crtc); |
---|
| 892 | + struct ast_crtc_state *ast_state = to_ast_crtc_state(state); |
---|
| 893 | + |
---|
| 894 | + __drm_atomic_helper_crtc_destroy_state(&ast_state->base); |
---|
| 895 | + kfree(ast_state); |
---|
681 | 896 | } |
---|
682 | 897 | |
---|
683 | 898 | static const struct drm_crtc_funcs ast_crtc_funcs = { |
---|
684 | | - .cursor_set = ast_cursor_set, |
---|
685 | | - .cursor_move = ast_cursor_move, |
---|
686 | 899 | .reset = ast_crtc_reset, |
---|
687 | | - .set_config = drm_crtc_helper_set_config, |
---|
688 | | - .gamma_set = ast_crtc_gamma_set, |
---|
689 | | - .destroy = ast_crtc_destroy, |
---|
| 900 | + .gamma_set = drm_atomic_helper_legacy_gamma_set, |
---|
| 901 | + .destroy = drm_crtc_cleanup, |
---|
| 902 | + .set_config = drm_atomic_helper_set_config, |
---|
| 903 | + .page_flip = drm_atomic_helper_page_flip, |
---|
| 904 | + .atomic_duplicate_state = ast_crtc_atomic_duplicate_state, |
---|
| 905 | + .atomic_destroy_state = ast_crtc_atomic_destroy_state, |
---|
690 | 906 | }; |
---|
691 | 907 | |
---|
692 | 908 | static int ast_crtc_init(struct drm_device *dev) |
---|
693 | 909 | { |
---|
694 | | - struct ast_crtc *crtc; |
---|
| 910 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 911 | + struct drm_crtc *crtc = &ast->crtc; |
---|
| 912 | + int ret; |
---|
695 | 913 | |
---|
696 | | - crtc = kzalloc(sizeof(struct ast_crtc), GFP_KERNEL); |
---|
697 | | - if (!crtc) |
---|
698 | | - return -ENOMEM; |
---|
| 914 | + ret = drm_crtc_init_with_planes(dev, crtc, &ast->primary_plane, |
---|
| 915 | + &ast->cursor_plane, &ast_crtc_funcs, |
---|
| 916 | + NULL); |
---|
| 917 | + if (ret) |
---|
| 918 | + return ret; |
---|
699 | 919 | |
---|
700 | | - drm_crtc_init(dev, &crtc->base, &ast_crtc_funcs); |
---|
701 | | - drm_mode_crtc_set_gamma_size(&crtc->base, 256); |
---|
702 | | - drm_crtc_helper_add(&crtc->base, &ast_crtc_helper_funcs); |
---|
| 920 | + drm_mode_crtc_set_gamma_size(crtc, 256); |
---|
| 921 | + drm_crtc_helper_add(crtc, &ast_crtc_helper_funcs); |
---|
| 922 | + |
---|
703 | 923 | return 0; |
---|
704 | 924 | } |
---|
705 | 925 | |
---|
706 | | -static void ast_encoder_destroy(struct drm_encoder *encoder) |
---|
707 | | -{ |
---|
708 | | - drm_encoder_cleanup(encoder); |
---|
709 | | - kfree(encoder); |
---|
710 | | -} |
---|
711 | | - |
---|
712 | | - |
---|
713 | | -static struct drm_encoder *ast_best_single_encoder(struct drm_connector *connector) |
---|
714 | | -{ |
---|
715 | | - int enc_id = connector->encoder_ids[0]; |
---|
716 | | - /* pick the encoder ids */ |
---|
717 | | - if (enc_id) |
---|
718 | | - return drm_encoder_find(connector->dev, NULL, enc_id); |
---|
719 | | - return NULL; |
---|
720 | | -} |
---|
721 | | - |
---|
722 | | - |
---|
723 | | -static const struct drm_encoder_funcs ast_enc_funcs = { |
---|
724 | | - .destroy = ast_encoder_destroy, |
---|
725 | | -}; |
---|
726 | | - |
---|
727 | | -static void ast_encoder_dpms(struct drm_encoder *encoder, int mode) |
---|
728 | | -{ |
---|
729 | | - |
---|
730 | | -} |
---|
731 | | - |
---|
732 | | -static void ast_encoder_mode_set(struct drm_encoder *encoder, |
---|
733 | | - struct drm_display_mode *mode, |
---|
734 | | - struct drm_display_mode *adjusted_mode) |
---|
735 | | -{ |
---|
736 | | -} |
---|
737 | | - |
---|
738 | | -static void ast_encoder_prepare(struct drm_encoder *encoder) |
---|
739 | | -{ |
---|
740 | | - |
---|
741 | | -} |
---|
742 | | - |
---|
743 | | -static void ast_encoder_commit(struct drm_encoder *encoder) |
---|
744 | | -{ |
---|
745 | | - |
---|
746 | | -} |
---|
747 | | - |
---|
748 | | - |
---|
749 | | -static const struct drm_encoder_helper_funcs ast_enc_helper_funcs = { |
---|
750 | | - .dpms = ast_encoder_dpms, |
---|
751 | | - .prepare = ast_encoder_prepare, |
---|
752 | | - .commit = ast_encoder_commit, |
---|
753 | | - .mode_set = ast_encoder_mode_set, |
---|
754 | | -}; |
---|
| 926 | +/* |
---|
| 927 | + * Encoder |
---|
| 928 | + */ |
---|
755 | 929 | |
---|
756 | 930 | static int ast_encoder_init(struct drm_device *dev) |
---|
757 | 931 | { |
---|
758 | | - struct ast_encoder *ast_encoder; |
---|
| 932 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 933 | + struct drm_encoder *encoder = &ast->encoder; |
---|
| 934 | + int ret; |
---|
759 | 935 | |
---|
760 | | - ast_encoder = kzalloc(sizeof(struct ast_encoder), GFP_KERNEL); |
---|
761 | | - if (!ast_encoder) |
---|
762 | | - return -ENOMEM; |
---|
| 936 | + ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_DAC); |
---|
| 937 | + if (ret) |
---|
| 938 | + return ret; |
---|
763 | 939 | |
---|
764 | | - drm_encoder_init(dev, &ast_encoder->base, &ast_enc_funcs, |
---|
765 | | - DRM_MODE_ENCODER_DAC, NULL); |
---|
766 | | - drm_encoder_helper_add(&ast_encoder->base, &ast_enc_helper_funcs); |
---|
| 940 | + encoder->possible_crtcs = 1; |
---|
767 | 941 | |
---|
768 | | - ast_encoder->base.possible_crtcs = 1; |
---|
769 | 942 | return 0; |
---|
770 | 943 | } |
---|
| 944 | + |
---|
| 945 | +/* |
---|
| 946 | + * Connector |
---|
| 947 | + */ |
---|
771 | 948 | |
---|
772 | 949 | static int ast_get_modes(struct drm_connector *connector) |
---|
773 | 950 | { |
---|
774 | 951 | struct ast_connector *ast_connector = to_ast_connector(connector); |
---|
775 | | - struct ast_private *ast = connector->dev->dev_private; |
---|
| 952 | + struct ast_private *ast = to_ast_private(connector->dev); |
---|
776 | 953 | struct edid *edid; |
---|
777 | 954 | int ret; |
---|
778 | 955 | bool flags = false; |
---|
.. | .. |
---|
803 | 980 | static enum drm_mode_status ast_mode_valid(struct drm_connector *connector, |
---|
804 | 981 | struct drm_display_mode *mode) |
---|
805 | 982 | { |
---|
806 | | - struct ast_private *ast = connector->dev->dev_private; |
---|
| 983 | + struct ast_private *ast = to_ast_private(connector->dev); |
---|
807 | 984 | int flags = MODE_NOMODE; |
---|
808 | 985 | uint32_t jtemp; |
---|
809 | 986 | |
---|
.. | .. |
---|
821 | 998 | |
---|
822 | 999 | if ((ast->chip == AST2100) || (ast->chip == AST2200) || |
---|
823 | 1000 | (ast->chip == AST2300) || (ast->chip == AST2400) || |
---|
824 | | - (ast->chip == AST2500) || (ast->chip == AST1180)) { |
---|
| 1001 | + (ast->chip == AST2500)) { |
---|
825 | 1002 | if ((mode->hdisplay == 1920) && (mode->vdisplay == 1080)) |
---|
826 | 1003 | return MODE_OK; |
---|
827 | 1004 | |
---|
.. | .. |
---|
861 | 1038 | { |
---|
862 | 1039 | struct ast_connector *ast_connector = to_ast_connector(connector); |
---|
863 | 1040 | ast_i2c_destroy(ast_connector->i2c); |
---|
864 | | - drm_connector_unregister(connector); |
---|
865 | 1041 | drm_connector_cleanup(connector); |
---|
866 | | - kfree(connector); |
---|
867 | 1042 | } |
---|
868 | 1043 | |
---|
869 | 1044 | static const struct drm_connector_helper_funcs ast_connector_helper_funcs = { |
---|
870 | | - .mode_valid = ast_mode_valid, |
---|
871 | 1045 | .get_modes = ast_get_modes, |
---|
872 | | - .best_encoder = ast_best_single_encoder, |
---|
| 1046 | + .mode_valid = ast_mode_valid, |
---|
873 | 1047 | }; |
---|
874 | 1048 | |
---|
875 | 1049 | static const struct drm_connector_funcs ast_connector_funcs = { |
---|
876 | | - .dpms = drm_helper_connector_dpms, |
---|
| 1050 | + .reset = drm_atomic_helper_connector_reset, |
---|
877 | 1051 | .fill_modes = drm_helper_probe_single_connector_modes, |
---|
878 | 1052 | .destroy = ast_connector_destroy, |
---|
| 1053 | + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
---|
| 1054 | + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
---|
879 | 1055 | }; |
---|
880 | 1056 | |
---|
881 | 1057 | static int ast_connector_init(struct drm_device *dev) |
---|
882 | 1058 | { |
---|
883 | | - struct ast_connector *ast_connector; |
---|
884 | | - struct drm_connector *connector; |
---|
885 | | - struct drm_encoder *encoder; |
---|
| 1059 | + struct ast_private *ast = to_ast_private(dev); |
---|
| 1060 | + struct ast_connector *ast_connector = &ast->connector; |
---|
| 1061 | + struct drm_connector *connector = &ast_connector->base; |
---|
| 1062 | + struct drm_encoder *encoder = &ast->encoder; |
---|
886 | 1063 | |
---|
887 | | - ast_connector = kzalloc(sizeof(struct ast_connector), GFP_KERNEL); |
---|
888 | | - if (!ast_connector) |
---|
889 | | - return -ENOMEM; |
---|
| 1064 | + ast_connector->i2c = ast_i2c_create(dev); |
---|
| 1065 | + if (!ast_connector->i2c) |
---|
| 1066 | + drm_err(dev, "failed to add ddc bus for connector\n"); |
---|
890 | 1067 | |
---|
891 | | - connector = &ast_connector->base; |
---|
892 | | - drm_connector_init(dev, connector, &ast_connector_funcs, DRM_MODE_CONNECTOR_VGA); |
---|
| 1068 | + drm_connector_init_with_ddc(dev, connector, |
---|
| 1069 | + &ast_connector_funcs, |
---|
| 1070 | + DRM_MODE_CONNECTOR_VGA, |
---|
| 1071 | + &ast_connector->i2c->adapter); |
---|
893 | 1072 | |
---|
894 | 1073 | drm_connector_helper_add(connector, &ast_connector_helper_funcs); |
---|
895 | 1074 | |
---|
896 | 1075 | connector->interlace_allowed = 0; |
---|
897 | 1076 | connector->doublescan_allowed = 0; |
---|
898 | 1077 | |
---|
899 | | - drm_connector_register(connector); |
---|
900 | | - |
---|
901 | 1078 | connector->polled = DRM_CONNECTOR_POLL_CONNECT; |
---|
902 | 1079 | |
---|
903 | | - encoder = list_first_entry(&dev->mode_config.encoder_list, struct drm_encoder, head); |
---|
904 | 1080 | drm_connector_attach_encoder(connector, encoder); |
---|
905 | 1081 | |
---|
906 | | - ast_connector->i2c = ast_i2c_create(dev); |
---|
907 | | - if (!ast_connector->i2c) |
---|
908 | | - DRM_ERROR("failed to add ddc bus for connector\n"); |
---|
909 | | - |
---|
910 | 1082 | return 0; |
---|
911 | 1083 | } |
---|
912 | 1084 | |
---|
913 | | -/* allocate cursor cache and pin at start of VRAM */ |
---|
914 | | -static int ast_cursor_init(struct drm_device *dev) |
---|
| 1085 | +/* |
---|
| 1086 | + * Mode config |
---|
| 1087 | + */ |
---|
| 1088 | + |
---|
| 1089 | +static const struct drm_mode_config_helper_funcs |
---|
| 1090 | +ast_mode_config_helper_funcs = { |
---|
| 1091 | + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, |
---|
| 1092 | +}; |
---|
| 1093 | + |
---|
| 1094 | +static const struct drm_mode_config_funcs ast_mode_config_funcs = { |
---|
| 1095 | + .fb_create = drm_gem_fb_create, |
---|
| 1096 | + .mode_valid = drm_vram_helper_mode_valid, |
---|
| 1097 | + .atomic_check = drm_atomic_helper_check, |
---|
| 1098 | + .atomic_commit = drm_atomic_helper_commit, |
---|
| 1099 | +}; |
---|
| 1100 | + |
---|
| 1101 | +int ast_mode_config_init(struct ast_private *ast) |
---|
915 | 1102 | { |
---|
916 | | - struct ast_private *ast = dev->dev_private; |
---|
917 | | - int size; |
---|
| 1103 | + struct drm_device *dev = &ast->base; |
---|
918 | 1104 | int ret; |
---|
919 | | - struct drm_gem_object *obj; |
---|
920 | | - struct ast_bo *bo; |
---|
921 | | - uint64_t gpu_addr; |
---|
922 | 1105 | |
---|
923 | | - size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM; |
---|
924 | | - |
---|
925 | | - ret = ast_gem_create(dev, size, true, &obj); |
---|
| 1106 | + ret = ast_cursor_init(ast); |
---|
926 | 1107 | if (ret) |
---|
927 | 1108 | return ret; |
---|
928 | | - bo = gem_to_ast_bo(obj); |
---|
929 | | - ret = ast_bo_reserve(bo, false); |
---|
930 | | - if (unlikely(ret != 0)) |
---|
931 | | - goto fail; |
---|
932 | 1109 | |
---|
933 | | - ret = ast_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); |
---|
934 | | - ast_bo_unreserve(bo); |
---|
| 1110 | + ret = drmm_mode_config_init(dev); |
---|
935 | 1111 | if (ret) |
---|
936 | | - goto fail; |
---|
| 1112 | + return ret; |
---|
937 | 1113 | |
---|
938 | | - /* kmap the object */ |
---|
939 | | - ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &ast->cache_kmap); |
---|
940 | | - if (ret) |
---|
941 | | - goto fail; |
---|
| 1114 | + dev->mode_config.funcs = &ast_mode_config_funcs; |
---|
| 1115 | + dev->mode_config.min_width = 0; |
---|
| 1116 | + dev->mode_config.min_height = 0; |
---|
| 1117 | + dev->mode_config.preferred_depth = 24; |
---|
| 1118 | + dev->mode_config.prefer_shadow = 1; |
---|
| 1119 | + dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0); |
---|
942 | 1120 | |
---|
943 | | - ast->cursor_cache = obj; |
---|
944 | | - ast->cursor_cache_gpu_addr = gpu_addr; |
---|
945 | | - DRM_DEBUG_KMS("pinned cursor cache at %llx\n", ast->cursor_cache_gpu_addr); |
---|
946 | | - return 0; |
---|
947 | | -fail: |
---|
948 | | - return ret; |
---|
949 | | -} |
---|
| 1121 | + if (ast->chip == AST2100 || |
---|
| 1122 | + ast->chip == AST2200 || |
---|
| 1123 | + ast->chip == AST2300 || |
---|
| 1124 | + ast->chip == AST2400 || |
---|
| 1125 | + ast->chip == AST2500) { |
---|
| 1126 | + dev->mode_config.max_width = 1920; |
---|
| 1127 | + dev->mode_config.max_height = 2048; |
---|
| 1128 | + } else { |
---|
| 1129 | + dev->mode_config.max_width = 1600; |
---|
| 1130 | + dev->mode_config.max_height = 1200; |
---|
| 1131 | + } |
---|
950 | 1132 | |
---|
951 | | -static void ast_cursor_fini(struct drm_device *dev) |
---|
952 | | -{ |
---|
953 | | - struct ast_private *ast = dev->dev_private; |
---|
954 | | - ttm_bo_kunmap(&ast->cache_kmap); |
---|
955 | | - drm_gem_object_put_unlocked(ast->cursor_cache); |
---|
956 | | -} |
---|
| 1133 | + dev->mode_config.helper_private = &ast_mode_config_helper_funcs; |
---|
957 | 1134 | |
---|
958 | | -int ast_mode_init(struct drm_device *dev) |
---|
959 | | -{ |
---|
960 | | - ast_cursor_init(dev); |
---|
| 1135 | + memset(&ast->primary_plane, 0, sizeof(ast->primary_plane)); |
---|
| 1136 | + ret = drm_universal_plane_init(dev, &ast->primary_plane, 0x01, |
---|
| 1137 | + &ast_primary_plane_funcs, |
---|
| 1138 | + ast_primary_plane_formats, |
---|
| 1139 | + ARRAY_SIZE(ast_primary_plane_formats), |
---|
| 1140 | + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); |
---|
| 1141 | + if (ret) { |
---|
| 1142 | + drm_err(dev, "ast: drm_universal_plane_init() failed: %d\n", ret); |
---|
| 1143 | + return ret; |
---|
| 1144 | + } |
---|
| 1145 | + drm_plane_helper_add(&ast->primary_plane, |
---|
| 1146 | + &ast_primary_plane_helper_funcs); |
---|
| 1147 | + |
---|
| 1148 | + ret = drm_universal_plane_init(dev, &ast->cursor_plane, 0x01, |
---|
| 1149 | + &ast_cursor_plane_funcs, |
---|
| 1150 | + ast_cursor_plane_formats, |
---|
| 1151 | + ARRAY_SIZE(ast_cursor_plane_formats), |
---|
| 1152 | + NULL, DRM_PLANE_TYPE_CURSOR, NULL); |
---|
| 1153 | + if (ret) { |
---|
| 1154 | + drm_err(dev, "drm_universal_plane_failed(): %d\n", ret); |
---|
| 1155 | + return ret; |
---|
| 1156 | + } |
---|
| 1157 | + drm_plane_helper_add(&ast->cursor_plane, |
---|
| 1158 | + &ast_cursor_plane_helper_funcs); |
---|
| 1159 | + |
---|
961 | 1160 | ast_crtc_init(dev); |
---|
962 | 1161 | ast_encoder_init(dev); |
---|
963 | 1162 | ast_connector_init(dev); |
---|
964 | | - return 0; |
---|
965 | | -} |
---|
966 | 1163 | |
---|
967 | | -void ast_mode_fini(struct drm_device *dev) |
---|
968 | | -{ |
---|
969 | | - ast_cursor_fini(dev); |
---|
| 1164 | + drm_mode_config_reset(dev); |
---|
| 1165 | + |
---|
| 1166 | + return 0; |
---|
970 | 1167 | } |
---|
971 | 1168 | |
---|
972 | 1169 | static int get_clock(void *i2c_priv) |
---|
973 | 1170 | { |
---|
974 | 1171 | struct ast_i2c_chan *i2c = i2c_priv; |
---|
975 | | - struct ast_private *ast = i2c->dev->dev_private; |
---|
| 1172 | + struct ast_private *ast = to_ast_private(i2c->dev); |
---|
976 | 1173 | uint32_t val, val2, count, pass; |
---|
977 | 1174 | |
---|
978 | 1175 | count = 0; |
---|
.. | .. |
---|
994 | 1191 | static int get_data(void *i2c_priv) |
---|
995 | 1192 | { |
---|
996 | 1193 | struct ast_i2c_chan *i2c = i2c_priv; |
---|
997 | | - struct ast_private *ast = i2c->dev->dev_private; |
---|
| 1194 | + struct ast_private *ast = to_ast_private(i2c->dev); |
---|
998 | 1195 | uint32_t val, val2, count, pass; |
---|
999 | 1196 | |
---|
1000 | 1197 | count = 0; |
---|
.. | .. |
---|
1016 | 1213 | static void set_clock(void *i2c_priv, int clock) |
---|
1017 | 1214 | { |
---|
1018 | 1215 | struct ast_i2c_chan *i2c = i2c_priv; |
---|
1019 | | - struct ast_private *ast = i2c->dev->dev_private; |
---|
| 1216 | + struct ast_private *ast = to_ast_private(i2c->dev); |
---|
1020 | 1217 | int i; |
---|
1021 | 1218 | u8 ujcrb7, jtemp; |
---|
1022 | 1219 | |
---|
.. | .. |
---|
1032 | 1229 | static void set_data(void *i2c_priv, int data) |
---|
1033 | 1230 | { |
---|
1034 | 1231 | struct ast_i2c_chan *i2c = i2c_priv; |
---|
1035 | | - struct ast_private *ast = i2c->dev->dev_private; |
---|
| 1232 | + struct ast_private *ast = to_ast_private(i2c->dev); |
---|
1036 | 1233 | int i; |
---|
1037 | 1234 | u8 ujcrb7, jtemp; |
---|
1038 | 1235 | |
---|
.. | .. |
---|
1072 | 1269 | i2c->bit.getscl = get_clock; |
---|
1073 | 1270 | ret = i2c_bit_add_bus(&i2c->adapter); |
---|
1074 | 1271 | if (ret) { |
---|
1075 | | - DRM_ERROR("Failed to register bit i2c\n"); |
---|
| 1272 | + drm_err(dev, "Failed to register bit i2c\n"); |
---|
1076 | 1273 | goto out_free; |
---|
1077 | 1274 | } |
---|
1078 | 1275 | |
---|
.. | .. |
---|
1088 | 1285 | return; |
---|
1089 | 1286 | i2c_del_adapter(&i2c->adapter); |
---|
1090 | 1287 | kfree(i2c); |
---|
1091 | | -} |
---|
1092 | | - |
---|
1093 | | -static void ast_show_cursor(struct drm_crtc *crtc) |
---|
1094 | | -{ |
---|
1095 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
1096 | | - u8 jreg; |
---|
1097 | | - |
---|
1098 | | - jreg = 0x2; |
---|
1099 | | - /* enable ARGB cursor */ |
---|
1100 | | - jreg |= 1; |
---|
1101 | | - ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, jreg); |
---|
1102 | | -} |
---|
1103 | | - |
---|
1104 | | -static void ast_hide_cursor(struct drm_crtc *crtc) |
---|
1105 | | -{ |
---|
1106 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
1107 | | - ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, 0x00); |
---|
1108 | | -} |
---|
1109 | | - |
---|
1110 | | -static u32 copy_cursor_image(u8 *src, u8 *dst, int width, int height) |
---|
1111 | | -{ |
---|
1112 | | - union { |
---|
1113 | | - u32 ul; |
---|
1114 | | - u8 b[4]; |
---|
1115 | | - } srcdata32[2], data32; |
---|
1116 | | - union { |
---|
1117 | | - u16 us; |
---|
1118 | | - u8 b[2]; |
---|
1119 | | - } data16; |
---|
1120 | | - u32 csum = 0; |
---|
1121 | | - s32 alpha_dst_delta, last_alpha_dst_delta; |
---|
1122 | | - u8 *srcxor, *dstxor; |
---|
1123 | | - int i, j; |
---|
1124 | | - u32 per_pixel_copy, two_pixel_copy; |
---|
1125 | | - |
---|
1126 | | - alpha_dst_delta = AST_MAX_HWC_WIDTH << 1; |
---|
1127 | | - last_alpha_dst_delta = alpha_dst_delta - (width << 1); |
---|
1128 | | - |
---|
1129 | | - srcxor = src; |
---|
1130 | | - dstxor = (u8 *)dst + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta; |
---|
1131 | | - per_pixel_copy = width & 1; |
---|
1132 | | - two_pixel_copy = width >> 1; |
---|
1133 | | - |
---|
1134 | | - for (j = 0; j < height; j++) { |
---|
1135 | | - for (i = 0; i < two_pixel_copy; i++) { |
---|
1136 | | - srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0; |
---|
1137 | | - srcdata32[1].ul = *((u32 *)(srcxor + 4)) & 0xf0f0f0f0; |
---|
1138 | | - data32.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4); |
---|
1139 | | - data32.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4); |
---|
1140 | | - data32.b[2] = srcdata32[1].b[1] | (srcdata32[1].b[0] >> 4); |
---|
1141 | | - data32.b[3] = srcdata32[1].b[3] | (srcdata32[1].b[2] >> 4); |
---|
1142 | | - |
---|
1143 | | - writel(data32.ul, dstxor); |
---|
1144 | | - csum += data32.ul; |
---|
1145 | | - |
---|
1146 | | - dstxor += 4; |
---|
1147 | | - srcxor += 8; |
---|
1148 | | - |
---|
1149 | | - } |
---|
1150 | | - |
---|
1151 | | - for (i = 0; i < per_pixel_copy; i++) { |
---|
1152 | | - srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0; |
---|
1153 | | - data16.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4); |
---|
1154 | | - data16.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4); |
---|
1155 | | - writew(data16.us, dstxor); |
---|
1156 | | - csum += (u32)data16.us; |
---|
1157 | | - |
---|
1158 | | - dstxor += 2; |
---|
1159 | | - srcxor += 4; |
---|
1160 | | - } |
---|
1161 | | - dstxor += last_alpha_dst_delta; |
---|
1162 | | - } |
---|
1163 | | - return csum; |
---|
1164 | | -} |
---|
1165 | | - |
---|
1166 | | -static int ast_cursor_set(struct drm_crtc *crtc, |
---|
1167 | | - struct drm_file *file_priv, |
---|
1168 | | - uint32_t handle, |
---|
1169 | | - uint32_t width, |
---|
1170 | | - uint32_t height) |
---|
1171 | | -{ |
---|
1172 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
1173 | | - struct ast_crtc *ast_crtc = to_ast_crtc(crtc); |
---|
1174 | | - struct drm_gem_object *obj; |
---|
1175 | | - struct ast_bo *bo; |
---|
1176 | | - uint64_t gpu_addr; |
---|
1177 | | - u32 csum; |
---|
1178 | | - int ret; |
---|
1179 | | - struct ttm_bo_kmap_obj uobj_map; |
---|
1180 | | - u8 *src, *dst; |
---|
1181 | | - bool src_isiomem, dst_isiomem; |
---|
1182 | | - if (!handle) { |
---|
1183 | | - ast_hide_cursor(crtc); |
---|
1184 | | - return 0; |
---|
1185 | | - } |
---|
1186 | | - |
---|
1187 | | - if (width > AST_MAX_HWC_WIDTH || height > AST_MAX_HWC_HEIGHT) |
---|
1188 | | - return -EINVAL; |
---|
1189 | | - |
---|
1190 | | - obj = drm_gem_object_lookup(file_priv, handle); |
---|
1191 | | - if (!obj) { |
---|
1192 | | - DRM_ERROR("Cannot find cursor object %x for crtc\n", handle); |
---|
1193 | | - return -ENOENT; |
---|
1194 | | - } |
---|
1195 | | - bo = gem_to_ast_bo(obj); |
---|
1196 | | - |
---|
1197 | | - ret = ast_bo_reserve(bo, false); |
---|
1198 | | - if (ret) |
---|
1199 | | - goto fail; |
---|
1200 | | - |
---|
1201 | | - ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map); |
---|
1202 | | - |
---|
1203 | | - src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem); |
---|
1204 | | - dst = ttm_kmap_obj_virtual(&ast->cache_kmap, &dst_isiomem); |
---|
1205 | | - |
---|
1206 | | - if (src_isiomem == true) |
---|
1207 | | - DRM_ERROR("src cursor bo should be in main memory\n"); |
---|
1208 | | - if (dst_isiomem == false) |
---|
1209 | | - DRM_ERROR("dst bo should be in VRAM\n"); |
---|
1210 | | - |
---|
1211 | | - dst += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor; |
---|
1212 | | - |
---|
1213 | | - /* do data transfer to cursor cache */ |
---|
1214 | | - csum = copy_cursor_image(src, dst, width, height); |
---|
1215 | | - |
---|
1216 | | - /* write checksum + signature */ |
---|
1217 | | - ttm_bo_kunmap(&uobj_map); |
---|
1218 | | - ast_bo_unreserve(bo); |
---|
1219 | | - { |
---|
1220 | | - u8 *dst = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE; |
---|
1221 | | - writel(csum, dst); |
---|
1222 | | - writel(width, dst + AST_HWC_SIGNATURE_SizeX); |
---|
1223 | | - writel(height, dst + AST_HWC_SIGNATURE_SizeY); |
---|
1224 | | - writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTX); |
---|
1225 | | - writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTY); |
---|
1226 | | - |
---|
1227 | | - /* set pattern offset */ |
---|
1228 | | - gpu_addr = ast->cursor_cache_gpu_addr; |
---|
1229 | | - gpu_addr += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor; |
---|
1230 | | - gpu_addr >>= 3; |
---|
1231 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc8, gpu_addr & 0xff); |
---|
1232 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc9, (gpu_addr >> 8) & 0xff); |
---|
1233 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xca, (gpu_addr >> 16) & 0xff); |
---|
1234 | | - } |
---|
1235 | | - ast_crtc->cursor_width = width; |
---|
1236 | | - ast_crtc->cursor_height = height; |
---|
1237 | | - ast_crtc->offset_x = AST_MAX_HWC_WIDTH - width; |
---|
1238 | | - ast_crtc->offset_y = AST_MAX_HWC_WIDTH - height; |
---|
1239 | | - |
---|
1240 | | - ast->next_cursor = (ast->next_cursor + 1) % AST_DEFAULT_HWC_NUM; |
---|
1241 | | - |
---|
1242 | | - ast_show_cursor(crtc); |
---|
1243 | | - |
---|
1244 | | - drm_gem_object_put_unlocked(obj); |
---|
1245 | | - return 0; |
---|
1246 | | -fail: |
---|
1247 | | - drm_gem_object_put_unlocked(obj); |
---|
1248 | | - return ret; |
---|
1249 | | -} |
---|
1250 | | - |
---|
1251 | | -static int ast_cursor_move(struct drm_crtc *crtc, |
---|
1252 | | - int x, int y) |
---|
1253 | | -{ |
---|
1254 | | - struct ast_crtc *ast_crtc = to_ast_crtc(crtc); |
---|
1255 | | - struct ast_private *ast = crtc->dev->dev_private; |
---|
1256 | | - int x_offset, y_offset; |
---|
1257 | | - u8 *sig; |
---|
1258 | | - |
---|
1259 | | - sig = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE; |
---|
1260 | | - writel(x, sig + AST_HWC_SIGNATURE_X); |
---|
1261 | | - writel(y, sig + AST_HWC_SIGNATURE_Y); |
---|
1262 | | - |
---|
1263 | | - x_offset = ast_crtc->offset_x; |
---|
1264 | | - y_offset = ast_crtc->offset_y; |
---|
1265 | | - if (x < 0) { |
---|
1266 | | - x_offset = (-x) + ast_crtc->offset_x; |
---|
1267 | | - x = 0; |
---|
1268 | | - } |
---|
1269 | | - |
---|
1270 | | - if (y < 0) { |
---|
1271 | | - y_offset = (-y) + ast_crtc->offset_y; |
---|
1272 | | - y = 0; |
---|
1273 | | - } |
---|
1274 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc2, x_offset); |
---|
1275 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc3, y_offset); |
---|
1276 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc4, (x & 0xff)); |
---|
1277 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc5, ((x >> 8) & 0x0f)); |
---|
1278 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc6, (y & 0xff)); |
---|
1279 | | - ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc7, ((y >> 8) & 0x07)); |
---|
1280 | | - |
---|
1281 | | - /* dummy write to fire HWC */ |
---|
1282 | | - ast_show_cursor(crtc); |
---|
1283 | | - |
---|
1284 | | - return 0; |
---|
1285 | 1288 | } |
---|