30 #include <linux/export.h>
41 struct drm_file *file_priv,
48 static inline void ast_load_palette_index(
struct ast_private *ast,
71 for (i = 0; i < 256; i++)
72 ast_load_palette_index(ast, i, ast_crtc->
lut_r[i],
81 u32 refresh_rate_index = 0, mode_id, color_index, refresh_rate;
84 switch (crtc->
fb->bits_per_pixel) {
102 switch (crtc->
mode.crtc_hdisplay) {
113 if (crtc->
mode.crtc_vdisplay == 800)
114 vbios_mode->
enh_table = &res_1280x800[refresh_rate_index];
119 vbios_mode->
enh_table = &res_1440x900[refresh_rate_index];
128 if (crtc->
mode.crtc_vdisplay == 1080)
138 while (vbios_mode->
enh_table->refresh_rate < refresh_rate) {
140 if ((vbios_mode->
enh_table->refresh_rate > refresh_rate) ||
141 (vbios_mode->
enh_table->refresh_rate == 0xff)) {
168 refresh_rate_index = vbios_mode->
enh_table->refresh_rate_index;
169 mode_id = vbios_mode->
enh_table->mode_id;
202 jreg = stdtable->
misc;
207 for (i = 0; i < 4; i++) {
208 jreg = stdtable->
seq[
i];
216 for (i = 0; i < 25; i++)
221 for (i = 0; i < 20; i++) {
222 jreg = stdtable->
ar[
i];
233 for (i = 0; i < 9; i++)
241 u8 jreg05 = 0, jreg07 = 0, jreg09 = 0, jregAC = 0, jregAD = 0, jregAE = 0;
337 static void ast_set_offset_reg(
struct drm_crtc *crtc)
343 offset = crtc->
fb->pitches[0] >> 3;
354 clk_info = &dclk_table[vbios_mode->
enh_table->dclk_index];
359 (clk_info->
param3 & 0x80) | ((clk_info->
param3 & 0x3) << 4));
366 u8 jregA0 = 0, jregA3 = 0, jregA8 = 0;
368 switch (crtc->
fb->bits_per_pixel) {
421 switch (crtc->
fb->bits_per_pixel) {
442 static void ast_crtc_dpms(
struct drm_crtc *crtc,
int mode)
454 ast_crtc_load_lut(crtc);
462 static bool ast_crtc_mode_fixup(
struct drm_crtc *crtc,
470 static int ast_crtc_do_set_base(
struct drm_crtc *crtc,
472 int x,
int y,
int atomic)
475 struct drm_gem_object *obj;
507 if (&ast->
fbdev->afb == ast_fb) {
511 DRM_ERROR(
"failed to kmap fbcon\n");
520 static int ast_crtc_mode_set_base(
struct drm_crtc *crtc,
int x,
int y,
523 return ast_crtc_do_set_base(crtc, old_fb, x, y, 0);
526 static int ast_crtc_mode_set(
struct drm_crtc *crtc,
537 DRM_ERROR(
"AST 1180 modesetting not supported\n");
541 ret = ast_get_vbios_mode_info(crtc, mode, adjusted_mode, &vbios_mode);
548 ast_set_std_reg(crtc, adjusted_mode, &vbios_mode);
549 ast_set_crtc_reg(crtc, adjusted_mode, &vbios_mode);
550 ast_set_offset_reg(crtc);
551 ast_set_dclk_reg(dev, adjusted_mode, &vbios_mode);
552 ast_set_ext_reg(crtc, adjusted_mode, &vbios_mode);
556 ast_crtc_mode_set_base(crtc, x, y, old_fb);
561 static void ast_crtc_disable(
struct drm_crtc *crtc)
566 static void ast_crtc_prepare(
struct drm_crtc *crtc)
571 static void ast_crtc_commit(
struct drm_crtc *crtc)
579 .dpms = ast_crtc_dpms,
580 .mode_fixup = ast_crtc_mode_fixup,
581 .mode_set = ast_crtc_mode_set,
582 .mode_set_base = ast_crtc_mode_set_base,
583 .disable = ast_crtc_disable,
584 .load_lut = ast_crtc_load_lut,
585 .prepare = ast_crtc_prepare,
586 .commit = ast_crtc_commit,
590 static void ast_crtc_reset(
struct drm_crtc *crtc)
599 int end = (start + size > 256) ? 256 : start + size, i;
602 for (i = start; i <
end; i++) {
603 ast_crtc->
lut_r[
i] = red[
i] >> 8;
604 ast_crtc->
lut_g[
i] = green[
i] >> 8;
605 ast_crtc->
lut_b[
i] = blue[
i] >> 8;
607 ast_crtc_load_lut(crtc);
611 static void ast_crtc_destroy(
struct drm_crtc *crtc)
618 .cursor_set = ast_cursor_set,
619 .cursor_move = ast_cursor_move,
620 .reset = ast_crtc_reset,
622 .gamma_set = ast_crtc_gamma_set,
623 .destroy = ast_crtc_destroy,
628 struct ast_crtc *crtc;
631 crtc = kzalloc(
sizeof(
struct ast_crtc),
GFP_KERNEL);
637 drm_crtc_helper_add(&crtc->
base, &ast_crtc_helper_funcs);
639 for (i = 0; i < 256; i++) {
647 static void ast_encoder_destroy(
struct drm_encoder *encoder)
673 .destroy = ast_encoder_destroy,
676 static void ast_encoder_dpms(
struct drm_encoder *encoder,
int mode)
681 static bool ast_mode_fixup(
struct drm_encoder *encoder,
688 static void ast_encoder_mode_set(
struct drm_encoder *encoder,
694 static void ast_encoder_prepare(
struct drm_encoder *encoder)
699 static void ast_encoder_commit(
struct drm_encoder *encoder)
706 .dpms = ast_encoder_dpms,
707 .mode_fixup = ast_mode_fixup,
708 .prepare = ast_encoder_prepare,
709 .commit = ast_encoder_commit,
710 .mode_set = ast_encoder_mode_set,
717 ast_encoder = kzalloc(
sizeof(
struct ast_encoder),
GFP_KERNEL);
723 drm_encoder_helper_add(&ast_encoder->
base, &ast_enc_helper_funcs);
725 ast_encoder->
base.possible_crtcs = 1;
752 static void ast_connector_destroy(
struct drm_connector *connector)
755 ast_i2c_destroy(ast_connector->
i2c);
768 .mode_valid = ast_mode_valid,
769 .get_modes = ast_get_modes,
770 .best_encoder = ast_best_single_encoder,
775 .detect = ast_connector_detect,
777 .destroy = ast_connector_destroy,
782 struct ast_connector *ast_connector;
786 ast_connector = kzalloc(
sizeof(
struct ast_connector),
GFP_KERNEL);
790 connector = &ast_connector->
base;
793 drm_connector_helper_add(connector, &ast_connector_helper_funcs);
805 ast_connector->
i2c = ast_i2c_create(dev);
806 if (!ast_connector->
i2c)
807 DRM_ERROR(
"failed to add ddc bus for connector\n");
818 struct drm_gem_object *obj;
878 return val & 1 ? 1 : 0;
881 static int get_data(
void *i2c_priv)
888 return val & 1 ? 1 : 0;
891 static void set_clock(
void *i2c_priv,
int clock)
898 for (i = 0; i < 0x10000; i++) {
899 ujcrb7 = ((clock & 0x01) ? 0 : 1);
907 static void set_data(
void *i2c_priv,
int data)
914 for (i = 0; i < 0x10000; i++) {
915 ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
934 i2c->
adapter.dev.parent = &dev->pdev->dev;
936 i2c_set_adapdata(&i2c->
adapter, i2c);
941 i2c->
bit.udelay = 20;
942 i2c->
bit.timeout = 2;
944 i2c->
bit.setsda = set_data;
945 i2c->
bit.setscl = set_clock;
946 i2c->
bit.getsda = get_data;
950 DRM_ERROR(
"Failed to register bit i2c\n");
990 } srcdata32[2], data32;
996 s32 alpha_dst_delta, last_alpha_dst_delta;
999 u32 per_pixel_copy, two_pixel_copy;
1002 last_alpha_dst_delta = alpha_dst_delta - (width << 1);
1006 per_pixel_copy = width & 1;
1007 two_pixel_copy = width >> 1;
1009 for (j = 0; j <
height; j++) {
1010 for (i = 0; i < two_pixel_copy; i++) {
1011 srcdata32[0].ul = *((
u32 *)srcxor) & 0xf0f0f0f0;
1012 srcdata32[1].ul = *((
u32 *)(srcxor + 4)) & 0xf0f0f0f0;
1013 data32.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
1014 data32.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
1015 data32.b[2] = srcdata32[0].b[1] | (srcdata32[1].b[0] >> 4);
1016 data32.b[3] = srcdata32[0].b[3] | (srcdata32[1].b[2] >> 4);
1018 writel(data32.ul, dstxor);
1026 for (i = 0; i < per_pixel_copy; i++) {
1027 srcdata32[0].ul = *((
u32 *)srcxor) & 0xf0f0f0f0;
1028 data16.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
1029 data16.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
1030 writew(data16.us, dstxor);
1031 csum += (
u32)data16.us;
1036 dstxor += last_alpha_dst_delta;
1041 static int ast_cursor_set(
struct drm_crtc *crtc,
1042 struct drm_file *file_priv,
1049 struct drm_gem_object *obj;
1056 bool src_isiomem, dst_isiomem;
1067 DRM_ERROR(
"Cannot find cursor object %x for crtc\n", handle);
1078 src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
1079 dst = ttm_kmap_obj_virtual(&ast->
cache_kmap, &dst_isiomem);
1081 if (src_isiomem ==
true)
1082 DRM_ERROR(
"src cursor bo should be in main memory\n");
1083 if (dst_isiomem ==
false)
1084 DRM_ERROR(
"dst bo should be in VRAM\n");
1089 csum = copy_cursor_image(src, dst, width, height);
1119 drm_gem_object_unreference_unlocked(obj);
1122 drm_gem_object_unreference_unlocked(obj);
1126 static int ast_cursor_move(
struct drm_crtc *crtc,
1131 int x_offset, y_offset;