display_gx.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Geode GX display controller.
  3. *
  4. * Copyright (C) 2005 Arcom Control Systems Ltd.
  5. *
  6. * Portions from AMD's original 2.4 driver:
  7. * Copyright (C) 2004 Advanced Micro Devices, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by * the
  11. * Free Software Foundation; either version 2 of the License, or * (at your
  12. * option) any later version.
  13. */
  14. #include <linux/spinlock.h>
  15. #include <linux/fb.h>
  16. #include <linux/delay.h>
  17. #include <asm/io.h>
  18. #include <asm/div64.h>
  19. #include <asm/delay.h>
  20. #include <linux/cs5535.h>
  21. #include "gxfb.h"
  22. unsigned int gx_frame_buffer_size(void)
  23. {
  24. unsigned int val;
  25. if (!cs5535_has_vsa2()) {
  26. uint32_t hi, lo;
  27. /* The number of pages is (PMAX - PMIN)+1 */
  28. rdmsr(MSR_GLIU_P2D_RO0, lo, hi);
  29. /* PMAX */
  30. val = ((hi & 0xff) << 12) | ((lo & 0xfff00000) >> 20);
  31. /* PMIN */
  32. val -= (lo & 0x000fffff);
  33. val += 1;
  34. /* The page size is 4k */
  35. return (val << 12);
  36. }
  37. /* FB size can be obtained from the VSA II */
  38. /* Virtual register class = 0x02 */
  39. /* VG_MEM_SIZE(512Kb units) = 0x00 */
  40. outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
  41. outw(VSA_VR_MEM_SIZE, VSA_VRC_INDEX);
  42. val = (unsigned int)(inw(VSA_VRC_DATA)) & 0xFFl;
  43. return (val << 19);
  44. }
  45. int gx_line_delta(int xres, int bpp)
  46. {
  47. /* Must be a multiple of 8 bytes. */
  48. return (xres * (bpp >> 3) + 7) & ~0x7;
  49. }
  50. void gx_set_mode(struct fb_info *info)
  51. {
  52. struct gxfb_par *par = info->par;
  53. u32 gcfg, dcfg;
  54. int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
  55. int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
  56. /* Unlock the display controller registers. */
  57. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  58. gcfg = read_dc(par, DC_GENERAL_CFG);
  59. dcfg = read_dc(par, DC_DISPLAY_CFG);
  60. /* Disable the timing generator. */
  61. dcfg &= ~DC_DISPLAY_CFG_TGEN;
  62. write_dc(par, DC_DISPLAY_CFG, dcfg);
  63. /* Wait for pending memory requests before disabling the FIFO load. */
  64. udelay(100);
  65. /* Disable FIFO load and compression. */
  66. gcfg &= ~(DC_GENERAL_CFG_DFLE | DC_GENERAL_CFG_CMPE |
  67. DC_GENERAL_CFG_DECE);
  68. write_dc(par, DC_GENERAL_CFG, gcfg);
  69. /* Setup DCLK and its divisor. */
  70. gx_set_dclk_frequency(info);
  71. /*
  72. * Setup new mode.
  73. */
  74. /* Clear all unused feature bits. */
  75. gcfg &= DC_GENERAL_CFG_YUVM | DC_GENERAL_CFG_VDSE;
  76. dcfg = 0;
  77. /* Set FIFO priority (default 6/5) and enable. */
  78. /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
  79. gcfg |= (6 << DC_GENERAL_CFG_DFHPEL_SHIFT) |
  80. (5 << DC_GENERAL_CFG_DFHPSL_SHIFT) | DC_GENERAL_CFG_DFLE;
  81. /* Framebuffer start offset. */
  82. write_dc(par, DC_FB_ST_OFFSET, 0);
  83. /* Line delta and line buffer length. */
  84. write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3);
  85. write_dc(par, DC_LINE_SIZE,
  86. ((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2);
  87. /* Enable graphics and video data and unmask address lines. */
  88. dcfg |= DC_DISPLAY_CFG_GDEN | DC_DISPLAY_CFG_VDEN |
  89. DC_DISPLAY_CFG_A20M | DC_DISPLAY_CFG_A18M;
  90. /* Set pixel format. */
  91. switch (info->var.bits_per_pixel) {
  92. case 8:
  93. dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
  94. break;
  95. case 16:
  96. dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
  97. break;
  98. case 32:
  99. dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
  100. dcfg |= DC_DISPLAY_CFG_PALB;
  101. break;
  102. }
  103. /* Enable timing generator. */
  104. dcfg |= DC_DISPLAY_CFG_TGEN;
  105. /* Horizontal and vertical timings. */
  106. hactive = info->var.xres;
  107. hblankstart = hactive;
  108. hsyncstart = hblankstart + info->var.right_margin;
  109. hsyncend = hsyncstart + info->var.hsync_len;
  110. hblankend = hsyncend + info->var.left_margin;
  111. htotal = hblankend;
  112. vactive = info->var.yres;
  113. vblankstart = vactive;
  114. vsyncstart = vblankstart + info->var.lower_margin;
  115. vsyncend = vsyncstart + info->var.vsync_len;
  116. vblankend = vsyncend + info->var.upper_margin;
  117. vtotal = vblankend;
  118. write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) |
  119. ((htotal - 1) << 16));
  120. write_dc(par, DC_H_BLANK_TIMING, (hblankstart - 1) |
  121. ((hblankend - 1) << 16));
  122. write_dc(par, DC_H_SYNC_TIMING, (hsyncstart - 1) |
  123. ((hsyncend - 1) << 16));
  124. write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) |
  125. ((vtotal - 1) << 16));
  126. write_dc(par, DC_V_BLANK_TIMING, (vblankstart - 1) |
  127. ((vblankend - 1) << 16));
  128. write_dc(par, DC_V_SYNC_TIMING, (vsyncstart - 1) |
  129. ((vsyncend - 1) << 16));
  130. /* Write final register values. */
  131. write_dc(par, DC_DISPLAY_CFG, dcfg);
  132. write_dc(par, DC_GENERAL_CFG, gcfg);
  133. gx_configure_display(info);
  134. /* Relock display controller registers */
  135. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  136. }
  137. void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
  138. unsigned red, unsigned green, unsigned blue)
  139. {
  140. struct gxfb_par *par = info->par;
  141. int val;
  142. /* Hardware palette is in RGB 8-8-8 format. */
  143. val = (red << 8) & 0xff0000;
  144. val |= (green) & 0x00ff00;
  145. val |= (blue >> 8) & 0x0000ff;
  146. write_dc(par, DC_PAL_ADDRESS, regno);
  147. write_dc(par, DC_PAL_DATA, val);
  148. }