display_gx.c 4.8 KB

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