display_gx.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 "gxfb.h"
  21. unsigned int gx_frame_buffer_size(void)
  22. {
  23. unsigned int val;
  24. /* FB size is reported by a virtual register */
  25. /* Virtual register class = 0x02 */
  26. /* VG_MEM_SIZE(512Kb units) = 0x00 */
  27. outw(0xFC53, 0xAC1C);
  28. outw(0x0200, 0xAC1C);
  29. val = (unsigned int)(inw(0xAC1E)) & 0xFFl;
  30. return (val << 19);
  31. }
  32. int gx_line_delta(int xres, int bpp)
  33. {
  34. /* Must be a multiple of 8 bytes. */
  35. return (xres * (bpp >> 3) + 7) & ~0x7;
  36. }
  37. void gx_set_mode(struct fb_info *info)
  38. {
  39. struct gxfb_par *par = info->par;
  40. u32 gcfg, dcfg;
  41. int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
  42. int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
  43. /* Unlock the display controller registers. */
  44. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  45. gcfg = read_dc(par, DC_GENERAL_CFG);
  46. dcfg = read_dc(par, DC_DISPLAY_CFG);
  47. /* Disable the timing generator. */
  48. dcfg &= ~DC_DISPLAY_CFG_TGEN;
  49. write_dc(par, DC_DISPLAY_CFG, dcfg);
  50. /* Wait for pending memory requests before disabling the FIFO load. */
  51. udelay(100);
  52. /* Disable FIFO load and compression. */
  53. gcfg &= ~(DC_GENERAL_CFG_DFLE | DC_GENERAL_CFG_CMPE |
  54. DC_GENERAL_CFG_DECE);
  55. write_dc(par, DC_GENERAL_CFG, gcfg);
  56. /* Setup DCLK and its divisor. */
  57. gx_set_dclk_frequency(info);
  58. /*
  59. * Setup new mode.
  60. */
  61. /* Clear all unused feature bits. */
  62. gcfg &= DC_GENERAL_CFG_YUVM | DC_GENERAL_CFG_VDSE;
  63. dcfg = 0;
  64. /* Set FIFO priority (default 6/5) and enable. */
  65. /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
  66. gcfg |= (6 << DC_GENERAL_CFG_DFHPEL_SHIFT) |
  67. (5 << DC_GENERAL_CFG_DFHPSL_SHIFT) | DC_GENERAL_CFG_DFLE;
  68. /* Framebuffer start offset. */
  69. write_dc(par, DC_FB_ST_OFFSET, 0);
  70. /* Line delta and line buffer length. */
  71. write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3);
  72. write_dc(par, DC_LINE_SIZE,
  73. ((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2);
  74. /* Enable graphics and video data and unmask address lines. */
  75. dcfg |= DC_DISPLAY_CFG_GDEN | DC_DISPLAY_CFG_VDEN |
  76. DC_DISPLAY_CFG_A20M | DC_DISPLAY_CFG_A18M;
  77. /* Set pixel format. */
  78. switch (info->var.bits_per_pixel) {
  79. case 8:
  80. dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
  81. break;
  82. case 16:
  83. dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
  84. break;
  85. case 32:
  86. dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
  87. dcfg |= DC_DISPLAY_CFG_PALB;
  88. break;
  89. }
  90. /* Enable timing generator. */
  91. dcfg |= DC_DISPLAY_CFG_TGEN;
  92. /* Horizontal and vertical timings. */
  93. hactive = info->var.xres;
  94. hblankstart = hactive;
  95. hsyncstart = hblankstart + info->var.right_margin;
  96. hsyncend = hsyncstart + info->var.hsync_len;
  97. hblankend = hsyncend + info->var.left_margin;
  98. htotal = hblankend;
  99. vactive = info->var.yres;
  100. vblankstart = vactive;
  101. vsyncstart = vblankstart + info->var.lower_margin;
  102. vsyncend = vsyncstart + info->var.vsync_len;
  103. vblankend = vsyncend + info->var.upper_margin;
  104. vtotal = vblankend;
  105. write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) |
  106. ((htotal - 1) << 16));
  107. write_dc(par, DC_H_BLANK_TIMING, (hblankstart - 1) |
  108. ((hblankend - 1) << 16));
  109. write_dc(par, DC_H_SYNC_TIMING, (hsyncstart - 1) |
  110. ((hsyncend - 1) << 16));
  111. write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) |
  112. ((vtotal - 1) << 16));
  113. write_dc(par, DC_V_BLANK_TIMING, (vblankstart - 1) |
  114. ((vblankend - 1) << 16));
  115. write_dc(par, DC_V_SYNC_TIMING, (vsyncstart - 1) |
  116. ((vsyncend - 1) << 16));
  117. /* Write final register values. */
  118. write_dc(par, DC_DISPLAY_CFG, dcfg);
  119. write_dc(par, DC_GENERAL_CFG, gcfg);
  120. gx_configure_display(info);
  121. /* Relock display controller registers */
  122. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  123. }
  124. void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
  125. unsigned red, unsigned green, unsigned blue)
  126. {
  127. struct gxfb_par *par = info->par;
  128. int val;
  129. /* Hardware palette is in RGB 8-8-8 format. */
  130. val = (red << 8) & 0xff0000;
  131. val |= (green) & 0x00ff00;
  132. val |= (blue >> 8) & 0x0000ff;
  133. write_dc(par, DC_PAL_ADDRESS, regno);
  134. write_dc(par, DC_PAL_DATA, val);
  135. }